Account
This crate provides components to implement account contracts that can be used for interacting with the network.
Interfaces
Starting from version 3.x.x, the interfaces are no longer part of the openzeppelin_account package. The references documented here are contained in the openzeppelin_interfaces package version v2.1.0.
ISRC6
use openzeppelin_interfaces::accounts::ISRC6;Interface of the SRC6 Standard Account as defined in the SNIP-6.
0x2ceccef7f994940b3962a6c67e0ba4fcd37df7d131417c604f91e03caecc1cd
Functions
Functions
__execute__(calls: Array<Call>) external
Executes the list of calls as a transaction after validation.
The Call struct is defined in corelib.
__validate__(calls: Array<Call>) → felt252 external
Validates a transaction before execution.
Returns the short string 'VALID' if valid, otherwise it reverts.
is_valid_signature(hash: felt252, signature: Array<felt252>) → felt252 external
Validates whether a signature is valid or not for the given message hash.
Returns the short string 'VALID' if valid, otherwise it reverts.
ISRC9_V2
use openzeppelin_interfaces::src9::ISRC9_V2;Interface of the SRC9 Standard as defined in the SNIP-9.
0x1d1144bb2138366ff28d8e9ab57456b1d332ac42196230c3a602003c89872
Functions
Functions
execute_from_outside_v2(outside_execution: OutsideExecution, signature: Span<felt252>,) → Array<Span<felt252>> external
Allows anyone to submit a transaction on behalf of the account as long as they have the relevant signatures.
This method allows reentrancy. A call to __execute__ or execute_from_outside_v2 can trigger another nested transaction to execute_from_outside_v2 thus the implementation MUST verify that the provided signature matches the hash of outside_execution and that nonce was not already used.
The implementation should expect version to be set to 2 in the domain separator.
Arguments:
outside_execution- The parameters of the transaction to execute.signature- A valid signature on the SNIP-12 message encoding ofoutside_execution.
is_valid_outside_execution_nonce(nonce: felt252) → bool external
Get the status of a given nonce. true if the nonce is available to use.
Core
AccountComponent
use openzeppelin_account::AccountComponent;Account component implementing ISRC6 for signatures over the Starknet curve.
Implementing SRC5Component is a requirement for this component to be implemented.
Embeddable Mixin Implementations
AccountMixinImpl
Embeddable Implementations
SRC6Impl
DeclarerImpl
DeployableImpl
PublicKeyImpl
SRC6CamelOnlyImpl
PublicKeyCamelImpl
SRC5Impl
Internal Implementations
InternalImpl
initializer(self, public_key)assert_only_self(self)assert_valid_new_owner(self, current_owner, new_owner, signature)validate_transaction(self)_set_public_key(self, new_public_key)_is_valid_signature(self, hash, signature)
Events
Embeddable functions
__execute__(self: @ContractState, calls: Array<Call>) external
See ISRC6::__execute__.
__validate__(self: @ContractState, calls: Array<Call>) → felt252 external
See ISRC6::__validate__.
is_valid_signature(self: @ContractState, hash: felt252, signature: Array<felt252>) → felt252 external
See ISRC6::is_valid_signature.
__validate_declare__(self: @ContractState, class_hash: felt252) → felt252 external
Validates a Declare transaction.
Returns the short string 'VALID' if valid, otherwise it reverts.
__validate_deploy__(self: @ContractState, class_hash: felt252, contract_address_salt: felt252, public_key: felt252) → felt252 external
Validates a DeployAccount transaction. See Counterfactual Deployments.
Returns the short string 'VALID' if valid, otherwise it reverts.
get_public_key(self: @ContractState) → felt252 external
Returns the current public key of the account.
set_public_key(ref self: ContractState, new_public_key: felt252, signature: Span<felt252>) external
Sets a new public key for the account. Only accessible by the account calling itself through __execute__.
Requirements:
- The caller must be the contract itself.
- The signature must be valid for the new owner.
Emits both an OwnerRemoved and an OwnerAdded event.
The message to be signed is computed in Cairo as follows:
let message_hash = PoseidonTrait::new()
.update_with('StarkNet Message')
.update_with('accept_ownership')
.update_with(get_contract_address())
.update_with(current_owner)
.finalize();isValidSignature(self: @ContractState, hash: felt252, signature: Array<felt252>) → felt252 external
See ISRC6::is_valid_signature.
getPublicKey(self: @ContractState) → felt252 external
See get_public_key.
setPublicKey(ref self: ContractState, newPublicKey: felt252, signature: Span<felt252>) external
See set_public_key.
Internal functions
initializer(ref self: ComponentState, public_key: felt252) internal
Initializes the account with the given public key, and registers the ISRC6 interface ID.
Emits an OwnerAdded event.
assert_only_self(self: @ComponentState) internal
Validates that the caller is the account itself. Otherwise it reverts.
assert_valid_new_owner(self: @ComponentState, current_owner: felt252, new_owner: felt252, signature: Span<felt252>) internal
Validates that new_owner accepted the ownership of the contract through a signature.
Requirements:
signaturemust be valid for the new owner.
This function assumes that current_owner is the current owner of the contract, and does not validate this assumption.
validate_transaction(self: @ComponentState) → felt252 internal
Validates a transaction signature from the global context.
Returns the short string 'VALID' if valid, otherwise it reverts.
_set_public_key(ref self: ComponentState, new_public_key: felt252) internal
Set the public key without validating the caller.
Emits an OwnerAdded event.
The usage of this method outside the set_public_key function is discouraged.
_is_valid_signature(self: @ComponentState, hash: felt252, signature: Span<felt252>) → bool internal
Validates the provided signature for the hash, using the account’s current public key.
Events
OwnerAdded(new_owner_guid: felt252) event
Emitted when a public_key is added.
OwnerRemoved(removed_owner_guid: felt252) event
Emitted when a public_key is removed.
EthAccountComponent
use openzeppelin_account::eth_account::EthAccountComponent;Account component implementing ISRC6 for signatures over the Secp256k1 curve.
Implementing SRC5Component is a requirement for this component to be implemented.
The EthPublicKey type is an alias for starknet::secp256k1::Secp256k1Point.
Embeddable Mixin Implementations
EthAccountMixinImpl
Embeddable Implementations
SRC6Impl
DeclarerImpl
DeployableImpl
PublicKeyImpl
SRC6CamelOnlyImpl
PublicKeyCamelImpl
SRC5Impl
Internal Implementations
InternalImpl
initializer(self, public_key)assert_only_self(self)assert_valid_new_owner(self, current_owner, new_owner, signature)validate_transaction(self)_set_public_key(self, new_public_key)_is_valid_signature(self, hash, signature)
Events
Embeddable functions
__execute__(self: @ContractState, calls: Array<Call>) external
See ISRC6::__execute__.
__validate__(self: @ContractState, calls: Array<Call>) → felt252 external
See ISRC6::__validate__.
is_valid_signature(self: @ContractState, hash: felt252, signature: Array<felt252>) → felt252 external
See ISRC6::is_valid_signature.
__validate_declare__(self: @ContractState, class_hash: felt252) → felt252 external
Validates a Declare transaction.
Returns the short string 'VALID' if valid, otherwise it reverts.
__validate_deploy__(self: @ContractState, class_hash: felt252, contract_address_salt: felt252, public_key: EthPublicKey) → felt252 external
Validates a DeployAccount transaction. See Counterfactual Deployments.
Returns the short string 'VALID' if valid, otherwise it reverts.
get_public_key(self: @ContractState) → EthPublicKey external
Returns the current public key of the account.
set_public_key(ref self: ContractState, new_public_key: EthPublicKey, signature: Span<felt252>) external
Sets a new public key for the account. Only accessible by the account calling itself through __execute__.
Requirements:
- The caller must be the contract itself.
- The signature must be valid for the new owner.
Emits both an OwnerRemoved and an OwnerAdded event.
The message to be signed is computed in Cairo as follows:
let message_hash = PoseidonTrait::new()
.update_with('StarkNet Message')
.update_with('accept_ownership')
.update_with(get_contract_address())
.update_with(current_owner.get_coordinates().unwrap_syscall())
.finalize();isValidSignature(self: @ContractState, hash: felt252, signature: Array<felt252>) → felt252 external
See ISRC6::is_valid_signature.
getPublicKey(self: @ContractState) → EthPublicKey external
See get_public_key.
setPublicKey(ref self: ContractState, newPublicKey: EthPublicKey, signature: Span<felt252>) external
See set_public_key.
Internal functions
initializer(ref self: ComponentState, public_key: EthPublicKey) internal
Initializes the account with the given public key, and registers the ISRC6 interface ID.
Emits an OwnerAdded event.
assert_only_self(self: @ComponentState) internal
Validates that the caller is the account itself. Otherwise it reverts.
assert_valid_new_owner(self: @ComponentState, current_owner: EthPublicKey, new_owner: EthPublicKey, signature: Span<felt252>) internal
Validates that new_owner accepted the ownership of the contract through a signature.
Requirements:
- The signature must be valid for the
new_owner.
This function assumes that current_owner is the current owner of the contract, and does not validate this assumption.
validate_transaction(self: @ComponentState) → felt252 internal
Validates a transaction signature from the global context.
Returns the short string 'VALID' if valid, otherwise it reverts.
_set_public_key(ref self: ComponentState, new_public_key: EthPublicKey) internal
Set the public key without validating the caller.
Emits an OwnerAdded event.
The usage of this method outside the set_public_key function is discouraged.
_is_valid_signature(self: @ComponentState, hash: felt252, signature: Span<felt252>) → bool internal
Validates the provided signature for the hash, using the account’s current public key.
Events
The guid is computed as the hash of the public key, using the poseidon hash function.
OwnerAdded(new_owner_guid: felt252) event
Emitted when a public_key is added.
OwnerRemoved(removed_owner_guid: felt252) event
Emitted when a public_key is removed.
Extensions
SRC9Component
use openzeppelin_account::extensions::SRC9Component;OutsideExecution component implementing ISRC9_V2.
This component is signature-agnostic, meaning it can be integrated into any account contract, as long as the account implements the ISRC6 interface.
Embeddable Implementations
OutsideExecutionV2Impl
execute_from_outside_v2(self, outside_execution, signature)is_valid_outside_execution_nonce(self, nonce)
Internal Implementations
InternalImpl
Embeddable functions
execute_from_outside_v2(ref self: ContractState, outside_execution: OutsideExecution, signature: Span<felt252>) → Array<Span<felt252>> external
Allows anyone to submit a transaction on behalf of the account as long as they have the relevant signatures.
This method allows reentrancy. A call to __execute__ or execute_from_outside_v2 can trigger another nested transaction to execute_from_outside_v2. This implementation verifies that the provided signature matches the hash of outside_execution and that nonce was not already used.
Arguments:
outside_execution- The parameters of the transaction to execute.signature- A valid signature on the SNIP-12 message encoding ofoutside_execution.
Requirements:
- The caller must be the
outside_execution.callerunless 'ANY_CALLER' is used. - The current time must be within the
outside_execution.execute_afterandoutside_execution.execute_beforespan. - The
outside_execution.noncemust not be used before. - The
signaturemust be valid.
is_valid_outside_execution_nonce(self: @ContractState, nonce: felt252) → bool external
Returns the status of a given nonce. true if the nonce is available to use.
Internal functions
initializer(ref self: ComponentState) internal
Initializes the account by registering the ISRC9_V2 interface ID.
Presets
AccountUpgradeable
use openzeppelin_presets::AccountUpgradeable;Upgradeable account which can change its public key and declare, deploy, or call contracts. Supports outside execution by implementing SRC9.
0x002de258cce5b9e160bf83956b09f982059582469f7e6fad07b438128317d029
Constructor
Embedded Implementations
AccountComponent
SRC9Component
External Functions
Constructor
constructor(ref self: ContractState, public_key: felt252) constructor
Sets the account public_key and registers the interfaces the contract supports.
External functions
upgrade(ref self: ContractState, new_class_hash: ClassHash) external
Upgrades the contract to a new implementation given by new_class_hash.
Requirements:
- The caller is the account contract itself.
new_class_hashcannot be zero.
EthAccountUpgradeable
use openzeppelin_presets::EthAccountUpgradeable;Upgradeable account which can change its public key and declare, deploy, or call contracts, using Ethereum signing keys. Supports outside execution by implementing SRC9.
The EthPublicKey type is an alias for starknet::secp256k1::Secp256k1Point.
0x07f54a43da3f7beb5099c87f5627b7fba5f31c7a704cce57f8fb73287c1ea3be
Constructor
Embedded Implementations
EthAccountComponent
SRC9Component
External Functions
Constructor
constructor(ref self: ContractState, public_key: EthPublicKey) constructor
Sets the account public_key and registers the interfaces the contract supports.
External functions
upgrade(ref self: ContractState, new_class_hash: ClassHash) external
Upgrades the contract to a new implementation given by new_class_hash.
Requirements:
- The caller is the account contract itself.
new_class_hashcannot be zero.