@aptos-labs/ts-sdk - v8.0.0
    Preparing search index...

    Class SlhDsaSha2128sPrivateKey

    Represents a SLH-DSA-SHA2-128s private key, providing functionality to create, sign messages, derive public keys, and serialize/deserialize the key.

    PERFORMANCE: SLH-DSA is slow in pure JavaScript and every operation below runs synchronously on the calling thread. Rough single-core timings with @noble/post-quantum:

    • constructing, generate(), deserialize(): cheap; only the 48-byte seed is stored.
    • first publicKey() or sign(): ~0.5 s to derive PK.root (a full top-layer XMSS tree). The result is cached, so later calls skip it. Creating a SingleKeyAccount calls publicKey().
    • each sign(): ~3 s.
    • SlhDsaSha2128sPublicKey.verifySignature(): a few ms.

    In a browser or a latency-sensitive server, run signing in a Web Worker / worker_threads worker (pass the AIP-80 string or the 48 bytes from toUint8Array(), and send back signature.toUint8Array()) instead of on the main thread.

    Signing is deterministic (FIPS 205 opt_rand = PK.seed), matching the Aptos node and the other Aptos SDKs: the same key and message always produce the same signature.

    Hierarchy (View Summary)

    Implements

    Index
    • 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.

    LENGTH: number = 48

    Length of SLH-DSA-SHA2-128s private key (48 bytes: SK seed + PRF seed + PK seed)

    • Overwrites the 48-byte seed and the expanded 64-byte noble secret key with random bytes and then zeros. After calling this method the key can no longer sign, derive a public key, or be serialized.

      SECURITY: This is a best-effort window-narrowing tool, NOT a true zeroization guarantee. It has the same limits as Ed25519PrivateKey.clear(): strings already produced by toString() / toHexString() / toAIP80String(), intermediates inside @noble/post-quantum, JIT register/stack residue and GC-relocated copies cannot be reached from JavaScript and survive clear().

      Returns void

    • Sign the given message with the private key. This function generates a cryptographic signature for the provided message.

      Produces a FIPS 205 pure SLH-DSA-SHA2-128s signature with an empty context, using the deterministic variant (opt_rand = PK.seed) like the Aptos node and the other Aptos SDKs.

      PERFORMANCE: blocks the calling thread for ~3 s (plus ~0.5 s on the first call to derive PK.root). See the class documentation for running it in a worker.

      Parameters

      • message: HexInput

        A message in HexInput format to be signed.

      Returns SlhDsaSha2128sSignature

      Signature - The generated signature for the provided message.

      Error if the private key has been cleared from memory.

    • Redacted JSON representation, so JSON.stringify of this key (or of an account holding it) does not dump the secret seed bytes. Use toAIP80String() or bcsToBytes() to export the key deliberately.

      Returns string

    • Get the private key as a string representation.

      SECURITY: This returns the AIP-80 encoded private key, i.e. the secret itself, as an immutable JS string that clear() cannot zero. Avoid calling it on long-lived keys and never log it. JSON.stringify and Node's util.inspect (console.log) are redacted, but template literals and string concatenation call toString() and are not.

      Returns string

      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().

      Returns string

      string representation of the private key.

      Error if the private key has been cleared from memory.