Skip to content

Commit 096a3e0

Browse files
Codex AgentBenWestgate
authored andcommitted
wallet: Mark unavailable Bails check inconclusive
When RIPEMD-160 is unavailable, a valid standard Bails identifier cannot be checked. Preserve the Bails-alpha SHA-256 result and distinguish that inconclusive state from a completed identifier mismatch, so the no-record restore prompt does not claim the cards are wrong. Keep the independent fingerprint and explicit operator-confirmation boundary unchanged. Refs #79
1 parent 37eef4d commit 096a3e0

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎src/codex32/_bitcoin_core.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ def parse_fingerprint(text: str) -> bytes:
6060

6161
def identifier_note(origin: str | None) -> str:
6262
# Say what `identifier_origin` found, for an operator restoring without a record.
63+
if origin == "Bails check unavailable":
64+
return (
65+
"The standard Bails identifier could not be checked because RIPEMD-160 is unavailable. "
66+
"This does not prove the cards are wrong or mixed up. Compare the fingerprint and any "
67+
"other wallet record you have before restoring."
68+
)
6369
if origin is None:
6470
return (
6571
"The backup identifier was not made from this seed. That can be normal for codex32 backups "
@@ -77,15 +83,18 @@ def identifier_origin(secret: MasterSeed, fingerprint: bytes) -> str | None:
7783
identifier = secret.header.identifier
7884
if identifier == _fingerprint_identifier(fingerprint):
7985
return "codex32"
86+
ripemd_unavailable = False
8087
for name, digest in (("Bails", "ripemd160"), ("Bails alpha", "sha256")):
8188
try:
8289
hashed = hashlib.new(digest, secret.seed_bytes).digest()
8390
except ValueError:
91+
if name == "Bails":
92+
ripemd_unavailable = True
8493
continue
8594
derived = convertbits(hashed, 8, 5, pad=True)
8695
if identifier[:3] == _u5_to_chars(tuple(derived[:3])):
8796
return name
88-
return None
97+
return "Bails check unavailable" if ripemd_unavailable else None
8998

9099

91100
@dataclass(frozen=True)

‎tests/test_bitcoin_core.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,13 @@ def test_identifier_origin_names_the_rule_that_made_it(identifier: str, origin:
843843
assert ("matches this seed" in identifier_note(origin)) is (origin is not None)
844844

845845

846-
def test_identifier_origin_still_checks_alpha_without_ripemd160(monkeypatch: pytest.MonkeyPatch) -> None:
846+
@pytest.mark.parametrize(
847+
("identifier", "expected"),
848+
(("hezu", "Bails alpha"), ("d9k8", "Bails check unavailable")),
849+
)
850+
def test_identifier_origin_without_ripemd160(
851+
monkeypatch: pytest.MonkeyPatch, identifier: str, expected: str
852+
) -> None:
847853
original_new = hashlib.new
848854

849855
def without_ripemd160(name: str, data: bytes = b"") -> object:
@@ -852,8 +858,11 @@ def without_ripemd160(name: str, data: bytes = b"") -> object:
852858
return original_new(name, data)
853859

854860
monkeypatch.setattr(hashlib, "new", without_ripemd160)
855-
secret = MasterSeed.from_seed(_BAILS_SEED, identifier="hezu")
856-
assert identifier_origin(secret, _FINGERPRINT) == "Bails alpha"
861+
secret = MasterSeed.from_seed(_BAILS_SEED, identifier=identifier)
862+
assert identifier_origin(secret, _FINGERPRINT) == expected
863+
if expected == "Bails check unavailable":
864+
assert "could not be checked" in identifier_note(expected)
865+
assert "does not prove" in identifier_note(expected)
857866

858867

859868
def test_identifier_note_allows_supported_nonderived_codex32_identifiers() -> None:

0 commit comments

Comments
 (0)