@zanii/core 0.1.0

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 (48) hide show
  1. package/LICENSE +159 -0
  2. package/README.md +64 -0
  3. package/dist/a2a.d.ts +58 -0
  4. package/dist/a2a.d.ts.map +1 -0
  5. package/dist/a2a.js +102 -0
  6. package/dist/a2a.js.map +1 -0
  7. package/dist/bundle.d.ts +55 -0
  8. package/dist/bundle.d.ts.map +1 -0
  9. package/dist/bundle.js +92 -0
  10. package/dist/bundle.js.map +1 -0
  11. package/dist/delegation.d.ts +48 -0
  12. package/dist/delegation.d.ts.map +1 -0
  13. package/dist/delegation.js +110 -0
  14. package/dist/delegation.js.map +1 -0
  15. package/dist/encoding.d.ts +8 -0
  16. package/dist/encoding.d.ts.map +1 -0
  17. package/dist/encoding.js +29 -0
  18. package/dist/encoding.js.map +1 -0
  19. package/dist/index.d.ts +9 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +9 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/keys.d.ts +10 -0
  24. package/dist/keys.d.ts.map +1 -0
  25. package/dist/keys.js +33 -0
  26. package/dist/keys.js.map +1 -0
  27. package/dist/merkle.d.ts +12 -0
  28. package/dist/merkle.d.ts.map +1 -0
  29. package/dist/merkle.js +146 -0
  30. package/dist/merkle.js.map +1 -0
  31. package/dist/receipt.d.ts +49 -0
  32. package/dist/receipt.d.ts.map +1 -0
  33. package/dist/receipt.js +87 -0
  34. package/dist/receipt.js.map +1 -0
  35. package/dist/sth.d.ts +17 -0
  36. package/dist/sth.d.ts.map +1 -0
  37. package/dist/sth.js +24 -0
  38. package/dist/sth.js.map +1 -0
  39. package/package.json +43 -0
  40. package/src/a2a.ts +139 -0
  41. package/src/bundle.ts +176 -0
  42. package/src/delegation.ts +134 -0
  43. package/src/encoding.ts +30 -0
  44. package/src/index.ts +56 -0
  45. package/src/keys.ts +38 -0
  46. package/src/merkle.ts +154 -0
  47. package/src/receipt.ts +123 -0
  48. package/src/sth.ts +35 -0
