- Resource
Account
- Resource
ResourceAccount
- Struct
SignerCapability
- Constants
- Function
create_account_entry
- Function
create_account
- Function
create_framework_reserved_account
- Function
sequence_number
- Function
sequence_number_for_sender
- Function
increment_sequence_number
- Function
signer_address
- Function
is_resource_account
- Function
exists_at
- Function
create_signer
- Function
create_resource_account
- Function
create_resource_address
- Function
create_signer_with_capability
- Function
get_signer_capability_address
use 0x1::hash;
use 0x1::signer;
use 0x1::vector;
use 0x2::bcs;
use 0x2::context;
use 0x3::account_authentication;
use 0x3::account_coin_store;
Resource representing an account.
struct Account has store, key
ResourceAccount can only be stored under address, not in other structs.
struct ResourceAccount has key
SignerCapability can only be stored in other structs, not under address. So that the capability is always controlled by contracts, not by some EOA.
struct SignerCapability has store
const MAX_U64: u128 = 18446744073709551615;
const CONTRACT_ACCOUNT_AUTH_KEY_PLACEHOLDER: vector<u8> = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
Account already exists
const ErrorAccountAlreadyExists: u64 = 1;
Resource Account can't derive resource account
const ErrorAccountIsAlreadyResourceAccount: u64 = 7;
Account does not exist
const ErrorAccountNotExist: u64 = 2;
Cannot create account because address is reserved
const ErrorAddressReseved: u64 = 5;
Address to create is not a valid reserved address for Rooch framework
const ErrorNotValidFrameworkReservedAddress: u64 = 11;
An attempt to create a resource account on an account that has a committed transaction
const ErrorResourceAccountAlreadyUsed: u64 = 6;
Sequence number exceeds the maximum value for a u64
const ErrorSequenceNumberTooBig: u64 = 3;
Scheme identifier used when hashing an account's address together with a seed to derive the address (not the authentication key) of a resource account. This is an abuse of the notion of a scheme identifier which, for now, serves to domain separate hashes used to derive resource account addresses from hashes used to derive authentication keys. Without such separation, an adversary could create (and get a signer for) a resource account whose address matches an existing address of a MultiEd25519 wallet.
const SCHEME_DERIVE_RESOURCE_ACCOUNT: u8 = 255;
const ZERO_AUTH_KEY: vector<u8> = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
A entry function to create an account under new_address
public entry fun create_account_entry(ctx: &mut context::Context, new_address: address)
Publishes a new Account
resource under new_address
. A signer representing new_address
is returned. This way, the caller of this function can publish additional resources under
new_address
.
public(friend) fun create_account(ctx: &mut context::Context, new_address: address): signer
create the account for system reserved addresses
public(friend) fun create_framework_reserved_account(ctx: &mut context::Context, addr: address): (signer, account::SignerCapability)
Return the current sequence number at addr
public fun sequence_number(ctx: &context::Context, addr: address): u64
public fun sequence_number_for_sender(ctx: &context::Context): u64
public(friend) fun increment_sequence_number(ctx: &mut context::Context)
public fun signer_address(cap: &account::SignerCapability): address
public fun is_resource_account(ctx: &context::Context, addr: address): bool
public fun exists_at(ctx: &context::Context, addr: address): bool
public(friend) fun create_signer(addr: address): signer
A resource account is used to manage resources independent of an account managed by a user. In Rooch a resource account is created based upon the sha3 256 of the source's address and additional seed data. A resource account can only be created once
public fun create_resource_account(ctx: &mut context::Context, source: &signer): (signer, account::SignerCapability)
This is a helper function to compute resource addresses. Computation of the address involves the use of a cryptographic hash operation and should be use thoughtfully.
public fun create_resource_address(source: &address, seed: vector<u8>): address
public fun create_signer_with_capability(capability: &account::SignerCapability): signer
public fun get_signer_capability_address(capability: &account::SignerCapability): address