bitauth / libauth

An ultra-lightweight, zero-dependency TypeScript library for Bitcoin Cash, Bitcoin, and Bitauth applications.

Home Page:https://libauth.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expand cash address utilities

bitjson opened this issue · comments

Some good developer experience observations from @rkalis:

Why is there a decodeCashAddress and decodeCashAddressFormat, but only decodeCashAddressFormatWithoutPrefix and no decodeCashAddressWithoutPrefix? And why are their return types not compatible with AddressContents so I cannot use them in addressContentsToLockingBytecode?
In any case, this is my goal:
I'm using cashAddressToLockingBytecode but that only works if you pass in a a prefixed address, I also want to support using an unprefixed address (don't think the prefix matters for the locking bytecode), but it throws an error if there's no prefix.

Originally, I’d thought you wouldn’t need decodeCashAddressWithoutPrefix if you already knew it was a cash address (since you simply need to add the prefix, no testing loop needed), but I think it would be valuable to have it just as a convenience method to "complete the set".

It would also be valuable to figure out how to make the results of decoding compatible with the AddressContents type – either by adjusting the types or by adding a couple more to/from utility methods.

So, TODO:

  • add decodeCashAddressWithoutPrefix
  • either:
    • make decoded cash address and AddressContents types compatible, or
    • add utility methods for converting between them