How to derive all possible segwit addresses from xpub
academe-01 opened this issue · comments
academe-01 commented
Hello,
I need derive all possible addresses from Ledger xPub.
I've tried this:
from cryptotools import Xpub
MY_XPUB = 'xpub-as-shown-in-ledger'
key = Xpub.decode(MY_XPUB)
pubkey0 = key/0/0
print(pubkey0.address('P2WPKH')) # Tell the wallet that you want a P2WPKH address
but it gives only 1 address.
Any idea ?
Thanks.
Mike Dallas commented
hey @academe-01 just change the key/0/0
to key/0/1
to get the second address etc. Or just do a for loop to get the first X addresses
academe-01 commented
hey @mcdallas !
thanks for help!
any idea if my ledger show "freshAddressPath": "49'/0'/0'/0/1" and it's segwit from what range should i start loop?
big thanks!
Mike Dallas commented
You should start from /0/1
since that’s the path ledger shows. For BIP49 addresses (starting with 3) use .address(‘ P2WPKH-P2SH’)
instead of ‘P2WPKH` in your example