Introduction
Extended keys are fundamental components in Hierarchical Deterministic (HD) wallets, enabling the derivation of child keys from a single seed. This guide explores how extended private and public keys work, their structure, and their role in secure key management.
1. Master Key Generation
Your initial extended key (or "master key") is created by processing a 64-byte seed through the HMAC-SHA512 hash function.
Key Components:
- Private Key: The first 32 bytes of the HMAC-SHA512 output.
- Chain Code: The remaining 32 bytes, providing additional entropy for child key derivation.
🔍 Note: The HMAC key uses the string "Bitcoin seed" for master key generation, ensuring a standardized process.
Extended Private Key
An extended private key combines a standard private key with its chain code (64 bytes total).
Extended Public Key
Derived by converting the private key to a public key (via elliptic curve multiplication) and pairing it with the same chain code.
2. Hierarchical Key Trees
Extended keys can derive child keys recursively:
- Extended Private Keys: Generate both child private and public keys.
- Extended Public Keys: Only generate child public keys (useful for watch-only wallets).
Child Key Types:
Normal Child Keys:
- Index range:
0to2147483647. - Both private and public keys can derive identical child public keys.
- Index range:
Hardened Child Keys:
- Index range:
2147483648to4294967295. - Only the extended private key can derive them, enhancing security.
- Index range:
⚠️ Security Tip: Exposing a child private key from a normal derivation path compromises the parent private key!
3. Child Key Derivation Methods
Normal Child Extended Private Key
Inputs:
- Data: Parent public key + index (concatenated).
- Key: Parent chain code.
Outputs:
- New private key = Parent private key + HMAC first 32 bytes (modulo curve order).
- New chain code = HMAC last 32 bytes.
Hardened Child Extended Private Key
Inputs:
- Data: Parent private key + index (concatenated).
- Key: Parent chain code.
Outputs:
- Same as normal, but uses the parent private key for HMAC input.
Normal Child Extended Public Key
- Same HMAC inputs as normal private derivation.
- New public key = Parent public key + (HMAC first 32 bytes × generator point).
4. Serialization
Extended keys are serialized for storage/transfer with metadata:
| Field | Description | Example |
|----------------|----------------------------------------------|----------------------------------|
| Version | xprv (private) or xpub (public) | 0488ade4 / 0488b21e |
| Depth | Derivation level from master key | 0 for master |
| Fingerprint| First 4 bytes of parent public key’s hash160 | Used to identify parent |
| Index | Child number (0–4,294,967,295) | 0 for master |
| Chain Code | 32-byte entropy | Required for child derivation |
| Key | 33-byte public key or prefixed private key | 0x00 + private key (32 bytes) |
Example serialized keys:
- xprv:
xprv9tuogRdb5YTgcL3P8Waj7REqDuQx4sXcodQaWTtEVFEp6yRKh1CjrWfXChnhgHeLDuXxo2auDZegMiVMGGxwxcrb2PmiGyCngLxvLeGsZRq - xpub:
xpub67uA5wAUuv1ypp7rEY7jUZBZmwFSULFUArLBJrHr3amnymkUEYWzQJz13zLacZv33sSuxKVmerpZeFExapBNt8HpAqtTtWqDQRAgyqSKUHu
5. FAQs
Q1: Why use hardened derivation?
A: Hardened keys prevent child private key exposure from compromising the parent key. Recommended for default use unless watch-only functionality is needed.
Q2: Can I derive hardened keys from an extended public key?
A: No. Only the extended private key can derive hardened child keys.
Q3: What happens if I lose my chain code?
A: Without the chain code, child key derivation is impossible, ensuring keys remain secure.
👉 Learn more about elliptic curve cryptography
Conclusion
Extended keys empower HD wallets with hierarchical, deterministic key management. By mastering their derivation paths and security trade-offs, users can optimize for both convenience and safety.
Key Takeaways:
- Use hardened keys for sensitive accounts.
- Never expose normal child private keys if the parent extended public key is known.
- Serialized keys (
xprv/xpub) encode vital metadata for recovery.
For further reading, consult BIP 32 or tools like Ian Coleman’s BIP39 Generator.