vbuterin / pybitcointools

SImple, common-sense Bitcoin-themed Python ECC library
1.28k stars 856 forks source link

I implemented bip39 support as bitcoin.mnemonic #128

Closed Steve132 closed 8 years ago

Steve132 commented 8 years ago

I implemented bip39 support, because I think it would be a useful addition to pybitcointools.

The code is inside the bitcoin.mnemonic module. For ease of use, I also included the text file for the default english wordlist, but if you want you can remove this from the repo.

I tried to closely mimic the style of pybitcointools.

For example, you can do

seed=bitcoin.mnemonic_to_seed('grocery toilet zone hill key replace second thought question canoe capable organ million tackle drip',passphrase='TREZOR')
print(hexlify(seed)) 

To get the output

bdfb76a0759f301b0b899a1e3985227e53b3f51e67e3f2a65363caedf3e32fde42a66c404f18d7b05818c95ef3ca1e5146646856c461c073169467511680876c

You can also generate words from an entropy source mnemonic.entropy_to_words, or verify a checksum with mnemonic.words_verify

Steve132 commented 8 years ago

Note: I forgot to add

from mnemonic import * 

to bitcoin/__init__.py ...so you should add that too.