Class PrivateKey

A class representing a private key.

Remarks

The private key is used to sign operations during interactions with the blockchain.

Constructors

Properties

bytes: Uint8Array
hasher: default
prefix: string = PRIVATE_KEY_PREFIX
serializer: default
signer: default
version: Version
versioner: Versioner

Methods

  • Signs the message with the private key.

    Parameters

    • message: Uint8Array

      The byte array to sign.

    Returns Promise<Signature>

    The signature byte array.

    Remarks

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

  • Serializes the private key to a string.

    Returns string

    The serialized private key string.

    Remarks

    A private key is serialized as follows:

    • The version is serialized as a varint and prepended to the private key bytes.
    • The result is then sent to the serializer.
  • Initializes a new private key object from the environment variables.

    Parameters

    • key: string = 'PRIVATE_KEY'

      The environment variable name containing the private key.

    Returns PrivateKey

    A new private key instance.

    Remarks

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

  • Initializes a new private key object from a serialized string.

    Parameters

    • str: string

      The serialized private key string.

    Returns PrivateKey

    A new private key instance.

    Throws

    If the private key prefix is invalid.

  • Initializes a random private key.

    Parameters

    • Optional version: Version

      The version of the private key. If not defined, the last version will be used.

    Returns PrivateKey

    A new private key instance.

  • Initializes a new private key object from a version.

    Parameters

    • version: Version = Version.V0

      The version of the private key. If not defined, the last version will be used.

    Returns PrivateKey

    A new private key instance.