@kya-os/mcp-i-runtime 1.3.1 → 1.3.3

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 (122) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/auth/handshake.d.ts +23 -43
  3. package/dist/auth/handshake.d.ts.map +1 -1
  4. package/dist/auth/handshake.js +51 -82
  5. package/dist/auth/handshake.js.map +1 -1
  6. package/dist/auth/index.d.ts +1 -1
  7. package/dist/auth/index.d.ts.map +1 -1
  8. package/dist/auth/index.js.map +1 -1
  9. package/dist/auth/resume-token.d.ts +52 -0
  10. package/dist/auth/resume-token.d.ts.map +1 -0
  11. package/dist/auth/resume-token.js +89 -0
  12. package/dist/auth/resume-token.js.map +1 -0
  13. package/dist/auth/types.d.ts +15 -0
  14. package/dist/auth/types.d.ts.map +1 -1
  15. package/dist/index.d.ts +7 -3
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +25 -3
  18. package/dist/index.js.map +1 -1
  19. package/dist/proof/companion.d.ts +25 -0
  20. package/dist/proof/companion.d.ts.map +1 -0
  21. package/dist/proof/companion.js +14 -0
  22. package/dist/proof/companion.js.map +1 -0
  23. package/dist/proof/generator.d.ts +22 -9
  24. package/dist/proof/generator.d.ts.map +1 -1
  25. package/dist/proof/generator.js +20 -27
  26. package/dist/proof/generator.js.map +1 -1
  27. package/dist/proof/index.d.ts +2 -1
  28. package/dist/proof/index.d.ts.map +1 -1
  29. package/dist/proof/index.js +3 -1
  30. package/dist/proof/index.js.map +1 -1
  31. package/dist/runtime/audit.d.ts.map +1 -1
  32. package/dist/runtime/audit.js +78 -18
  33. package/dist/runtime/audit.js.map +1 -1
  34. package/dist/runtime/base.d.ts +6 -1
  35. package/dist/runtime/base.d.ts.map +1 -1
  36. package/dist/runtime/base.js +65 -17
  37. package/dist/runtime/base.js.map +1 -1
  38. package/dist/runtime/dif-core.d.ts +8 -0
  39. package/dist/runtime/dif-core.d.ts.map +1 -1
  40. package/dist/runtime/dif-core.js +10 -0
  41. package/dist/runtime/dif-core.js.map +1 -1
  42. package/dist/services/access-control.service.d.ts.map +1 -1
  43. package/dist/services/access-control.service.js +12 -5
  44. package/dist/services/access-control.service.js.map +1 -1
  45. package/dist/services/claims-first-guard.d.ts +33 -0
  46. package/dist/services/claims-first-guard.d.ts.map +1 -0
  47. package/dist/services/claims-first-guard.js +77 -0
  48. package/dist/services/claims-first-guard.js.map +1 -0
  49. package/dist/services/holder-keys.d.ts +95 -0
  50. package/dist/services/holder-keys.d.ts.map +1 -0
  51. package/dist/services/holder-keys.js +281 -0
  52. package/dist/services/holder-keys.js.map +1 -0
  53. package/dist/services/holder-read-slots.d.ts +42 -0
  54. package/dist/services/holder-read-slots.d.ts.map +1 -0
  55. package/dist/services/holder-read-slots.js +82 -0
  56. package/dist/services/holder-read-slots.js.map +1 -0
  57. package/dist/services/proof-verifier.d.ts +13 -35
  58. package/dist/services/proof-verifier.d.ts.map +1 -1
  59. package/dist/services/proof-verifier.js +16 -74
  60. package/dist/services/proof-verifier.js.map +1 -1
  61. package/dist/services/request-holder.d.ts +78 -0
  62. package/dist/services/request-holder.d.ts.map +1 -0
  63. package/dist/services/request-holder.js +81 -0
  64. package/dist/services/request-holder.js.map +1 -0
  65. package/dist/services/tool-context-builder.d.ts.map +1 -1
  66. package/dist/services/tool-context-builder.js +16 -4
  67. package/dist/services/tool-context-builder.js.map +1 -1
  68. package/dist/services/tool-protection.service.d.ts +7 -0
  69. package/dist/services/tool-protection.service.d.ts.map +1 -1
  70. package/dist/services/tool-protection.service.js +34 -15
  71. package/dist/services/tool-protection.service.js.map +1 -1
  72. package/dist/types/tool-protection.d.ts +94 -0
  73. package/dist/types/tool-protection.d.ts.map +1 -1
  74. package/dist/types/tool-protection.js +113 -1
  75. package/dist/types/tool-protection.js.map +1 -1
  76. package/eslint.config.js +20 -0
  77. package/package.json +8 -2
  78. package/src/__tests__/runtime/amount-limit-enforcement.test.ts +269 -0
  79. package/src/__tests__/runtime/amount-limit-result.test.ts +61 -0
  80. package/src/__tests__/runtime/audit-contracts-compat.test.ts +20 -5
  81. package/src/__tests__/runtime/audit.test.ts +363 -53
  82. package/src/__tests__/runtime/process-tool-call-security.test.ts +97 -13
  83. package/src/__tests__/runtime/provider-selection.test.ts +4 -6
  84. package/src/__tests__/runtime/route-interception.test.ts +215 -214
  85. package/src/__tests__/runtime/tool-protection-enforcement.test.ts +89 -6
  86. package/src/__tests__/services/tool-protection-amount.test.ts +107 -0
  87. package/src/__tests__/services/tool-protection-failsafe.test.ts +71 -4
  88. package/src/__tests__/utils/tool-protection-runtime.ts +3 -0
  89. package/src/auth/__tests__/verify-or-hints-presented.test.ts +155 -0
  90. package/src/auth/handshake.ts +80 -125
  91. package/src/auth/index.ts +1 -0
  92. package/src/auth/resume-token.ts +134 -0
  93. package/src/auth/types.ts +20 -2
  94. package/src/index.ts +40 -1
  95. package/src/proof/__tests__/proof-generator.test.ts +80 -13
  96. package/src/proof/companion.ts +35 -0
  97. package/src/proof/generator.ts +51 -33
  98. package/src/proof/index.ts +3 -0
  99. package/src/runtime/__tests__/ext-apps-consent.test.ts +87 -2
  100. package/src/runtime/audit.ts +170 -65
  101. package/src/runtime/base.ts +95 -31
  102. package/src/runtime/dif-core.ts +16 -0
  103. package/src/services/__tests__/access-control.service.test.ts +44 -0
  104. package/src/services/__tests__/claims-first-guard.test.ts +93 -0
  105. package/src/services/__tests__/holder-fixtures.ts +135 -0
  106. package/src/services/__tests__/holder-keys.test.ts +257 -0
  107. package/src/services/__tests__/holder-read-slots.test.ts +117 -0
  108. package/src/services/__tests__/holder-reads.test.ts +284 -0
  109. package/src/services/__tests__/proof-verifier.test.ts +286 -195
  110. package/src/services/__tests__/request-holder.test.ts +210 -0
  111. package/src/services/__tests__/tool-context-builder-authtype.test.ts +79 -0
  112. package/src/services/__tests__/tool-context-builder.test.ts +4 -7
  113. package/src/services/__tests__/tool-protection-served-revision.test.ts +102 -0
  114. package/src/services/access-control.service.ts +11 -5
  115. package/src/services/claims-first-guard.ts +89 -0
  116. package/src/services/holder-keys.ts +379 -0
  117. package/src/services/holder-read-slots.ts +85 -0
  118. package/src/services/proof-verifier.ts +18 -79
  119. package/src/services/request-holder.ts +146 -0
  120. package/src/services/tool-context-builder.ts +19 -4
  121. package/src/services/tool-protection.service.ts +62 -19
  122. package/src/types/tool-protection.ts +161 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holder-keys.js","sourceRoot":"","sources":["../../src/services/holder-keys.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;;;AA+OH,4CAoFC;AAMD,8CAWC;AA9UD,wCAAoC;AACpC,kDAA6E;AAC7E,2DAAsE;AAyCtE,0EAA0E;AAC1E,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,0EAA0E;AAC1E,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,iFAAiF;AACjF,MAAM,mBAAmB,GAAG,EAAE,GAAG,MAAM,CAAC;AACxC,4EAA4E;AAC5E,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC;;;;GAIG;AACU,QAAA,iBAAiB,GAAG;IAC/B,KAAK,EAAE,EAAE;IACT,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,GAAG;CACJ,CAAC;AAEX,yDAAyD;AACzD,MAAM,aAAa;IAGY;IAFZ,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEnD,YAA6B,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAE9C,GAAG,CAAC,GAAW;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QACtC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;YAAE,OAAO,IAAI,CAAC;QACpC,IAAI,CAAC,KAAK,CAAC,MA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CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC;IACvE,OAAO;QACL,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;QAChE,cAAc,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC;KACzE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The slots holder documents are read in.
