Keys
Accounts have keys associated with them. When a key is added to an account, the key can be used to sign a transaction, which in turn gets access the account and can perform write operations on it.
An account exposes its keys through the keys
field,
which has the type Account.Keys
.
Account.Keys
Account key
An account key has the following structure:
Refer to the public keys section for more details on the creation and validity of public keys.
Refer to the hash algorithms section for more details on supported hash algorithms.
Getting an account key
The functions keys.get
and keys.forEach
allow retrieving the keys of an account.
The get
function allows retrieving a key with a specific index.
The function returns the key if it exists, and nil
otherwise.
The forEach
function allows iterating over all keys of an account.
For each key of the account, the forEach
function calls the given callback, passing the key to it.
When the callback function returns true
the iteration continues,
and when it returns false
, iteration stops.
The keys.get
and keys.forEach
functions include revoked keys,
which have the isRevoked
field set to true
.
Adding an account key
The function keys.add
allows a key to access an account.
Calling the add
function requires access to an account via a reference which is authorized
with the coarse-grained Keys
entitlement (auth(Keys) &Account
),
or the fine-grained AddKey
entitlement (auth(AddKey) &Account
).
For example, to add a public key to an existing account, which signed the transaction:
A more complex transaction, which creates an account, has the signer of the transaction pay for the account creation, and authorizes one key to access the account, could look like:
Revoking an account key
The revoke
function revokes a key from accessing an account.
The function only marks the key at the given index as revoked, but never deletes it.
Calling the revoke
function requires access to an account via a reference which is authorized
with the coarse-grained Keys
entitlement (auth(Keys) &Account
),
or the fine-grained RevokeKey
entitlement (auth(RevokeKey) &Account
).
For example, to revoke the third key of the account which signed the transaction: