zanii 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.
- zanii-0.1.0/LICENSE +159 -0
- zanii-0.1.0/PKG-INFO +144 -0
- zanii-0.1.0/README.md +114 -0
- zanii-0.1.0/pyproject.toml +42 -0
- zanii-0.1.0/setup.cfg +4 -0
- zanii-0.1.0/tests/test_bundle.py +71 -0
- zanii-0.1.0/tests/test_mcp_proxy.py +77 -0
- zanii-0.1.0/tests/test_parity.py +152 -0
- zanii-0.1.0/zanii/__init__.py +97 -0
- zanii-0.1.0/zanii/a2a.py +122 -0
- zanii-0.1.0/zanii/bundle.py +102 -0
- zanii-0.1.0/zanii/client.py +151 -0
- zanii-0.1.0/zanii/core.py +105 -0
- zanii-0.1.0/zanii/delegation.py +135 -0
- zanii-0.1.0/zanii/encoding.py +56 -0
- zanii-0.1.0/zanii/keys.py +81 -0
- zanii-0.1.0/zanii/mcp_proxy.py +121 -0
- zanii-0.1.0/zanii/merkle.py +126 -0
- zanii-0.1.0/zanii/py.typed +0 -0
- zanii-0.1.0/zanii/receipt.py +110 -0
- zanii-0.1.0/zanii/sth.py +24 -0
- zanii-0.1.0/zanii.egg-info/PKG-INFO +144 -0
- zanii-0.1.0/zanii.egg-info/SOURCES.txt +24 -0
- zanii-0.1.0/zanii.egg-info/dependency_links.txt +1 -0
- zanii-0.1.0/zanii.egg-info/requires.txt +9 -0
- zanii-0.1.0/zanii.egg-info/top_level.txt +1 -0
zanii-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
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 Derivative
|
|
95
|
+
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; and
|
|
103
|
+
|
|
104
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
105
|
+
distribution, then any Derivative Works that You distribute must
|
|
106
|
+
include a readable copy of the attribution notices contained
|
|
107
|
+
within such NOTICE file.
|
|
108
|
+
|
|
109
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
110
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
111
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
112
|
+
this License, without any additional terms or conditions.
|
|
113
|
+
|
|
114
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
115
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
116
|
+
except as required for reasonable and customary use in describing the
|
|
117
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
118
|
+
|
|
119
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
120
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
121
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
122
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
123
|
+
without limitation, any warranties or conditions of TITLE,
|
|
124
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
|
125
|
+
|
|
126
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
127
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
128
|
+
unless required by applicable law (such as deliberate and grossly
|
|
129
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
130
|
+
liable to You for damages, including any direct, indirect, special,
|
|
131
|
+
incidental, or consequential damages of any character arising as a
|
|
132
|
+
result of this License or out of the use or inability to use the
|
|
133
|
+
Work.
|
|
134
|
+
|
|
135
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
136
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
137
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
138
|
+
or other liability obligations and/or rights consistent with this
|
|
139
|
+
License. However, in accepting such obligations, You may act only
|
|
140
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
141
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
142
|
+
defend, and hold each Contributor harmless for any liability
|
|
143
|
+
incurred by, or claims asserted against, such Contributor.
|
|
144
|
+
|
|
145
|
+
END OF TERMS AND CONDITIONS
|
|
146
|
+
|
|
147
|
+
Copyright 2026 Zanii
|
|
148
|
+
|
|
149
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
150
|
+
you may not use this file except in compliance with the License.
|
|
151
|
+
You may obtain a copy of the License at
|
|
152
|
+
|
|
153
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
154
|
+
|
|
155
|
+
Unless required by applicable law or agreed to in writing, software
|
|
156
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
157
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
158
|
+
See the License for the specific language governing permissions and
|
|
159
|
+
limitations under the License.
|
zanii-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zanii
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Zanii Python SDK — verifiable identity and proof-of-action for AI agents
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://ledger.zanii.agency
|
|
7
|
+
Project-URL: Documentation, https://ledger.zanii.agency/docs
|
|
8
|
+
Keywords: ai-agents,identity,transparency-log,merkle,ed25519,audit
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Security :: Cryptography
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: cryptography>=42
|
|
23
|
+
Provides-Extra: mcp
|
|
24
|
+
Requires-Dist: mcp>=1.10; extra == "mcp"
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
27
|
+
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
28
|
+
Requires-Dist: mcp>=1.10; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# zanii
|
|
32
|
+
|
|
33
|
+
**Verifiable identity and proof-of-action for AI agents.** Give every agent a
|
|
34
|
+
cryptographic identity (`did:key`), scope what it's allowed to do with signed
|
|
35
|
+
delegation certificates, and emit a tamper-proof, hash-chained receipt for every
|
|
36
|
+
action it takes — anchored in an RFC 6962 Merkle transparency log. Anyone can
|
|
37
|
+
verify what an agent did, offline, without trusting the server that stored it.
|
|
38
|
+
|
|
39
|
+
Full protocol parity with the TypeScript SDK (`@zanii/core` / `@zanii/sdk`) —
|
|
40
|
+
cross-language test vectors guarantee byte-identical hashes and signatures. The
|
|
41
|
+
only runtime dependency is [`cryptography`](https://cryptography.io).
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
pip install zanii
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Quickstart
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from zanii import ZaniiAgent, fetch_and_verify_proof
|
|
51
|
+
from zanii.core import generate_keypair, create_cert
|
|
52
|
+
|
|
53
|
+
# 1. Identities. The owner delegates a scoped, expiring capability to the agent.
|
|
54
|
+
owner = generate_keypair()
|
|
55
|
+
agent = generate_keypair()
|
|
56
|
+
cert = create_cert(
|
|
57
|
+
issuer=owner.did,
|
|
58
|
+
subject=agent.did,
|
|
59
|
+
scopes=["crm.*"], # this agent may only act within crm.*
|
|
60
|
+
exp="2027-01-01T00:00:00Z",
|
|
61
|
+
issuer_private_key=owner.private_key,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# 2. Instrument the agent. Every action is signed and hash-chained locally,
|
|
65
|
+
# then batched to the log.
|
|
66
|
+
zanii = ZaniiAgent(
|
|
67
|
+
server_url="https://ledger.zanii.agency",
|
|
68
|
+
agent_did=agent.did,
|
|
69
|
+
agent_private_key=agent.private_key,
|
|
70
|
+
delegation=[cert],
|
|
71
|
+
# api_key="zk_live_...", # required when the log enforces write auth
|
|
72
|
+
)
|
|
73
|
+
receipt, receipt_hash = zanii.record(target="crm.lookup", payload={"email": "a@b.co"})
|
|
74
|
+
zanii.flush() # ship queued receipts to the log
|
|
75
|
+
|
|
76
|
+
# 3. Anyone can verify that proof — offline, zero trust in the server.
|
|
77
|
+
proof = fetch_and_verify_proof("https://ledger.zanii.agency", receipt_hash)
|
|
78
|
+
assert proof.ok
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`wrap_tool` instruments an existing function so every call (sync or async) is
|
|
82
|
+
recorded automatically — result on success, error on failure:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
lookup = zanii.wrap_tool("crm.lookup", crm.find) # crm.find is your own function
|
|
86
|
+
lookup("a@b.co") # transparently receipted
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## `zanii.core` — pure verification, no network
|
|
90
|
+
|
|
91
|
+
Import from `zanii.core` when you only build or verify proofs and never touch the
|
|
92
|
+
network (an auditor, a third-party verifier, an offline signer). Everything there
|
|
93
|
+
is deterministic and does no I/O; the network client lives on the top-level
|
|
94
|
+
`zanii` package.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from zanii.core import verify_audit_bundle
|
|
98
|
+
|
|
99
|
+
# A self-contained audit bundle (GET /v1/export/{agent_did}) is verified with no
|
|
100
|
+
# trusted party: signatures, delegation scope, Merkle inclusion, the per-agent
|
|
101
|
+
# hash chain, and on-chain anchor consistency.
|
|
102
|
+
report = verify_audit_bundle(bundle)
|
|
103
|
+
assert report.ok, [c for c in report.checks if not c["ok"]]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Fully typed — ships `py.typed` (PEP 561), so your type-checker sees every
|
|
107
|
+
signature.
|
|
108
|
+
|
|
109
|
+
## MCP proxy
|
|
110
|
+
|
|
111
|
+
Front any [MCP](https://modelcontextprotocol.io) server so every tool call is
|
|
112
|
+
receipted — **no changes to the agent or the upstream server.** Install the
|
|
113
|
+
extra:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
pip install "zanii[mcp]"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Wrap a connected upstream `ClientSession` with a `ZaniiAgent`; serve the result
|
|
120
|
+
in place of the real server. Tool lists pass through unchanged; each call is
|
|
121
|
+
recorded as `mcp.<tool>` — result on success, error on failure.
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from zanii import ZaniiAgent
|
|
125
|
+
from zanii.mcp_proxy import create_zanii_proxy
|
|
126
|
+
|
|
127
|
+
proxy = create_zanii_proxy(upstream_session, ZaniiAgent(...))
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Or run it standalone over stdio, wrapping an upstream stdio MCP server:
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
ZANII_SERVER=https://ledger.zanii.agency ZANII_IDENTITY=./identity.json \
|
|
134
|
+
python -m zanii.mcp_proxy -- npx some-mcp-server --its-args
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Links
|
|
138
|
+
|
|
139
|
+
- **Docs & concepts** — https://ledger.zanii.agency/docs
|
|
140
|
+
- **Live transparency log** — https://ledger.zanii.agency
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
Apache-2.0.
|
zanii-0.1.0/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# zanii
|
|
2
|
+
|
|
3
|
+
**Verifiable identity and proof-of-action for AI agents.** Give every agent a
|
|
4
|
+
cryptographic identity (`did:key`), scope what it's allowed to do with signed
|
|
5
|
+
delegation certificates, and emit a tamper-proof, hash-chained receipt for every
|
|
6
|
+
action it takes — anchored in an RFC 6962 Merkle transparency log. Anyone can
|
|
7
|
+
verify what an agent did, offline, without trusting the server that stored it.
|
|
8
|
+
|
|
9
|
+
Full protocol parity with the TypeScript SDK (`@zanii/core` / `@zanii/sdk`) —
|
|
10
|
+
cross-language test vectors guarantee byte-identical hashes and signatures. The
|
|
11
|
+
only runtime dependency is [`cryptography`](https://cryptography.io).
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pip install zanii
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quickstart
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from zanii import ZaniiAgent, fetch_and_verify_proof
|
|
21
|
+
from zanii.core import generate_keypair, create_cert
|
|
22
|
+
|
|
23
|
+
# 1. Identities. The owner delegates a scoped, expiring capability to the agent.
|
|
24
|
+
owner = generate_keypair()
|
|
25
|
+
agent = generate_keypair()
|
|
26
|
+
cert = create_cert(
|
|
27
|
+
issuer=owner.did,
|
|
28
|
+
subject=agent.did,
|
|
29
|
+
scopes=["crm.*"], # this agent may only act within crm.*
|
|
30
|
+
exp="2027-01-01T00:00:00Z",
|
|
31
|
+
issuer_private_key=owner.private_key,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# 2. Instrument the agent. Every action is signed and hash-chained locally,
|
|
35
|
+
# then batched to the log.
|
|
36
|
+
zanii = ZaniiAgent(
|
|
37
|
+
server_url="https://ledger.zanii.agency",
|
|
38
|
+
agent_did=agent.did,
|
|
39
|
+
agent_private_key=agent.private_key,
|
|
40
|
+
delegation=[cert],
|
|
41
|
+
# api_key="zk_live_...", # required when the log enforces write auth
|
|
42
|
+
)
|
|
43
|
+
receipt, receipt_hash = zanii.record(target="crm.lookup", payload={"email": "a@b.co"})
|
|
44
|
+
zanii.flush() # ship queued receipts to the log
|
|
45
|
+
|
|
46
|
+
# 3. Anyone can verify that proof — offline, zero trust in the server.
|
|
47
|
+
proof = fetch_and_verify_proof("https://ledger.zanii.agency", receipt_hash)
|
|
48
|
+
assert proof.ok
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`wrap_tool` instruments an existing function so every call (sync or async) is
|
|
52
|
+
recorded automatically — result on success, error on failure:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
lookup = zanii.wrap_tool("crm.lookup", crm.find) # crm.find is your own function
|
|
56
|
+
lookup("a@b.co") # transparently receipted
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## `zanii.core` — pure verification, no network
|
|
60
|
+
|
|
61
|
+
Import from `zanii.core` when you only build or verify proofs and never touch the
|
|
62
|
+
network (an auditor, a third-party verifier, an offline signer). Everything there
|
|
63
|
+
is deterministic and does no I/O; the network client lives on the top-level
|
|
64
|
+
`zanii` package.
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from zanii.core import verify_audit_bundle
|
|
68
|
+
|
|
69
|
+
# A self-contained audit bundle (GET /v1/export/{agent_did}) is verified with no
|
|
70
|
+
# trusted party: signatures, delegation scope, Merkle inclusion, the per-agent
|
|
71
|
+
# hash chain, and on-chain anchor consistency.
|
|
72
|
+
report = verify_audit_bundle(bundle)
|
|
73
|
+
assert report.ok, [c for c in report.checks if not c["ok"]]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Fully typed — ships `py.typed` (PEP 561), so your type-checker sees every
|
|
77
|
+
signature.
|
|
78
|
+
|
|
79
|
+
## MCP proxy
|
|
80
|
+
|
|
81
|
+
Front any [MCP](https://modelcontextprotocol.io) server so every tool call is
|
|
82
|
+
receipted — **no changes to the agent or the upstream server.** Install the
|
|
83
|
+
extra:
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
pip install "zanii[mcp]"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Wrap a connected upstream `ClientSession` with a `ZaniiAgent`; serve the result
|
|
90
|
+
in place of the real server. Tool lists pass through unchanged; each call is
|
|
91
|
+
recorded as `mcp.<tool>` — result on success, error on failure.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from zanii import ZaniiAgent
|
|
95
|
+
from zanii.mcp_proxy import create_zanii_proxy
|
|
96
|
+
|
|
97
|
+
proxy = create_zanii_proxy(upstream_session, ZaniiAgent(...))
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Or run it standalone over stdio, wrapping an upstream stdio MCP server:
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
ZANII_SERVER=https://ledger.zanii.agency ZANII_IDENTITY=./identity.json \
|
|
104
|
+
python -m zanii.mcp_proxy -- npx some-mcp-server --its-args
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Links
|
|
108
|
+
|
|
109
|
+
- **Docs & concepts** — https://ledger.zanii.agency/docs
|
|
110
|
+
- **Live transparency log** — https://ledger.zanii.agency
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
Apache-2.0.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "zanii"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Zanii Python SDK — verifiable identity and proof-of-action for AI agents"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
dependencies = ["cryptography>=42"]
|
|
9
|
+
keywords = ["ai-agents", "identity", "transparency-log", "merkle", "ed25519", "audit"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 4 - Beta",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3.10",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Topic :: Security :: Cryptography",
|
|
20
|
+
"Typing :: Typed",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://ledger.zanii.agency"
|
|
25
|
+
Documentation = "https://ledger.zanii.agency/docs"
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
# MCP proxy (zanii.mcp_proxy) — front any MCP server so every tool call is receipted.
|
|
29
|
+
mcp = ["mcp>=1.10"]
|
|
30
|
+
dev = ["pytest>=8", "httpx>=0.27", "mcp>=1.10"]
|
|
31
|
+
|
|
32
|
+
[build-system]
|
|
33
|
+
requires = ["setuptools>=68"]
|
|
34
|
+
build-backend = "setuptools.build_meta"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools]
|
|
37
|
+
# Only the public SDK ships to PyPI. The `server` package is INTERNAL (see PUBLISHING.md).
|
|
38
|
+
packages = ["zanii"]
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.package-data]
|
|
41
|
+
# PEP 561 — ship the type marker so downstream type-checkers see zanii's types.
|
|
42
|
+
zanii = ["py.typed"]
|
zanii-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Audit-bundle verification: valid bundle passes; tamper and chain breaks fail."""
|
|
2
|
+
from zanii.core import (
|
|
3
|
+
canonical_bytes,
|
|
4
|
+
create_cert,
|
|
5
|
+
create_receipt,
|
|
6
|
+
create_sth,
|
|
7
|
+
generate_keypair,
|
|
8
|
+
hash_payload,
|
|
9
|
+
inclusion_proof,
|
|
10
|
+
jcs_hash,
|
|
11
|
+
leaf_hash,
|
|
12
|
+
merkle_root,
|
|
13
|
+
verify_audit_bundle,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _build_bundle():
|
|
18
|
+
log, owner, agent = generate_keypair(), generate_keypair(), generate_keypair()
|
|
19
|
+
cert = create_cert(owner.did, agent.did, ["email.*"], "2099-01-01T00:00:00Z", owner.private_key)
|
|
20
|
+
receipts, prev = [], None
|
|
21
|
+
for i in range(3):
|
|
22
|
+
r = create_receipt(agent.did, [cert], "email:send", f"email.user{i}",
|
|
23
|
+
hash_payload(f"body{i}".encode()), f"2026-01-0{i + 1}T00:00:00Z",
|
|
24
|
+
prev, agent.private_key)
|
|
25
|
+
receipts.append(r)
|
|
26
|
+
prev = jcs_hash(r)
|
|
27
|
+
leaves = [leaf_hash(canonical_bytes(r)) for r in receipts]
|
|
28
|
+
root = merkle_root(leaves)
|
|
29
|
+
sth = create_sth(log.did, len(leaves), "sha256:" + root.hex(), "2026-01-04T00:00:00Z", log.private_key)
|
|
30
|
+
return {
|
|
31
|
+
"v": 1, "bundle_type": "zanii-audit-bundle", "log_id": log.did, "agent_id": agent.did,
|
|
32
|
+
"sth": sth,
|
|
33
|
+
"receipts": [
|
|
34
|
+
{"index": i, "hash": jcs_hash(r), "receipt": r,
|
|
35
|
+
"proof": [p.hex() for p in inclusion_proof(i, leaves)]}
|
|
36
|
+
for i, r in enumerate(receipts)
|
|
37
|
+
],
|
|
38
|
+
"revocations": [], "anchors": [],
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_valid_bundle_verifies():
|
|
43
|
+
report = verify_audit_bundle(_build_bundle())
|
|
44
|
+
assert report.ok, [c for c in report.checks if not c["ok"]]
|
|
45
|
+
assert report.stats["receipts"] == 3
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_tampered_receipt_fails():
|
|
49
|
+
b = _build_bundle()
|
|
50
|
+
b["receipts"][1]["receipt"]["target"] = "email.attacker"
|
|
51
|
+
assert not verify_audit_bundle(b).ok
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_broken_hash_chain_fails():
|
|
55
|
+
b = _build_bundle()
|
|
56
|
+
b["receipts"][2]["receipt"]["prev"] = "sha256:" + "00" * 32
|
|
57
|
+
assert not verify_audit_bundle(b).ok
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_forged_sth_fails():
|
|
61
|
+
b = _build_bundle()
|
|
62
|
+
b["sth"]["log_id"] = generate_keypair().did # STH now signed by the wrong log key
|
|
63
|
+
assert not verify_audit_bundle(b).ok
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if __name__ == "__main__":
|
|
67
|
+
test_valid_bundle_verifies()
|
|
68
|
+
test_tampered_receipt_fails()
|
|
69
|
+
test_broken_hash_chain_fails()
|
|
70
|
+
test_forged_sth_fails()
|
|
71
|
+
print("ok")
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""MCP proxy: every forwarded tool call — success or upstream error — produces a
|
|
2
|
+
signed, in-scope, verifiable `mcp.<tool>` receipt, and tool lists pass through."""
|
|
3
|
+
import anyio
|
|
4
|
+
import mcp.types as types
|
|
5
|
+
|
|
6
|
+
from zanii import ZaniiAgent, verify_receipt
|
|
7
|
+
from zanii.core import create_cert, generate_keypair
|
|
8
|
+
from zanii.mcp_proxy import create_zanii_proxy
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FakeUpstream:
|
|
12
|
+
"""Duck-typed stand-in for a connected mcp ClientSession."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, *, error: bool = False):
|
|
15
|
+
self.error = error
|
|
16
|
+
self.calls: list[tuple[str, dict]] = []
|
|
17
|
+
|
|
18
|
+
async def list_tools(self):
|
|
19
|
+
return types.ListToolsResult(tools=[types.Tool(name="echo", inputSchema={"type": "object"})])
|
|
20
|
+
|
|
21
|
+
async def call_tool(self, name, arguments):
|
|
22
|
+
self.calls.append((name, arguments))
|
|
23
|
+
text = "boom" if self.error else "pong"
|
|
24
|
+
return types.CallToolResult(content=[types.TextContent(type="text", text=text)], isError=self.error)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _proxy(error: bool = False):
|
|
28
|
+
owner, agent = generate_keypair(), generate_keypair()
|
|
29
|
+
cert = create_cert(issuer=owner.did, subject=agent.did, scopes=["mcp.*"],
|
|
30
|
+
exp="2099-01-01T00:00:00Z", issuer_private_key=owner.private_key)
|
|
31
|
+
z = ZaniiAgent(server_url="http://localhost:4600", agent_did=agent.did,
|
|
32
|
+
agent_private_key=agent.private_key, delegation=[cert])
|
|
33
|
+
z._synced = True # skip the network head-sync; keep the test offline
|
|
34
|
+
up = FakeUpstream(error=error)
|
|
35
|
+
return create_zanii_proxy(up, z), z, up
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _call(server):
|
|
39
|
+
handler = server.request_handlers[types.CallToolRequest]
|
|
40
|
+
req = types.CallToolRequest(method="tools/call",
|
|
41
|
+
params=types.CallToolRequestParams(name="echo", arguments={"email": "a@b.co"}))
|
|
42
|
+
return anyio.run(handler, req)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_tool_call_is_receipted_and_verifies():
|
|
46
|
+
server, z, up = _proxy()
|
|
47
|
+
res = _call(server)
|
|
48
|
+
assert res.root.isError is False
|
|
49
|
+
assert up.calls == [("echo", {"email": "a@b.co"})]
|
|
50
|
+
assert len(z._queue) == 1
|
|
51
|
+
receipt = z._queue[0]
|
|
52
|
+
assert receipt["target"] == "mcp.echo"
|
|
53
|
+
assert verify_receipt(receipt).ok
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_upstream_error_is_receipted():
|
|
57
|
+
server, z, up = _proxy(error=True)
|
|
58
|
+
res = _call(server)
|
|
59
|
+
assert res.root.isError is True
|
|
60
|
+
assert len(z._queue) == 1
|
|
61
|
+
receipt = z._queue[0]
|
|
62
|
+
assert receipt["target"] == "mcp.echo"
|
|
63
|
+
assert verify_receipt(receipt).ok # error calls are proof too
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_list_tools_passthrough():
|
|
67
|
+
server, _, _ = _proxy()
|
|
68
|
+
handler = server.request_handlers[types.ListToolsRequest]
|
|
69
|
+
res = anyio.run(handler, types.ListToolsRequest(method="tools/list"))
|
|
70
|
+
assert [t.name for t in res.root.tools] == ["echo"]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if __name__ == "__main__":
|
|
74
|
+
test_tool_call_is_receipted_and_verifies()
|
|
75
|
+
test_upstream_error_is_receipted()
|
|
76
|
+
test_list_tools_passthrough()
|
|
77
|
+
print("ok")
|