Attach a new resource to an existing Aptos object

Publishing an additional resource under an object address requires a signer for that address. An extension reference retained during construction provides a controlled path to that signer.

Retain the extension reference at construction

When the object is created, generate an ExtendRef from its ConstructorRef and store it in a private module-managed control resource. The excerpt adds a Calibration resource later. The calling user’s own signer would publish at the user’s address.

let object_signer = object::generate_signer_for_extending(&control.extension);
move_to(&object_signer, Calibration { revision: 2 });

Check absence and authorization before publishing

A second move_to of the same Calibration type at this address aborts. To update revision 2 to 3, mutate the existing resource through the module defining it. Protect every public operation that can use the stored ExtendRef; ownership of an Object handle alone cannot authorize arbitrary code to create its signer.

Sources