How do I generate multiple address with a master public key in pybitcointools?

2

2

I'm goofing around with this fork of pybitcointools and I got stock with generating multiple address for receiving coins with a master public key. So far, this is what I have:

import bitcoin as btc

privatekey = btc.sha256("large example seed for this great test")
print privatekey

# 03e02b95a485112b543ac29cd262afbbd64dca9b4496e264e47312cb193ae5ab

bip32_masterprivatekey = btc.bip32_master_key(privatekey)
bip32_masterpublickey = btc.bip32_privtopub(bip32_masterprivatekey)

print bip32_masterprivatekey
# xprv9s21ZrQH143K3tQmGrVtKc7B6ZPtCJAmD6wDAJXxb7YXAoZFTb55UroSxrU7k823vSQmYPDhdseRKqP1mgSUWDneinai2seUd7RLX2xkmGW

print bip32_masterpublickey
# xpub661MyMwAqRbcGNVENt2tgk3uebENbktcaKroxgwa9T5W3btQ18PL2f7vp78LNoioGhZcgSH1i2cH48YcQttiEaAh86TuJpsUu2J7jQWnmbC

shackra

Posted 2016-07-22T02:10:36.133

Reputation: 123

Answers

2

You want to use bip32_bin_extract_key on the bip32_masterpublickey:

https://github.com/vbuterin/pybitcointools/blob/8e8a33d7281c871950519e5f256ad08cf0d5df69/bitcoin/deterministic.py#L140

And then use pubkey_to_address on the result:

https://github.com/vbuterin/pybitcointools/blob/8e8a33d7281c871950519e5f256ad08cf0d5df69/bitcoin/main.py#L446

simply put:

btc.pubkey_to_address(btc.bip32_bin_extract_key(bip32_masterpublickey))

Jimmy Song

Posted 2016-07-22T02:10:36.133

Reputation: 7 067

That would generate one bitcoin address, right? How do I generate two or more using the master public key?shackra 2016-07-22T04:57:05.620

1Indeed, that would. You'll want to do bip32_descend to get keys that are not the root key.Jimmy Song 2016-07-22T13:45:58.150

Sorry for being annoying, but what parameters should I exactly feed bip32_descend with, besides the public master key (I guess) to achieve what I'm looking? I did this btc.pubkey_to_address(btc.bip32_descend(bip32_masterpublickey, [1, 0, 0])) and I'm getting a different address changing the third 0 of the list, but I'm not sure if that equals to M/i'/0shackra 2016-07-22T21:42:52.160

1So the last argument is the BIP32 path. [1,0,0] => M/1/0/0 path. Changing any of the numbers in the path or making it longer by an element will change the address.Jimmy Song 2016-07-23T15:41:55.760