What is Nostr?
Pieter Wuille [ARCHIVE] /
npub1tje…tl6r
2023-06-07 18:27:42
in reply to nevent1q…ldtx

Pieter Wuille [ARCHIVE] on Nostr: 📅 Original date posted:2020-12-18 📝 Original message:On Tuesday, December 8, ...

📅 Original date posted:2020-12-18
📝 Original message:On Tuesday, December 8, 2020 9:39 AM, Ryan Grant <bitcoin-dev at rgrant.org> wrote:

> It looks like a good strategy for a bech32 library that is external to
> Bitcoin Core would be:
>
> - Default to the new M, under the same bech32 brand.
> - Provide an interface to explicitly use both M=1 and M=0x2bc830a3.
> - If decoding fails, throw an error; but in constructing that error
> inform whether the other M would have succeeded.
>
> - Provide an interface for a BIP173 implementation to peek at the
> witness version byte of the data part, which may also involve
> sanity-checking that byte for errors using a BIP173-specific
> understanding of the appropriate checksum.

I think there are two possible interfaces that make sense:

- Have the caller explicitly specify whether they want bech32 or bech32m (which someone - I think Rusty? - started using in reference to this new code and I'm going to adopt now).

- Have the bech32 decoding function return a tristate (failed, valid as bech32, valid as bech32m). No string is ever valid as both, so there is no loss of information here.

The former is a bit cleaner, and also the only real choice if error location hinting is desired. The second is more efficient if decoding twice is a performance concern.

Cheers,

--
Pieter
Author Public Key
npub1tjephawh7fdf6358jufuh5eyxwauzrjqa7qn50pglee4tayc2ntqcjtl6r