Class SoftwareEd25519SecureKeyHandler

A software-based implementation of a secure key handler for single Ed25519 keys.

This class securely manages a single private 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 the securely stored Ed25519 private key.

    Parameters

    • data: string

      The hex-encoded data to be signed.

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

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

  • Deserializes an encrypted Ed25519 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 Ed25519SecureKeyHandler

    A new instance of the key handler.

  • Creates a new Ed25519-based key handler from a raw private key and a passphrase.

    Parameters

    • privateKey: Ed25519PrivateKey

      The raw Ed25519 private key.

    • passphrase: Uint8Array

      The passphrase to initially encrypt the key.

    • getPassphrase: () => Promise<Uint8Array>

      An async function called when the passphrase is needed for cryptographic operations.

    Returns Promise<Ed25519SecureKeyHandler>

    A new instance of the key handler.

    For security, this function will zero out the passphrase Uint8Array buffer after it is used. Do not reuse it.