libwally-core icon indicating copy to clipboard operation
libwally-core copied to clipboard

bip32 should support ypub, zpub etc.

Open benma opened this issue 6 years ago • 9 comments

The bip32 library only works with xpub/xprv.

If you want to use xpub/ypub/zpub etc. (see https://github.com/satoshilabs/slips/blob/master/slip-0132.md), the library gives you a hard time currently.

I currently work around it by using only the xprv/xpub versions, and then force overwriting the version bytes when serializing.

It would be great to keep the bip32 API flexible enough so that one can provide custom version bytes.

benma avatar Oct 10 '19 15:10 benma

@benma hey. could you share your code?

I'm also replacing version bytes but I have

OverflowError: Invalid unsigned integer

Obviously doing something wrong.

evd0kim avatar Nov 02 '20 18:11 evd0kim

@engenegr sure thing:

https://github.com/digitalbitbox/bitbox02-firmware/blob/ddcdb0e03e5c5734c46876ad25eff74d22ab26a2/src/apps/btc/btc_common.c#L284-L286

benma avatar Nov 03 '20 11:11 benma

@benma

Thanks a lot!

evd0kim avatar Nov 03 '20 11:11 evd0kim

My opinion is libwally should not do this. bip32 has nothing to do with slip0132.

Fonta1n3 avatar Nov 03 '20 14:11 Fonta1n3

@Fonta1n3 what is the disadvantage in supporting it?

Note that Zpub, Ypub etc. are already pervasively used by Electrum and compatible wallets. If it is not supported by the library, weird workarounds like the one I linked above are necessary.

benma avatar Nov 03 '20 14:11 benma

@Fonta1n3

Actually I couldn't manage libwally working with zpub even with substituting version bytes. I would be grateful if you could say how I can import zpub and derive native segwit addresses.

evd0kim avatar Nov 03 '20 17:11 evd0kim

@Fonta1n3

Actually I couldn't manage libwally working with zpub even with substituting version bytes. I would be grateful if you could say how I can import zpub and derive native segwit addresses.

This is what i use to convert:

https://github.com/Fonta1n3/FullyNoded/blob/master/FullyNoded/Helpers/Xpub%20Converter/XpubConverter.swift

Fonta1n3 avatar Nov 04 '20 02:11 Fonta1n3

@Fonta1n3 are you using libwally-core in this project? If so, I don't understand why you prefer to re-implement xpub encoding almost completely than having it be supported upstream.

benma avatar Nov 04 '20 05:11 benma

@Fonta1n3 Thank you. I see I have to replace checksum also.

evd0kim avatar Nov 04 '20 07:11 evd0kim