|
7 | 7 |
|
8 | 8 | import pytest |
9 | 9 | from _codex32_oracle import oracle_encode |
| 10 | +from data.bip93_vectors import BIP93_GENERAL_HRP |
10 | 11 |
|
11 | 12 | from codex32 import ( |
12 | 13 | CorrectionContext, |
|
18 | 19 | recover_secret, |
19 | 20 | ) |
20 | 21 | from codex32.cli import main, ms_main |
21 | | -from codex32.errors import InvalidLength, MismatchedHrp, MismatchedProfile |
| 22 | +from codex32.errors import InvalidChecksum, InvalidLength, MismatchedHrp, MismatchedProfile |
22 | 23 | from tools._wallet_test_vectors import STUB_FINGERPRINT |
23 | 24 |
|
24 | 25 | UNKNOWN = { |
@@ -180,16 +181,31 @@ def fingerprint(_secret: object) -> bytes: |
180 | 181 | assert _invoke(ms_main, ["share", "d", "--plain"], basis)[0] == 2 |
181 | 182 |
|
182 | 183 |
|
183 | | -def test_83_character_hrp_may_span_printable_ascii() -> None: |
184 | | - pool = [chr(code) for code in range(33, 127) if not chr(code).isupper()] |
185 | | - hrp = "".join(pool[index % len(pool)] for index in range(83)) |
186 | | - assert "1" in hrp # the separator is the last "1", so an HRP may contain one |
187 | | - assert parse_codex32(oracle_encode(hrp, "0testsq")).hrp == hrp |
| 184 | +def test_bip93_generalized_hrp_share_vectors() -> None: |
| 185 | + share_a = parse_codex32(BIP93_GENERAL_HRP["share_a"]) |
| 186 | + share_c = parse_codex32(BIP93_GENERAL_HRP["share_c"]) |
| 187 | + assert share_a.hrp == share_c.hrp == "test_vector" |
| 188 | + assert recover_secret([share_a, share_c]).text == BIP93_GENERAL_HRP["secret_s"] |
| 189 | + assert derive_share([share_a, share_c], "d").text == BIP93_GENERAL_HRP["derived_d"] |
188 | 190 |
|
189 | 191 |
|
190 | | -def test_hrp_over_83_characters_is_rejected_at_the_bip173_limit() -> None: |
191 | | - within_limit = oracle_encode("z" * 83, "0testsq") |
192 | | - over_limit = oracle_encode("z" * 84, "0testsq") |
193 | | - assert parse_codex32(within_limit).hrp == "z" * 83 |
| 192 | +def test_bip93_generalized_hrp_boundary_vectors() -> None: |
| 193 | + valid = BIP93_GENERAL_HRP["valid_83"] |
| 194 | + invalid = BIP93_GENERAL_HRP["invalid_84"] |
| 195 | + artifact = parse_codex32(valid) |
| 196 | + |
| 197 | + assert len(artifact.hrp) == 83 |
| 198 | + assert artifact.hrp == valid.rsplit("1", 1)[0] |
| 199 | + with pytest.raises(InvalidLength): |
| 200 | + parse_codex32(invalid) |
| 201 | + |
| 202 | + |
| 203 | +@pytest.mark.parametrize("key", ("invalid_gap_regular", "invalid_gap_long")) |
| 204 | +def test_bip93_generalized_hrp_gap_vectors_are_invalid(key: str) -> None: |
194 | 205 | with pytest.raises(InvalidLength): |
195 | | - parse_codex32(over_limit) |
| 206 | + parse_codex32(BIP93_GENERAL_HRP[key]) |
| 207 | + |
| 208 | + |
| 209 | +def test_bip93_generalized_hrp_checksum_uses_lowercase_hrp() -> None: |
| 210 | + with pytest.raises(InvalidChecksum): |
| 211 | + parse_codex32(BIP93_GENERAL_HRP["invalid_uppercase_hrp_checksum"]) |
0 commit comments