@kya-os/mcp-i 1.2.11 → 1.3.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.
@@ -4,7 +4,8 @@
4
4
  * Identity-aware MCP runtime with proof generation, session management,
5
5
  * audit logging, and well-known endpoints.
6
6
  */
7
- export { MCPIRuntime, createMCPIRuntime, RuntimeFactory, RUNTIME_ERRORS, type MCPIRuntimeConfig, type RuntimeEnvironment, } from "./mcpi-runtime";
7
+ export { MCPIRuntimeWrapper as MCPIRuntime, createMCPIRuntime } from "./mcpi-runtime-wrapper";
8
+ export { RuntimeFactory, RUNTIME_ERRORS, type MCPIRuntimeConfig, type RuntimeEnvironment, } from "./mcpi-runtime";
8
9
  export { IdentityManager, defaultIdentityManager, ensureIdentity, IDENTITY_ERRORS, type AgentIdentity, type DevIdentityFile, type ProdEnvironment, type IdentityConfig, } from "./identity";
9
10
  export { SessionManager, defaultSessionManager, createHandshakeRequest, validateHandshakeFormat, type SessionConfig, type HandshakeResult, } from "./session";
10
11
  export { ProofGenerator, createProofResponse, extractCanonicalData, type ToolRequest, type ToolResponse, type ProofOptions, } from "./proof";
@@ -7,10 +7,12 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.formatVerifyLink = exports.DemoConsole = exports.createDemoManager = exports.DemoManager = exports.createDebugEndpoint = exports.DebugManager = exports.extractDIDFromPath = exports.validateAgentDocument = exports.validateDIDDocument = exports.createWellKnownHandler = exports.WellKnownManager = exports.validateAuditRecord = exports.parseAuditLine = exports.logKeyRotationAudit = exports.defaultAuditLogger = exports.AuditLogger = exports.extractCanonicalData = exports.createProofResponse = exports.ProofGenerator = exports.validateHandshakeFormat = exports.createHandshakeRequest = exports.defaultSessionManager = exports.SessionManager = exports.IDENTITY_ERRORS = exports.ensureIdentity = exports.defaultIdentityManager = exports.IdentityManager = exports.RUNTIME_ERRORS = exports.RuntimeFactory = exports.createMCPIRuntime = exports.MCPIRuntime = void 0;
10
- // Main runtime
10
+ // Main runtime - now using core with Node.js providers
11
+ var mcpi_runtime_wrapper_1 = require("./mcpi-runtime-wrapper");
12
+ Object.defineProperty(exports, "MCPIRuntime", { enumerable: true, get: function () { return mcpi_runtime_wrapper_1.MCPIRuntimeWrapper; } });
13
+ Object.defineProperty(exports, "createMCPIRuntime", { enumerable: true, get: function () { return mcpi_runtime_wrapper_1.createMCPIRuntime; } });
14
+ // Legacy exports for compatibility
11
15
  var mcpi_runtime_1 = require("./mcpi-runtime");
12
- Object.defineProperty(exports, "MCPIRuntime", { enumerable: true, get: function () { return mcpi_runtime_1.MCPIRuntime; } });
13
- Object.defineProperty(exports, "createMCPIRuntime", { enumerable: true, get: function () { return mcpi_runtime_1.createMCPIRuntime; } });
14
16
  Object.defineProperty(exports, "RuntimeFactory", { enumerable: true, get: function () { return mcpi_runtime_1.RuntimeFactory; } });
15
17
  Object.defineProperty(exports, "RUNTIME_ERRORS", { enumerable: true, get: function () { return mcpi_runtime_1.RUNTIME_ERRORS; } });
16
18
  // Identity management