3
+ *
4
+ * A request proof names its holder before anything verifies it, so a call
5
+ * can name any did:web holder and have its document read. The reads such
6
+ * calls drive are held to so many at once, in all and for one host; a read
7
+ * beyond that waits its turn, in the order it came, and a read beyond the
8
+ * line is refused. A burst of new holders is then read a few at a time, and
9
+ * no number of calls opens more connections than the slots.
10
+ *
11
+ * @module services/holder-read-slots
12
+ */
13
+ /** A read refused because the slots and the line behind them are full. */
14
+ export declare class HolderReadsBusyError extends Error {
15
+ constructor();
16
+ }
17
+ export interface ReadSlotLimits {
18
+ /** The most reads at once. */
19
+ total: number;
20
+ /** The most reads at once of one host. */
21
+ perHost: number;
22
+ /** The most reads waiting for a slot. */
23
+ waiting: number;
24
+ }
25
+ export declare class ReadSlots {
26
+ private readonly limits;
27
+ private reading;
28
+ private readonly readingOf;
29
+ private readonly line;
30
+ constructor(limits: ReadSlotLimits);
31
+ /**
32
+ * Run `read` of a document on `host` in a slot, waiting for one in line.
33
+ *
34
+ * @throws HolderReadsBusyError when the line is full; `read` did not run
35
+ */
36
+ run<T>(host: string, read: () => Promise<T>): Promise<T>;
37
+ private hasSlot;
38
+ private take;
39
+ /** Free `host`'s slot, and give one to the first read in line it suits. */
40
+ private release;
41
+ }
42
+ //# sourceMappingURL=holder-read-slots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holder-read-slots.d.ts","sourceRoot":"","sources":["../../src/services/holder-read-slots.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,0EAA0E;AAC1E,qBAAa,oBAAqB,SAAQ,KAAK;;CAK9C;AAED,MAAM,WAAW,cAAc;IAC7B,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,SAAS;IAKR,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA6B;IACvD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAkD;gBAE1C,MAAM,EAAE,cAAc;IAEnD;;;;OAIG;IACG,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAgB9D,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,IAAI;IAKZ,2EAA2E;IAC3E,OAAO,CAAC,OAAO;CAahB"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ /**
3
+ * The slots holder documents are read in.
4
+ *
5
+ * A request proof names its holder before anything verifies it, so a call
6
+ * can name any did:web holder and have its document read. The reads such
7
+ * calls drive are held to so many at once, in all and for one host; a read
8
+ * beyond that waits its turn, in the order it came, and a read beyond the
9
+ * line is refused. A burst of new holders is then read a few at a time, and
10
+ * no number of calls opens more connections than the slots.
11
+ *
12
+ * @module services/holder-read-slots
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ReadSlots = exports.HolderReadsBusyError = void 0;
16
+ /** A read refused because the slots and the line behind them are full. */
17
+ class HolderReadsBusyError extends Error {
18
+ constructor() {
19
+ super("Too many holder documents are being read");
20
+ this.name = "HolderReadsBusyError";
21
+ }
22
+ }
23
+ exports.HolderReadsBusyError = HolderReadsBusyError;
24
+ class ReadSlots {
25
+ limits;
26
+ reading = 0;
27
+ readingOf = new Map();
28
+ line = [];
29
+ constructor(limits) {
30
+ this.limits = limits;
31
+ }
32
+ /**
33
+ * Run `read` of a document on `host` in a slot, waiting for one in line.
34
+ *
35
+ * @throws HolderReadsBusyError when the line is full; `read` did not run
36
+ */
37
+ async run(host, read) {
38
+ if (this.hasSlot(host)) {
39
+ this.take(host);
40
+ }
41
+ else if (this.line.length >= this.limits.waiting) {
42
+ throw new HolderReadsBusyError();
43
+ }
44
+ else {
45
+ // Its slot is taken for it when its turn comes (./release).
46
+ await new Promise((start) => this.line.push({ host, start }));
47
+ }
48
+ try {
49
+ return await read();
50
+ }
51
+ finally {
52
+ this.release(host);
53
+ }
54
+ }
55
+ hasSlot(host) {
56
+ return (this.reading < this.limits.total &&
57
+ (this.readingOf.get(host) ?? 0) < this.limits.perHost);
58
+ }
59
+ take(host) {
60
+ this.reading += 1;
61
+ this.readingOf.set(host, (this.readingOf.get(host) ?? 0) + 1);
62
+ }
63
+ /** Free `host`'s slot, and give one to the first read in line it suits. */
64
+ release(host) {
65
+ this.reading -= 1;
66
+ const left = (this.readingOf.get(host) ?? 1) - 1;
67
+ if (left > 0)
68
+ this.readingOf.set(host, left);
69
+ else
70
+ this.readingOf.delete(host);
71
+ const next = this.line.findIndex((waiting) => this.hasSlot(waiting.host));
72
+ if (next < 0)
73
+ return;
74
+ const [waiting] = this.line.splice(next, 1);
75
+ if (!waiting)
76
+ return;
77
+ this.take(waiting.host);
78
+ waiting.start();
79
+ }
80
+ }
81
+ exports.ReadSlots = ReadSlots;
82
+ //# sourceMappingURL=holder-read-slots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holder-read-slots.js","sourceRoot":"","sources":["../../src/services/holder-read-slots.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,0EAA0E;AAC1E,MAAa,oBAAqB,SAAQ,K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;QACvB,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAClB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,2EAA2E;IACnE,OAAO,CAAC,IAAY;QAC1B,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAClB,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACjD,IAAI,IAAI,GAAG,CAAC;YAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;;YACxC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEjC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1E,IAAI,IAAI,GAAG,CAAC;YAAE,OAAO;QACrB,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;CACF;AAtDD,8BAsDC"}
@@ -14,19 +14,11 @@
14
14
  * `runtime/base.ts` and the runtime subclasses that inject a `ProofVerifier` —
