Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: merclyn on October 17, 2018, 03:35:28 PM



Title: HD Key Derivation Help
Post by: merclyn on October 17, 2018, 03:35:28 PM
Greetings,

  I am trying to create a python routine/function that would take an input of a xpub public key from a HD wallet, and return list of public addresses / change addresses
  We wont have access to the xpriv, or the seed.

  Ive spend a good amount of time trying to put this together by looking through other projects, and diving through alot of docs.    I was hoping I could get some advise or help.

Thx
merclyn


Title: Re: HD Key Derivation Help
Post by: achow101 on October 18, 2018, 05:01:34 AM
I have implemented public BIP 32 derivation in a project of mine, you can look at the implementation here: https://github.com/achow101/HWI/blob/master/hwilib/bip32.py. The function that does the derivation is CKDpub and it takes as arguments: the parent public key as bytes, the parent chaincode as bytes, and the index of the child to derive as an integer.

It will only derive a child key at a particular index. You can derive keys at paths by using a loop to derive the child at each step in the path until you get to the final child.

If all you need is public derivation, then you can use that code. It is provided under the MIT license.