bitcoinjs / bip32

A BIP32 compatible library.
MIT License
177 stars 127 forks source link

Add support for other xpub versions (zpub & ypub) #67

Closed bilthon closed 1 year ago

bilthon commented 1 year ago

If one tries to use this library with a zpub or ypub like:

const zpub = 'zpub6rJ2iP3x8vJGTf2H8i2RK8KfwpRwyiKmbRYPtvC3zUGK9DHFQYCx5sPhH9TV7ekGgU5bR8fmqNadhRYG9LtWV6gw2UG3UA2BmNNQ2Dp5dJf'
const node = bip32.fromBase58(xpub, networks.bitcoin)

This will fail, because the networks.bitcoin has only 0488b21e & 0488ade4 defined as public and private extended key prefixes.

Is there any interest to add support for zpub & ypub as well? And if so, how to approach this? as these constants are not even defined here but in bitcoinjs-lib as I can see here.

junderw commented 1 year ago

zpub and ypub are not defined in BIP32, so unfortunately no.

You can get around it by creating your own network constant(s).

bilthon commented 1 year ago

Makes total sense, and your suggestion does the trick