@decionis/agentsafe 0.1.0 → 0.2.1

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 (128) hide show
  1. package/README.md +41 -3
  2. package/dist/Cli.js +16 -7
  3. package/dist/Cli.js.map +1 -1
  4. package/dist/Index.d.ts +8 -2
  5. package/dist/Index.d.ts.map +1 -1
  6. package/dist/Index.js +8 -2
  7. package/dist/Index.js.map +1 -1
  8. package/dist/adapters/AdapterActionHandler.d.ts +4 -0
  9. package/dist/adapters/AdapterActionHandler.d.ts.map +1 -1
  10. package/dist/adapters/AdapterActionHandler.js +12 -1
  11. package/dist/adapters/AdapterActionHandler.js.map +1 -1
  12. package/dist/adapters/EffectAdapter.d.ts +6 -0
  13. package/dist/adapters/EffectAdapter.d.ts.map +1 -1
  14. package/dist/adapters/EffectAdapter.js.map +1 -1
  15. package/dist/adapters/EffectComparison.d.ts +35 -0
  16. package/dist/adapters/EffectComparison.d.ts.map +1 -1
  17. package/dist/adapters/EffectComparison.js +58 -0
  18. package/dist/adapters/EffectComparison.js.map +1 -1
  19. package/dist/adapters/EffectEvidenceBuilder.d.ts +5 -3
  20. package/dist/adapters/EffectEvidenceBuilder.d.ts.map +1 -1
  21. package/dist/adapters/EffectEvidenceBuilder.js +29 -5
  22. package/dist/adapters/EffectEvidenceBuilder.js.map +1 -1
  23. package/dist/adapters/EffectEvidenceRegister.d.ts +7 -0
  24. package/dist/adapters/EffectEvidenceRegister.d.ts.map +1 -1
  25. package/dist/adapters/EffectEvidenceRegister.js.map +1 -1
  26. package/dist/adapters/banking/CoreBankingHttpAdapter.d.ts.map +1 -1
  27. package/dist/adapters/banking/CoreBankingHttpAdapter.js +7 -0
  28. package/dist/adapters/banking/CoreBankingHttpAdapter.js.map +1 -1
  29. package/dist/cli/CliProcess.d.ts +2 -0
  30. package/dist/cli/CliProcess.d.ts.map +1 -1
  31. package/dist/cli/CliProcess.js +9 -1
  32. package/dist/cli/CliProcess.js.map +1 -1
  33. package/dist/cli/Commands.d.ts +1 -1
  34. package/dist/cli/Commands.d.ts.map +1 -1
  35. package/dist/cli/Commands.js +5 -0
  36. package/dist/cli/Commands.js.map +1 -1
  37. package/dist/cli/Help.d.ts.map +1 -1
  38. package/dist/cli/Help.js +2 -0
  39. package/dist/cli/Help.js.map +1 -1
  40. package/dist/cli/Intercept.d.ts +30 -0
  41. package/dist/cli/Intercept.d.ts.map +1 -0
  42. package/dist/cli/Intercept.js +146 -0
  43. package/dist/cli/Intercept.js.map +1 -0
  44. package/dist/cli/Status.d.ts.map +1 -1
  45. package/dist/cli/Status.js +13 -1
  46. package/dist/cli/Status.js.map +1 -1
  47. package/dist/cli/TestCommand.d.ts +9 -0
  48. package/dist/cli/TestCommand.d.ts.map +1 -1
  49. package/dist/cli/TestCommand.js +8 -3
  50. package/dist/cli/TestCommand.js.map +1 -1
  51. package/dist/cli/VerifyIntent.d.ts +28 -0
  52. package/dist/cli/VerifyIntent.d.ts.map +1 -0
  53. package/dist/cli/VerifyIntent.js +136 -0
  54. package/dist/cli/VerifyIntent.js.map +1 -0
  55. package/dist/egress/TransparentDial.d.ts +17 -0
  56. package/dist/egress/TransparentDial.d.ts.map +1 -0
  57. package/dist/egress/TransparentDial.js +32 -0
  58. package/dist/egress/TransparentDial.js.map +1 -0
  59. package/dist/gateway/Activation.d.ts +10 -3
  60. package/dist/gateway/Activation.d.ts.map +1 -1
  61. package/dist/gateway/Activation.js +17 -2
  62. package/dist/gateway/Activation.js.map +1 -1
  63. package/dist/gateway/ForwardHandler.d.ts.map +1 -1
  64. package/dist/gateway/ForwardHandler.js +8 -0
  65. package/dist/gateway/ForwardHandler.js.map +1 -1
  66. package/dist/gateway/Gateway.d.ts +16 -0
  67. package/dist/gateway/Gateway.d.ts.map +1 -1
  68. package/dist/gateway/Gateway.js +33 -4
  69. package/dist/gateway/Gateway.js.map +1 -1
  70. package/dist/gateway/GatewayConfig.d.ts +7 -0
  71. package/dist/gateway/GatewayConfig.d.ts.map +1 -1
  72. package/dist/gateway/GatewayConfig.js +12 -7
  73. package/dist/gateway/GatewayConfig.js.map +1 -1
  74. package/dist/gateway/GatewayReport.d.ts +2 -1
  75. package/dist/gateway/GatewayReport.d.ts.map +1 -1
  76. package/dist/gateway/GatewayReport.js +3 -0
  77. package/dist/gateway/GatewayReport.js.map +1 -1
  78. package/dist/gateway/InstallSurface.d.ts +26 -0
  79. package/dist/gateway/InstallSurface.d.ts.map +1 -0
  80. package/dist/gateway/InstallSurface.js +53 -0
  81. package/dist/gateway/InstallSurface.js.map +1 -0
  82. package/dist/gateway/ShadowLedger.d.ts +55 -0
  83. package/dist/gateway/ShadowLedger.d.ts.map +1 -0
  84. package/dist/gateway/ShadowLedger.js +82 -0
  85. package/dist/gateway/ShadowLedger.js.map +1 -0
  86. package/dist/handlers/ForwardRequestHandler.d.ts.map +1 -1
  87. package/dist/handlers/ForwardRequestHandler.js +7 -0
  88. package/dist/handlers/ForwardRequestHandler.js.map +1 -1
  89. package/dist/http/InterceptServer.d.ts +94 -0
  90. package/dist/http/InterceptServer.d.ts.map +1 -0
  91. package/dist/http/InterceptServer.js +252 -0
  92. package/dist/http/InterceptServer.js.map +1 -0
  93. package/dist/incident/SecurityEvents.d.ts +10 -0
  94. package/dist/incident/SecurityEvents.d.ts.map +1 -1
  95. package/dist/incident/SecurityEvents.js +9 -0
  96. package/dist/incident/SecurityEvents.js.map +1 -1
  97. package/dist/intercept/ClientHello.d.ts +37 -0
  98. package/dist/intercept/ClientHello.d.ts.map +1 -0
  99. package/dist/intercept/ClientHello.js +212 -0
  100. package/dist/intercept/ClientHello.js.map +1 -0
  101. package/dist/intercept/Destination.d.ts +35 -0
  102. package/dist/intercept/Destination.d.ts.map +1 -0
  103. package/dist/intercept/Destination.js +62 -0
  104. package/dist/intercept/Destination.js.map +1 -0
  105. package/dist/intercept/InterceptLedger.d.ts +67 -0
  106. package/dist/intercept/InterceptLedger.d.ts.map +1 -0
  107. package/dist/intercept/InterceptLedger.js +80 -0
  108. package/dist/intercept/InterceptLedger.js.map +1 -0
  109. package/dist/intercept/RequestHead.d.ts +48 -0
  110. package/dist/intercept/RequestHead.d.ts.map +1 -0
  111. package/dist/intercept/RequestHead.js +151 -0
  112. package/dist/intercept/RequestHead.js.map +1 -0
  113. package/dist/service/TrustedExecutorService.d.ts.map +1 -1
  114. package/dist/service/TrustedExecutorService.js +18 -2
  115. package/dist/service/TrustedExecutorService.js.map +1 -1
  116. package/dist/verify/EffectReceipt.d.ts +78 -0
  117. package/dist/verify/EffectReceipt.d.ts.map +1 -0
  118. package/dist/verify/EffectReceipt.js +98 -0
  119. package/dist/verify/EffectReceipt.js.map +1 -0
  120. package/dist/verify/VerifyIntentVector.d.ts +25 -0
  121. package/dist/verify/VerifyIntentVector.d.ts.map +1 -0
  122. package/dist/verify/VerifyIntentVector.js +188 -0
  123. package/dist/verify/VerifyIntentVector.js.map +1 -0
  124. package/dist/verify/VerifyingProvider.d.ts +112 -0
  125. package/dist/verify/VerifyingProvider.d.ts.map +1 -0
  126. package/dist/verify/VerifyingProvider.js +266 -0
  127. package/dist/verify/VerifyingProvider.js.map +1 -0
  128. package/package.json +2 -2
