@agentplat/trust 0.3.0-alpha.4

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 (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +14 -0
  3. package/dist/canonical.d.ts +20 -0
  4. package/dist/canonical.d.ts.map +1 -0
  5. package/dist/canonical.js +173 -0
  6. package/dist/canonical.js.map +1 -0
  7. package/dist/causal.d.ts +7 -0
  8. package/dist/causal.d.ts.map +1 -0
  9. package/dist/causal.js +155 -0
  10. package/dist/causal.js.map +1 -0
  11. package/dist/eligibility.d.ts +8 -0
  12. package/dist/eligibility.d.ts.map +1 -0
  13. package/dist/eligibility.js +325 -0
  14. package/dist/eligibility.js.map +1 -0
  15. package/dist/evidence.d.ts +20 -0
  16. package/dist/evidence.d.ts.map +1 -0
  17. package/dist/evidence.js +424 -0
  18. package/dist/evidence.js.map +1 -0
  19. package/dist/fusion.d.ts +8 -0
  20. package/dist/fusion.d.ts.map +1 -0
  21. package/dist/fusion.js +1278 -0
  22. package/dist/fusion.js.map +1 -0
  23. package/dist/index.d.ts +13 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +13 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/lifecycle.d.ts +41 -0
  28. package/dist/lifecycle.d.ts.map +1 -0
  29. package/dist/lifecycle.js +1369 -0
  30. package/dist/lifecycle.js.map +1 -0
  31. package/dist/mesh-records.d.ts +36 -0
  32. package/dist/mesh-records.d.ts.map +1 -0
  33. package/dist/mesh-records.js +133 -0
  34. package/dist/mesh-records.js.map +1 -0
  35. package/dist/policy.d.ts +9 -0
  36. package/dist/policy.d.ts.map +1 -0
  37. package/dist/policy.js +598 -0
  38. package/dist/policy.js.map +1 -0
  39. package/dist/profile.d.ts +21 -0
  40. package/dist/profile.d.ts.map +1 -0
  41. package/dist/profile.js +253 -0
  42. package/dist/profile.js.map +1 -0
  43. package/dist/quarantine.d.ts +53 -0
  44. package/dist/quarantine.d.ts.map +1 -0
  45. package/dist/quarantine.js +742 -0
  46. package/dist/quarantine.js.map +1 -0
  47. package/dist/sha256.d.ts +2 -0
  48. package/dist/sha256.d.ts.map +1 -0
  49. package/dist/sha256.js +66 -0
  50. package/dist/sha256.js.map +1 -0
  51. package/dist/state.d.ts +18 -0
  52. package/dist/state.d.ts.map +1 -0
  53. package/dist/state.js +1015 -0
  54. package/dist/state.js.map +1 -0
  55. package/dist/types.d.ts +862 -0
  56. package/dist/types.d.ts.map +1 -0
  57. package/dist/types.js +60 -0
  58. package/dist/types.js.map +1 -0
  59. package/dist/validation.d.ts +18 -0
  60. package/dist/validation.d.ts.map +1 -0
  61. package/dist/validation.js +223 -0
  62. package/dist/validation.js.map +1 -0
  63. package/package.json +43 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
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
95
+ Derivative 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,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # @agentplat/trust
2
+
3
+ Provider-neutral, browser-safe primitives for deterministic Evidence and Trust
4
+ state. The package has no network, clock, persistence, key-discovery or
5
+ dispatch dependency.
6
+
7
+ The root exports strict canonical JSON handling, domain-separated digests,
8
+ closed Evidence contracts, immutable empty state and protected snapshot helpers.
9
+ `@agentplat/trust/mesh-records` exports pure Mesh-to-local normalizers; callers
10
+ must perform authentication and authority checks before admitting their output.
11
+
12
+ This package supplies no global reputation, identity, admission, lease or action
13
+ authority. Those boundaries remain with the application and their existing
14
+ packages.
@@ -0,0 +1,20 @@
1
+ import type { JsonValue } from "@agentplat/core";
2
+ import type { TrustDigestDomainV1 } from "./types.js";
3
+ export declare class TrustValidationError extends Error {
4
+ readonly name = "TrustValidationError";
5
+ }
6
+ export interface StrictJsonLimitsV1 {
7
+ readonly maximumBytes: number;
8
+ readonly maximumDepth: number;
9
+ readonly maximumNodes: number;
10
+ readonly maximumKeysPerObject: number;
11
+ readonly maximumItemsPerArray: number;
12
+ }
13
+ export declare const DEFAULT_STRICT_JSON_LIMITS_V1: Readonly<StrictJsonLimitsV1>;
14
+ export declare function canonicalizeTrustJsonV1(value: JsonValue, limits?: StrictJsonLimitsV1): string;
15
+ export declare function canonicalTrustJsonBytesV1(value: JsonValue, limits?: StrictJsonLimitsV1): Uint8Array;
16
+ export declare function digestTrustJsonV1(domain: TrustDigestDomainV1, value: JsonValue, limits?: StrictJsonLimitsV1): string;
17
+ export declare function sha256TrustBytesV1(bytes: Uint8Array): string;
18
+ export declare function utf8ByteLengthV1(value: string): number;
19
+ export declare function deepFreeze<T>(value: T, seen?: Set<object>): T;
20
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AA+CtD,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,IAAI,0BAA0B;CACxC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;CACvC;AAED,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,kBAAkB,CAOnE,CAAC;AA6GL,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,EAChB,MAAM,GAAE,kBAAkD,GACzD,MAAM,CAKR;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,SAAS,EAChB,MAAM,CAAC,EAAE,kBAAkB,GAC1B,UAAU,CAEZ;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,SAAS,EAChB,MAAM,CAAC,EAAE,kBAAkB,GAC1B,MAAM,CAQR;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAE5D;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,cAAoB,GAAG,CAAC,CAQnE"}
@@ -0,0 +1,173 @@
1
+ import { sha256Hex } from "./sha256.js";
2
+ const encoder = new TextEncoder();
3
+ const trustDigestDomains = new Set([
4
+ "scope",
5
+ "subject",
6
+ "claim",
7
+ "claim-relation",
8
+ "attestation",
9
+ "attestation-relation",
10
+ "challenge",
11
+ "challenge-relation",
12
+ "challenge-resolution",
13
+ "retraction",
14
+ "retraction-relation",
15
+ "assertion",
16
+ "root-basis",
17
+ "content-resolution",
18
+ "content-resolution-invalidation",
19
+ "policy",
20
+ "source-binding",
21
+ "fusion-input",
22
+ "fusion-decision",
23
+ "profile-key",
24
+ "profile",
25
+ "eligibility-request",
26
+ "eligibility-decision",
27
+ "quarantine-key",
28
+ "quarantine-evidence-set",
29
+ "quarantine-record",
30
+ "recovery-evidence-set",
31
+ "recovery-decision",
32
+ "mesh-subject-mapping",
33
+ "mesh-eligibility-config",
34
+ "inference-subject-mapping",
35
+ "inference-eligibility-config",
36
+ "dependency-binding",
37
+ "causal-authorization",
38
+ "origin-proof",
39
+ "state",
40
+ "snapshot",
41
+ "snapshot-integrity",
42
+ "trace",
43
+ "observation",
44
+ ]);
45
+ export class TrustValidationError extends Error {
46
+ name = "TrustValidationError";
47
+ }
48
+ export const DEFAULT_STRICT_JSON_LIMITS_V1 = Object.freeze({
49
+ maximumBytes: 65_536,
50
+ maximumDepth: 32,
51
+ maximumNodes: 4_096,
52
+ maximumKeysPerObject: 256,
53
+ maximumItemsPerArray: 4_096,
54
+ });
55
+ function assertWellFormedUnicode(value, label) {
56
+ for (let index = 0; index < value.length; index += 1) {
57
+ const code = value.charCodeAt(index);
58
+ if (code >= 0xd800 && code <= 0xdbff) {
59
+ index += 1;
60
+ if (index >= value.length ||
61
+ value.charCodeAt(index) < 0xdc00 ||
62
+ value.charCodeAt(index) > 0xdfff)
63
+ throw new TrustValidationError(`${label} contains an unpaired surrogate`);
64
+ }
65
+ else if (code >= 0xdc00 && code <= 0xdfff) {
66
+ throw new TrustValidationError(`${label} contains an unpaired surrogate`);
67
+ }
68
+ }
69
+ }
70
+ function canonical(value, seen, limits, depth, counters) {
71
+ if (depth > limits.maximumDepth)
72
+ throw new TrustValidationError("JSON maximum depth exceeded");
73
+ counters.nodes += 1;
74
+ if (counters.nodes > limits.maximumNodes)
75
+ throw new TrustValidationError("JSON maximum nodes exceeded");
76
+ if (value === null)
77
+ return "null";
78
+ switch (typeof value) {
79
+ case "boolean":
80
+ return value ? "true" : "false";
81
+ case "string":
82
+ assertWellFormedUnicode(value, "JSON string");
83
+ return JSON.stringify(value);
84
+ case "number":
85
+ if (!Number.isFinite(value))
86
+ throw new TrustValidationError("JSON numbers must be finite");
87
+ if (Number.isInteger(value) && !Number.isSafeInteger(value))
88
+ throw new TrustValidationError("JSON integers must be safe");
89
+ return Object.is(value, -0) ? "0" : JSON.stringify(value);
90
+ case "object":
91
+ break;
92
+ default:
93
+ throw new TrustValidationError("JSON contains a non-JSON value");
94
+ }
95
+ if (seen.has(value))
96
+ throw new TrustValidationError("JSON may not contain cycles");
97
+ seen.add(value);
98
+ let result;
99
+ if (Array.isArray(value)) {
100
+ if (value.length > limits.maximumItemsPerArray)
101
+ throw new TrustValidationError("JSON maximum array items exceeded");
102
+ if (Object.getOwnPropertySymbols(value).length)
103
+ throw new TrustValidationError("JSON arrays may not contain symbol keys");
104
+ const names = Object.getOwnPropertyNames(value);
105
+ for (let index = 0; index < value.length; index += 1) {
106
+ const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
107
+ if (!descriptor)
108
+ throw new TrustValidationError("JSON arrays may not be sparse");
109
+ if (!descriptor.enumerable || descriptor.get || descriptor.set)
110
+ throw new TrustValidationError("JSON arrays must contain enumerable data");
111
+ }
112
+ if (names.length !== value.length + 1 || !names.includes("length"))
113
+ throw new TrustValidationError("JSON arrays may not contain extra properties");
114
+ const lengthDescriptor = Object.getOwnPropertyDescriptor(value, "length");
115
+ if (!lengthDescriptor || lengthDescriptor.get || lengthDescriptor.set)
116
+ throw new TrustValidationError("JSON arrays have an invalid length property");
117
+ result = `[${value.map((item) => canonical(item, seen, limits, depth + 1, counters)).join(",")}]`;
118
+ }
119
+ else {
120
+ const prototype = Object.getPrototypeOf(value);
121
+ if (prototype !== Object.prototype && prototype !== null)
122
+ throw new TrustValidationError("JSON requires plain objects");
123
+ if (Object.getOwnPropertySymbols(value).length)
124
+ throw new TrustValidationError("JSON may not contain symbol keys");
125
+ const keys = Object.getOwnPropertyNames(value);
126
+ if (keys.length > limits.maximumKeysPerObject)
127
+ throw new TrustValidationError("JSON maximum object keys exceeded");
128
+ keys.sort();
129
+ for (const key of keys) {
130
+ assertWellFormedUnicode(key, "JSON key");
131
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
132
+ if (!descriptor ||
133
+ !descriptor.enumerable ||
134
+ descriptor.get ||
135
+ descriptor.set)
136
+ throw new TrustValidationError("JSON must contain enumerable data properties");
137
+ }
138
+ result = `{${keys.map((key) => `${JSON.stringify(key)}:${canonical(value[key], seen, limits, depth + 1, counters)}`).join(",")}}`;
139
+ }
140
+ seen.delete(value);
141
+ return result;
142
+ }
143
+ export function canonicalizeTrustJsonV1(value, limits = DEFAULT_STRICT_JSON_LIMITS_V1) {
144
+ const result = canonical(value, new Set(), limits, 0, { nodes: 0 });
145
+ if (encoder.encode(result).byteLength > limits.maximumBytes)
146
+ throw new TrustValidationError("JSON maximum bytes exceeded");
147
+ return result;
148
+ }
149
+ export function canonicalTrustJsonBytesV1(value, limits) {
150
+ return encoder.encode(canonicalizeTrustJsonV1(value, limits));
151
+ }
152
+ export function digestTrustJsonV1(domain, value, limits) {
153
+ if (!trustDigestDomains.has(domain))
154
+ throw new TrustValidationError("digest domain is invalid");
155
+ return sha256Hex(encoder.encode(`agentplat.trust/${domain}/v1\0${canonicalizeTrustJsonV1(value, limits)}`));
156
+ }
157
+ export function sha256TrustBytesV1(bytes) {
158
+ return sha256Hex(bytes);
159
+ }
160
+ export function utf8ByteLengthV1(value) {
161
+ assertWellFormedUnicode(value, "string");
162
+ return encoder.encode(value).byteLength;
163
+ }
164
+ export function deepFreeze(value, seen = new Set()) {
165
+ if (value && typeof value === "object" && !seen.has(value)) {
166
+ seen.add(value);
167
+ for (const item of Object.values(value))
168
+ deepFreeze(item, seen);
169
+ Object.freeze(value);
170
+ }
171
+ return value;
172
+ }
173
+ //# sourceMappingURL=canonical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAsB;IACtD,OAAO;IACP,SAAS;IACT,OAAO;IACP,gBAAgB;IAChB,aAAa;IACb,sBAAsB;IACtB,WAAW;IACX,oBAAoB;IACpB,sBAAsB;IACtB,YAAY;IACZ,qBAAqB;IACrB,WAAW;IACX,YAAY;IACZ,oBAAoB;IACpB,iCAAiC;IACjC,QAAQ;IACR,gBAAgB;IAChB,cAAc;IACd,iBAAiB;IACjB,aAAa;IACb,SAAS;IACT,qBAAqB;IACrB,sBAAsB;IACtB,gBAAgB;IAChB,yBAAyB;IACzB,mBAAmB;IACnB,uBAAuB;IACvB,mBAAmB;IACnB,sBAAsB;IACtB,yBAAyB;IACzB,2BAA2B;IAC3B,8BAA8B;IAC9B,oBAAoB;IACpB,sBAAsB;IACtB,cAAc;IACd,OAAO;IACP,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;AAC1C,CAAC;AAED,MAAM,UAAU,UAAU,CAAI,KAAQ,EAAE,OAAO,IAAI,GAAG,EAAU;IAC9D,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAe,CAAC,EAAE,CAAC;QACrE,IAAI,CAAC,GAAG,CAAC,KAAe,CAAC,CAAC;QAC1B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAgC,CAAC;YAChE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { EvidenceCausalAuthorizationBasisV1, EvidenceCausalAuthorizationV1 } from "./types.js";
2
+ export declare function validateEvidenceCausalAuthorizationBasisV1(value: unknown): EvidenceCausalAuthorizationBasisV1;
3
+ export declare function digestEvidenceCausalAuthorizationV1(value: unknown): string;
4
+ export declare function validateEvidenceCausalAuthorizationV1(value: unknown): EvidenceCausalAuthorizationV1;
5
+ export declare function createEvidenceCausalAuthorizationV1(input: Omit<EvidenceCausalAuthorizationV1, "authorizationId" | "authorizationDigest">): EvidenceCausalAuthorizationV1;
6
+ export declare function causalAuthorizationReferenceKeyV1(value: Pick<EvidenceCausalAuthorizationBasisV1, "kind" | "referenceType" | "referenceId" | "referenceDigest">): string;
7
+ //# sourceMappingURL=causal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"causal.d.ts","sourceRoot":"","sources":["../src/causal.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,kCAAkC,EAClC,6BAA6B,EAE9B,MAAM,YAAY,CAAC;AAuDpB,wBAAgB,0CAA0C,CACxD,KAAK,EAAE,OAAO,GACb,kCAAkC,CAgCpC;AAWD,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAM1E;AAoFD,wBAAgB,qCAAqC,CACnD,KAAK,EAAE,OAAO,GACb,6BAA6B,CAE/B;AACD,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,IAAI,CACT,6BAA6B,EAC7B,iBAAiB,GAAG,qBAAqB,CAC1C,GACA,6BAA6B,CAuB/B;AAED,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,IAAI,CACT,kCAAkC,EAClC,MAAM,GAAG,eAAe,GAAG,aAAa,GAAG,iBAAiB,CAC7D,GACA,MAAM,CAER"}
package/dist/causal.js ADDED
@@ -0,0 +1,155 @@
1
+ import { deepFreeze, digestTrustJsonV1, TrustValidationError, } from "./canonical.js";
2
+ import { assertExactKeys, assertIdentifier, assertSafeInteger, assertTrustDigest, validateEvidenceReferenceV1, } from "./validation.js";
3
+ const compare = (left, right) => left < right ? -1 : left > right ? 1 : 0;
4
+ const relationValues = new Set([
5
+ "subject_self",
6
+ "work_assignee",
7
+ "work_owner",
8
+ "objective_observer",
9
+ "recovery_witness",
10
+ "local_system",
11
+ "target_author",
12
+ ]);
13
+ const authorizationKeys = [
14
+ "schemaVersion",
15
+ "authorizationId",
16
+ "authorizationDigest",
17
+ "recordId",
18
+ "recordDigest",
19
+ "recordKind",
20
+ "policyDigest",
21
+ "criterionId",
22
+ "subjectDigest",
23
+ "scopeDigest",
24
+ "targetRecordId",
25
+ "targetRecordDigest",
26
+ "sourceRelation",
27
+ "authorityBindingDigest",
28
+ "authorityProofDigest",
29
+ "bases",
30
+ "authorizedAtLogicalMs",
31
+ ];
32
+ const basisKeys = [
33
+ "schemaVersion",
34
+ "kind",
35
+ "referenceType",
36
+ "referenceId",
37
+ "referenceDigest",
38
+ "resolvedDigest",
39
+ "trustedEffectiveAtLogicalMs",
40
+ "resolverBindingDigest",
41
+ "resolutionProofDigest",
42
+ ];
43
+ function referenceKey(value) {
44
+ return `${value.kind}\u0000${value.referenceType}\u0000${value.referenceId}\u0000${value.referenceDigest}`;
45
+ }
46
+ export function validateEvidenceCausalAuthorizationBasisV1(value) {
47
+ assertExactKeys(value, basisKeys, "causal authorization basis");
48
+ const v = value;
49
+ if (v.schemaVersion !== 1)
50
+ throw new TrustValidationError("causal authorization basis schema is invalid");
51
+ // Reuse the public reference grammar, including Mesh and Control digest domains.
52
+ validateEvidenceReferenceV1({
53
+ schemaVersion: v.schemaVersion,
54
+ kind: v.kind,
55
+ referenceType: v.referenceType,
56
+ referenceId: v.referenceId,
57
+ referenceDigest: v.referenceDigest,
58
+ });
59
+ assertTrustDigest(v.resolvedDigest, "resolvedDigest");
60
+ assertSafeInteger(v.trustedEffectiveAtLogicalMs, "trustedEffectiveAtLogicalMs");
61
+ if (v.kind === "evidence") {
62
+ if (v.resolverBindingDigest !== null || v.resolutionProofDigest !== null)
63
+ throw new TrustValidationError("evidence causal basis may not carry a resolver proof");
64
+ }
65
+ else {
66
+ assertTrustDigest(v.resolverBindingDigest, "resolverBindingDigest");
67
+ assertTrustDigest(v.resolutionProofDigest, "resolutionProofDigest");
68
+ }
69
+ return deepFreeze(structuredClone(v));
70
+ }
71
+ function authorizationBody(value) {
72
+ const { authorizationId: _id, authorizationDigest: _digest, ...body } = value;
73
+ return body;
74
+ }
75
+ export function digestEvidenceCausalAuthorizationV1(value) {
76
+ const authorization = validateCausalAuthorization(value, false);
77
+ return digestTrustJsonV1("causal-authorization", authorizationBody(authorization));
78
+ }
79
+ function validateCausalAuthorization(value, verifyDigest) {
80
+ assertExactKeys(value, authorizationKeys, "causal authorization");
81
+ const v = value;
82
+ if (v.schemaVersion !== 1 ||
83
+ (v.recordKind !== "claim" && v.recordKind !== "challenge"))
84
+ throw new TrustValidationError("causal authorization schema is invalid");
85
+ for (const key of ["recordId", "criterionId"])
86
+ assertIdentifier(v[key], key);
87
+ for (const key of [
88
+ "recordDigest",
89
+ "policyDigest",
90
+ "subjectDigest",
91
+ "scopeDigest",
92
+ "authorityBindingDigest",
93
+ "authorityProofDigest",
94
+ ])
95
+ assertTrustDigest(v[key], key);
96
+ if ((v.targetRecordId === null) !== (v.targetRecordDigest === null))
97
+ throw new TrustValidationError("causal authorization target is inconsistent");
98
+ if (v.targetRecordId !== null) {
99
+ assertIdentifier(v.targetRecordId, "targetRecordId");
100
+ assertTrustDigest(v.targetRecordDigest, "targetRecordDigest");
101
+ }
102
+ if (typeof v.sourceRelation !== "string" ||
103
+ !relationValues.has(v.sourceRelation))
104
+ throw new TrustValidationError("causal authorization source relation is invalid");
105
+ assertSafeInteger(v.authorizedAtLogicalMs, "authorizedAtLogicalMs");
106
+ if (!Array.isArray(v.bases) || v.bases.length === 0)
107
+ throw new TrustValidationError("causal authorization requires bases");
108
+ const bases = v.bases.map(validateEvidenceCausalAuthorizationBasisV1);
109
+ const keys = bases.map(referenceKey);
110
+ if (keys.some((key, index) => index > 0 && compare(keys[index - 1], key) >= 0))
111
+ throw new TrustValidationError("causal authorization bases must be canonically ordered and unique");
112
+ if (bases.some((basis) => basis.trustedEffectiveAtLogicalMs > v.authorizedAtLogicalMs))
113
+ throw new TrustValidationError("causal authorization basis cannot come from the future");
114
+ if (verifyDigest) {
115
+ assertTrustDigest(v.authorizationDigest, "authorizationDigest");
116
+ const candidate = {
117
+ ...v,
118
+ bases,
119
+ };
120
+ const digest = digestTrustJsonV1("causal-authorization", authorizationBody(candidate));
121
+ if (v.authorizationDigest !== digest ||
122
+ v.authorizationId !== `causal-authorization:${digest}`)
123
+ throw new TrustValidationError("causal authorization digest is invalid");
124
+ }
125
+ else {
126
+ assertIdentifier(v.authorizationId, "authorizationId");
127
+ assertTrustDigest(v.authorizationDigest, "authorizationDigest");
128
+ }
129
+ return deepFreeze(structuredClone({
130
+ ...v,
131
+ bases,
132
+ }));
133
+ }
134
+ export function validateEvidenceCausalAuthorizationV1(value) {
135
+ return validateCausalAuthorization(value, true);
136
+ }
137
+ export function createEvidenceCausalAuthorizationV1(input) {
138
+ const body = structuredClone(input);
139
+ // Temporary derived fields let the closed validator normalize bases before digesting.
140
+ const provisional = validateCausalAuthorization({
141
+ ...body,
142
+ authorizationId: "causal-authorization:pending",
143
+ authorizationDigest: "0".repeat(64),
144
+ }, false);
145
+ const digest = digestTrustJsonV1("causal-authorization", authorizationBody(provisional));
146
+ return validateCausalAuthorization({
147
+ ...body,
148
+ authorizationId: `causal-authorization:${digest}`,
149
+ authorizationDigest: digest,
150
+ }, true);
151
+ }
152
+ export function causalAuthorizationReferenceKeyV1(value) {
153
+ return `${value.kind}\u0000${value.referenceType}\u0000${value.referenceId}\u0000${value.referenceDigest}`;
154
+ }
155
+ //# sourceMappingURL=causal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"causal.js","sourceRoot":"","sources":["../src/causal.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EAEjB,iBAAiB,EACjB,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AAEzB,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,KAAa,EAAU,EAAE,CACtD,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,cAAc;IACd,eAAe;IACf,YAAY;IACZ,oBAAoB;IACpB,kBAAkB;IAClB,cAAc;IACd,eAAe;CAChB,CAAC,CAAC;AACH,MAAM,iBAAiB,GAAG;IACxB,eAAe;IACf,iBAAiB;IACjB,qBAAqB;IACrB,UAAU;IACV,cAAc;IACd,YAAY;IACZ,cAAc;IACd,aAAa;IACb,eAAe;IACf,aAAa;IACb,gBAAgB;IAChB,oBAAoB;IACpB,gBAAgB;IAChB,wBAAwB;IACxB,sBAAsB;IACtB,OAAO;IACP,uBAAuB;CACf,CAAC;AACX,MAAM,SAAS,GAAG;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J,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,KAGC;IAED,OAAO,GAAG,KAAK,CAAC,IAA+B,SAAS,KAAK,CAAC,aAAa,SAAS,KAAK,CAAC,WAAW,SAAS,KAAK,CAAC,eAAe,EAAE,CAAC;AACxI,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { EvidenceTrustStateV1, TrustEligibilityDecisionV1, TrustEligibilityRequestV1 } from "./types.js";
2
+ export declare function validateTrustEligibilityRequestV1(value: unknown): TrustEligibilityRequestV1;
3
+ export declare const createTrustEligibilityRequestV1: typeof validateTrustEligibilityRequestV1;
4
+ export declare function digestTrustEligibilityRequestV1(value: TrustEligibilityRequestV1): string;
5
+ export declare function digestTrustEligibilityDecisionV1(value: TrustEligibilityDecisionV1): string;
6
+ export declare function validateTrustEligibilityDecisionV1(value: unknown): TrustEligibilityDecisionV1;
7
+ export declare function evaluateTrustEligibilityV1(stateValue: EvidenceTrustStateV1, requestValue: TrustEligibilityRequestV1, logicalTimeMs: number): TrustEligibilityDecisionV1;
8
+ //# sourceMappingURL=eligibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eligibility.d.ts","sourceRoot":"","sources":["../src/eligibility.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,yBAAyB,EAG1B,MAAM,YAAY,CAAC;AAyGpB,wBAAgB,iCAAiC,CAC/C,KAAK,EAAE,OAAO,GACb,yBAAyB,CAiC3B;AACD,eAAO,MAAM,+BAA+B,0CACT,CAAC;AAEpC,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,yBAAyB,GAC/B,MAAM,CAKR;AASD,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,0BAA0B,GAChC,MAAM,CAKR;AAED,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,OAAO,GACb,0BAA0B,CAsH5B;AAED,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,oBAAoB,EAChC,YAAY,EAAE,yBAAyB,EACvC,aAAa,EAAE,MAAM,GACpB,0BAA0B,CAyL5B"}