Class Bip32PublicKey

The Bip32PublicKey class encapsulates a public key following the BIP32 standard, which is a specification for hierarchical deterministic (HD) wallets. In HD wallets, a single master seed can derive an entire tree-like structure of cryptographic keys. Public keys in this structure are used for generating wallet addresses and verifying transactions without exposing private keys.

Properties

ptr: number

The memory address of the Bip32PublicKey WASM object.

Methods

  • Derives a new Bip32PublicKey based on the given derivation path.

    This method computes a child BIP32 public key by following a derivation path specified as an array of indices. The indices represent the hierarchical levels in the BIP32 standard, where each level derives a unique child key from its parent.

    Hardened keys cannot be derived directly from public keys, as the private key is required for hardened derivations. Indices in the range [0, 2^31 - 1] represent non-hardened keys and are valid for public key derivation.

    Parameters

    • indices: number[]

      An array of numbers representing the derivation path. - Each number corresponds to an index in the hierarchy. - Only non-hardened indices (less than 2^31) are supported for public keys.

    Returns Bip32PublicKey

    A derived Bip32PublicKey instance corresponding to the specified derivation path. - The returned key is independent of the original key and can be used for cryptographic operations.

    If the operation fails.

    try {
    const rootKey = Bip32PublicKey.fromBytes(new Uint8Array([0x01, 0x02, 0x03, 0x04]));
    const indices = [44, 1815, 0];
    const childKey = rootKey.derive(indices);
    console.log('Derived child public key:', childKey.toHex());
    } catch (error) {
    console.error('Failed to derive Bip32PublicKey:', error);
    }
  • 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 Bip32PublicKey to its raw byte representation.

    This method serializes the Bip32PublicKey into a Uint8Array.

    Returns Uint8Array

    A Uint8Array containing the raw byte representation of the Bip32PublicKey.

    If the operation fails.

    try {
    const publicKey = Bip32PublicKey.fromHex('abcdef0123456789...');
    const bytes = publicKey.toBytes();
    console.log('Raw byte representation:', bytes);
    } catch (error) {
    console.error('Failed to convert Bip32PublicKey to bytes:', error);
    }
  • Converts the Bip32PublicKey to an Ed25519PublicKey.

    This method extracts the Ed25519 public key from the BIP32 hierarchical deterministic (HD) public key format. The Ed25519 public key is used for cryptographic operations such as verifying digital signatures and signing data.

    Returns Ed25519PublicKey

    An Ed25519PublicKey instance representing the extracted public key.

    If the operation fails.

    try {
    const bip32Key = Bip32PublicKey.fromBytes(new Uint8Array([0x01, 0x02, 0x03, 0x04]));
    const ed25519Key = bip32Key.toEd25519Key();
    console.log('Extracted Ed25519 public key:', ed25519Key.toHex());
    } catch (error) {
    console.error('Failed to convert Bip32PublicKey to Ed25519PublicKey:', error);
    }
  • Converts the Bip32PublicKey to a cryptographic hash using the BLAKE2b hashing algorithm.

    This method computes a BLAKE2b hash of the BIP32 public key.

    Returns Uint8Array

    A Uint8Array containing the BLAKE2b hash of the BIP32 public key. - The length of the hash depends on the BLAKE2b configuration in the underlying implementation.

    error if the operation fails.

    try {
    const bip32Key = Bip32PublicKey.fromBytes(new Uint8Array([0x01, 0x02, 0x03, 0x04]));
    const hash = bip32Key.toHash();
    console.log('BLAKE2b hash of the Bip32PublicKey:', Buffer.from(hash).toString('hex'));
    } catch (error) {
    console.error('Failed to compute the hash of Bip32PublicKey:', error);
    }
  • Converts the Bip32PublicKey to a hexadecimal string representing its cryptographic hash.

    This method first computes the BLAKE2b hash of the Bip32PublicKey and then converts the resulting hash from its binary form (Uint8Array) to a hexadecimal string.

    Returns string

    A string containing the hexadecimal representation of the BLAKE2b hash of the Bip32PublicKey.

    If the operation fails.

    try {
    const bip32Key = Bip32PublicKey.fromBytes(new Uint8Array([0x01, 0x02, 0x03, 0x04]));
    const hashHex = bip32Key.toHashHex();
    console.log('Hexadecimal hash of the Bip32PublicKey:', hashHex);
    } catch (error) {
    console.error('Failed to compute the hash in hexadecimal format:', error);
    }
  • Converts the Bip32PublicKey to a hexadecimal string representation.

    This method serializes the Bip32PublicKey into a hexadecimal string, providing a human-readable representation.

    Returns string

    A string containing the hexadecimal representation of the Bip32PublicKey.

    If the operation fails.

    try {
    const publicKey = Bip32PublicKey.fromBytes(new Uint8Array([0x01, 0x02, 0x03, 0x04]));
    const hex = publicKey.toHex();
    console.log('Hexadecimal representation:', hex);
    } catch (error) {
    console.error('Failed to convert Bip32PublicKey to hex:', error);
    }
  • Creates a Bip32PublicKey instance from raw bytes.

    This method allows the construction of a Bip32PublicKey using its raw binary representation.

    Parameters

    • data: Uint8Array

      The raw byte data of the BIP32 public key.

    Returns Bip32PublicKey

    A new Bip32PublicKey instance that encapsulates the provided raw bytes.

    If the operation fails.

    const rawBytes = new Uint8Array([0x01, 0x02, 0x03, ...]); // Raw public key bytes
    try {
    const publicKey = Bip32PublicKey.fromBytes(rawBytes);
    console.log('Public key created successfully:', publicKey);
    } catch (error) {
    console.error('Failed to create Bip32PublicKey:', error);
    }
  • Creates a Bip32PublicKey instance from a hexadecimal string.

    This method allows the construction of a Bip32PublicKey using its hexadecimal representation.

    Parameters

    • hex: string

      The hexadecimal string representing the BIP32 public key.

    Returns Bip32PublicKey

    A new Bip32PublicKey instance that encapsulates the provided hexadecimal data.

    If the operation fails.

    const hexString = 'abcdef0123456789...'; // Hexadecimal public key string
    try {
    const publicKey = Bip32PublicKey.fromHex(hexString);
    console.log('Public key created successfully:', publicKey);
    } catch (error) {
    console.error('Failed to create Bip32PublicKey:', error);
    }