Bech32 (BIP173) address support - #115
Conversation
|
I took sipa's and dropped over this version to see the diff: When given an invalid HRP, like 0x80 or 0x20, sipa's will return 0 (fail to encode) and this version encodes an invalid bech32 string ("�1wzqgcn" and " 1nwldj5", respectively). Neither version accepts uppercase HRP values. They could as long as they follow the BIP guidance that "The lowercase form is used when determining a character's value for checksum purposes." and "Encoders MUST always output an all lowercase Bech32 string." This was helpful for testing: The reference code has not been updated to include all of the latest test vectors either (https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki) The C++ version that got merged into Bitcoin Core got more review (bitcoin/bitcoin#11167) and is implemented differently with better comments. You may want to start from that version and back out the C++ specific stuff like std::string, etc... |
|
I imported the source code a while ago, just found the time to add it. But I can update the last patches from Sipa's repository. Hope that the changes to the tests apply without too much conflict... I'm not sure I want to get the C++ code and backport it to C. It may introduce new problems with memory management, since C++ strings resize themselves automatically. I think it is better to stick to the reference implementation in sipa's repository unless there is a known problem with it. EDIT: Okay, I see you claim there are problems, if we want to support hrp with uppercase letters. OTOH we will probably only call this function only with fixed hrp's for the coins we support. |
|
Right, there are some practicalities that make the inconsistencies with the BIP less of a concern. I think another one might be around empty HRP IIRC (bitcoin/bips#587 (comment)). I wrote some java that tried to adhere closely to the BIP (https://github.com/sipa/bech32/pull/35/files) so that's why I'm aware of this. You're probably right that the best strategy is to just use sipa's latest reference code and then update if the reference code updates. |
hrp is ASCII character, not 5 bit words
Added bech32 (code by Peter Wuille).
Adapted the unit tests to our library.