@aptos-labs/ts-sdk - v6.1.0
    Preparing search index...

    Class Secp256k1PrivateKey

    Represents a Secp256k1 ECDSA private key, providing functionality to create, sign messages, derive public keys, and serialize/deserialize the key.

    Hierarchy (View Summary)

    Implements

    Index

    Implementation - BCS

    • Serializes a Serializable value to its BCS representation. This function is the TypeScript SDK equivalent of bcs::to_bytes in Move.

      Returns Uint8Array

      the BCS representation of the Serializable instance as a byte buffer.

    • Converts the BCS-serialized bytes of a value into a Hex instance. This function provides a Hex representation of the BCS-serialized data for easier handling and manipulation.

      Returns Hex

      A Hex instance with the BCS-serialized bytes loaded into its underlying Uint8Array.

    Implementation - Serialization

    LENGTH: number = 32

    Length of Secp256k1 ecdsa private key

    • Clears the private key from memory by overwriting it with random bytes. After calling this method, the private key can no longer be used for signing or deriving public keys.

      Note: Due to JavaScript's memory management, this cannot guarantee complete removal of sensitive data from memory, but it significantly reduces the window of exposure.

      Returns void

    • Returns whether the private key has been cleared from memory.

      Returns boolean

      true if the key has been cleared, false otherwise

    • Sign the given message with the private key. This function generates a cryptographic signature for the provided message, ensuring the signature is canonical and non-malleable.

      Parameters

      • message: HexInput

        A message in HexInput format to be signed.

      Returns Secp256k1Signature

      Signature - The generated signature for the provided message.

      Error if the private key has been cleared from memory.

    • Get the private key in bytes (Uint8Array).

      Returns Uint8Array

      Uint8Array representation of the private key

      Error if the private key has been cleared from memory.

    • Derives a private key from a mnemonic seed phrase using a specified BIP44 path.

      Parameters

      • path: string

        The BIP44 path to derive the key from.

      • mnemonics: string

        The mnemonic seed phrase used for key generation.

      Returns Secp256k1PrivateKey

      The generated private key.

      Error if the provided path is not a valid BIP44 path.

    Methods

    • Get the private key as a AIP-80 compliant hex string.

      Read about AIP-80

      Returns string

      AIP-80 compliant string representation of the private key.

      Error if the private key has been cleared from memory.

    • Get the private key as a hex string with the 0x prefix.

      Returns string

      string representation of the private key.

      Error if the private key has been cleared from memory.