@algovoi/substrate 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.
package/LICENSE ADDED
@@ -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.
package/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # @algovoi/substrate (TypeScript)
2
+
3
+ AlgoVoi agentic-payments substrate reference implementation.
4
+
5
+ JCS RFC 8785 canonicalisation, `actionRef` atomic primitive, composite
6
+ trust-query algorithm, compliance receipt shape, and audit chain primitives
7
+ that compose the substrate underneath x402, AP2, A2A, and MPP receipts.
8
+
9
+ The substrate runs in production at `https://api.algovoi.co.uk/compliance`.
10
+ This package is the AlgoVoi-authored TypeScript reference implementation;
11
+ cross-validated byte-for-byte against four other JCS implementations
12
+ (Python `rfc8785`, Go `gowebpki/jcs`, Java `cyberphone`, Rust `serde_jcs`)
13
+ on 53 conformance vectors and 3 composite-trust-query vectors.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install @algovoi/substrate
19
+ ```
20
+
21
+ ## Quickstart
22
+
23
+ ```typescript
24
+ import {
25
+ canonicalize,
26
+ sha256Jcs,
27
+ actionRef,
28
+ compositeTrustQueryHash,
29
+ buildComplianceReceipt,
30
+ appendToChain,
31
+ verifyAuditChain,
32
+ } from '@algovoi/substrate';
33
+
34
+ // Canonicalise to RFC 8785 JCS string.
35
+ canonicalize({ b: 1, a: 2 }); // -> '{"a":2,"b":1}'
36
+
37
+ // action_ref atomic primitive:
38
+ // SHA-256(JCS({agent_id, action_type, scope, timestamp_ms}))
39
+ const ref = actionRef({
40
+ agent_id: 'agent-x',
41
+ action_type: 'payment',
42
+ scope: 'bilateral',
43
+ timestamp_ms: 1716460800000,
44
+ });
45
+
46
+ // Composite trust-query (PR #2440 in x402-foundation/x402).
47
+ const compositeHash = compositeTrustQueryHash([
48
+ { source_id: 'trust-a', score: 80, sig: 'sig-bytes' },
49
+ { source_id: 'trust-b', score: 75, sig: 'sig-bytes' },
50
+ ]);
51
+
52
+ // Compliance receipt (AlgoVoi production schema).
53
+ const receipt = buildComplianceReceipt({
54
+ payer_ref: 'sha256:abc123',
55
+ screen_result: 'ALLOW',
56
+ screen_timestamp_ms: 1716460800000,
57
+ screen_provider_did: 'did:web:api.algovoi.co.uk',
58
+ jurisdiction_flags: ['UK', 'EU'],
59
+ });
60
+
61
+ // Audit chain: monotonic per-row hash chain.
62
+ const row0 = appendToChain(receipt, null);
63
+ const row1 = appendToChain({ event: 'next' }, row0);
64
+ verifyAuditChain([row0, row1]);
65
+ ```
66
+
67
+ ## Substrate discipline
68
+
69
+ This package enforces the AlgoVoi-discipline rules formalised in PR #2436
70
+ (`x402-foundation/x402`, three-voice coalition co-signed):
71
+
72
+ - **Rule 1.** `timestamp_ms` is an epoch-millisecond integer. Floats, ISO
73
+ 8601 strings, and negative values are rejected at the source-side.
74
+ - **Rule 4.** Type validation happens before canonicalisation. Schema-level
75
+ fields that should be integers reject floats hard, not silent-cast.
76
+ - **`canon_version` pin.** Receipts carry `canon_version: "jcs-rfc8785-v1"`
77
+ as an in-band format-version pin for year-five auditability.
78
+ - **Array element order preserved.** `["UK","EU"]` and `["EU","UK"]` hash
79
+ differently per RFC 8785 §3.2.3 -- producer-side ordering is load-bearing.
80
+
81
+ The categorical screen result (`ALLOW` / `REFER` / `DENY`) is enforced as a
82
+ closed set.
83
+
84
+ ## Cross-impl validation
85
+
86
+ This TypeScript package is byte-for-byte equivalent to the Python sibling
87
+ (`algovoi-substrate` on PyPI). The substrate has been validated across five
88
+ implementations:
89
+
90
+ - Python `rfc8785@0.1.4`
91
+ - JavaScript / TypeScript `canonicalize@3.0.0` (this package)
92
+ - Go `gowebpki/jcs v1.0.1`
93
+ - Java `cyberphone/json-canonicalization`
94
+ - Rust `serde_jcs@0.2.0`
95
+
96
+ Substrate matrix:
97
+ <https://gist.github.com/chopmob-cloud/b327814c4e17ed9fc7b4f29c8bda523c>
98
+
99
+ Composite trust-query matrix:
100
+ <https://gist.github.com/chopmob-cloud/f2e9f0877b7d9fff70c8eca46e4ce636>
101
+
102
+ ## Tests
103
+
104
+ ```bash
105
+ npm install
106
+ npm test
107
+ ```
108
+
109
+ ## Production reference
110
+
111
+ The reference exhibit for this substrate is AlgoVoi's
112
+ `/compliance/attestation` audit chain, live at
113
+ `https://api.algovoi.co.uk/compliance/attestation`. The migration boundary
114
+ (receipts before / after 2026-05-21) is observable directly from the chain.
115
+
116
+ ## Spec references
117
+
118
+ - [PR #2436](https://github.com/x402-foundation/x402/pull/2436) -- canonicalisation discipline
119
+ - [PR #2440](https://github.com/x402-foundation/x402/pull/2440) -- composite trust-query
120
+ - [PR #2434](https://github.com/x402-foundation/x402/pull/2434) -- compliance-receipt-fixture
121
+ - [draft-vauban-x402-stark-receipts](https://datatracker.ietf.org/doc/draft-vauban-x402-stark-receipts/)
122
+
123
+ ## Licence
124
+
125
+ Apache 2.0. See `LICENSE`.
126
+
127
+ ## Author
128
+
129
+ AlgoVoi (Christopher Hopley, GitHub `chopmob-cloud`).
@@ -0,0 +1,45 @@
1
+ /**
2
+ * action_ref atomic primitive.
3
+ *
4
+ * action_ref = SHA-256(JCS({agent_id, action_type, scope, timestamp_ms}))
5
+ *
6
+ * The action_ref is the AlgoVoi-authored canonical action identifier used
7
+ * across the substrate. Two emitters describing the same logical action
8
+ * produce the same action_ref by construction.
9
+ *
10
+ * - timestamp_ms is enforced as an epoch-millisecond integer per Substrate
11
+ * Rule 1. Float, ISO 8601 strings, and negative values are rejected.
12
+ * - agent_id, action_type, scope are required non-empty strings.
13
+ * - The preimage shape is fixed at exactly these four fields.
14
+ */
15
+ export declare class ActionRefError extends Error {
16
+ constructor(message: string);
17
+ }
18
+ export interface ActionRefObject {
19
+ agent_id: string;
20
+ action_type: string;
21
+ scope: string;
22
+ timestamp_ms: number;
23
+ }
24
+ export interface ActionRefInput {
25
+ agent_id: string;
26
+ action_type: string;
27
+ scope: string;
28
+ timestamp_ms: number;
29
+ }
30
+ /**
31
+ * Return the validated preimage object for action_ref.
32
+ *
33
+ * The four-field shape is fixed by the substrate; extending it produces
34
+ * a different primitive, not a different action_ref.
35
+ */
36
+ export declare function actionRefObject(input: ActionRefInput): ActionRefObject;
37
+ /**
38
+ * Return the lowercase hex SHA-256 action_ref.
39
+ *
40
+ * action_ref = SHA-256(JCS({agent_id, action_type, scope, timestamp_ms}))
41
+ *
42
+ * Output is plain hex (no algorithm prefix).
43
+ */
44
+ export declare function actionRef(input: ActionRefInput): string;
45
+ //# sourceMappingURL=action-ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-ref.d.ts","sourceRoot":"","sources":["../src/action-ref.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACtB;AAkCD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,eAAe,CAOtE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAGvD"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * action_ref atomic primitive.
3
+ *
4
+ * action_ref = SHA-256(JCS({agent_id, action_type, scope, timestamp_ms}))
5
+ *
6
+ * The action_ref is the AlgoVoi-authored canonical action identifier used
7
+ * across the substrate. Two emitters describing the same logical action
8
+ * produce the same action_ref by construction.
9
+ *
10
+ * - timestamp_ms is enforced as an epoch-millisecond integer per Substrate
11
+ * Rule 1. Float, ISO 8601 strings, and negative values are rejected.
12
+ * - agent_id, action_type, scope are required non-empty strings.
13
+ * - The preimage shape is fixed at exactly these four fields.
14
+ */
15
+ import { sha256Jcs } from './canonicalize.js';
16
+ export class ActionRefError extends Error {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = 'ActionRefError';
20
+ }
21
+ }
22
+ function requireString(field, value) {
23
+ if (typeof value !== 'string') {
24
+ throw new ActionRefError(`${field} must be string, got ${typeof value}`);
25
+ }
26
+ if (value.length === 0) {
27
+ throw new ActionRefError(`${field} must be a non-empty string`);
28
+ }
29
+ return value;
30
+ }
31
+ function requireIntTimestampMs(value) {
32
+ if (typeof value !== 'number') {
33
+ throw new ActionRefError(`timestamp_ms must be epoch-millisecond integer (Substrate Rule 1), got ${typeof value}`);
34
+ }
35
+ if (!Number.isFinite(value)) {
36
+ throw new ActionRefError(`timestamp_ms must be a finite number, got ${value}`);
37
+ }
38
+ if (!Number.isInteger(value)) {
39
+ throw new ActionRefError(`timestamp_ms must be epoch-millisecond integer (Substrate Rule 1), got float ${value}`);
40
+ }
41
+ if (value < 0) {
42
+ throw new ActionRefError(`timestamp_ms must be non-negative, got ${value}`);
43
+ }
44
+ return value;
45
+ }
46
+ /**
47
+ * Return the validated preimage object for action_ref.
48
+ *
49
+ * The four-field shape is fixed by the substrate; extending it produces
50
+ * a different primitive, not a different action_ref.
51
+ */
52
+ export function actionRefObject(input) {
53
+ return {
54
+ agent_id: requireString('agent_id', input.agent_id),
55
+ action_type: requireString('action_type', input.action_type),
56
+ scope: requireString('scope', input.scope),
57
+ timestamp_ms: requireIntTimestampMs(input.timestamp_ms),
58
+ };
59
+ }
60
+ /**
61
+ * Return the lowercase hex SHA-256 action_ref.
62
+ *
63
+ * action_ref = SHA-256(JCS({agent_id, action_type, scope, timestamp_ms}))
64
+ *
65
+ * Output is plain hex (no algorithm prefix).
66
+ */
67
+ export function actionRef(input) {
68
+ const obj = actionRefObject(input);
69
+ return sha256Jcs(obj);
70
+ }
71
+ //# sourceMappingURL=action-ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-ref.js","sourceRoot":"","sources":["../src/action-ref.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AASD,SAAS,aAAa,CAAC,KAAa,EAAE,KAAc;IAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,cAAc,CAAC,GAAG,KAAK,wBAAwB,OAAO,KAAK,EAAE,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,cAAc,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC3C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,cAAc,CACtB,0EAA0E,OAAO,KAAK,EAAE,CACzF,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,cAAc,CACtB,6CAA6C,KAAK,EAAE,CACrD,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,cAAc,CACtB,gFAAgF,KAAK,EAAE,CACxF,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,MAAM,IAAI,cAAc,CAAC,0CAA0C,KAAK,EAAE,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AASD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAqB;IACnD,OAAO;QACL,QAAQ,EAAE,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC;QACnD,WAAW,EAAE,aAAa,CAAC,aAAa,EAAE,KAAK,CAAC,WAAW,CAAC;QAC5D,KAAK,EAAE,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC;QAC1C,YAAY,EAAE,qBAAqB,CAAC,KAAK,CAAC,YAAY,CAAC;KACxD,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,GAAG,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Audit chain primitive: monotonic per-row hash chain.
3
+ *
4
+ * Each row carries:
5
+ * - content_hash: SHA-256(JCS(payload))
6
+ * - prev_hash: previous row's content_hash, or null for the head row
7
+ * - chain_position: monotonically increasing integer starting at 0
8
+ *
9
+ * This is the structure AlgoVoi's production /compliance/attestation chain
10
+ * exposes (Object Lock COMPLIANCE retention to 2033-05-04).
11
+ */
12
+ export declare class AuditChainError extends Error {
13
+ constructor(message: string);
14
+ }
15
+ export interface AuditChainRow {
16
+ chain_position: number;
17
+ content_hash: string;
18
+ prev_hash: string | null;
19
+ payload: unknown;
20
+ }
21
+ /**
22
+ * Build the next row in an audit chain.
23
+ *
24
+ * If prevRow is null, the new row becomes the head (chain_position = 0,
25
+ * prev_hash = null). Otherwise chain_position increments and prev_hash
26
+ * links to prevRow.content_hash.
27
+ */
28
+ export declare function appendToChain(payload: unknown, prevRow: AuditChainRow | null): AuditChainRow;
29
+ /**
30
+ * Verify a chain of audit rows is well-formed and linkage-consistent.
31
+ *
32
+ * Throws AuditChainError on any violation; otherwise returns void.
33
+ */
34
+ export declare function verifyAuditChain(rows: readonly AuditChainRow[]): void;
35
+ //# sourceMappingURL=audit-chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-chain.d.ts","sourceRoot":"","sources":["../src/audit-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,aAAa,GAAG,IAAI,GAC5B,aAAa,CAmCf;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,aAAa,EAAE,GAAG,IAAI,CAqCrE"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Audit chain primitive: monotonic per-row hash chain.
3
+ *
4
+ * Each row carries:
5
+ * - content_hash: SHA-256(JCS(payload))
6
+ * - prev_hash: previous row's content_hash, or null for the head row
7
+ * - chain_position: monotonically increasing integer starting at 0
8
+ *
9
+ * This is the structure AlgoVoi's production /compliance/attestation chain
10
+ * exposes (Object Lock COMPLIANCE retention to 2033-05-04).
11
+ */
12
+ import { sha256Jcs } from './canonicalize.js';
13
+ export class AuditChainError extends Error {
14
+ constructor(message) {
15
+ super(message);
16
+ this.name = 'AuditChainError';
17
+ }
18
+ }
19
+ /**
20
+ * Build the next row in an audit chain.
21
+ *
22
+ * If prevRow is null, the new row becomes the head (chain_position = 0,
23
+ * prev_hash = null). Otherwise chain_position increments and prev_hash
24
+ * links to prevRow.content_hash.
25
+ */
26
+ export function appendToChain(payload, prevRow) {
27
+ let chainPosition;
28
+ let prevHash;
29
+ if (prevRow === null) {
30
+ chainPosition = 0;
31
+ prevHash = null;
32
+ }
33
+ else {
34
+ if (typeof prevRow.chain_position !== 'number' ||
35
+ !Number.isInteger(prevRow.chain_position) ||
36
+ prevRow.chain_position < 0) {
37
+ throw new AuditChainError('prevRow.chain_position must be a non-negative integer');
38
+ }
39
+ if (typeof prevRow.content_hash !== 'string' ||
40
+ prevRow.content_hash.length === 0) {
41
+ throw new AuditChainError('prevRow.content_hash must be a non-empty string');
42
+ }
43
+ chainPosition = prevRow.chain_position + 1;
44
+ prevHash = prevRow.content_hash;
45
+ }
46
+ return {
47
+ chain_position: chainPosition,
48
+ content_hash: sha256Jcs(payload),
49
+ prev_hash: prevHash,
50
+ payload,
51
+ };
52
+ }
53
+ /**
54
+ * Verify a chain of audit rows is well-formed and linkage-consistent.
55
+ *
56
+ * Throws AuditChainError on any violation; otherwise returns void.
57
+ */
58
+ export function verifyAuditChain(rows) {
59
+ let expectedPosition = 0;
60
+ let prevContentHash = null;
61
+ for (let i = 0; i < rows.length; i++) {
62
+ const row = rows[i];
63
+ if (row.chain_position !== expectedPosition) {
64
+ throw new AuditChainError(`row ${i}: chain_position ${row.chain_position} != expected ${expectedPosition}`);
65
+ }
66
+ const recomputed = sha256Jcs(row.payload);
67
+ if (row.content_hash !== recomputed) {
68
+ throw new AuditChainError(`row ${i}: content_hash mismatch -- stored ${row.content_hash} vs recomputed ${recomputed}`);
69
+ }
70
+ if (expectedPosition === 0) {
71
+ if (row.prev_hash !== null) {
72
+ throw new AuditChainError(`row 0 (head): prev_hash must be null, got ${JSON.stringify(row.prev_hash)}`);
73
+ }
74
+ }
75
+ else {
76
+ if (row.prev_hash !== prevContentHash) {
77
+ throw new AuditChainError(`row ${i}: prev_hash ${JSON.stringify(row.prev_hash)} != previous content_hash ${JSON.stringify(prevContentHash)}`);
78
+ }
79
+ }
80
+ prevContentHash = row.content_hash;
81
+ expectedPosition += 1;
82
+ }
83
+ }
84
+ //# sourceMappingURL=audit-chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-chain.js","sourceRoot":"","sources":["../src/audit-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AASD;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAgB,EAChB,OAA6B;IAE7B,IAAI,aAAqB,CAAC;IAC1B,IAAI,QAAuB,CAAC;IAE5B,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,aAAa,GAAG,CAAC,CAAC;QAClB,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC;SAAM,CAAC;QACN,IACE,OAAO,OAAO,CAAC,cAAc,KAAK,QAAQ;YAC1C,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC;YACzC,OAAO,CAAC,cAAc,GAAG,CAAC,EAC1B,CAAC;YACD,MAAM,IAAI,eAAe,CACvB,uDAAuD,CACxD,CAAC;QACJ,CAAC;QACD,IACE,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ;YACxC,OAAO,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EACjC,CAAC;YACD,MAAM,IAAI,eAAe,CACvB,iDAAiD,CAClD,CAAC;QACJ,CAAC;QACD,aAAa,GAAG,OAAO,CAAC,cAAc,GAAG,CAAC,CAAC;QAC3C,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;IAClC,CAAC;IAED,OAAO;QACL,cAAc,EAAE,aAAa;QAC7B,YAAY,EAAE,SAAS,CAAC,OAAO,CAAC;QAChC,SAAS,EAAE,QAAQ;QACnB,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAA8B;IAC7D,IAAI,gBAAgB,GAAG,CAAC,CAAC;IACzB,IAAI,eAAe,GAAkB,IAAI,CAAC;IAE1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;QAErB,IAAI,GAAG,CAAC,cAAc,KAAK,gBAAgB,EAAE,CAAC;YAC5C,MAAM,IAAI,eAAe,CACvB,OAAO,CAAC,oBAAoB,GAAG,CAAC,cAAc,gBAAgB,gBAAgB,EAAE,CACjF,CAAC;QACJ,CAAC;QAED,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,GAAG,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;YACpC,MAAM,IAAI,eAAe,CACvB,OAAO,CAAC,qCAAqC,GAAG,CAAC,YAAY,kBAAkB,UAAU,EAAE,CAC5F,CAAC;QACJ,CAAC;QAED,IAAI,gBAAgB,KAAK,CAAC,EAAE,CAAC;YAC3B,IAAI,GAAG,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;gBAC3B,MAAM,IAAI,eAAe,CACvB,6CAA6C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAC7E,CAAC;YACJ,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,CAAC,SAAS,KAAK,eAAe,EAAE,CAAC;gBACtC,MAAM,IAAI,eAAe,CACvB,OAAO,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,6BAA6B,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CACnH,CAAC;YACJ,CAAC;QACH,CAAC;QAED,eAAe,GAAG,GAAG,CAAC,YAAY,CAAC;QACnC,gBAAgB,IAAI,CAAC,CAAC;IACxB,CAAC;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * JCS RFC 8785 canonicalisation with the AlgoVoi-discipline rules.
3
+ *
4
+ * The canonicalisation discipline is the shared normative substrate for
5
+ * x402, AP2, A2A, and MPP receipts, formalised in PR #2436 in
6
+ * x402-foundation/x402 (three-voice coalition co-signed). This module
7
+ * wraps the `canonicalize` npm package (v3.0.0) with the discipline's
8
+ * pre-canonicalisation rules.
9
+ *
10
+ * Reference matrix: https://gist.github.com/chopmob-cloud/b327814c4e17ed9fc7b4f29c8bda523c
11
+ */
12
+ /**
13
+ * Pin the discipline version. Receipts emitted under this substrate carry
14
+ * this string in their canon_version field so a year-five verifier can pick
15
+ * the correct re-canonicalisation rule from the retained bytes alone.
16
+ */
17
+ export declare const CANON_VERSION: "jcs-rfc8785-v1";
18
+ export declare class CanonicalizationError extends Error {
19
+ constructor(message: string);
20
+ }
21
+ /**
22
+ * Return the canonical JCS string representation of obj.
23
+ *
24
+ * Applies AlgoVoi-discipline pre-canonicalisation type validation, then
25
+ * delegates to canonicalize (RFC 8785) for the canonical bytes.
26
+ *
27
+ * Throws CanonicalizationError on type-validation failure.
28
+ */
29
+ export declare function canonicalize(obj: unknown): string;
30
+ /**
31
+ * Return the canonical JCS UTF-8 bytes of obj as a Uint8Array.
32
+ */
33
+ export declare function canonicalizeBytes(obj: unknown): Uint8Array;
34
+ /**
35
+ * Return the lowercase hex SHA-256 of the JCS canonical bytes of obj.
36
+ *
37
+ * This is the substrate primitive used by action_ref, compliance receipts,
38
+ * audit chain entries, and the composite trust-query algorithm. The string
39
+ * is plain hex without an algorithm prefix.
40
+ */
41
+ export declare function sha256Jcs(obj: unknown): string;
42
+ //# sourceMappingURL=canonicalize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonicalize.d.ts","sourceRoot":"","sources":["../src/canonicalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAG,gBAAyB,CAAC;AAEvD,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAwCD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAYjD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAE1D;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAE9C"}