Class SoftwareBip32SecureKeyHandler

A software-based implementation of a secure key handler for BIP32 hierarchical deterministic keys.

This class securely manages a root key by encrypting it with a passphrase. The passphrase is provided on-demand via an asynchronous callback, and the decrypted key material only exists in memory for the brief moment it's needed for an operation, after which it is securely wiped.

Implements

Methods

  • Serializes the encrypted key data for secure storage into a binary format.

    The binary format is: [ 4-byte magic | 1-byte version | 1-byte type | 4-byte data_len | data | 4-byte crc32 checksum ]

    Returns Promise<Uint8Array>

    A promise that resolves with the serialized and encrypted key data.

  • Signs arbitrary data using a BIP32-derived key.

    Parameters

    • data: string

      The hex-encoded data to be signed.

    • path: DerivationPath

      The derivation path specifying which key to use for signing.

    Returns Promise<{ key: string; signature: string }>

    A promise that resolves with an object containing the signature and the public key.

  • Deserializes an encrypted key handler from a byte array.

    The binary format is: [ 4-byte magic | 1-byte version | 1-byte type | 4-byte data_len | data | 4-byte crc32 checksum ]

    Parameters

    • data: Uint8Array

      The serialized and encrypted key data.

    • getPassphrase: () => Promise<Uint8Array>

      An async function called when the passphrase is needed.

    Returns Bip32SecureKeyHandler

    A new instance of the key handler.

  • Creates a new BIP32-based key handler from entropy and a passphrase.

    Parameters

    • entropy: Uint8Array

      The entropy bytes for the root key.

    • passphrase: Uint8Array

      The passphrase to initially encrypt the key.

    • getPassphrase: () => Promise<Uint8Array>

      An async function that will be called whenever the passphrase is needed for cryptographic operations.

    Returns Bip32SecureKeyHandler

    A new instance of the key handler.

    For security, this function will zero out the entropy and passphrase Uint8Array buffers after they are used. Do not reuse them.