@kya-os/mcp-i 0.1.0 → 1.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.
- package/README.md +406 -71
- package/dist/149.js +1 -0
- package/dist/189.js +1 -0
- package/dist/261.js +1 -0
- package/dist/28.js +1 -0
- package/dist/295.js +1 -0
- package/dist/460.js +1 -0
- package/dist/570.js +1 -0
- package/dist/634.js +1 -0
- package/dist/647.js +1 -0
- package/dist/67.js +1 -0
- package/dist/739.js +1 -0
- package/dist/742.js +1 -0
- package/dist/904.js +1 -0
- package/dist/938.js +1 -0
- package/dist/auth/api-key.d.ts +16 -0
- package/dist/auth/api-key.js +82 -0
- package/dist/auth/jwt.d.ts +43 -0
- package/dist/auth/jwt.js +51 -0
- package/dist/auth/oauth/factory.d.ts +12 -0
- package/dist/auth/oauth/factory.js +36 -0
- package/dist/auth/oauth/index.d.ts +5 -0
- package/dist/auth/oauth/index.js +27 -0
- package/dist/auth/oauth/providers/proxy-provider.d.ts +13 -0
- package/dist/auth/oauth/providers/proxy-provider.js +159 -0
- package/dist/auth/oauth/router.d.ts +4 -0
- package/dist/auth/oauth/router.js +294 -0
- package/dist/auth/oauth/storage/memory-storage.d.ts +12 -0
- package/dist/auth/oauth/storage/memory-storage.js +40 -0
- package/dist/auth/oauth/types.d.ts +112 -0
- package/dist/auth/oauth/types.js +2 -0
- package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.js +176 -0
- package/dist/cache/__tests__/concurrency.test.d.ts +5 -0
- package/dist/cache/__tests__/concurrency.test.js +300 -0
- package/dist/cache/__tests__/dynamodb-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/dynamodb-nonce-cache.test.js +176 -0
- package/dist/cache/__tests__/memory-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/memory-nonce-cache.test.js +132 -0
- package/dist/cache/__tests__/nonce-cache-factory-simple.test.d.ts +4 -0
- package/dist/cache/__tests__/nonce-cache-factory-simple.test.js +133 -0
- package/dist/cache/__tests__/nonce-cache-factory.test.d.ts +4 -0
- package/dist/cache/__tests__/nonce-cache-factory.test.js +252 -0
- package/dist/cache/__tests__/redis-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/redis-nonce-cache.test.js +95 -0
- package/dist/cache/cloudflare-kv-nonce-cache.d.ts +14 -0
- package/dist/cache/cloudflare-kv-nonce-cache.js +93 -0
- package/dist/cache/dynamodb-nonce-cache.d.ts +15 -0
- package/dist/cache/dynamodb-nonce-cache.js +92 -0
- package/dist/cache/index.d.ts +16 -0
- package/dist/cache/index.js +32 -0
- package/dist/cache/memory-nonce-cache.d.ts +44 -0
- package/dist/cache/memory-nonce-cache.js +105 -0
- package/dist/cache/nonce-cache-factory.d.ts +20 -0
- package/dist/cache/nonce-cache-factory.js +208 -0
- package/dist/cache/redis-nonce-cache.d.ts +14 -0
- package/dist/cache/redis-nonce-cache.js +53 -0
- package/dist/compiler/compiler-context.d.ts +23 -0
- package/dist/compiler/compiler-context.js +24 -0
- package/dist/compiler/config/constants.d.ts +41 -0
- package/dist/compiler/config/constants.js +45 -0
- package/dist/compiler/config/index.d.ts +252 -0
- package/dist/compiler/config/index.js +15 -0
- package/dist/compiler/config/injection.d.ts +26 -0
- package/dist/compiler/config/injection.js +58 -0
- package/dist/compiler/config/schemas/experimental/index.d.ts +91 -0
- package/dist/compiler/config/schemas/experimental/index.js +16 -0
- package/dist/compiler/config/schemas/experimental/oauth.d.ts +74 -0
- package/dist/compiler/config/schemas/experimental/oauth.js +25 -0
- package/dist/compiler/config/schemas/index.d.ts +6 -0
- package/dist/compiler/config/schemas/index.js +17 -0
- package/dist/compiler/config/schemas/paths.d.ts +9 -0
- package/dist/compiler/config/schemas/paths.js +12 -0
- package/dist/compiler/config/schemas/transport/http.d.ts +82 -0
- package/dist/compiler/config/schemas/transport/http.js +33 -0
- package/dist/compiler/config/schemas/transport/stdio.d.ts +9 -0
- package/dist/compiler/config/schemas/transport/stdio.js +15 -0
- package/dist/compiler/config/schemas/webpack.d.ts +3 -0
- package/dist/compiler/config/schemas/webpack.js +15 -0
- package/dist/compiler/config/types.d.ts +1 -0
- package/dist/compiler/config/types.js +2 -0
- package/dist/compiler/config/utils.d.ts +20 -0
- package/dist/compiler/config/utils.js +36 -0
- package/dist/compiler/generate-env-code.d.ts +1 -0
- package/dist/compiler/generate-env-code.js +8 -0
- package/dist/compiler/generate-import-code.d.ts +1 -0
- package/dist/compiler/generate-import-code.js +24 -0
- package/dist/compiler/get-webpack-config/get-entries.d.ts +3 -0
- package/dist/compiler/get-webpack-config/get-entries.js +29 -0
- package/dist/compiler/get-webpack-config/get-externals.d.ts +7 -0
- package/dist/compiler/get-webpack-config/get-externals.js +88 -0
- package/dist/compiler/get-webpack-config/get-injected-variables.d.ts +8 -0
- package/dist/compiler/get-webpack-config/get-injected-variables.js +25 -0
- package/dist/compiler/get-webpack-config/index.d.ts +4 -0
- package/dist/compiler/get-webpack-config/index.js +101 -0
- package/dist/compiler/get-webpack-config/plugins.d.ts +8 -0
- package/dist/compiler/get-webpack-config/plugins.js +132 -0
- package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.d.ts +9 -0
- package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.js +40 -0
- package/dist/compiler/index.d.ts +6 -0
- package/dist/compiler/index.js +194 -0
- package/dist/compiler/on-first-build.d.ts +3 -0
- package/dist/compiler/on-first-build.js +58 -0
- package/dist/compiler/parse-xmcp-config.d.ts +9 -0
- package/dist/compiler/parse-xmcp-config.js +155 -0
- package/dist/compiler/start-http-server.d.ts +1 -0
- package/dist/compiler/start-http-server.js +34 -0
- package/dist/index.d.ts +12 -54
- package/dist/index.js +22 -190
- package/dist/index.js.LICENSE.txt +49 -0
- package/dist/runtime/__tests__/audit.test.d.ts +4 -0
- package/dist/runtime/__tests__/audit.test.js +328 -0
- package/dist/runtime/__tests__/identity.test.d.ts +4 -0
- package/dist/runtime/__tests__/identity.test.js +164 -0
- package/dist/runtime/__tests__/mcpi-runtime.test.d.ts +4 -0
- package/dist/runtime/__tests__/mcpi-runtime.test.js +372 -0
- package/dist/runtime/__tests__/proof.test.d.ts +4 -0
- package/dist/runtime/__tests__/proof.test.js +302 -0
- package/dist/runtime/__tests__/session.test.d.ts +4 -0
- package/dist/runtime/__tests__/session.test.js +254 -0
- package/dist/runtime/__tests__/well-known.test.d.ts +4 -0
- package/dist/runtime/__tests__/well-known.test.js +312 -0
- package/dist/runtime/adapter-express.js +2 -0
- package/dist/runtime/adapter-express.js.LICENSE.txt +252 -0
- package/dist/runtime/adapter-nextjs.js +2 -0
- package/dist/runtime/adapter-nextjs.js.LICENSE.txt +53 -0
- package/dist/runtime/adapters/express/index.d.ts +2 -0
- package/dist/runtime/adapters/express/index.js +48 -0
- package/dist/runtime/adapters/nextjs/index.d.ts +8 -0
- package/dist/runtime/adapters/nextjs/index.js +18 -0
- package/dist/runtime/audit.d.ts +93 -0
- package/dist/runtime/audit.js +212 -0
- package/dist/runtime/debug.d.ts +118 -0
- package/dist/runtime/debug.js +612 -0
- package/dist/runtime/delegation-hooks.d.ts +85 -0
- package/dist/runtime/delegation-hooks.js +116 -0
- package/dist/runtime/demo.d.ts +71 -0
- package/dist/runtime/demo.js +135 -0
- package/dist/runtime/headers.d.ts +1 -0
- package/dist/runtime/headers.js +9 -0
- package/dist/runtime/http.js +2 -0
- package/dist/runtime/http.js.LICENSE.txt +252 -0
- package/dist/runtime/identity.d.ts +105 -0
- package/dist/runtime/identity.js +232 -0
- package/dist/runtime/index.d.ts +16 -0
- package/dist/runtime/index.js +56 -0
- package/dist/runtime/mcpi-runtime.d.ts +164 -0
- package/dist/runtime/mcpi-runtime.js +352 -0
- package/dist/runtime/proof.d.ts +87 -0
- package/dist/runtime/proof.js +223 -0
- package/dist/runtime/session.d.ts +88 -0
- package/dist/runtime/session.js +216 -0
- package/dist/runtime/stdio.js +2 -0
- package/dist/runtime/stdio.js.LICENSE.txt +1 -0
- package/dist/runtime/templates/home.d.ts +2 -0
- package/dist/runtime/templates/home.js +50 -0
- package/dist/runtime/transports/http/base-streamable-http.d.ts +25 -0
- package/dist/runtime/transports/http/base-streamable-http.js +16 -0
- package/dist/runtime/transports/http/http-context.d.ts +9 -0
- package/dist/runtime/transports/http/http-context.js +8 -0
- package/dist/runtime/transports/http/index.d.ts +1 -0
- package/dist/runtime/transports/http/index.js +55 -0
- package/dist/runtime/transports/http/setup-cors.d.ts +4 -0
- package/dist/runtime/transports/http/setup-cors.js +24 -0
- package/dist/runtime/transports/http/stateless-streamable-http.d.ts +39 -0
- package/dist/runtime/transports/http/stateless-streamable-http.js +331 -0
- package/dist/runtime/transports/stdio/index.d.ts +1 -0
- package/dist/runtime/transports/stdio/index.js +51 -0
- package/dist/runtime/utils/server.d.ts +42 -0
- package/dist/runtime/utils/server.js +39 -0
- package/dist/runtime/utils/tools.d.ts +8 -0
- package/dist/runtime/utils/tools.js +115 -0
- package/dist/runtime/verifier-middleware.d.ts +76 -0
- package/dist/runtime/verifier-middleware.js +322 -0
- package/dist/runtime/well-known.d.ts +151 -0
- package/dist/runtime/well-known.js +258 -0
- package/dist/storage/config.d.ts +28 -0
- package/dist/storage/config.js +79 -0
- package/dist/storage/delegation.d.ts +59 -0
- package/dist/storage/delegation.js +130 -0
- package/dist/storage/merkle-verifier.d.ts +84 -0
- package/dist/storage/merkle-verifier.js +261 -0
- package/dist/test/__tests__/nonce-cache-integration.test.d.ts +1 -0
- package/dist/test/__tests__/nonce-cache-integration.test.js +116 -0
- package/dist/test/__tests__/nonce-cache.test.d.ts +1 -0
- package/dist/test/__tests__/nonce-cache.test.js +122 -0
- package/dist/test/__tests__/runtime-integration.test.d.ts +4 -0
- package/dist/test/__tests__/runtime-integration.test.js +192 -0
- package/dist/test/__tests__/test-infrastructure.test.d.ts +4 -0
- package/dist/test/__tests__/test-infrastructure.test.js +178 -0
- package/dist/test/deterministic-keys.d.ts +31 -0
- package/dist/test/deterministic-keys.js +108 -0
- package/dist/test/examples/test-usage-example.d.ts +140 -0
- package/dist/test/examples/test-usage-example.js +175 -0
- package/dist/test/index.d.ts +11 -0
- package/dist/test/index.js +27 -0
- package/dist/test/local-verification.d.ts +28 -0
- package/dist/test/local-verification.js +342 -0
- package/dist/test/mock-identity-provider.d.ts +96 -0
- package/dist/test/mock-identity-provider.js +243 -0
- package/dist/test/runtime-integration.d.ts +63 -0
- package/dist/test/runtime-integration.js +140 -0
- package/dist/test/test-environment.d.ts +26 -0
- package/dist/test/test-environment.js +50 -0
- package/dist/types/declarations.d.ts +1 -0
- package/dist/types/declarations.js +6 -0
- package/dist/types/middleware.d.ts +2 -0
- package/dist/types/middleware.js +2 -0
- package/dist/types/tool.d.ts +80 -0
- package/dist/types/tool.js +2 -0
- package/dist/utils/cli-icons.d.ts +3 -0
- package/dist/utils/cli-icons.js +7 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.js +13 -0
- package/dist/utils/context.d.ts +33 -0
- package/dist/utils/context.js +58 -0
- package/dist/utils/file-watcher.d.ts +19 -0
- package/dist/utils/file-watcher.js +49 -0
- package/dist/utils/fs-utils.d.ts +2 -0
- package/dist/utils/fs-utils.js +22 -0
- package/dist/utils/path-validation.d.ts +3 -0
- package/dist/utils/path-validation.js +56 -0
- package/dist/utils/spawn-process.d.ts +9 -0
- package/dist/utils/spawn-process.js +50 -0
- package/dist/utils/subscribable.d.ts +12 -0
- package/dist/utils/subscribable.js +44 -0
- package/package.json +99 -21
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* XMCP-I Debug Tools - Development-only debug endpoints
|
|
4
|
+
*
|
|
5
|
+
* Provides /verify endpoint for proof inspection and debugging
|
|
6
|
+
* in development environments only.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DebugManager = void 0;
|
|
10
|
+
exports.createDebugEndpoint = createDebugEndpoint;
|
|
11
|
+
/**
|
|
12
|
+
* Debug endpoint manager
|
|
13
|
+
*/
|
|
14
|
+
class DebugManager {
|
|
15
|
+
identity;
|
|
16
|
+
environment;
|
|
17
|
+
lastProof;
|
|
18
|
+
lastSession;
|
|
19
|
+
logRoot;
|
|
20
|
+
constructor(identity, environment = "development") {
|
|
21
|
+
this.identity = identity;
|
|
22
|
+
this.environment = environment;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Update debug state with latest proof and session
|
|
26
|
+
*/
|
|
27
|
+
updateDebugState(proof, session) {
|
|
28
|
+
if (this.environment === "development") {
|
|
29
|
+
this.lastProof = proof;
|
|
30
|
+
this.lastSession = session;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set log root for receipt verification
|
|
35
|
+
*/
|
|
36
|
+
setLogRoot(logRoot) {
|
|
37
|
+
this.logRoot = logRoot;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generate debug page data
|
|
41
|
+
*/
|
|
42
|
+
async generateDebugPageData(_didDocument, agentDocument, logRoot) {
|
|
43
|
+
if (this.environment !== "development") {
|
|
44
|
+
throw new Error("Debug endpoint only available in development");
|
|
45
|
+
}
|
|
46
|
+
const data = {
|
|
47
|
+
identity: {
|
|
48
|
+
did: this.identity.did,
|
|
49
|
+
keyId: this.identity.keyId,
|
|
50
|
+
didDocumentUrl: this.generateDIDDocumentUrl(this.identity.did),
|
|
51
|
+
},
|
|
52
|
+
registry: {
|
|
53
|
+
ktaUrl: this.generateKTAUrl(this.identity.did),
|
|
54
|
+
mcpMirrorStatus: "unknown", // Would be fetched from KTA in real implementation
|
|
55
|
+
},
|
|
56
|
+
capabilities: {
|
|
57
|
+
protocol: ["handshake", "signing", "verification"],
|
|
58
|
+
identity: ["handshake", "signing", "verification"],
|
|
59
|
+
source: agentDocument ? "well-known" : "handshake",
|
|
60
|
+
},
|
|
61
|
+
timestamp: Date.now(),
|
|
62
|
+
environment: this.environment,
|
|
63
|
+
};
|
|
64
|
+
// Add proof data if available
|
|
65
|
+
if (this.lastProof) {
|
|
66
|
+
data.proof = {
|
|
67
|
+
jws: this.lastProof.jws,
|
|
68
|
+
meta: this.lastProof.meta,
|
|
69
|
+
canonicalHashes: {
|
|
70
|
+
requestHash: this.lastProof.meta.requestHash,
|
|
71
|
+
responseHash: this.lastProof.meta.responseHash,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
// Perform local verification
|
|
75
|
+
data.verification = await this.performLocalVerification(this.lastProof, this.lastSession);
|
|
76
|
+
}
|
|
77
|
+
// Add log root for receipt verification
|
|
78
|
+
if (logRoot) {
|
|
79
|
+
data.logRoot = logRoot;
|
|
80
|
+
}
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create debug endpoint handler
|
|
85
|
+
*/
|
|
86
|
+
createDebugHandler() {
|
|
87
|
+
return async (_request) => {
|
|
88
|
+
if (this.environment !== "development") {
|
|
89
|
+
return new Response("Debug endpoint not available in production", {
|
|
90
|
+
status: 404,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const debugData = await this.generateDebugPageData(undefined, undefined, this.logRoot);
|
|
95
|
+
const html = this.generateDebugHTML(debugData);
|
|
96
|
+
return new Response(html, {
|
|
97
|
+
headers: {
|
|
98
|
+
"Content-Type": "text/html",
|
|
99
|
+
"Cache-Control": "no-store",
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error("Debug endpoint error:", error);
|
|
105
|
+
return new Response("Internal server error", { status: 500 });
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Perform local verification of proof
|
|
111
|
+
*/
|
|
112
|
+
async performLocalVerification(proof, session) {
|
|
113
|
+
const result = {
|
|
114
|
+
success: false,
|
|
115
|
+
signature: {
|
|
116
|
+
valid: false,
|
|
117
|
+
algorithm: "EdDSA",
|
|
118
|
+
keyId: proof.meta.kid,
|
|
119
|
+
},
|
|
120
|
+
proof: {
|
|
121
|
+
valid: false,
|
|
122
|
+
timestamp: {
|
|
123
|
+
valid: false,
|
|
124
|
+
skew: 0,
|
|
125
|
+
},
|
|
126
|
+
hashes: {
|
|
127
|
+
requestValid: false,
|
|
128
|
+
responseValid: false,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
session: {
|
|
132
|
+
valid: false,
|
|
133
|
+
expired: false,
|
|
134
|
+
ttl: 0,
|
|
135
|
+
},
|
|
136
|
+
errors: [],
|
|
137
|
+
};
|
|
138
|
+
try {
|
|
139
|
+
// Validate timestamp
|
|
140
|
+
const now = Math.floor(Date.now() / 1000);
|
|
141
|
+
const skew = Math.abs(now - proof.meta.ts);
|
|
142
|
+
result.proof.timestamp.skew = skew;
|
|
143
|
+
result.proof.timestamp.valid = skew <= 120; // Default 120s tolerance
|
|
144
|
+
if (!result.proof.timestamp.valid) {
|
|
145
|
+
result.errors?.push(`Timestamp skew too large: ${skew}s (max 120s). Check NTP sync.`);
|
|
146
|
+
result.proof.timestamp.remediation =
|
|
147
|
+
"Check NTP sync; adjust XMCP_I_TS_SKEW_SEC";
|
|
148
|
+
}
|
|
149
|
+
// Validate hash format
|
|
150
|
+
result.proof.hashes.requestValid = /^sha256:[a-f0-9]{64}$/.test(proof.meta.requestHash);
|
|
151
|
+
result.proof.hashes.responseValid = /^sha256:[a-f0-9]{64}$/.test(proof.meta.responseHash);
|
|
152
|
+
if (!result.proof.hashes.requestValid) {
|
|
153
|
+
result.errors?.push("Invalid request hash format");
|
|
154
|
+
}
|
|
155
|
+
if (!result.proof.hashes.responseValid) {
|
|
156
|
+
result.errors?.push("Invalid response hash format");
|
|
157
|
+
}
|
|
158
|
+
// Validate session if available
|
|
159
|
+
if (session) {
|
|
160
|
+
const sessionAge = now - Math.floor(session.createdAt / 1000);
|
|
161
|
+
const sessionTtl = session.ttlMinutes || 30;
|
|
162
|
+
result.session.ttl = sessionTtl * 60 - sessionAge;
|
|
163
|
+
result.session.expired = result.session.ttl <= 0;
|
|
164
|
+
result.session.valid = !result.session.expired;
|
|
165
|
+
if (result.session.expired) {
|
|
166
|
+
result.errors?.push("Session expired");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Overall validation
|
|
170
|
+
result.proof.valid =
|
|
171
|
+
result.proof.timestamp.valid &&
|
|
172
|
+
result.proof.hashes.requestValid &&
|
|
173
|
+
result.proof.hashes.responseValid;
|
|
174
|
+
result.success =
|
|
175
|
+
result.proof.valid && result.session.valid && !result.errors?.length;
|
|
176
|
+
// Note: In a real implementation, we would verify the JWS signature
|
|
177
|
+
// using the public key from the DID document
|
|
178
|
+
result.signature.valid = true; // Placeholder for actual signature verification
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
result.errors?.push(`Verification error: ${error}`);
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Generate DID document URL
|
|
187
|
+
*/
|
|
188
|
+
generateDIDDocumentUrl(did) {
|
|
189
|
+
if (did.startsWith("did:web:")) {
|
|
190
|
+
const domain = did.replace("did:web:", "").replace(/:/g, "/");
|
|
191
|
+
return `https://${domain}/.well-known/did.json`;
|
|
192
|
+
}
|
|
193
|
+
return `${did}/.well-known/did.json`;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Generate KTA URL
|
|
197
|
+
*/
|
|
198
|
+
generateKTAUrl(did) {
|
|
199
|
+
// Extract agent identifier from DID for KTA URL
|
|
200
|
+
const agentId = did.split(":").pop() || "unknown";
|
|
201
|
+
return `https://knowthat.ai/agents/${agentId}`;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Generate debug HTML page
|
|
205
|
+
*/
|
|
206
|
+
generateDebugHTML(data) {
|
|
207
|
+
return `<!DOCTYPE html>
|
|
208
|
+
<html lang="en">
|
|
209
|
+
<head>
|
|
210
|
+
<meta charset="UTF-8">
|
|
211
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
212
|
+
<title>XMCP-I Debug - Proof Verification</title>
|
|
213
|
+
<style>
|
|
214
|
+
body {
|
|
215
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
216
|
+
line-height: 1.6;
|
|
217
|
+
margin: 0;
|
|
218
|
+
padding: 20px;
|
|
219
|
+
background: #f5f5f5;
|
|
220
|
+
}
|
|
221
|
+
.container {
|
|
222
|
+
max-width: 1200px;
|
|
223
|
+
margin: 0 auto;
|
|
224
|
+
background: white;
|
|
225
|
+
border-radius: 8px;
|
|
226
|
+
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
227
|
+
overflow: hidden;
|
|
228
|
+
}
|
|
229
|
+
.header {
|
|
230
|
+
background: #2563eb;
|
|
231
|
+
color: white;
|
|
232
|
+
padding: 20px;
|
|
233
|
+
}
|
|
234
|
+
.header h1 {
|
|
235
|
+
margin: 0;
|
|
236
|
+
font-size: 24px;
|
|
237
|
+
}
|
|
238
|
+
.header .subtitle {
|
|
239
|
+
opacity: 0.9;
|
|
240
|
+
margin-top: 5px;
|
|
241
|
+
}
|
|
242
|
+
.section {
|
|
243
|
+
padding: 20px;
|
|
244
|
+
border-bottom: 1px solid #e5e7eb;
|
|
245
|
+
}
|
|
246
|
+
.section:last-child {
|
|
247
|
+
border-bottom: none;
|
|
248
|
+
}
|
|
249
|
+
.section h2 {
|
|
250
|
+
margin: 0 0 15px 0;
|
|
251
|
+
color: #1f2937;
|
|
252
|
+
font-size: 18px;
|
|
253
|
+
}
|
|
254
|
+
.grid {
|
|
255
|
+
display: grid;
|
|
256
|
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
257
|
+
gap: 20px;
|
|
258
|
+
}
|
|
259
|
+
.card {
|
|
260
|
+
background: #f9fafb;
|
|
261
|
+
border: 1px solid #e5e7eb;
|
|
262
|
+
border-radius: 6px;
|
|
263
|
+
padding: 15px;
|
|
264
|
+
}
|
|
265
|
+
.card h3 {
|
|
266
|
+
margin: 0 0 10px 0;
|
|
267
|
+
color: #374151;
|
|
268
|
+
font-size: 16px;
|
|
269
|
+
}
|
|
270
|
+
.field {
|
|
271
|
+
margin-bottom: 10px;
|
|
272
|
+
}
|
|
273
|
+
.field label {
|
|
274
|
+
display: block;
|
|
275
|
+
font-weight: 600;
|
|
276
|
+
color: #4b5563;
|
|
277
|
+
margin-bottom: 2px;
|
|
278
|
+
font-size: 14px;
|
|
279
|
+
}
|
|
280
|
+
.field .value {
|
|
281
|
+
font-family: 'SF Mono', Monaco, monospace;
|
|
282
|
+
font-size: 13px;
|
|
283
|
+
background: white;
|
|
284
|
+
border: 1px solid #d1d5db;
|
|
285
|
+
border-radius: 4px;
|
|
286
|
+
padding: 8px;
|
|
287
|
+
word-break: break-all;
|
|
288
|
+
}
|
|
289
|
+
.status {
|
|
290
|
+
display: inline-block;
|
|
291
|
+
padding: 2px 8px;
|
|
292
|
+
border-radius: 12px;
|
|
293
|
+
font-size: 12px;
|
|
294
|
+
font-weight: 600;
|
|
295
|
+
}
|
|
296
|
+
.status.success {
|
|
297
|
+
background: #dcfce7;
|
|
298
|
+
color: #166534;
|
|
299
|
+
}
|
|
300
|
+
.status.error {
|
|
301
|
+
background: #fef2f2;
|
|
302
|
+
color: #dc2626;
|
|
303
|
+
}
|
|
304
|
+
.status.warning {
|
|
305
|
+
background: #fef3c7;
|
|
306
|
+
color: #d97706;
|
|
307
|
+
}
|
|
308
|
+
.status.unknown {
|
|
309
|
+
background: #f3f4f6;
|
|
310
|
+
color: #6b7280;
|
|
311
|
+
}
|
|
312
|
+
.code-block {
|
|
313
|
+
background: #1f2937;
|
|
314
|
+
color: #f9fafb;
|
|
315
|
+
padding: 15px;
|
|
316
|
+
border-radius: 6px;
|
|
317
|
+
font-family: 'SF Mono', Monaco, monospace;
|
|
318
|
+
font-size: 13px;
|
|
319
|
+
overflow-x: auto;
|
|
320
|
+
white-space: pre-wrap;
|
|
321
|
+
word-break: break-all;
|
|
322
|
+
}
|
|
323
|
+
.warning-banner {
|
|
324
|
+
background: #fef3c7;
|
|
325
|
+
border: 1px solid #f59e0b;
|
|
326
|
+
border-radius: 6px;
|
|
327
|
+
padding: 15px;
|
|
328
|
+
margin-bottom: 20px;
|
|
329
|
+
}
|
|
330
|
+
.warning-banner strong {
|
|
331
|
+
color: #92400e;
|
|
332
|
+
}
|
|
333
|
+
.link {
|
|
334
|
+
color: #2563eb;
|
|
335
|
+
text-decoration: none;
|
|
336
|
+
}
|
|
337
|
+
.link:hover {
|
|
338
|
+
text-decoration: underline;
|
|
339
|
+
}
|
|
340
|
+
.timestamp {
|
|
341
|
+
color: #6b7280;
|
|
342
|
+
font-size: 12px;
|
|
343
|
+
margin-top: 20px;
|
|
344
|
+
}
|
|
345
|
+
</style>
|
|
346
|
+
</head>
|
|
347
|
+
<body>
|
|
348
|
+
<div class="container">
|
|
349
|
+
<div class="header">
|
|
350
|
+
<h1>🔍 XMCP-I Debug Console</h1>
|
|
351
|
+
<div class="subtitle">Proof Verification & Identity Inspection</div>
|
|
352
|
+
</div>
|
|
353
|
+
|
|
354
|
+
<div class="warning-banner">
|
|
355
|
+
<strong>Development Only:</strong> This debug endpoint is only available in development mode and does not expose payload bodies or secrets.
|
|
356
|
+
</div>
|
|
357
|
+
|
|
358
|
+
<div class="section">
|
|
359
|
+
<h2>Agent Identity</h2>
|
|
360
|
+
<div class="grid">
|
|
361
|
+
<div class="card">
|
|
362
|
+
<h3>Identity Information</h3>
|
|
363
|
+
<div class="field">
|
|
364
|
+
<label>DID</label>
|
|
365
|
+
<div class="value">${data.identity.did}</div>
|
|
366
|
+
</div>
|
|
367
|
+
<div class="field">
|
|
368
|
+
<label>Key ID</label>
|
|
369
|
+
<div class="value">${data.identity.keyId}</div>
|
|
370
|
+
</div>
|
|
371
|
+
<div class="field">
|
|
372
|
+
<label>DID Document</label>
|
|
373
|
+
<div class="value">
|
|
374
|
+
<a href="${data.identity.didDocumentUrl}" class="link" target="_blank">
|
|
375
|
+
${data.identity.didDocumentUrl}
|
|
376
|
+
</a>
|
|
377
|
+
</div>
|
|
378
|
+
</div>
|
|
379
|
+
</div>
|
|
380
|
+
|
|
381
|
+
<div class="card">
|
|
382
|
+
<h3>Registry Status</h3>
|
|
383
|
+
<div class="field">
|
|
384
|
+
<label>Know-That-AI</label>
|
|
385
|
+
<div class="value">
|
|
386
|
+
<a href="${data.registry.ktaUrl}" class="link" target="_blank">
|
|
387
|
+
${data.registry.ktaUrl}
|
|
388
|
+
</a>
|
|
389
|
+
</div>
|
|
390
|
+
</div>
|
|
391
|
+
<div class="field">
|
|
392
|
+
<label>MCP Mirror Status</label>
|
|
393
|
+
<div class="value">
|
|
394
|
+
<span class="status ${data.registry.mcpMirrorStatus}">
|
|
395
|
+
${data.registry.mcpMirrorStatus}
|
|
396
|
+
</span>
|
|
397
|
+
</div>
|
|
398
|
+
</div>
|
|
399
|
+
${data.logRoot
|
|
400
|
+
? `
|
|
401
|
+
<div class="field">
|
|
402
|
+
<label>Log Root (Receipt Verification)</label>
|
|
403
|
+
<div class="value">${data.logRoot}</div>
|
|
404
|
+
</div>
|
|
405
|
+
`
|
|
406
|
+
: ""}
|
|
407
|
+
</div>
|
|
408
|
+
</div>
|
|
409
|
+
</div>
|
|
410
|
+
|
|
411
|
+
<div class="section">
|
|
412
|
+
<h2>Protocol Capabilities</h2>
|
|
413
|
+
<div class="card">
|
|
414
|
+
<h3>Advertised Capabilities</h3>
|
|
415
|
+
<div class="field">
|
|
416
|
+
<label>MCP-I Features</label>
|
|
417
|
+
<div class="value">${JSON.stringify(data.capabilities.identity)}</div>
|
|
418
|
+
</div>
|
|
419
|
+
<div class="field">
|
|
420
|
+
<label>Source</label>
|
|
421
|
+
<div class="value">${data.capabilities.source}</div>
|
|
422
|
+
</div>
|
|
423
|
+
</div>
|
|
424
|
+
</div>
|
|
425
|
+
|
|
426
|
+
${data.proof
|
|
427
|
+
? `
|
|
428
|
+
<div class="section">
|
|
429
|
+
<h2>Latest Proof</h2>
|
|
430
|
+
<div class="grid">
|
|
431
|
+
<div class="card">
|
|
432
|
+
<h3>Proof Metadata</h3>
|
|
433
|
+
<div class="field">
|
|
434
|
+
<label>Session ID</label>
|
|
435
|
+
<div class="value">${data.proof.meta.sessionId}</div>
|
|
436
|
+
</div>
|
|
437
|
+
<div class="field">
|
|
438
|
+
<label>Audience</label>
|
|
439
|
+
<div class="value">${data.proof.meta.audience}</div>
|
|
440
|
+
</div>
|
|
441
|
+
<div class="field">
|
|
442
|
+
<label>Timestamp</label>
|
|
443
|
+
<div class="value">${new Date(data.proof.meta.ts * 1000).toISOString()}</div>
|
|
444
|
+
</div>
|
|
445
|
+
<div class="field">
|
|
446
|
+
<label>Nonce</label>
|
|
447
|
+
<div class="value">${data.proof.meta.nonce}</div>
|
|
448
|
+
</div>
|
|
449
|
+
${data.proof.meta.scopeId
|
|
450
|
+
? `
|
|
451
|
+
<div class="field">
|
|
452
|
+
<label>Scope ID</label>
|
|
453
|
+
<div class="value">${data.proof.meta.scopeId}</div>
|
|
454
|
+
</div>
|
|
455
|
+
`
|
|
456
|
+
: ""}
|
|
457
|
+
${data.proof.meta.delegationRef
|
|
458
|
+
? `
|
|
459
|
+
<div class="field">
|
|
460
|
+
<label>Delegation Ref</label>
|
|
461
|
+
<div class="value">${data.proof.meta.delegationRef}</div>
|
|
462
|
+
</div>
|
|
463
|
+
`
|
|
464
|
+
: ""}
|
|
465
|
+
</div>
|
|
466
|
+
|
|
467
|
+
<div class="card">
|
|
468
|
+
<h3>Canonical Hashes</h3>
|
|
469
|
+
<div class="field">
|
|
470
|
+
<label>Request Hash</label>
|
|
471
|
+
<div class="value">${data.proof.canonicalHashes.requestHash}</div>
|
|
472
|
+
</div>
|
|
473
|
+
<div class="field">
|
|
474
|
+
<label>Response Hash</label>
|
|
475
|
+
<div class="value">${data.proof.canonicalHashes.responseHash}</div>
|
|
476
|
+
</div>
|
|
477
|
+
</div>
|
|
478
|
+
</div>
|
|
479
|
+
|
|
480
|
+
<div class="card" style="margin-top: 20px;">
|
|
481
|
+
<h3>Detached JWS</h3>
|
|
482
|
+
<div class="code-block">${data.proof.jws}</div>
|
|
483
|
+
</div>
|
|
484
|
+
</div>
|
|
485
|
+
`
|
|
486
|
+
: `
|
|
487
|
+
<div class="section">
|
|
488
|
+
<h2>Latest Proof</h2>
|
|
489
|
+
<div class="card">
|
|
490
|
+
<p style="color: #6b7280; font-style: italic;">
|
|
491
|
+
No proof data available. Make a tool call to see proof verification details.
|
|
492
|
+
</p>
|
|
493
|
+
</div>
|
|
494
|
+
</div>
|
|
495
|
+
`}
|
|
496
|
+
|
|
497
|
+
${data.verification
|
|
498
|
+
? `
|
|
499
|
+
<div class="section">
|
|
500
|
+
<h2>Local Verification Result</h2>
|
|
501
|
+
<div class="grid">
|
|
502
|
+
<div class="card">
|
|
503
|
+
<h3>Overall Status</h3>
|
|
504
|
+
<div class="field">
|
|
505
|
+
<label>Verification</label>
|
|
506
|
+
<div class="value">
|
|
507
|
+
<span class="status ${data.verification.success ? "success" : "error"}">
|
|
508
|
+
${data.verification.success ? "VALID" : "INVALID"}
|
|
509
|
+
</span>
|
|
510
|
+
</div>
|
|
511
|
+
</div>
|
|
512
|
+
${data.verification.errors?.length
|
|
513
|
+
? `
|
|
514
|
+
<div class="field">
|
|
515
|
+
<label>Errors</label>
|
|
516
|
+
<div class="value" style="color: #dc2626;">
|
|
517
|
+
${data.verification.errors.join("; ")}
|
|
518
|
+
</div>
|
|
519
|
+
</div>
|
|
520
|
+
`
|
|
521
|
+
: ""}
|
|
522
|
+
</div>
|
|
523
|
+
|
|
524
|
+
<div class="card">
|
|
525
|
+
<h3>Signature Check</h3>
|
|
526
|
+
<div class="field">
|
|
527
|
+
<label>Valid</label>
|
|
528
|
+
<div class="value">
|
|
529
|
+
<span class="status ${data.verification.signature.valid
|
|
530
|
+
? "success"
|
|
531
|
+
: "error"}">
|
|
532
|
+
${data.verification.signature.valid
|
|
533
|
+
? "VALID"
|
|
534
|
+
: "INVALID"}
|
|
535
|
+
</span>
|
|
536
|
+
</div>
|
|
537
|
+
</div>
|
|
538
|
+
<div class="field">
|
|
539
|
+
<label>Algorithm</label>
|
|
540
|
+
<div class="value">${data.verification.signature.algorithm}</div>
|
|
541
|
+
</div>
|
|
542
|
+
</div>
|
|
543
|
+
|
|
544
|
+
<div class="card">
|
|
545
|
+
<h3>Timestamp Check</h3>
|
|
546
|
+
<div class="field">
|
|
547
|
+
<label>Valid</label>
|
|
548
|
+
<div class="value">
|
|
549
|
+
<span class="status ${data.verification.proof.timestamp.valid
|
|
550
|
+
? "success"
|
|
551
|
+
: "error"}">
|
|
552
|
+
${data.verification.proof.timestamp.valid
|
|
553
|
+
? "VALID"
|
|
554
|
+
: "INVALID"}
|
|
555
|
+
</span>
|
|
556
|
+
</div>
|
|
557
|
+
</div>
|
|
558
|
+
<div class="field">
|
|
559
|
+
<label>Clock Skew</label>
|
|
560
|
+
<div class="value">${data.verification.proof.timestamp.skew}s</div>
|
|
561
|
+
</div>
|
|
562
|
+
${data.verification.proof.timestamp.remediation
|
|
563
|
+
? `
|
|
564
|
+
<div class="field">
|
|
565
|
+
<label>Remediation</label>
|
|
566
|
+
<div class="value" style="color: #d97706;">
|
|
567
|
+
${data.verification.proof.timestamp.remediation}
|
|
568
|
+
</div>
|
|
569
|
+
</div>
|
|
570
|
+
`
|
|
571
|
+
: ""}
|
|
572
|
+
</div>
|
|
573
|
+
|
|
574
|
+
<div class="card">
|
|
575
|
+
<h3>Session Check</h3>
|
|
576
|
+
<div class="field">
|
|
577
|
+
<label>Valid</label>
|
|
578
|
+
<div class="value">
|
|
579
|
+
<span class="status ${data.verification.session.valid
|
|
580
|
+
? "success"
|
|
581
|
+
: "error"}">
|
|
582
|
+
${data.verification.session.valid
|
|
583
|
+
? "VALID"
|
|
584
|
+
: "INVALID"}
|
|
585
|
+
</span>
|
|
586
|
+
</div>
|
|
587
|
+
</div>
|
|
588
|
+
<div class="field">
|
|
589
|
+
<label>TTL Remaining</label>
|
|
590
|
+
<div class="value">${Math.max(0, data.verification.session.ttl)}s</div>
|
|
591
|
+
</div>
|
|
592
|
+
</div>
|
|
593
|
+
</div>
|
|
594
|
+
</div>
|
|
595
|
+
`
|
|
596
|
+
: ""}
|
|
597
|
+
|
|
598
|
+
<div class="timestamp">
|
|
599
|
+
Generated at ${new Date(data.timestamp).toISOString()} • Environment: ${data.environment}
|
|
600
|
+
</div>
|
|
601
|
+
</div>
|
|
602
|
+
</body>
|
|
603
|
+
</html>`;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
exports.DebugManager = DebugManager;
|
|
607
|
+
/**
|
|
608
|
+
* Create debug endpoint handler for development
|
|
609
|
+
*/
|
|
610
|
+
function createDebugEndpoint(identity, environment = "development") {
|
|
611
|
+
return new DebugManager(identity, environment);
|
|
612
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { ProofMeta } from "@kya-os/contracts/proof";
|
|
2
|
+
import { DelegationManager } from "../storage/delegation";
|
|
3
|
+
/**
|
|
4
|
+
* Runtime hooks for delegation support
|
|
5
|
+
*/
|
|
6
|
+
export interface DelegationHooks {
|
|
7
|
+
/**
|
|
8
|
+
* Called before proof generation to attach delegation context
|
|
9
|
+
*/
|
|
10
|
+
beforeProof?: (meta: Partial<ProofMeta>) => Promise<Partial<ProofMeta>>;
|
|
11
|
+
/**
|
|
12
|
+
* Called after proof generation to validate delegation
|
|
13
|
+
*/
|
|
14
|
+
afterProof?: (meta: ProofMeta) => Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Called to resolve delegation reference for a request
|
|
17
|
+
*/
|
|
18
|
+
resolveDelegation?: (context: RequestContext) => Promise<string | undefined>;
|
|
19
|
+
}
|
|
20
|
+
export interface RequestContext {
|
|
21
|
+
audience: string;
|
|
22
|
+
scopes?: string[];
|
|
23
|
+
sessionId: string;
|
|
24
|
+
did: string;
|
|
25
|
+
kid: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Default delegation hooks implementation
|
|
29
|
+
*/
|
|
30
|
+
export declare class DefaultDelegationHooks implements DelegationHooks {
|
|
31
|
+
private delegationManager;
|
|
32
|
+
private options;
|
|
33
|
+
constructor(delegationManager: DelegationManager, options?: DelegationHookOptions);
|
|
34
|
+
beforeProof(meta: Partial<ProofMeta>): Promise<Partial<ProofMeta>>;
|
|
35
|
+
afterProof(meta: ProofMeta): Promise<void>;
|
|
36
|
+
resolveDelegation(_context: RequestContext): Promise<string | undefined>;
|
|
37
|
+
}
|
|
38
|
+
export interface DelegationHookOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Automatically resolve delegation references for requests
|
|
41
|
+
*/
|
|
42
|
+
autoResolveDelegation?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Require delegation for all requests
|
|
45
|
+
*/
|
|
46
|
+
requireDelegation?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Default delegation duration in seconds
|
|
49
|
+
*/
|
|
50
|
+
defaultDuration?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create delegation hooks instance
|
|
54
|
+
*/
|
|
55
|
+
export declare function createDelegationHooks(delegationManager: DelegationManager, options?: DelegationHookOptions): DelegationHooks;
|
|
56
|
+
/**
|
|
57
|
+
* Delegation middleware for runtime integration
|
|
58
|
+
*/
|
|
59
|
+
export declare class DelegationMiddleware {
|
|
60
|
+
private hooks;
|
|
61
|
+
private options;
|
|
62
|
+
constructor(hooks: DelegationHooks, options?: DelegationMiddlewareOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Process request and attach delegation context
|
|
65
|
+
*/
|
|
66
|
+
processRequest(meta: Partial<ProofMeta>, context: RequestContext): Promise<Partial<ProofMeta>>;
|
|
67
|
+
/**
|
|
68
|
+
* Validate proof after generation
|
|
69
|
+
*/
|
|
70
|
+
validateProof(meta: ProofMeta): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
export interface DelegationMiddlewareOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Require delegation for all requests
|
|
75
|
+
*/
|
|
76
|
+
requireDelegation?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Skip delegation validation in test mode
|
|
79
|
+
*/
|
|
80
|
+
skipValidationInTest?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create delegation middleware instance
|
|
84
|
+
*/
|
|
85
|
+
export declare function createDelegationMiddleware(hooks: DelegationHooks, options?: DelegationMiddlewareOptions): DelegationMiddleware;
|