@kya-os/mcp-i 0.1.0-alpha.1.0 → 0.1.0-alpha.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -90
- package/dist/__tests__/challenge-response.test.d.ts +5 -0
- package/dist/__tests__/challenge-response.test.d.ts.map +1 -0
- package/dist/__tests__/challenge-response.test.js +218 -0
- package/dist/__tests__/challenge-response.test.js.map +1 -0
- package/dist/__tests__/crypto.test.d.ts +5 -0
- package/dist/__tests__/crypto.test.d.ts.map +1 -0
- package/dist/__tests__/crypto.test.js +153 -0
- package/dist/__tests__/crypto.test.js.map +1 -0
- package/dist/auto-enhance.d.ts +41 -0
- package/dist/auto-enhance.d.ts.map +1 -0
- package/dist/auto-enhance.js +193 -0
- package/dist/auto-enhance.js.map +1 -0
- package/dist/auto-init.d.ts +12 -0
- package/dist/auto-init.d.ts.map +1 -0
- package/dist/auto-init.js +166 -0
- package/dist/auto-init.js.map +1 -0
- package/dist/auto.d.ts +13 -0
- package/dist/auto.d.ts.map +1 -0
- package/dist/auto.js +24 -0
- package/dist/auto.js.map +1 -0
- package/dist/crypto.d.ts +32 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +117 -0
- package/dist/crypto.js.map +1 -0
- package/dist/index.d.ts +43 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +208 -28
- package/dist/index.js.map +1 -1
- package/dist/patch.d.ts +22 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js +164 -0
- package/dist/patch.js.map +1 -0
- package/dist/transparent.d.ts +40 -0
- package/dist/transparent.d.ts.map +1 -0
- package/dist/transparent.js +167 -0
- package/dist/transparent.js.map +1 -0
- package/dist/types.d.ts +79 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +19 -4
package/README.md
CHANGED
|
@@ -1,121 +1,97 @@
|
|
|
1
1
|
# @kya-os/mcp-i
|
|
2
2
|
|
|
3
|
-
Ultra-light MCP Identity auto-registration
|
|
3
|
+
Ultra-light MCP Identity auto-registration. Give any MCP server a verifiable identity with just 2 lines of code.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## The Vision
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
npm install @kya-os/mcp-i
|
|
9
|
-
```
|
|
7
|
+
Make MCP-I adoption a no-brainer for the hundreds of thousands of MCP servers. Zero friction, immediate benefits.
|
|
10
8
|
|
|
11
|
-
##
|
|
9
|
+
## Installation
|
|
12
10
|
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// That's it! Your MCP server now has identity
|
|
17
|
-
const identity = await MCPIdentity.init();
|
|
18
|
-
|
|
19
|
-
console.log("My DID:", identity.did);
|
|
20
|
-
// Output: did:web:knowthat.ai:agents:your-server-name
|
|
11
|
+
```bash
|
|
12
|
+
npm install @kya-os/mcp-i
|
|
21
13
|
```
|
|
22
14
|
|
|
23
|
-
##
|
|
24
|
-
|
|
25
|
-
1. **First Run**: Automatically registers your MCP server with knowthat.ai
|
|
26
|
-
2. **Gets DID**: Receives a decentralized identifier for your agent
|
|
27
|
-
3. **Saves Identity**: Stores credentials in `.env.local` and `.mcp-identity.json`
|
|
28
|
-
4. **Future Runs**: Loads existing identity (no re-registration)
|
|
29
|
-
|
|
30
|
-
## ✨ Features
|
|
31
|
-
|
|
32
|
-
- **Zero Configuration**: Works out of the box
|
|
33
|
-
- **Ultra-Light**: Only depends on `axios`
|
|
34
|
-
- **No Other Dependencies**: Completely standalone package
|
|
35
|
-
- **Persistent Identity**: Same DID across restarts
|
|
36
|
-
- **Verification Badges**: Get verified status in MCP directories
|
|
15
|
+
## Usage
|
|
37
16
|
|
|
38
|
-
|
|
17
|
+
### Option 1: Zero Configuration (Recommended)
|
|
39
18
|
|
|
40
19
|
```typescript
|
|
41
|
-
|
|
42
|
-
name: "My Awesome MCP Server", // Optional: Server name
|
|
43
|
-
description: "Does amazing things", // Optional: Description
|
|
44
|
-
repository: "https://github.com/...", // Optional: GitHub URL
|
|
45
|
-
apiEndpoint: "https://knowthat.ai", // Optional: Custom endpoint
|
|
46
|
-
});
|
|
20
|
+
import "@kya-os/mcp-i/auto"; // That's it! Your server now has identity
|
|
47
21
|
```
|
|
48
22
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
The package stores identity in multiple locations (checked in order):
|
|
52
|
-
|
|
53
|
-
1. **Environment Variables**
|
|
54
|
-
|
|
55
|
-
- `AGENT_DID`
|
|
56
|
-
- `AGENT_PUBLIC_KEY`
|
|
57
|
-
- `AGENT_PRIVATE_KEY`
|
|
58
|
-
|
|
59
|
-
2. **Local Files**
|
|
60
|
-
- `.env.local` (auto-generated)
|
|
61
|
-
- `.mcp-identity.json` (auto-generated)
|
|
62
|
-
|
|
63
|
-
## 🔐 Security
|
|
64
|
-
|
|
65
|
-
- Private keys are stored locally only
|
|
66
|
-
- Never share your `.env.local` or `.mcp-identity.json` files
|
|
67
|
-
- Add them to `.gitignore`
|
|
68
|
-
|
|
69
|
-
## 🤝 Integration with MCP Servers
|
|
23
|
+
### Option 2: With Configuration
|
|
70
24
|
|
|
71
25
|
```typescript
|
|
72
|
-
import {
|
|
73
|
-
import { MCPIdentity } from "@kya-os/mcp-i";
|
|
26
|
+
import { enableMCPIdentity } from "@kya-os/mcp-i";
|
|
74
27
|
|
|
75
|
-
|
|
76
|
-
const identity = await MCPIdentity.init({
|
|
28
|
+
await enableMCPIdentity({
|
|
77
29
|
name: "Calendar Booker",
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// Pass to your MCP server
|
|
81
|
-
const server = new Server({
|
|
82
|
-
name: "calendar-booker",
|
|
83
|
-
version: "1.0.0",
|
|
84
|
-
identity, // Your server now has verifiable identity!
|
|
30
|
+
description: "Professional calendar booking for AI agents",
|
|
31
|
+
repository: "https://github.com/awesome-dev/calendar-booker"
|
|
85
32
|
});
|
|
86
33
|
```
|
|
87
34
|
|
|
88
|
-
##
|
|
89
|
-
|
|
90
|
-
1. **
|
|
91
|
-
2. **
|
|
92
|
-
3. **
|
|
93
|
-
4. **
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
35
|
+
## What Happens
|
|
36
|
+
|
|
37
|
+
1. **First Run**: Automatically registers with knowthat.ai and gets a DID
|
|
38
|
+
2. **Identity Saved**: Persists to `.env.local` and `.mcp-identity.json`
|
|
39
|
+
3. **All Responses Signed**: Every response includes `_mcp_identity` field
|
|
40
|
+
4. **MCP-I Handshake**: Automatically handles challenge-response authentication
|
|
41
|
+
5. **Capabilities Advertised**: Server advertises MCP-I support to clients
|
|
42
|
+
|
|
43
|
+
## Example Response
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"content": [{
|
|
48
|
+
"type": "text",
|
|
49
|
+
"text": "Event booked successfully!"
|
|
50
|
+
}],
|
|
51
|
+
"_mcp_identity": {
|
|
52
|
+
"did": "did:web:knowthat.ai:agents:calendar-booker",
|
|
53
|
+
"signature": "0x3045...",
|
|
54
|
+
"timestamp": "2025-01-31T10:00:00Z",
|
|
55
|
+
"conformanceLevel": 2
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
98
59
|
|
|
99
|
-
|
|
60
|
+
## Benefits
|
|
100
61
|
|
|
101
|
-
|
|
62
|
+
- ✅ **Verification Badge** on Smithery and other directories
|
|
63
|
+
- 🔝 **Priority Discovery** in search results
|
|
64
|
+
- 🔐 **Access to Identity-Aware APIs** with higher rate limits
|
|
65
|
+
- 📊 **Analytics & Reputation** tracking
|
|
66
|
+
- 🛡️ **Protection Against Impersonation**
|
|
102
67
|
|
|
103
|
-
|
|
68
|
+
## How It Works
|
|
104
69
|
|
|
105
|
-
|
|
70
|
+
The package automatically:
|
|
71
|
+
1. Patches the MCP Server class to inject identity into all responses
|
|
72
|
+
2. Handles MCP-I challenge-response authentication
|
|
73
|
+
3. Advertises capabilities in server info
|
|
74
|
+
4. Works with all transports (STDIO, SSE, HTTP)
|
|
106
75
|
|
|
107
|
-
|
|
76
|
+
## Environment Variables
|
|
108
77
|
|
|
109
|
-
|
|
78
|
+
After first run, these are saved automatically:
|
|
110
79
|
|
|
111
|
-
|
|
80
|
+
```bash
|
|
81
|
+
AGENT_DID="did:web:knowthat.ai:agents:your-agent"
|
|
82
|
+
AGENT_PUBLIC_KEY="base64-encoded-public-key"
|
|
83
|
+
AGENT_PRIVATE_KEY="base64-encoded-private-key"
|
|
84
|
+
AGENT_ID="uuid"
|
|
85
|
+
AGENT_SLUG="your-agent-slug"
|
|
86
|
+
```
|
|
112
87
|
|
|
113
|
-
##
|
|
88
|
+
## Security
|
|
114
89
|
|
|
115
|
-
-
|
|
116
|
-
-
|
|
117
|
-
-
|
|
90
|
+
- Private keys are stored locally, never sent to knowthat.ai
|
|
91
|
+
- All responses are cryptographically signed with Ed25519
|
|
92
|
+
- Challenge-response prevents replay attacks
|
|
93
|
+
- Nonce tracking prevents reuse
|
|
118
94
|
|
|
119
|
-
|
|
95
|
+
## License
|
|
120
96
|
|
|
121
|
-
|
|
97
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"challenge-response.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/challenge-response.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tests for challenge-response authentication
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const vitest_1 = require("vitest");
|
|
40
|
+
const index_1 = require("../index");
|
|
41
|
+
const crypto = __importStar(require("../crypto"));
|
|
42
|
+
// Mock axios for auto-registration
|
|
43
|
+
vitest_1.vi.mock('axios');
|
|
44
|
+
// Mock fs for identity persistence
|
|
45
|
+
vitest_1.vi.mock('fs', () => ({
|
|
46
|
+
existsSync: vitest_1.vi.fn(() => false),
|
|
47
|
+
readFileSync: vitest_1.vi.fn(),
|
|
48
|
+
writeFileSync: vitest_1.vi.fn()
|
|
49
|
+
}));
|
|
50
|
+
(0, vitest_1.describe)('MCPIdentity Challenge-Response', () => {
|
|
51
|
+
let identity;
|
|
52
|
+
let keyPair;
|
|
53
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
54
|
+
// Mock environment to have pre-existing identity
|
|
55
|
+
keyPair = await crypto.generateKeyPair();
|
|
56
|
+
process.env.AGENT_DID = 'did:web:knowthat.ai:agents:test-agent';
|
|
57
|
+
process.env.AGENT_PUBLIC_KEY = keyPair.publicKey;
|
|
58
|
+
process.env.AGENT_PRIVATE_KEY = keyPair.privateKey;
|
|
59
|
+
process.env.AGENT_ID = 'agent-123';
|
|
60
|
+
process.env.AGENT_SLUG = 'test-agent';
|
|
61
|
+
identity = await index_1.MCPIdentity.init();
|
|
62
|
+
});
|
|
63
|
+
(0, vitest_1.afterEach)(() => {
|
|
64
|
+
// Clean up environment
|
|
65
|
+
delete process.env.AGENT_DID;
|
|
66
|
+
delete process.env.AGENT_PUBLIC_KEY;
|
|
67
|
+
delete process.env.AGENT_PRIVATE_KEY;
|
|
68
|
+
delete process.env.AGENT_ID;
|
|
69
|
+
delete process.env.AGENT_SLUG;
|
|
70
|
+
});
|
|
71
|
+
(0, vitest_1.describe)('respondToChallenge', () => {
|
|
72
|
+
(0, vitest_1.it)('should successfully respond to a valid challenge', async () => {
|
|
73
|
+
const challenge = {
|
|
74
|
+
nonce: crypto.generateNonce(),
|
|
75
|
+
timestamp: Date.now(),
|
|
76
|
+
verifier_did: 'did:web:example.com:verifier',
|
|
77
|
+
scope: ['read', 'write']
|
|
78
|
+
};
|
|
79
|
+
const response = await identity.respondToChallenge(challenge);
|
|
80
|
+
(0, vitest_1.expect)(response).toMatchObject({
|
|
81
|
+
did: 'did:web:knowthat.ai:agents:test-agent',
|
|
82
|
+
nonce: challenge.nonce,
|
|
83
|
+
publicKey: keyPair.publicKey
|
|
84
|
+
});
|
|
85
|
+
(0, vitest_1.expect)(response.signature).toBeDefined();
|
|
86
|
+
(0, vitest_1.expect)(response.timestamp).toBeGreaterThanOrEqual(challenge.timestamp);
|
|
87
|
+
// Verify the signature
|
|
88
|
+
const messageComponents = [
|
|
89
|
+
challenge.nonce,
|
|
90
|
+
challenge.timestamp.toString(),
|
|
91
|
+
response.did,
|
|
92
|
+
challenge.verifier_did || '',
|
|
93
|
+
(challenge.scope || []).join(',')
|
|
94
|
+
];
|
|
95
|
+
const message = messageComponents.join(':');
|
|
96
|
+
const isValid = await identity.verify(message, response.signature);
|
|
97
|
+
(0, vitest_1.expect)(isValid).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
(0, vitest_1.it)('should reject expired challenges', async () => {
|
|
100
|
+
const challenge = {
|
|
101
|
+
nonce: crypto.generateNonce(),
|
|
102
|
+
timestamp: Date.now() - 120000, // 2 minutes ago
|
|
103
|
+
};
|
|
104
|
+
await (0, vitest_1.expect)(identity.respondToChallenge(challenge))
|
|
105
|
+
.rejects.toThrow('Challenge expired');
|
|
106
|
+
});
|
|
107
|
+
(0, vitest_1.it)('should reject challenges with future timestamps', async () => {
|
|
108
|
+
const challenge = {
|
|
109
|
+
nonce: crypto.generateNonce(),
|
|
110
|
+
timestamp: Date.now() + 60000, // 1 minute in future
|
|
111
|
+
};
|
|
112
|
+
await (0, vitest_1.expect)(identity.respondToChallenge(challenge))
|
|
113
|
+
.rejects.toThrow('Challenge timestamp is in the future');
|
|
114
|
+
});
|
|
115
|
+
(0, vitest_1.it)('should reject reused nonces when tracking is enabled', async () => {
|
|
116
|
+
const challenge = {
|
|
117
|
+
nonce: crypto.generateNonce(),
|
|
118
|
+
timestamp: Date.now(),
|
|
119
|
+
};
|
|
120
|
+
// First use should succeed
|
|
121
|
+
await identity.respondToChallenge(challenge);
|
|
122
|
+
// Second use should fail
|
|
123
|
+
await (0, vitest_1.expect)(identity.respondToChallenge(challenge))
|
|
124
|
+
.rejects.toThrow('Nonce already used');
|
|
125
|
+
});
|
|
126
|
+
(0, vitest_1.it)('should handle challenges without optional fields', async () => {
|
|
127
|
+
const challenge = {
|
|
128
|
+
nonce: crypto.generateNonce(),
|
|
129
|
+
timestamp: Date.now(),
|
|
130
|
+
};
|
|
131
|
+
const response = await identity.respondToChallenge(challenge);
|
|
132
|
+
(0, vitest_1.expect)(response).toMatchObject({
|
|
133
|
+
did: 'did:web:knowthat.ai:agents:test-agent',
|
|
134
|
+
nonce: challenge.nonce,
|
|
135
|
+
});
|
|
136
|
+
// Verify signature with empty optional fields
|
|
137
|
+
const messageComponents = [
|
|
138
|
+
challenge.nonce,
|
|
139
|
+
challenge.timestamp.toString(),
|
|
140
|
+
response.did,
|
|
141
|
+
'', // No verifier_did
|
|
142
|
+
'' // No scope
|
|
143
|
+
];
|
|
144
|
+
const message = messageComponents.join(':');
|
|
145
|
+
const isValid = await identity.verify(message, response.signature);
|
|
146
|
+
(0, vitest_1.expect)(isValid).toBe(true);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
(0, vitest_1.describe)('timestamp tolerance', () => {
|
|
150
|
+
(0, vitest_1.it)('should accept challenges within tolerance window', async () => {
|
|
151
|
+
// Create identity with 5 second tolerance
|
|
152
|
+
const strictIdentity = await index_1.MCPIdentity.init({
|
|
153
|
+
timestampTolerance: 5000
|
|
154
|
+
});
|
|
155
|
+
const challenge = {
|
|
156
|
+
nonce: crypto.generateNonce(),
|
|
157
|
+
timestamp: Date.now() - 4000, // 4 seconds ago
|
|
158
|
+
};
|
|
159
|
+
// Should succeed
|
|
160
|
+
const response = await strictIdentity.respondToChallenge(challenge);
|
|
161
|
+
(0, vitest_1.expect)(response).toBeDefined();
|
|
162
|
+
});
|
|
163
|
+
(0, vitest_1.it)('should reject challenges outside tolerance window', async () => {
|
|
164
|
+
// Create identity with 5 second tolerance
|
|
165
|
+
const strictIdentity = await index_1.MCPIdentity.init({
|
|
166
|
+
timestampTolerance: 5000,
|
|
167
|
+
forceNew: true
|
|
168
|
+
});
|
|
169
|
+
const challenge = {
|
|
170
|
+
nonce: crypto.generateNonce(),
|
|
171
|
+
timestamp: Date.now() - 6000, // 6 seconds ago
|
|
172
|
+
};
|
|
173
|
+
// Should fail
|
|
174
|
+
await (0, vitest_1.expect)(strictIdentity.respondToChallenge(challenge))
|
|
175
|
+
.rejects.toThrow('Challenge expired');
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
(0, vitest_1.describe)('nonce tracking', () => {
|
|
179
|
+
(0, vitest_1.it)('should allow disabling nonce tracking', async () => {
|
|
180
|
+
const identityNoTracking = await index_1.MCPIdentity.init({
|
|
181
|
+
enableNonceTracking: false,
|
|
182
|
+
forceNew: true
|
|
183
|
+
});
|
|
184
|
+
const challenge = {
|
|
185
|
+
nonce: crypto.generateNonce(),
|
|
186
|
+
timestamp: Date.now(),
|
|
187
|
+
};
|
|
188
|
+
// Should succeed multiple times
|
|
189
|
+
await identityNoTracking.respondToChallenge(challenge);
|
|
190
|
+
await identityNoTracking.respondToChallenge(challenge);
|
|
191
|
+
// No error thrown
|
|
192
|
+
(0, vitest_1.expect)(true).toBe(true);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
(0, vitest_1.describe)('getCapabilities', () => {
|
|
196
|
+
(0, vitest_1.it)('should advertise MCP-I capabilities', () => {
|
|
197
|
+
const capabilities = identity.getCapabilities();
|
|
198
|
+
(0, vitest_1.expect)(capabilities.version).toBe('1.0');
|
|
199
|
+
(0, vitest_1.expect)(capabilities.did).toBe('did:web:knowthat.ai:agents:test-agent');
|
|
200
|
+
(0, vitest_1.expect)(capabilities.conformanceLevel).toBe(2);
|
|
201
|
+
(0, vitest_1.expect)(capabilities.handshakeSupported).toBe(true);
|
|
202
|
+
(0, vitest_1.expect)(capabilities.handshakeEndpoint).toBe('/_mcp-i/handshake');
|
|
203
|
+
(0, vitest_1.expect)(capabilities.verificationEndpoint).toBe('https://knowthat.ai/api/agents/did:web:knowthat.ai:agents:test-agent/verify');
|
|
204
|
+
(0, vitest_1.expect)(capabilities.publicKey).toBeDefined();
|
|
205
|
+
(0, vitest_1.expect)(capabilities.publicKey).toMatch(/^[A-Za-z0-9+/]+=*$/); // Base64 format
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
(0, vitest_1.describe)('static methods', () => {
|
|
209
|
+
(0, vitest_1.it)('should generate nonces', () => {
|
|
210
|
+
const nonce1 = index_1.MCPIdentity.generateNonce();
|
|
211
|
+
const nonce2 = index_1.MCPIdentity.generateNonce();
|
|
212
|
+
(0, vitest_1.expect)(nonce1).toHaveLength(64);
|
|
213
|
+
(0, vitest_1.expect)(nonce2).toHaveLength(64);
|
|
214
|
+
(0, vitest_1.expect)(nonce1).not.toEqual(nonce2);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
//# sourceMappingURL=challenge-response.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"challenge-response.test.js","sourceRoot":"","sources":["../../src/__tests__/challenge-response.test.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,mCAAwE;AACxE,oCAAsC;AACtC,kDAAmC;AAEnC,mCAAmC;AACnC,WAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAEhB,mCAAmC;AACnC,WAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IACnB,UAAU,EAAE,WAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC;IAC9B,YAAY,EAAE,WAAE,CAAC,EAAE,EAAE;IACrB,aAAa,EAAE,WAAE,CAAC,EAAE,EAAE;CACvB,CAAC,CAAC,CAAA;AAEH,IAAA,iBAAQ,EAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,IAAI,QAAqB,CAAC;IAC1B,IAAI,OAAkD,CAAC;IAEvD,IAAA,mBAAU,EAAC,KAAK,IAAI,EAAE;QACpB,iDAAiD;QACjD,OAAO,GAAG,MAAM,MAAM,CAAC,eAAe,EAAE,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,uCAAuC,CAAC;QAChE,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,OAA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,EAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACjE,IAAA,eAAM,EAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,6EAA6E,CAAC,CAAC;YAC9H,IAAA,eAAM,EAAC,YAAY,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YAC7C,IAAA,eAAM,EAAC,YAAY,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,gBAAgB;QAChF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAA,iBAAQ,EAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,IAAA,WAAE,EAAC,wBAAwB,EAAE,GAAG,EAAE;YAChC,MAAM,MAAM,GAAG,mBAAW,CAAC,aAAa,EAAE,CAAC;YAC3C,MAAM,MAAM,GAAG,mBAAW,CAAC,aAAa,EAAE,CAAC;YAE3C,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;YAChC,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;YAChC,IAAA,eAAM,EAAC,MAAM,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/crypto.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tests for cryptographic utilities
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const vitest_1 = require("vitest");
|
|
40
|
+
const crypto = __importStar(require("../crypto"));
|
|
41
|
+
(0, vitest_1.describe)('Cryptographic Utilities', () => {
|
|
42
|
+
(0, vitest_1.describe)('generateKeyPair', () => {
|
|
43
|
+
(0, vitest_1.it)('should generate a valid Ed25519 key pair', async () => {
|
|
44
|
+
const keyPair = await crypto.generateKeyPair();
|
|
45
|
+
(0, vitest_1.expect)(keyPair.publicKey).toBeDefined();
|
|
46
|
+
(0, vitest_1.expect)(keyPair.privateKey).toBeDefined();
|
|
47
|
+
(0, vitest_1.expect)(Buffer.from(keyPair.publicKey, 'base64')).toHaveLength(32);
|
|
48
|
+
(0, vitest_1.expect)(Buffer.from(keyPair.privateKey, 'base64')).toHaveLength(32);
|
|
49
|
+
});
|
|
50
|
+
(0, vitest_1.it)('should generate different key pairs each time', async () => {
|
|
51
|
+
const keyPair1 = await crypto.generateKeyPair();
|
|
52
|
+
const keyPair2 = await crypto.generateKeyPair();
|
|
53
|
+
(0, vitest_1.expect)(keyPair1.publicKey).not.toEqual(keyPair2.publicKey);
|
|
54
|
+
(0, vitest_1.expect)(keyPair1.privateKey).not.toEqual(keyPair2.privateKey);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
(0, vitest_1.describe)('sign and verify', () => {
|
|
58
|
+
let keyPair;
|
|
59
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
60
|
+
keyPair = await crypto.generateKeyPair();
|
|
61
|
+
});
|
|
62
|
+
(0, vitest_1.it)('should sign and verify a string message', async () => {
|
|
63
|
+
const message = 'Hello, MCP-I!';
|
|
64
|
+
const signature = await crypto.sign(message, keyPair.privateKey);
|
|
65
|
+
(0, vitest_1.expect)(signature).toBeDefined();
|
|
66
|
+
(0, vitest_1.expect)(typeof signature).toBe('string');
|
|
67
|
+
const isValid = await crypto.verify(message, signature, keyPair.publicKey);
|
|
68
|
+
(0, vitest_1.expect)(isValid).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
(0, vitest_1.it)('should sign and verify a buffer message', async () => {
|
|
71
|
+
const message = Buffer.from('Binary data test');
|
|
72
|
+
const signature = await crypto.sign(message, keyPair.privateKey);
|
|
73
|
+
const isValid = await crypto.verify(message, signature, keyPair.publicKey);
|
|
74
|
+
(0, vitest_1.expect)(isValid).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.it)('should fail verification with wrong message', async () => {
|
|
77
|
+
const message = 'Original message';
|
|
78
|
+
const signature = await crypto.sign(message, keyPair.privateKey);
|
|
79
|
+
const isValid = await crypto.verify('Different message', signature, keyPair.publicKey);
|
|
80
|
+
(0, vitest_1.expect)(isValid).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
(0, vitest_1.it)('should fail verification with wrong public key', async () => {
|
|
83
|
+
const message = 'Test message';
|
|
84
|
+
const signature = await crypto.sign(message, keyPair.privateKey);
|
|
85
|
+
const otherKeyPair = await crypto.generateKeyPair();
|
|
86
|
+
const isValid = await crypto.verify(message, signature, otherKeyPair.publicKey);
|
|
87
|
+
(0, vitest_1.expect)(isValid).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
(0, vitest_1.it)('should fail verification with invalid signature', async () => {
|
|
90
|
+
const message = 'Test message';
|
|
91
|
+
const invalidSignature = 'invalid-base64-signature';
|
|
92
|
+
const isValid = await crypto.verify(message, invalidSignature, keyPair.publicKey);
|
|
93
|
+
(0, vitest_1.expect)(isValid).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
(0, vitest_1.describe)('generateNonce', () => {
|
|
97
|
+
(0, vitest_1.it)('should generate a nonce of default length', () => {
|
|
98
|
+
const nonce = crypto.generateNonce();
|
|
99
|
+
(0, vitest_1.expect)(nonce).toBeDefined();
|
|
100
|
+
(0, vitest_1.expect)(nonce).toHaveLength(64); // 32 bytes = 64 hex chars
|
|
101
|
+
});
|
|
102
|
+
(0, vitest_1.it)('should generate a nonce of specified length', () => {
|
|
103
|
+
const nonce = crypto.generateNonce(16);
|
|
104
|
+
(0, vitest_1.expect)(nonce).toHaveLength(32); // 16 bytes = 32 hex chars
|
|
105
|
+
});
|
|
106
|
+
(0, vitest_1.it)('should generate different nonces each time', () => {
|
|
107
|
+
const nonce1 = crypto.generateNonce();
|
|
108
|
+
const nonce2 = crypto.generateNonce();
|
|
109
|
+
(0, vitest_1.expect)(nonce1).not.toEqual(nonce2);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
(0, vitest_1.describe)('constantTimeEqual', () => {
|
|
113
|
+
(0, vitest_1.it)('should return true for equal strings', () => {
|
|
114
|
+
const result = crypto.constantTimeEqual('hello', 'hello');
|
|
115
|
+
(0, vitest_1.expect)(result).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
(0, vitest_1.it)('should return false for different strings', () => {
|
|
118
|
+
const result = crypto.constantTimeEqual('hello', 'world');
|
|
119
|
+
(0, vitest_1.expect)(result).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
(0, vitest_1.it)('should return false for different length strings', () => {
|
|
122
|
+
const result = crypto.constantTimeEqual('hello', 'hello world');
|
|
123
|
+
(0, vitest_1.expect)(result).toBe(false);
|
|
124
|
+
});
|
|
125
|
+
(0, vitest_1.it)('should handle empty strings', () => {
|
|
126
|
+
const result = crypto.constantTimeEqual('', '');
|
|
127
|
+
(0, vitest_1.expect)(result).toBe(true);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
(0, vitest_1.describe)('publicKeyToDid', () => {
|
|
131
|
+
(0, vitest_1.it)('should convert Ed25519 public key to did:key format', async () => {
|
|
132
|
+
const keyPair = await crypto.generateKeyPair();
|
|
133
|
+
const did = crypto.publicKeyToDid(keyPair.publicKey);
|
|
134
|
+
// Our simplified implementation uses base64url-like encoding
|
|
135
|
+
(0, vitest_1.expect)(did).toMatch(/^did:key:z[A-Za-z0-9_-]+$/);
|
|
136
|
+
(0, vitest_1.expect)(did).toContain('did:key:z');
|
|
137
|
+
});
|
|
138
|
+
(0, vitest_1.it)('should generate consistent DIDs for the same public key', async () => {
|
|
139
|
+
const keyPair = await crypto.generateKeyPair();
|
|
140
|
+
const did1 = crypto.publicKeyToDid(keyPair.publicKey);
|
|
141
|
+
const did2 = crypto.publicKeyToDid(keyPair.publicKey);
|
|
142
|
+
(0, vitest_1.expect)(did1).toEqual(did2);
|
|
143
|
+
});
|
|
144
|
+
(0, vitest_1.it)('should generate different DIDs for different public keys', async () => {
|
|
145
|
+
const keyPair1 = await crypto.generateKeyPair();
|
|
146
|
+
const keyPair2 = await crypto.generateKeyPair();
|
|
147
|
+
const did1 = crypto.publicKeyToDid(keyPair1.publicKey);
|
|
148
|
+
const did2 = crypto.publicKeyToDid(keyPair2.publicKey);
|
|
149
|
+
(0, vitest_1.expect)(did1).not.toEqual(did2);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
//# sourceMappingURL=crypto.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.test.js","sourceRoot":"","sources":["../../src/__tests__/crypto.test.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,mCAAyD;AACzD,kDAAmC;AAEnC,IAAA,iBAAQ,EAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,IAAA,iBAAQ,EAAC,iBAAiB,EAAE,GAAG,EAAE;QAC/B,IAAA,WAAE,EAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;YACxD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,eAAe,EAAE,CAAC;YAE/C,IAAA,eAAM,EAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YACxC,IAAA,eAAM,EAAC,OAAO,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;YACzC,IAAA,eAAM,EAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;YAClE,IAAA,eAAM,EAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;Y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GAAG,CAAC,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;YACjD,IAAA,eAAM,EAAC,GAAG,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;YACvE,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,eAAe,EAAE,CAAC;YAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACtD,MAAM,IAAI,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAEtD,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,IAAA,WAAE,EAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;YACxE,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,eAAe,EAAE,CAAC;YAChD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,eAAe,EAAE,CAAC;YAEhD,MAAM,IAAI,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YACvD,MAAM,IAAI,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;YAEvD,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-enhancement module for transparent MCP-I integration
|
|
3
|
+
*
|
|
4
|
+
* This module automatically wraps MCP server instances to add identity
|
|
5
|
+
* without requiring any code changes or type modifications.
|
|
6
|
+
*/
|
|
7
|
+
import { MCPIdentity } from './index';
|
|
8
|
+
/**
|
|
9
|
+
* Internal type for MCP server instance
|
|
10
|
+
*/
|
|
11
|
+
interface MCPServerLike {
|
|
12
|
+
setRequestHandler?: (schema: any, handler: Function) => void;
|
|
13
|
+
tool?: (name: string, schema: any, handler: Function) => void;
|
|
14
|
+
resource?: (name: string, template: any, handler: Function) => void;
|
|
15
|
+
prompt?: (name: string, schema: any, handler: Function) => void;
|
|
16
|
+
_mcpIdentityEnhanced?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Enhance an MCP server instance with automatic identity
|
|
20
|
+
*/
|
|
21
|
+
export declare function enhanceMCPServer(server: MCPServerLike): Promise<MCPServerLike>;
|
|
22
|
+
/**
|
|
23
|
+
* Proxy constructor for automatic enhancement
|
|
24
|
+
*/
|
|
25
|
+
export declare function createMCPServerProxy(ServerClass: any): any;
|
|
26
|
+
/**
|
|
27
|
+
* Module loader hook for automatic enhancement
|
|
28
|
+
* This can be used with Node.js --loader flag
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolve(specifier: string, context: any, defaultResolve: Function): Promise<any>;
|
|
31
|
+
export declare function load(url: string, context: any, defaultLoad: Function): Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Get the current identity instance
|
|
34
|
+
*/
|
|
35
|
+
export declare function getCurrentIdentity(): MCPIdentity | null;
|
|
36
|
+
/**
|
|
37
|
+
* Initialize identity explicitly (optional)
|
|
38
|
+
*/
|
|
39
|
+
export declare function initializeIdentity(options?: any): Promise<MCPIdentity>;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=auto-enhance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-enhance.d.ts","sourceRoot":"","sources":["../src/auto-enhance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAMtC;;GAEG;AACH,UAAU,aAAa;IACrB,iBAAiB,CAAC,EAAE,CAAC,MAA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