@@ -0,0 +1,19 @@
1
+ /**
2
+ * MCPIRuntime Wrapper
3
+ *
4
+ * Extends the core runtime with Node.js-specific providers while
5
+ * maintaining the exact same API for backward compatibility.
6
+ */
7
+ import { MCPIRuntimeBase } from '@kya-os/mcp-i-core';
8
+ import type { MCPIRuntimeConfig } from './mcpi-runtime';
9
+ /**
10
+ * Enhanced MCPIRuntime using the core with Node.js providers
11
+ */
12
+ export declare class MCPIRuntimeWrapper extends MCPIRuntimeBase {
13
+ private legacyConfig;
14
+ constructor(config?: MCPIRuntimeConfig);
15
+ }
16
+ /**
17
+ * Factory function for creating runtime
18
+ */
19
+ export declare function createMCPIRuntime(config?: MCPIRuntimeConfig): MCPIRuntimeWrapper;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * MCPIRuntime Wrapper
4
+ *
5
+ * Extends the core runtime with Node.js-specific providers while
6
+ * maintaining the exact same API for backward compatibility.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MCPIRuntimeWrapper = void 0;
13
+ exports.createMCPIRuntime = createMCPIRuntime;
14
+ const mcp_i_core_1 = require("@kya-os/mcp-i-core");
15
+ const node_providers_1 = require("../providers/node-providers");
16
+ const path_1 = __importDefault(require("path"));
17
+ /**
18
+ * Convert legacy config to provider-based config
19
+ */
20
+ function createProvidersFromConfig(config) {
21
+ const cryptoProvider = new node_providers_1.NodeCryptoProvider();
22
+ const clockProvider = new node_providers_1.NodeClockProvider();
23
+ const fetchProvider = new node_providers_1.NodeFetchProvider();
24
+ const identityPath = config.identity?.devIdentityPath ||
25
+ path_1.default.join(process.cwd(), '.mcp-i');
26
+ const storageProvider = new node_providers_1.FileStorageProvider(identityPath);
27
+ const identityProvider = new node_providers_1.FileIdentityProvider(identityPath, cryptoProvider);
28
+ const nonceCacheProvider = (0, node_providers_1.getNonceCacheProvider)();
29
+ return {
30
+ cryptoProvider,
31
+ clockProvider,
32
+ fetchProvider,
33
+ storageProvider,
34
+ nonceCacheProvider,
35
+ identityProvider,
36
+ environment: config.identity?.environment || 'development',
37
+ timestampSkewSeconds: config.session?.timestampSkewSeconds || 120,
38
+ sessionTtlMinutes: config.session?.sessionTtlMinutes || 30,
39
+ audit: config.audit ? {
40
+ enabled: config.audit.enabled !== false,
41
+ logFunction: config.audit.logFunction,
42
+ includePayloads: config.audit.includePayloads
43
+ } : undefined,
44
+ wellKnown: config.wellKnown ? {
45
+ enabled: true,
46
+ serviceName: config.wellKnown.agentMetadata?.name,
47
+ serviceEndpoint: config.wellKnown.baseUrl
48
+ } : undefined,
49
+ showVerifyLink: config.runtime?.showVerifyLink !== false,
50
+ identityBadge: config.demo?.identityBadge || config.runtime?.identityBadge || false
51
+ };
52
+ }
53
+ /**
54
+ * Enhanced MCPIRuntime using the core with Node.js providers
55
+ */
56
+ class MCPIRuntimeWrapper extends mcp_i_core_1.MCPIRuntimeBase {
57
+ legacyConfig;
58
+ constructor(config = {}) {
59
+ const coreConfig = createProvidersFromConfig(config);
60
+ super(coreConfig);
61
+ this.legacyConfig = config;
62
+ }
63
+ }
64
+ exports.MCPIRuntimeWrapper = MCPIRuntimeWrapper;
65
+ /**
66
+ * Factory function for creating runtime
67
+ */
68
+ function createMCPIRuntime(config) {
69
+ return new MCPIRuntimeWrapper(config);
70
+ }
@@ -53,8 +53,7 @@ export declare class ProofGenerator {
53
53
  */
54
54
  private generateSHA256Hash;
55
55
  /**
56
- * JCS canonicalization implementation
57
- * This is a simplified implementation - in production, use a proper JCS library
56
+ * JCS canonicalization implementation (RFC 8785)
58
57
  */
59
58
  private canonicalizeJSON;
60
59
  /**
@@ -63,7 +62,7 @@ export declare class ProofGenerator {
63
62
  */
64
63
  private generateDetachedJWS;
65
64
  /**
66
- * Format base64 private key as PEM for JOSE library
65
+ * Format base64 private key as PKCS#8 PEM for JOSE library
67
66
  */
68
67
  private formatPrivateKeyAsPEM;
69
68
  /**
@@ -11,6 +11,7 @@ exports.createProofResponse = createProofResponse;
11
11
  exports.extractCanonicalData = extractCanonicalData;
12
12
  const crypto_1 = require("crypto");
13
13
  const jose_1 = require("jose");
14
+ const json_canonicalize_1 = require("json-canonicalize");
14
15
  /**
15
16
  * Proof generator class
16
17
  */
@@ -79,39 +80,10 @@ class ProofGenerator {
79
80
  return `sha256:${hash}`;
80
81
  }
81
82
  /**
82
- * JCS canonicalization implementation
83
- * This is a simplified implementation - in production, use a proper JCS library
83
+ * JCS canonicalization implementation (RFC 8785)
84
84
  */
85
85
  canonicalizeJSON(obj) {
86
- if (obj === null)
87
- return "null";
88
- if (typeof obj === "boolean")
89
- return obj.toString();
90
- if (typeof obj === "number") {
91
- // Handle special number cases
92
- if (Number.isNaN(obj))
93
- return "null";
94
- if (!Number.isFinite(obj))
95
- return "null";
96
- return obj.toString();
97
- }
98
- if (typeof obj === "string")
99
- return JSON.stringify(obj);
100
- if (Array.isArray(obj)) {
101
- const items = obj.map((item) => this.canonicalizeJSON(item));
102
- return `[${items.join(",")}]`;
103
- }
104
- if (typeof obj === "object") {
105
- // Sort keys for canonical ordering
106
- const sortedKeys = Object.keys(obj).sort();
107
- const pairs = sortedKeys.map((key) => {
108
- const value = this.canonicalizeJSON(obj[key]);
109
- return `${JSON.stringify(key)}:${value}`;
110
- });
111
- return `{${pairs.join(",")}}`;
112
- }
113
- // Fallback for other types
114
- return JSON.stringify(obj);
86
+ return (0, json_canonicalize_1.canonicalize)(obj);
115
87
  }
116
88
  /**
117
89
  * Generate Ed25519 detached JWS (compact format)
@@ -138,17 +110,14 @@ class ProofGenerator {
138
110
  }
139
111
  }
140
112
  /**
141
- * Format base64 private key as PEM for JOSE library
113
+ * Format base64 private key as PKCS#8 PEM for JOSE library
142
114
  */
143
115
  formatPrivateKeyAsPEM(base64PrivateKey) {
144
- // For Ed25519, we need to format as PKCS#8 PEM
145
- // This is a simplified implementation - in production, use proper key formatting
146
116
  const keyData = Buffer.from(base64PrivateKey, "base64");
147
117
  // Ed25519 PKCS#8 header and footer
148
118
  const header = "-----BEGIN PRIVATE KEY-----\n";
149
119
  const footer = "\n-----END PRIVATE KEY-----";
150
- // For Ed25519, we need to wrap the raw key in PKCS#8 structure
151
- // This is a simplified approach - in production, use proper ASN.1 encoding
120
+ // Wrap Ed25519 raw key in PKCS#8 structure (ASN.1 encoding)
152
121
  const pkcs8Header = Buffer.from([
153
122
  0x30,
154
123
  0x2e, // SEQUENCE, length 46