@kya-os/mcp-i-runtime 1.2.2 → 1.2.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.
- 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/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 +3 -3
- package/src/proof/__tests__/proof-generator.test.ts +65 -0
- package/src/proof/generator.ts +12 -1
- package/src/services/__tests__/proof-verifier.test.ts +182 -0
- package/src/services/proof-verifier.ts +52 -17
package/.turbo/turbo-build.log
CHANGED
|
@@ -45,6 +45,8 @@ export interface ProofOptions {
|
|
|
45
45
|
scopeId?: string;
|
|
46
46
|
delegationRef?: string;
|
|
47
47
|
clientDid?: string;
|
|
48
|
+
toolName?: string;
|
|
49
|
+
submissionOutcome?: "success" | "failure" | "denied";
|
|
48
50
|
}
|
|
49
51
|
/**
|
|
50
52
|
* Platform-agnostic proof generator.
|
|
@@ -79,7 +81,11 @@ export declare class ProofGenerator {
|
|
|
79
81
|
* Generate Ed25519 JWS in compact format (header.payload.signature).
|
|
80
82
|
* Requirement: 5.3
|
|
81
83
|
*
|
|
82
|
-
*
|
|
84
|
+
* Includes both the JWT-standard claims (aud, sub, iss) and the literal
|
|
85
|
+
* did/kid/audience field names verifiers check for -- a verifier that
|
|
86
|
+
* compares payload fields against proof metadata by exact property name
|
|
87
|
+
* (did, kid, nonce, ts, audience) would otherwise see them all as
|
|
88
|
+
* undefined, since none of the JWT-standard aliases match those names.
|
|
83
89
|
*/
|
|
84
90
|
private generateJWS;
|
|
85
91
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/proof/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EACL,aAAa,EAGd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE;QACL,KAAK,CAAC,EAAE,aAAa,CAAC;QACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/proof/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EACL,aAAa,EAGd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;G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CACvC,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,cAAc,EACvB,cAAc,EAAE,cAAc,EAC9B,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,YAAY,CAAC,CAWvB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,YAAY,GACrB;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAQA"}
|
package/dist/proof/generator.js
CHANGED
|
@@ -81,7 +81,11 @@ class ProofGenerator {
|
|
|
81
81
|
* Generate Ed25519 JWS in compact format (header.payload.signature).
|
|
82
82
|
* Requirement: 5.3
|
|
83
83
|
*
|
|
84
|
-
*
|
|
84
|
+
* Includes both the JWT-standard claims (aud, sub, iss) and the literal
|
|
85
|
+
* did/kid/audience field names verifiers check for -- a verifier that
|
|
86
|
+
* compares payload fields against proof metadata by exact property name
|
|
87
|
+
* (did, kid, nonce, ts, audience) would otherwise see them all as
|
|
88
|
+
* undefined, since none of the JWT-standard aliases match those names.
|
|
85
89
|
*/
|
|
86
90
|
async generateJWS(meta) {
|
|
87
91
|
try {
|
|
@@ -91,6 +95,9 @@ class ProofGenerator {
|
|
|
91
95
|
aud: meta.audience,
|
|
92
96
|
sub: meta.did,
|
|
93
97
|
iss: meta.did,
|
|
98
|
+
did: meta.did,
|
|
99
|
+
kid: this.identity.kid,
|
|
100
|
+
audience: meta.audience,
|
|
94
101
|
requestHash: meta.requestHash,
|
|
95
102
|
responseHash: meta.responseHash,
|
|
96
103
|
ts: meta.ts,
|
|
@@ -99,6 +106,8 @@ class ProofGenerator {
|
|
|
99
106
|
...(meta.scopeId && { scopeId: meta.scopeId }),
|
|
100
107
|
...(meta.delegationRef && { delegationRef: meta.delegationRef }),
|
|
101
108
|
...(meta.clientDid && { clientDid: meta.clientDid }),
|
|
109
|
+
...(meta.toolName && { toolName: meta.toolName }),
|
|
110
|
+
...(meta.submissionOutcome && { outcome: meta.submissionOutcome }),
|
|
102
111
|
};
|
|
103
112
|
const jwt = await new jose_1.SignJWT(payload)
|
|
104
113
|
.setProtectedHeader({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/proof/generator.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/proof/generator.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAwTH,kDAkBC;AAKD,oDAcC;AA3VD,+BAA4C;AAC5C,yDAAiD;AAQjD,+DAA4E;AA4C5E;;;GAGG;AACH,MAAa,cAAc;IACjB,QAAQ,CAAqB;IAC7B,cAAc,CAAiB;IAEvC,YAAY,QAA4B,EAAE,cAA8B;QACtE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,aAAa,CACjB,OAAoB,EACpB,QAAsB,EACtB,OAAuB,EACvB,UAAwB,EAAE;QAE1B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAErE,MAAM,IAAI,GAAc;YACtB,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG;YACtB,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG;YACtB,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;YACjC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,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,QAA4B,EAC5B,OAAuB,EACvB,cAA8B,EAC9B,UAAwB,EAAE;IAE1B,MAAM,QAAQ,GAAiB,EAAE,IAAI,EAAE,CAAC;IACxC,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IACpE,MAAM,KAAK,GAAG,MAAM,cAAc,CAAC,aAAa,CAC9C,OAAO,EACP,QAAQ,EACR,OAAO,EACP,OAAO,CACR,CAAC;IACF,QAAQ,CAAC,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC;IAC1B,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAClC,OAAoB,EACpB,QAAsB;IAKtB,OAAO;QACL,OAAO,EAAE;YACP,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACtD;QACD,QAAQ,EAAE,QAAQ,CAAC,IAAI;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -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
|
import { type Ed25519JWK } from "./crypto.service.js";
|
|
26
32
|
import { CryptoProvider } from "../providers/base.js";
|
|
@@ -57,9 +63,20 @@ export declare class ProofVerifier {
|
|
|
57
63
|
*/
|
|
58
64
|
private getDifVerifier;
|
|
59
65
|
/**
|
|
60
|
-
* Verify a DetachedProof.
|
|
61
|
-
*
|
|
62
|
-
*
|
|
66
|
+
* Verify a DetachedProof. Checks the JWS signature, nonce replay, and
|
|
67
|
+
* timestamp skew via the DIF `ProofVerifier` pipeline.
|
|
68
|
+
*
|
|
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.
|
|
63
80
|
*
|
|
64
81
|
* @param proof - The proof to verify
|
|
65
82
|
* @param publicKeyJwk - Ed25519 public key in JWK format (from DID document)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proof-verifier.d.ts","sourceRoot":"","sources":["../../src/services/proof-verifier.ts"],"names":[],"mappings":"AAAA
|
|
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,EAAE,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAGL,KAAK,0BAA0B,EAChC,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,SAAS,CAAC,EAAE,0BAA0B,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,mBAAmB;IAClC,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;IAC7B,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAeD,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,wEAAwE;IACxE,OAAO,CAAC,WAAW,CAAC,CAA4B;gBAEpC,MAAM,EAAE,mBAAmB;IAKvC;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAqBtB;;;;;;;;;;;;;;;;;;;OAmBG;IACG,WAAW,CACf,KAAK,EAAE,aAAa,EACpB,YAAY,EAAE,UAAU,GACvB,OAAO,CAAC,uBAAuB,CAAC;IAUnC;;;;;;;;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;;;;;;;;;;;;;OAaG;IACH,qBAAqB,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM;CA2C3D"}
|
|
@@ -8,24 +8,29 @@
|
|
|
8
8
|
* C2 (#2916): the verification pipeline is re-homed onto the DIF
|
|
9
9
|
* `@kya-os/mcp` `ProofVerifier` — this class is now a thin façade that lazily
|
|
10
10
|
* composes the DIF verifier (via the `loadDifCore()` ESM-bridge seam) and
|
|
11
|
-
* delegates
|
|
12
|
-
* duplicate of
|
|
11
|
+
* delegates the structure/nonce-replay/timestamp-skew/signature pipeline to
|
|
12
|
+
* it, instead of carrying a duplicate of that logic. The public surface
|
|
13
13
|
* (`verifyProof`, `verifyProofDetached`, `buildCanonicalPayload`,
|
|
14
14
|
* `fetchPublicKeyFromDID`, the result/config shapes) is preserved so callers —
|
|
15
15
|
* `runtime/base.ts` and the runtime subclasses that inject a `ProofVerifier` —
|
|
16
16
|
* are unchanged.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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.
|
|
25
31
|
*/
|
|
26
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
33
|
exports.ProofVerifier = void 0;
|
|
28
|
-
const json_canonicalize_1 = require("json-canonicalize");
|
|
29
34
|
const errors_js_1 = require("./errors.js");
|
|
30
35
|
const dif_core_js_1 = require("../runtime/dif-core.js");
|
|
31
36
|
/**
|
|
@@ -68,9 +73,20 @@ class ProofVerifier {
|
|
|
68
73
|
return this.difVerifier;
|
|
69
74
|
}
|
|
70
75
|
/**
|
|
71
|
-
* Verify a DetachedProof.
|
|
72
|
-
*
|
|
73
|
-
*
|
|
76
|
+
* Verify a DetachedProof. Checks the JWS signature, nonce replay, and
|
|
77
|
+
* timestamp skew via the DIF `ProofVerifier` pipeline.
|
|
78
|
+
*
|
|
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.
|
|
74
90
|
*
|
|
75
91
|
* @param proof - The proof to verify
|
|
76
92
|
* @param publicKeyJwk - Ed25519 public key in JWK format (from DID document)
|
|
@@ -78,7 +94,8 @@ class ProofVerifier {
|
|
|
78
94
|
*/
|
|
79
95
|
async verifyProof(proof, publicKeyJwk) {
|
|
80
96
|
const verifier = await this.getDifVerifier();
|
|
81
|
-
|
|
97
|
+
const canonicalPayload = this.buildCanonicalPayload(proof.meta);
|
|
98
|
+
return verifier.verifyProofDetached(proof, canonicalPayload, publicKeyJwk);
|
|
82
99
|
}
|
|
83
100
|
/**
|
|
84
101
|
* Verify proof with an explicit detached payload (for CLI/verifier
|
|
@@ -170,6 +187,13 @@ class ProofVerifier {
|
|
|
170
187
|
aud: meta.audience, // Audience (who the token is for)
|
|
171
188
|
sub: meta.did, // Subject (agent DID)
|
|
172
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,
|
|
173
197
|
// Custom MCP-I proof claims
|
|
174
198
|
requestHash: meta.requestHash,
|
|
175
199
|
responseHash: meta.responseHash,
|
|
@@ -180,10 +204,19 @@ class ProofVerifier {
|
|
|
180
204
|
...(meta.scopeId && { scopeId: meta.scopeId }),
|
|
181
205
|
...(meta.delegationRef && { delegationRef: meta.delegationRef }),
|
|
182
206
|
...(meta.clientDid && { clientDid: meta.clientDid }),
|
|
207
|
+
...(meta.toolName && { toolName: meta.toolName }),
|
|
208
|
+
...(meta.submissionOutcome && { outcome: meta.submissionOutcome }),
|
|
183
209
|
};
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
|
|
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);
|
|
187
220
|
}
|
|
188
221
|
}
|
|
189
222
|
exports.ProofVerifier = ProofVerifier;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proof-verifier.js","sourceRoot":"","sources":["../../src/services/proof-verifier.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"proof-verifier.js","sourceRoot":"","sources":["../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,EAAE,IAAI,CAAC,SAAS;YAEzB,4CAA4C;YAC5C,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;YAC9C,GAAG,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;YAChE,GAAG,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;YACpD,GAAG,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjD,GAAG,CAAC,IAAI,CAAC,iBAAiB,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC;SACnE,CAAC;QAEF,uEAAuE;QACvE,+DAA+D;QAC/D,mEAAmE;QACnE,qEAAqE;QACrE,qEAAqE;QACrE,sEAAsE;QACtE,kEAAkE;QAClE,uEAAuE;QACvE,gCAAgC;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;CACF;AA/PD,sCA+PC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kya-os/mcp-i-runtime",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Shared product-runtime layer for the MCP-I framework (Node + Cloudflare adapters). Protocol types/values live in @kya-os/mcp (DIF).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Dylan Hobbs",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-no-workspace.js"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@kya-os/contracts": "^1.
|
|
62
|
+
"@kya-os/contracts": "^1.12.1",
|
|
63
63
|
"@kya-os/mcp": "1.11.0",
|
|
64
64
|
"jose": "^5.6.3",
|
|
65
|
-
"json-canonicalize": "
|
|
65
|
+
"json-canonicalize": "2.0.0",
|
|
66
66
|
"zod": "^3.25.67"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
@@ -272,6 +272,71 @@ describe("ProofGenerator", () => {
|
|
|
272
272
|
|
|
273
273
|
expect(payload.clientDid).toBe("did:key:zClientPayload");
|
|
274
274
|
});
|
|
275
|
+
|
|
276
|
+
it("encodes did, kid, and audience as literal payload fields, since verifiers check those exact property names, not the JWT-standard sub/iss/aud aliases", async () => {
|
|
277
|
+
const request: ToolRequest = {
|
|
278
|
+
method: "test-tool",
|
|
279
|
+
params: { input: "hello" },
|
|
280
|
+
};
|
|
281
|
+
const response: ToolResponse = { data: { output: "world" } };
|
|
282
|
+
|
|
283
|
+
const proof = await proofGenerator.generateProof(
|
|
284
|
+
request,
|
|
285
|
+
response,
|
|
286
|
+
mockSession
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
const payload = JSON.parse(
|
|
290
|
+
Buffer.from(proof.jws.split(".")[1], "base64url").toString()
|
|
291
|
+
) as { did?: string; kid?: string; audience?: string };
|
|
292
|
+
|
|
293
|
+
expect(payload.did).toBe(mockIdentity.did);
|
|
294
|
+
expect(payload.kid).toBe(mockIdentity.kid);
|
|
295
|
+
expect(payload.audience).toBe(mockSession.audience);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("omits toolName and outcome from the JWS payload when not provided", async () => {
|
|
299
|
+
const request: ToolRequest = {
|
|
300
|
+
method: "test-tool",
|
|
301
|
+
params: { input: "hello" },
|
|
302
|
+
};
|
|
303
|
+
const response: ToolResponse = { data: { output: "world" } };
|
|
304
|
+
|
|
305
|
+
const proof = await proofGenerator.generateProof(
|
|
306
|
+
request,
|
|
307
|
+
response,
|
|
308
|
+
mockSession
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const payload = JSON.parse(
|
|
312
|
+
Buffer.from(proof.jws.split(".")[1], "base64url").toString()
|
|
313
|
+
) as Record<string, unknown>;
|
|
314
|
+
|
|
315
|
+
expect(payload).not.toHaveProperty("toolName");
|
|
316
|
+
expect(payload).not.toHaveProperty("outcome");
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("encodes toolName as a literal payload field, and renames submissionOutcome to the literal payload key outcome, since know-that-ai's verifier checks those exact property names", async () => {
|
|
320
|
+
const request: ToolRequest = {
|
|
321
|
+
method: "test-tool",
|
|
322
|
+
params: { input: "hello" },
|
|
323
|
+
};
|
|
324
|
+
const response: ToolResponse = { data: { output: "world" } };
|
|
325
|
+
|
|
326
|
+
const proof = await proofGenerator.generateProof(
|
|
327
|
+
request,
|
|
328
|
+
response,
|
|
329
|
+
mockSession,
|
|
330
|
+
{ toolName: "get_weather", submissionOutcome: "success" }
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
const payload = JSON.parse(
|
|
334
|
+
Buffer.from(proof.jws.split(".")[1], "base64url").toString()
|
|
335
|
+
) as { toolName?: string; outcome?: string };
|
|
336
|
+
|
|
337
|
+
expect(payload.toolName).toBe("get_weather");
|
|
338
|
+
expect(payload.outcome).toBe("success");
|
|
339
|
+
});
|
|
275
340
|
});
|
|
276
341
|
|
|
277
342
|
describe("Proof Verification", () => {
|
package/src/proof/generator.ts
CHANGED
|
@@ -57,6 +57,8 @@ export interface ProofOptions {
|
|
|
57
57
|
scopeId?: string;
|
|
58
58
|
delegationRef?: string;
|
|
59
59
|
clientDid?: string;
|
|
60
|
+
toolName?: string;
|
|
61
|
+
submissionOutcome?: "success" | "failure" | "denied";
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
/**
|
|
@@ -144,7 +146,11 @@ export class ProofGenerator {
|
|
|
144
146
|
* Generate Ed25519 JWS in compact format (header.payload.signature).
|
|
145
147
|
* Requirement: 5.3
|
|
146
148
|
*
|
|
147
|
-
*
|
|
149
|
+
* Includes both the JWT-standard claims (aud, sub, iss) and the literal
|
|
150
|
+
* did/kid/audience field names verifiers check for -- a verifier that
|
|
151
|
+
* compares payload fields against proof metadata by exact property name
|
|
152
|
+
* (did, kid, nonce, ts, audience) would otherwise see them all as
|
|
153
|
+
* undefined, since none of the JWT-standard aliases match those names.
|
|
148
154
|
*/
|
|
149
155
|
private async generateJWS(meta: ProofMeta): Promise<string> {
|
|
150
156
|
try {
|
|
@@ -155,6 +161,9 @@ export class ProofGenerator {
|
|
|
155
161
|
aud: meta.audience,
|
|
156
162
|
sub: meta.did,
|
|
157
163
|
iss: meta.did,
|
|
164
|
+
did: meta.did,
|
|
165
|
+
kid: this.identity.kid,
|
|
166
|
+
audience: meta.audience,
|
|
158
167
|
requestHash: meta.requestHash,
|
|
159
168
|
responseHash: meta.responseHash,
|
|
160
169
|
ts: meta.ts,
|
|
@@ -163,6 +172,8 @@ export class ProofGenerator {
|
|
|
163
172
|
...(meta.scopeId && { scopeId: meta.scopeId }),
|
|
164
173
|
...(meta.delegationRef && { delegationRef: meta.delegationRef }),
|
|
165
174
|
...(meta.clientDid && { clientDid: meta.clientDid }),
|
|
175
|
+
...(meta.toolName && { toolName: meta.toolName }),
|
|
176
|
+
...(meta.submissionOutcome && { outcome: meta.submissionOutcome }),
|
|
166
177
|
};
|
|
167
178
|
|
|
168
179
|
const jwt = await new SignJWT(payload)
|
|
@@ -22,6 +22,10 @@ import {
|
|
|
22
22
|
ProofVerificationError,
|
|
23
23
|
PROOF_VERIFICATION_ERROR_CODES,
|
|
24
24
|
} from '../errors.js';
|
|
25
|
+
import { ProofGenerator } from '../../proof/generator.js';
|
|
26
|
+
// Cross-package relative import for a real Node crypto provider in tests —
|
|
27
|
+
// same pattern already used by proof/__tests__/proof-generator.test.ts.
|
|
28
|
+
import { NodeCryptoProvider } from '../../../../mcp-i/src/providers/node-providers';
|
|
25
29
|
|
|
26
30
|
describe('ProofVerifier Security', () => {
|
|
27
31
|
let proofVerifier: ProofVerifier;
|
|
@@ -256,6 +260,69 @@ describe('ProofVerifier Security', () => {
|
|
|
256
260
|
expect(canonical1).toBe(canonical2);
|
|
257
261
|
});
|
|
258
262
|
|
|
263
|
+
it('omits toolName and outcome from the reconstructed payload when meta carries neither', () => {
|
|
264
|
+
const meta = {
|
|
265
|
+
did: 'did:test',
|
|
266
|
+
kid: 'kid',
|
|
267
|
+
ts: 123,
|
|
268
|
+
nonce: 'nonce',
|
|
269
|
+
audience: 'aud',
|
|
270
|
+
sessionId: 'session',
|
|
271
|
+
requestHash: 'sha256:' + 'a'.repeat(64),
|
|
272
|
+
responseHash: 'sha256:' + 'b'.repeat(64),
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const canonical = JSON.parse(proofVerifier.buildCanonicalPayload(meta));
|
|
276
|
+
|
|
277
|
+
expect(canonical).not.toHaveProperty('toolName');
|
|
278
|
+
expect(canonical).not.toHaveProperty('outcome');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('reconstructs the same fields a real ProofGenerator actually signs — regression guard for generator/verifier payload drift', async () => {
|
|
282
|
+
const cryptoProvider = new NodeCryptoProvider();
|
|
283
|
+
const keyPair = await cryptoProvider.generateKeyPair();
|
|
284
|
+
const identity = {
|
|
285
|
+
did: 'did:web:example.com:agents:sync-test',
|
|
286
|
+
kid: 'did:web:example.com:agents:sync-test#key-1',
|
|
287
|
+
privateKey: keyPair.privateKey,
|
|
288
|
+
publicKey: keyPair.publicKey,
|
|
289
|
+
};
|
|
290
|
+
const generator = new ProofGenerator(identity, cryptoProvider);
|
|
291
|
+
|
|
292
|
+
const proof = await generator.generateProof(
|
|
293
|
+
{ method: 'test-tool', params: { input: 'hello' } },
|
|
294
|
+
{ data: { output: 'world' } },
|
|
295
|
+
{
|
|
296
|
+
sessionId: 'sess-sync-test',
|
|
297
|
+
audience: 'did:web:business.example',
|
|
298
|
+
nonce: 'nonce-sync-test',
|
|
299
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
300
|
+
createdAt: Math.floor(Date.now() / 1000),
|
|
301
|
+
lastActivity: Math.floor(Date.now() / 1000),
|
|
302
|
+
ttlMinutes: 30,
|
|
303
|
+
identityState: 'anonymous',
|
|
304
|
+
} as never,
|
|
305
|
+
{ toolName: 'test-tool', submissionOutcome: 'success' }
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
const actualPayload = JSON.parse(
|
|
309
|
+
Buffer.from(proof.jws.split('.')[1]!, 'base64url').toString('utf8')
|
|
310
|
+
);
|
|
311
|
+
const reconstructedPayload = JSON.parse(
|
|
312
|
+
proofVerifier.buildCanonicalPayload(proof.meta)
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
// Field-level equality (not byte/order equality — canonicalization
|
|
316
|
+
// sorts keys, which the signed JWS payload does not). If the
|
|
317
|
+
// reconstruction ever drifts from what generator.ts actually signs,
|
|
318
|
+
// this fails long before it reaches a live 403. Covers toolName and
|
|
319
|
+
// the submissionOutcome -> outcome rename too, since those are the
|
|
320
|
+
// two newest fields most likely to drift out of lockstep.
|
|
321
|
+
expect(reconstructedPayload).toEqual(actualPayload);
|
|
322
|
+
expect(reconstructedPayload.toolName).toBe('test-tool');
|
|
323
|
+
expect(reconstructedPayload.outcome).toBe('success');
|
|
324
|
+
});
|
|
325
|
+
|
|
259
326
|
it('should handle detached JWS reconstruction', async () => {
|
|
260
327
|
const header = { alg: 'EdDSA', kid: 'did:key:z123#key-1' };
|
|
261
328
|
const headerB64 = btoa(JSON.stringify(header))
|
|
@@ -419,6 +486,121 @@ describe('ProofVerifier Security', () => {
|
|
|
419
486
|
});
|
|
420
487
|
});
|
|
421
488
|
|
|
489
|
+
describe('End-to-end verifyProof() with real crypto — regression guard for DIF payload drift', () => {
|
|
490
|
+
// Uses a REAL NodeCryptoProvider (unlike the mocked cryptoProvider used
|
|
491
|
+
// elsewhere in this file, whose verify() always returns true and so
|
|
492
|
+
// could never catch a signature mismatch). This is the only way to
|
|
493
|
+
// prove verifyProof() itself -- not just buildCanonicalPayload() --
|
|
494
|
+
// still accepts a proof signed with the literal did/kid/audience/
|
|
495
|
+
// toolName/outcome fields once the DIF-delegated verifier is involved.
|
|
496
|
+
function makeRealVerifier() {
|
|
497
|
+
const cryptoProvider = new NodeCryptoProvider();
|
|
498
|
+
const clockProvider: ClockProvider = {
|
|
499
|
+
now: () => Date.now(),
|
|
500
|
+
isWithinSkew: () => true,
|
|
501
|
+
hasExpired: () => false,
|
|
502
|
+
calculateExpiry: (ttlSeconds: number) => Date.now() + ttlSeconds * 1000,
|
|
503
|
+
format: (d: number) => new Date(d).toISOString(),
|
|
504
|
+
};
|
|
505
|
+
const nonceCacheProvider: NonceCacheProvider = {
|
|
506
|
+
has: async () => false,
|
|
507
|
+
add: async () => {},
|
|
508
|
+
cleanup: async () => {},
|
|
509
|
+
destroy: async () => {},
|
|
510
|
+
};
|
|
511
|
+
const fetchProvider: FetchProvider = {
|
|
512
|
+
resolveDID: async () => null,
|
|
513
|
+
fetchStatusList: async () => null,
|
|
514
|
+
fetchDelegationChain: async () => null,
|
|
515
|
+
fetch: async () => {
|
|
516
|
+
throw new Error('not used');
|
|
517
|
+
},
|
|
518
|
+
};
|
|
519
|
+
const verifier = new ProofVerifier({
|
|
520
|
+
cryptoProvider,
|
|
521
|
+
clockProvider,
|
|
522
|
+
nonceCacheProvider,
|
|
523
|
+
fetchProvider,
|
|
524
|
+
});
|
|
525
|
+
return { cryptoProvider, verifier };
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function toJwk(publicKeyBase64: string, kid: string): Ed25519JWK {
|
|
529
|
+
const bytes = Buffer.from(publicKeyBase64, 'base64');
|
|
530
|
+
const x = bytes
|
|
531
|
+
.toString('base64')
|
|
532
|
+
.replace(/\+/g, '-')
|
|
533
|
+
.replace(/\//g, '_')
|
|
534
|
+
.replace(/=/g, '');
|
|
535
|
+
return { kty: 'OKP', crv: 'Ed25519', x, kid };
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
it('accepts a proof signed with the literal did/kid/audience/toolName/outcome fields', async () => {
|
|
539
|
+
const { cryptoProvider, verifier } = makeRealVerifier();
|
|
540
|
+
const keyPair = await cryptoProvider.generateKeyPair();
|
|
541
|
+
const identity = {
|
|
542
|
+
did: 'did:web:example.com:agents:e2e-test',
|
|
543
|
+
kid: 'did:web:example.com:agents:e2e-test#key-1',
|
|
544
|
+
privateKey: keyPair.privateKey,
|
|
545
|
+
publicKey: keyPair.publicKey,
|
|
546
|
+
};
|
|
547
|
+
const generator = new ProofGenerator(identity, cryptoProvider);
|
|
548
|
+
|
|
549
|
+
const proof = await generator.generateProof(
|
|
550
|
+
{ method: 'test-tool', params: { input: 'hello' } },
|
|
551
|
+
{ data: { output: 'world' } },
|
|
552
|
+
{
|
|
553
|
+
sessionId: 'sess-e2e-test',
|
|
554
|
+
audience: 'did:web:business.example',
|
|
555
|
+
nonce: 'nonce-e2e-test',
|
|
556
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
557
|
+
createdAt: Math.floor(Date.now() / 1000),
|
|
558
|
+
lastActivity: Math.floor(Date.now() / 1000),
|
|
559
|
+
ttlMinutes: 30,
|
|
560
|
+
identityState: 'anonymous',
|
|
561
|
+
} as never,
|
|
562
|
+
{ toolName: 'get_weather', submissionOutcome: 'success' }
|
|
563
|
+
);
|
|
564
|
+
|
|
565
|
+
const publicKeyJwk = toJwk(identity.publicKey, identity.kid);
|
|
566
|
+
const result = await verifier.verifyProof(proof, publicKeyJwk);
|
|
567
|
+
|
|
568
|
+
expect(result.valid).toBe(true);
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
it('also accepts a proof signed WITHOUT toolName/outcome (PR651-era fields only)', async () => {
|
|
572
|
+
const { cryptoProvider, verifier } = makeRealVerifier();
|
|
573
|
+
const keyPair = await cryptoProvider.generateKeyPair();
|
|
574
|
+
const identity = {
|
|
575
|
+
did: 'did:web:example.com:agents:e2e-test-2',
|
|
576
|
+
kid: 'did:web:example.com:agents:e2e-test-2#key-1',
|
|
577
|
+
privateKey: keyPair.privateKey,
|
|
578
|
+
publicKey: keyPair.publicKey,
|
|
579
|
+
};
|
|
580
|
+
const generator = new ProofGenerator(identity, cryptoProvider);
|
|
581
|
+
|
|
582
|
+
const proof = await generator.generateProof(
|
|
583
|
+
{ method: 'test-tool', params: { input: 'hello' } },
|
|
584
|
+
{ data: { output: 'world' } },
|
|
585
|
+
{
|
|
586
|
+
sessionId: 'sess-e2e-test-2',
|
|
587
|
+
audience: 'did:web:business.example',
|
|
588
|
+
nonce: 'nonce-e2e-test-2',
|
|
589
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
590
|
+
createdAt: Math.floor(Date.now() / 1000),
|
|
591
|
+
lastActivity: Math.floor(Date.now() / 1000),
|
|
592
|
+
ttlMinutes: 30,
|
|
593
|
+
identityState: 'anonymous',
|
|
594
|
+
} as never
|
|
595
|
+
);
|
|
596
|
+
|
|
597
|
+
const publicKeyJwk = toJwk(identity.publicKey, identity.kid);
|
|
598
|
+
const result = await verifier.verifyProof(proof, publicKeyJwk);
|
|
599
|
+
|
|
600
|
+
expect(result.valid).toBe(true);
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
|
|
422
604
|
describe('fetchPublicKeyFromDID', () => {
|
|
423
605
|
it('should fetch public key from DID document', async () => {
|
|
424
606
|
const jwk = await proofVerifier.fetchPublicKeyFromDID('did:key:z123', 'key-1');
|
|
@@ -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
|
}
|