agent-warrant 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.
Files changed (46) hide show
  1. agent_warrant-0.1.0/LICENSE +202 -0
  2. agent_warrant-0.1.0/PKG-INFO +127 -0
  3. agent_warrant-0.1.0/README.md +102 -0
  4. agent_warrant-0.1.0/agent_warrant/__init__.py +46 -0
  5. agent_warrant-0.1.0/agent_warrant/canonical.py +224 -0
  6. agent_warrant-0.1.0/agent_warrant/chain.py +458 -0
  7. agent_warrant-0.1.0/agent_warrant/encoding.py +44 -0
  8. agent_warrant-0.1.0/agent_warrant/exceptions.py +19 -0
  9. agent_warrant-0.1.0/agent_warrant/grant.py +276 -0
  10. agent_warrant-0.1.0/agent_warrant/https_fetch.py +133 -0
  11. agent_warrant-0.1.0/agent_warrant/identity.py +87 -0
  12. agent_warrant-0.1.0/agent_warrant/issuer.py +92 -0
  13. agent_warrant-0.1.0/agent_warrant/ledger.py +723 -0
  14. agent_warrant-0.1.0/agent_warrant/py.typed +0 -0
  15. agent_warrant-0.1.0/agent_warrant/resolver.py +313 -0
  16. agent_warrant-0.1.0/agent_warrant/revocation.py +340 -0
  17. agent_warrant-0.1.0/agent_warrant/scope.py +110 -0
  18. agent_warrant-0.1.0/agent_warrant/task_root.py +226 -0
  19. agent_warrant-0.1.0/agent_warrant/trust.py +118 -0
  20. agent_warrant-0.1.0/agent_warrant.egg-info/PKG-INFO +127 -0
  21. agent_warrant-0.1.0/agent_warrant.egg-info/SOURCES.txt +44 -0
  22. agent_warrant-0.1.0/agent_warrant.egg-info/dependency_links.txt +1 -0
  23. agent_warrant-0.1.0/agent_warrant.egg-info/requires.txt +6 -0
  24. agent_warrant-0.1.0/agent_warrant.egg-info/top_level.txt +1 -0
  25. agent_warrant-0.1.0/pyproject.toml +42 -0
  26. agent_warrant-0.1.0/setup.cfg +4 -0
  27. agent_warrant-0.1.0/tests/test_canonical.py +49 -0
  28. agent_warrant-0.1.0/tests/test_chain.py +983 -0
  29. agent_warrant-0.1.0/tests/test_chain_vectors.py +70 -0
  30. agent_warrant-0.1.0/tests/test_grant.py +464 -0
  31. agent_warrant-0.1.0/tests/test_https_fetch.py +256 -0
  32. agent_warrant-0.1.0/tests/test_identity_keys.py +139 -0
  33. agent_warrant-0.1.0/tests/test_integration.py +89 -0
  34. agent_warrant-0.1.0/tests/test_ledger.py +325 -0
  35. agent_warrant-0.1.0/tests/test_ledger_files.py +504 -0
  36. agent_warrant-0.1.0/tests/test_ledger_race.py +132 -0
  37. agent_warrant-0.1.0/tests/test_ledger_reserve.py +607 -0
  38. agent_warrant-0.1.0/tests/test_property.py +201 -0
  39. agent_warrant-0.1.0/tests/test_resolver.py +474 -0
  40. agent_warrant-0.1.0/tests/test_revocation.py +384 -0
  41. agent_warrant-0.1.0/tests/test_scope.py +284 -0
  42. agent_warrant-0.1.0/tests/test_strict_decode.py +305 -0
  43. agent_warrant-0.1.0/tests/test_task_root.py +470 -0
  44. agent_warrant-0.1.0/tests/test_task_root_vectors.py +47 -0
  45. agent_warrant-0.1.0/tests/test_trust.py +269 -0
  46. agent_warrant-0.1.0/tests/test_vectors.py +85 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,127 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-warrant
