bindable 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bindable-0.1.2 → bindable-0.1.3}/PKG-INFO +1 -1
- {bindable-0.1.2 → bindable-0.1.3}/bindable/__init__.py +9 -3
- bindable-0.1.3/bindable/_version.py +1 -0
- bindable-0.1.3/bindable/decision.py +75 -0
- {bindable-0.1.2 → bindable-0.1.3}/pyproject.toml +1 -1
- bindable-0.1.3/tests/test_decision_from.py +104 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/test_version.py +1 -1
- bindable-0.1.2/bindable/_version.py +0 -1
- {bindable-0.1.2 → bindable-0.1.3}/.gitignore +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/LICENSE +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/NOTICE +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/README.md +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/bindable/_canonical_record.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/bindable/client.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/bindable/crypto/__init__.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/bindable/crypto/canonical.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/bindable/crypto/hash.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/bindable/crypto/keys.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/bindable/crypto/sign.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/bindable/errors.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/bindable/py.typed +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/bindable/verify.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/__init__.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/crypto/sign_vectors.json +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/crypto/vectors.json +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/fixtures/KEY_PROVENANCE.md +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/fixtures/bindable-test-rc4-2026-08.pem +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/fixtures/receipt_public_blocked_rc4.json +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/fixtures/receipt_public_released_rc4.json +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/test_canonical_vectors.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/test_client.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/test_signature_verify.py +0 -0
- {bindable-0.1.2 → bindable-0.1.3}/tests/test_verify_receipt.py +0 -0
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
"""Bindable — Python client for the hosted Bindable Action Gate.
|
|
2
2
|
|
|
3
3
|
Submit a Proposal to the Bindable Action Gate via ``ActionGate.decide()``,
|
|
4
|
-
receive
|
|
5
|
-
``verify_receipt``.
|
|
6
|
-
|
|
4
|
+
receive an Outcome, and verify the returned Receipt offline with
|
|
5
|
+
``verify_receipt``. Derive the Decision — released or blocked — from the
|
|
6
|
+
signed Receipt with ``decision_from``. The client is pure transport; all
|
|
7
|
+
proof-rule evaluation happens on the hosted gate, and receipt verification
|
|
8
|
+
is fully offline.
|
|
7
9
|
"""
|
|
8
10
|
|
|
9
11
|
from ._version import __version__
|
|
10
12
|
from .client import ActionGate
|
|
11
13
|
from .crypto import load_public_key
|
|
14
|
+
from .decision import BLOCKED, RELEASED, decision_from
|
|
12
15
|
from .errors import BindableAPIError
|
|
13
16
|
from .verify import ReceiptVerification, verify_receipt
|
|
14
17
|
|
|
15
18
|
__all__ = [
|
|
19
|
+
"BLOCKED",
|
|
20
|
+
"RELEASED",
|
|
16
21
|
"ActionGate",
|
|
17
22
|
"BindableAPIError",
|
|
18
23
|
"ReceiptVerification",
|
|
19
24
|
"__version__",
|
|
25
|
+
"decision_from",
|
|
20
26
|
"load_public_key",
|
|
21
27
|
"verify_receipt",
|
|
22
28
|
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.3"
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""The published derivation of a Decision from a signed Receipt.
|
|
2
|
+
|
|
3
|
+
The Action Review does not return released/blocked. Callers derive it from
|
|
4
|
+
the Receipt, by this rule and only this rule:
|
|
5
|
+
|
|
6
|
+
released iff verdict == "passed"
|
|
7
|
+
blocked for every other verdict, and for any Receipt that cannot be
|
|
8
|
+
obtained or read.
|
|
9
|
+
|
|
10
|
+
This is the CANONICAL, PUBLIC derivation. It is deliberately small enough
|
|
11
|
+
to reimplement in any language — TypeScript, Go, Rust, Java — in a few
|
|
12
|
+
lines, and any such reimplementation MUST behave identically:
|
|
13
|
+
|
|
14
|
+
// TypeScript, equivalent by construction
|
|
15
|
+
const decisionFrom = (r: any): "released" | "blocked" =>
|
|
16
|
+
r?.verdict === "passed" ? "released" : "blocked";
|
|
17
|
+
|
|
18
|
+
Two properties are load-bearing and must be preserved in every port:
|
|
19
|
+
|
|
20
|
+
1. The comparison is EXACT. ``"passed"`` releases; ``"Passed"``,
|
|
21
|
+
``"PASSED"``, ``" passed"``, and ``True`` do not. Leniency here would
|
|
22
|
+
let two implementations disagree about the same Receipt.
|
|
23
|
+
2. Blocked is the SAFE DEFAULT. A missing verdict, an unreadable Receipt,
|
|
24
|
+
a null, a non-mapping, or anything unexpected yields "blocked". This
|
|
25
|
+
function never raises and never returns "released" on ambiguity.
|
|
26
|
+
|
|
27
|
+
Reading the verdict is all this does. It performs no I/O, no
|
|
28
|
+
canonicalization, and no cryptography, and it does not establish that the
|
|
29
|
+
Receipt is authentic — pair it with ``verify_receipt`` when the Receipt's
|
|
30
|
+
integrity matters.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
from __future__ import annotations
|
|
34
|
+
|
|
35
|
+
from collections.abc import Mapping
|
|
36
|
+
from typing import Any
|
|
37
|
+
|
|
38
|
+
#: The Decision vocabulary. These exact strings are the wire words.
|
|
39
|
+
RELEASED = "released"
|
|
40
|
+
BLOCKED = "blocked"
|
|
41
|
+
|
|
42
|
+
#: The one verdict value that releases an action.
|
|
43
|
+
PASSED = "passed"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def decision_from(receipt: Mapping[str, Any] | None) -> str:
|
|
47
|
+
"""Derive the Decision from a Receipt: ``"released"`` or ``"blocked"``.
|
|
48
|
+
|
|
49
|
+
Returns ``"released"`` if and only if the Receipt's ``verdict`` field
|
|
50
|
+
is exactly ``"passed"``. Everything else — any other verdict, a
|
|
51
|
+
missing field, an unreadable or absent Receipt — is ``"blocked"``.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
receipt: A Receipt as a plain mapping, the same shape
|
|
55
|
+
``verify_receipt`` takes (for example ``outcome["receipt"]``
|
|
56
|
+
parsed from JSON). ``None`` and malformed values are accepted
|
|
57
|
+
and yield ``"blocked"``.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
``"released"`` or ``"blocked"``. Never raises.
|
|
61
|
+
|
|
62
|
+
Example:
|
|
63
|
+
>>> from bindable import decision_from, verify_receipt
|
|
64
|
+
>>> receipt = outcome["receipt"]
|
|
65
|
+
>>> if verify_receipt(receipt, public_key=pem).valid:
|
|
66
|
+
... if decision_from(receipt) == "released":
|
|
67
|
+
... run_the_action()
|
|
68
|
+
'released'
|
|
69
|
+
"""
|
|
70
|
+
try:
|
|
71
|
+
if not isinstance(receipt, Mapping):
|
|
72
|
+
return BLOCKED
|
|
73
|
+
return RELEASED if receipt.get("verdict") == PASSED else BLOCKED
|
|
74
|
+
except Exception: # noqa: BLE001 - fail-closed: never raise, never release
|
|
75
|
+
return BLOCKED
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""decision_from — the published released/blocked derivation.
|
|
2
|
+
|
|
3
|
+
This rule is reimplemented by counterparties in other languages, so these
|
|
4
|
+
tests pin it precisely: exactly one verdict releases, everything else
|
|
5
|
+
blocks, and nothing raises.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
from bindable import BLOCKED, RELEASED, decision_from
|
|
17
|
+
|
|
18
|
+
_FIX = Path(__file__).parent / "fixtures"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# ─── The rule ──────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_passed_verdict_releases() -> None:
|
|
25
|
+
assert decision_from({"verdict": "passed"}) == "released"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.mark.parametrize("verdict", ["failed", "error", "exception"])
|
|
29
|
+
def test_every_other_verdict_blocks(verdict: str) -> None:
|
|
30
|
+
assert decision_from({"verdict": verdict}) == "blocked"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_missing_verdict_key_blocks() -> None:
|
|
34
|
+
"""Fail-closed: an absent verdict is never a release."""
|
|
35
|
+
assert decision_from({}) == "blocked"
|
|
36
|
+
assert decision_from({"receipt_id": "r1", "chain_hash": "ab" * 32}) == "blocked"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@pytest.mark.parametrize("receipt", [
|
|
40
|
+
None,
|
|
41
|
+
"not a receipt",
|
|
42
|
+
["not", "a", "receipt"],
|
|
43
|
+
42,
|
|
44
|
+
object(),
|
|
45
|
+
])
|
|
46
|
+
def test_unreadable_receipt_blocks_without_raising(receipt: Any) -> None:
|
|
47
|
+
"""'Any Receipt that cannot be obtained or read' -> blocked."""
|
|
48
|
+
assert decision_from(receipt) == "blocked"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@pytest.mark.parametrize("verdict", ["Passed", "PASSED", " passed", "passed ", True, 1, None])
|
|
52
|
+
def test_comparison_is_exact(verdict: Any) -> None:
|
|
53
|
+
"""Near-misses must NOT release — leniency would let ports disagree."""
|
|
54
|
+
assert decision_from({"verdict": verdict}) == "blocked"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_only_ever_returns_the_two_wire_words() -> None:
|
|
58
|
+
for receipt in ({"verdict": "passed"}, {"verdict": "failed"}, {}, None):
|
|
59
|
+
assert decision_from(receipt) in {RELEASED, BLOCKED}
|
|
60
|
+
assert (RELEASED, BLOCKED) == ("released", "blocked")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_a_verdict_whose_equality_explodes_still_blocks() -> None:
|
|
64
|
+
"""The function never raises, whatever it is handed."""
|
|
65
|
+
|
|
66
|
+
class Hostile:
|
|
67
|
+
def __eq__(self, other: object) -> bool:
|
|
68
|
+
raise RuntimeError("boom")
|
|
69
|
+
|
|
70
|
+
assert decision_from({"verdict": Hostile()}) == "blocked"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# ─── Against real minted Receipts ──────────────────────────────────────
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@pytest.mark.parametrize("filename,expected", [
|
|
77
|
+
("receipt_public_released_rc4.json", "released"),
|
|
78
|
+
("receipt_public_blocked_rc4.json", "blocked"),
|
|
79
|
+
])
|
|
80
|
+
def test_real_minted_receipts_derive_the_right_decision(
|
|
81
|
+
filename: str, expected: str
|
|
82
|
+
) -> None:
|
|
83
|
+
receipt = json.loads((_FIX / filename).read_text(encoding="utf-8"))
|
|
84
|
+
assert decision_from(receipt) == expected
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_the_derivation_tracks_the_verdict_field_specifically() -> None:
|
|
88
|
+
"""A released Receipt whose verdict is altered derives blocked.
|
|
89
|
+
|
|
90
|
+
(Altering it also breaks the chain hash — that is verify_receipt's job,
|
|
91
|
+
not this function's. decision_from reads the verdict, nothing more.)
|
|
92
|
+
"""
|
|
93
|
+
receipt = json.loads(
|
|
94
|
+
(_FIX / "receipt_public_released_rc4.json").read_text(encoding="utf-8")
|
|
95
|
+
)
|
|
96
|
+
assert decision_from(receipt) == "released"
|
|
97
|
+
receipt["verdict"] = "failed"
|
|
98
|
+
assert decision_from(receipt) == "blocked"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_derivation_does_not_depend_on_status_or_failed_rule() -> None:
|
|
102
|
+
"""Only the verdict decides — no other field participates."""
|
|
103
|
+
assert decision_from({"verdict": "passed", "failed_rule": "r-2"}) == "released"
|
|
104
|
+
assert decision_from({"verdict": "failed", "status": "released"}) == "blocked"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|