BIP 32, 39, and 44: Hierarchical Deterministic Wallets and Mnemonic Phrases.
Exploring the Significance of BIP 32, 39, and 44 in Wallet Security.
BIP 32, BIP 39, and BIP 44 are all Bitcoin Improvement Proposals (BIPs) that define standards for different aspects of Bitcoin wallets, particularly regarding hierarchical deterministic wallets (HD wallets) and mnemonic phrases. But what are hierarchical deterministic wallets and mnemonic phrases?
Hierarchical deterministic wallets (HD wallets) provide a convenient way to manage multiple addresses and private keys from a single master seed. HD wallets use a tree structure where parent keys can produce children keys infinitely, allowing for organized transactions by type or entity. They offer the advantage of creating public keys without accessing corresponding private keys, enhancing security.
Mnemonic phrases, also known as seed phrases or recovery phrases, are a way to represent the master private key in a hierarchical deterministic (HD) wallet. They consist of a sequence of words that can be used to restore the wallet and all its derived keys. Mnemonic phrases are typically 12, 18, or 24 words long and are generated using a standardized process defined in the BIP39 (Bitcoin Improvement Proposal 39) specification.
The Significance of BIP 32, 39, and 44.
- BIP 32:
— BIP 32 is a key derivation standard that allows for the creation of child keys from a parent key in a deterministic manner. This means that given the same input (the parent key), the same output (the child key) will always be produced. This is in contrast to non-deterministic methods, where the output can vary even with the same input.
The BIP 32 standard defines two types of child keys: hardened and non-hardened. Hardened child keys are generated in such a way that knowing a child key does not allow you to compute the parent key or any sibling keys. Non-hardened child keys do not have this property, meaning that if you know a non-hardened child key and the parent public key, you can compute all the sibling keys.
From the explanations above, we can see that BIP 32 allows for a single backup of the master key to recover all derived keys. This is because the child keys are derived in a deterministic manner from the parent key. So if you have the parent key and the derivation path (i.e., the “path” from the parent key to the child key in the tree), you can always re-derive the child key.
A major downside of BIP 32 is that if a non-hardened child key and the parent public key are both revealed, it is possible to compute the parent private key. This is why it is recommended to use hardened child keys for any situation where the parent public key might be revealed.
2. BIP 39:
— BIP39, or Bitcoin Improvement Proposal 39, is a standard used for. creating mnemonic phrases in the context of hierarchical deterministic (HD) wallets. It defines a method for generating a sequence of words — typically consisting of 12 to 24 words chosen from a predefined word list — that can be used to back up and restore a wallet’s master private key and all its derived keys. These phrases serve as a human-readable representation of the master seed, making it easier for users to backup and restore their wallets. BIP39 ensures that different wallets can generate and interpret the same mnemonic phrases, enhancing compatibility and usability across various wallet implementations.
3. BIP 44:
— BIP 44 is a specific application of BIP 32. It defines a multi-account hierarchy for deterministic wallets, providing a standardized way to organize keys for different cryptocurrency accounts within the same wallet. BIP 44 introduces the concept of ‘account levels’ and ‘purpose levels’ to create a hierarchical structure for keys. Each account has its own subtree, allowing for better organization and separation of funds.
The main purpose of BIP44 is to provide a structured method for creating and organizing keys in a deterministic wallet. It extends the concepts introduced in BIP32 (Hierarchical Deterministic wallets) and BIP39 (mnemonic sentence as a backup recovery seed) by specifying a specific hierarchy for wallet structures. This hierarchy improves organization, utility, and compatibility.
What is the relationship between these BIPs?
- BIP 39 provides a standard way to generate mnemonic phrases, which can be used to derive the master seed specified in BIP 32.
- BIP 32 defines the structure and derivation paths for hierarchical deterministic wallets, which are used in conjunction with mnemonic phrases generated according to BIP 39.
- BIP 44 builds upon BIP 32 by providing a specific organizational structure for multi-account wallets, allowing users to manage different cryptocurrency accounts within the same wallet while maintaining a hierarchical deterministic structure.
Generating a Mnemonic Phrase
Let’s start by generating a mnemonic phrase in Go using the `github.com/tyler-smith/go-bip39` package:
This code generates a 24-word mnemonic phrase using 256 bits of entropy, which provides a good balance between security and memorability.
Deriving Keys from Mnemonic
Once we have a mnemonic phrase, we can derive the master seed and subsequently generate child keys using the BIP 32 algorithm. Let’s see how to do this in Go using the same package used above:
This code first generates a seed from the mnemonic key, then derives a master key from that seed using BIP 32. Finally, it derives two child keys from the master key.
Conclusion
HD Wallets and mnemonic phrases play a crucial role in Bitcoin Core, providing a secure and convenient way to manage keys. By following the BIP 32 standard and using libraries, developers can easily integrate HD wallet functionality into their applications using Go.
References
1. https://www.ledger.com/academy/crypto/what-are-hierarchical-deterministic-hd-wallets
2. https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
3. https://river.com/learn/images/articles/hd-wallet-structure.png