package/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.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @zanii/core
2
+
3
+ The Zanii protocol as pure functions — **no I/O, no network, no trusted party.**
4
+ Agent identities (`did:key`), scoped delegation certificates, signed action
5
+ receipts, RFC 6962 Merkle transparency-log proofs, and self-contained audit
6
+ bundles. Everything here is deterministic; use it to build proofs, or to
7
+ **verify** them independently of any Zanii server.
8
+
9
+ If you want to instrument a live agent (batching, HTTP ingest, tool wrapping),
10
+ use [`@zanii/sdk`](https://www.npmjs.com/package/@zanii/sdk), which builds on
11
+ this.
12
+
13
+ ```sh
14
+ npm install @zanii/core
15
+ ```
16
+
17
+ ## Verify a receipt, offline
18
+
19
+ ```ts
20
+ import {
21
+ generateKeypair,
22
+ createCert,
23
+ createReceipt,
24
+ hashPayload,
25
+ verifyReceipt,
26
+ } from '@zanii/core';
27
+
28
+ const owner = generateKeypair();
29
+ const agent = generateKeypair();
30
+ const cert = createCert(
31
+ { issuer: owner.did, subject: agent.did, scopes: ['crm.*'], exp: '2027-01-01T00:00:00Z' },
32
+ owner.privateKey,
33
+ );
34
+ const receipt = createReceipt(
35
+ {
36
+ agentId: agent.did,
37
+ delegation: [cert],
38
+ action: 'tool_call',
39
+ target: 'crm.lookup',
40
+ payloadHash: hashPayload(JSON.stringify({ email: 'a@b.co' })),
41
+ ts: new Date().toISOString(),
42
+ prev: null,
43
+ },
44
+ agent.privateKey,
45
+ );
46
+
47
+ // Checks the signature, the delegation chain, and that the action is in scope —
48
+ // with no server and no trust.
49
+ const result = verifyReceipt(receipt);
50
+ if (!result.ok) throw new Error(result.error);
51
+ ```
52
+
53
+ `verifyAuditBundle(bundle)` does the same for a complete exported history at
54
+ once: every receipt's signature and Merkle inclusion, the per-agent hash chain,
55
+ revocations, and on-chain anchor consistency.
56
+
57
+ ## Links
58
+
59
+ - **Docs & concepts** — https://ledger.zanii.agency/docs
60
+ - **Live transparency log** — https://ledger.zanii.agency
61
+
62
+ ## License
63
+
64
+ Apache-2.0.
package/dist/a2a.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { type DelegationCert } from './delegation.js';
2
+ import type { VerifyResult } from './receipt.js';
3
+ export interface A2AParty {
4
+ agent_id: string;
5
+ delegation: DelegationCert[];
6
+ prev: string | null;
7
+ sig: string;
8
+ }
9
+ export interface A2AReceipt {
10
+ v: 1;
11
+ type: 'a2a';
12
+ action: string;
13
+ target: string;
14
+ payload_hash: string;
15
+ ts: string;
16
+ initiator: A2AParty;
17
+ responder: A2AParty;
18
+ }
19
+ /** The body both parties sign: the receipt with both sig fields removed. */
20
+ export type A2ABody = Omit<A2AReceipt, 'initiator' | 'responder'> & {
21
+ initiator: Omit<A2AParty, 'sig'>;
22
+ responder: Omit<A2AParty, 'sig'>;
23
+ };
24
+ export declare function buildA2ABody(fields: {
25
+ action: string;
26
+ target: string;
27
+ payloadHash: string;
28
+ ts: string;
29
+ initiator: Omit<A2AParty, 'sig'>;
30
+ responder: Omit<A2AParty, 'sig'>;
31
+ }): A2ABody;
32
+ /** Both parties sign the identical body — order-independent. */
33
+ export declare function signA2ABody(body: A2ABody, privateKey: Uint8Array): string;
34
+ export declare function assembleA2AReceipt(body: A2ABody, initiatorSig: string, responderSig: string): A2AReceipt;
35
+ /** Hash of the full receipt (both sigs) — what both agents' next `prev` points to. */
36
+ export declare function a2aHash(receipt: A2AReceipt): string;
37
+ export declare function bodyOf(receipt: A2AReceipt): A2ABody;
38
+ /** Full A2A verification per SPEC §9. `expectedPrevFor` maps agent DID → required prev. */
39
+ export declare function verifyA2AReceipt(receipt: A2AReceipt, opts?: {
40
+ revoked?: Set<string>;
41
+ expectedPrevFor?: Record<string, string | null>;
42
+ }): VerifyResult;
43
+ /** The DIDs participating in any log receipt (solo or a2a). */
44
+ export declare function participantsOf(entry: {
45
+ agent_id?: string;
46
+ type?: string;
47
+ initiator?: A2AParty;
48
+ responder?: A2AParty;
49
+ }): string[];
50
+ /** The `prev` a given participant declared in a log receipt, or undefined if not a party. */
51
+ export declare function prevFor(entry: {
52
+ agent_id?: string;
53
+ prev?: string | null;
54
+ type?: string;
55
+ initiator?: A2AParty;
56
+ responder?: A2AParty;
57
+ }, agentId: string): string | null | undefined;
58
+ //# sourceMappingURL=a2a.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2a.d.ts","sourceRoot":"","sources":["../src/a2a.ts"],"names":[],"mappings":"AAOA,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,UAAU;IACzB,CAAC,EAAE,CAAC,CAAC;IACL,IAAI,EAAE,KAAK,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,QAAQ,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC;CACrB;AAED,4EAA4E;AAC5E,MAAM,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC,GAAG;IAClE,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,C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,OAAO,CACrB,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,QAAQ,CAAC;IAAC,SAAS,CAAC,EAAE,QAAQ,CAAA;CAAE,EAC7G,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,GAAG,SAAS,CAO3B"}
package/dist/a2a.js ADDED
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Cross-org co-signed receipts — SPEC §9. One interaction, two signers, one
3
+ * neutral proof that enters both agents' hash chains.
4
+ */
5
+ import { ed25519 } from '@noble/curves/ed25519';
6
+ import { canonicalBytes, decodeSig, encodeSig, jcsHash } from './encoding.js';
7
+ import { publicKeyFromDid } from './keys.js';
8
+ import { scopesAllow, verifyChain } from './delegation.js';
9
+ export function buildA2ABody(fields) {
10
+ if (Number.isNaN(Date.parse(fields.ts)))
11
+ throw new Error(`invalid ts timestamp: ${fields.ts}`);
12
+ if (fields.initiator.agent_id === fields.responder.agent_id) {
13
+ throw new Error('initiator and responder must be distinct agents');
14
+ }
15
+ return {
16
+ v: 1,
17
+ type: 'a2a',
18
+ action: fields.action,
19
+ target: fields.target,
20
+ payload_hash: fields.payloadHash,
21
+ ts: fields.ts,
22
+ initiator: fields.initiator,
23
+ responder: fields.responder,
24
+ };
25
+ }
26
+ /** Both parties sign the identical body — order-independent. */
27
+ export function signA2ABody(body, privateKey) {
28
+ return encodeSig(ed25519.sign(canonicalBytes(body), privateKey));
29
+ }
30
+ export function assembleA2AReceipt(body, initiatorSig, responderSig) {
31
+ return {
32
+ ...body,
33
+ initiator: { ...body.initiator, sig: initiatorSig },
34
+ responder: { ...body.responder, sig: responderSig },
35
+ };
36
+ }
37
+ /** Hash of the full receipt (both sigs) — what both agents' next `prev` points to. */
38
+ export function a2aHash(receipt) {
39
+ return jcsHash(receipt);
40
+ }
41
+ export function bodyOf(receipt) {
42
+ const { sig: _i, ...initiator } = receipt.initiator;
43
+ const { sig: _r, ...responder } = receipt.responder;
44
+ return { ...receipt, initiator, responder };
45
+ }
46
+ function partySigOk(body, party) {
47
+ const pub = publicKeyFromDid(party.agent_id);
48
+ const sig = decodeSig(party.sig);
49
+ if (!pub || !sig)
50
+ return false;
51
+ try {
52
+ return ed25519.verify(sig, canonicalBytes(body), pub);
53
+ }
54
+ catch {
55
+ return false;
56
+ }
57
+ }
58
+ /** Full A2A verification per SPEC §9. `expectedPrevFor` maps agent DID → required prev. */
59
+ export function verifyA2AReceipt(receipt, opts = {}) {
60
+ if (receipt.v !== 1 || receipt.type !== 'a2a')
61
+ return { ok: false, error: 'not an a2a receipt' };
62
+ if (receipt.initiator.agent_id === receipt.responder.agent_id) {
63
+ return { ok: false, error: 'initiator and responder must be distinct' };
64
+ }
65
+ const ts = new Date(receipt.ts);
66
+ if (Number.isNaN(ts.getTime()))
67
+ return { ok: false, error: 'invalid ts' };
68
+ const body = bodyOf(receipt);
69
+ for (const [role, party] of [['initiator', receipt.initiator], ['responder', receipt.responder]]) {
70
+ if (!partySigOk(body, party))
71
+ return { ok: false, error: `${role}: bad signature` };
72
+ const chain = verifyChain(party.delegation, { agentId: party.agent_id, revoked: opts.revoked, at: ts });
73
+ if (!chain.ok)
74
+ return { ok: false, error: `${role} delegation: ${chain.error}` };
75
+ if (!scopesAllow(chain.effectiveScopes, receipt.target)) {
76
+ return { ok: false, error: `${role}: target ${receipt.target} outside effective scopes` };
77
+ }
78
+ const expected = opts.expectedPrevFor?.[party.agent_id];
79
+ if (expected !== undefined && party.prev !== expected) {
80
+ return { ok: false, error: `${role}: prev hash does not match chain head (chain broken)` };
81
+ }
82
+ }
83
+ return { ok: true };
84
+ }
85
+ /** The DIDs participating in any log receipt (solo or a2a). */
86
+ export function participantsOf(entry) {
87
+ if (entry.type === 'a2a')
88
+ return [entry.initiator.agent_id, entry.responder.agent_id];
89
+ return entry.agent_id ? [entry.agent_id] : [];
90
+ }
91
+ /** The `prev` a given participant declared in a log receipt, or undefined if not a party. */
92
+ export function prevFor(entry, agentId) {
93
+ if (entry.type === 'a2a') {
94
+ if (entry.initiator?.agent_id === agentId)
95
+ return entry.initiator.prev;
96
+ if (entry.responder?.agent_id === agentId)
97
+ return entry.responder.prev;
98
+ return undefined;
99
+ }
100
+ return entry.agent_id === agentId ? entry.prev : undefined;
101
+ }
102
+ //# sourceMappingURL=a2a.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2a.js","sourceRoot":"","sources":["../src/a2a.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAuB,MAAM,iBAAiB,CAAC;AA2BhF,MAAM,UAAU,YAAY,CAAC,MAO5B;IACC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/F,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,OAAO;QACL,CAAC,EAAE,CAAC;QACJ,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,YAAY,EAAE,MAAM,CAAC,WAAW;QAChC,EAAE,EAAE,MAAM,CAAC,EAAE;QACb,SAAS,EAAE,MAAM,CAAC,SAAS;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;YAAE,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC;QACvE,IAAI,KAAK,CAAC,SAAS,EAAE,QAAQ,KAAK,OAAO;YAAE,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC;QACvE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAE,KAAK,CAAC,IAAsB,CAAC,CAAC,CAAC,SAAS,CAAC;AAChF,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { type RevocationRecord } from './delegation.js';
2
+ import { type SignedTreeHead } from './sth.js';
3
+ import { type Receipt } from './receipt.js';
4
+ import { type A2AReceipt } from './a2a.js';
5
+ export interface BundledReceipt {
6
+ receipt: Receipt | A2AReceipt;
7
+ hash: string;
8
+ index: number;
9
+ proof: string[];
10
+ }
11
+ export interface BundledRevocation {
12
+ revocation: RevocationRecord;
13
+ cert_hash: string;
14
+ index: number;
15
+ proof: string[];
16
+ }
17
+ export interface BundledAnchor {
18
+ sth: SignedTreeHead;
19
+ backend: string;
20
+ ref: string;
21
+ block?: number;
22
+ anchored_at: string;
23
+ /** Consistency proof from the anchored tree to this bundle's STH. */
24
+ consistency_proof: string[];
25
+ }
26
+ export interface AuditBundle {
27
+ v: 1;
28
+ bundle_type: 'zanii-audit-bundle';
29
+ generated_at: string;
30
+ log_id: string;
31
+ agent_id: string;
32
+ sth: SignedTreeHead;
33
+ receipts: BundledReceipt[];
34
+ revocations: BundledRevocation[];
35
+ anchors: BundledAnchor[];
36
+ }
37
+ export interface BundleCheck {
38
+ label: string;
39
+ ok: boolean;
40
+ detail?: string;
41
+ }
42
+ export interface BundleReport {
43
+ ok: boolean;
44
+ checks: BundleCheck[];
45
+ stats: {
46
+ receipts: number;
47
+ first_ts: string | null;
48
+ last_ts: string | null;
49
+ revoked_certs: number;
50
+ anchored_through: number | null;
51
+ };
52
+ }
53
+ /** Fully verify an audit bundle offline. Every failure is reported, none throws. */
54
+ export declare function verifyAuditBundle(bundle: AuditBundle): BundleReport;
55
+ //# sourceMappingURL=bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAOA,OAAO,EAA8B,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEpF,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAA6C,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtF,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,GAAG,UAAU,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,gBAAgB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,cAAc,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IAC1B,CAAC,EAAE,CAAC,CAAC;IACL,WAAW,EAAE,oBAAoB,CAAC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,cAAc,CAAC;IACpB,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,WAAW,EAAE,iBAAiB,EAAE,CAAC;IACjC,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,KAAK,EAAE;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,aAAa,EAAE,MAAM,CAAC;QACtB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;KACjC,CAAC;CACH;AAID,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY,CAyGnE"}
package/dist/bundle.js ADDED
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Audit bundles — SPEC §8. A self-contained, offline-verifiable export of one
3
+ * agent's complete action history: receipts, proofs, revocations, anchors.
4
+ * verifyAuditBundle() is pure: no network, no trusted party.
5
+ */
6
+ import { hexToBytes } from '@noble/hashes/utils';
7
+ import { canonicalBytes, jcsHash } from './encoding.js';
8
+ import { certHash, verifyRevocation } from './delegation.js';
9
+ import { leafHash, verifyConsistency, verifyInclusion } from './merkle.js';
10
+ import { verifySTH } from './sth.js';
11
+ import { verifyReceipt } from './receipt.js';
12
+ import { participantsOf, prevFor, verifyA2AReceipt } from './a2a.js';
13
+ const root = (sth) => hexToBytes(sth.root.replace('sha256:', ''));
14
+ /** Fully verify an audit bundle offline. Every failure is reported, none throws. */
15
+ export function verifyAuditBundle(bundle) {
16
+ const checks = [];
17
+ const push = (label, ok, detail) => checks.push({ label, ok, detail });
18
+ try {
19
+ push('bundle format', bundle.v === 1 && bundle.bundle_type === 'zanii-audit-bundle');
20
+ push('signed tree head signature and log identity', verifySTH(bundle.sth) && bundle.sth.log_id === bundle.log_id, bundle.log_id);
21
+ // Receipts: signature/delegation/scope, identity, hash, inclusion, prev-chain continuity.
22
+ let receiptsOk = true;
23
+ let chainOk = true;
24
+ let expectedPrev = null;
25
+ const sorted = [...bundle.receipts].sort((a, b) => a.index - b.index);
26
+ for (const [i, br] of sorted.entries()) {
27
+ // revocation reported separately below
28
+ const check = br.receipt.type === 'a2a'
29
+ ? verifyA2AReceipt(br.receipt)
30
+ : verifyReceipt(br.receipt);
31
+ const identityOk = participantsOf(br.receipt).includes(bundle.agent_id);
32
+ const hashOk = jcsHash(br.receipt) === br.hash;
33
+ const inclusionOk = verifyInclusion(leafHash(canonicalBytes(br.receipt)), br.index, bundle.sth.size, br.proof.map(hexToBytes), root(bundle.sth));
34
+ if (!check.ok || !identityOk || !hashOk || !inclusionOk) {
35
+ receiptsOk = false;
36
+ push(`receipt #${i} (leaf ${br.index})`, false, check.error ?? 'hash/identity/inclusion mismatch');
37
+ }
38
+ if (prevFor(br.receipt, bundle.agent_id) !== expectedPrev)
39
+ chainOk = false;
40
+ expectedPrev = br.hash;
41
+ }
42
+ push(`all ${sorted.length} receipts: signature, delegation, scope, hash, Merkle inclusion`, receiptsOk);
43
+ push('per-agent hash chain is complete and unbroken (full history, no gaps)', chainOk);
44
+ // Revocations: issuer-signed and present in the tree.
45
+ let revocationsOk = true;
46
+ for (const bv of bundle.revocations) {
47
+ const sigOk = verifyRevocation(bv.revocation) && certHash(bv.revocation.cert) === bv.cert_hash;
48
+ const inclusionOk = verifyInclusion(leafHash(canonicalBytes(bv.revocation)), bv.index, bundle.sth.size, bv.proof.map(hexToBytes), root(bundle.sth));
49
+ if (!sigOk || !inclusionOk) {
50
+ revocationsOk = false;
51
+ push(`revocation of ${bv.cert_hash.slice(0, 24)}…`, false);
52
+ }
53
+ }
54
+ push(`all ${bundle.revocations.length} revocation records: issuer signature and Merkle inclusion`, revocationsOk);
55
+ // Anchors: each anchored STH verifies and the bundle tree is an append-only extension of it.
56
+ let anchorsOk = true;
57
+ let anchoredThrough = null;
58
+ for (const a of bundle.anchors) {
59
+ const sthOk = verifySTH(a.sth) && a.sth.log_id === bundle.log_id;
60
+ const consistent = verifyConsistency(a.sth.size, bundle.sth.size, root(a.sth), root(bundle.sth), a.consistency_proof.map(hexToBytes));
61
+ if (!sthOk || !consistent) {
62
+ anchorsOk = false;
63
+ push(`anchor ${a.ref}`, false, 'STH signature or consistency proof failed');
64
+ }
65
+ else {
66
+ anchoredThrough = Math.max(anchoredThrough ?? 0, a.sth.size);
67
+ }
68
+ }
69
+ push(`all ${bundle.anchors.length} anchors: anchored STH valid, bundle tree is append-only extension`, anchorsOk, anchoredThrough !== null ? `history immutable through leaf ${anchoredThrough - 1}` : undefined);
70
+ const revokedCertHashes = new Set(bundle.revocations.map((r) => r.cert_hash));
71
+ return {
72
+ ok: checks.every((c) => c.ok),
73
+ checks,
74
+ stats: {
75
+ receipts: sorted.length,
76
+ first_ts: sorted[0]?.receipt.ts ?? null,
77
+ last_ts: sorted[sorted.length - 1]?.receipt.ts ?? null,
78
+ revoked_certs: revokedCertHashes.size,
79
+ anchored_through: anchoredThrough,
80
+ },
81
+ };
82
+ }
83
+ catch (err) {
84
+ push('bundle parses and verifies without errors', false, String(err));
85
+ return {
86
+ ok: false,
87
+ checks,
88
+ stats: { receipts: 0, first_ts: null, last_ts: null, revoked_certs: 0, anchored_through: null },
89
+ };
90
+ }
91
+ }
92
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAyB,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,iBAAi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B,CAAC,IAAI;gBACrC,gBAAgB,EAAE,eAAe;aAClC;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,2CAA2C,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACtE,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM;YACN,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,EAAE,gBAAgB,EAAE,IAAI,EAAE;SAChG,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,48 @@
1
+ export interface DelegationCert {
2
+ v: 1;
3
+ issuer: string;
4
+ subject: string;
5
+ scopes: string[];
6
+ exp: string;
7
+ sig: string;
8
+ }
9
+ export interface ChainResult {
10
+ ok: boolean;
11
+ error?: string;
12
+ /** Only set when ok. Scopes the final subject may act under. */
13
+ effectiveScopes?: string[];
14
+ }
15
+ export declare function createCert(fields: {
16
+ issuer: string;
17
+ subject: string;
18
+ scopes: string[];
19
+ exp: string;
20
+ }, issuerPrivateKey: Uint8Array): DelegationCert;
21
+ /** Hash of the full cert (incl. sig) — the revocation identifier. */
22
+ export declare function certHash(cert: DelegationCert): string;
23
+ /** Does `scope` cover `target`? `a.*` covers `a`, `a.b`, `a.b.c`, `a.*`; `*` covers all. */
24
+ export declare function scopeCovers(scope: string, target: string): boolean;
25
+ export declare function scopesAllow(scopes: string[], target: string): boolean;
26
+ /** In-log revocation record — SPEC §6. Only the cert's issuer can revoke it. */
27
+ export interface RevocationRecord {
28
+ v: 1;
29
+ type: 'revocation';
30
+ cert: DelegationCert;
31
+ ts: string;
32
+ sig: string;
33
+ }
34
+ export declare function createRevocation(cert: DelegationCert, ts: string, issuerPrivateKey: Uint8Array): RevocationRecord;
35
+ /** Valid iff the embedded cert verifies AND the record is signed by the cert's issuer. */
36
+ export declare function verifyRevocation(record: RevocationRecord): boolean;
37
+ export declare function verifyCertSignature(cert: DelegationCert): boolean;
38
+ /**
39
+ * Validate a delegation chain (root first) per SPEC §2.
40
+ * `at` defaults to now; `revoked` is a set of cert hashes.
41
+ */
42
+ export declare function verifyChain(chain: DelegationCert[], opts: {
43
+ agentId: string;
44
+ expectedRoot?: string;
45
+ revoked?: Set<string>;
46
+ at?: Date;
47
+ }): ChainResult;
48
+ //# sourceMappingURL=delegation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegation.d.ts","sourceRoot":"","sources":["../src/delegation.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,CAAC,CAAC;IACL,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,wBAAgB,UAAU,CACxB,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAC1E,gBAAgB,EAAE,UAAU,GAC3B,cAAc,CAMhB;AAED,qEAAqE;AACrE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAErD;AAED,4FAA4F;AAC5F,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAQlE;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAErE;AAED,g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