@@ -0,0 +1,98 @@
1
+ import { createPrivateKey, sign } from "node:crypto";
2
+ import { jcsCanonical } from "../adapters/JcsDigest.js";
3
+ /**
4
+ * The effect receipt: the provider's half of the evidence (the Verifying
5
+ * Provider Profile, VP-3).
6
+ *
7
+ * The attestation let this provider refuse what the authority never claimed.
8
+ * The receipt closes the other direction: after effecting, or refusing, the
9
+ * claimed request, the provider signs a compact JWS under its own key naming
10
+ * the grant it acted under, the claim it answered and what it did, and
11
+ * returns it in `x-agent-safe-effect-receipt`. The executor forwards it
12
+ * unread at finalization; the authority verifies it against the public key
13
+ * the organisation registered for this provider and records it with the
14
+ * commit evidence, so the dossier carries the provider's signature over the
15
+ * effect and not only the executor's report of it.
16
+ *
17
+ * Every field the receipt binds comes from the attestation the provider has
18
+ * already verified, which is the point: `sub` is the grant, `decision_id`
19
+ * and `dossier_id` are the decision's, and `claim_token_digest` is copied
20
+ * from the attestation of this very claim, which is how the authority ties
21
+ * the receipt to the claim being finalized without the claim token ever
22
+ * reaching the provider. The header and the payload are serialised in RFC
23
+ * 8785 canonical form, so every implementation of this profile signs the
24
+ * same bytes for the same receipt and the conformance vectors can say so.
25
+ */
26
+ export const EFFECT_RECEIPT_TYPE = "decionis-effect-receipt+jwt";
27
+ /** The response header the receipt travels in. */
28
+ export const EFFECT_RECEIPT_HEADER = "x-agent-safe-effect-receipt";
29
+ const SHA256 = /^sha256:[0-9a-f]{64}$/;
30
+ const STATUSES = ["EFFECTED", "REFUSED", "INDETERMINATE"];
31
+ export class EffectReceiptError extends Error {
32
+ code;
33
+ constructor(code) {
34
+ super(code);
35
+ this.code = code;
36
+ this.name = "EffectReceiptError";
37
+ }
38
+ }
39
+ /** The payload of the receipt, before it is signed; what the authority reads. */
40
+ export function effectReceiptClaims(input) {
41
+ if (!STATUSES.includes(input.effect.status))
42
+ throw new EffectReceiptError("EFFECT_STATUS_UNKNOWN");
43
+ if (input.effect.digest !== undefined && !SHA256.test(input.effect.digest)) {
44
+ throw new EffectReceiptError("EFFECT_DIGEST_MALFORMED");
45
+ }
46
+ if (Number.isNaN(Date.parse(input.effect.effected_at))) {
47
+ throw new EffectReceiptError("EFFECTED_AT_MALFORMED");
48
+ }
49
+ if (!Number.isInteger(input.issuedAt) || input.issuedAt < 0) {
50
+ throw new EffectReceiptError("ISSUED_AT_MALFORMED");
51
+ }
52
+ for (const [name, value] of [
53
+ ["KID", input.kid],
54
+ ["ISSUER", input.issuer],
55
+ ["AUDIENCE", input.audience],
56
+ ["JTI", input.jti],
57
+ ]) {
58
+ if (value.length === 0)
59
+ throw new EffectReceiptError(`${name}_EMPTY`);
60
+ }
61
+ return {
62
+ iss: input.issuer,
63
+ aud: input.audience,
64
+ sub: input.attestation.sub,
65
+ decision_id: input.attestation.decision_id,
66
+ dossier_id: input.attestation.dossier_id,
67
+ claim_token_digest: input.attestation.claim_token_digest,
68
+ attestation_jti: input.attestation.jti,
69
+ intent_hash: input.attestation.binding.intent_hash,
70
+ ...(input.idempotencyKey === undefined ? {} : { idempotency_key: input.idempotencyKey }),
71
+ effect: {
72
+ status: input.effect.status,
73
+ ...(input.effect.reference === undefined ? {} : { reference: input.effect.reference }),
74
+ ...(input.effect.digest === undefined ? {} : { digest: input.effect.digest }),
75
+ effected_at: input.effect.effected_at,
76
+ },
77
+ iat: input.issuedAt,
78
+ jti: input.jti,
79
+ };
80
+ }
81
+ /** The `header.payload` the signature covers: both segments RFC 8785 canonical, base64url. */
82
+ export function effectReceiptSigningInput(input) {
83
+ const header = { alg: "EdDSA", kid: input.kid, typ: EFFECT_RECEIPT_TYPE };
84
+ return `${base64url(jcsCanonical(header))}.${base64url(jcsCanonical(effectReceiptClaims(input)))}`;
85
+ }
86
+ /** The receipt: a compact EdDSA JWS the provider returns in `x-agent-safe-effect-receipt`. */
87
+ export function signEffectReceipt(input) {
88
+ const signingInput = effectReceiptSigningInput(input);
89
+ const key = typeof input.key === "string" ? createPrivateKey(input.key) : input.key;
90
+ if (key.asymmetricKeyType !== "ed25519")
91
+ throw new EffectReceiptError("KEY_NOT_ED25519");
92
+ const signature = sign(null, Buffer.from(signingInput), key);
93
+ return `${signingInput}.${signature.toString("base64url")}`;
94
+ }
95
+ function base64url(text) {
96
+ return Buffer.from(text).toString("base64url");
97
+ }
98
+ //# sourceMappingURL=EffectReceipt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EffectReceipt.js","sourceRoot":"","sources":["../../src/verify/EffectReceipt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAkB,MAAM,aAAa,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,6BAA6B,CAAC;AACjE,kDAAkD;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T_UNRECOGNISED" | "BINDING_INVALID" | "CANONICAL_MISMATCH" | "HASH_MISMATCH" | "MUTATION_INVALID" | "MUTATION_CANONICAL_MISMATCH" | "MUTATION_HASH_MISMATCH" | "MUTATION_NOT_DISTINCT" | "MUTATION_PATH_UNCHANGED";
3
+ export interface IntentVectorFinding {
4
+ readonly code: IntentVectorFindingCode;
5
+ /** The mutation's path, or the schema path that failed; null for the base. */
6
+ readonly path: string | null;
7
+ readonly expected: string | null;
8
+ readonly computed: string | null;
9
+ }
10
+ export interface IntentVectorReport {
11
+ readonly protocol: typeof INTENT_PROTOCOL;
12
+ /** `binding` for a whole intent binding, `canonical` for a bytes-and-digest case. */
13
+ readonly kind: "binding" | "canonical" | "unrecognised";
14
+ readonly ok: boolean;
15
+ /** Whether the document stated a hash to reproduce, or only asked for one. */
16
+ readonly pinned: boolean;
17
+ readonly canonical_json: string | null;
18
+ readonly intent_hash: string | null;
19
+ /** Mutations the document carried, and how many distinct hashes the whole vector came to. */
20
+ readonly mutations: number;
21
+ readonly hashes: number;
22
+ readonly findings: readonly IntentVectorFinding[];
23
+ }
24
+ export declare function verifyIntentVector(document: unknown): IntentVectorReport;
25
+ //# sourceMappingURL=VerifyIntentVector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VerifyIntentVector.d.ts","sourceRoot":"","sources":["../../src/verify/VerifyIntentVector.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,eAAe,wBAAwB,CAAC;AAErD,MAAM,MAAM,uBAAuB,GAC/B,uBAAuB,GACvB,iBAAiB,GACjB,oBAAoB,GACpB,eAAe,GACf,kBAAkB,GAClB,6BAA6B,GAC7B,wBAAwB,GACxB,uBAAuB,GACvB,yBAAyB,CAAC;AAE9B,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,OAAO,eAAe,CAAC;IAC1C,qFAAqF;IACrF,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,cAAc,CAAC;IACxD,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,6FAA6F;IAC7F,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACnD;AAsDD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,GAAG,kBAAkB,CA0HxE"}
@@ -0,0 +1,188 @@
1
+ /**
2
+ * The offline half of Agent-Safe Intent conformance: given a vector from the
3
+ * corpus under `conformance/`, or a binding another implementation produced,
4
+ * recompute the canonical bytes and the hash with this runtime's own
5
+ * canonicalizer and say whether they agree. Two kinds of vector exist. A
6
+ * `binding` vector holds a whole `agent-safe.intent/1` binding, which must
7
+ * also parse under the strict schema, and may carry `mutations`: single-field
8
+ * changes that must each hash differently from the base and from one
9
+ * another, which is the Compromised Principal requirement. A `canonical`
10
+ * vector holds any JSON object and pins only the bytes and the digest, which
11
+ * is how the Unicode, number and key-order cases are stated. A document with
12
+ * no expected hash is a binding to describe: its canonical bytes and hash are
13
+ * computed and returned, so an implementer can compare them with theirs.
14
+ */
15
+ import { createHash } from "node:crypto";
16
+ import { AuthorityIntentBindingSchema, CanonicalIntentHasher, } from "@decionis/agent-safe-pipeline";
17
+ export const INTENT_PROTOCOL = "agent-safe.intent/1";
18
+ const hasher = new CanonicalIntentHasher();
19
+ function isObject(value) {
20
+ return value !== null && typeof value === "object" && !Array.isArray(value);
21
+ }
22
+ function digest(canonical) {
23
+ return `sha256:${createHash("sha256").update(canonical, "utf8").digest("hex")}`;
24
+ }
25
+ /** The value at a dotted path, or undefined; arrays are not addressed. */
26
+ function valueAt(value, path) {
27
+ let current = value;
28
+ for (const key of path.split(".")) {
29
+ if (!isObject(current))
30
+ return undefined;
31
+ current = current[key];
32
+ }
33
+ return current;
34
+ }
35
+ /** Canonical bytes and hash of a bounded JSON object; null when it is not one. */
36
+ function canonicalize(value) {
37
+ if (!isObject(value))
38
+ return null;
39
+ try {
40
+ hasher.assertInputBounded(value);
41
+ const canonical = CanonicalIntentHasher.stringify(value);
42
+ return { canonical, hash: digest(canonical) };
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ function schemaFinding(binding, code, path) {
49
+ const result = AuthorityIntentBindingSchema.safeParse(binding);
50
+ if (result.success)
51
+ return null;
52
+ const issue = result.error.issues[0];
53
+ const segments = issue === undefined ? [] : issue.path.map(String);
54
+ // A key the schema does not name is reported by that name, not by its parent.
55
+ if (issue?.code === "unrecognized_keys")
56
+ segments.push(...issue.keys);
57
+ const at = segments.join(".");
58
+ return {
59
+ code,
60
+ path: path === null ? (at === "" ? null : at) : `${path}${at === "" ? "" : ` (${at})`}`,
61
+ expected: issue?.code ?? null,
62
+ computed: null,
63
+ };
64
+ }
65
+ export function verifyIntentVector(document) {
66
+ const unrecognised = {
67
+ protocol: INTENT_PROTOCOL,
68
+ kind: "unrecognised",
69
+ ok: false,
70
+ pinned: false,
71
+ canonical_json: null,
72
+ intent_hash: null,
73
+ mutations: 0,
74
+ hashes: 0,
75
+ findings: [{ code: "DOCUMENT_UNRECOGNISED", path: null, expected: null, computed: null }],
76
+ };
77
+ if (!isObject(document))
78
+ return unrecognised;
79
+ // A vector wraps its binding; a bare binding is the document itself.
80
+ const wrapped = isObject(document["binding"]);
81
+ const binding = wrapped ? document["binding"] : document;
82
+ if (!isObject(binding))
83
+ return unrecognised;
84
+ const kind = binding["protocol_version"] === INTENT_PROTOCOL ? "binding" : "canonical";
85
+ if (!wrapped && kind !== "binding")
86
+ return unrecognised;
87
+ const findings = [];
88
+ const base = canonicalize(binding);
89
+ if (base === null) {
90
+ findings.push({
91
+ code: "BINDING_INVALID",
92
+ path: null,
93
+ expected: "bounded JSON object",
94
+ computed: null,
95
+ });
96
+ return { ...unrecognised, kind, findings };
97
+ }
98
+ if (kind === "binding") {
99
+ const finding = schemaFinding(binding, "BINDING_INVALID", null);
100
+ if (finding !== null)
101
+ findings.push(finding);
102
+ }
103
+ const expectedCanonical = wrapped ? document["canonical_json"] : undefined;
104
+ const expectedHash = wrapped ? document["intent_hash"] : undefined;
105
+ const pinned = typeof expectedHash === "string";
106
+ if (typeof expectedCanonical === "string" && expectedCanonical !== base.canonical) {
107
+ findings.push({
108
+ code: "CANONICAL_MISMATCH",
109
+ path: null,
110
+ expected: expectedCanonical,
111
+ computed: base.canonical,
112
+ });
113
+ }
114
+ if (pinned && expectedHash !== base.hash) {
115
+ findings.push({
116
+ code: "HASH_MISMATCH",
117
+ path: null,
118
+ expected: expectedHash,
119
+ computed: base.hash,
120
+ });
121
+ }
122
+ const hashes = new Set([base.hash]);
123
+ const mutations = wrapped && Array.isArray(document["mutations"]) ? document["mutations"] : [];
124
+ for (const [index, mutation] of mutations.entries()) {
125
+ const label = isObject(mutation) && typeof mutation["path"] === "string"
126
+ ? mutation["path"]
127
+ : `#${String(index)}`;
128
+ const mutated = isObject(mutation) ? canonicalize(mutation["binding"]) : null;
129
+ if (!isObject(mutation) || mutated === null || typeof mutation["intent_hash"] !== "string") {
130
+ findings.push({ code: "MUTATION_INVALID", path: label, expected: null, computed: null });
131
+ continue;
132
+ }
133
+ if (kind === "binding") {
134
+ const finding = schemaFinding(mutation["binding"], "MUTATION_INVALID", label);
135
+ if (finding !== null)
136
+ findings.push(finding);
137
+ }
138
+ if (typeof mutation["canonical_json"] === "string" &&
139
+ mutation["canonical_json"] !== mutated.canonical) {
140
+ findings.push({
141
+ code: "MUTATION_CANONICAL_MISMATCH",
142
+ path: label,
143
+ expected: mutation["canonical_json"],
144
+ computed: mutated.canonical,
145
+ });
146
+ }
147
+ if (mutation["intent_hash"] !== mutated.hash) {
148
+ findings.push({
149
+ code: "MUTATION_HASH_MISMATCH",
150
+ path: label,
151
+ expected: mutation["intent_hash"],
152
+ computed: mutated.hash,
153
+ });
154
+ }
155
+ if (hashes.has(mutated.hash)) {
156
+ findings.push({
157
+ code: "MUTATION_NOT_DISTINCT",
158
+ path: label,
159
+ expected: null,
160
+ computed: mutated.hash,
161
+ });
162
+ }
163
+ hashes.add(mutated.hash);
164
+ // The mutation must be what it says it is: the named field differs from the base.
165
+ if (typeof mutation["path"] === "string" &&
166
+ JSON.stringify(valueAt(mutation["binding"], mutation["path"])) ===
167
+ JSON.stringify(valueAt(binding, mutation["path"]))) {
168
+ findings.push({
169
+ code: "MUTATION_PATH_UNCHANGED",
170
+ path: label,
171
+ expected: null,
172
+ computed: null,
173
+ });
174
+ }
175
+ }
176
+ return {
177
+ protocol: INTENT_PROTOCOL,
178
+ kind,
179
+ ok: findings.length === 0,
180
+ pinned,
181
+ canonical_json: base.canonical,
182
+ intent_hash: base.hash,
183
+ mutations: mutations.length,
184
+ hashes: hashes.size,
185
+ findings,
186
+ };
187
+ }
188
+ //# sourceMappingURL=VerifyIntentVector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VerifyIntentVector.js","sourceRoot":"","sources":["../../src/verify/VerifyIntentVector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,4BAA4B,EAC5B,qBAAqB,GAEtB,MAAM,+BAA+B,CAAC;AAEvC,MAAM,CAAC,MAAM,eAAe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* a provider runs it: the reference for VP-1 and VP-2. Everything the profile
5
+ * numbers is a step here, in the profile's order, and the first failing step
6
+ * names the refusal. The signature half is `SignedRequestCredential.verify`,
7
+ * unchanged; this adds what a provider does around it: the freshness window,
8
+ * the key registry, the attestation, the canonical body digest, and the
9
+ * single presentation of a grant. It is held to the same mutation gate,
10
+ * because a mutant that accepts what it should refuse is a provider that
11
+ * effects what the authority never claimed.
12
+ */
13
+ export type ProviderRefusalCode = "SIGNATURE_INVALID_OR_INCOMPLETE" | "ATTESTATION_INVALID" | "ATTESTATION_DOES_NOT_DESCRIBE_THIS_REQUEST" | "GRANT_REPLAYED";
14
+ export declare const ATTESTATION_TYPE = "decionis-claim-attestation+jwt";
15
+ export declare const JCS_PROFILE = "RFC8785/JCS";
16
+ /** A key the provider issued to, or registered for, the executor, by the `keyid` a signature names. */
17
+ export type ExecutorKey = {
18
+ readonly keyId: string;
19
+ readonly algorithm: "ed25519";
20
+ readonly publicKeyPem: string;
21
+ } | {
22
+ readonly keyId: string;
23
+ readonly algorithm: "hmac-sha256";
24
+ readonly secret: Uint8Array;
25
+ };
26
+ /**
27
+ * The claims of an attestation, as far as the provider reads them; the
28
+ * authority's schema has more. The dossier, the claim-token digest and the
29
+ * attestation's own id are what a receipt (VP-3) is built from, so a
30
+ * provider that effects has them in hand.
31
+ */
32
+ export interface ClaimAttestationClaims {
33
+ readonly iss: string;
34
+ readonly sub: string;
35
+ readonly decision_id: string;
36
+ readonly dossier_id: string;
37
+ readonly binding: {
38
+ readonly intent_hash: string;
39
+ readonly execution_payload_digest: string;
40
+ readonly execution_payload_canonicalization_profile: string;
41
+ };
42
+ readonly claim_token_digest: string;
43
+ readonly jti: string;
44
+ readonly exp: number;
45
+ }
46
+ /**
47
+ * Where a provider keeps the grants it accepted, until their attestation
48
+ * expires. `record` answers true when the grant was not there and is now,
49
+ * false when it was: the second presentation. Shared by every instance that
50
+ * can effect; the profile's step 8.
51
+ */
52
+ export interface ReplayStore {
53
+ record(grantId: string, expiresAtMs: number): boolean;
54
+ }
55
+ export interface VerifyingProviderOptions {
56
+ /** Whether this endpoint effects anything. An effecting provider requires all eight components. */
57
+ readonly effects: boolean;
58
+ /** Unique by `keyId`; the first match is the key. */
59
+ readonly executorKeys: readonly ExecutorKey[];
60
+ /** The authority's execution-grant JWKS, as its well-known path serves it. */
61
+ readonly authorityJwks: {
62
+ readonly keys: readonly Readonly<Record<string, unknown>>[];
63
+ };
64
+ /** The `iss` the provider trusts: `https://decionis.com` for Decionis. */
65
+ readonly authorityIssuer: string;
66
+ /** How far `created` may lie from `now`, each way. */
67
+ readonly clockWindowSeconds: number;
68
+ readonly replay: ReplayStore;
69
+ readonly now?: () => number;
70
+ }
71
+ export interface ReceivedRequest {
72
+ readonly method: string;
73
+ /** The request path, without its query. */
74
+ readonly path: string;
75
+ readonly body: string | null;
76
+ /** Header names in lower case. A covered header received more than once is a refusal; do not collapse it here. */
77
+ readonly headers: Readonly<Record<string, string>>;
78
+ }
79
+ export type ProviderVerdict = {
80
+ readonly accepted: true;
81
+ readonly reasonCode: null;
82
+ readonly attestation: ClaimAttestationClaims | null;
83
+ } | {
84
+ readonly accepted: false;
85
+ readonly reasonCode: ProviderRefusalCode;
86
+ readonly attestation: null;
87
+ };
88
+ /** The body as I-JSON, or null: not JSON, or a name repeated within one object. Lone surrogates are the canonicaliser's to refuse. */
89
+ export declare function parseIJson(body: string): JsonValue | null;
90
+ /**
91
+ * The whole procedure for one received request. An accepted verdict carries
92
+ * the attestation's claims for the provider's own record, or null for a read
93
+ * a non-effecting provider verified at VP-1 alone; a refusal carries the code
94
+ * the response body names.
95
+ */
96
+ export declare function verifyProviderRequest(received: ReceivedRequest, options: VerifyingProviderOptions): ProviderVerdict;
97
+ /** The refusal body the profile names; the status is the provider's, 409 in the references. */
98
+ export declare function refusalBody(reasonCode: ProviderRefusalCode): string;
99
+ /**
100
+ * A replay store for one process: enough for a single instance, and for the
101
+ * vectors. A provider with more than one instance that can effect shares one
102
+ * instead, keyed the same way. Expired grants are forgotten on the next
103
+ * record, which is why the store needs no life beyond the lease.
104
+ */
105
+ export declare class MemoryReplayStore implements ReplayStore {
106
+ private readonly clock;
107
+ private readonly seen;
108
+ constructor(clock?: () => number);
109
+ record(grantId: string, expiresAtMs: number): boolean;
110
+ get size(): number;
111
+ }
112
+ //# sourceMappingURL=VerifyingProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VerifyingProvider.d.ts","sourceRoot":"","sources":["../../src/verify/VerifyingProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAS/D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mBAAmB,GAC3B,iCAAiC,GACjC,qBAAqB,GACrB,4CAA4C,GAC5C,gBAAgB,CAAC;AAErB,eAAO,MAAM,gBAAgB,mCAAmC,CAAC;AACjE,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,uGAAuG;AACvG,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GACxF;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAE/F;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE;QAChB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,wBAAw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