Principles of using BIP39 mnemonics

rinayhiron

Member
Jul 30, 2024
47
0
BIP39 mnemonics are a mechanism used in Bitcoin Improvement Proposals (BIPs) to generate deterministic wallets. It simplifies the process of creating and managing wallets by encoding random numbers (called entropy) into a set of words (mnemonics) that are easy to remember and communicate. Here are some basic principles for using BIP39 mnemonics:

1. Generate mnemonics

Initial entropy length: The BIP39 specification allows the initial entropy length (ENT) to be 128-256 bits, usually increasing in multiples of 32 bits (i.e. 4 bytes).
Checksum: When generating mnemonics, a checksum of the initial entropy is calculated and appended to the end of the initial entropy. The length of the checksum is ENT/32, that is, the first ENT/32 bits are taken from the SHA-256 hash of the initial entropy as the checksum.
Word encoding: The binary representation of the initial entropy (including the checksum) is cut into 11 bits, and each 11-bit binary number is converted into a number between 0-2047, and then the corresponding word is selected from the predefined word list. Eventually, these words are concatenated to form the mnemonic string.

2. Wordlist Selection

Characteristics of an ideal wordlist:
Clever word selection: The wordlist should be created in such a way that typing the first four letters can clearly identify the word.
Avoid similar words: such as "build" and "built", "woman" and "women", etc., to reduce the difficulty of memorization and the possibility of errors.
Classification word library: The wordlist should be sorted to make it more efficient to find the code, binary search can be used instead of linear search, and data structures such as trie (prefix tree) can be used for compression.
Localization support: The wordlist can contain localized characters, but it must use the Normalized Form Compatible Decomposition (NFKD) encoded in UTF-8.

3. Security

Entropy length: The length of entropy directly affects the security of the mnemonic. The longer the entropy, the higher the security of the mnemonic, but the corresponding sentence length will also increase.
Password protection: Users can set an additional password (password) for the mnemonic to increase security. This password will be used together with the mnemonic when generating HD seeds.
Do not disclose: The mnemonic is an alternative way to access the private key of the wallet, so it must be kept properly to avoid disclosure.

4. Usage scenarios

Wallet creation: Using BIP39 mnemonics, you can easily create a deterministic wallet, which is easy for users to remember and manage.
Recovering a wallet: When you need to restore a wallet, just enter the correct mnemonic and password (if any) to regenerate the private key and address of the wallet.

5. Notes

The relationship between mnemonics and HD seeds: Mnemonics are the basis for generating HD seeds, but the generation of HD seeds also depends on mnemonics and possible passwords (passwords).
Verification of mnemonics: The software should implement the verification function of mnemonics to ensure that the mnemonics entered by the user are valid.
Multi-language support: The BIP39 specification supports word lists in multiple languages, and users can choose the appropriate language according to their needs.

In short, the use of BIP39 mnemonics should follow the above principles to ensure the security and ease of use of the wallet. At the same time, users should also pay attention to properly keep mnemonics and passwords to avoid leakage and asset loss.

Mnemonic generation tool