Summary
Generalize codex32 so that the human-readable part is not restricted to ms.
This PR is based on top of behavior neutral #2285.
BIP-32 master seeds and their shares continue to use ms, while other applications can use their own human-readable parts.
Changes
- Specify the human-readable part as in BIP-173 and include it in checksum construction and verification.
- Rename the inline
ms32helpers tocodex32.codex32_encodetakes the human-readable part andcodex32_decodereturns it. - Leave master seed lengths to a master seed decoder, as BIP-173 leaves witness program rules to a segwit address decoder.
- Require all shares in a set to use the same human-readable part.
- Clarify that the interpolation helpers do not check the valid set conditions.
- Limit fresh-secret generation to applications that accept every payload.
- Other applications MAY use rejection sampling on the last share.
- Do not recommend correcting errors in the human-readable part unless the application specifies how.
- Update the existing invalid vectors whose interpretation changes when other human-readable parts become valid, and list invalid master seeds separately from invalid codex32 strings.
- Add test vectors covering:
- the registered
clhuman-readable part used by Core Lightning; - checksum selection affected by human-readable-part length;
- an 83-character human-readable part containing
1; - the shortest human-readable part with an empty payload;
- the longest string with each checksum (expanded lengths 93 and 1023);
- expanded lengths 94 and 95;
- a checksum computed over an uppercase human-readable part;
- a human-readable part longer than 83 characters.
- the registered
Strings using ms are unchanged.
Testing
The codex32 checksum functions were checked against the previous ms32
functions for ms over random data parts, including both checksum variants.
The new vectors were checked with both the specification's Python code and an
independent implementation, python-codex32. They agree except that
python-codex32 does not yet enforce the 83-character human-readable-part
limit. The empty-payload and longest-string vectors were generated with the
specification's codex32_encode and checked with its codex32_decode.