@kya-os/mcp-i 1.2.2 → 1.2.3

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 (42) hide show
  1. package/dist/compiler/get-webpack-config/get-externals.js +2 -2
  2. package/dist/compiler/get-webpack-config/plugins.js +1 -13
  3. package/dist/runtime/session.js +4 -2
  4. package/dist/storage/encryption.d.ts +61 -0
  5. package/dist/storage/encryption.js +151 -0
  6. package/dist/storage/index.d.ts +11 -0
  7. package/dist/storage/index.js +26 -0
  8. package/package.json +2 -2
  9. package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.d.ts +0 -4
  10. package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.js +0 -176
  11. package/dist/cache/__tests__/concurrency.test.d.ts +0 -5
  12. package/dist/cache/__tests__/concurrency.test.js +0 -300
  13. package/dist/cache/__tests__/dynamodb-nonce-cache.test.d.ts +0 -4
  14. package/dist/cache/__tests__/dynamodb-nonce-cache.test.js +0 -176
  15. package/dist/cache/__tests__/memory-nonce-cache.test.d.ts +0 -4
  16. package/dist/cache/__tests__/memory-nonce-cache.test.js +0 -132
  17. package/dist/cache/__tests__/nonce-cache-factory-simple.test.d.ts +0 -4
  18. package/dist/cache/__tests__/nonce-cache-factory-simple.test.js +0 -133
  19. package/dist/cache/__tests__/nonce-cache-factory.test.d.ts +0 -4
  20. package/dist/cache/__tests__/nonce-cache-factory.test.js +0 -252
  21. package/dist/cache/__tests__/redis-nonce-cache.test.d.ts +0 -4
  22. package/dist/cache/__tests__/redis-nonce-cache.test.js +0 -95
  23. package/dist/runtime/__tests__/audit.test.d.ts +0 -4
  24. package/dist/runtime/__tests__/audit.test.js +0 -328
  25. package/dist/runtime/__tests__/identity.test.d.ts +0 -4
  26. package/dist/runtime/__tests__/identity.test.js +0 -164
  27. package/dist/runtime/__tests__/mcpi-runtime.test.d.ts +0 -4
  28. package/dist/runtime/__tests__/mcpi-runtime.test.js +0 -372
  29. package/dist/runtime/__tests__/proof.test.d.ts +0 -4
  30. package/dist/runtime/__tests__/proof.test.js +0 -302
  31. package/dist/runtime/__tests__/session.test.d.ts +0 -4
  32. package/dist/runtime/__tests__/session.test.js +0 -254
  33. package/dist/runtime/__tests__/well-known.test.d.ts +0 -4
  34. package/dist/runtime/__tests__/well-known.test.js +0 -312
  35. package/dist/test/__tests__/nonce-cache-integration.test.d.ts +0 -1
  36. package/dist/test/__tests__/nonce-cache-integration.test.js +0 -116
  37. package/dist/test/__tests__/nonce-cache.test.d.ts +0 -1
  38. package/dist/test/__tests__/nonce-cache.test.js +0 -122
  39. package/dist/test/__tests__/runtime-integration.test.d.ts +0 -4
  40. package/dist/test/__tests__/runtime-integration.test.js +0 -192
  41. package/dist/test/__tests__/test-infrastructure.test.d.ts +0 -4
  42. package/dist/test/__tests__/test-infrastructure.test.js +0 -178
