@kya-os/mcp-i 0.1.0-alpha.2.9 → 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.
- package/dist/{crypto.js → cjs/crypto.js} +17 -2
- package/dist/esm/auto.d.ts +13 -0
- package/dist/esm/auto.d.ts.map +1 -0
- package/dist/esm/auto.js +30 -0
- package/dist/esm/auto.js.map +1 -0
- package/dist/esm/crypto.d.ts +51 -0
- package/dist/esm/crypto.d.ts.map +1 -0
- package/dist/esm/crypto.js +230 -0
- package/dist/esm/crypto.js.map +1 -0
- package/dist/esm/dev-helper.d.ts +15 -0
- package/dist/esm/dev-helper.d.ts.map +1 -0
- package/dist/esm/dev-helper.js +63 -0
- package/dist/esm/dev-helper.js.map +1 -0
- package/dist/esm/encrypted-storage.d.ts +19 -0
- package/dist/esm/encrypted-storage.d.ts.map +1 -0
- package/dist/esm/encrypted-storage.js +48 -0
- package/dist/esm/encrypted-storage.js.map +1 -0
- package/dist/esm/index.d.ts +128 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +671 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger.d.ts +46 -0
- package/dist/esm/logger.d.ts.map +1 -0
- package/dist/esm/logger.js +76 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/nextjs.d.ts +22 -0
- package/dist/esm/nextjs.d.ts.map +1 -0
- package/dist/esm/nextjs.js +82 -0
- package/dist/esm/nextjs.js.map +1 -0
- package/dist/esm/registry/index.d.ts +43 -0
- package/dist/esm/registry/index.d.ts.map +1 -0
- package/dist/esm/registry/index.js +89 -0
- package/dist/esm/registry/index.js.map +1 -0
- package/dist/esm/registry/knowthat.d.ts +30 -0
- package/dist/esm/registry/knowthat.d.ts.map +1 -0
- package/dist/esm/registry/knowthat.js +106 -0
- package/dist/esm/registry/knowthat.js.map +1 -0
- package/dist/esm/rotation.d.ts +57 -0
- package/dist/esm/rotation.d.ts.map +1 -0
- package/dist/esm/rotation.js +133 -0
- package/dist/esm/rotation.js.map +1 -0
- package/dist/esm/storage.d.ts +65 -0
- package/dist/esm/storage.d.ts.map +1 -0
- package/dist/esm/storage.js +160 -0
- package/dist/esm/storage.js.map +1 -0
- package/dist/esm/transport.d.ts +52 -0
- package/dist/esm/transport.d.ts.map +1 -0
- package/dist/esm/transport.js +209 -0
- package/dist/esm/transport.js.map +1 -0
- package/dist/esm/types.d.ts +188 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +5 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/vercel-adapter.d.ts +26 -0
- package/dist/esm/vercel-adapter.d.ts.map +1 -0
- package/dist/esm/vercel-adapter.js +80 -0
- package/dist/esm/vercel-adapter.js.map +1 -0
- package/package.json +23 -19
- /package/dist/{auto.d.ts → cjs/auto.d.ts} +0 -0
- /package/dist/{auto.js → cjs/auto.js} +0 -0
- /package/dist/{crypto.d.ts → cjs/crypto.d.ts} +0 -0
- /package/dist/{dev-helper.d.ts → cjs/dev-helper.d.ts} +0 -0
- /package/dist/{dev-helper.js → cjs/dev-helper.js} +0 -0
- /package/dist/{encrypted-storage.d.ts → cjs/encrypted-storage.d.ts} +0 -0
- /package/dist/{encrypted-storage.js → cjs/encrypted-storage.js} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{logger.d.ts → cjs/logger.d.ts} +0 -0
- /package/dist/{logger.js → cjs/logger.js} +0 -0
- /package/dist/{nextjs.d.ts → cjs/nextjs.d.ts} +0 -0
- /package/dist/{nextjs.js → cjs/nextjs.js} +0 -0
- /package/dist/{registry → cjs/registry}/index.d.ts +0 -0
- /package/dist/{registry → cjs/registry}/index.js +0 -0
- /package/dist/{registry → cjs/registry}/knowthat.d.ts +0 -0
- /package/dist/{registry → cjs/registry}/knowthat.js +0 -0
- /package/dist/{rotation.d.ts → cjs/rotation.d.ts} +0 -0
- /package/dist/{rotation.js → cjs/rotation.js} +0 -0
- /package/dist/{storage.d.ts → cjs/storage.d.ts} +0 -0
- /package/dist/{storage.js → cjs/storage.js} +0 -0
- /package/dist/{transport.d.ts → cjs/transport.d.ts} +0 -0
- /package/dist/{transport.js → cjs/transport.js} +0 -0
- /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
- /package/dist/{types.js → cjs/types.js} +0 -0
- /package/dist/{vercel-adapter.d.ts → cjs/vercel-adapter.d.ts} +0 -0
- /package/dist/{vercel-adapter.js → cjs/vercel-adapter.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
|
-
|
|
124
|
-
|
|
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;
|
|
@@ -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"}
|
package/dist/esm/auto.js
ADDED
|
@@ -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,CAAC;QACb,OAAO,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAYD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,MAAM,EAAE,GAAG,MAAM,WAAW,EAAE,CAAC;IAE/B,MAAM,eAAe,GAAG,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;IACpD,MAAM,cAAc,GAAG,MAAM,EAAE,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;IAEnE,4BAA4B;IAC5B,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CA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E,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC;YAC1B,UAAU,EAAE,MAAM;YAClB,IAAI,EAAE,SAAS;SAChB,EACD,WAAW,EACX,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,EAChC,KAAK,EACL,CAAC,SAAS,CAAC,CACZ,CAAC;QAEF,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CACtD,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,UAAU,CAAC,EAAE,CAAC,EAAE,EAC3C,GAAG,EACH,IAAI,UAAU,CAAC,SAAS,CAAC,CAC1B,CAAC;QAEF,OAAO,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,mCAAmC;QACnC,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAChF,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU;IACxB,cAAc,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Development Helper for MCP-I Package
|
|
3
|
+
*
|
|
4
|
+
* Provides additional developer experience improvements for local development
|
|
5
|
+
*/
|
|
6
|
+
import { MCPIdentity } from './index';
|
|
7
|
+
/**
|
|
8
|
+
* Enhanced development experience with helpful logging and tips
|
|
9
|
+
*/
|
|
10
|
+
export declare function initWithDevExperience(options?: any): Promise<MCPIdentity>;
|
|
11
|
+
/**
|
|
12
|
+
* Quick agent status check for debugging
|
|
13
|
+
*/
|
|
14
|
+
export declare function showAgentStatus(identity: MCPIdentity): void;
|
|
15
|
+
//# sourceMappingURL=dev-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-helper.d.ts","sourceRoot":"","sources":["../../src/dev-helper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,GAAE,GAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAoCnF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI,CAmB3D"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Development Helper for MCP-I Package
|
|
3
|
+
*
|
|
4
|
+
* Provides additional developer experience improvements for local development
|
|
5
|
+
*/
|
|
6
|
+
import { MCPIdentity } from './index.js';
|
|
7
|
+
import { getLogger } from './logger.js';
|
|
8
|
+
/**
|
|
9
|
+
* Enhanced development experience with helpful logging and tips
|
|
10
|
+
*/
|
|
11
|
+
export async function initWithDevExperience(options = {}) {
|
|
12
|
+
const logger = getLogger();
|
|
13
|
+
// Add development mode if not specified
|
|
14
|
+
if (process.env.NODE_ENV === 'development' && !options.mode) {
|
|
15
|
+
options.mode = 'development';
|
|
16
|
+
logger.info('🔧 Development mode detected - agents will be created as drafts');
|
|
17
|
+
}
|
|
18
|
+
// Auto-detect MCP server name from package.json
|
|
19
|
+
if (!options.name && !process.env.MCP_SERVER_NAME) {
|
|
20
|
+
// In Next.js and other bundled environments, we can't dynamically require package.json
|
|
21
|
+
// Users should provide the name explicitly
|
|
22
|
+
options.name = 'Development MCP Server';
|
|
23
|
+
logger.info('💡 Tip: Provide a name in options for better agent identification');
|
|
24
|
+
}
|
|
25
|
+
// Performance tips
|
|
26
|
+
if (!options.storage) {
|
|
27
|
+
logger.info('💡 Tip: Use storage: "file" for persistent identity across restarts');
|
|
28
|
+
}
|
|
29
|
+
const identity = await MCPIdentity.init(options);
|
|
30
|
+
// Show useful development information
|
|
31
|
+
logger.info('✨ MCP Identity initialized successfully!');
|
|
32
|
+
logger.info(`🆔 DID: ${identity.did}`);
|
|
33
|
+
// Show claim URL in development
|
|
34
|
+
const { claimUrl } = await identity.requestEditAccess();
|
|
35
|
+
logger.info(`🔗 Claim your agent: ${claimUrl}`);
|
|
36
|
+
// Show integration tip
|
|
37
|
+
logger.info('💡 Your MCP server responses are now automatically signed with your agent identity');
|
|
38
|
+
return identity;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Quick agent status check for debugging
|
|
42
|
+
*/
|
|
43
|
+
export function showAgentStatus(identity) {
|
|
44
|
+
const logger = getLogger();
|
|
45
|
+
const capabilities = identity.getCapabilities();
|
|
46
|
+
logger.info('📊 Agent Status:');
|
|
47
|
+
logger.info(` DID: ${identity.did}`);
|
|
48
|
+
logger.info(` Conformance Level: ${capabilities.conformanceLevel}`);
|
|
49
|
+
logger.info(` Registry: ${capabilities.registry || 'knowthat.ai'}`);
|
|
50
|
+
logger.info(` Handshake Supported: ${capabilities.handshakeSupported}`);
|
|
51
|
+
// Show directory preferences
|
|
52
|
+
const directories = identity.getDirectories();
|
|
53
|
+
if (directories === 'none') {
|
|
54
|
+
logger.info('📋 Directories: Not listing on any directories');
|
|
55
|
+
}
|
|
56
|
+
else if (directories === 'verified') {
|
|
57
|
+
logger.info('📋 Directories: Listing on all verified directories');
|
|
58
|
+
}
|
|
59
|
+
else if (Array.isArray(directories)) {
|
|
60
|
+
logger.info(`📋 Directories: ${directories.join(', ')}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=dev-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-helper.js","sourceRoot":"","sources":["../../src/dev-helper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,UAAe,EAAE;IAC3D,MAAM,MAAM,GAAG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AM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAChC,MAAM,CAAC,IAAI,CAAC,WAAW,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IACvC,MAAM,CAAC,IAAI,CAAC,yBAAyB,YAAY,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACtE,MAAM,CAAC,IAAI,CAAC,gBAAgB,YAAY,CAAC,QAAQ,IAAI,aAAa,EAAE,CAAC,CAAC;IACtE,MAAM,CAAC,IAAI,CAAC,2BAA2B,YAAY,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAE1E,6BAA6B;IAC7B,MAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAC;IAC9C,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;QAC3B,MAAM,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAC;IAChE,CAAC;SAAM,IAAI,WAAW,KAAK,UAAU,EAAE,CAAC;QACtC,MAAM,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;IACrE,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QACtC,MAAM,CAAC,IAAI,CAAC,mBAAmB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypted storage wrapper for MCP-I identity
|
|
3
|
+
* Adds encryption layer on top of any storage provider
|
|
4
|
+
*/
|
|
5
|
+
import { StorageProvider } from './storage';
|
|
6
|
+
import { PersistedIdentity } from './types';
|
|
7
|
+
export declare class EncryptedStorage implements StorageProvider {
|
|
8
|
+
private baseStorage;
|
|
9
|
+
private password;
|
|
10
|
+
constructor(baseStorage: StorageProvider, password: string);
|
|
11
|
+
load(): Promise<PersistedIdentity | null>;
|
|
12
|
+
save(identity: PersistedIdentity): Promise<void>;
|
|
13
|
+
exists(): Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create encrypted storage wrapper
|
|
17
|
+
*/
|
|
18
|
+
export declare function createEncryptedStorage(baseStorage: StorageProvider, password: string): StorageProvider;
|
|
19
|
+
//# sourceMappingURL=encrypted-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypted-storage.d.ts","sourceRoot":"","sources":["../../src/encrypted-storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAG5C,qBAAa,gBAAiB,YAAW,eAAe;IAEpD,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,QAAQ;gBADR,WAAW,EAAE,eAAe,EAC5B,QAAQ,EAAE,MAAM;IAGpB,IAAI,IAAI,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAkBzC,IAAI,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAehD,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;CAGjC;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,eAAe,EAC5B,QAAQ,EAAE,MAAM,GACf,eAAe,CAEjB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypted storage wrapper for MCP-I identity
|
|
3
|
+
* Adds encryption layer on top of any storage provider
|
|
4
|
+
*/
|
|
5
|
+
import * as crypto from './crypto.js';
|
|
6
|
+
export class EncryptedStorage {
|
|
7
|
+
baseStorage;
|
|
8
|
+
password;
|
|
9
|
+
constructor(baseStorage, password) {
|
|
10
|
+
this.baseStorage = baseStorage;
|
|
11
|
+
this.password = password;
|
|
12
|
+
}
|
|
13
|
+
async load() {
|
|
14
|
+
const identity = await this.baseStorage.load();
|
|
15
|
+
if (!identity) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
// Decrypt private key if encrypted
|
|
19
|
+
if (identity.privateKey.startsWith('enc:')) {
|
|
20
|
+
try {
|
|
21
|
+
identity.privateKey = await crypto.decrypt(identity.privateKey, this.password);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new Error('Failed to decrypt stored identity - invalid password');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return identity;
|
|
28
|
+
}
|
|
29
|
+
async save(identity) {
|
|
30
|
+
// Create a copy to avoid modifying the original
|
|
31
|
+
const encryptedIdentity = { ...identity };
|
|
32
|
+
// Encrypt private key before saving
|
|
33
|
+
if (!encryptedIdentity.privateKey.startsWith('enc:')) {
|
|
34
|
+
encryptedIdentity.privateKey = await crypto.encrypt(encryptedIdentity.privateKey, this.password);
|
|
35
|
+
}
|
|
36
|
+
await this.baseStorage.save(encryptedIdentity);
|
|
37
|
+
}
|
|
38
|
+
async exists() {
|
|
39
|
+
return this.baseStorage.exists();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create encrypted storage wrapper
|
|
44
|
+
*/
|
|
45
|
+
export function createEncryptedStorage(baseStorage, password) {
|
|
46
|
+
return new EncryptedStorage(baseStorage, password);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=encrypted-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypted-storage.js","sourceRoot":"","sources":["../../src/encrypted-storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAEnC,MAAM,OAAO,gBAAgB;IAEjB;IACA;IAFV,YACU,WAA4B,EAC5B,QAAgB;QADhB,gBAAW,GAAX,WAAW,CAAiB;QAC5B,aAAQ,GAAR,QAAQ,CAAQ;IACvB,CAAC;IAEJ,KAAK,CAAC,IAAI;QACR,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,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