Bip32-Hd-Wallets

如何在 pybitcointools 中使用主公鑰生成多個地址?

  • July 22, 2016

我在玩這個pybitcointools的分支,我通過生成多個地址來接收帶有主公鑰的硬幣。到目前為止,這就是我所擁有的:

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

您想在 bip32_masterpublickey 上使用 bip32_bin_extract_key:

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

然後在結果上使用 pubkey_to_address :

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

簡單的說:

btc.pubkey_to_address(btc.bip32_bin_extract_key(bip32_masterpublickey))

引用自:https://bitcoin.stackexchange.com/questions/46657