Class Bip32PrivateKey

Represents a BIP32 hierarchical deterministic (HD) private key.

The Bip32PrivateKey class encapsulates private key operations under the BIP32 standard. BIP32 defines a standard for HD wallets, enabling the derivation of an extensive tree of private keys from a single seed. These private keys can be used to generate public keys, derive addresses, and sign transactions within the Cardano ecosystem.

Properties

ptr: number

The memory address of the Bip32PrivateKey WASM object.

Methods

  • Derives a child BIP32 private key using a specified derivation path.

    This method computes a child private key by following a derivation path represented by an array of indices. Indices >= 2^31 represent hardened keys, which cannot be derived from public keys.

    Parameters

    • indices: number[]

      An array of indices specifying the derivation path.

    Returns Bip32PrivateKey

    A new Bip32PrivateKey instance for the derived key.

    If the operation fails.

    const parentKey = Bip32PrivateKey.fromHex('abcdef...');
    const childKey = parentKey.derive([44, 1815, 0]);
  • Derives the public key corresponding to this private key.

    This method extracts the public key associated with the current private key. The resulting Bip32PublicKey can be used for address generation, signature verification, and other operations that do not require private key access.

    Returns Bip32PublicKey

    A Bip32PublicKey instance corresponding to the derived public key.

    If the operation fails.

    const privateKey = Bip32PrivateKey.fromHex('abcdef...');
    const publicKey = privateKey.getPublicKey();
    console.log('Derived public key:', publicKey.toHex());
  • The reference count retrieved by this method reflects the number of references maintained internally by libcardano-c for this native instance of the object. This is unrelated to the reference counting mechanism in JavaScript, which is managed by the JavaScript engine's garbage collector.

    This method is primarily intended for diagnostic purposes.

    Returns number

    The current reference count of the object in the WASM context.

  • Converts the BIP32 private key to its raw byte representation.

    This method serializes the private key into a Uint8Array, which is the raw binary format.

    Returns Uint8Array

    A Uint8Array containing the raw byte representation of the private key.

    If the operation fails.

    const privateKey = Bip32PrivateKey.fromHex('abcdef...');
    const rawBytes = privateKey.toBytes();
    console.log('Private key raw bytes:', rawBytes);
  • Converts the BIP32 private key to an Ed25519 private key.

    This method transforms the hierarchical deterministic (HD) private key into an Ed25519 private key. The resulting key can be used in cryptographic operations such as signing.

    Returns Ed25519PrivateKey

    An instance of Ed25519PrivateKey.

    If the conversion fails.

    const privateKey = Bip32PrivateKey.fromBytes(new Uint8Array([0x01, 0x02, ...]));
    const ed25519Key = privateKey.toEd25519();
    console.log('Derived Ed25519 private key:', ed25519Key.toHex());
  • Converts the BIP32 private key to a hexadecimal string.

    This method serializes the private key into a hexadecimal string, providing a human-readable format.

    Returns string

    A string containing the hexadecimal representation of the private key.

    If the operation fails.

    const privateKey = Bip32PrivateKey.fromBytes(new Uint8Array([0x01, 0x02, ...]));
    const hex = privateKey.toHex();
    console.log('Private key in hexadecimal:', hex);
  • Creates a BIP32 private key from BIP39 entropy.

    This method initializes a BIP32 private key using entropy derived from a BIP39 mnemonic. A password can also be provided to enhance security.

    Parameters

    • password: Uint8Array

      The password or passphrase as a Uint8Array.

    • entropy: Uint8Array

      The entropy derived from a BIP39 mnemonic as a Uint8Array.

    Returns Bip32PrivateKey

    A new Bip32PrivateKey instance.

    If the operation fails.

    const password = new TextEncoder().encode("my-secure-password");
    const entropy = new Uint8Array([0x01, 0x02, 0x03, ...]);
    const privateKey = Bip32PrivateKey.fromBip39Entropy(password, entropy);
  • Creates a BIP32 private key from raw bytes.

    This method allows for constructing a Bip32PrivateKey directly from its raw binary representation.

    Parameters

    • data: Uint8Array

      The raw byte data of the private key as a Uint8Array.

    Returns Bip32PrivateKey

    A new Bip32PrivateKey instance.

    If the operation fails.

    const bytes = new Uint8Array([0x01, 0x02, 0x03, ...]);
    const privateKey = Bip32PrivateKey.fromBytes(bytes);
  • Creates a BIP32 private key from a hexadecimal string.

    This method initializes a Bip32PrivateKey using its hexadecimal representation.

    Parameters

    • hex: string

      A hexadecimal string representing the private key.

    Returns Bip32PrivateKey

    A new Bip32PrivateKey instance.

    If the operation fails.

    const hex = 'abcdef0123456789...';
    const privateKey = Bip32PrivateKey.fromHex(hex);