Expand description
BIP-39: bytes as words from the English list, as a hardware wallet shows its recovery phrase and takes it back.
The bytes are the wallet’s entropy, 16 to 32 bytes in steps of 4. The first byte of their SHA-256 digest supplies a checksum of one bit per 32 bits of entropy, appended to them; the result is read eleven bits at a time, most significant first, each an index into the 2048 words of the English list. 32 bytes are 24 words, 16 bytes are 12.
The words, not the entropy, are what a wallet derives its keys from, so the same entropy in another language’s list is a different wallet. This module knows the English list only, which is the one hardware wallets use.
The decoder takes either case and the first four letters of a word, which the list keeps unique and which metal backup plates carry. A word it does not find, a count that is not a phrase and a checksum that does not match are refused, each by the word’s position and never by the word, since the words are a secret.
Structs§
- Decoded
- A phrase read back: the entropy, wiped when dropped.
Enums§
- Bip39
Error - Why a phrase or a word does not read. None of these names a word.
Constants§
- MAX_
WORDS - The most words a phrase has.
- MIN_
WORDS - The fewest words a phrase has.
- PHRASE_
LENGTHS - The word counts a phrase may have, as a person reads them.
- WORD_
MAX - The longest word in the list, in letters.
Functions§
- bytes_
for - Bytes of entropy a phrase of
wordswords carries: four per three words. - decode
- Read a phrase back into its entropy. Words are separated by whitespace.
- encode
- Write entropy as a phrase, words separated by single spaces.
- is_
entropy_ len - Whether
bytesbytes of entropy make a phrase: 16 to 32 in steps of 4. - is_
phrase_ len - Whether a phrase may have
wordswords: 12 to 24 in steps of 3. - phrase_
lengths - The word counts a phrase may have, shortest first.
- read_
word - One word as typed, for a frontend that takes a phrase a word at a
time: the word it is, in full and lower case.
wordis its position from 1, for the error to name. - words_
for - Words in a phrase for
bytesbytes of entropy, rounded up for a length that is not one: three words per four bytes.