3
+ Version: 0.1.0
4
+ Summary: A portable, cryptographically-verifiable authority grant for AI agents -- cross-org, no shared infrastructure.
5
+ Author: voltagebots
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/agent-rails/agent-warrant
8
+ Project-URL: Repository, https://github.com/agent-rails/agent-warrant
9
+ Project-URL: Issues, https://github.com/agent-rails/agent-warrant/issues
10
+ Keywords: ai,agents,authorization,identity,verifiable-credentials,security
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Security
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: cryptography>=42
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest>=8; extra == "dev"
22
+ Requires-Dist: ruff>=0.6; extra == "dev"
23
+ Requires-Dist: hypothesis>=6.100; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # agent-warrant
27
+
28
+ A portable, cryptographically-verifiable authority grant for AI agents — cross-org, no shared infrastructure.
29
+
30
+ Lets one team's AI agent cryptographically verify another team's agent's delegated authority, with no shared secret. Ships two `IssuerResolver` implementations: out-of-band issuer-key pinning via `PinnedResolver` (TOFU), and real trust bootstrap via `DidWebResolver` (HTTPS + domain ownership, per the [did:web method spec](https://w3c-ccg.github.io/did-method-web/)). Also ships opt-in revocation checking (`RevocationChecker`) — pre-expiry invalidation of a specific `Grant`, checked as the last gate in `verify()`. Spun out of [`agent-guard`](https://github.com/agent-rails/agent-guard) (which stays the local, single-org authorization/audit boundary) specifically because cross-org verification needs a different crypto trust model — asymmetric signing, not a shared HMAC secret.
31
+
32
+ Deeper reference: [`docs/DESIGN.md`](docs/DESIGN.md) (why it's shaped this way, including the design history — what was tried, what was corrected, and why), [`docs/THREAT_MODEL.md`](docs/THREAT_MODEL.md) (what's defended, what's explicitly not).
33
+
34
+ ## The shape
35
+
36
+ - A `Grant` is issuer-signed (Ed25519), scoped, expiring — VC-data-model-*shaped*, not VC-spec-conformant (no `credentialStatus` field on the Grant itself; see THREAT_MODEL.md). Revocation checking exists, but as a separate, opt-in gate `verify()` runs against a caller-supplied `RevocationChecker` — not as data carried on the credential.
37
+ - `subject` is the holder's public key — but a Grant alone is still a bearer credential unless paired with a fresh `PossessionProof` at verification time, proving the presenter actually holds the matching private key.
38
+ - `IssuerResolver` resolves an issuer identifier to a public key. `PinnedResolver` — honestly named: it performs zero trust verification, it's out-of-band key pinning (TOFU). `DidWebResolver` is real trust bootstrap via HTTPS + domain ownership: it fetches `https://<domain>/.well-known/did.json` (or a path-scoped variant, e.g. `example.com:agents:team-a` → `https://example.com/agents/team-a/did.json`) and extracts an Ed25519 key from the DID document — binding selection to the document's `id`, the method's `controller`, and any declared `assertionMethod`, not array order. Every failure (DNS/HTTP error, non-200 status, `id` mismatch, malformed document, wrong key type, ambiguous or no matching `verificationMethod`) fails closed as `UnresolvableIssuer`.
39
+ - Revocation is opt-in: a `Verifier` constructed without a `revocation_checker` behaves exactly as before this existed — TTL is the only expiry mechanism. Opting in means the issuer publishes a `RevocationList` (a signed set of revoked `grant_binding` values carrying a signed `issued_at`/`expires_at`/monotonic `sequence` — see `sign_revocation_list()`), and a caller wires up `StaticRevocationChecker` (for an already-fetched list) or `HttpRevocationChecker` (fetches + verifies on every `is_revoked()` call, no caching). Any inability to determine revocation status — fetch failure, malformed list, bad signature, a stale/expired or rolled-back list, or a list whose issuer doesn't match the grant's — fails closed: the grant is rejected, never silently treated as "not revoked." `StaticRevocationChecker` checks freshness only when it is constructed and keeps answering from that list afterwards; replace it before the list's `expires_at`.
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ pip install agent-warrant
45
+ ```
46
+
47
+ ## Development
48
+
49
+ Dev dependencies (pytest, ruff, hypothesis) are the `dev` extra. Quote the extra so the shell does not expand the brackets:
50
+
51
+ ```bash
52
+ uv venv
53
+ uv pip install -e '.[dev]' # or, inside any venv: pip install -e '.[dev]'
54
+ .venv/bin/ruff check
55
+ .venv/bin/ruff format --check
56
+ .venv/bin/pytest -q
57
+ ```
58
+
59
+ ## Quickstart
60
+
61
+ ```python
62
+ from agent_warrant import Issuer, HolderKeypair, PinnedResolver, Verifier, generate_keypair, encode_public_key
63
+
64
+ # Team A: mints a grant for a holder it doesn't need to share any secret with.
65
+ team_a_key = generate_keypair()
66
+ issuer = Issuer(issuer_id="team-a", private_key=team_a_key)
67
+
68
+ holder_key = generate_keypair()
69
+ holder = HolderKeypair(holder_key)
70
+ grant = issuer.issue(subject=encode_public_key(holder_key.public_key()), scope={"tool": "read_file"})
71
+ proof = holder.prove_possession(grant)
72
+
73
+ # Team B: only ever obtains team A's PUBLIC key, out-of-band. No shared secret.
74
+ # `path_prefix` is illustrative application data: agent-warrant authenticates
75
+ # the scope but does not interpret or enforce it for authorization.
76
+ resolver = PinnedResolver({"team-a": team_a_key.public_key()})
77
+ verifier = Verifier(resolver)
78
+
79
+ result = verifier.check(grant.encode(), proof)
80
+ assert result.valid
81
+ ```
82
+
83
+ A stolen `grant.encode()` string alone is not enough — presenting it without a valid `PossessionProof` (or with a proof forged by a different keypair) is rejected. See `tests/test_integration.py::test_stolen_grant_without_possession_proof_is_rejected` for the live proof.
84
+
85
+ ### did:web, instead of pinning
86
+
87
+ ```python
88
+ from agent_warrant import DidWebResolver, Verifier
89
+
90
+ # No out-of-band key exchange -- team-a's key is fetched from
91
+ # https://team-a.example.com/.well-known/did.json and cryptographically
92
+ # tied to domain ownership over HTTPS, the same trust model TLS uses.
93
+ resolver = DidWebResolver()
94
+ verifier = Verifier(resolver)
95
+ result = verifier.check(grant.encode(), proof) # grant.issuer == "team-a.example.com"
96
+ ```
97
+
98
+ ### Revocation, opt-in
99
+
100
+ ```python
101
+ from agent_warrant import StaticRevocationChecker, Verifier, sign_revocation_list
102
+
103
+ # Team A decides to invalidate a specific grant before its TTL expires
104
+ # (compromised holder key, mistaken scope, ended sponsorship) and signs a
105
+ # RevocationList naming it -- by grant_binding, this project's stable
106
+ # identity for a specific Grant (see PossessionProof.grant_binding).
107
+ revocation_list = sign_revocation_list("team-a", [proof.grant_binding], team_a_key)
108
+
109
+ # Team B opts in by wiring a RevocationChecker into its Verifier. Without
110
+ # this, revocation is never checked -- default behavior is unchanged.
111
+ checker = StaticRevocationChecker(revocation_list, resolver)
112
+ verifier = Verifier(resolver, revocation_checker=checker)
113
+ result = verifier.check(grant.encode(), proof)
114
+ assert result.valid is False and "revoked" in result.reason
115
+ ```
116
+
117
+ `HttpRevocationChecker` + `HttpRevocationListFetcher` do the same thing over HTTPS instead of an in-process `RevocationList` -- fetching and re-verifying the signed list on every `is_revoked()` call, no caching. If the revocation endpoint is unreachable, verification fails closed (rejected), not open.
118
+
119
+ ## Constraints worth knowing before you hit them
120
+
121
+ - **Encoded grant size**: capped at `agent_warrant.grant.MAX_ENCODED_GRANT_BYTES` (16KB). A compact authority claim never legitimately needs more — if your `scope` is large enough to hit this, reconsider what you're encoding into it rather than raising the constant (it's load-bearing for a resource-exhaustion defense, see docs/THREAT_MODEL.md).
122
+ - **`DidWebResolver` fetches on every `resolve()` call, no caching.** And because `grant.issuer` reaches `resolver.resolve()` before any signature check, an unauthenticated grant can make the verifying process issue an outbound HTTPS request to an attacker-influenced host. `https_fetch.py` resolves the host once, rejects the fetch if any resolved address is private/loopback/link-local/reserved/multicast/unspecified, pins the screened IP, and connects to it directly while verifying TLS against the original hostname (SSRF hardening; this closes the DNS-rebinding TOCTOU a check-then-connect pattern would have). A wall-clock watchdog bounds the total time any single fetch can consume against a slow-drip host. See docs/THREAT_MODEL.md for the remaining residual (the DNS-resolution step uses the OS resolver's own timeout).
123
+ - **Revocation is opt-in and unbundled from StatusList2021.** It's a small signed set of revoked `grant_binding` values, sized for a known, bounded cross-org verifier population -- not the anonymity-preserving bitstring StatusList2021 uses for public, anonymous-verifier scale. See docs/DESIGN.md for why that tradeoff fits this project's actual shape.
124
+
125
+ ## Design history worth knowing before extending this
126
+
127
+ This design went through two real review cycles (documented in full at `~/identity-unification-plan.md` in the originating session) before any code was written. The most important correction: an earlier draft called `subject = holder's public key` alone "holder-binding" — it wasn't. A public key sitting in an issuer-signed credential with no separate possession check at verification time is still a bearer credential; anyone who intercepts the encoded grant can replay it. `PossessionProof` exists specifically to close that gap, mirroring `agent-guard`'s own `PoPProof`/`verify_pop` pattern. Read `docs/DESIGN.md` before changing anything in `grant.py`'s `verify()` — most of its structure (narrow exception catches, version-check-first ordering, the iat type guard) is there because a specific finding required it, not by convention.
@@ -0,0 +1,102 @@
1
+ # agent-warrant
2
+
3
+ A portable, cryptographically-verifiable authority grant for AI agents — cross-org, no shared infrastructure.
4
+
5
+ Lets one team's AI agent cryptographically verify another team's agent's delegated authority, with no shared secret. Ships two `IssuerResolver` implementations: out-of-band issuer-key pinning via `PinnedResolver` (TOFU), and real trust bootstrap via `DidWebResolver` (HTTPS + domain ownership, per the [did:web method spec](https://w3c-ccg.github.io/did-method-web/)). Also ships opt-in revocation checking (`RevocationChecker`) — pre-expiry invalidation of a specific `Grant`, checked as the last gate in `verify()`. Spun out of [`agent-guard`](https://github.com/agent-rails/agent-guard) (which stays the local, single-org authorization/audit boundary) specifically because cross-org verification needs a different crypto trust model — asymmetric signing, not a shared HMAC secret.
6
+
7
+ Deeper reference: [`docs/DESIGN.md`](docs/DESIGN.md) (why it's shaped this way, including the design history — what was tried, what was corrected, and why), [`docs/THREAT_MODEL.md`](docs/THREAT_MODEL.md) (what's defended, what's explicitly not).
8
+
9
+ ## The shape
10
+
11
+ - A `Grant` is issuer-signed (Ed25519), scoped, expiring — VC-data-model-*shaped*, not VC-spec-conformant (no `credentialStatus` field on the Grant itself; see THREAT_MODEL.md). Revocation checking exists, but as a separate, opt-in gate `verify()` runs against a caller-supplied `RevocationChecker` — not as data carried on the credential.
12
+ - `subject` is the holder's public key — but a Grant alone is still a bearer credential unless paired with a fresh `PossessionProof` at verification time, proving the presenter actually holds the matching private key.
13
+ - `IssuerResolver` resolves an issuer identifier to a public key. `PinnedResolver` — honestly named: it performs zero trust verification, it's out-of-band key pinning (TOFU). `DidWebResolver` is real trust bootstrap via HTTPS + domain ownership: it fetches `https://<domain>/.well-known/did.json` (or a path-scoped variant, e.g. `example.com:agents:team-a` → `https://example.com/agents/team-a/did.json`) and extracts an Ed25519 key from the DID document — binding selection to the document's `id`, the method's `controller`, and any declared `assertionMethod`, not array order. Every failure (DNS/HTTP error, non-200 status, `id` mismatch, malformed document, wrong key type, ambiguous or no matching `verificationMethod`) fails closed as `UnresolvableIssuer`.
14
+ - Revocation is opt-in: a `Verifier` constructed without a `revocation_checker` behaves exactly as before this existed — TTL is the only expiry mechanism. Opting in means the issuer publishes a `RevocationList` (a signed set of revoked `grant_binding` values carrying a signed `issued_at`/`expires_at`/monotonic `sequence` — see `sign_revocation_list()`), and a caller wires up `StaticRevocationChecker` (for an already-fetched list) or `HttpRevocationChecker` (fetches + verifies on every `is_revoked()` call, no caching). Any inability to determine revocation status — fetch failure, malformed list, bad signature, a stale/expired or rolled-back list, or a list whose issuer doesn't match the grant's — fails closed: the grant is rejected, never silently treated as "not revoked." `StaticRevocationChecker` checks freshness only when it is constructed and keeps answering from that list afterwards; replace it before the list's `expires_at`.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ pip install agent-warrant
20
+ ```
21
+
22
+ ## Development
23
+
24
+ Dev dependencies (pytest, ruff, hypothesis) are the `dev` extra. Quote the extra so the shell does not expand the brackets:
25
+
26
+ ```bash
27
+ uv venv
28
+ uv pip install -e '.[dev]' # or, inside any venv: pip install -e '.[dev]'
29
+ .venv/bin/ruff check
30
+ .venv/bin/ruff format --check
31
+ .venv/bin/pytest -q
32
+ ```
33
+
34
+ ## Quickstart
35
+
36
+ ```python
37
+ from agent_warrant import Issuer, HolderKeypair, PinnedResolver, Verifier, generate_keypair, encode_public_key
38
+
39
+ # Team A: mints a grant for a holder it doesn't need to share any secret with.
40
+ team_a_key = generate_keypair()
41
+ issuer = Issuer(issuer_id="team-a", private_key=team_a_key)
42
+
43
+ holder_key = generate_keypair()
44
+ holder = HolderKeypair(holder_key)
45
+ grant = issuer.issue(subject=encode_public_key(holder_key.public_key()), scope={"tool": "read_file"})
46
+ proof = holder.prove_possession(grant)
47
+
48
+ # Team B: only ever obtains team A's PUBLIC key, out-of-band. No shared secret.
49
+ # `path_prefix` is illustrative application data: agent-warrant authenticates
50
+ # the scope but does not interpret or enforce it for authorization.
51
+ resolver = PinnedResolver({"team-a": team_a_key.public_key()})
52
+ verifier = Verifier(resolver)
53
+
54
+ result = verifier.check(grant.encode(), proof)
55
+ assert result.valid
56
+ ```
57
+
58
+ A stolen `grant.encode()` string alone is not enough — presenting it without a valid `PossessionProof` (or with a proof forged by a different keypair) is rejected. See `tests/test_integration.py::test_stolen_grant_without_possession_proof_is_rejected` for the live proof.
59
+
60
+ ### did:web, instead of pinning
61
+
62
+ ```python
63
+ from agent_warrant import DidWebResolver, Verifier
64
+
65
+ # No out-of-band key exchange -- team-a's key is fetched from
66
+ # https://team-a.example.com/.well-known/did.json and cryptographically
67
+ # tied to domain ownership over HTTPS, the same trust model TLS uses.
68
+ resolver = DidWebResolver()
69
+ verifier = Verifier(resolver)
70
+ result = verifier.check(grant.encode(), proof) # grant.issuer == "team-a.example.com"
71
+ ```
72
+
73
+ ### Revocation, opt-in
74
+
75
+ ```python
76
+ from agent_warrant import StaticRevocationChecker, Verifier, sign_revocation_list
77
+
78
+ # Team A decides to invalidate a specific grant before its TTL expires
79
+ # (compromised holder key, mistaken scope, ended sponsorship) and signs a
80
+ # RevocationList naming it -- by grant_binding, this project's stable
81
+ # identity for a specific Grant (see PossessionProof.grant_binding).
82
+ revocation_list = sign_revocation_list("team-a", [proof.grant_binding], team_a_key)
83
+
84
+ # Team B opts in by wiring a RevocationChecker into its Verifier. Without
85
+ # this, revocation is never checked -- default behavior is unchanged.
86
+ checker = StaticRevocationChecker(revocation_list, resolver)
87
+ verifier = Verifier(resolver, revocation_checker=checker)
88
+ result = verifier.check(grant.encode(), proof)
89
+ assert result.valid is False and "revoked" in result.reason
90
+ ```
91
+
92
+ `HttpRevocationChecker` + `HttpRevocationListFetcher` do the same thing over HTTPS instead of an in-process `RevocationList` -- fetching and re-verifying the signed list on every `is_revoked()` call, no caching. If the revocation endpoint is unreachable, verification fails closed (rejected), not open.
93
+
94
+ ## Constraints worth knowing before you hit them
95
+
96
+ - **Encoded grant size**: capped at `agent_warrant.grant.MAX_ENCODED_GRANT_BYTES` (16KB). A compact authority claim never legitimately needs more — if your `scope` is large enough to hit this, reconsider what you're encoding into it rather than raising the constant (it's load-bearing for a resource-exhaustion defense, see docs/THREAT_MODEL.md).
97
+ - **`DidWebResolver` fetches on every `resolve()` call, no caching.** And because `grant.issuer` reaches `resolver.resolve()` before any signature check, an unauthenticated grant can make the verifying process issue an outbound HTTPS request to an attacker-influenced host. `https_fetch.py` resolves the host once, rejects the fetch if any resolved address is private/loopback/link-local/reserved/multicast/unspecified, pins the screened IP, and connects to it directly while verifying TLS against the original hostname (SSRF hardening; this closes the DNS-rebinding TOCTOU a check-then-connect pattern would have). A wall-clock watchdog bounds the total time any single fetch can consume against a slow-drip host. See docs/THREAT_MODEL.md for the remaining residual (the DNS-resolution step uses the OS resolver's own timeout).
98
+ - **Revocation is opt-in and unbundled from StatusList2021.** It's a small signed set of revoked `grant_binding` values, sized for a known, bounded cross-org verifier population -- not the anonymity-preserving bitstring StatusList2021 uses for public, anonymous-verifier scale. See docs/DESIGN.md for why that tradeoff fits this project's actual shape.
99
+
100
+ ## Design history worth knowing before extending this
101
+
102
+ This design went through two real review cycles (documented in full at `~/identity-unification-plan.md` in the originating session) before any code was written. The most important correction: an earlier draft called `subject = holder's public key` alone "holder-binding" — it wasn't. A public key sitting in an issuer-signed credential with no separate possession check at verification time is still a bearer credential; anyone who intercepts the encoded grant can replay it. `PossessionProof` exists specifically to close that gap, mirroring `agent-guard`'s own `PoPProof`/`verify_pop` pattern. Read `docs/DESIGN.md` before changing anything in `grant.py`'s `verify()` — most of its structure (narrow exception catches, version-check-first ordering, the iat type guard) is there because a specific finding required it, not by convention.
@@ -0,0 +1,46 @@
1
+ from __future__ import annotations
2
+
3
+ from .canonical import canonicalize
4
+ from .exceptions import RevocationSourceUnreachable, UnresolvableIssuer
5
+ from .grant import CURRENT_VERSION, Grant, PossessionProof, VerifyResult, prove, sign, verify
6
+ from .identity import decode_public_key, encode_public_key, generate_keypair
7
+ from .issuer import HolderKeypair, Issuer, Verifier
8
+ from .resolver import DidWebResolver, IssuerResolver, PinnedResolver
9
+ from .revocation import (
10
+ HttpRevocationChecker,
11
+ HttpRevocationListFetcher,
12
+ RevocationChecker,
13
+ RevocationList,
14
+ RevocationListFetcher,
15
+ StaticRevocationChecker,
16
+ sign_revocation_list,
17
+ )
18
+
19
+ __all__ = [
20
+ "CURRENT_VERSION",
21
+ "DidWebResolver",
22
+ "Grant",
23
+ "HolderKeypair",
24
+ "HttpRevocationChecker",
25
+ "HttpRevocationListFetcher",
26
+ "Issuer",
27
+ "IssuerResolver",
28
+ "PinnedResolver",
29
+ "PossessionProof",
30
+ "RevocationChecker",
31
+ "RevocationList",
32
+ "RevocationListFetcher",
33
+ "RevocationSourceUnreachable",
34
+ "StaticRevocationChecker",
35
+ "UnresolvableIssuer",
36
+ "VerifyResult",
37
+ "Verifier",
38
+ "canonicalize",
39
+ "decode_public_key",
40
+ "encode_public_key",
41
+ "generate_keypair",
42
+ "prove",
43
+ "sign",
44
+ "sign_revocation_list",
45
+ "verify",
46
+ ]