bitcoinjs / bolt11

A library for encoding and decoding lightning network payment requests as defined in BOLT #11.
MIT License
92 stars 64 forks source link

fix: support uppercase payment requests #12

Closed mrfelton closed 5 years ago

mrfelton commented 5 years ago

According to the bech32 spec, both uppercase and lowercase payment requests are valid. some QR codes use a special mode where they only use UPPER case to encode the data more efficiently.

Here is the relevant part of the spec:

https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#specification

The lowercase form is used when determining a character's value for checksum purposes.

Encoders MUST always output an all lowercase Bech32 string. If an uppercase version of the encoding result is desired, (e.g.- for presentation purposes, or QR code use), then an uppercasing procedure can be performed external to the encoding process.

Decoders MUST NOT accept strings where some characters are uppercase and some are lowercase (such strings are referred to as mixed case strings).

For presentation, lowercase is usually preferable, but inside QR codes uppercase SHOULD be used, as those permit the use of alphanumeric mode, which is 45% more compact than the normal byte mode.

This PR adds support for decoding uppercase payment requests

junderw commented 5 years ago
  1. Do we need to throw on mixed case?
  2. Please add test to maintain 100% coverage.
mrfelton commented 5 years ago

The spec says that mixed case is invalid.

junderw commented 5 years ago

Yes... the bech32 spec says so, and bech32 does throw.

https://github.com/bitcoinjs/bech32/blob/v1.1.3/index.js#L75-L79

I went ahead and added tests, and simplified the fix a little #13

mrfelton commented 5 years ago

Closing in favour of #13