bindable 0.0.7__tar.gz → 0.1.0__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.0/.gitignore +8 -0
- bindable-0.1.0/LICENSE +201 -0
- bindable-0.1.0/NOTICE +3 -0
- bindable-0.1.0/PKG-INFO +38 -0
- bindable-0.1.0/README.md +20 -0
- bindable-0.1.0/bindable/__init__.py +22 -0
- bindable-0.1.0/bindable/_canonical_record.py +78 -0
- bindable-0.1.0/bindable/_version.py +1 -0
- bindable-0.1.0/bindable/client.py +130 -0
- bindable-0.1.0/bindable/crypto/__init__.py +57 -0
- bindable-0.1.0/bindable/crypto/canonical.py +250 -0
- bindable-0.1.0/bindable/crypto/hash.py +42 -0
- bindable-0.1.0/bindable/crypto/keys.py +90 -0
- bindable-0.1.0/bindable/crypto/sign.py +90 -0
- bindable-0.1.0/bindable/errors.py +18 -0
- bindable-0.1.0/bindable/verify.py +251 -0
- bindable-0.1.0/pyproject.toml +23 -0
- bindable-0.1.0/tests/crypto/sign_vectors.json +35 -0
- bindable-0.1.0/tests/crypto/vectors.json +94 -0
- bindable-0.1.0/tests/fixtures/receipt_public_key.pem +4 -0
- bindable-0.1.0/tests/fixtures/receipt_released.json +30 -0
- bindable-0.1.0/tests/test_canonical_vectors.py +133 -0
- bindable-0.1.0/tests/test_client.py +193 -0
- bindable-0.1.0/tests/test_signature_verify.py +79 -0
- bindable-0.1.0/tests/test_verify_receipt.py +165 -0
- bindable-0.1.0/tests/test_version.py +5 -0
- bindable-0.0.7/.github/workflows/python-publish.yml +0 -70
- bindable-0.0.7/.gitignore +0 -174
- bindable-0.0.7/LICENSE +0 -674
- bindable-0.0.7/PKG-INFO +0 -66
- bindable-0.0.7/README.md +0 -53
- bindable-0.0.7/bindable/__init__.py +0 -4
- bindable-0.0.7/bindable/_main.py +0 -72
- bindable-0.0.7/pyproject.toml +0 -21
- bindable-0.0.7/test/bindable_test.py +0 -33
- {bindable-0.0.7 → bindable-0.1.0}/bindable/py.typed +0 -0
- {bindable-0.0.7/test → bindable-0.1.0/tests}/__init__.py +0 -0
bindable-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Bindable AI LLC
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
bindable-0.1.0/NOTICE
ADDED
bindable-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bindable
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for the hosted Bindable Action Gate, with offline Receipt verification
|
|
5
|
+
Author: Bindable AI LLC
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
License-File: NOTICE
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Requires-Dist: cryptography>=42
|
|
11
|
+
Requires-Dist: httpx>=0.27
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
14
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
15
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
16
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# bindable
|
|
20
|
+
|
|
21
|
+
Bindable Python client — propose, decide, and verify accountable agent actions against the hosted Bindable Action Gate. Offline receipt verification included.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
pip install bindable
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import bindable
|
|
33
|
+
|
|
34
|
+
# Submit a Proposal to the Bindable Action Gate, receive a Decision,
|
|
35
|
+
# record the Outcome, then verify the returned Receipt offline.
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Status: pre-release (0.1.0.dev0)
|
bindable-0.1.0/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# bindable
|
|
2
|
+
|
|
3
|
+
Bindable Python client — propose, decide, and verify accountable agent actions against the hosted Bindable Action Gate. Offline receipt verification included.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install bindable
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import bindable
|
|
15
|
+
|
|
16
|
+
# Submit a Proposal to the Bindable Action Gate, receive a Decision,
|
|
17
|
+
# record the Outcome, then verify the returned Receipt offline.
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Status: pre-release (0.1.0.dev0)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Bindable — Python client for the hosted Bindable Action Gate.
|
|
2
|
+
|
|
3
|
+
Submit a Proposal to the Bindable Action Gate via ``ActionGate.decide()``,
|
|
4
|
+
receive a Decision (the Outcome), and verify the returned Receipt offline with
|
|
5
|
+
``verify_receipt``. The client is pure transport; all proof-rule evaluation
|
|
6
|
+
happens on the hosted gate, and receipt verification is fully offline.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from ._version import __version__
|
|
10
|
+
from .client import ActionGate
|
|
11
|
+
from .crypto import load_public_key
|
|
12
|
+
from .errors import BindableAPIError
|
|
13
|
+
from .verify import ReceiptVerification, verify_receipt
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"ActionGate",
|
|
17
|
+
"BindableAPIError",
|
|
18
|
+
"ReceiptVerification",
|
|
19
|
+
"__version__",
|
|
20
|
+
"load_public_key",
|
|
21
|
+
"verify_receipt",
|
|
22
|
+
]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Canonical hash-input serialization for receipts (thin client).
|
|
2
|
+
|
|
3
|
+
Byte-faithful port of the engine's ``_canonical_hash_input``
|
|
4
|
+
(bindable-interlock-engine @ 5f129a6), adapted to read a receipt
|
|
5
|
+
delivered as a plain JSON dict from the hosted Bindable Action Gate
|
|
6
|
+
rather than as a pydantic ``Receipt``. The 15 included fields, the
|
|
7
|
+
§12.3 exclusions, and the field set match the engine EXACTLY so that
|
|
8
|
+
``canonical_sha256`` of this output is byte-identical across the
|
|
9
|
+
hosted gate and any offline verifier.
|
|
10
|
+
|
|
11
|
+
This module is NOT part of the public API.
|
|
12
|
+
|
|
13
|
+
verified_at handling (de-pydantic departure, behaviour-preserving):
|
|
14
|
+
In the engine, ``Receipt.verified_at`` is a ``datetime`` and the
|
|
15
|
+
builder calls ``_serialize_wire_datetime`` to produce the wire
|
|
16
|
+
string (YYYY-MM-DDTHH:MM:SS.sssZ). In the thin client the receipt
|
|
17
|
+
arrives from /v1/decide as JSON, so ``verified_at`` is ALREADY the
|
|
18
|
+
wire string. It is used verbatim — passing it back through a
|
|
19
|
+
datetime serializer would be a double-serialization bug. No
|
|
20
|
+
``datetime`` object can reach this path, so ``_serialize_wire_datetime``
|
|
21
|
+
is not ported here. The vectors.json production-shape record
|
|
22
|
+
(verified_at = "2026-05-19T14:00:00.000Z" hashed verbatim) confirms
|
|
23
|
+
the wire string is what the hash commits to.
|
|
24
|
+
|
|
25
|
+
Pure and deterministic: given a receipt mapping, returns a new dict
|
|
26
|
+
of wire-form fields with no I/O and no mutation. Canonical ordering
|
|
27
|
+
is applied downstream by ``canonical_json`` (alphabetical key sort),
|
|
28
|
+
so the literal order here is illustrative only.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from __future__ import annotations
|
|
32
|
+
|
|
33
|
+
from collections.abc import Mapping
|
|
34
|
+
from typing import Any
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _canonical_hash_input(receipt: Mapping[str, Any]) -> dict[str, Any]:
|
|
38
|
+
"""Return the canonical hash input dict per MVP spec §12.3.
|
|
39
|
+
|
|
40
|
+
Included fields (canonical_json sorts alphabetically):
|
|
41
|
+
action_type, claim_payload, contract_id, contract_version,
|
|
42
|
+
counterparty_identity, failed_rule, nonce,
|
|
43
|
+
persistent_agent_id, previous_hash, proposed_action_id,
|
|
44
|
+
referenced_evidence, sponsor_identity,
|
|
45
|
+
sponsor_identity_context, verification_outcome, verified_at.
|
|
46
|
+
|
|
47
|
+
Excluded per §12.3:
|
|
48
|
+
receipt_id, signature, signing_key_id, signed_at,
|
|
49
|
+
chain_hash (self-reference), reason_detail, claim_digest
|
|
50
|
+
(derivable from canonical claim_payload).
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
receipt: A receipt as a plain mapping (e.g. parsed JSON from
|
|
54
|
+
/v1/decide). All 15 included fields must be present;
|
|
55
|
+
nullable fields carry ``None``. ``verified_at`` must be
|
|
56
|
+
the wire-format string already.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
A dict of exactly the 15 canonical-hash-input fields, ready
|
|
60
|
+
to feed into ``canonical_sha256``.
|
|
61
|
+
"""
|
|
62
|
+
return {
|
|
63
|
+
"action_type": receipt["action_type"],
|
|
64
|
+
"claim_payload": receipt["claim_payload"],
|
|
65
|
+
"contract_id": receipt["contract_id"],
|
|
66
|
+
"contract_version": receipt["contract_version"],
|
|
67
|
+
"counterparty_identity": receipt["counterparty_identity"],
|
|
68
|
+
"failed_rule": receipt["failed_rule"],
|
|
69
|
+
"nonce": receipt["nonce"],
|
|
70
|
+
"persistent_agent_id": receipt["persistent_agent_id"],
|
|
71
|
+
"previous_hash": receipt["previous_hash"],
|
|
72
|
+
"proposed_action_id": receipt["proposed_action_id"],
|
|
73
|
+
"referenced_evidence": receipt["referenced_evidence"],
|
|
74
|
+
"sponsor_identity": receipt["sponsor_identity"],
|
|
75
|
+
"sponsor_identity_context": receipt["sponsor_identity_context"],
|
|
76
|
+
"verification_outcome": receipt["verification_outcome"],
|
|
77
|
+
"verified_at": receipt["verified_at"],
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Transport client for the hosted Bindable Action Gate.
|
|
2
|
+
|
|
3
|
+
``ActionGate.decide()`` submits a Proposal to ``POST /v1/decide`` and returns
|
|
4
|
+
the hosted Decision (the Outcome dict) verbatim. The client is pure transport:
|
|
5
|
+
it does NOT evaluate, canonicalize, or decide anything locally — all
|
|
6
|
+
proof-rule evaluation happens on the hosted gate. To verify the returned
|
|
7
|
+
receipt offline, hand ``outcome["receipt"]`` to ``bindable.verify_receipt``.
|
|
8
|
+
|
|
9
|
+
Runtime dependency: httpx only (plus cryptography via the verify path).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import secrets
|
|
15
|
+
from collections.abc import Mapping
|
|
16
|
+
from types import TracebackType
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
import httpx
|
|
20
|
+
|
|
21
|
+
from bindable.errors import BindableAPIError
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ActionGate:
|
|
25
|
+
"""Thin, token-authenticated httpx client for the hosted Bindable Action Gate.
|
|
26
|
+
|
|
27
|
+
Transports a Proposal to the hosted ``/v1/decide`` endpoint and returns the
|
|
28
|
+
Decision verbatim as a dict. The client performs no local evaluation,
|
|
29
|
+
canonicalization, or decision-making; offline receipt verification is a
|
|
30
|
+
separate concern handled by ``bindable.verify_receipt``.
|
|
31
|
+
|
|
32
|
+
Usage:
|
|
33
|
+
with ActionGate(base_url="https://gate.example.com", token="...") as gate:
|
|
34
|
+
outcome = gate.decide(
|
|
35
|
+
persistent_agent_id="agent_1",
|
|
36
|
+
action_type="send_invoice",
|
|
37
|
+
payload={"po_number": "PO-001", "amount": 1000},
|
|
38
|
+
proposed_action_id="claim_1",
|
|
39
|
+
)
|
|
40
|
+
# Offline verification of the returned receipt:
|
|
41
|
+
result = verify_receipt(outcome["receipt"])
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, *, base_url: str, token: str, timeout: float = 30.0) -> None:
|
|
45
|
+
self._base_url = base_url.rstrip("/")
|
|
46
|
+
self._token = token
|
|
47
|
+
self._client = httpx.Client(timeout=timeout)
|
|
48
|
+
|
|
49
|
+
def decide(
|
|
50
|
+
self,
|
|
51
|
+
*,
|
|
52
|
+
persistent_agent_id: str,
|
|
53
|
+
action_type: str,
|
|
54
|
+
payload: Mapping[str, Any],
|
|
55
|
+
proposed_action_id: str,
|
|
56
|
+
nonce: str | None = None,
|
|
57
|
+
) -> dict[str, Any]:
|
|
58
|
+
"""Submit a Proposal to ``/v1/decide`` and return the hosted Outcome dict.
|
|
59
|
+
|
|
60
|
+
Sends exactly the five wire fields (persistent_agent_id, action_type,
|
|
61
|
+
payload, proposed_action_id, nonce) with bearer-token auth. The Outcome
|
|
62
|
+
is returned verbatim; its ``receipt`` field (when present) can be passed
|
|
63
|
+
to ``verify_receipt`` for offline verification.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
persistent_agent_id: The stable agent identity.
|
|
67
|
+
action_type: The action being proposed.
|
|
68
|
+
payload: The action payload (sent as the ``payload`` field).
|
|
69
|
+
proposed_action_id: The caller's id for this proposed action.
|
|
70
|
+
nonce: Replay-protection nonce; a fresh ``secrets.token_hex(16)``
|
|
71
|
+
is generated when omitted.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
The parsed Outcome JSON object as a dict.
|
|
75
|
+
|
|
76
|
+
Raises:
|
|
77
|
+
BindableAPIError: If the gate returns a non-2xx response. The
|
|
78
|
+
error carries ``.status`` and the ``detail`` from the JSON body.
|
|
79
|
+
"""
|
|
80
|
+
if nonce is None:
|
|
81
|
+
nonce = secrets.token_hex(16)
|
|
82
|
+
body = {
|
|
83
|
+
"persistent_agent_id": persistent_agent_id,
|
|
84
|
+
"action_type": action_type,
|
|
85
|
+
"payload": dict(payload),
|
|
86
|
+
"proposed_action_id": proposed_action_id,
|
|
87
|
+
"nonce": nonce,
|
|
88
|
+
}
|
|
89
|
+
response = self._client.post(
|
|
90
|
+
f"{self._base_url}/v1/decide",
|
|
91
|
+
json=body,
|
|
92
|
+
headers={
|
|
93
|
+
"Authorization": f"Bearer {self._token}",
|
|
94
|
+
"Content-Type": "application/json",
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
if not response.is_success:
|
|
98
|
+
raise BindableAPIError(response.status_code, _extract_detail(response))
|
|
99
|
+
result: dict[str, Any] = response.json()
|
|
100
|
+
return result
|
|
101
|
+
|
|
102
|
+
def close(self) -> None:
|
|
103
|
+
"""Close the underlying httpx.Client."""
|
|
104
|
+
self._client.close()
|
|
105
|
+
|
|
106
|
+
def __enter__(self) -> ActionGate:
|
|
107
|
+
return self
|
|
108
|
+
|
|
109
|
+
def __exit__(
|
|
110
|
+
self,
|
|
111
|
+
exc_type: type[BaseException] | None,
|
|
112
|
+
exc: BaseException | None,
|
|
113
|
+
tb: TracebackType | None,
|
|
114
|
+
) -> None:
|
|
115
|
+
self.close()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _extract_detail(response: httpx.Response) -> str:
|
|
119
|
+
"""Pull the ``detail`` from an error JSON body, falling back to text.
|
|
120
|
+
|
|
121
|
+
The gate returns errors as ``{"detail": ...}``. ``detail`` may be a string
|
|
122
|
+
(401/403) or a structured value (422); it is stringified either way.
|
|
123
|
+
"""
|
|
124
|
+
try:
|
|
125
|
+
body = response.json()
|
|
126
|
+
except Exception: # noqa: BLE001 - non-JSON error body; fall back to text
|
|
127
|
+
return response.text or response.reason_phrase
|
|
128
|
+
if isinstance(body, dict) and "detail" in body:
|
|
129
|
+
return str(body["detail"])
|
|
130
|
+
return str(body)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Cryptographic primitives for the Bindable thin client.
|
|
2
|
+
|
|
3
|
+
This subpackage provides the deterministic, offline-verifiable
|
|
4
|
+
primitives used to recompute a receipt's chain_hash and to verify its
|
|
5
|
+
ECDSA P-256 signature. Per D6 these live under ``bindable.crypto`` and
|
|
6
|
+
are NOT re-exported at the top-level ``bindable`` namespace (except the
|
|
7
|
+
high-level ``verify_receipt`` / ``ReceiptVerification`` / ``load_public_key``
|
|
8
|
+
surface exposed by ``bindable`` directly).
|
|
9
|
+
|
|
10
|
+
Surface (stdlib + cryptography — no pydantic):
|
|
11
|
+
|
|
12
|
+
Type aliases:
|
|
13
|
+
PublicKey # alias for cryptography EllipticCurvePublicKey
|
|
14
|
+
|
|
15
|
+
Hashing (pure, stdlib only):
|
|
16
|
+
sha256_hex(data: bytes) -> str
|
|
17
|
+
canonicalize(value: Any) -> Any
|
|
18
|
+
canonical_json(record: Mapping[str, Any]) -> bytes
|
|
19
|
+
canonical_sha256(record: Mapping[str, Any]) -> str
|
|
20
|
+
|
|
21
|
+
Key loading (cryptography library):
|
|
22
|
+
load_public_key(pem_bytes: bytes) -> PublicKey
|
|
23
|
+
|
|
24
|
+
Signature verification (cryptography library):
|
|
25
|
+
verify(public_key, record, signature) -> bool
|
|
26
|
+
|
|
27
|
+
This is a VERIFY-ONLY surface: there is no signing, key generation, or
|
|
28
|
+
private-key handling client-side.
|
|
29
|
+
|
|
30
|
+
PATENT-CRITICAL: these primitives produce the canonical bytes a
|
|
31
|
+
receipt's chain_hash commits to and verify the signature over them.
|
|
32
|
+
The hashing primitives use only the Python standard library; key
|
|
33
|
+
loading and signature verification depend on the cryptography library,
|
|
34
|
+
which is pinned in [project] dependencies. All primitives operate
|
|
35
|
+
without network access.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
from __future__ import annotations
|
|
39
|
+
|
|
40
|
+
from bindable.crypto.canonical import (
|
|
41
|
+
canonical_json,
|
|
42
|
+
canonical_sha256,
|
|
43
|
+
canonicalize,
|
|
44
|
+
)
|
|
45
|
+
from bindable.crypto.hash import sha256_hex
|
|
46
|
+
from bindable.crypto.keys import PublicKey, load_public_key
|
|
47
|
+
from bindable.crypto.sign import verify
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"PublicKey",
|
|
51
|
+
"canonical_json",
|
|
52
|
+
"canonical_sha256",
|
|
53
|
+
"canonicalize",
|
|
54
|
+
"load_public_key",
|
|
55
|
+
"sha256_hex",
|
|
56
|
+
"verify",
|
|
57
|
+
]
|