@kya-os/mcp-i 0.1.0-alpha.2.8 → 0.1.0-alpha.3.0

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 (85) hide show
  1. package/dist/{crypto.js → cjs/crypto.js} +17 -2
  2. package/dist/{index.d.ts → cjs/index.d.ts} +1 -0
  3. package/dist/{index.js → cjs/index.js} +31 -13
  4. package/dist/cjs/nextjs.d.ts +10 -0
  5. package/dist/cjs/nextjs.js +82 -0
  6. package/dist/cjs/vercel-adapter.d.ts +8 -0
  7. package/dist/cjs/vercel-adapter.js +67 -0
  8. package/dist/esm/auto.d.ts +13 -0
  9. package/dist/esm/auto.d.ts.map +1 -0
  10. package/dist/esm/auto.js +30 -0
  11. package/dist/esm/auto.js.map +1 -0
  12. package/dist/esm/crypto.d.ts +51 -0
  13. package/dist/esm/crypto.d.ts.map +1 -0
  14. package/dist/esm/crypto.js +230 -0
  15. package/dist/esm/crypto.js.map +1 -0
  16. package/dist/esm/dev-helper.d.ts +15 -0
  17. package/dist/esm/dev-helper.d.ts.map +1 -0
  18. package/dist/esm/dev-helper.js +63 -0
  19. package/dist/esm/dev-helper.js.map +1 -0
  20. package/dist/esm/encrypted-storage.d.ts +19 -0
  21. package/dist/esm/encrypted-storage.d.ts.map +1 -0
  22. package/dist/esm/encrypted-storage.js +48 -0
  23. package/dist/esm/encrypted-storage.js.map +1 -0
  24. package/dist/esm/index.d.ts +128 -0
  25. package/dist/esm/index.d.ts.map +1 -0
  26. package/dist/esm/index.js +671 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/logger.d.ts +46 -0
  29. package/dist/esm/logger.d.ts.map +1 -0
  30. package/dist/esm/logger.js +76 -0
  31. package/dist/esm/logger.js.map +1 -0
  32. package/dist/esm/nextjs.d.ts +22 -0
  33. package/dist/esm/nextjs.d.ts.map +1 -0
  34. package/dist/esm/nextjs.js +82 -0
  35. package/dist/esm/nextjs.js.map +1 -0
  36. package/dist/esm/registry/index.d.ts +43 -0
  37. package/dist/esm/registry/index.d.ts.map +1 -0
  38. package/dist/esm/registry/index.js +89 -0
  39. package/dist/esm/registry/index.js.map +1 -0
  40. package/dist/esm/registry/knowthat.d.ts +30 -0
  41. package/dist/esm/registry/knowthat.d.ts.map +1 -0
  42. package/dist/esm/registry/knowthat.js +106 -0
  43. package/dist/esm/registry/knowthat.js.map +1 -0
  44. package/dist/esm/rotation.d.ts +57 -0
  45. package/dist/esm/rotation.d.ts.map +1 -0
  46. package/dist/esm/rotation.js +133 -0
  47. package/dist/esm/rotation.js.map +1 -0
  48. package/dist/esm/storage.d.ts +65 -0
  49. package/dist/esm/storage.d.ts.map +1 -0
  50. package/dist/esm/storage.js +160 -0
  51. package/dist/esm/storage.js.map +1 -0
  52. package/dist/esm/transport.d.ts +52 -0
  53. package/dist/esm/transport.d.ts.map +1 -0
  54. package/dist/esm/transport.js +209 -0
  55. package/dist/esm/transport.js.map +1 -0
  56. package/dist/esm/types.d.ts +188 -0
  57. package/dist/esm/types.d.ts.map +1 -0
  58. package/dist/esm/types.js +5 -0
  59. package/dist/esm/types.js.map +1 -0
  60. package/dist/esm/vercel-adapter.d.ts +26 -0
  61. package/dist/esm/vercel-adapter.d.ts.map +1 -0
  62. package/dist/esm/vercel-adapter.js +80 -0
  63. package/dist/esm/vercel-adapter.js.map +1 -0
  64. package/package.json +27 -13
  65. /package/dist/{auto.d.ts → cjs/auto.d.ts} +0 -0
  66. /package/dist/{auto.js → cjs/auto.js} +0 -0
  67. /package/dist/{crypto.d.ts → cjs/crypto.d.ts} +0 -0
  68. /package/dist/{dev-helper.d.ts → cjs/dev-helper.d.ts} +0 -0
  69. /package/dist/{dev-helper.js → cjs/dev-helper.js} +0 -0
  70. /package/dist/{encrypted-storage.d.ts → cjs/encrypted-storage.d.ts} +0 -0
  71. /package/dist/{encrypted-storage.js → cjs/encrypted-storage.js} +0 -0
  72. /package/dist/{logger.d.ts → cjs/logger.d.ts} +0 -0
  73. /package/dist/{logger.js → cjs/logger.js} +0 -0
  74. /package/dist/{registry → cjs/registry}/index.d.ts +0 -0
  75. /package/dist/{registry → cjs/registry}/index.js +0 -0
  76. /package/dist/{registry → cjs/registry}/knowthat.d.ts +0 -0
  77. /package/dist/{registry → cjs/registry}/knowthat.js +0 -0
  78. /package/dist/{rotation.d.ts → cjs/rotation.d.ts} +0 -0
  79. /package/dist/{rotation.js → cjs/rotation.js} +0 -0
  80. /package/dist/{storage.d.ts → cjs/storage.d.ts} +0 -0
  81. /package/dist/{storage.js → cjs/storage.js} +0 -0
  82. /package/dist/{transport.d.ts → cjs/transport.d.ts} +0 -0
  83. /package/dist/{transport.js → cjs/transport.js} +0 -0
  84. /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
  85. /package/dist/{types.js → cjs/types.js} +0 -0
