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

    Class Secp256r1PrivateKey

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

    Hierarchy (View Summary)

    Index

    Implementation - Serialization

    LENGTH: number = 32

    Length of Secp256r1 ecdsa private key

    • 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. See Ed25519PrivateKey.clear() for the full enumeration of JavaScript-level limits (immutable string copies, noble BigInt intermediates, JIT register/stack residue, GC-relocated copies). For Secp256r1 specifically, non-extractable crypto.subtle P-256 keys are universally supported across modern runtimes and are the architecturally-correct path for callers who need real memory hygiene; consider that alternative for new code.

      Returns void

    • Serializes the data into a byte array using the provided serializer. This function is essential for converting data into a format suitable for transmission or storage.

      Parameters

      • serializer: Serializer

        The serializer instance used to convert the data.

      Returns void

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

      Parameters

      • message: HexInput

        A message in HexInput format to be signed.

      Returns Secp256r1Signature

      Signature - The generated 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 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.

    • Sign exactly the bytes of message. The input is interpreted as raw bytes regardless of what they encode. Pair with Secp256r1PublicKey.verifyBytes.

      The message is SHA3-256 hashed before signing (matching the Aptos-side Secp256r1 signing convention).

      Parameters

      • message: Uint8Array

        The exact bytes to sign.

      Returns Secp256r1Signature

      The generated signature for the provided bytes.

      Error if the private key has been cleared from memory.

    • Get the private key as a string representation.

      SECURITY: This produces an immutable JS string containing the key material. Strings cannot be zeroed by clear() (see the clear() JSDoc for the four classes of unreachable copies). Avoid calling this method on long-lived Secp256r1PrivateKey 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.

    Methods

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

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

      Returns string

      string representation of the private key.

      Error if the private key has been cleared from memory.

    Properties

    AIP80_PREFIXES: { ed25519: string; secp256k1: string; secp256r1: string } = ...

    The AIP-80 compliant prefixes for each private key type. Append this to a private key's hex representation to get an AIP-80 compliant string.

    Read about AIP-80