Function authorize_once
pub comptime fn authorize_once(
f: FunctionDefinition,
from_arg_name: CtString,
nonce_arg_name: CtString,
)
pub comptime fn authorize_once(
f: FunctionDefinition,
from_arg_name: CtString,
nonce_arg_name: CtString,
)
Restricts access to an external private or public function so that it can only be called by an authorized account.
Receives the name of a
fromAztecAddressvariable which will be the default authorized account, and the name of anonceFieldvariable which is used byfromto grant one-time-only access to other accounts.Usage
The
fromaccount can always call an authorize_once function by passing a value of 0 as thenonce. Any other caller requires explicit permission granted by thefromaccount, which 1) will be tied to a specificnoncevalue that must be passed by the caller, and which can only be used once, and 2) will restrict all other function params to be exactly the ones that have been authorized byfrom.Cost
Private functions perform a private authwit check by calling the standard account contract
verify_private_authwitfunction onfromwith the hash resulting of all function params and the nonce. A nullifier is then emitted, preventing the same permission from being used again. Note that this requires that the caller has access tofrom's contract class ID and salted initialization hash, as it would otherwise not be possible to call theverify_private_authwitfunction.Public functions call the
consumefunction on theAuthRegistrycontract, which requires that either a)fromfirst calls theset_authorizedpublic function, or b) that a private authwit check byfromis passed for the registry'sset_authorized_privatefunction, allowing in turn the caller to privately callset_authorized_privatein the same transaction in which the authorize_once function is invoked.