agent-receipts 0.2.1__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 (45) hide show
  1. agent_receipts-0.2.1/.github/workflows/ci.yml +33 -0
  2. agent_receipts-0.2.1/.github/workflows/publish.yml +26 -0
  3. agent_receipts-0.2.1/.gitignore +9 -0
  4. agent_receipts-0.2.1/CLAUDE.md +31 -0
  5. agent_receipts-0.2.1/CONTRIBUTING.md +62 -0
  6. agent_receipts-0.2.1/LICENSE +21 -0
  7. agent_receipts-0.2.1/PKG-INFO +279 -0
  8. agent_receipts-0.2.1/README.md +250 -0
  9. agent_receipts-0.2.1/SECURITY.md +41 -0
  10. agent_receipts-0.2.1/pyproject.toml +67 -0
  11. agent_receipts-0.2.1/src/attest_protocol/__init__.py +139 -0
  12. agent_receipts-0.2.1/src/attest_protocol/_version.py +1 -0
  13. agent_receipts-0.2.1/src/attest_protocol/py.typed +0 -0
  14. agent_receipts-0.2.1/src/attest_protocol/receipt/__init__.py +70 -0
  15. agent_receipts-0.2.1/src/attest_protocol/receipt/chain.py +95 -0
  16. agent_receipts-0.2.1/src/attest_protocol/receipt/create.py +101 -0
  17. agent_receipts-0.2.1/src/attest_protocol/receipt/hash.py +113 -0
  18. agent_receipts-0.2.1/src/attest_protocol/receipt/signing.py +146 -0
  19. agent_receipts-0.2.1/src/attest_protocol/receipt/types.py +157 -0
  20. agent_receipts-0.2.1/src/attest_protocol/store/__init__.py +17 -0
  21. agent_receipts-0.2.1/src/attest_protocol/store/store.py +214 -0
  22. agent_receipts-0.2.1/src/attest_protocol/store/verify.py +21 -0
  23. agent_receipts-0.2.1/src/attest_protocol/taxonomy/__init__.py +29 -0
  24. agent_receipts-0.2.1/src/attest_protocol/taxonomy/actions.py +105 -0
  25. agent_receipts-0.2.1/src/attest_protocol/taxonomy/classify.py +35 -0
  26. agent_receipts-0.2.1/src/attest_protocol/taxonomy/config.py +54 -0
  27. agent_receipts-0.2.1/src/attest_protocol/taxonomy/types.py +26 -0
  28. agent_receipts-0.2.1/tests/__init__.py +0 -0
  29. agent_receipts-0.2.1/tests/conftest.py +100 -0
  30. agent_receipts-0.2.1/tests/fixtures/ts_vectors.json +139 -0
  31. agent_receipts-0.2.1/tests/receipt/__init__.py +0 -0
  32. agent_receipts-0.2.1/tests/receipt/test_chain.py +107 -0
  33. agent_receipts-0.2.1/tests/receipt/test_create.py +109 -0
  34. agent_receipts-0.2.1/tests/receipt/test_hash.py +109 -0
  35. agent_receipts-0.2.1/tests/receipt/test_signing.py +81 -0
  36. agent_receipts-0.2.1/tests/receipt/test_types.py +61 -0
  37. agent_receipts-0.2.1/tests/store/__init__.py +0 -0
  38. agent_receipts-0.2.1/tests/store/test_store.py +223 -0
  39. agent_receipts-0.2.1/tests/store/test_verify.py +57 -0
  40. agent_receipts-0.2.1/tests/taxonomy/__init__.py +0 -0
  41. agent_receipts-0.2.1/tests/taxonomy/test_actions.py +52 -0
  42. agent_receipts-0.2.1/tests/taxonomy/test_classify.py +40 -0
  43. agent_receipts-0.2.1/tests/taxonomy/test_config.py +80 -0
  44. agent_receipts-0.2.1/tests/test_cross_language.py +84 -0
  45. agent_receipts-0.2.1/uv.lock +417 -0
