BIP 39
BIP stands for Bitcoin Improvment Proposal and defines several standards and key features. BIP 39 is the proposal 39, which defines a mnemonic code for generating deterministic keys. Thus, it can be used as a seed for your keys, or represent a private key.
Exercise 1
Read and understand BIP 39.
- Q1: What is the advantage of a mnemonic?
- Q2: For a 128 bit number that should be converted to a mnemonic code, how much words do you need in your mnemonic?
A mnemonic code is created from a word list with 2048 words. We'll use the following word list: https://raw.githubusercontent.com/bitcoin/bips/master/bip-0039/english.txt.
Exercise 2
You have the following random number: 94b8c423610d2ce4adb08ca74bae438e
and you want to create a mnemonic according to BIP 39.
- Q1: At which position in the word list is your first mnemonic (the first mnemonic starts at 94...)?
- Q2: What is the first word in your mnemonic?
The SHA256 hash of 94b8c423610d2ce4adb08ca74bae438e
is b1de5c24b373385e95c8dc42fea83d5adb13ab1c3f6f4e214bb596e3a7c53c0a
. The first n bits of this hash will be used as a checksum. Append these bits to your random number.
Exercise 3
- Q1: How much bits will you append?
- Q2: Which character(s) will you append?
Your number looks as follows: 94b8c423610d2ce4adb08ca74bae438eX
, where X is your answer from Q2.
- Q3: At which position in the word list is your last mnemonic?
- Q4: What is the last word in your mnemonic?
Take a look at the BIP 39 implementation at https://github.com/tbocek/VSS-BIP39. Some crucial parts are missing, marked with **.
Exercise 4
- Q1: You know how to find the first and the last word in your mnemonic code. Find all other words by completing the implementation at https://github.com/tbocek/VSS-BIP39. Decide if you need to bit-wise shift left (Lsh) or shift right (Rsh).
Once we have the words we can calculate the BIP 39 seed according to the specification. For the BIP 39 seed, PBKDF2 (Password-Based Key Derivation Function 2) is used. The password is the space separated word list, the salt is "mnemonic", number of iterations is 2048, and key length is 64 bytes as the hash is SHA512.
Exercise 5
- Q1: Double check if your words match with the online BIP 39 calculator at https://iancoleman.io/bip39/.