From 5051283eae36542b5383e723a0532b8394e7b8b6 Mon Sep 17 00:00:00 2001 From: Ben Westgate Date: Mon, 21 Sep 2026 02:03:33 -0500 Subject: [PATCH] Require integer header thresholds Check the runtime threshold type before range membership so numerically equal floats cannot enter immutable BIP93 headers and fail later during symbol encoding. Security: strengthens the validated-artifact construction boundary without changing valid integer thresholds. Validation: focused public API and BIP93 tests; Ruff check and format; strict mypy. --- src/codex32/bip93.py | 6 +++++- tests/test_public_api.py | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/codex32/bip93.py b/src/codex32/bip93.py index b73a3ff..9e3757c 100644 --- a/src/codex32/bip93.py +++ b/src/codex32/bip93.py @@ -47,7 +47,11 @@ class Header: index: str def __post_init__(self) -> None: - if isinstance(self.threshold, bool) or self.threshold not in (0, *range(2, 10)): + if ( + isinstance(self.threshold, bool) + or not isinstance(self.threshold, int) + or self.threshold not in (0, *range(2, 10)) + ): raise InvalidThreshold("threshold must be 0 or an integer from 2 through 9") if not isinstance(self.identifier, str): raise InvalidIdentifier("identifier must be str") diff --git a/tests/test_public_api.py b/tests/test_public_api.py index 12f906a..09d66d4 100644 --- a/tests/test_public_api.py +++ b/tests/test_public_api.py @@ -115,6 +115,7 @@ def test_master_seed_factory_can_only_construct_index_s() -> None: ("arguments", "error"), ( ((1, "test", "s"), InvalidThreshold), + ((2.0, "test", "a"), InvalidThreshold), ((2, "bad", "a"), InvalidIdentifier), ((0, "test", "a"), InvalidShareIndex), ),