@@ -1,254 +0,0 @@
1
- "use strict";
2
- /**
3
- * Tests for Session Management System
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const vitest_1 = require("vitest");
7
- const session_js_1 = require("../session.js");
8
- const memory_nonce_cache_js_1 = require("../../cache/memory-nonce-cache.js");
9
- (0, vitest_1.describe)("SessionManager", () => {
10
- let sessionManager;
11
- let mockNonceCache;
12
- (0, vitest_1.beforeEach)(() => {
13
- mockNonceCache = new memory_nonce_cache_js_1.MemoryNonceCache();
14
- sessionManager = new session_js_1.SessionManager({
15
- timestampSkewSeconds: 120,
16
- sessionTtlMinutes: 30,
17
- nonceCache: mockNonceCache,
18
- });
19
- // Mock console.warn to avoid noise in tests
20
- vitest_1.vi.spyOn(console, "warn").mockImplementation(() => { });
21
- });
22
- (0, vitest_1.afterEach)(() => {
23
- mockNonceCache.destroy();
24
- vitest_1.vi.restoreAllMocks();
25
- });
26
- (0, vitest_1.describe)("Handshake Validation", () => {
27
- (0, vitest_1.it)("should accept valid handshake", async () => {
28
- const request = {
29
- nonce: "test-nonce-123",
30
- audience: "example.com",
31
- timestamp: Math.floor(Date.now() / 1000),
32
- };
33
- const result = await sessionManager.validateHandshake(request);
34
- (0, vitest_1.expect)(result.success).toBe(true);
35
- (0, vitest_1.expect)(result.session).toBeDefined();
36
- (0, vitest_1.expect)(result.session.audience).toBe("example.com");
37
- (0, vitest_1.expect)(result.session.nonce).toBe("test-nonce-123");
38
- (0, vitest_1.expect)(result.session.sessionId).toMatch(/^sess_/);
39
- });
40
- (0, vitest_1.it)("should reject handshake with timestamp too old", async () => {
41
- const request = {
42
- nonce: "test-nonce-old",
43
- audience: "example.com",
44
- timestamp: Math.floor(Date.now() / 1000) - 200, // 200 seconds ago
45
- };
46
- const result = await sessionManager.validateHandshake(request);
47
- (0, vitest_1.expect)(result.success).toBe(false);
48
- (0, vitest_1.expect)(result.error?.code).toBe("XMCP_I_EHANDSHAKE");
49
- (0, vitest_1.expect)(result.error?.message).toContain("Timestamp outside acceptable range");
50
- (0, vitest_1.expect)(result.error?.remediation).toContain("Check NTP sync");
51
- });
52
- (0, vitest_1.it)("should reject handshake with timestamp too far in future", async () => {
53
- const request = {
54
- nonce: "test-nonce-future",
55
- audience: "example.com",
56
- timestamp: Math.floor(Date.now() / 1000) + 200, // 200 seconds in future
57
- };
58
- const result = await sessionManager.validateHandshake(request);
59
- (0, vitest_1.expect)(result.success).toBe(false);
60
- (0, vitest_1.expect)(result.error?.code).toBe("XMCP_I_EHANDSHAKE");
61
- (0, vitest_1.expect)(result.error?.message).toContain("Timestamp outside acceptable range");
62
- });
63
- (0, vitest_1.it)("should reject duplicate nonce (replay attack)", async () => {
64
- const request = {
65
- nonce: "duplicate-nonce",
66
- audience: "example.com",
67
- timestamp: Math.floor(Date.now() / 1000),
68
- };
69
- // First request should succeed
70
- const result1 = await sessionManager.validateHandshake(request);
71
- (0, vitest_1.expect)(result1.success).toBe(true);
72
- // Second request with same nonce should fail
73
- const result2 = await sessionManager.validateHandshake(request);
74
- (0, vitest_1.expect)(result2.success).toBe(false);
75
- (0, vitest_1.expect)(result2.error?.code).toBe("XMCP_I_EHANDSHAKE");
76
- (0, vitest_1.expect)(result2.error?.message).toContain("Nonce already used");
77
- });
78
- (0, vitest_1.it)("should respect custom timestamp skew configuration", async () => {
79
- const customManager = new session_js_1.SessionManager({
80
- timestampSkewSeconds: 60, // 1 minute
81
- nonceCache: mockNonceCache,
82
- });
83
- const request = {
84
- nonce: "test-nonce-skew",
85
- audience: "example.com",
86
- timestamp: Math.floor(Date.now() / 1000) - 90, // 90 seconds ago
87
- };
88
- const result = await customManager.validateHandshake(request);
89
- (0, vitest_1.expect)(result.success).toBe(false);
90
- (0, vitest_1.expect)(result.error?.message).toContain("±60s");
91
- });
92
- });
93
- (0, vitest_1.describe)("Session Management", () => {
94
- (0, vitest_1.it)("should retrieve active session", async () => {
95
- const request = {
96
- nonce: "session-test-nonce",
97
- audience: "example.com",
98
- timestamp: Math.floor(Date.now() / 1000),
99
- };
100
- const handshakeResult = await sessionManager.validateHandshake(request);
101
- (0, vitest_1.expect)(handshakeResult.success).toBe(true);
102
- const sessionId = handshakeResult.session.sessionId;
103
- const retrievedSession = await sessionManager.getSession(sessionId);
104
- (0, vitest_1.expect)(retrievedSession).toBeDefined();
105
- (0, vitest_1.expect)(retrievedSession.sessionId).toBe(sessionId);
106
- (0, vitest_1.expect)(retrievedSession.audience).toBe("example.com");
107
- });
108
- (0, vitest_1.it)("should return null for non-existent session", async () => {
109
- const session = await sessionManager.getSession("non-existent-session");
110
- (0, vitest_1.expect)(session).toBeNull();
111
- });
112
- (0, vitest_1.it)("should expire session after idle timeout", async () => {
113
- const shortTtlManager = new session_js_1.SessionManager({
114
- sessionTtlMinutes: 0.01, // 0.6 seconds
115
- nonceCache: mockNonceCache,
116
- });
117
- const request = {
118
- nonce: "expire-test-nonce",
119
- audience: "example.com",
120
- timestamp: Math.floor(Date.now() / 1000),
121
- };
122
- const handshakeResult = await shortTtlManager.validateHandshake(request);
123
- const sessionId = handshakeResult.session.sessionId;
124
- // Session should exist initially
125
- let session = await shortTtlManager.getSession(sessionId);
126
- (0, vitest_1.expect)(session).toBeDefined();
127
- // Wait for expiration
128
- await new Promise((resolve) => setTimeout(resolve, 1000));
129
- // Session should be expired
130
- session = await shortTtlManager.getSession(sessionId);
131
- (0, vitest_1.expect)(session).toBeNull();
132
- });
133
- (0, vitest_1.it)("should update last activity on session access", async () => {
134
- const request = {
135
- nonce: "activity-test-nonce",
136
- audience: "example.com",
137
- timestamp: Math.floor(Date.now() / 1000),
138
- };
139
- const handshakeResult = await sessionManager.validateHandshake(request);
140
- const sessionId = handshakeResult.session.sessionId;
141
- const initialActivity = handshakeResult.session.lastActivity;
142
- // Wait a bit to ensure time difference
143
- await new Promise((resolve) => setTimeout(resolve, 1100));
144
- // Access session
145
- const session = await sessionManager.getSession(sessionId);
146
- (0, vitest_1.expect)(session.lastActivity).toBeGreaterThan(initialActivity);
147
- });
148
- (0, vitest_1.it)("should respect absolute session lifetime when configured", async () => {
149
- const absoluteLifetimeManager = new session_js_1.SessionManager({
150
- sessionTtlMinutes: 60, // 1 hour idle
151
- absoluteSessionLifetime: 0.01, // 0.6 seconds absolute
152
- nonceCache: mockNonceCache,
153
- });
154
- const request = {
155
- nonce: "absolute-test-nonce",
156
- audience: "example.com",
157
- timestamp: Math.floor(Date.now() / 1000),
158
- };
159
- const handshakeResult = await absoluteLifetimeManager.validateHandshake(request);
160
- const sessionId = handshakeResult.session.sessionId;
161
- // Wait for absolute expiration
162
- await new Promise((resolve) => setTimeout(resolve, 1000));
163
- // Session should be expired due to absolute lifetime
164
- const session = await absoluteLifetimeManager.getSession(sessionId);
165
- (0, vitest_1.expect)(session).toBeNull();
166
- });
167
- });
168
- (0, vitest_1.describe)("Cleanup", () => {
169
- (0, vitest_1.it)("should clean up expired sessions", async () => {
170
- const shortTtlManager = new session_js_1.SessionManager({
171
- sessionTtlMinutes: 0.01, // 0.6 seconds
172
- nonceCache: mockNonceCache,
173
- });
174
- const request = {
175
- nonce: "cleanup-test-nonce",
176
- audience: "example.com",
177
- timestamp: Math.floor(Date.now() / 1000),
178
- };
179
- await shortTtlManager.validateHandshake(request);
180
- // Should have 1 active session
181
- (0, vitest_1.expect)(shortTtlManager.getStats().activeSessions).toBe(1);
182
- // Wait for expiration
183
- await new Promise((resolve) => setTimeout(resolve, 1000));
184
- // Cleanup
185
- await shortTtlManager.cleanup();
186
- // Should have 0 active sessions
187
- (0, vitest_1.expect)(shortTtlManager.getStats().activeSessions).toBe(0);
188
- });
189
- });
190
- (0, vitest_1.describe)("Statistics", () => {
191
- (0, vitest_1.it)("should provide session statistics", async () => {
192
- const stats = sessionManager.getStats();
193
- (0, vitest_1.expect)(stats).toHaveProperty("activeSessions");
194
- (0, vitest_1.expect)(stats).toHaveProperty("config");
195
- (0, vitest_1.expect)(stats.config.timestampSkewSeconds).toBe(120);
196
- (0, vitest_1.expect)(stats.config.sessionTtlMinutes).toBe(30);
197
- (0, vitest_1.expect)(stats.config.cacheType).toBe("MemoryNonceCache");
198
- });
199
- });
200
- (0, vitest_1.describe)("Environment Configuration", () => {
201
- (0, vitest_1.it)("should read configuration from environment variables", () => {
202
- // Mock environment variables
203
- const originalEnv = process.env;
204
- process.env.XMCP_I_TS_SKEW_SEC = "60";
205
- process.env.XMCP_I_SESSION_TTL_MIN = "15";
206
- const envManager = new session_js_1.SessionManager();
207
- const stats = envManager.getStats();
208
- (0, vitest_1.expect)(stats.config.timestampSkewSeconds).toBe(60);
209
- (0, vitest_1.expect)(stats.config.sessionTtlMinutes).toBe(15);
210
- // Restore environment
211
- process.env = originalEnv;
212
- });
213
- });
214
- });
215
- (0, vitest_1.describe)("Utility Functions", () => {
216
- (0, vitest_1.describe)("createHandshakeRequest", () => {
217
- (0, vitest_1.it)("should create valid handshake request", () => {
218
- const request = (0, session_js_1.createHandshakeRequest)("example.com");
219
- (0, vitest_1.expect)(request.audience).toBe("example.com");
220
- (0, vitest_1.expect)(request.nonce).toBeTruthy();
221
- (0, vitest_1.expect)(request.timestamp).toBeCloseTo(Math.floor(Date.now() / 1000), 1);
222
- });
223
- (0, vitest_1.it)("should generate unique nonces", () => {
224
- const request1 = (0, session_js_1.createHandshakeRequest)("example.com");
225
- const request2 = (0, session_js_1.createHandshakeRequest)("example.com");
226
- (0, vitest_1.expect)(request1.nonce).not.toBe(request2.nonce);
227
- });
228
- });
229
- (0, vitest_1.describe)("validateHandshakeFormat", () => {
230
- (0, vitest_1.it)("should validate correct handshake format", () => {
231
- const validRequest = {
232
- nonce: "test-nonce",
233
- audience: "example.com",
234
- timestamp: Math.floor(Date.now() / 1000),
235
- };
236
- (0, vitest_1.expect)((0, session_js_1.validateHandshakeFormat)(validRequest)).toBe(true);
237
- });
238
- (0, vitest_1.it)("should reject invalid handshake formats", () => {
239
- const invalidRequests = [
240
- null,
241
- undefined,
242
- {},
243
- { nonce: "", audience: "example.com", timestamp: 123 },
244
- { nonce: "test", audience: "", timestamp: 123 },
245
- { nonce: "test", audience: "example.com", timestamp: "invalid" },
246
- { nonce: "test", audience: "example.com", timestamp: -1 },
247
- { nonce: "test", audience: "example.com", timestamp: 123.45 },
248
- ];
249
- for (const invalid of invalidRequests) {
250
- (0, vitest_1.expect)((0, session_js_1.validateHandshakeFormat)(invalid)).toBe(false);
251
- }
252
- });
253
- });
254
- });
@@ -1,4 +0,0 @@
1
- /**
2
- * Tests for Well-Known Endpoints
3
- */
4
- export {};
@@ -1,312 +0,0 @@
1
- "use strict";
2
- /**
3
- * Tests for Well-Known Endpoints
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const vitest_1 = require("vitest");
7
- const well_known_js_1 = require("../well-known.js");
8
- (0, vitest_1.describe)("WellKnownManager", () => {
9
- let wellKnownManager;
10
- let mockIdentity;
11
- let mockConfig;
12
- (0, vitest_1.beforeEach)(() => {
13
- mockIdentity = {
14
- did: "did:web:example.com:agents:test-agent",
15
- keyId: "key-test-123",
16
- privateKey: "test-private-key",
17
- publicKey: Buffer.from("test-public-key-32-bytes-long!!!").toString("base64"),
18
- createdAt: new Date().toISOString(),
19
- };
20
- mockConfig = {
21
- environment: "development",
22
- baseUrl: "https://example.com",
23
- agentMetadata: {
24
- name: "Test Agent",
25
- description: "A test XMCP-I agent",
26
- version: "1.0.0",
27
- },
28
- registryUrls: {
29
- kta: "https://knowthat.ai/agents/test-agent",
30
- mcp: "https://registry.mcp.dev/agents/test-agent",
31
- },
32
- };
33
- wellKnownManager = new well_known_js_1.WellKnownManager(mockIdentity, mockConfig);
34
- });
35
- (0, vitest_1.describe)("DID Document Generation", () => {
36
- (0, vitest_1.it)("should generate valid DID document", () => {
37
- const didDocument = wellKnownManager.generateDIDDocument();
38
- (0, vitest_1.expect)(didDocument["@context"]).toContain("https://www.w3.org/ns/did/v1");
39
- (0, vitest_1.expect)(didDocument.id).toBe(mockIdentity.did);
40
- (0, vitest_1.expect)(didDocument.verificationMethod).toHaveLength(1);
41
- (0, vitest_1.expect)(didDocument.verificationMethod[0].id).toBe("#key-test-123");
42
- (0, vitest_1.expect)(didDocument.verificationMethod[0].type).toBe("Ed25519VerificationKey2020");
43
- (0, vitest_1.expect)(didDocument.verificationMethod[0].controller).toBe(mockIdentity.did);
44
- (0, vitest_1.expect)(didDocument.verificationMethod[0].publicKeyMultibase).toMatch(/^z/);
45
- (0, vitest_1.expect)(didDocument.authentication).toEqual(["#key-test-123"]);
46
- (0, vitest_1.expect)(didDocument.assertionMethod).toEqual(["#key-test-123"]);
47
- });
48
- (0, vitest_1.it)("should include proper verification method structure", () => {
49
- const didDocument = wellKnownManager.generateDIDDocument();
50
- const verificationMethod = didDocument.verificationMethod[0];
51
- (0, vitest_1.expect)(verificationMethod.id).toBe(`#${mockIdentity.keyId}`);
52
- (0, vitest_1.expect)(verificationMethod.type).toBe("Ed25519VerificationKey2020");
53
- (0, vitest_1.expect)(verificationMethod.controller).toBe(mockIdentity.did);
54
- (0, vitest_1.expect)(verificationMethod.publicKeyMultibase).toBeTruthy();
55
- });
56
- (0, vitest_1.it)("should encode public key as multibase", () => {
57
- const didDocument = wellKnownManager.generateDIDDocument();
58
- const publicKeyMultibase = didDocument.verificationMethod[0].publicKeyMultibase;
59
- (0, vitest_1.expect)(publicKeyMultibase).toMatch(/^z[1-9A-HJ-NP-Za-km-z]+$/); // Base58btc format
60
- });
61
- });
62
- (0, vitest_1.describe)("Agent Document Generation", () => {
63
- (0, vitest_1.it)("should generate valid agent document", () => {
64
- const agentDocument = wellKnownManager.generateAgentDocument();
65
- (0, vitest_1.expect)(agentDocument.id).toBe(mockIdentity.did);
66
- (0, vitest_1.expect)(agentDocument.capabilities["mcp-i"]).toEqual([
67
- "handshake",
68
- "signing",
69
- "verification",
70
- ]);
71
- (0, vitest_1.expect)(agentDocument.registry?.kta).toBe("https://knowthat.ai/agents/test-agent");
72
- (0, vitest_1.expect)(agentDocument.registry?.mcp).toBe("https://registry.mcp.dev/agents/test-agent");
73
- (0, vitest_1.expect)(agentDocument.metadata?.name).toBe("Test Agent");
74
- (0, vitest_1.expect)(agentDocument.metadata?.description).toBe("A test XMCP-I agent");
75
- (0, vitest_1.expect)(agentDocument.metadata?.version).toBe("1.0.0");
76
- });
77
- (0, vitest_1.it)("should include exact MCP-I capability triplet", () => {
78
- const agentDocument = wellKnownManager.generateAgentDocument();
79
- const capabilities = agentDocument.capabilities["mcp-i"];
80
- (0, vitest_1.expect)(capabilities).toHaveLength(3);
81
- (0, vitest_1.expect)(capabilities).toContain("handshake");
82
- (0, vitest_1.expect)(capabilities).toContain("signing");
83
- (0, vitest_1.expect)(capabilities).toContain("verification");
84
- (0, vitest_1.expect)(capabilities).toEqual(["handshake", "signing", "verification"]);
85
- });
86
- (0, vitest_1.it)("should work without optional metadata", () => {
87
- const minimalConfig = {
88
- environment: "development",
89
- };
90
- const minimalManager = new well_known_js_1.WellKnownManager(mockIdentity, minimalConfig);
91
- const agentDocument = minimalManager.generateAgentDocument();
92
- (0, vitest_1.expect)(agentDocument.id).toBe(mockIdentity.did);
93
- (0, vitest_1.expect)(agentDocument.capabilities["mcp-i"]).toEqual([
94
- "handshake",
95
- "signing",
96
- "verification",
97
- ]);
98
- (0, vitest_1.expect)(agentDocument.registry).toBeUndefined();
99
- (0, vitest_1.expect)(agentDocument.metadata).toBeUndefined();
100
- });
101
- });
102
- (0, vitest_1.describe)("HTTP Headers", () => {
103
- (0, vitest_1.it)("should return correct headers for DID document in development", () => {
104
- const headers = wellKnownManager.getDIDDocumentHeaders();
105
- (0, vitest_1.expect)(headers["Content-Type"]).toBe("application/did+json");
106
- (0, vitest_1.expect)(headers["Cache-Control"]).toBe("no-store");
107
- });
108
- (0, vitest_1.it)("should return correct headers for DID document in production", () => {
109
- const prodConfig = { ...mockConfig, environment: "production" };
110
- const prodManager = new well_known_js_1.WellKnownManager(mockIdentity, prodConfig);
111
- const headers = prodManager.getDIDDocumentHeaders();
112
- (0, vitest_1.expect)(headers["Content-Type"]).toBe("application/did+json");
113
- (0, vitest_1.expect)(headers["Cache-Control"]).toBe("public, max-age=300");
114
- });
115
- (0, vitest_1.it)("should return correct headers for agent document in development", () => {
116
- const headers = wellKnownManager.getAgentDocumentHeaders();
117
- (0, vitest_1.expect)(headers["Content-Type"]).toBe("application/json");
118
- (0, vitest_1.expect)(headers["Cache-Control"]).toBe("no-store");
119
- });
120
- (0, vitest_1.it)("should return correct headers for agent document in production", () => {
121
- const prodConfig = { ...mockConfig, environment: "production" };
122
- const prodManager = new well_known_js_1.WellKnownManager(mockIdentity, prodConfig);
123
- const headers = prodManager.getAgentDocumentHeaders();
124
- (0, vitest_1.expect)(headers["Content-Type"]).toBe("application/json");
125
- (0, vitest_1.expect)(headers["Cache-Control"]).toBe("public, max-age=300");
126
- });
127
- });
128
- (0, vitest_1.describe)("Configuration Management", () => {
129
- (0, vitest_1.it)("should update configuration", () => {
130
- const newConfig = {
131
- environment: "production",
132
- agentMetadata: {
133
- name: "Updated Agent",
134
- },
135
- };
136
- wellKnownManager.updateConfig(newConfig);
137
- const config = wellKnownManager.getConfig();
138
- (0, vitest_1.expect)(config.environment).toBe("production");
139
- (0, vitest_1.expect)(config.agentMetadata?.name).toBe("Updated Agent");
140
- (0, vitest_1.expect)(config.baseUrl).toBe("https://example.com"); // Should preserve existing values
141
- });
142
- (0, vitest_1.it)("should return current configuration", () => {
143
- const config = wellKnownManager.getConfig();
144
- (0, vitest_1.expect)(config.environment).toBe("development");
145
- (0, vitest_1.expect)(config.baseUrl).toBe("https://example.com");
146
- (0, vitest_1.expect)(config.agentMetadata?.name).toBe("Test Agent");
147
- });
148
- });
149
- });
150
- (0, vitest_1.describe)("Well-Known Handler", () => {
151
- let handler;
152
- let mockIdentity;
153
- let mockConfig;
154
- (0, vitest_1.beforeEach)(() => {
155
- mockIdentity = {
156
- did: "did:web:example.com:agents:test-agent",
157
- keyId: "key-test-123",
158
- privateKey: "test-private-key",
159
- publicKey: Buffer.from("test-public-key-32-bytes-long!!!").toString("base64"),
160
- createdAt: new Date().toISOString(),
161
- };
162
- mockConfig = {
163
- environment: "development",
164
- baseUrl: "https://example.com",
165
- };
166
- handler = (0, well_known_js_1.createWellKnownHandler)(mockIdentity, mockConfig);
167
- });
168
- (0, vitest_1.describe)("DID Document Handler", () => {
169
- (0, vitest_1.it)("should handle DID document request successfully", () => {
170
- const response = handler.handleDIDDocument();
171
- (0, vitest_1.expect)(response.status).toBe(200);
172
- (0, vitest_1.expect)(response.headers["Content-Type"]).toBe("application/did+json");
173
- (0, vitest_1.expect)(response.body).toBeTruthy();
174
- const didDocument = JSON.parse(response.body);
175
- (0, vitest_1.expect)(didDocument.id).toBe(mockIdentity.did);
176
- (0, vitest_1.expect)(didDocument.verificationMethod).toHaveLength(1);
177
- });
178
- (0, vitest_1.it)("should return valid JSON in response body", () => {
179
- const response = handler.handleDIDDocument();
180
- (0, vitest_1.expect)(() => JSON.parse(response.body)).not.toThrow();
181
- const didDocument = JSON.parse(response.body);
182
- (0, vitest_1.expect)((0, well_known_js_1.validateDIDDocument)(didDocument)).toBe(true);
183
- });
184
- });
185
- (0, vitest_1.describe)("Agent Document Handler", () => {
186
- (0, vitest_1.it)("should handle agent document request successfully", () => {
187
- const response = handler.handleAgentDocument();
188
- (0, vitest_1.expect)(response.status).toBe(200);
189
- (0, vitest_1.expect)(response.headers["Content-Type"]).toBe("application/json");
190
- (0, vitest_1.expect)(response.body).toBeTruthy();
191
- const agentDocument = JSON.parse(response.body);
192
- (0, vitest_1.expect)(agentDocument.id).toBe(mockIdentity.did);
193
- (0, vitest_1.expect)(agentDocument.capabilities["mcp-i"]).toEqual([
194
- "handshake",
195
- "signing",
196
- "verification",
197
- ]);
198
- });
199
- (0, vitest_1.it)("should return valid JSON in response body", () => {
200
- const response = handler.handleAgentDocument();
201
- (0, vitest_1.expect)(() => JSON.parse(response.body)).not.toThrow();
202
- const agentDocument = JSON.parse(response.body);
203
- (0, vitest_1.expect)((0, well_known_js_1.validateAgentDocument)(agentDocument)).toBe(true);
204
- });
205
- });
206
- });
207
- (0, vitest_1.describe)("Validation Functions", () => {
208
- (0, vitest_1.describe)("validateDIDDocument", () => {
209
- (0, vitest_1.it)("should validate correct DID document", () => {
210
- const validDIDDocument = {
211
- "@context": ["https://www.w3.org/ns/did/v1"],
212
- id: "did:web:example.com:agents:test-agent",
213
- verificationMethod: [
214
- {
215
- id: "#key-test-123",
216
- type: "Ed25519VerificationKey2020",
217
- controller: "did:web:example.com:agents:test-agent",
218
- publicKeyMultibase: "z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
219
- },
220
- ],
221
- authentication: ["#key-test-123"],
222
- assertionMethod: ["#key-test-123"],
223
- };
224
- (0, vitest_1.expect)((0, well_known_js_1.validateDIDDocument)(validDIDDocument)).toBe(true);
225
- });
226
- (0, vitest_1.it)("should reject invalid DID documents", () => {
227
- const invalidDocuments = [
228
- null,
229
- undefined,
230
- {},
231
- { "@context": "invalid" },
232
- { "@context": [], id: "not-a-did" },
233
- {
234
- "@context": [],
235
- id: "did:web:example.com",
236
- verificationMethod: "invalid",
237
- },
238
- ];
239
- for (const doc of invalidDocuments) {
240
- (0, vitest_1.expect)((0, well_known_js_1.validateDIDDocument)(doc)).toBe(false);
241
- }
242
- });
243
- });
244
- (0, vitest_1.describe)("validateAgentDocument", () => {
245
- (0, vitest_1.it)("should validate correct agent document", () => {
246
- const validAgentDocument = {
247
- id: "did:web:example.com:agents:test-agent",
248
- capabilities: {
249
- "mcp-i": ["handshake", "signing", "verification"],
250
- },
251
- };
252
- (0, vitest_1.expect)((0, well_known_js_1.validateAgentDocument)(validAgentDocument)).toBe(true);
253
- });
254
- (0, vitest_1.it)("should reject agent documents with incorrect capabilities", () => {
255
- const invalidDocuments = [
256
- {
257
- id: "did:web:example.com:agents:test-agent",
258
- capabilities: {
259
- "mcp-i": ["handshake", "signing"], // Missing verification
260
- },
261
- },
262
- {
263
- id: "did:web:example.com:agents:test-agent",
264
- capabilities: {
265
- "mcp-i": ["handshake", "signing", "verification", "extra"], // Extra capability
266
- },
267
- },
268
- {
269
- id: "did:web:example.com:agents:test-agent",
270
- capabilities: {
271
- "mcp-i": ["wrong", "capabilities", "list"],
272
- },
273
- },
274
- ];
275
- for (const doc of invalidDocuments) {
276
- (0, vitest_1.expect)((0, well_known_js_1.validateAgentDocument)(doc)).toBe(false);
277
- }
278
- });
279
- (0, vitest_1.it)("should reject invalid agent documents", () => {
280
- const invalidDocuments = [
281
- null,
282
- undefined,
283
- {},
284
- { id: "not-a-did" },
285
- { id: "did:web:example.com", capabilities: "invalid" },
286
- ];
287
- for (const doc of invalidDocuments) {
288
- (0, vitest_1.expect)((0, well_known_js_1.validateAgentDocument)(doc)).toBe(false);
289
- }
290
- });
291
- });
292
- });
293
- (0, vitest_1.describe)("Utility Functions", () => {
294
- (0, vitest_1.describe)("extractDIDFromPath", () => {
295
- (0, vitest_1.it)("should extract DID from root path", () => {
296
- const did = (0, well_known_js_1.extractDIDFromPath)("/.well-known/did.json", "https://example.com");
297
- (0, vitest_1.expect)(did).toBe("did:web:example.com");
298
- });
299
- (0, vitest_1.it)("should extract DID from nested path", () => {
300
- const did = (0, well_known_js_1.extractDIDFromPath)("/agents/my-agent/.well-known/did.json", "https://example.com");
301
- (0, vitest_1.expect)(did).toBe("did:web:example.com:agents:my-agent");
302
- });
303
- (0, vitest_1.it)("should handle complex paths", () => {
304
- const did = (0, well_known_js_1.extractDIDFromPath)("/users/alice/agents/assistant/.well-known/did.json", "https://example.com");
305
- (0, vitest_1.expect)(did).toBe("did:web:example.com:users:alice:agents:assistant");
306
- });
307
- (0, vitest_1.it)("should return null for invalid URLs", () => {
308
- const did = (0, well_known_js_1.extractDIDFromPath)("/.well-known/did.json", "invalid-url");
309
- (0, vitest_1.expect)(did).toBeNull();
310
- });
311
- });
312
- });
@@ -1 +0,0 @@
1
- export {};