Skip to content

Account

MarcoDotIO edited this page Apr 25, 2023 · 1 revision

Account

Aptos Blockchain Account

public struct Account: Equatable 

Inheritance

Equatable

Properties

accountAddress

The account address associated with the account

public let accountAddress: AccountAddress

privateKey

The private key for the account

public let privateKey: PrivateKey

Methods

generate()

Generate a new account instance with a random private key.

public static func generate() throws -> Account 

This function generates a new private key and derives the associated account address. A new account instance is created with the generated address and private key.

Throws

An error of type Error if there was a problem generating the private key or account address.

Returns

A new Account instance with a randomly generated private key and associated account address.

loadKey(_:)

Load an account from a private key in hex format.

public static func loadKey(_ key: String) throws -> Account 

This function takes a private key in hex format and attempts to load it into an account by creating a PrivateKey instance from the hex string and then deriving an AccountAddress from the public key. A new Account instance is created using the derived AccountAddress and the PrivateKey.

Parameters

  • key: A private key in hex format.

Throws

An error of type PrivateKeyError if the private key cannot be derived from the hex string, or AccountAddressError if the account address cannot be derived from the private key.

Returns

An Account instance containing the derived AccountAddress and PrivateKey.

load(_:)

Load an account from a JSON file.

public static func load(_ path: String) throws -> Account 

This function loads an account object from a JSON file by reading the file content from the provided path, deserializing the JSON data, retrieving the account_address and private_key keys, and then constructing and returning an account object from them.

Parameters

  • path: A string representing the path to the JSON file.

Throws

An error of type AptosError if the JSON file is invalid, if the account_address key is missing, or if the private_key key is missing.

Returns

An account object constructed from the account_address and private_key keys in the JSON file.

store(_:)

Store the account information to a file at the given path.

public func store(_ path: String) throws 

This function takes a path as a string and stores the account information in a JSON file with keys for the account address and the private key in hex format.

Parameters

  • path: A string representing the file path to store the account information.

Throws

An error of type AptosError if there is an issue writing to the file.

address()

Returns the account's account address.

public func address() -> AccountAddress 

Returns

An AccountAddress object

authKey()

Returns the hexadecimal representation of the authorization key for the account

public func authKey() throws -> String 

Returns

A String object

sign(_:)

Use the private key to sign the data inputted.

public func sign(_ data: Data) throws -> Signature 

Parameters

  • data: The data being serialized / signed

Returns

A Signature object

publicKey()

Returns the public key of the associated account

public func publicKey() throws -> PublicKey 

Returns

A PublicKey object

Operators

==

public static func == (lhs: Account, rhs: Account) -> Bool 
Types
Protocols
Global Variables
Global Functions
Extensions
Clone this wiki locally