segregated witness – How can I generate SegWit addresses from a mnemonic utilizing python?

0
74


So, I’ve written a script that generates BIP39 mnemonics. I now need to generate N native SegWit public keys from this mnemonic.

I’ve discovered this, nevertheless it generates legacy addresses. It makes use of the module bip32utils.

def bip39(mnemonic_words):
    mobj = mnemonic.Mnemonic("english")
    seed = mobj.to_seed(mnemonic_words)

    bip32_root_key_obj = bip32utils.BIP32Key.fromEntropy(seed)
    bip32_child_key_obj = bip32_root_key_obj.ChildKey(
        44 + bip32utils.BIP32_HARDEN
    ).ChildKey(
        0 + bip32utils.BIP32_HARDEN
    ).ChildKey(
        0 + bip32utils.BIP32_HARDEN
    ).ChildKey(0).ChildKey(0)

    return {
        'mnemonic_words': mnemonic_words,
        'addr': bip32_child_key_obj.Tackle(),
        'publickey': binascii.hexlify(bip32_child_key_obj.PublicKey()).decode(),
        'privatekey': bip32_child_key_obj.WalletImportFormat(),
        'coin': 'BTC'
    }

if __name__ == '__main__':
    seed = 'enter show smile visa encompass be taught photo voltaic hero vacuum parrot cigar dedicate'
    pprint.pprint(bip39(seed))

I assume I want bip44utils or one thing, nevertheless it does not exists. I’ve tried taking a look at bip-utils however I can not work out how one can convert my mnemonic to an deal with.

Does anybody know the way I can convert a mnemonic to a SegWit deal with (in a manner that I can change the derivation path to get a number of addresses)?

EDIT (SOLVED):

I discovered bitcoinlib can do that.

from bitcoinlib.wallets import Pockets

passphrase="enter show smile visa encompass be taught photo voltaic hero vacuum parrot cigar dedicate"

w = Pockets.create("Wallet1", witness_type="segwit", keys=passphrase, community='bitcoin')
WalletKeys = (w.get_keys(number_of_keys=10))

for ok in WalletKeys:
    print(ok.deal with)

And now it really works simply as I needed it to.

LEAVE A REPLY

Please enter your comment!
Please enter your name here