15
15
  * are unchanged.
16
16
  *
17
- * `verifyProof` calls DIF's `verifyProofDetached` (not DIF's `verifyProof`),
18
- * passing a canonical payload built by this façade's own
19
- * `buildCanonicalPayload` rather than letting DIF reconstruct it internally.
20
- * `@kya-os/mcp` is a separately-versioned, externally-published dependency,
21
- * so its own reconstruction does not know about fields this repo's signers
22
- * add to the payload (see `buildCanonicalPayload`'s doc comment) — supplying
23
- * the payload ourselves keeps the crypto/replay/skew pipeline delegated to
24
- * DIF while staying correct regardless of DIF's release cadence. One
25
- * consequence: the content-binding fail-closed check (DIF's `verifyProof`
26
- * third `expected` argument) is not reachable through `verifyProofDetached`,
27
- * but this façade never passed that argument through anyway. The one
28
- * pre-C2 default that differs (local timestamp skew defaulted to 300s vs
29
- * DIF's 120s) is preserved explicitly when composing the DIF verifier.
17
+ * `verifyProof` calls DIF's `verifyProof`, which rebuilds the signed payload
18
+ * from `proof.meta` with the same `buildProofJwsPayload` the signers use, so
19
+ * nothing in this repo reconstructs the payload itself. The one pre-C2
20
+ * default that differs (local timestamp skew defaulted to 300s vs DIF's
21
+ * 120s) is preserved explicitly when composing the DIF verifier.
30
22
  */
31
23
  import { type Ed25519JWK } from "./crypto.service.js";
32
24
  import { CryptoProvider } from "../providers/base.js";
@@ -66,17 +58,9 @@ export declare class ProofVerifier {
66
58
  * Verify a DetachedProof. Checks the JWS signature, nonce replay, and
67
59
  * timestamp skew via the DIF `ProofVerifier` pipeline.
68
60
  *
69
- * Deliberately calls the DIF verifier's `verifyProofDetached()` with a
70
- * canonical payload built by this class's own `buildCanonicalPayload()`,
71
- * rather than the DIF verifier's `verifyProof()` (which would reconstruct
72
- * the payload using ITS OWN internal builder). `@kya-os/mcp` is a
73
- * separately-versioned, externally-published dependency; its internal
74
- * builder does not know about the literal did/kid/audience/toolName/
75
- * outcome fields this repo's signers add to the payload, so proofs signed
76
- * here would fail `@kya-os/mcp`'s own reconstruction even though the
77
- * signature is genuinely valid. Supplying the payload ourselves keeps the
78
- * nonce-replay/timestamp-skew/signature pipeline delegated to DIF while
79
- * sidestepping its stale reconstruction.
61
+ * Calls the DIF verifier's `verifyProof()`, which rebuilds the signed
62
+ * payload from `proof.meta` (the shared `buildProofJwsPayload`, RFC 8785)
63
+ * and checks the signature over it.
80
64
  *
81
65
  * @param proof - The proof to verify
82
66
  * @param publicKeyJwk - Ed25519 public key in JWK format (from DID document)
@@ -102,19 +86,13 @@ export declare class ProofVerifier {
102
86
  */
103
87
  fetchPublicKeyFromDID(did: string, kid?: string): Promise<Ed25519JWK | null>;
104
88
  /**
105
- * Build canonical payload from proof meta
106
- *
107
- * CRITICAL: This must reconstruct the exact JWS payload structure that was originally signed.
108
- * The original JWS payload uses standard JWT claims (aud, sub, iss) plus custom proof claims,
109
- * NOT the proof.meta structure directly.
110
- *
111
- * Kept local (not delegated): callers invoke this synchronously, while the DIF
112
- * verifier is only reachable through the async seam. The reconstruction is
113
- * byte-identical to DIF's `buildCanonicalPayload`.
89
+ * The canonical (RFC 8785) JWS payload for `meta`, for detached-JWS
90
+ * consumers. Delegates to `@kya-os/mcp`'s `buildProofJwsPayload`; async
91
+ * because that module is reached through the ESM-bridge seam.
114
92
  *
115
93
  * @param meta - Proof metadata
116
- * @returns Canonical JSON string matching the original JWS payload structure
94
+ * @returns Canonical JSON string identical to the payload a signer signs
117
95
  */
118
- buildCanonicalPayload(meta: DetachedProof["meta"]): string;
96
+ buildCanonicalPayload(meta: DetachedProof["meta"]): Promise<string>;
119
97
  }
120
98
  //# sourceMappingURL=proof-verifier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"proof-verifier.d.ts","sourceRoot":"","sources":["../../src/services/proof-verifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAA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AAE,mBAAmB;IAKvC;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAqBtB;;;;;;;;;;;OAWG;IACG,WAAW,CACf,KAAK,EAAE,aAAa,EACpB,YAAY,EAAE,UAAU,GACvB,OAAO,CAAC,uBAAuB,CAAC;IAQnC;;;;;;;;OAQG;IACG,mBAAmB,CACvB,KAAK,EAAE,aAAa,EACpB,gBAAgB,EAAE,MAAM,GAAG,UAAU,EACrC,YAAY,EAAE,UAAU,GACvB,OAAO,CAAC,uBAAuB,CAAC;IASnC;;;;;;OAMG;IACG,qBAAqB,CACzB,GAAG,EAAE,MAAM,EACX,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAgG7B;;;;;;;OAOG;IACG,qBAAqB,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAM1E"}
@@ -15,19 +15,11 @@
15
15
  * `runtime/base.ts` and the runtime subclasses that inject a `ProofVerifier` —
16
16
  * are unchanged.
17
17
  *
18
- * `verifyProof` calls DIF's `verifyProofDetached` (not DIF's `verifyProof`),
19
- * passing a canonical payload built by this façade's own
20
- * `buildCanonicalPayload` rather than letting DIF reconstruct it internally.
21
- * `@kya-os/mcp` is a separately-versioned, externally-published dependency,
22
- * so its own reconstruction does not know about fields this repo's signers
23
- * add to the payload (see `buildCanonicalPayload`'s doc comment) — supplying
24
- * the payload ourselves keeps the crypto/replay/skew pipeline delegated to
25
- * DIF while staying correct regardless of DIF's release cadence. One
26
- * consequence: the content-binding fail-closed check (DIF's `verifyProof`
27
- * third `expected` argument) is not reachable through `verifyProofDetached`,
28
- * but this façade never passed that argument through anyway. The one
29
- * pre-C2 default that differs (local timestamp skew defaulted to 300s vs
30
- * DIF's 120s) is preserved explicitly when composing the DIF verifier.
18
+ * `verifyProof` calls DIF's `verifyProof`, which rebuilds the signed payload
19
+ * from `proof.meta` with the same `buildProofJwsPayload` the signers use, so
20
+ * nothing in this repo reconstructs the payload itself. The one pre-C2
21
+ * default that differs (local timestamp skew defaulted to 300s vs DIF's
22
+ * 120s) is preserved explicitly when composing the DIF verifier.
31
23
  */
32
24
  Object.defineProperty(exports, "__esModule", { value: true });
33
25
  exports.ProofVerifier = void 0;
@@ -76,17 +68,9 @@ class ProofVerifier {
76
68
  * Verify a DetachedProof. Checks the JWS signature, nonce replay, and
77
69
  * timestamp skew via the DIF `ProofVerifier` pipeline.
78
70
  *
79
- * Deliberately calls the DIF verifier's `verifyProofDetached()` with a
80
- * canonical payload built by this class's own `buildCanonicalPayload()`,
81
- * rather than the DIF verifier's `verifyProof()` (which would reconstruct
82
- * the payload using ITS OWN internal builder). `@kya-os/mcp` is a
83
- * separately-versioned, externally-published dependency; its internal
84
- * builder does not know about the literal did/kid/audience/toolName/
85
- * outcome fields this repo's signers add to the payload, so proofs signed
86
- * here would fail `@kya-os/mcp`'s own reconstruction even though the
87
- * signature is genuinely valid. Supplying the payload ourselves keeps the
88
- * nonce-replay/timestamp-skew/signature pipeline delegated to DIF while
89
- * sidestepping its stale reconstruction.
71
+ * Calls the DIF verifier's `verifyProof()`, which rebuilds the signed
72
+ * payload from `proof.meta` (the shared `buildProofJwsPayload`, RFC 8785)
73
+ * and checks the signature over it.
90
74
  *
91
75
  * @param proof - The proof to verify
92
76
  * @param publicKeyJwk - Ed25519 public key in JWK format (from DID document)
@@ -94,8 +78,7 @@ class ProofVerifier {
94
78
  */
95
79
  async verifyProof(proof, publicKeyJwk) {
96
80
  const verifier = await this.getDifVerifier();
97
- const canonicalPayload = this.buildCanonicalPayload(proof.meta);
98
- return verifier.verifyProofDetached(proof, canonicalPayload, publicKeyJwk);
81
+ return verifier.verifyProof(proof, publicKeyJwk);
99
82
  }
100
83
  /**
101
84
  * Verify proof with an explicit detached payload (for CLI/verifier
@@ -166,57 +149,16 @@ class ProofVerifier {
166
149
  }
167
150
  }
168
151
  /**
169
- * Build canonical payload from proof meta
170
- *
171
- * CRITICAL: This must reconstruct the exact JWS payload structure that was originally signed.
172
- * The original JWS payload uses standard JWT claims (aud, sub, iss) plus custom proof claims,
173
- * NOT the proof.meta structure directly.
174
- *
175
- * Kept local (not delegated): callers invoke this synchronously, while the DIF
176
- * verifier is only reachable through the async seam. The reconstruction is
177
- * byte-identical to DIF's `buildCanonicalPayload`.
152
+ * The canonical (RFC 8785) JWS payload for `meta`, for detached-JWS
153
+ * consumers. Delegates to `@kya-os/mcp`'s `buildProofJwsPayload`; async
154
+ * because that module is reached through the ESM-bridge seam.
178
155
  *
179
156
  * @param meta - Proof metadata
180
- * @returns Canonical JSON string matching the original JWS payload structure
157
+ * @returns Canonical JSON string identical to the payload a signer signs
181
158
  */
182
- buildCanonicalPayload(meta) {
183
- // Reconstruct the original JWS payload structure that was signed
184
- // This matches the structure used in proof generation (proof.ts, proof-generator.ts)
185
- const payload = {
186
- // Standard JWT claims (RFC 7519) - these are what was actually signed
187
- aud: meta.audience, // Audience (who the token is for)
188
- sub: meta.did, // Subject (agent DID)
189
- iss: meta.did, // Issuer (agent DID - self-issued)
190
- // Literal field names some verifiers (e.g. knowthat.ai) check by
191
- // exact property, rather than the JWT-standard aliases above -- must
192
- // stay in lockstep with generator.ts's payload, or reconstruction
193
- // here will byte-diverge from what was actually signed.
194
- did: meta.did,
195
- kid: meta.kid,
196
- audience: meta.audience,
197
- // Custom MCP-I proof claims
198
- requestHash: meta.requestHash,
199
- responseHash: meta.responseHash,
200
- ts: meta.ts,
201
- nonce: meta.nonce,
202
- sessionId: meta.sessionId,
203
- // Optional claims (only include if present)
204
- ...(meta.scopeId && { scopeId: meta.scopeId }),
205
- ...(meta.delegationRef && { delegationRef: meta.delegationRef }),
206
- ...(meta.clientDid && { clientDid: meta.clientDid }),
207
- ...(meta.toolName && { toolName: meta.toolName }),
208
- ...(meta.submissionOutcome && { outcome: meta.submissionOutcome }),
209
- };
210
- // generator.ts signs this payload via jose's SignJWT, which serializes
211
- // with a plain JSON.stringify() in object-insertion order (see
212
- // JWTClaimsBuilder.data() in the jose source) -- NOT RFC 8785 JCS.
213
- // canonicalize() sorts keys alphabetically, which byte-diverges from
214
- // what was actually signed even when every field VALUE matches (this
215
- // silently broke DIF-delegated verification: see the regression tests
216
- // above). The object literal above already mirrors generator.ts's
217
- // field order exactly, so a plain JSON.stringify() here reproduces the
218
- // exact bytes that were signed.
219
- return JSON.stringify(payload);
159
+ async buildCanonicalPayload(meta) {
160
+ const { buildProofJwsPayload, canonicalizeJSON } = await (0, dif_core_js_1.loadDifCore)();
161
+ return canonicalizeJSON(buildProofJwsPayload(meta));
220
162
  }
221
163
  }
222
164
  exports.ProofVerifier = ProofVerifier;
@@ -1 +1 @@
1
- {"version":3,"file":"proof-verifier.js","sourceRoot":"","sources":["../../src/services/proof-verifier.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;AAQH,2CAIqB;AACrB,wDAAmE;AAmBnE;;;;GAIG;AACH,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAC3C,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAOtC,MAAa,aAAa;IACP,MAAM,CAAsB;IAC5B,KAAK,CAAgB;IACtC,wEAAwE;IAChE,WAAW,CAA6B;IAEhD,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,aAAa,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACK,cAAc;QACpB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC,WAAW,GAAG,IAAA,yBAAW,GAAE,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC5C,wEAAwE;gBACxE,kEAAkE;gBAClE,MAAM,SAAS,GAAG;oBAChB,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc;oBAC1C,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa;oBACxC,kBAAkB,EAAE,IAA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AAE,CAAC;YACf,IAAI,KAAK,YAAY,kCAAsB,EAAE,CAAC;gBAC5C,MAAM,KAAK,CAAC;YACd,CAAC;YACD,OAAO,CAAC,KAAK,CACX,sDAAsD,EACtD,KAAK,CACN,CAAC;YACF,MAAM,IAAI,kCAAsB,CAC9B,0CAA8B,CAAC,qBAAqB,EACpD,0BAA0B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAClF;gBACE,GAAG;gBACH,GAAG;gBACH,aAAa,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aACtE,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,qBAAqB,CAAC,IAA2B;QACrD,MAAM,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,GAAG,MAAM,IAAA,yBAAW,GAAE,CAAC;QACvE,OAAO,gBAAgB,CACrB,oBAAoB,CAAC,IAAkD,CAAC,CACzE,CAAC;IACJ,CAAC;CACF;AA1MD,sCA0MC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Request holder: the DID whose key a tools/call proves its caller holds.
3
+ *
4
+ * The proof is the call's request proof, `_meta["org.kya-os/request-proof"]`
5
+ * (SPEC-ENTITY-CARD §8, SPEC-MCP-EXTENSION §6), verified fail closed by
6
+ * `@kya-os/mcp/card`'s `requireProof`: its request hash covers the call's
7
+ * method and params without `_meta`, its audience is this server's DID, its
8
+ * nonce is spent once, and it is signed by the key the holder DID names. This
9
+ * is the check the Cloudflare adapter's request admission makes
10
+ * (mcp-i-cloudflare `security/mcp-holder-admission`). A did:key holder's key
11
+ * is resolved locally with no network; a did:web holder's keys are the ones
12
+ * its DID document lists for authentication (./holder-keys).
13
+ *
14
+ * A proof names its holder before anything verifies it, so the holder's
15
+ * document is read only for a proof its own claims do not already refuse
16
+ * (./claims-first-guard).
17
+ *
18
+ * A verified holder is identity only: it grants nothing until a delegation
19
+ * the call presents is verified for it.
20
+ *
21
+ * @module services/request-holder
22
+ */
23
+ import { type DifCard } from "../runtime/dif-core";
24
+ import { type DidWebHolderOptions, type ProofPublicJwk } from "./holder-keys";
25
+ type VerifyProofDeps = Parameters<DifCard["requireProof"]>[0];
26
+ type ProofGateCode = Extract<Awaited<ReturnType<ReturnType<DifCard["requireProof"]>>>, {
27
+ ok: false;
28
+ }>["error"]["code"];
29
+ /** Seconds of clock skew a request proof's validity window is widened by. */
30
+ export declare const REQUEST_PROOF_SKEW_SEC = 30;
31
+ /** Why a call proved no holder: it carried no request proof, or a bad one. */
32
+ export type RequestHolderRefusal = "holder_proof_required" | ProofGateCode;
33
+ /** The holder a call proved, or why it proved none. */
34
+ export type RequestHolderResult = {
35
+ ok: true;
36
+ did: string;
37
+ } | {
38
+ ok: false;
39
+ code: RequestHolderRefusal;
40
+ };
41
+ /** How a server checks its calls' request proofs, beside their audience. */
42
+ export interface RequestProofOptions extends DidWebHolderOptions {
43
+ /**
44
+ * The atomic test-and-set that spends a proof's nonce:
45
+ * `(nonce, did, minTtlSec) => Promise<boolean>`, true when the nonce was
46
+ * fresh. Default: one in-memory cache per verifier, so one per process. A
47
+ * proof lives at most 60 seconds and is accepted within 30 seconds of
48
+ * clock skew, so behind several instances that each keep their own cache,
49
+ * a captured proof is accepted once by each, for up to 90 seconds after
50
+ * it was signed. Share one store across the instances that serve one
51
+ * server DID, as the Cloudflare adapter shares a Durable Object.
52
+ */
53
+ consumeNonceIfFresh?: VerifyProofDeps["consumeNonceIfFresh"];
54
+ }
55
+ export interface RequestHolderOptions extends RequestProofOptions {
56
+ /** This server's DID: a proof addressed to any other is refused. */
57
+ audience: string;
58
+ /** Clock in epoch milliseconds, for tests. */
59
+ now?: () => number;
60
+ }
61
+ /** A tools/call as received: its method and params, `_meta` included. */
62
+ export interface HolderRequest {
63
+ method: string;
64
+ params?: Record<string, unknown>;
65
+ }
66
+ export type RequestHolderVerifier = (request: HolderRequest) => Promise<RequestHolderResult>;
67
+ /**
68
+ * The Ed25519 key a did:key holder names by its own key id, resolved with no
69
+ * network. Any other kid, or any other DID method, has no key here.
70
+ */
71
+ export declare function resolveDidKeyHolder(kid: string): Promise<ProofPublicJwk>;
72
+ /**
73
+ * Build the verifier of the holder a tools/call proves. One verifier keeps
74
+ * one nonce cache, so build it once per server.
75
+ */
76
+ export declare function createRequestHolderVerifier(options: RequestHolderOptions): RequestHolderVerifier;
77
+ export {};
78
+ //# sourceMappingURL=request-holder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-holder.d.ts","sourceRoot":"","sources":["../../src/services/request-holder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAA4B,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAEvB,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9D,KAAK,aAAa,GAAG,OAAO,CAC1B,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACxD;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CACd,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnB,6EAA6E;AAC7E,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC,8EAA8E;AAC9E,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,GAAG,aAAa,CAAC;AAE3E,uDAAuD;AACvD,MAAM,MAAM,mBAAmB,GAC3B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,oBAAoB,CAAA;CAAE,CAAC;AAE9C,4EAA4E;AAC5E,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;IAC9D;;;;;;;;;OASG;IACH,mBAAmB,CAAC,EAAE,eAAe,CAAC,qBAAqB,CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,MAAM,qBAAqB,GAAG,CAClC,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAElC;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,cAAc,CAAC,CAgBzB;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,oBAAoB,GAC5B,qBAAqB,CAmCvB"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * Request holder: the DID whose key a tools/call proves its caller holds.
4
+ *
5
+ * The proof is the call's request proof, `_meta["org.kya-os/request-proof"]`
6
+ * (SPEC-ENTITY-CARD §8, SPEC-MCP-EXTENSION §6), verified fail closed by
7
+ * `@kya-os/mcp/card`'s `requireProof`: its request hash covers the call's
8
+ * method and params without `_meta`, its audience is this server's DID, its
9
+ * nonce is spent once, and it is signed by the key the holder DID names. This
10
+ * is the check the Cloudflare adapter's request admission makes
11
+ * (mcp-i-cloudflare `security/mcp-holder-admission`). A did:key holder's key
12
+ * is resolved locally with no network; a did:web holder's keys are the ones
13
+ * its DID document lists for authentication (./holder-keys).
14
+ *
15
+ * A proof names its holder before anything verifies it, so the holder's
16
+ * document is read only for a proof its own claims do not already refuse
17
+ * (./claims-first-guard).
18
+ *
19
+ * A verified holder is identity only: it grants nothing until a delegation
20
+ * the call presents is verified for it.
21
+ *
22
+ * @module services/request-holder
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.REQUEST_PROOF_SKEW_SEC = void 0;
26
+ exports.resolveDidKeyHolder = resolveDidKeyHolder;
27
+ exports.createRequestHolderVerifier = createRequestHolderVerifier;
28
+ const dif_core_1 = require("../runtime/dif-core");
29
+ const claims_first_guard_1 = require("./claims-first-guard");
30
+ const holder_keys_1 = require("./holder-keys");
31
+ /** Seconds of clock skew a request proof's validity window is widened by. */
32
+ exports.REQUEST_PROOF_SKEW_SEC = 30;
33
+ /**
34
+ * The Ed25519 key a did:key holder names by its own key id, resolved with no
35
+ * network. Any other kid, or any other DID method, has no key here.
36
+ */
37
+ async function resolveDidKeyHolder(kid) {
38
+ const { didKeyFragment, extractPublicKeyFromDidKey, isEd25519DidKey, publicKeyToJwk, } = await (0, dif_core_1.loadDifCore)();
39
+ const did = kid.split("#")[0] ?? "";
40
+ const publicKey = isEd25519DidKey(did) && kid === `${did}#${didKeyFragment(did)}`
41
+ ? extractPublicKeyFromDidKey(did)
42
+ : null;
43
+ if (!publicKey) {
44
+ throw new Error("Only an Ed25519 did:key holder's own key is accepted");
45
+ }
46
+ return publicKeyToJwk(publicKey);
47
+ }
48
+ /**
49
+ * Build the verifier of the holder a tools/call proves. One verifier keeps
50
+ * one nonce cache, so build it once per server.
51
+ */
52
+ function createRequestHolderVerifier(options) {
53
+ let guard;
54
+ const holderKeys = (0, holder_keys_1.withDidWebHolders)({
55
+ resolveKey: resolveDidKeyHolder,
56
+ resolveDidKeys: async (did) => {
57
+ const { didKeyFragment } = await (0, dif_core_1.loadDifCore)();
58
+ return [await resolveDidKeyHolder(`${did}#${didKeyFragment(did)}`)];
59
+ },
60
+ }, options);
61
+ const guardFor = (card) => (guard ??= (0, claims_first_guard_1.claimsFirstGuard)(card.requireProof, {
62
+ expectedAudience: options.audience,
63
+ skewSec: exports.REQUEST_PROOF_SKEW_SEC,
64
+ ...(options.now ? { now: options.now } : {}),
65
+ resolveKey: holderKeys.resolveKey,
66
+ resolveDidKeys: holderKeys.resolveDidKeys,
67
+ consumeNonceIfFresh: options.consumeNonceIfFresh ?? new card.InMemoryNonceCache().consume,
68
+ }));
69
+ return async ({ method, params = {} }) => {
70
+ const { _meta, ...signed } = params;
71
+ const card = await (0, dif_core_1.loadDifCard)();
72
+ if (card.readCardProof(_meta) === undefined) {
73
+ return { ok: false, code: "holder_proof_required" };
74
+ }
75
+ const verdict = await guardFor(card)({ method, params: signed }, _meta);
76
+ return verdict.ok
77
+ ? { ok: true, did: verdict.did }
78
+ : { ok: false, code: verdict.error.code };
79
+ };
80
+ }
81
+ //# sourceMappingURL=request-holder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-holder.js","sourceRoot":"","sources":["../../src/services/request-holder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AA+DH,kDAkBC;AAMD,kEAqCC;AA1HD,kDAA6E;AAC7E,6DAAwD;AACxD,+CAIuB;AAQvB,6EAA6E;AAChE,QAAA,sBAAsB,GAAG,EAAE,CAAC;AA0CzC;;;GAGG;AACI,KAAK,UAAU,mBAAmB,CACvC,GAAW;IAEX,MAAM,EACJ,cAAc,EACd,0BAA0B,EAC1B,eAAe,EACf,cAAc,GACf,GAAG,MAAM,IAAA,sBAAW,GAAE,CAAC;IACxB,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACpC,MAAM,SAAS,GACb,eAAe,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,GAAG,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE;QAC7D,CAAC,CAAC,0BAA0B,CAAC,GAAG,CAAC;QACjC,CAAC,CAAC,IAAI,CAAC;I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O,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACpD;AAED;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAEZ;gBAEU,MAAM,EAAE,wBAAwB;IAU5C;;;;;;;;;;;;;;OAcG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,cAAc,EAAE,cAAc,GAAG,IAAI,EACrC,2BAA2B,CAAC,EAAE,MAAM,GACnC,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IA8L5C;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,gBAAgB;IA2CxB;;;;;;;OAOG;YACW,eAAe;CAsB9B"}
@@ -82,8 +82,20 @@ class ToolContextBuilder {
82
82
  // CRED-003: Resolve full token data (not just access_token)
83
83
  // This includes tokenUsage, cookieFormat, apiHeaders for credential providers
84
84
  const tokenData = await this.config.tokenResolver.resolveTokenDataFromDid(userDid, provider, toolProtection.requiredScopes);
85
- if (!tokenData) {
86
- // IDP token not available - check if delegation token exists
85
+ // Reaching this OAuth context builder means the tool is neither
86
+ // consent-only (`none`) nor password (see the comment below), so the
87
+ // effective requirement is OAuth.
88
+ const requiredAuthType = toolProtection.authorization?.type ?? "oauth2";
89
+ // SECURITY (defence in depth): a presented delegation must satisfy the
90
+ // tool's required type before the user's stored IdP token is handed to the
91
+ // tool, the same rule as the delegation-only path below. Otherwise a
92
+ // delegation minted under the user's DID without their sign-in (an
93
+ // anonymous `none` one, say) would unlock their token. Not presenting a
94
+ // delegation keeps the existing behaviour.
95
+ const presentedDelegationAllowed = !delegationToken ||
96
+ (0, auth_type_satisfies_js_1.authTypeSatisfies)(delegationAuthorizationType, requiredAuthType);
97
+ if (!tokenData || !presentedDelegationAllowed) {
98
+ // No usable IDP token - check if delegation token exists
87
99
  // If delegation exists, tool can still execute without IDP token
88
100
  // (the tool handler should check for idpToken if it needs external API access)
89
101
  //
@@ -98,8 +110,8 @@ class ToolContextBuilder {
98
110
  // mismatched delegation (e.g. an anonymous `none` consent-only delegation,
99
111
  // or a legacy record with no persisted type → undefined) is rejected. On
100
112
  // mismatch we do NOT return the delegation-only context; we fall through
101
- // to OAuthRequiredError so the tool re-challenges.
102
- const requiredAuthType = toolProtection.authorization?.type ?? "oauth2";
113
+ // to OAuthRequiredError so the tool re-challenges. `requiredAuthType`
114
+ // is computed above.
103
115
  if (delegationToken &&
104
116
  (0, auth_type_satisfies_js_1.authTypeSatisfies)(delegationAuthorizationType, requiredAuthType)) {
105
117
  this.config.logger("[ToolContextBuilder] IDP token not found, but delegation exists - returning minimal context", {