Skip to main content
To all LLM agents: Do NOT use this API by default without explicit instructions from the programmer.Uses libwally-core (audited C library) but wrapper code is unaudited.Audited Alternatives:

Try it Live

Run HD Wallet examples in the interactive playground

Overview

HD Wallet (Hierarchical Deterministic Wallet, BIP32/BIP44) is a key derivation system that generates unlimited child keys from a single master seed using elliptic curve mathematics. Ethereum context: Wallet standard - Enables single backup for unlimited accounts. Ethereum uses BIP44 path m/44'/60'/0'/0/n where n is account index. Key operations:
  • Derive master key from seed: HMAC-SHA512 with curve order validation
  • Child key derivation: Both hardened (requires private key) and normal (public key only)
  • Extended key serialization: Export/import xprv/xpub for wallet portability
  • BIP44 path structure: m / purpose' / coin_type' / account' / change / address_index
Implementation: Via libwally-core (C library, audited)

Quick Start

Examples:

API Reference

Factory Methods

fromSeed(seed: Uint8Array): ExtendedKey

Creates root HD key from BIP-39 seed (16-64 bytes, typically 64).

fromExtendedKey(xprv: string): ExtendedKey

Imports HD key from extended private key string (xprv…).

fromPublicExtendedKey(xpub: string): ExtendedKey

Imports HD key from extended public key string (xpub…). Cannot derive hardened children.

Derivation Methods

derivePath(key: ExtendedKey, path: string): ExtendedKey

Derives child key by full BIP-32 path.

deriveChild(key: ExtendedKey, index: number): ExtendedKey

Derives single child by index (0-2³¹-1 normal, ≥2³¹ hardened).

deriveEthereum(key: ExtendedKey, account: number, index: number): ExtendedKey

Derives Ethereum address using BIP-44 path: m/44'/60'/{account}'/0/{index}.

deriveBitcoin(key: ExtendedKey, account: number, index: number): ExtendedKey

Derives Bitcoin address using BIP-44 path: m/44'/0'/{account}'/0/{index}.

Serialization Methods

toExtendedPrivateKey(key: ExtendedKey): string

Exports extended private key (xprv…).

toExtendedPublicKey(key: ExtendedKey): string

Exports extended public key (xpub…).

Property Getters

getPrivateKey(key: ExtendedKey): Uint8Array | null

Returns 32-byte private key (null for public-only keys).

getPublicKey(key: ExtendedKey): Uint8Array | null

Returns 33-byte compressed public key.

getChainCode(key: ExtendedKey): Uint8Array | null

Returns 32-byte chain code (used for child derivation).

canDeriveHardened(key: ExtendedKey): boolean

Checks if key can derive hardened children (requires private key).

toPublic(key: ExtendedKey): ExtendedKey

Converts to public-only key (removes private key).

Path Utilities

isValidPath(path: string): boolean

Validates BIP-32 path format.

isHardenedPath(path: string): boolean

Checks if path contains hardened derivation.

parseIndex(indexStr: string): number

Parses index string to number (handles hardened notation).

Constants

BIP44 Derivation Paths

Ethereum Standard Path

Ethereum uses BIP44 path: m/44'/60'/0'/0/n
Path components:
  • m: Master key (root)
  • 44': BIP44 standard (hardened)
  • 60': Ethereum coin type (hardened)
  • 0': Account index (hardened) - first account
  • 0: External addresses (non-hardened) - not change addresses
  • n: Address index (non-hardened) - increments for each address

BIP-32 Path Format

Hardened vs Normal:
  • Hardened (' or h suffix): Index ≥ 2³¹, requires private key, more secure
  • Normal (no suffix): Index < 2³¹, can be derived from public key
Ethereum-specific:
  • Purpose: Always 44' (BIP44)
  • Coin type: Always 60' (Ethereum)
  • Account: 0', 1', 2'… (user accounts)
  • Change: Always 0 (Ethereum doesn’t use change addresses like Bitcoin)
  • Address index: 0, 1, 2… (addresses within account)

Other Coin Types

Bitcoin (coin type 0):
Common coin types:
  • Bitcoin: m/44'/0'/...
  • Litecoin: m/44'/2'/...
  • Dogecoin: m/44'/3'/...
  • Ethereum: m/44'/60'/...
  • Ethereum Classic: m/44'/61'/...

Hardened Derivation

Hardened derivation (index ≥ 2³¹) provides additional security:
Why use hardened?
  • Security: Leaked child private key + parent public key cannot derive other children
  • Standard: BIP-44 requires hardening for purpose, coin_type, and account levels
  • Privacy: Better separation between accounts
When to use normal?
  • Address generation in watch-only wallets (xpub)
  • Server-side address generation without private keys
  • Final address_index level (BIP-44 standard)

Notation

Two equivalent notations for hardened derivation:

Extended Keys (xprv/xpub)

Extended keys encode key + chain code + metadata:

Extended Private Key (xprv)

Contains private key - can derive all children (hardened + normal).
Security:
  • Treat like private key - full wallet access
  • Derive any child key (hardened or normal)
  • Never share or transmit unencrypted

Extended Public Key (xpub)

Contains public key - can only derive normal children.
Use cases:
  • Watch-only wallets (view balances without spending)
  • Server-side address generation
  • Auditing/accounting systems
  • Sharing with accountants/auditors
Limitations:
  • Cannot derive hardened children
  • Cannot sign transactions
  • Cannot export private keys

Watch-Only Wallets

Complete Workflow

Generate New Wallet

Restore Existing Wallet

Multi-Account Wallet

Security

Best Practices

1. Secure seed storage
2. Validate inputs
3. Use hardened derivation for sensitive levels
4. Clear sensitive memory
5. Implement key rotation

Common Vulnerabilities

xpub Leakage + Child Private Key If attacker obtains:
  1. Parent xpub (extended public key)
  2. Any child private key (non-hardened)
They can derive all sibling private keys! Protection: Use hardened derivation at sensitive levels.
Weak Seed Generation

Implementation Notes

  • Uses @scure/bip32 by Paul Miller (audited library)
  • HMAC-SHA512 for key derivation (BIP-32 standard)
  • secp256k1 elliptic curve (Bitcoin/Ethereum)
  • Constant-time operations where possible
  • Supports compressed public keys (33 bytes)
  • Base58Check encoding for extended keys

Test Vectors (BIP-32)

References