hd-wallet-derive
hd-wallet-derive copied to clipboard
Possibility to obtain ypub / zpub from xpub?
Since we have the plumbing available to create p2sh-segwit and bech32 addresses from an xpub. Would it be possible to also have the ability to derive a ypub or zpub from a given xpub?
Should be possible I suppose. What's the use case?
Funny enough, it's actually for your other package (hd-wallet-addr) as this one only checks the addresses that should be obtained from an extended public key (i.e. 1... for xpub, 3... for ypub and bc1... for zpub according to SLIP-0132). Because of Ledger's implementation of only using xpub's and derive the required addresses, I need to check the xpub, ypub and zpub of a given xpub (to see whether it has been used).
My thought was thus to use the hd-wallet-derive (which we already have implemented) to obtain the ypub and zpub from a given xpub and throw those into the hd-wallet-addr. I guess the better solution would be to implement a parameter (like --addr-type=p2sh-segwit in hd-wallet-derive) into hd-wallet-addr? I can open a pull request for that instead if that's your preferred way of going?
If you can create a PR for hd-wallet-addrs, that would be great.
As I recall, there is some trickiness (a lot of setup) required to make a given key generate x, y, or z type addresses, as the bitcoin-php lib doesn't really support it cleanly yet. I opened an issue for it. You should be able to port over what I did in hd-wallet-derive though, or let me know if difficulties.