I basically followed the instructions here How to generate mycelium addresses from the 12 words in python
So my code is similar:
from bip32utils import BIP32Key
from bip32utils import BIP32_HARDEN
from bip32utils import Base58
import os, bip39
strength_bits = 128
entropy = os.urandom(strength_bits // 8)
wallet_generator = bip39.Mnemonic('english')
mnemonic = wallet_generator.to_mnemonic(entropy)
assert wallet_generator.to_entropy(mnemonic) == entropy # see, bijective!
# Or specify the mnemonic directly if you prefer:
mnemonic = 'aware report movie exile buyer drum poverty supreme gym oppose float elegant'
passphrase = 'test'
seed = bip39.Mnemonic.to_seed(mnemonic, passphrase=passphrase)
key = BIP32Key.fromEntropy(seed)
account_number = 0
i = 0
print "Address: " + key.ChildKey(44 + BIP32_HARDEN) \
.ChildKey(0 + BIP32_HARDEN) \
.ChildKey(account_number + BIP32_HARDEN) \
.ChildKey(0) \
.ChildKey(i) \
.Address()
And I verified it using https://iancoleman.io/bip39/#english that the generated address is indeed the first address that this webpage generated as well. However, I also want to get the public and private key pairs using this same library. I originally tried:
print "Public Key: " + Base58.check_encode(key.ChildKey(44 + BIP32_HARDEN) \
.ChildKey(0 + BIP32_HARDEN) \
.ChildKey(account_number + BIP32_HARDEN) \
.ChildKey(0) \
.ChildKey(i) \
.PublicKey())
print "Private Key: " + Base58.check_encode(key.ChildKey(44 + BIP32_HARDEN) \
.ChildKey(0 + BIP32_HARDEN) \
.ChildKey(account_number + BIP32_HARDEN) \
.ChildKey(0) \
.ChildKey(i) \
.PrivateKey())
However, the output of these two calls are not the same as the ones provided by the website above for the same address.
So my question is: what's the proper way for me to generate the public and private key pairs?
Edit: To clarify, for the exact mnemonic and passphrase above, the website I'm using for reference tells me the first address and keypair should be:
While the output of the above python code is:
Address: 1K6WQtD7bLQ5nQ14GyBV33mBWSbkiRKhQs
Public Key: 62Yi9HBYYagf8CY1Ve2fquHKjBqAA7GFjGUUtkUHbkP5PHzv3W
Private Key: EGHMsAp7nY7Jo9F589zCU227KBLTDhiwRq5vYVvRVZxJNPJn4
So the address matches, but not the keypair.
PublicKey()
vsAddress()
, did you want the public key or the address?