@@ -113,6 +113,7 @@ async function generateNonce(length = 32) {
113
113
  const crypto = await loadCrypto();
114
114
  return crypto.randomBytes(length).toString('hex');
115
115
  }
116
+ let cachedCrypto = null;
116
117
  function generateNonceSync(length = 32) {
117
118
  if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto.getRandomValues) {
118
119
  const bytes = new Uint8Array(length);
@@ -120,10 +121,24 @@ function generateNonceSync(length = 32) {
120
121
  return Buffer.from(bytes).toString('hex');
121
122
  }
122
123
  else {
123
- const crypto = require('crypto');
124
- return crypto.randomBytes(length).toString('hex');
124
+ if (!cachedCrypto) {
125
+ const hex = '0123456789abcdef';
126
+ let output = '';
127
+ for (let i = 0; i < length * 2; i++) {
128
+ output += hex[Math.floor(Math.random() * 16)];
129
+ }
130
+ console.warn('Using Math.random for nonce generation - not cryptographically secure!');
131
+ return output;
132
+ }
133
+ return cachedCrypto.randomBytes(length).toString('hex');
125
134
  }
126
135
  }
136
+ if (typeof process !== 'undefined' && process.versions && process.versions.node) {
137
+ loadCrypto().then(crypto => {
138
+ cachedCrypto = crypto;
139
+ }).catch(() => {
140
+ });
141
+ }
127
142
  function constantTimeEqual(a, b) {
128
143
  if (a.length !== b.length) {
129
144
  return false;
@@ -1,6 +1,7 @@
1
1
  import { MCPIdentityOptions, Challenge, ChallengeResponse, MCPICapabilities, SignedResponse, MCPMiddleware, DirectoryPreference } from './types';
2
2
  import { KeyRotationResult, KeyHealth } from './rotation';
3
3
  export * from './types';
4
+ export * from './vercel-adapter';
4
5
  export { RegistryFactory, REGISTRY_TIERS, resolveRegistries } from './registry';
5
6
  export { LoggerFactory, ConsoleLogger, SilentLogger } from './logger';
6
7
  export { StorageFactory, MemoryStorage, FileStorage } from './storage';
@@ -44,7 +44,9 @@ const storage_1 = require("./storage");
44
44
  const transport_1 = require("./transport");
45
45
  const logger_1 = require("./logger");
46
46
  const rotation_1 = require("./rotation");
47
+ const vercel_adapter_1 = require("./vercel-adapter");
47
48
  __exportStar(require("./types"), exports);
49
+ __exportStar(require("./vercel-adapter"), exports);
48
50
  var registry_1 = require("./registry");
49
51
  Object.defineProperty(exports, "RegistryFactory", { enumerable: true, get: function () { return registry_1.RegistryFactory; } });
50
52
  Object.defineProperty(exports, "REGISTRY_TIERS", { enumerable: true, get: function () { return registry_1.REGISTRY_TIERS; } });
@@ -110,13 +112,24 @@ class MCPIdentity {
110
112
  if (globalIdentity) {
111
113
  return globalIdentity;
112
114
  }
115
+ const isVercel = process.env.VERCEL || process.env.VERCEL_ENV;
116
+ const isServerless = isVercel || process.env.AWS_LAMBDA_FUNCTION_NAME || process.env.FUNCTIONS_WORKER_RUNTIME;
117
+ let identity = null;
118
+ if (isServerless || options?.storage === 'memory') {
119
+ identity = (0, vercel_adapter_1.loadIdentityFromEnv)();
120
+ if (identity) {
121
+ logger.info('✅ Loaded existing identity from environment variables');
122
+ }
123
+ }
113
124
  const storage = storage_1.StorageFactory.create({
114
125
  storage: options?.storage,
115
126
  customPath: options?.persistencePath,
116
127
  memoryKey: options?.memoryKey,
117
128
  encryptionPassword: options?.encryptionPassword
118
129
  });
119
- let identity = await storage.load();
130
+ if (!identity) {
131
+ identity = await storage.load();
132
+ }
120
133
  if (identity) {
121
134
  logger.info('Loaded existing identity:', identity.did);
122
135
  globalIdentity = new MCPIdentity(identity, options);
@@ -136,7 +149,7 @@ class MCPIdentity {
136
149
  repository: options?.repository,
137
150
  publicKey: keyPair.publicKey,
138
151
  directories: options?.directories,
139
- isDraft: options?.mode === 'development'
152
+ isDraft: options?.mode !== 'production'
140
153
  };
141
154
  logger.debug('Registration data:', {
142
155
  name: registrationData.name,
@@ -190,17 +203,22 @@ class MCPIdentity {
190
203
  directories: options?.directories || 'verified'
191
204
  };
192
205
  await storage.save(identity);
193
- logger.info('✅ Success! Your agent has been registered.');
194
- logger.info(`DID: ${response.did}`);
195
- logger.info(`Profile: ${response.agent.url}`);
196
- if (response.agent.claimUrl) {
197
- logger.info(`Claim your agent: ${response.agent.claimUrl}`);
198
- }
199
- if (options?.directories && options.directories !== 'none') {
200
- const dirMessage = options.directories === 'verified'
201
- ? 'Your agent will be submitted to all verified directories'
202
- : `Your agent will be submitted to: ${options.directories.join(', ')}`;
203
- logger.info(dirMessage);
206
+ if (isServerless) {
207
+ (0, vercel_adapter_1.showVercelDeveloperInstructions)(identity, response.agent.claimUrl);
208
+ }
209
+ else {
210
+ logger.info('✅ Success! Your agent has been registered.');
211
+ logger.info(`DID: ${response.did}`);
212
+ logger.info(`Profile: ${response.agent.url}`);
213
+ if (response.agent.claimUrl) {
214
+ logger.info(`Claim your agent: ${response.agent.claimUrl}`);
215
+ }
216
+ if (options?.directories && options.directories !== 'none') {
217
+ const dirMessage = options.directories === 'verified'
218
+ ? 'Your agent will be submitted to all verified directories'
219
+ : `Your agent will be submitted to: ${options.directories.join(', ')}`;
220
+ logger.info(dirMessage);
221
+ }
204
222
  }
205
223
  globalIdentity = new MCPIdentity(identity, options);
206
224
  return globalIdentity;
@@ -0,0 +1,10 @@
1
+ import { MCPIdentity } from './index';
2
+ import { MCPIdentityOptions } from './types';
3
+ export interface NextJSMCPOptions extends Omit<MCPIdentityOptions, 'transport' | 'storage'> {
4
+ storage?: 'memory';
5
+ transport?: 'fetch';
6
+ showSetupInstructions?: boolean;
7
+ }
8
+ export declare function enableMCPIdentityForNextJS(options?: NextJSMCPOptions): Promise<MCPIdentity>;
9
+ export { enableMCPIdentity, MCPIdentity } from './index';
10
+ export * from './types';
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.MCPIdentity = exports.enableMCPIdentity = void 0;
18
+ exports.enableMCPIdentityForNextJS = enableMCPIdentityForNextJS;
19
+ const index_1 = require("./index");
20
+ async function enableMCPIdentityForNextJS(options = {}) {
21
+ const isProduction = process.env.NODE_ENV === 'production';
22
+ const isVercel = process.env.VERCEL || process.env.VERCEL_ENV;
23
+ try {
24
+ console.log(`\n🚀 Initializing MCP-I for Next.js...`);
25
+ const identity = await (0, index_1.enableMCPIdentity)({
26
+ ...options,
27
+ transport: 'fetch',
28
+ storage: 'memory',
29
+ logLevel: options.logLevel || (isProduction ? 'error' : 'info'),
30
+ mode: isProduction ? 'production' : 'development',
31
+ });
32
+ if (!isProduction && options.showSetupInstructions !== false) {
33
+ console.log('\n✅ MCP-I Ready for Next.js!');
34
+ console.log(`\n📋 Quick Info:`);
35
+ console.log(` Environment: ${isVercel ? 'Vercel' : 'Local'}`);
36
+ console.log(` DID: ${identity.did}`);
37
+ if (isVercel && !process.env.MCP_IDENTITY_DID) {
38
+ console.log('\n⚠️ Remember to set environment variables in Vercel Dashboard!');
39
+ console.log(' See console output above for the exact variables to add.');
40
+ }
41
+ }
42
+ return identity;
43
+ }
44
+ catch (error) {
45
+ console.error('\n❌ MCP-I Initialization Failed\n');
46
+ if (error?.message?.includes('429')) {
47
+ console.error('📛 Rate Limit Hit');
48
+ console.error(' You\'ve made too many registration attempts.');
49
+ console.error(' Wait a few minutes and try again.');
50
+ console.error('\n💡 Tip: In development, you can use environment variables to persist identity:');
51
+ console.error(' 1. Copy the MCP_IDENTITY_* variables from a successful run');
52
+ console.error(' 2. Add them to your .env.local file');
53
+ }
54
+ else if (error?.message?.includes('500') || error?.message?.includes('fetch failed')) {
55
+ console.error('📛 Server Connection Error');
56
+ console.error(' Cannot connect to knowthat.ai registry.');
57
+ console.error('\n💡 Possible causes:');
58
+ console.error(' - Registry is temporarily down');
59
+ console.error(' - Network connectivity issues');
60
+ console.error(' - Firewall blocking outbound connections');
61
+ console.error('\n💡 Workaround for development:');
62
+ console.error(' Add to your route: mode: "development" to allow offline mode');
63
+ }
64
+ else if (error?.message?.includes('MODULE_NOT_FOUND')) {
65
+ console.error('📛 Missing Dependencies');
66
+ console.error(' Make sure all dependencies are installed:');
67
+ console.error(' npm install @kya-os/mcp-i');
68
+ }
69
+ else {
70
+ console.error('📛 Unexpected Error:', error?.message || error);
71
+ }
72
+ if (!isProduction) {
73
+ console.error('\n🔍 Full Error Details:');
74
+ console.error(error);
75
+ }
76
+ throw error;
77
+ }
78
+ }
79
+ var index_2 = require("./index");
80
+ Object.defineProperty(exports, "enableMCPIdentity", { enumerable: true, get: function () { return index_2.enableMCPIdentity; } });
81
+ Object.defineProperty(exports, "MCPIdentity", { enumerable: true, get: function () { return index_2.MCPIdentity; } });
82
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,8 @@
1
+ import { MCPIdentityOptions, PersistedIdentity } from './types';
2
+ export interface VercelMCPIdentityOptions extends MCPIdentityOptions {
3
+ envPrefix?: string;
4
+ showClaimInstructions?: boolean;
5
+ }
6
+ export declare function loadIdentityFromEnv(prefix?: string): PersistedIdentity | null;
7
+ export declare function generateEnvInstructions(identity: PersistedIdentity, prefix?: string): string;
8
+ export declare function showVercelDeveloperInstructions(identity: PersistedIdentity, claimUrl?: string): void;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadIdentityFromEnv = loadIdentityFromEnv;
4
+ exports.generateEnvInstructions = generateEnvInstructions;
5
+ exports.showVercelDeveloperInstructions = showVercelDeveloperInstructions;
6
+ const logger_1 = require("./logger");
7
+ function loadIdentityFromEnv(prefix = 'MCP_IDENTITY_') {
8
+ const logger = (0, logger_1.getLogger)();
9
+ try {
10
+ const did = process.env[`${prefix}DID`];
11
+ const publicKey = process.env[`${prefix}PUBLIC_KEY`];
12
+ const privateKey = process.env[`${prefix}PRIVATE_KEY`];
13
+ const agentId = process.env[`${prefix}AGENT_ID`];
14
+ const agentSlug = process.env[`${prefix}AGENT_SLUG`];
15
+ if (did && publicKey && privateKey) {
16
+ logger.info('📦 Loaded identity from environment variables');
17
+ return {
18
+ did,
19
+ publicKey,
20
+ privateKey,
21
+ agentId: agentId || 'unknown',
22
+ agentSlug: agentSlug || 'unknown',
23
+ registeredAt: new Date().toISOString(),
24
+ directories: 'verified'
25
+ };
26
+ }
27
+ }
28
+ catch (error) {
29
+ logger.debug('No identity found in environment variables');
30
+ }
31
+ return null;
32
+ }
33
+ function generateEnvInstructions(identity, prefix = 'MCP_IDENTITY_') {
34
+ return `
35
+ # Add these to your Vercel environment variables:
36
+ ${prefix}DID="${identity.did}"
37
+ ${prefix}PUBLIC_KEY="${identity.publicKey}"
38
+ ${prefix}PRIVATE_KEY="${identity.privateKey}"
39
+ ${prefix}AGENT_ID="${identity.agentId}"
40
+ ${prefix}AGENT_SLUG="${identity.agentSlug}"
41
+ `;
42
+ }
43
+ function showVercelDeveloperInstructions(identity, claimUrl) {
44
+ const logger = (0, logger_1.getLogger)();
45
+ console.log('\n');
46
+ console.log('='.repeat(60));
47
+ console.log('🎉 MCP-I IDENTITY CREATED SUCCESSFULLY! 🎉');
48
+ console.log('='.repeat(60));
49
+ console.log('\n📋 Your Agent Details:\n');
50
+ console.log(` DID: ${identity.did}`);
51
+ console.log(` Agent ID: ${identity.agentId}`);
52
+ console.log(` Profile: https://knowthat.ai/agents/${identity.agentSlug}`);
53
+ if (claimUrl) {
54
+ console.log('\n🎯 IMPORTANT: Claim your agent to manage it:');
55
+ console.log(` ${claimUrl}`);
56
+ console.log('\n This link lets you:');
57
+ console.log(' - Edit your agent details');
58
+ console.log(' - Add logos and descriptions');
59
+ console.log(' - Manage directory listings');
60
+ console.log(' - View analytics');
61
+ }
62
+ console.log('\n⚡ For Vercel Deployment:');
63
+ console.log('\n1. Add these environment variables in Vercel Dashboard:');
64
+ console.log(generateEnvInstructions(identity));
65
+ console.log('2. Your identity will persist across deployments!');
66
+ console.log('\n' + '='.repeat(60) + '\n');
67
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Auto-initialization for MCP Identity
3
+ *
4
+ * Just import this file to automatically enable MCP-I for any MCP server:
5
+ *
6
+ * ```typescript
7
+ * import "@kya-os/mcp-i/auto";
8
+ * ```
9
+ *
10
+ * That's it! Your MCP server now has identity.
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=auto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto.d.ts","sourceRoot":"","sources":["../../src/auto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Auto-initialization for MCP Identity
3
+ *
4
+ * Just import this file to automatically enable MCP-I for any MCP server:
5
+ *
6
+ * ```typescript
7
+ * import "@kya-os/mcp-i/auto";
8
+ * ```
9
+ *
10
+ * That's it! Your MCP server now has identity.
11
+ */
12
+ import { enableMCPIdentity } from './index.js';
13
+ import { getLogger } from './logger.js';
14
+ // Auto-initialize on import
15
+ (async () => {
16
+ try {
17
+ await enableMCPIdentity();
18
+ }
19
+ catch (error) {
20
+ const logger = getLogger();
21
+ logger.error('[MCP-I] Failed to auto-initialize:', error);
22
+ // More detailed error logging for debugging
23
+ if (error.stack) {
24
+ logger.debug('[MCP-I] Error stack:', error.stack);
25
+ }
26
+ // Don't throw the error - allow the server to continue running
27
+ // even if MCP-I initialization fails
28
+ }
29
+ })();
30
+ //# sourceMappingURL=auto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto.js","sourceRoot":"","sources":["../../src/auto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,4BAA4B;AAC5B,CAAC,KAAK,IAAI,EAAE;IACV,IAAI,CAAC;QACH,MAAM,iBAAiB,EAAE,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,MAAM,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;QAE1D,4CAA4C;QAC5C,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACpD,CAAC;QAED,+DAA+D;QAC/D,qCAAqC;IACvC,CAAC;AACH,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Optimized cryptographic utilities for MCP-I with lazy loading
3
+ * Implements Ed25519 signing and verification with caching
4
+ */
5
+ /**
6
+ * Precomputed key pair with cached base64 strings
7
+ */
8
+ export interface PrecomputedKeyPair {
9
+ publicKey: string;
10
+ privateKey: string;
11
+ publicKeyBytes?: Uint8Array;
12
+ privateKeyBytes?: Uint8Array;
13
+ }
14
+ /**
15
+ * Generate a new Ed25519 key pair with precomputed values
16
+ */
17
+ export declare function generateKeyPair(): Promise<PrecomputedKeyPair>;
18
+ /**
19
+ * Sign a message with Ed25519 (with caching)
20
+ */
21
+ export declare function sign(message: string | Buffer, privateKeyBase64: string): Promise<string>;
22
+ /**
23
+ * Verify an Ed25519 signature
24
+ */
25
+ export declare function verify(message: string | Buffer, signatureBase64: string, publicKeyBase64: string): Promise<boolean>;
26
+ /**
27
+ * Generate a cryptographically secure nonce
28
+ */
29
+ export declare function generateNonce(length?: number): Promise<string>;
30
+ export declare function generateNonceSync(length?: number): string;
31
+ /**
32
+ * Constant-time string comparison to prevent timing attacks
33
+ */
34
+ export declare function constantTimeEqual(a: string, b: string): boolean;
35
+ /**
36
+ * Convert Ed25519 public key to did:key format
37
+ */
38
+ export declare function publicKeyToDid(publicKeyBase64: string): string;
39
+ /**
40
+ * Encrypt data using AES-256-GCM (for key storage)
41
+ */
42
+ export declare function encrypt(data: string, password: string): Promise<string>;
43
+ /**
44
+ * Decrypt data using AES-256-GCM
45
+ */
46
+ export declare function decrypt(encryptedData: string, password: string): Promise<string>;
47
+ /**
48
+ * Clear signature cache (useful for testing or memory management)
49
+ */
50
+ export declare function clearCache(): void;
51
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/crypto.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2BH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,UAAU,CAAC;IAC5B,eAAe,CAAC,EAAE,UAAU,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAgBnE;AAED;;GAEG;AACH,wBAAsB,IAAI,CACxB,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC,CAgCjB;AAED;;GAEG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,eAAe,EAAE,MAAM,EACvB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,OAAO,CAAC,CAclB;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAGxE;AAQD,wBAAgB,iBAAiB,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM,CAqB7D;AAWD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAW/D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAQ9D;AAED;;GAEG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2C7E;AAED;;GAEG;AACH,wBAAsB,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA6DtF;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAEjC"}
@@ -0,0 +1,230 @@
1
+ /**
2
+ * Optimized cryptographic utilities for MCP-I with lazy loading
3
+ * Implements Ed25519 signing and verification with caching
4
+ */
5
+ // Lazy-loaded modules
6
+ let ed25519 = null;
7
+ let cryptoModule = null;
8
+ // Cache for computed values
9
+ const signatureCache = new Map();
10
+ const MAX_CACHE_SIZE = 100;
11
+ /**
12
+ * Lazy load crypto dependencies
13
+ */
14
+ async function loadEd25519() {
15
+ if (!ed25519) {
16
+ ed25519 = await import('@noble/ed25519');
17
+ }
18
+ return ed25519;
19
+ }
20
+ async function loadCrypto() {
21
+ if (!cryptoModule) {
22
+ cryptoModule = await import('crypto');
23
+ }
24
+ return cryptoModule;
25
+ }
26
+ /**
27
+ * Generate a new Ed25519 key pair with precomputed values
28
+ */
29
+ export async function generateKeyPair() {
30
+ const ed = await loadEd25519();
31
+ const privateKeyBytes = ed.utils.randomPrivateKey();
32
+ const publicKeyBytes = await ed.getPublicKeyAsync(privateKeyBytes);
33
+ // Precompute base64 strings
34
+ const publicKey = Buffer.from(publicKeyBytes).toString('base64');
35
+ const privateKey = Buffer.from(privateKeyBytes).toString('base64');
36
+ return {
37
+ publicKey,
38
+ privateKey,
39
+ publicKeyBytes,
40
+ privateKeyBytes
41
+ };
42
+ }
43
+ /**
44
+ * Sign a message with Ed25519 (with caching)
45
+ */
46
+ export async function sign(message, privateKeyBase64) {
47
+ // Create cache key
48
+ const messageStr = typeof message === 'string' ? message : message.toString('base64');
49
+ const cacheKey = `${privateKeyBase64}:${messageStr}`;
50
+ // Check cache
51
+ const cached = signatureCache.get(cacheKey);
52
+ if (cached) {
53
+ return cached;
54
+ }
55
+ // Perform signing
56
+ const ed = await loadEd25519();
57
+ const messageBuffer = typeof message === 'string'
58
+ ? Buffer.from(message, 'utf-8')
59
+ : message;
60
+ const privateKey = Buffer.from(privateKeyBase64, 'base64');
61
+ const signature = await ed.signAsync(messageBuffer, privateKey);
62
+ const signatureBase64 = Buffer.from(signature).toString('base64');
63
+ // Cache result (with size limit)
64
+ if (signatureCache.size >= MAX_CACHE_SIZE) {
65
+ // Remove oldest entry
66
+ const firstKey = signatureCache.keys().next().value;
67
+ if (firstKey) {
68
+ signatureCache.delete(firstKey);
69
+ }
70
+ }
71
+ signatureCache.set(cacheKey, signatureBase64);
72
+ return signatureBase64;
73
+ }
74
+ /**
75
+ * Verify an Ed25519 signature
76
+ */
77
+ export async function verify(message, signatureBase64, publicKeyBase64) {
78
+ try {
79
+ const ed = await loadEd25519();
80
+ const messageBuffer = typeof message === 'string'
81
+ ? Buffer.from(message, 'utf-8')
82
+ : message;
83
+ const signature = Buffer.from(signatureBase64, 'base64');
84
+ const publicKey = Buffer.from(publicKeyBase64, 'base64');
85
+ return await ed.verifyAsync(signature, messageBuffer, publicKey);
86
+ }
87
+ catch {
88
+ return false;
89
+ }
90
+ }
91
+ /**
92
+ * Generate a cryptographically secure nonce
93
+ */
94
+ export async function generateNonce(length = 32) {
95
+ const crypto = await loadCrypto();
96
+ return crypto.randomBytes(length).toString('hex');
97
+ }
98
+ /**
99
+ * Generate nonce synchronously (for performance-critical paths)
100
+ * Uses cached crypto module if available
101
+ */
102
+ let cachedCrypto = null;
103
+ export function generateNonceSync(length = 32) {
104
+ if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto.getRandomValues) {
105
+ // Use Web Crypto API if available
106
+ const bytes = new Uint8Array(length);
107
+ globalThis.crypto.getRandomValues(bytes);
108
+ return Buffer.from(bytes).toString('hex');
109
+ }
110
+ else {
111
+ // Try to use cached crypto module
112
+ if (!cachedCrypto) {
113
+ // In Node.js environment, we should have already loaded crypto module
114
+ // This is a fallback for edge cases
115
+ const hex = '0123456789abcdef';
116
+ let output = '';
117
+ for (let i = 0; i < length * 2; i++) {
118
+ output += hex[Math.floor(Math.random() * 16)];
119
+ }
120
+ console.warn('Using Math.random for nonce generation - not cryptographically secure!');
121
+ return output;
122
+ }
123
+ return cachedCrypto.randomBytes(length).toString('hex');
124
+ }
125
+ }
126
+ // Initialize crypto module cache on load (for Node.js environments)
127
+ if (typeof process !== 'undefined' && process.versions && process.versions.node) {
128
+ loadCrypto().then(crypto => {
129
+ cachedCrypto = crypto;
130
+ }).catch(() => {
131
+ // Ignore errors - will fallback to other methods
132
+ });
133
+ }
134
+ /**
135
+ * Constant-time string comparison to prevent timing attacks
136
+ */
137
+ export function constantTimeEqual(a, b) {
138
+ if (a.length !== b.length) {
139
+ return false;
140
+ }
141
+ let result = 0;
142
+ for (let i = 0; i < a.length; i++) {
143
+ result |= a.charCodeAt(i) ^ b.charCodeAt(i);
144
+ }
145
+ return result === 0;
146
+ }
147
+ /**
148
+ * Convert Ed25519 public key to did:key format
149
+ */
150
+ export function publicKeyToDid(publicKeyBase64) {
151
+ const publicKey = Buffer.from(publicKeyBase64, 'base64');
152
+ // Multicodec ed25519-pub header (0xed 0x01)
153
+ const multicodec = Buffer.from([0xed, 0x01]);
154
+ const multikey = Buffer.concat([multicodec, publicKey]);
155
+ // Base58 encode (simplified - in production use a proper base58 library)
156
+ return `did:key:z${multikey.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '')}`;
157
+ }
158
+ /**
159
+ * Encrypt data using AES-256-GCM (for key storage)
160
+ */
161
+ export async function encrypt(data, password) {
162
+ const encoder = new TextEncoder();
163
+ const salt = new Uint8Array(16);
164
+ globalThis.crypto.getRandomValues(salt);
165
+ // Derive key from password
166
+ const keyMaterial = await globalThis.crypto.subtle.importKey('raw', encoder.encode(password), 'PBKDF2', false, ['deriveKey']);
167
+ const key = await globalThis.crypto.subtle.deriveKey({
168
+ name: 'PBKDF2',
169
+ salt,
170
+ iterations: 100000,
171
+ hash: 'SHA-256'
172
+ }, keyMaterial, { name: 'AES-GCM', length: 256 }, false, ['encrypt']);
173
+ const iv = new Uint8Array(12);
174
+ globalThis.crypto.getRandomValues(iv);
175
+ const encrypted = await globalThis.crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, encoder.encode(data));
176
+ // Combine salt + iv + encrypted data
177
+ const combined = new Uint8Array(salt.length + iv.length + encrypted.byteLength);
178
+ combined.set(salt);
179
+ combined.set(iv, salt.length);
180
+ combined.set(new Uint8Array(encrypted), salt.length + iv.length);
181
+ return 'enc:' + Buffer.from(combined).toString('base64');
182
+ }
183
+ /**
184
+ * Decrypt data using AES-256-GCM
185
+ */
186
+ export async function decrypt(encryptedData, password) {
187
+ // Handle enc: prefix
188
+ let dataToDecrypt = encryptedData;
189
+ if (encryptedData.startsWith('enc:')) {
190
+ dataToDecrypt = encryptedData.slice(4);
191
+ }
192
+ // If data doesn't look like base64 encrypted data, return as-is
193
+ if (!dataToDecrypt || dataToDecrypt.length < 44) {
194
+ return encryptedData;
195
+ }
196
+ const encoder = new TextEncoder();
197
+ const decoder = new TextDecoder();
198
+ try {
199
+ const combined = Buffer.from(dataToDecrypt, 'base64');
200
+ // Check minimum size for encrypted data (salt + iv + auth tag + at least 1 byte)
201
+ if (combined.length < 29) {
202
+ return encryptedData;
203
+ }
204
+ // Extract salt, iv, and encrypted data
205
+ const salt = combined.slice(0, 16);
206
+ const iv = combined.slice(16, 28);
207
+ const encrypted = combined.slice(28);
208
+ // Derive key from password
209
+ const keyMaterial = await globalThis.crypto.subtle.importKey('raw', encoder.encode(password), 'PBKDF2', false, ['deriveKey']);
210
+ const key = await globalThis.crypto.subtle.deriveKey({
211
+ name: 'PBKDF2',
212
+ salt: new Uint8Array(salt),
213
+ iterations: 100000,
214
+ hash: 'SHA-256'
215
+ }, keyMaterial, { name: 'AES-GCM', length: 256 }, false, ['decrypt']);
216
+ const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: new Uint8Array(iv) }, key, new Uint8Array(encrypted));
217
+ return decoder.decode(decrypted);
218
+ }
219
+ catch (error) {
220
+ // If decryption fails, throw error
221
+ throw new Error('Failed to decrypt data: invalid password or corrupted data');
222
+ }
223
+ }
224
+ /**
225
+ * Clear signature cache (useful for testing or memory management)
226
+ */
227
+ export function clearCache() {
228
+ signatureCache.clear();
229
+ }
230
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/crypto.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sBAAsB;AACtB,IAAI,OAAO,GAA2C,IAAI,CAAC;AAC3D,IAAI,YAAY,GAAmC,IAAI,CAAC;AAExD,4BAA4B;AAC5B,MAAM,cAAc,GAAG,IAAI,GAAG,EAAkB,CAAC;AACjD,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B;;GAEG;AACH,KAAK,UAAU,WAAW;IACxB,IAAI,CAAC,OAAO,EAAE,CAA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