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

    Class Ed25519PrivateKey

    Represents the private key of an Ed25519 key pair.

    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 an Ed25519 private key

    SLIP_0010_SEED: "ed25519 seed"

    The Ed25519 key seed to use for BIP-32 compatibility See more https://github.com/satoshilabs/slips/blob/master/slip-0010.md

    • Overwrites the underlying private-key byte buffer with random bytes and then zeros. After calling this method the key can no longer sign or derive a public key.

      SECURITY: This is a best-effort window-narrowing tool, NOT a true zeroization guarantee. In JavaScript, four classes of copies cannot be reached from user code and so survive clear():

      1. JS string copies. Any value previously produced by toString(), toHexString(), or bcsToHex().toString() is an immutable string in the heap. The language provides no API to overwrite string memory; it is reclaimed only when GC collects it.
      2. noble-curves internals. The sign path inside @noble/curves expands the private key into scalar BigInt field elements, which are also immutable in V8/JSC/Hermes. Even if noble explicitly zeroed its own byte copies after use, the BigInt intermediates persist.
      3. JIT register / stack residue. The engine may have held key bytes in CPU registers or on the engine stack during a sign call. There is no JS-visible way to scrub those.
      4. GC-relocated copies. Generational GCs (V8, JSC) copy live objects between heap regions during minor/major collections. The Uint8Array we zeroed may have stale copies sitting in survivor space until the next cycle reclaims them.

      This method zeros the SDK's own Uint8Array (the most reachable copy), but downstream consumers should treat it as a hardening signal, not a guarantee. If you need real key-material hygiene, prefer non-extractable crypto.subtle keys (where the underlying algorithm is supported by the host runtime), a WASM-backed crypto library, or hardware-backed keys (passkeys / secure enclave / HSM).

      To minimize the size of the unreachable-copy set, avoid calling toString() / toHexString() on private keys at all in long-lived processes — the byte form is what gets cleared.

      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 digital signature for the specified message, ensuring its authenticity and integrity.

      Parameters

      • message: HexInput

        A message as a string or Uint8Array in HexInput format.

      Returns Ed25519Signature

      A digital signature for the provided message.

      The polymorphic message: HexInput input is ambiguous — a bare even-length string of hex characters (e.g., "cafe") is signed as the 2 bytes [0xCA, 0xFE], not as 4 UTF-8 text bytes. Use signBytes for Uint8Array input or signText for string input; both are unambiguous. See convertSigningMessage for the full legacy rule.

      Error if the private key has been cleared from memory.

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

      SECURITY: This produces an immutable JS string containing the key material in hex. Strings cannot be zeroed by clear() (see the clear() JSDoc for the four classes of unreachable copies). Avoid calling this method on long-lived Ed25519PrivateKey instances in processes where memory hygiene matters; prefer toUint8Array(), which returns a clearable Uint8Array.

      Returns string

      string representation of the private key.

      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. To derive multiple keys from the same phrase, change the path

      IMPORTANT: Ed25519 supports hardened derivation only, as it lacks a key homomorphism, making non-hardened derivation impossible.

      Parameters

      • path: string

        The BIP44 path used for key derivation.

      • mnemonics: string

        The mnemonic seed phrase from which the key will be derived.

      Returns Ed25519PrivateKey

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

    Methods

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

      Read about AIP-80

      SECURITY: Same caveat as toString() — produces an immutable JS string containing the key material; cannot be zeroed by clear().

      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.

      SECURITY: Same caveat as toString() — the returned string is an immutable JS heap allocation that clear() cannot zero.

      Returns string

      string representation of the private key.

      Error if the private key has been cleared from memory.