A very specific and interesting topic!
You're referring to BIP39 (Bitcoin Improvement Proposal 39), which defines a mnemonic code for generating deterministic keys, also known as a mnemonic seed or seed phrase.
What is a mnemonic code?
A mnemonic code is a human-readable, memorable phrase used to generate a set of cryptographic keys. It's a way to encode a large, randomly generated number (the entropy) into a series of words, making it easier to store, backup, and restore cryptographic keys.
How does it work?
Here's a high-level overview:
- Entropy generation: A cryptographically secure pseudorandom number generator (CSPRNG) generates a random binary string (the entropy). The length of the entropy is typically 128, 160, 192, 224, or 256 bits.
- Checksum calculation: A checksum is calculated by taking the first
entropy_length / 32 bits of the SHA256 hash of the entropy. This checksum is appended to the end of the entropy.
- Mnemonic code generation: The entropy + checksum is divided into 11-bit chunks (since 2^11 = 2048, which is the number of words in the wordlist). Each chunk is used as an index to select a word from a predefined wordlist (more on this below).
- Mnemonic sentence construction: The selected words are concatenated to form a sentence, which is the mnemonic code or seed phrase.
Wordlist
The BIP39 standard defines a wordlist of 2048 words, carefully chosen to:
- Be easy to read and write
- Avoid similar words (e.g., "cat" and "bat")
- Be language-agnostic (the wordlist is designed to work with many languages)
The wordlist is based on the English Word List by the Electronic Frontier Foundation (EFF). You can find the official BIP39 wordlist here.
Example
Suppose we generate 128 bits of entropy:
Entropy (128 bits): 0x1234567890abcdef1234567890abcdef
Checksum (4 bits): 0x8 (first 4 bits of SHA256(entropy))
Entropy + Checksum: 0x1234567890abcdef1234567890abcdef8
Divide the entropy + checksum into 11-bit chunks:
Chunk 1: 0x123 (index 291)
Chunk 2: 0x456 (index 1110)
Chunk 3: 0x789 (index 1929)
...
Chunk 12: 0x8 (index 8)
Using the wordlist, we get:
Word 1 (index 291): abandon
Word 2 (index 1110): fossil
Word 3 (index 1929): zone
...
Word 12 (index 8): eight
The resulting mnemonic code (seed phrase) is:
abandon fossil zone ... eight
This sentence encodes the original 128 bits of entropy and checksum. You can now store this phrase securely, and use it to deterministically generate keys for various cryptographic applications (e.g., Bitcoin, Ethereum, PGP).
Key derivation
To generate keys from the mnemonic code:
- PBKDF2 (Password-Based Key Derivation Function 2) is applied to the mnemonic sentence, using a salt (
"mnemonic" + passphrase , where passphrase is an optional user-defined string). This produces a seed (512 bits).
- The seed is used as input for BIP32 (Hierarchical Deterministic Wallets), which generates a tree-like structure of cryptographic keys (master key, child keys, grandchild keys, ...).
Benefits
- Easy backup: Store the mnemonic sentence in a secure location (e.g., safe, encrypted file).
- Deterministic: Re-generate the same keys from the mnemonic sentence, even on a different device.
- Flexibility: Derive multiple keys and addresses from a single mnemonic sentence.
Important notes
- Keep your mnemonic sentence secret: Anyone with access to it can generate your keys.
- Use a secure passphrase (if desired): Adds an additional layer of protection.
- Don't lose the mnemonic sentence: If lost, your keys and funds are irretrievable.
Now, go impress your friends with your new understanding of BIP39 mnemonic codes!
Resources:
Hope this helps! Let me know if you have further questions.