Skip to content

Commit ddbf956

Browse files
hardingjnewbery
authored andcommitted
Newsletter 46: describe mixed-case QR codes
1 parent 9f83f90 commit ddbf956

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

_includes/specials/bech32/09-qrcode.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,42 @@ same dimensions).
3030

3131
Unfortunately, the `?` and `&` needed for passing additional parameters
3232
in a BIP21 URI are not part of the QR code uppercase character set, so
33-
only binary mode can be used. Additionally, BIP21 specifies that query
33+
only binary mode can be used for those characters. Additionally, BIP21 specifies that query
3434
parameter names such as `amount` and `label` are case sensitive, so
3535
uppercase versions of them aren't expected to work anyway.
3636

37-
Still, anywhere you want to display just an address in a QR code, you
38-
should consider using all-uppercase for bech32 addresses and [bech32-like
39-
addresses][News 44 bech32].
37+
{:#qrcode-edit}
38+
However, QR codes can support mixed character sets and doing so will
39+
always be at least slightly more efficient when used with a string that
40+
either begins or ends with an all-caps substring containing a bech32
41+
address. This is because the minimum allowed size of a bech32 address
42+
(14 characters) combined with the efficiency gain from using uppercase
43+
mode (31.25%) exceeds the worst-case overhead of switching modes (20
44+
extra bits). At least two QR code encoders we're aware of,
45+
[libqrencode][] (C) and [node-qrcode][] (JS), automatically mix
46+
character sets by default as necessary to produce the least-complex QR
47+
code possible:
48+
49+
![BIP21/bech32 mixed character mode](/img/posts/2019-05-bip21-bech32-qr-mixed.png)
50+
{:.center}
51+
52+
In summary, when using bech32 addresses in QR codes, consider
53+
uppercasing them and any other adjacent characters that can be
54+
uppercased in order to produce smaller and less complex QR codes.
55+
(However, for all other purposes, bech32 addresses should use all
56+
lowercase characters.)
57+
58+
*Correction:* an earlier version of this section claimed that QR codes
59+
which included BIP21 query parameters needed to use binary mode. Nadav Ivgi
60+
kindly [informed us][ivgi tweet] that it was possible to mix character
61+
modes, and we've updated the final two paragraphs of this section
62+
accordingly.
4063

4164
[bech32 easy]: {{news38}}#bech32-sending-support
4265
[rfc3986]: https://tools.ietf.org/html/rfc3986#section-3.1
43-
[news 44 bech32]: {{news44}}#bech32-sending-support
66+
[ivgi tweet]: https://twitter.com/shesek/status/1131733590235131905
67+
[node-qrcode]: https://github.com/soldair/node-qrcode#mixed-modes
68+
[libqrencode]: https://fukuchi.org/works/qrencode/
4469

4570
[^only-bc]:
4671
Bech32 addresses have three parts, a Human Readable Prefix (HRP)
17.4 KB
Loading

0 commit comments

Comments
 (0)