@kya-os/mcp-i-core 1.7.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +1 -1
  2. package/dist/conformance/capability-verifier-adapter.d.ts +66 -0
  3. package/dist/conformance/capability-verifier-adapter.js +61 -0
  4. package/dist/conformance/index.d.ts +10 -0
  5. package/dist/conformance/index.js +19 -0
  6. package/dist/conformance/validate-level2.d.ts +203 -0
  7. package/dist/conformance/validate-level2.js +294 -0
  8. package/dist/conformance/vc-jwt-verifier.d.ts +55 -0
  9. package/dist/conformance/vc-jwt-verifier.js +147 -0
  10. package/dist/delegation/did-web-resolver.d.ts +60 -0
  11. package/dist/delegation/did-web-resolver.js +129 -0
  12. package/dist/delegation/outbound-proof.d.ts +3 -2
  13. package/dist/delegation/outbound-proof.js +3 -2
  14. package/dist/delegation/utils.d.ts +3 -1
  15. package/dist/index.d.ts +9 -63
  16. package/dist/index.js +22 -161
  17. package/dist/utils/base58.d.ts +4 -28
  18. package/dist/utils/base58.js +18 -98
  19. package/dist/utils/base64.d.ts +4 -29
  20. package/dist/utils/base64.js +18 -167
  21. package/dist/utils/did-helpers.d.ts +4 -165
  22. package/dist/utils/did-helpers.js +18 -217
  23. package/package.json +5 -7
  24. package/dist/auth/handshake.d.ts +0 -119
  25. package/dist/auth/handshake.js +0 -250
  26. package/dist/auth/index.d.ts +0 -6
  27. package/dist/auth/index.js +0 -11
  28. package/dist/auth/types.d.ts +0 -46
  29. package/dist/auth/types.js +0 -10
  30. package/dist/cache/oauth-config-cache.d.ts +0 -69
  31. package/dist/cache/oauth-config-cache.js +0 -76
  32. package/dist/cache/tool-protection-cache.d.ts +0 -89
  33. package/dist/cache/tool-protection-cache.js +0 -118
  34. package/dist/compliance/index.d.ts +0 -8
  35. package/dist/compliance/index.js +0 -24
  36. package/dist/compliance/schema-registry.d.ts +0 -50
  37. package/dist/compliance/schema-registry.js +0 -438
  38. package/dist/compliance/schema-verifier.d.ts +0 -110
  39. package/dist/compliance/schema-verifier.js +0 -518
  40. package/dist/config/remote-config.d.ts +0 -173
  41. package/dist/config/remote-config.js +0 -253
  42. package/dist/config.d.ts +0 -182
  43. package/dist/config.js +0 -148
  44. package/dist/identity/idp-token-resolver.d.ts +0 -69
  45. package/dist/identity/idp-token-resolver.js +0 -136
  46. package/dist/identity/idp-token-storage.interface.d.ts +0 -80
  47. package/dist/identity/idp-token-storage.interface.js +0 -14
  48. package/dist/identity/user-did-manager.d.ts +0 -228
  49. package/dist/identity/user-did-manager.js +0 -356
  50. package/dist/logging/index.d.ts +0 -5
  51. package/dist/logging/index.js +0 -10
  52. package/dist/logging/logger.d.ts +0 -33
  53. package/dist/logging/logger.js +0 -104
  54. package/dist/proof/generator.d.ts +0 -109
  55. package/dist/proof/generator.js +0 -236
  56. package/dist/proof/index.d.ts +0 -5
  57. package/dist/proof/index.js +0 -11
  58. package/dist/providers/base.d.ts +0 -95
  59. package/dist/providers/base.js +0 -47
  60. package/dist/providers/memory.d.ts +0 -42
  61. package/dist/providers/memory.js +0 -121
  62. package/dist/runtime/audit-logger.d.ts +0 -37
  63. package/dist/runtime/audit-logger.js +0 -9
  64. package/dist/runtime/base.d.ts +0 -375
  65. package/dist/runtime/base.js +0 -1491
  66. package/dist/runtime/ext-apps-constants.d.ts +0 -14
  67. package/dist/runtime/ext-apps-constants.js +0 -17
  68. package/dist/services/access-control.service.d.ts +0 -138
  69. package/dist/services/access-control.service.js +0 -721
  70. package/dist/services/authorization/authorization-registry.d.ts +0 -29
  71. package/dist/services/authorization/authorization-registry.js +0 -58
  72. package/dist/services/authorization/types.d.ts +0 -53
  73. package/dist/services/authorization/types.js +0 -10
  74. package/dist/services/batch-delegation.service.d.ts +0 -53
  75. package/dist/services/batch-delegation.service.js +0 -95
  76. package/dist/services/crypto.service.d.ts +0 -69
  77. package/dist/services/crypto.service.js +0 -225
  78. package/dist/services/delegation-error-formatter.d.ts +0 -124
  79. package/dist/services/delegation-error-formatter.js +0 -214
  80. package/dist/services/errors.d.ts +0 -49
  81. package/dist/services/errors.js +0 -66
  82. package/dist/services/index.d.ts +0 -9
  83. package/dist/services/index.js +0 -15
  84. package/dist/services/oauth-config.service.d.ts +0 -53
  85. package/dist/services/oauth-config.service.js +0 -141
  86. package/dist/services/oauth-provider-registry.d.ts +0 -88
  87. package/dist/services/oauth-provider-registry.js +0 -128
  88. package/dist/services/oauth-service.d.ts +0 -122
  89. package/dist/services/oauth-service.js +0 -442
  90. package/dist/services/oauth-token-retrieval.service.d.ts +0 -49
  91. package/dist/services/oauth-token-retrieval.service.js +0 -150
  92. package/dist/services/policy.service.d.ts +0 -130
  93. package/dist/services/policy.service.js +0 -399
  94. package/dist/services/proof-verifier.d.ts +0 -98
  95. package/dist/services/proof-verifier.js +0 -319
  96. package/dist/services/provider-resolver.d.ts +0 -89
  97. package/dist/services/provider-resolver.js +0 -196
  98. package/dist/services/provider-validator.d.ts +0 -55
  99. package/dist/services/provider-validator.js +0 -135
  100. package/dist/services/session-registration.service.d.ts +0 -80
  101. package/dist/services/session-registration.service.js +0 -174
  102. package/dist/services/storage.service.d.ts +0 -116
  103. package/dist/services/storage.service.js +0 -411
  104. package/dist/services/tool-context-builder.d.ts +0 -74
  105. package/dist/services/tool-context-builder.js +0 -215
  106. package/dist/services/tool-protection.service.d.ts +0 -193
  107. package/dist/services/tool-protection.service.js +0 -736
  108. package/dist/session/index.d.ts +0 -5
  109. package/dist/session/index.js +0 -11
  110. package/dist/session/manager.d.ts +0 -113
  111. package/dist/session/manager.js +0 -273
  112. package/dist/types/oauth-required-error.d.ts +0 -46
  113. package/dist/types/oauth-required-error.js +0 -42
  114. package/dist/types/tool-protection.d.ts +0 -144
  115. package/dist/types/tool-protection.js +0 -48
  116. package/dist/utils/cors.d.ts +0 -44
  117. package/dist/utils/cors.js +0 -71
  118. package/dist/utils/index.d.ts +0 -8
  119. package/dist/utils/index.js +0 -24
  120. package/dist/utils/storage-keys.d.ts +0 -120
  121. package/dist/utils/storage-keys.js +0 -217
