Class Account

A class representing an account.

Constructors

Properties

address: Address
privateKey: PrivateKey
publicKey: PublicKey
sealer: default
version: Version

Methods

  • Signs a message.

    Parameters

    • message: Uint8Array

      The byte array to sign.

    Returns Promise<Signature>

    A signature object.

    Remarks

    This function signs a byte-encoded message with the account private key. The message is first hashed and then signed. Do not pass a digest to this function as it will be hashed twice.

  • Encodes the account to a serializable object.

    Parameters

    • Optional password: string

      The password to encrypt the private key.

    • Optional salt: Uint8Array

      The salt to use for the encryption. If not provided, a random salt will be generated.

    • Optional nonce: Uint8Array

      The nonce to use for the encryption. If not provided, a random nonce will be generated.

    Returns Promise<AccountKeyStore>

    A serializable object.

    Remarks

    The serializable object can be serialized to any format (JSON, YAML, XML, etc.) on any support (file, database, browser storage, etc.). The keystore format is defined in the Massa standard format document: Massa Standard Format

    Throws

    If the password is not provided for V0 and V1 keystores.

    Throws

    If the version is not supported.

  • Verifies a message signature.

    Parameters

    • message: Uint8Array

      The byte array that was signed.

    • signature: Signature

      The signature to verify.

    Returns Promise<boolean>

    A boolean indicating whether the signature is valid.

    Remarks

    This function verifies a byte-encoded message signature using the account's public key. The message is first hashed and then the signature is verified against the hashed message. Do not pass a digest to this function as it will be hashed twice.

  • Uses the environment variables to create an account.

    Parameters

    • Optional key: string

      The environment variable key containing the private key.

    Returns Promise<Account>

    An account instance.

    Remarks

    The PRIVATE_KEY or the provided key is required in the environment variables.

  • Decodes the account from a serializable object.

    Parameters

    • keystore: AccountKeyStore

      The serializable object to decode.

    • Optional password: string

      The password to decrypt the private key.

    Returns Promise<Account>

    A new Account instance.

    Remarks

    The serializable object can be serialized to any format (JSON, YAML, XML, etc.) on any support (file, database, browser storage, etc.). The keystore format is defined in the Massa standard format document: Massa Standard Format

    Throws

    If the password is not provided for V0 and V1 keystores.

    Throws

    If the version is not supported.

  • Initializes a new account object from a private key.

    Parameters

    • key: string | PrivateKey

      The private key of the account.

    • version: Version = Version.V1

      The version of the account.

    Returns Promise<Account>

    A new instance of the Account class.

  • Generates a new account object.

    Parameters

    • Optional version: Version

      The version of the account.

    Returns Promise<Account>

    A new instance of the Account class.