Simple implementation of Bitcoin's BIP39 mnemonic and seed generator using the reference implementation as guide.
Personal disclaimer: This is a personal experimentation to learn by practice how the entropy, mnemonic, seeds, etc., works internally. It includes passing tests taken from the reference implementation as well (vectors, checksum, instantiation from different sources, languages, etc.).
Run:
Metacello new
baseline: 'BIP39Mnemonic';
repository: 'github://eMaringolo/pharo-bip39mnemonic/src';
load.
| m |
"Creating a mnemonic from Pharo's weak PRNG"
m := BIP39Mnemonic generate.
"Getting its mnemonic words"
m words. "#('argue' 'snap' 'this' 'common' 'cube' 'length'
'abandon' 'abandon' 'abandon' 'abandon' 'abandon' 'ability')"
"Generating a seed with
m seedForPassphrase: 'Pharo'. "'154ad96ab7ad44d2c47beb3801e278b37b82fe9fc3...'"
BIP39Mnemonic fromWords: 'legal winner thank year wave sausage worth useful legal winner thank yellow'.
BIP39Mnemonic fromWords: #('legal' 'winner' 'thank' 'year' 'wave' 'sausage'
'worth' 'useful' 'legal' 'winner' 'thank' 'yellow')