@@ -1,356 +0,0 @@
1
- "use strict";
2
- /**
3
- * User DID Manager
4
- *
5
- * Manages user DIDs for MCP-I sessions.
6
- *
7
- * Phase 5: Anonymous Sessions Until OAuth
8
- * - Sessions start anonymous (no userDid) until OAuth completes
9
- * - User DIDs are resolved via AgentShield identity/resolve after OAuth
10
- * - Eliminates DID fragmentation (same user = same DID across sessions)
11
- *
12
- * DID Resolution Priority:
13
- * 1. OAuth mapping lookup (persistent)
14
- * 2. Session storage lookup
15
- * 3. Return null (session stays anonymous)
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.UserDidManager = void 0;
19
- const did_helpers_1 = require("../utils/did-helpers");
20
- /**
21
- * User DID Manager
22
- *
23
- * Generates and manages user DIDs for MCP-I sessions.
24
- * Supports both ephemeral (did:key) and persistent (did:web) formats.
25
- */
26
- class UserDidManager {
27
- config;
28
- sessionDidCache = new Map();
29
- sessionKeyPairCache = new Map();
30
- constructor(config) {
31
- this.config = config;
32
- }
33
- /**
34
- * Get key pair for a session (for VC signing)
35
- *
36
- * Returns the key pair if available, null otherwise.
37
- * Key pairs are stored when DIDs are generated.
38
- *
39
- * @param sessionId - MCP session ID
40
- * @param oauthIdentity - Optional OAuth identity for persistent lookup
41
- * @returns UserKeyPair or null if not available
42
- */
43
- async getKeyPairForSession(sessionId, oauthIdentity) {
44
- // Check in-memory cache first
45
- if (this.sessionKeyPairCache.has(sessionId)) {
46
- return this.sessionKeyPairCache.get(sessionId);
47
- }
48
- // Check OAuth-based persistent storage if available
49
- if (oauthIdentity?.provider &&
50
- oauthIdentity?.subject &&
51
- this.config.storage?.getKeyPairByOAuth) {
52
- try {
53
- const keyPair = await this.config.storage.getKeyPairByOAuth(oauthIdentity.provider, oauthIdentity.subject);
54
- if (keyPair) {
55
- this.sessionKeyPairCache.set(sessionId, keyPair);
56
- return keyPair;
57
- }
58
- }
59
- catch (error) {
60
- console.warn("[UserDidManager] OAuth key pair lookup failed:", error);
61
- }
62
- }
63
- // Check session storage if available
64
- if (this.config.storage?.getKeyPair) {
65
- try {
66
- const keyPair = await this.config.storage.getKeyPair(sessionId);
67
- if (keyPair) {
68
- this.sessionKeyPairCache.set(sessionId, keyPair);
69
- return keyPair;
70
- }
71
- }
72
- catch (error) {
73
- console.warn("[UserDidManager] Session key pair lookup failed:", error);
74
- }
75
- }
76
- return null;
77
- }
78
- /**
79
- * Get user DID for a session (Phase 5: No ephemeral generation)
80
- *
81
- * If a user DID already exists for the session, it is returned.
82
- * If OAuth identity is provided, checks for persistent user DID mapping.
83
- * Returns null if no DID found - session stays anonymous until OAuth completes.
84
- *
85
- * @param sessionId - MCP session ID
86
- * @param oauthIdentity - Optional OAuth identity for persistent user DID lookup
87
- * @returns User DID (did:key format) or null if session is anonymous
88
- *
89
- * @remarks
90
- * - Phase 5: Sessions start anonymous, no ephemeral DID generation
91
- * - User DIDs are resolved via AgentShield after OAuth completes
92
- * - Returns null if no existing DID found (instead of generating ephemeral)
93
- */
94
- async getOrCreateUserDid(sessionId, oauthIdentity) {
95
- // Check cache first
96
- if (this.sessionDidCache.has(sessionId)) {
97
- return this.sessionDidCache.get(sessionId);
98
- }
99
- // PRIORITY 1: If OAuth identity provided, check for persistent user DID mapping
100
- if (oauthIdentity &&
101
- oauthIdentity.provider &&
102
- oauthIdentity.subject &&
103
- this.config.storage?.getByOAuth) {
104
- try {
105
- const persistentUserDid = await this.config.storage.getByOAuth(oauthIdentity.provider, oauthIdentity.subject);
106
- if (persistentUserDid) {
107
- console.error("[UserDidManager] Found persistent user DID from OAuth mapping:", {
108
- provider: oauthIdentity.provider,
109
- userDid: persistentUserDid.substring(0, 20) + "...",
110
- });
111
- // Cache it for this session
112
- this.sessionDidCache.set(sessionId, persistentUserDid);
113
- // Also store in session storage for faster future lookups
114
- if (this.config.storage) {
115
- try {
116
- await this.config.storage.set(sessionId, persistentUserDid, 1800); // 30 minutes TTL
117
- }
118
- catch (error) {
119
- // Log but continue - DID is cached and will be returned
120
- console.warn("[UserDidManager] Failed to cache persistent DID in session storage:", error);
121
- }
122
- }
123
- return persistentUserDid;
124
- }
125
- }
126
- catch (error) {
127
- // Log but continue - will check session storage or generate new DID
128
- console.warn("[UserDidManager] OAuth lookup failed, falling back to session storage:", error);
129
- }
130
- }
131
- // PRIORITY 2: Check session storage if available
132
- if (this.config.storage) {
133
- try {
134
- const storedDid = await this.config.storage.get(sessionId);
135
- if (storedDid) {
136
- this.sessionDidCache.set(sessionId, storedDid);
137
- // If OAuth identity provided but no persistent mapping found, create one now
138
- if (oauthIdentity &&
139
- oauthIdentity.provider &&
140
- oauthIdentity.subject &&
141
- this.config.storage.setByOAuth) {
142
- try {
143
- await this.config.storage.setByOAuth(oauthIdentity.provider, oauthIdentity.subject, storedDid, 90 * 24 * 60 * 60 // 90 days TTL for persistent mapping
144
- );
145
- console.error("[UserDidManager] Created persistent OAuth mapping for existing user DID:", {
146
- provider: oauthIdentity.provider,
147
- userDid: storedDid.substring(0, 20) + "...",
148
- });
149
- }
150
- catch (error) {
151
- // Log but continue - mapping creation failed, but DID is still valid
152
- console.warn("[UserDidManager] Failed to create OAuth mapping:", error);
153
- }
154
- }
155
- return storedDid;
156
- }
157
- }
158
- catch (error) {
159
- // Log but continue - session will be anonymous
160
- console.warn("[UserDidManager] Storage.get failed:", error);
161
- }
162
- }
163
- // PHASE 5: No ephemeral DID generation - session stays anonymous
164
- // User DID will be resolved via AgentShield after OAuth completes
165
- return null;
166
- }
167
- /**
168
- * Set user DID for a session (Phase 5: After OAuth resolution)
169
- *
170
- * Called after AgentShield identity/resolve returns a persistent user DID.
171
- * Caches the DID and optionally stores in session storage.
172
- *
173
- * @param sessionId - MCP session ID
174
- * @param userDid - Persistent user DID from AgentShield
175
- * @param oauthIdentity - OAuth identity for creating persistent mappings
176
- */
177
- async setUserDidForSession(sessionId, userDid, oauthIdentity) {
178
- // Cache in memory
179
- this.sessionDidCache.set(sessionId, userDid);
180
- // Store in session storage if available
181
- if (this.config.storage) {
182
- try {
183
- await this.config.storage.set(sessionId, userDid, 1800); // 30 minutes TTL
184
- }
185
- catch (error) {
186
- console.warn("[UserDidManager] Failed to store user DID in session storage:", error);
187
- }
188
- }
189
- // Create OAuth mapping if provided
190
- if (oauthIdentity?.provider &&
191
- oauthIdentity?.subject &&
192
- this.config.storage?.setByOAuth) {
193
- try {
194
- await this.config.storage.setByOAuth(oauthIdentity.provider, oauthIdentity.subject, userDid, 90 * 24 * 60 * 60 // 90 days TTL for persistent mapping
195
- );
196
- console.error("[UserDidManager] Created OAuth → DID mapping:", {
197
- provider: oauthIdentity.provider,
198
- userDid: userDid.substring(0, 20) + "...",
199
- });
200
- }
201
- catch (error) {
202
- console.warn("[UserDidManager] Failed to create OAuth mapping:", error);
203
- }
204
- }
205
- }
206
- /**
207
- * Generate a new ephemeral user DID
208
- *
209
- * Uses did:key format by default for simplicity.
210
- * did:web can be used if configured, but requires additional setup.
211
- */
212
- async generateUserDid() {
213
- const keyPairData = await this.generateUserDidWithKeyPair();
214
- return keyPairData.did;
215
- }
216
- /**
217
- * Generate a new ephemeral user DID with full key pair
218
- *
219
- * Returns the DID along with the key pair for VC signing.
220
- * Uses did:key format by default.
221
- *
222
- * @returns UserKeyPair containing DID, public key, private key, and key ID
223
- */
224
- async generateUserDidWithKeyPair() {
225
- if (this.config.useDidWeb && this.config.didWebBaseUrl) {
226
- // did:web generation requires a web server to host the DID document.
227
- // Currently falls back to did:key which is self-resolving.
228
- // TODO(feature): Implement did:web generation when required for production use cases.
229
- // This would involve generating the DID document and coordinating with
230
- // the hosting infrastructure to serve it at the well-known URL.
231
- console.warn("[UserDidManager] did:web not yet implemented, using did:key");
232
- }
233
- // Generate Ed25519 keypair for user DID
234
- const keyPair = await this.config.crypto.generateKeyPair();
235
- // Extract public key bytes (32 bytes for Ed25519)
236
- const publicKeyBytes = this.base64ToBytes(keyPair.publicKey);
237
- // Generate did:key from public key
238
- const did = this.generateDidKeyFromPublicKey(publicKeyBytes);
239
- // Key ID uses spec-compliant fragment (multibase value for did:key)
240
- const keyId = `${did}#${(0, did_helpers_1.didKeyFragment)(did)}`;
241
- return {
242
- did,
243
- publicKey: keyPair.publicKey,
244
- privateKey: keyPair.privateKey,
245
- keyId,
246
- };
247
- }
248
- /**
249
- * Generate did:key from Ed25519 public key bytes
250
- * Following spec: https://w3c-ccg.github.io/did-method-key/
251
- *
252
- * Format: did:key:z<multibase-base58btc(<multicodec-ed25519-pub><publicKey>)>
253
- */
254
- generateDidKeyFromPublicKey(publicKeyBytes) {
255
- // Ed25519 multicodec prefix (0xed 0x01)
256
- const multicodecPrefix = new Uint8Array([0xed, 0x01]);
257
- // Combine prefix + public key
258
- const multicodecKey = new Uint8Array(multicodecPrefix.length + publicKeyBytes.length);
259
- multicodecKey.set(multicodecPrefix);
260
- multicodecKey.set(publicKeyBytes, multicodecPrefix.length);
261
- // Base58 encode (using a simple implementation)
262
- // Note: For production, consider using base-x library
263
- const base58Encoded = this.base58Encode(multicodecKey);
264
- // Add multibase prefix 'z' for base58-btc
265
- return `did:key:z${base58Encoded}`;
266
- }
267
- /**
268
- * Base58 encode (Bitcoin alphabet)
269
- * Simple implementation for did:key generation
270
- */
271
- base58Encode(bytes) {
272
- const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
273
- let num = BigInt(0);
274
- // Convert bytes to big integer
275
- for (let i = 0; i < bytes.length; i++) {
276
- num = num * BigInt(256) + BigInt(bytes[i]);
277
- }
278
- // Convert to base58
279
- let result = "";
280
- while (num > 0) {
281
- result = alphabet[Number(num % BigInt(58))] + result;
282
- num = num / BigInt(58);
283
- }
284
- // Add leading zeros
285
- for (let i = 0; i < bytes.length && bytes[i] === 0; i++) {
286
- result = "1" + result;
287
- }
288
- return result;
289
- }
290
- /**
291
- * Convert base64 or base64url string to Uint8Array
292
- * Handles both standard base64 (+/) and base64url (-_) formats
293
- */
294
- base64ToBytes(base64) {
295
- // Convert base64url to standard base64 if needed
296
- // Base64url uses - instead of + and _ instead of /
297
- let standardBase64 = base64.replace(/-/g, "+").replace(/_/g, "/");
298
- // Add padding if needed (base64url often omits padding)
299
- const paddingNeeded = (4 - (standardBase64.length % 4)) % 4;
300
- standardBase64 += "=".repeat(paddingNeeded);
301
- if (typeof Buffer !== "undefined") {
302
- // Node.js environment
303
- return new Uint8Array(Buffer.from(standardBase64, "base64"));
304
- }
305
- else {
306
- // Browser/Workers environment
307
- const binaryString = atob(standardBase64);
308
- const bytes = new Uint8Array(binaryString.length);
309
- for (let i = 0; i < binaryString.length; i++) {
310
- bytes[i] = binaryString.charCodeAt(i);
311
- }
312
- return bytes;
313
- }
314
- }
315
- /**
316
- * Get user DID for a session without creating one
317
- */
318
- async getUserDid(sessionId) {
319
- // Check cache
320
- if (this.sessionDidCache.has(sessionId)) {
321
- return this.sessionDidCache.get(sessionId);
322
- }
323
- // Check storage
324
- if (this.config.storage) {
325
- const storedDid = await this.config.storage.get(sessionId);
326
- if (storedDid) {
327
- this.sessionDidCache.set(sessionId, storedDid);
328
- return storedDid;
329
- }
330
- }
331
- return null;
332
- }
333
- /**
334
- * Clear user DID for a session
335
- */
336
- async clearUserDid(sessionId) {
337
- this.sessionDidCache.delete(sessionId);
338
- if (this.config.storage) {
339
- try {
340
- await this.config.storage.delete(sessionId);
341
- }
342
- catch (error) {
343
- // Log but continue - cache is already cleared
344
- console.warn("[UserDidManager] Storage.delete failed, continuing:", error);
345
- }
346
- }
347
- }
348
- /**
349
- * Clear all cached user DIDs (useful for testing)
350
- */
351
- clearCache() {
352
- this.sessionDidCache.clear();
353
- }
354
- }
355
- exports.UserDidManager = UserDidManager;
356
- //# sourceMappingURL=user-did-manager.js.map
@@ -1,5 +0,0 @@
1
- /**
2
- * Logging module exports
3
- */
4
- export { logger, createDefaultConsoleLogger, type Logger, type Level, } from "./logger";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1,10 +0,0 @@
1
- "use strict";
2
- /**
3
- * Logging module exports
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createDefaultConsoleLogger = exports.logger = void 0;
7
- var logger_1 = require("./logger");
8
- Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
9
- Object.defineProperty(exports, "createDefaultConsoleLogger", { enumerable: true, get: function () { return logger_1.createDefaultConsoleLogger; } });
10
- //# sourceMappingURL=index.js.map
@@ -1,33 +0,0 @@
1
- /**
2
- * Transport-aware Logger for MCP-I
3
- *
4
- * Provides a lightweight, dependency-free logging interface that:
5
- * - Maps log levels correctly for Cloudflare Workers (so wrangler tail shows correct severities)
6
- * - Routes all logs to stderr for stdio transport (so stdout remains protocol-only)
7
- * - Supports runtime configuration of log level and transport mode
8
- */
9
- export type Level = "debug" | "info" | "warn" | "error";
10
- export interface Logger {
11
- configure: (opts?: {
12
- level?: Level;
13
- transport?: string;
14
- forceStderr?: boolean;
15
- }) => void;
16
- debug: (...args: any[]) => void;
17
- info: (...args: any[]) => void;
18
- warn: (...args: any[]) => void;
19
- error: (...args: any[]) => void;
20
- }
21
- /**
22
- * Create a default console logger with transport-aware behavior
23
- *
24
- * - Cloudflare Workers: Maps levels to console.debug/info/warn/error
25
- * - stdio transport: Routes all levels to console.error (stderr) to keep stdout protocol-only
26
- */
27
- export declare function createDefaultConsoleLogger(): Logger;
28
- /**
29
- * Default singleton logger instance
30
- * Configure via logger.configure() before use
31
- */
32
- export declare const logger: Logger;
33
- //# sourceMappingURL=logger.d.ts.map
@@ -1,104 +0,0 @@
1
- "use strict";
2
- /**
3
- * Transport-aware Logger for MCP-I
4
- *
5
- * Provides a lightweight, dependency-free logging interface that:
6
- * - Maps log levels correctly for Cloudflare Workers (so wrangler tail shows correct severities)
7
- * - Routes all logs to stderr for stdio transport (so stdout remains protocol-only)
8
- * - Supports runtime configuration of log level and transport mode
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.logger = void 0;
12
- exports.createDefaultConsoleLogger = createDefaultConsoleLogger;
13
- const SEVERITY = {
14
- debug: 10,
15
- info: 20,
16
- warn: 30,
17
- error: 40,
18
- };
19
- /**
20
- * Create a default console logger with transport-aware behavior
21
- *
22
- * - Cloudflare Workers: Maps levels to console.debug/info/warn/error
23
- * - stdio transport: Routes all levels to console.error (stderr) to keep stdout protocol-only
24
- */
25
- function createDefaultConsoleLogger() {
26
- let level = "info";
27
- let forceStderr = false;
28
- function shouldLog(l) {
29
- return SEVERITY[l] >= SEVERITY[level];
30
- }
31
- function write(l, ...args) {
32
- if (!shouldLog(l))
33
- return;
34
- if (forceStderr) {
35
- // stdio transport: all logs go to stderr (console.error)
36
- // This ensures stdout remains protocol-only
37
- console.error(...args);
38
- return;
39
- }
40
- // Cloudflare Workers: map to appropriate console method
41
- switch (l) {
42
- case "debug":
43
- if (typeof console.debug === "function") {
44
- console.debug(...args);
45
- }
46
- else {
47
- console.log(...args);
48
- }
49
- break;
50
- case "info":
51
- if (typeof console.info === "function") {
52
- console.info(...args);
53
- }
54
- else {
55
- console.log(...args);
56
- }
57
- break;
58
- case "warn":
59
- if (typeof console.warn === "function") {
60
- console.warn(...args);
61
- }
62
- else {
63
- console.error(...args);
64
- }
65
- break;
66
- case "error":
67
- console.error(...args);
68
- break;
69
- }
70
- }
71
- return {
72
- configure(opts = {}) {
73
- if (opts.level)
74
- level = opts.level;
75
- // Handle transport-based stderr routing
76
- // - stdio transport: force all logs to stderr (stdout is protocol-only)
77
- // - sse/http transports: use normal console routing
78
- // - explicit forceStderr overrides transport-based behavior
79
- if (opts.forceStderr === true) {
80
- forceStderr = true;
81
- }
82
- else if (opts.forceStderr === false) {
83
- forceStderr = false;
84
- }
85
- else if (opts.transport === "stdio") {
86
- forceStderr = true;
87
- }
88
- else if (opts.transport === "sse" || opts.transport === "http") {
89
- // Reset to normal console routing for non-stdio transports
90
- forceStderr = false;
91
- }
92
- },
93
- debug: (...a) => write("debug", ...a),
94
- info: (...a) => write("info", ...a),
95
- warn: (...a) => write("warn", ...a),
96
- error: (...a) => write("error", ...a),
97
- };
98
- }
99
- /**
100
- * Default singleton logger instance
101
- * Configure via logger.configure() before use
102
- */
103
- exports.logger = createDefaultConsoleLogger();
104
- //# sourceMappingURL=logger.js.map
@@ -1,109 +0,0 @@
1
- /**
2
- * Proof Generation — Platform-agnostic Protocol Reference
3
- *
4
- * Handles JCS canonicalization, SHA-256 digest generation, and Ed25519 JWS
5
- * signing (compact format) according to MCP-I requirements 5.1, 5.2, 5.3, 5.6.
6
- *
7
- * This module is the authoritative proof implementation. All platform adapters
8
- * (Node.js, Cloudflare Workers) inject a CryptoProvider and delegate here.
9
- */
10
- import { DetachedProof } from "@kya-os/contracts/proof";
11
- import { SessionContext } from "@kya-os/contracts/handshake";
12
- import { CryptoProvider } from "../providers/base";
13
- /**
14
- * Minimal agent identity required by ProofGenerator.
15
- * Structurally compatible with both AgentIdentity definitions
16
- * in mcp-i-core (providers/base) and packages/mcp-i (runtime/identity).
17
- */
18
- export interface ProofAgentIdentity {
19
- did: string;
20
- kid: string;
21
- privateKey: string;
22
- publicKey: string;
23
- }
24
- /**
25
- * Tool request structure for proof generation
26
- */
27
- export interface ToolRequest {
28
- method: string;
29
- params?: unknown;
30
- }
31
- /**
32
- * Tool response structure for proof generation
33
- */
34
- export interface ToolResponse {
35
- data: unknown;
36
- meta?: {
37
- proof?: DetachedProof;
38
- [key: string]: unknown;
39
- };
40
- }
41
- /**
42
- * Proof generation options
43
- */
44
- export interface ProofOptions {
45
- scopeId?: string;
46
- delegationRef?: string;
47
- clientDid?: string;
48
- }
49
- /**
50
- * Platform-agnostic proof generator.
51
- * Requires a CryptoProvider for all cryptographic operations.
52
- */
53
- export declare class ProofGenerator {
54
- private identity;
55
- private cryptoProvider;
56
- constructor(identity: ProofAgentIdentity, cryptoProvider: CryptoProvider);
57
- /**
58
- * Generate proof for tool request/response.
59
- * Requirements: 5.1, 5.2, 5.3, 5.6
60
- */
61
- generateProof(request: ToolRequest, response: ToolResponse, session: SessionContext, options?: ProofOptions): Promise<DetachedProof>;
62
- /**
63
- * Generate canonical hashes for request and response.
64
- * Requirement: 5.1
65
- */
66
- private generateCanonicalHashes;
67
- /**
68
- * Generate SHA-256 hash with JCS canonicalization.
69
- * Requirement: 5.2
70
- *
71
- * Delegates to CryptoProvider.hash() which must return "sha256:<hex>".
72
- */
73
- private generateSHA256Hash;
74
- /**
75
- * JCS canonicalization implementation (RFC 8785)
76
- */
77
- private canonicalizeJSON;
78
- /**
79
- * Generate Ed25519 JWS in compact format (header.payload.signature).
80
- * Requirement: 5.3
81
- *
82
- * Uses standard JWT claims (aud, sub, iss) in addition to custom claims.
83
- */
84
- private generateJWS;
85
- /**
86
- * Format base64 private key as PKCS#8 PEM for JOSE library.
87
- */
88
- private formatPrivateKeyAsPEM;
89
- /**
90
- * Verify a proof (for testing/validation).
91
- */
92
- verifyProof(proof: DetachedProof, request: ToolRequest, response: ToolResponse): Promise<boolean>;
93
- /**
94
- * Convert base64 public key to Ed25519 JWK format.
95
- */
96
- private base64PublicKeyToJWK;
97
- }
98
- /**
99
- * Create a tool response with proof.
100
- */
101
- export declare function createProofResponse(request: ToolRequest, data: unknown, identity: ProofAgentIdentity, session: SessionContext, cryptoProvider: CryptoProvider, options?: ProofOptions): Promise<ToolResponse>;
102
- /**
103
- * Extract canonical data for hashing (utility for testing).
104
- */
105
- export declare function extractCanonicalData(request: ToolRequest, response: ToolResponse): {
106
- request: unknown;
107
- response: unknown;
108
- };
109
- //# sourceMappingURL=generator.d.ts.map