Signer
signer
is a built-in Move resource type. A signer
is a capability that allows the holder to act on behalf of a particular address
. You can think of the native implementation as being:
A signer
is somewhat similar to a Unix UID in that it represents a user authenticated by code outside of Move (e.g., by checking a cryptographic signature or password).
Comparison to address
address
A Move program can create any address
value without special permission using address literals:
However, signer
values are special because they cannot be created via literals or instructions--only by the Move VM. Before the VM runs a script with parameters of type signer
, it will automatically create signer
values and pass them into the script:
This script will abort with code 0
if the script is sent from any address other than 0x42
.
A transaction script can have an arbitrary number of signer
s as long as the signer
s are a prefix to any other arguments. In other words, all of the signer
arguments must come first:
This is useful for implementing multi-signer scripts that atomically act with the authority of multiple parties. For example, an extension of the script above could perform an atomic currency swap between s1
and s2
.
signer
Operators
signer
OperatorsThe std::signer
standard library module provides two utility functions over signer
values:
In addition, the move_to<T>(&signer, T)
global storage operator requires a &signer
argument to publish a resource T
under signer.address
's account. This ensures that only an authenticated user can elect to publish a resource under their address
.
Ownership
Unlike simple scalar values, signer
values are not copyable, meaning they cannot be copied (from any operation whether it be through an explicit copy
instruction or through a dereference *
.