['''Why are the high bits of the human-readable part processed first?'''
This results in the actually checksummed data being ''[high hrp] 0 [low hrp] [data]''. This means that under the assumption that errors to the
human readable part only change the low 5 bits (like changing an alphabetical character into another), errors are restricted to the ''[low hrp] [data]''
@@ -182,11 +182,15 @@ to make.
'''Uppercase/lowercase'''
-Decoders MUST accept both uppercase and lowercase strings, but
-not mixed case. The lowercase form is used when determining a character's
-value for checksum purposes. For presentation, lowercase is usually
-preferable, but inside QR codes uppercase SHOULD be used, as those permit
-the use of
+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
''[http://www.thonky.com/qr-code-tutorial/alphanumeric-mode-encoding alphanumeric mode]'', which is 45% more compact than the normal
''[http://www.thonky.com/qr-code-tutorial/byte-mode-encoding byte mode]''.
@@ -262,22 +266,33 @@ P2PKH addresses can be used.
===Test vectors===
-The following strings have a valid Bech32 checksum.
+The following strings are valid Bech32:
* A12UEL5L
+* a12uel5l
* an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs
* abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw
* 11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j
* split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w
+* ?1ezyfcl WARNING: During conversion to US-ASCII some encoders may set unmappable characters to a valid US-ASCII character, such as '?'. For example:
-The following strings have an invalid Bech32 checksum (with reason for invalidity):
+]
+>>> bech32_encode('\x80'.encode('ascii', 'replace').decode('ascii'), [])
+'?1ezyfcl'
+
+
+The following string are not valid Bech32 (with reason for invalidity):
* 0x20 + 1nwldj5: HRP character out of range
* 0x7F + 1axkwrx: HRP character out of range
+* 0x80 + 1eym55h: HRP character out of range
* an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx: overall max length exceeded
* pzry9x0s0muk: No separator character
* 1pzry9x0s0muk: Empty HRP
* x1b4n0q5v: Invalid data character
* li1dgmt3: Too short checksum
* de1lg7wt + 0xFF: Invalid character in checksum
+* A1G7SGD8: checksum calculated with uppercase form of HRP
+* 10a06t8: empty HRP
+* 1qzzfhee: empty HRP
The following list gives valid segwit addresses and the scriptPubKey that they
translate to in hex.