@kya-os/mcp-i-runtime 1.2.2 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/dist/proof/generator.d.ts +7 -1
- package/dist/proof/generator.d.ts.map +1 -1
- package/dist/proof/generator.js +10 -1
- package/dist/proof/generator.js.map +1 -1
- package/dist/runtime/base.d.ts +3 -0
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +12 -4
- package/dist/runtime/base.js.map +1 -1
- package/dist/services/proof-verifier.d.ts +29 -12
- package/dist/services/proof-verifier.d.ts.map +1 -1
- package/dist/services/proof-verifier.js +50 -17
- package/dist/services/proof-verifier.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/runtime/native-holder-enforcement.test.ts +107 -0
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +19 -36
- package/src/__tests__/utils/tool-protection-runtime.ts +25 -0
- package/src/proof/__tests__/proof-generator.test.ts +65 -0
- package/src/proof/generator.ts +12 -1
- package/src/runtime/base.ts +18 -4
- package/src/services/__tests__/proof-verifier.test.ts +182 -0
- package/src/services/__tests__/storage.service.test.ts +21 -16
- package/src/services/proof-verifier.ts +52 -17
|
@@ -7,20 +7,26 @@
|
|
|
7
7
|
* C2 (#2916): the verification pipeline is re-homed onto the DIF
|
|
8
8
|
* `@kya-os/mcp` `ProofVerifier` — this class is now a thin façade that lazily
|
|
9
9
|
* composes the DIF verifier (via the `loadDifCore()` ESM-bridge seam) and
|
|
10
|
-
* delegates
|
|
11
|
-
* duplicate of
|
|
10
|
+
* delegates the structure/nonce-replay/timestamp-skew/signature pipeline to
|
|
11
|
+
* it, instead of carrying a duplicate of that logic. The public surface
|
|
12
12
|
* (`verifyProof`, `verifyProofDetached`, `buildCanonicalPayload`,
|
|
13
13
|
* `fetchPublicKeyFromDID`, the result/config shapes) is preserved so callers —
|
|
14
14
|
* `runtime/base.ts` and the runtime subclasses that inject a `ProofVerifier` —
|
|
15
15
|
* are unchanged.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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.
|
|
24
30
|
*/
|
|
25
31
|
|
|
26
32
|
import { type Ed25519JWK } from "./crypto.service.js";
|
|
@@ -29,7 +35,6 @@ import { ClockProvider } from "../providers/base.js";
|
|
|
29
35
|
import { NonceCacheProvider } from "../providers/base.js";
|
|
30
36
|
import { FetchProvider } from "../providers/base.js";
|
|
31
37
|
import { type DetachedProof } from "@kya-os/contracts/proof";
|
|
32
|
-
import { canonicalize } from "json-canonicalize";
|
|
33
38
|
import {
|
|
34
39
|
ProofVerificationError,
|
|
35
40
|
PROOF_VERIFICATION_ERROR_CODES,
|
|
@@ -105,9 +110,20 @@ export class ProofVerifier {
|
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
/**
|
|
108
|
-
* Verify a DetachedProof.
|
|
109
|
-
*
|
|
110
|
-
*
|
|
113
|
+
* Verify a DetachedProof. Checks the JWS signature, nonce replay, and
|
|
114
|
+
* timestamp skew via the DIF `ProofVerifier` pipeline.
|
|
115
|
+
*
|
|
116
|
+
* Deliberately calls the DIF verifier's `verifyProofDetached()` with a
|
|
117
|
+
* canonical payload built by this class's own `buildCanonicalPayload()`,
|
|
118
|
+
* rather than the DIF verifier's `verifyProof()` (which would reconstruct
|
|
119
|
+
* the payload using ITS OWN internal builder). `@kya-os/mcp` is a
|
|
120
|
+
* separately-versioned, externally-published dependency; its internal
|
|
121
|
+
* builder does not know about the literal did/kid/audience/toolName/
|
|
122
|
+
* outcome fields this repo's signers add to the payload, so proofs signed
|
|
123
|
+
* here would fail `@kya-os/mcp`'s own reconstruction even though the
|
|
124
|
+
* signature is genuinely valid. Supplying the payload ourselves keeps the
|
|
125
|
+
* nonce-replay/timestamp-skew/signature pipeline delegated to DIF while
|
|
126
|
+
* sidestepping its stale reconstruction.
|
|
111
127
|
*
|
|
112
128
|
* @param proof - The proof to verify
|
|
113
129
|
* @param publicKeyJwk - Ed25519 public key in JWK format (from DID document)
|
|
@@ -118,8 +134,10 @@ export class ProofVerifier {
|
|
|
118
134
|
publicKeyJwk: Ed25519JWK
|
|
119
135
|
): Promise<ProofVerificationResult> {
|
|
120
136
|
const verifier = await this.getDifVerifier();
|
|
121
|
-
|
|
137
|
+
const canonicalPayload = this.buildCanonicalPayload(proof.meta);
|
|
138
|
+
return verifier.verifyProofDetached(
|
|
122
139
|
proof,
|
|
140
|
+
canonicalPayload,
|
|
123
141
|
publicKeyJwk
|
|
124
142
|
) as Promise<ProofVerificationResult>;
|
|
125
143
|
}
|
|
@@ -275,6 +293,14 @@ export class ProofVerifier {
|
|
|
275
293
|
sub: meta.did, // Subject (agent DID)
|
|
276
294
|
iss: meta.did, // Issuer (agent DID - self-issued)
|
|
277
295
|
|
|
296
|
+
// Literal field names some verifiers (e.g. knowthat.ai) check by
|
|
297
|
+
// exact property, rather than the JWT-standard aliases above -- must
|
|
298
|
+
// stay in lockstep with generator.ts's payload, or reconstruction
|
|
299
|
+
// here will byte-diverge from what was actually signed.
|
|
300
|
+
did: meta.did,
|
|
301
|
+
kid: meta.kid,
|
|
302
|
+
audience: meta.audience,
|
|
303
|
+
|
|
278
304
|
// Custom MCP-I proof claims
|
|
279
305
|
requestHash: meta.requestHash,
|
|
280
306
|
responseHash: meta.responseHash,
|
|
@@ -286,10 +312,19 @@ export class ProofVerifier {
|
|
|
286
312
|
...(meta.scopeId && { scopeId: meta.scopeId }),
|
|
287
313
|
...(meta.delegationRef && { delegationRef: meta.delegationRef }),
|
|
288
314
|
...(meta.clientDid && { clientDid: meta.clientDid }),
|
|
315
|
+
...(meta.toolName && { toolName: meta.toolName }),
|
|
316
|
+
...(meta.submissionOutcome && { outcome: meta.submissionOutcome }),
|
|
289
317
|
};
|
|
290
318
|
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
|
|
319
|
+
// generator.ts signs this payload via jose's SignJWT, which serializes
|
|
320
|
+
// with a plain JSON.stringify() in object-insertion order (see
|
|
321
|
+
// JWTClaimsBuilder.data() in the jose source) -- NOT RFC 8785 JCS.
|
|
322
|
+
// canonicalize() sorts keys alphabetically, which byte-diverges from
|
|
323
|
+
// what was actually signed even when every field VALUE matches (this
|
|
324
|
+
// silently broke DIF-delegated verification: see the regression tests
|
|
325
|
+
// above). The object literal above already mirrors generator.ts's
|
|
326
|
+
// field order exactly, so a plain JSON.stringify() here reproduces the
|
|
327
|
+
// exact bytes that were signed.
|
|
328
|
+
return JSON.stringify(payload);
|
|
294
329
|
}
|
|
295
330
|
}
|