@@ -0,0 +1,33 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ check:
14
+ runs-on: ubuntu-latest
15
+
16
+ strategy:
17
+ matrix:
18
+ python-version: ["3.11", "3.12", "3.13"]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+
23
+ - uses: astral-sh/setup-uv@v6
24
+ with:
25
+ python-version: ${{ matrix.python-version }}
26
+
27
+ - run: uv sync --all-extras
28
+
29
+ - run: uv run ruff check .
30
+
31
+ - run: uv run ruff format --check .
32
+
33
+ - run: uv run pytest -v
@@ -0,0 +1,26 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ contents: read
9
+ id-token: write
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - uses: astral-sh/setup-uv@v6
19
+ with:
20
+ python-version: "3.13"
21
+
22
+ - run: uv build
23
+
24
+ - uses: pypa/gh-action-pypi-publish@release/v1
25
+ with:
26
+ packages-dir: dist/
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .venv/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ *.egg
@@ -0,0 +1,31 @@
1
+ # CLAUDE.md
2
+
3
+ ## Project
4
+
5
+ Python SDK for the [Attest Protocol](https://github.com/attest-protocol/spec) — cryptographically signed, hash-chained Action Receipts for AI agent audit trails.
6
+
7
+ ## Commands
8
+
9
+ ```sh
10
+ uv sync --all-extras # install deps
11
+ uv run pytest -v # run tests
12
+ uv run ruff check . # lint
13
+ uv run ruff format . # format
14
+ uv run pyright src # type check (168 pre-existing Pydantic errors are expected)
15
+ ```
16
+
17
+ ## Architecture
18
+
19
+ - `src/attest_protocol/receipt/` — Core: types, create, sign, hash, chain verification
20
+ - `src/attest_protocol/store/` — SQLite persistence: ReceiptStore, query, verify_stored_chain
21
+ - `src/attest_protocol/taxonomy/` — Action type classification, config loading
22
+ - `tests/` — Mirrors src structure. Uses conftest.py fixtures for receipt creation.
23
+
24
+ ## Conventions
25
+
26
+ - `from __future__ import annotations` in every file
27
+ - Pydantic v2 for receipt models, frozen dataclasses for simple types
28
+ - `TYPE_CHECKING` guards for type-only imports
29
+ - Ruff for lint+format (line-length 88), pyright strict mode
30
+ - camelCase aliases exported at package level for TypeScript SDK users
31
+ - Schema must match TypeScript SDK exactly (cross-language tests verify this)
@@ -0,0 +1,62 @@
1
+ # Contributing to attest-protocol
2
+
3
+ Thank you for your interest in contributing to the Action Receipts Python SDK.
4
+
5
+ ## How to contribute
6
+
7
+ ### Reporting issues
8
+
9
+ Open a [GitHub issue](https://github.com/attest-protocol/attest-py/issues) for:
10
+
11
+ - Bugs in receipt creation, signing, hashing, or verification
12
+ - Store (SQLite) issues — data corruption, query problems
13
+ - Taxonomy classification errors
14
+ - Missing or incorrect type annotations
15
+ - Documentation gaps
16
+
17
+ ### Proposing changes
18
+
19
+ 1. Open an issue describing the change and its motivation.
20
+ 2. Fork the repo and create a branch from `main`.
21
+ 3. Make your changes following the conventions below.
22
+ 4. Run `uv run ruff check .` and `uv run pytest -v`.
23
+ 5. Open a pull request referencing the issue.
24
+
25
+ ## Development setup
26
+
27
+ ```sh
28
+ uv sync --all-extras
29
+ uv run pytest -v # run all tests
30
+ uv run ruff check . # lint
31
+ uv run ruff format . # format
32
+ uv run pyright src # type check
33
+ ```
34
+
35
+ ## Code conventions
36
+
37
+ - **Python 3.11+** with `from __future__ import annotations`.
38
+ - **Ruff** for linting and formatting (line length 88).
39
+ - Use `TYPE_CHECKING` guards for type-only imports.
40
+ - **Pydantic v2** for receipt data models, **dataclasses** for simple types.
41
+ - Test files: `tests/` directory mirroring `src/` structure.
42
+ - All changes go through pull requests — never push directly to `main`.
43
+
44
+ ## Testing
45
+
46
+ - Write tests for all new functionality and bug fixes.
47
+ - Tests use [pytest](https://docs.pytest.org/).
48
+ - Cover both happy paths and edge cases (empty inputs, invalid data, error handling).
49
+ - Use the test factories in `tests/conftest.py` for creating receipt fixtures.
50
+ - Cross-language compatibility tests in `tests/test_cross_language.py` verify parity with the TypeScript SDK.
51
+
52
+ ## Spec alignment
53
+
54
+ This SDK implements the [Action Receipt Protocol](https://github.com/attest-protocol/spec). If you find a discrepancy between the SDK behavior and the spec, please open an issue in both repos.
55
+
56
+ ## Code of conduct
57
+
58
+ Be respectful and constructive. We follow the [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/).
59
+
60
+ ## License
61
+
62
+ By contributing, you agree that your contributions will be licensed under the [Apache 2.0 License](LICENSE).
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 attest-protocol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,279 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-receipts
3
+ Version: 0.2.1
4
+ Summary: Python SDK for the Action Receipts protocol
5
+ Project-URL: Homepage, https://github.com/agnt-rcpt/sdk-py
6
+ Project-URL: Repository, https://github.com/agnt-rcpt/sdk-py
7
+ Project-URL: Issues, https://github.com/agnt-rcpt/sdk-py/issues
8
+ Project-URL: Spec, https://github.com/agnt-rcpt/spec
9
+ Author: Otto Jongerius
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: agent,ai,audit,receipts,verifiable-credentials
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: cryptography>=41.0
23
+ Requires-Dist: pydantic>=2.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pyright>=1.1; extra == 'dev'
26
+ Requires-Dist: pytest>=8.0; extra == 'dev'
27
+ Requires-Dist: ruff>=0.9; extra == 'dev'
28
+ Description-Content-Type: text/markdown
29
+
30
+ <div align="center">
31
+
32
+ # attest-protocol
33
+
34
+ ### Python SDK for the Action Receipts protocol
35
+
36
+ [![PyPI](https://img.shields.io/pypi/v/attest-protocol)](https://pypi.org/project/attest-protocol/)
37
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
38
+ [![Python](https://img.shields.io/badge/Python-3.11+-3776AB?logo=python&logoColor=white)](https://www.python.org/)
39
+ [![CI](https://github.com/attest-protocol/attest-py/actions/workflows/ci.yml/badge.svg)](https://github.com/attest-protocol/attest-py/actions/workflows/ci.yml)
40
+
41
+ ---
42
+
43
+ Create, sign, hash-chain, store, and verify cryptographically signed audit trails for AI agent actions.
44
+
45
+ [Spec](https://github.com/attest-protocol/spec) &bull; [TypeScript SDK](https://github.com/attest-protocol/attest-ts) &bull; [Reference Implementation](https://github.com/ojongerius/attest)
46
+
47
+ </div>
48
+
49
+ ---
50
+
51
+ ## Why receipts?
52
+
53
+ If you're building with AI agents, you're probably already logging what they do. Receipts go further: they're **cryptographically signed, hash-chained records** that can't be quietly altered after the fact — and they follow a standard format that works across languages, agents, and systems.
54
+
55
+ Here's where that matters in practice:
56
+
57
+ - **Post-incident review** — An agent ran overnight and something broke. The receipt chain shows exactly which actions it took, in what order, and whether each succeeded or failed — with cryptographic proof the log hasn't been tampered with after the fact.
58
+
59
+ - **Compliance and audit** — Regulated environments require evidence of what systems did and why. Receipts are W3C Verifiable Credentials with Ed25519 signatures, giving auditors a tamper-evident trail they can independently verify.
60
+
61
+ - **Safer autonomous agents** — Agents can query their own audit trail mid-session. Before taking a high-risk action, an agent can check what it has already done and whether previous steps succeeded, enabling self-correcting workflows.
62
+
63
+ - **Multi-agent trust** — When agents collaborate, receipts serve as proof of prior actions. Agent B can verify that Agent A actually completed step 1 before proceeding to step 2, without trusting a shared log.
64
+
65
+ - **Usage tracking** — Every action is classified by type and risk level, giving you a structured breakdown of what agents spent their time on.
66
+
67
+ ### Beyond local storage
68
+
69
+ The protocol is designed for receipts to travel — publishing to a shared ledger, forwarding to a compliance system, or exchanging between agents as proof of prior actions. Receipts are portable W3C Verifiable Credentials, but where they go is always under the user's control.
70
+
71
+ ---
72
+
73
+ ## Install
74
+
75
+ ```sh
76
+ pip install attest-protocol
77
+ ```
78
+
79
+ ## Quick start
80
+
81
+ ### Create and sign a receipt
82
+
83
+ ```python
84
+ from attest_protocol import (
85
+ create_receipt,
86
+ generate_key_pair,
87
+ hash_receipt,
88
+ sign_receipt,
89
+ CreateReceiptInput,
90
+ Chain,
91
+ Issuer,
92
+ Outcome,
93
+ Principal,
94
+ )
95
+ from attest_protocol.receipt.create import ActionInput
96
+
97
+ # Generate an Ed25519 key pair
98
+ keys = generate_key_pair()
99
+
100
+ # Create an unsigned receipt
101
+ unsigned = create_receipt(CreateReceiptInput(
102
+ issuer=Issuer(id="did:agent:my-agent"),
103
+ principal=Principal(id="did:user:alice"),
104
+ action=ActionInput(
105
+ type="filesystem.file.read",
106
+ risk_level="low",
107
+ ),
108
+ outcome=Outcome(status="success"),
109
+ chain=Chain(
110
+ sequence=1,
111
+ previous_receipt_hash=None,
112
+ chain_id="chain_session-1",
113
+ ),
114
+ ))
115
+
116
+ # Sign and hash
117
+ receipt = sign_receipt(unsigned, keys.private_key, "did:agent:my-agent#key-1")
118
+ receipt_hash = hash_receipt(receipt)
119
+ ```
120
+
121
+ ### Verify a receipt
122
+
123
+ ```python
124
+ from attest_protocol import verify_receipt
125
+
126
+ valid = verify_receipt(receipt, keys.public_key)
127
+ print(f"Signature valid: {valid}") # True
128
+ ```
129
+
130
+ ### Verify a chain
131
+
132
+ ```python
133
+ from attest_protocol import verify_chain
134
+
135
+ # Verify a list of receipts (e.g. [receipt] from the example above)
136
+ result = verify_chain([receipt], keys.public_key)
137
+ print(f"Chain valid: {result.valid}")
138
+ print(f"Receipts verified: {result.length}")
139
+ if not result.valid:
140
+ print(f"Broken at index: {result.broken_at}")
141
+ ```
142
+
143
+ ### Action taxonomy
144
+
145
+ The standardized action taxonomy (action types and risk levels) is defined in the
146
+ [protocol specification](https://github.com/attest-protocol/spec/tree/main/spec/taxonomy).
147
+ Taxonomy classification will be added in a future milestone (M3).
148
+
149
+ ## What is an Action Receipt?
150
+
151
+ A [W3C Verifiable Credential](https://www.w3.org/TR/vc-data-model-2.0/) signed with Ed25519, recording:
152
+
153
+ | Field | What it captures |
154
+ |:---|:---|
155
+ | **Action** | What happened, classified by a [standardized taxonomy](https://github.com/attest-protocol/spec/tree/main/spec/taxonomy) |
156
+ | **Principal** | Who authorized it (human or organization) |
157
+ | **Issuer** | Which agent performed it |
158
+ | **Outcome** | Success/failure, reversibility, undo method |
159
+ | **Chain** | SHA-256 hash link to the previous receipt (tamper-evident) |
160
+ | **Privacy** | Parameters are hashed, never stored in plaintext |
161
+
162
+ ## API reference
163
+
164
+ ### Receipt creation and signing
165
+
166
+ ```python
167
+ from attest_protocol import (
168
+ create_receipt, # Build an unsigned receipt from input fields
169
+ generate_key_pair, # Ed25519 key pair (PEM-encoded)
170
+ sign_receipt, # Sign with Ed25519Signature2020 proof
171
+ verify_receipt, # Verify a receipt's signature
172
+ )
173
+ ```
174
+
175
+ ### Hashing and canonicalization
176
+
177
+ ```python
178
+ from attest_protocol import (
179
+ canonicalize, # RFC 8785 JSON canonicalization
180
+ hash_receipt, # Hash receipt (excluding proof) -> "sha256:<hex>"
181
+ sha256, # Hash arbitrary data -> "sha256:<hex>"
182
+ )
183
+ ```
184
+
185
+ ### Chain verification
186
+
187
+ ```python
188
+ from attest_protocol import (
189
+ verify_chain, # Verify signatures, hash links, and sequence numbering
190
+ )
191
+ ```
192
+
193
+ ### Types (Pydantic v2 models)
194
+
195
+ ```python
196
+ from attest_protocol import (
197
+ ActionReceipt, # Signed receipt with proof
198
+ UnsignedActionReceipt, # Receipt before signing
199
+ Action, ActionTarget, Authorization, Chain,
200
+ CredentialSubject, Intent, Issuer, Operator,
201
+ Outcome, Principal, Proof, StateChange,
202
+ )
203
+ ```
204
+
205
+ ### Subpackage imports
206
+
207
+ ```python
208
+ from attest_protocol.receipt import create_receipt, sign_receipt
209
+ from attest_protocol.receipt.hash import canonicalize
210
+ from attest_protocol.receipt.types import CONTEXT, CREDENTIAL_TYPE
211
+ ```
212
+
213
+ ### TypeScript SDK compatibility
214
+
215
+ camelCase aliases are available for users coming from the TS SDK:
216
+
217
+ ```python
218
+ from attest_protocol import (
219
+ createReceipt, # = create_receipt
220
+ generateKeyPair, # = generate_key_pair
221
+ signReceipt, # = sign_receipt
222
+ verifyReceipt, # = verify_receipt
223
+ hashReceipt, # = hash_receipt
224
+ verifyChain, # = verify_chain
225
+ )
226
+ ```
227
+
228
+ ## Cross-language compatibility
229
+
230
+ This SDK produces **byte-identical** output to [`@attest-protocol/attest-ts`](https://github.com/attest-protocol/attest-ts):
231
+
232
+ - RFC 8785 canonical JSON matches exactly
233
+ - SHA-256 hashes are identical
234
+ - Ed25519 signatures from either SDK verify in the other
235
+
236
+ Cross-language compatibility is verified by test vectors generated from the TypeScript SDK.
237
+
238
+ ## Project structure
239
+
240
+ ```
241
+ src/attest_protocol/
242
+ receipt/
243
+ types.py # Pydantic models for all receipt types
244
+ create.py # Receipt creation with auto-generated IDs
245
+ signing.py # Ed25519 signing and verification
246
+ hash.py # RFC 8785 canonicalization + SHA-256
247
+ chain.py # Chain verification
248
+ ```
249
+
250
+ ## Development
251
+
252
+ ```sh
253
+ uv sync --all-extras
254
+ uv run pytest # run tests
255
+ uv run ruff check . # lint
256
+ uv run ruff format . # format
257
+ uv run pyright # type check
258
+ ```
259
+
260
+ | | |
261
+ |:---|:---|
262
+ | **Language** | Python 3.11+ |
263
+ | **Types** | Pydantic v2, pyright strict mode |
264
+ | **Linting** | ruff |
265
+ | **Testing** | pytest |
266
+ | **Dependencies** | `pydantic>=2.0`, `cryptography>=41.0` |
267
+
268
+ ## Ecosystem
269
+
270
+ | Repository | Description |
271
+ |:---|:---|
272
+ | [attest-protocol/spec](https://github.com/attest-protocol/spec) | Protocol specification, JSON Schemas, canonical taxonomy |
273
+ | [attest-protocol/attest-ts](https://github.com/attest-protocol/attest-ts) | TypeScript SDK ([npm](https://www.npmjs.com/package/@attest-protocol/attest-ts)) |
274
+ | **attest-protocol/attest-py** (this package) | Python SDK |
275
+ | [ojongerius/attest](https://github.com/ojongerius/attest) | MCP proxy + CLI (reference implementation) |
276
+
277
+ ## License
278
+
279
+ Apache 2.0 — see [LICENSE](LICENSE).