bitcoin-php icon indicating copy to clipboard operation
bitcoin-php copied to clipboard

enable toExtendedKey(), fromExtended() to work with GlobalPrefixConfig

Open dan-da opened this issue 5 years ago • 4 comments

It seems like right now if I want to work with ypub, zpub, I have to roll my own implementations of fromExtended() and toExtendedKey() (and friends), as shown in the example files zpub.create.php and zpub.parse.php.

It would be very nice if this could be abstracted away, eg during init of HierarchicalKeyFactory.

For now I've rolled my own, but I'd love to ditch that at some point...

dan-da avatar Jul 14 '18 10:07 dan-da

Are you running master? I think you can pass in your own Base58ExtendedKeySerializer into HierarchicalKeyFactory now, adding support to fromExtended for zpubs/ypubs

toExtended sucks, and I really should have made the serializer a mandatory parameter there. But since I didn't want to BC break the HD wallet api, for now it's "opt in" by making the registries, making your own serializer, and encoding using that.

afk11 avatar Jul 14 '18 14:07 afk11

Well, maybe that's the way. Just so long as its consistent for xpub, ypub, zpub is my hope....

dan-da avatar Jul 14 '18 14:07 dan-da

I hadn't fully realized the way forward for you at the time, but once you don't use prefixes that conflict, if you want a consistent codepath for serializing xpubs, Zpubs, ypubs, etc, it's to no longer use toExtendedPublicKey, toExtendedPrivateKey, or toExtendedKey. The ExtendedKeySerializer needs a GlobalPrefixConfig initialized for it to be able to work, which the toExtended* functions don't have.

afk11 avatar Dec 16 '18 22:12 afk11

ok, so what to use in place of them? maybe an example?? It's late at night here and code not in front of me, I'm probably missing something obvious. :-)

dan-da avatar Dec 17 '18 09:12 dan-da