@kya-os/mcp-i-core 1.1.13-canary.2 → 1.2.1-canary.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/__tests__/utils/mock-providers.d.ts +5 -3
- package/dist/__tests__/utils/mock-providers.d.ts.map +1 -1
- package/dist/__tests__/utils/mock-providers.js +23 -12
- package/dist/__tests__/utils/mock-providers.js.map +1 -1
- package/dist/index.d.ts +33 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/base.d.ts +18 -3
- package/dist/providers/base.d.ts.map +1 -1
- package/dist/providers/base.js +5 -1
- package/dist/providers/base.js.map +1 -1
- package/dist/providers/memory.d.ts +2 -2
- package/dist/providers/memory.d.ts.map +1 -1
- package/dist/providers/memory.js +9 -5
- package/dist/providers/memory.js.map +1 -1
- package/dist/runtime/base.d.ts +40 -1
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +148 -20
- package/dist/runtime/base.js.map +1 -1
- package/dist/services/access-control.service.d.ts +121 -0
- package/dist/services/access-control.service.d.ts.map +1 -0
- package/dist/services/access-control.service.js +458 -0
- package/dist/services/access-control.service.js.map +1 -0
- package/dist/services/crypto.service.d.ts +69 -0
- package/dist/services/crypto.service.d.ts.map +1 -0
- package/dist/services/crypto.service.js +225 -0
- package/dist/services/crypto.service.js.map +1 -0
- package/dist/services/errors.d.ts +49 -0
- package/dist/services/errors.d.ts.map +1 -0
- package/dist/services/errors.js +66 -0
- package/dist/services/errors.js.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +8 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/proof-verifier.d.ts +98 -0
- package/dist/services/proof-verifier.d.ts.map +1 -0
- package/dist/services/proof-verifier.js +319 -0
- package/dist/services/proof-verifier.js.map +1 -0
- package/dist/services/storage.service.d.ts +116 -0
- package/dist/services/storage.service.d.ts.map +1 -0
- package/dist/services/storage.service.js +405 -0
- package/dist/services/storage.service.js.map +1 -0
- package/dist/utils/base64.d.ts +31 -0
- package/dist/utils/base64.d.ts.map +1 -0
- package/dist/utils/base64.js +138 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/storage-keys.d.ts +120 -0
- package/dist/utils/storage-keys.d.ts.map +1 -0
- package/dist/utils/storage-keys.js +217 -0
- package/dist/utils/storage-keys.js.map +1 -0
- package/package.json +5 -4
- package/dist/compliance/schema-verifier-v2.d.ts +0 -110
- package/dist/compliance/schema-verifier-v2.d.ts.map +0 -1
- package/dist/compliance/schema-verifier-v2.js +0 -510
- package/dist/compliance/schema-verifier-v2.js.map +0 -1
- package/dist/did/resolver.d.ts +0 -92
- package/dist/did/resolver.d.ts.map +0 -1
- package/dist/did/resolver.js +0 -203
- package/dist/did/resolver.js.map +0 -1
- package/dist/proof/proof-engine.d.ts +0 -89
- package/dist/proof/proof-engine.d.ts.map +0 -1
- package/dist/proof/proof-engine.js +0 -249
- package/dist/proof/proof-engine.js.map +0 -1
- package/dist/runtime/base-v2.d.ts +0 -117
- package/dist/runtime/base-v2.d.ts.map +0 -1
- package/dist/runtime/base-v2.js +0 -328
- package/dist/runtime/base-v2.js.map +0 -1
- package/dist/types/providers.d.ts +0 -142
- package/dist/types/providers.d.ts.map +0 -1
- package/dist/types/providers.js +0 -43
- package/dist/types/providers.js.map +0 -1
- package/dist/verification/interfaces.d.ts +0 -125
- package/dist/verification/interfaces.d.ts.map +0 -1
- package/dist/verification/interfaces.js +0 -101
- package/dist/verification/interfaces.js.map +0 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Key Migration Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for migrating from old storage key formats to new composite formats.
|
|
5
|
+
* This supports Phase 3 Task 2 (StorageService) and Phase 4 (User DID identity linking).
|
|
6
|
+
*
|
|
7
|
+
* @package @kya-os/mcp-i-core
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Legacy storage key format (agent-only, causes multi-tenant conflicts)
|
|
11
|
+
* Format: `agent:${agentDid}:delegation`
|
|
12
|
+
*/
|
|
13
|
+
export declare function legacyDelegationKey(agentDid: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* New composite storage key format (user+agent scoped, prevents conflicts)
|
|
16
|
+
* Format: `delegation:user:${userDid}:agent:${agentDid}:project:${projectId}`
|
|
17
|
+
*
|
|
18
|
+
* Note: projectId is optional for backward compatibility
|
|
19
|
+
*/
|
|
20
|
+
export declare function compositeDelegationKey(userDid: string, agentDid: string, projectId?: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Session cache key format
|
|
23
|
+
* Format: `session:${sessionId}`
|
|
24
|
+
*/
|
|
25
|
+
export declare function sessionKey(sessionId: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* User DID storage key format
|
|
28
|
+
* Format: `userDid:oauth:${provider}:${subject}`
|
|
29
|
+
*/
|
|
30
|
+
export declare function userDidKey(provider: string, subject: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* OAuth identity mapping key format
|
|
33
|
+
* Format: `oauth:${provider}:${subject}`
|
|
34
|
+
*/
|
|
35
|
+
export declare function oauthIdentityKey(provider: string, subject: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Verification cache key format
|
|
38
|
+
* Format: `verified:${tokenHash}`
|
|
39
|
+
*/
|
|
40
|
+
export declare function verificationCacheKey(tokenHash: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Nonce tracking key format
|
|
43
|
+
* Format: `nonce:${nonce}`
|
|
44
|
+
*/
|
|
45
|
+
export declare function nonceKey(nonce: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Storage key migration result
|
|
48
|
+
*/
|
|
49
|
+
export interface MigrationResult {
|
|
50
|
+
/** Number of keys migrated */
|
|
51
|
+
migrated: number;
|
|
52
|
+
/** Number of keys that failed to migrate */
|
|
53
|
+
failed: number;
|
|
54
|
+
/** List of migrated key pairs (old -> new) */
|
|
55
|
+
migrations: Array<{
|
|
56
|
+
oldKey: string;
|
|
57
|
+
newKey: string;
|
|
58
|
+
}>;
|
|
59
|
+
/** List of errors encountered */
|
|
60
|
+
errors: Array<{
|
|
61
|
+
key: string;
|
|
62
|
+
error: string;
|
|
63
|
+
}>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Storage provider interface for migration operations
|
|
67
|
+
*
|
|
68
|
+
* Matches the base StorageProvider abstract class contract.
|
|
69
|
+
*/
|
|
70
|
+
export interface StorageProvider {
|
|
71
|
+
get(key: string): Promise<string | null>;
|
|
72
|
+
set(key: string, value: string): Promise<void>;
|
|
73
|
+
delete(key: string): Promise<void>;
|
|
74
|
+
exists(key: string): Promise<boolean>;
|
|
75
|
+
list(prefix?: string): Promise<string[]>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Migrate delegation keys from legacy format to composite format
|
|
79
|
+
*
|
|
80
|
+
* This function:
|
|
81
|
+
* 1. Finds all legacy keys (`agent:${did}:delegation`)
|
|
82
|
+
* 2. Attempts to extract userDid from session data or OAuth mappings
|
|
83
|
+
* 3. Creates new composite keys (`delegation:user:${userDid}:agent:${agentDid}`)
|
|
84
|
+
* 4. Copies values to new keys
|
|
85
|
+
* 5. Optionally deletes old keys (dry-run mode available)
|
|
86
|
+
*
|
|
87
|
+
* @param storage - Storage provider instance
|
|
88
|
+
* @param options - Migration options
|
|
89
|
+
* @returns Migration result with statistics
|
|
90
|
+
*/
|
|
91
|
+
export declare function migrateDelegationKeys(storage: StorageProvider, options?: {
|
|
92
|
+
/** If true, only report what would be migrated without making changes */
|
|
93
|
+
dryRun?: boolean;
|
|
94
|
+
/** If true, delete old keys after successful migration */
|
|
95
|
+
deleteOldKeys?: boolean;
|
|
96
|
+
/** Optional userDid resolver function (if not provided, attempts to extract from session) */
|
|
97
|
+
resolveUserDid?: (agentDid: string, sessionId?: string) => Promise<string | null>;
|
|
98
|
+
}): Promise<MigrationResult>;
|
|
99
|
+
/**
|
|
100
|
+
* Storage key constants for consistent namespace management
|
|
101
|
+
*
|
|
102
|
+
* These match the Phase 4 storage key architecture.
|
|
103
|
+
*/
|
|
104
|
+
export declare const STORAGE_KEYS: {
|
|
105
|
+
/** User DID storage (persistent - 90 days) */
|
|
106
|
+
readonly userDid: typeof userDidKey;
|
|
107
|
+
/** OAuth identity mapping (persistent - 90 days) */
|
|
108
|
+
readonly oauthIdentity: typeof oauthIdentityKey;
|
|
109
|
+
/** User+Agent delegation tokens (persistent - 7 days) */
|
|
110
|
+
readonly delegation: typeof compositeDelegationKey;
|
|
111
|
+
/** Session cache (temporary - 30 minutes) */
|
|
112
|
+
readonly session: typeof sessionKey;
|
|
113
|
+
/** Legacy delegation format (deprecated - 24 hours) */
|
|
114
|
+
readonly legacyDelegation: typeof legacyDelegationKey;
|
|
115
|
+
/** Verification cache (temporary - 5 minutes) */
|
|
116
|
+
readonly verificationCache: typeof verificationCacheKey;
|
|
117
|
+
/** Nonce tracking (temporary - 5 minutes) */
|
|
118
|
+
readonly nonce: typeof nonceKey;
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=storage-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-keys.d.ts","sourceRoot":"","sources":["../../src/utils/storage-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAKR;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,SAAS,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AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,eAAe,EACxB,OAAO,GAAE;IACP,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,0DAA0D;IAC1D,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,6FAA6F;IAC7F,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CAC9E,GACL,OAAO,CAAC,eAAe,CAAC,CAsH1B;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY;IACvB,8CAA8C;;IAG9C,oDAAoD;;IAGpD,yDAAyD;;IAGzD,6CAA6C;;IAG7C,uDAAuD;;IAGvD,iDAAiD;;IAGjD,6CAA6C;;CAErC,CAAC"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Storage Key Migration Utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides utilities for migrating from old storage key formats to new composite formats.
|
|
6
|
+
* This supports Phase 3 Task 2 (StorageService) and Phase 4 (User DID identity linking).
|
|
7
|
+
*
|
|
8
|
+
* @package @kya-os/mcp-i-core
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.STORAGE_KEYS = void 0;
|
|
12
|
+
exports.legacyDelegationKey = legacyDelegationKey;
|
|
13
|
+
exports.compositeDelegationKey = compositeDelegationKey;
|
|
14
|
+
exports.sessionKey = sessionKey;
|
|
15
|
+
exports.userDidKey = userDidKey;
|
|
16
|
+
exports.oauthIdentityKey = oauthIdentityKey;
|
|
17
|
+
exports.verificationCacheKey = verificationCacheKey;
|
|
18
|
+
exports.nonceKey = nonceKey;
|
|
19
|
+
exports.migrateDelegationKeys = migrateDelegationKeys;
|
|
20
|
+
/**
|
|
21
|
+
* Legacy storage key format (agent-only, causes multi-tenant conflicts)
|
|
22
|
+
* Format: `agent:${agentDid}:delegation`
|
|
23
|
+
*/
|
|
24
|
+
function legacyDelegationKey(agentDid) {
|
|
25
|
+
return `agent:${agentDid}:delegation`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* New composite storage key format (user+agent scoped, prevents conflicts)
|
|
29
|
+
* Format: `delegation:user:${userDid}:agent:${agentDid}:project:${projectId}`
|
|
30
|
+
*
|
|
31
|
+
* Note: projectId is optional for backward compatibility
|
|
32
|
+
*/
|
|
33
|
+
function compositeDelegationKey(userDid, agentDid, projectId) {
|
|
34
|
+
if (projectId) {
|
|
35
|
+
return `delegation:user:${userDid}:agent:${agentDid}:project:${projectId}`;
|
|
36
|
+
}
|
|
37
|
+
return `delegation:user:${userDid}:agent:${agentDid}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Session cache key format
|
|
41
|
+
* Format: `session:${sessionId}`
|
|
42
|
+
*/
|
|
43
|
+
function sessionKey(sessionId) {
|
|
44
|
+
return `session:${sessionId}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* User DID storage key format
|
|
48
|
+
* Format: `userDid:oauth:${provider}:${subject}`
|
|
49
|
+
*/
|
|
50
|
+
function userDidKey(provider, subject) {
|
|
51
|
+
return `userDid:oauth:${provider}:${subject}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* OAuth identity mapping key format
|
|
55
|
+
* Format: `oauth:${provider}:${subject}`
|
|
56
|
+
*/
|
|
57
|
+
function oauthIdentityKey(provider, subject) {
|
|
58
|
+
return `oauth:${provider}:${subject}`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Verification cache key format
|
|
62
|
+
* Format: `verified:${tokenHash}`
|
|
63
|
+
*/
|
|
64
|
+
function verificationCacheKey(tokenHash) {
|
|
65
|
+
return `verified:${tokenHash}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Nonce tracking key format
|
|
69
|
+
* Format: `nonce:${nonce}`
|
|
70
|
+
*/
|
|
71
|
+
function nonceKey(nonce) {
|
|
72
|
+
return `nonce:${nonce}`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Migrate delegation keys from legacy format to composite format
|
|
76
|
+
*
|
|
77
|
+
* This function:
|
|
78
|
+
* 1. Finds all legacy keys (`agent:${did}:delegation`)
|
|
79
|
+
* 2. Attempts to extract userDid from session data or OAuth mappings
|
|
80
|
+
* 3. Creates new composite keys (`delegation:user:${userDid}:agent:${agentDid}`)
|
|
81
|
+
* 4. Copies values to new keys
|
|
82
|
+
* 5. Optionally deletes old keys (dry-run mode available)
|
|
83
|
+
*
|
|
84
|
+
* @param storage - Storage provider instance
|
|
85
|
+
* @param options - Migration options
|
|
86
|
+
* @returns Migration result with statistics
|
|
87
|
+
*/
|
|
88
|
+
async function migrateDelegationKeys(storage, options = {}) {
|
|
89
|
+
const result = {
|
|
90
|
+
migrated: 0,
|
|
91
|
+
failed: 0,
|
|
92
|
+
migrations: [],
|
|
93
|
+
errors: [],
|
|
94
|
+
};
|
|
95
|
+
try {
|
|
96
|
+
// Find all legacy delegation keys
|
|
97
|
+
const legacyKeys = await storage.list('agent:');
|
|
98
|
+
const delegationKeys = legacyKeys.filter((key) => key.match(/^agent:[^:]+:delegation$/));
|
|
99
|
+
console.log(`Found ${delegationKeys.length} legacy delegation keys to migrate`);
|
|
100
|
+
for (const oldKey of delegationKeys) {
|
|
101
|
+
try {
|
|
102
|
+
// Extract agentDid from key: `agent:${agentDid}:delegation`
|
|
103
|
+
const match = oldKey.match(/^agent:([^:]+):delegation$/);
|
|
104
|
+
if (!match) {
|
|
105
|
+
result.errors.push({
|
|
106
|
+
key: oldKey,
|
|
107
|
+
error: 'Invalid legacy key format',
|
|
108
|
+
});
|
|
109
|
+
result.failed++;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const agentDid = match[1];
|
|
113
|
+
// Get the value from old key
|
|
114
|
+
const value = await storage.get(oldKey);
|
|
115
|
+
if (!value) {
|
|
116
|
+
// Key exists but has no value - skip
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
// Try to resolve userDid
|
|
120
|
+
let userDid = null;
|
|
121
|
+
let sessionId = undefined;
|
|
122
|
+
// First, attempt to extract from session data to get both userDid and sessionId
|
|
123
|
+
const sessionKeys = await storage.list('session:');
|
|
124
|
+
for (const sessionKey of sessionKeys) {
|
|
125
|
+
const sessionData = await storage.get(sessionKey);
|
|
126
|
+
if (sessionData) {
|
|
127
|
+
try {
|
|
128
|
+
const parsed = JSON.parse(sessionData);
|
|
129
|
+
if (parsed.userDid && parsed.agentDid === agentDid) {
|
|
130
|
+
userDid = parsed.userDid;
|
|
131
|
+
// Extract sessionId from key: `session:${sessionId}`
|
|
132
|
+
const sessionMatch = sessionKey.match(/^session:(.+)$/);
|
|
133
|
+
if (sessionMatch) {
|
|
134
|
+
sessionId = sessionMatch[1];
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Not JSON, skip
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// If custom resolver provided, use it (with sessionId context if available)
|
|
145
|
+
if (options.resolveUserDid) {
|
|
146
|
+
const resolvedUserDid = await options.resolveUserDid(agentDid, sessionId);
|
|
147
|
+
// Use resolved userDid if available, otherwise fall back to extracted one
|
|
148
|
+
if (resolvedUserDid) {
|
|
149
|
+
userDid = resolvedUserDid;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (!userDid) {
|
|
153
|
+
// Cannot migrate without userDid - skip for now
|
|
154
|
+
result.errors.push({
|
|
155
|
+
key: oldKey,
|
|
156
|
+
error: 'Cannot resolve userDid - skipping migration',
|
|
157
|
+
});
|
|
158
|
+
result.failed++;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
// Create new composite key
|
|
162
|
+
const newKey = compositeDelegationKey(userDid, agentDid);
|
|
163
|
+
if (options.dryRun) {
|
|
164
|
+
// Just record what would be migrated
|
|
165
|
+
result.migrations.push({ oldKey, newKey });
|
|
166
|
+
result.migrated++;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// Copy value to new key
|
|
170
|
+
await storage.set(newKey, value);
|
|
171
|
+
result.migrations.push({ oldKey, newKey });
|
|
172
|
+
result.migrated++;
|
|
173
|
+
// Optionally delete old key
|
|
174
|
+
if (options.deleteOldKeys) {
|
|
175
|
+
await storage.delete(oldKey);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
result.errors.push({
|
|
181
|
+
key: oldKey,
|
|
182
|
+
error: error instanceof Error ? error.message : String(error),
|
|
183
|
+
});
|
|
184
|
+
result.failed++;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
result.errors.push({
|
|
190
|
+
key: 'migration',
|
|
191
|
+
error: error instanceof Error ? error.message : String(error),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Storage key constants for consistent namespace management
|
|
198
|
+
*
|
|
199
|
+
* These match the Phase 4 storage key architecture.
|
|
200
|
+
*/
|
|
201
|
+
exports.STORAGE_KEYS = {
|
|
202
|
+
/** User DID storage (persistent - 90 days) */
|
|
203
|
+
userDid: userDidKey,
|
|
204
|
+
/** OAuth identity mapping (persistent - 90 days) */
|
|
205
|
+
oauthIdentity: oauthIdentityKey,
|
|
206
|
+
/** User+Agent delegation tokens (persistent - 7 days) */
|
|
207
|
+
delegation: compositeDelegationKey,
|
|
208
|
+
/** Session cache (temporary - 30 minutes) */
|
|
209
|
+
session: sessionKey,
|
|
210
|
+
/** Legacy delegation format (deprecated - 24 hours) */
|
|
211
|
+
legacyDelegation: legacyDelegationKey,
|
|
212
|
+
/** Verification cache (temporary - 5 minutes) */
|
|
213
|
+
verificationCache: verificationCacheKey,
|
|
214
|
+
/** Nonce tracking (temporary - 5 minutes) */
|
|
215
|
+
nonce: nonceKey,
|
|
216
|
+
};
|
|
217
|
+
//# sourceMappingURL=storage-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-keys.js","sourceRoot":"","sources":["../../src/utils/storage-keys.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAMH,kDAEC;AAQD,wDASC;AAMD,gCAEC;AAMD,gCAEC;AAMD,4CAEC;AAMD,oDAEC;AAMD,4BAEC;AA8CD,sDAkIC;AA/OD;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,QAAgB;IAClD,OAAO,SAAS,QAAQ,aAAa,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,OAAe,EACf,QAAgB,EAChB,SAAkB;IAElB,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,mBAAmB,OAAO,UAAU,QAAQ,YAAY,SAAS,EAAE,CAAC;IAC7E,CAAC;IACD,OAAO,mBAAmB,OAAO,UAAU,QAAQ,EAAE,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,SAAgB,UAAU,CAAC,SAAiB;IAC1C,OAAO,WAAW,SAAS,EAAE,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,SAAgB,UAAU,CAAC,QAAgB,EAAE,OAAe;IAC1D,OAAO,iBAAiB,QAAQ,IAAI,OAAO,EAAE,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,QAAgB,EAAE,OAAe;IAChE,OAAO,SAAS,QAAQ,IAAI,OAAO,EAAE,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,SAAiB;IACpD,OAAO,YAAY,SAAS,EAAE,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,SAAgB,QAAQ,CAAC,KAAa;IACpC,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B,CAAC;AAED;;;;GAIG;AACU,QAAA,YAAY,GAAG;IAC1B,8CAA8C;IAC9C,OAAO,EAAE,UAAU;IAEnB,oDAAoD;IACpD,aAAa,EAAE,gBAAgB;IAE/B,yDAAyD;IACzD,UAAU,EAAE,sBAAsB;IAElC,6CAA6C;IAC7C,OAAO,EAAE,UAAU;IAEnB,uDAAuD;IACvD,gBAAgB,EAAE,mBAAmB;IAErC,iDAAiD;IACjD,iBAAiB,EAAE,oBAAoB;IAEvC,6CAA6C;IAC7C,KAAK,EAAE,QAAQ;CACP,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kya-os/mcp-i-core",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1-canary.0",
|
|
4
4
|
"description": "Core provider-based architecture for MCP-I framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"test:watch": "vitest",
|
|
32
32
|
"test:e2e": "vitest run src/__tests__/delegation-e2e.test.ts",
|
|
33
33
|
"audit:compliance": "tsx scripts/audit-compliance.ts",
|
|
34
|
-
"prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-
|
|
34
|
+
"prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-dependencies.js"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"mcp-i",
|
|
@@ -42,8 +42,9 @@
|
|
|
42
42
|
"core"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@kya-os/contracts": "1.5.2-canary.
|
|
46
|
-
"@modelcontextprotocol/sdk": "^1.11.4"
|
|
45
|
+
"@kya-os/contracts": "^1.5.2-canary.5",
|
|
46
|
+
"@modelcontextprotocol/sdk": "^1.11.4",
|
|
47
|
+
"json-canonicalize": "^2.0.0"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@types/node": "^20.0.0",
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enhanced Schema Compliance Verification Tool v2
|
|
3
|
-
*
|
|
4
|
-
* Supports JSON Schema draft-07 features:
|
|
5
|
-
* - $ref resolution
|
|
6
|
-
* - oneOf, anyOf, allOf
|
|
7
|
-
* - Nested required fields
|
|
8
|
-
* - Array tuple validation
|
|
9
|
-
* - Format, pattern, enum, const
|
|
10
|
-
* - Recursive object validation
|
|
11
|
-
*/
|
|
12
|
-
export interface SchemaMetadata {
|
|
13
|
-
id: string;
|
|
14
|
-
url: string;
|
|
15
|
-
version: string;
|
|
16
|
-
type: string;
|
|
17
|
-
description?: string;
|
|
18
|
-
}
|
|
19
|
-
export interface FieldComplianceResult {
|
|
20
|
-
fieldPath: string;
|
|
21
|
-
present: boolean;
|
|
22
|
-
expectedType: string;
|
|
23
|
-
actualType?: string;
|
|
24
|
-
typeMatches: boolean;
|
|
25
|
-
required: boolean;
|
|
26
|
-
status: 'pass' | 'fail' | 'warning';
|
|
27
|
-
reason?: string;
|
|
28
|
-
}
|
|
29
|
-
export interface SchemaComplianceReport {
|
|
30
|
-
schema: SchemaMetadata;
|
|
31
|
-
compliant: boolean;
|
|
32
|
-
compliancePercentage: number;
|
|
33
|
-
fields: FieldComplianceResult[];
|
|
34
|
-
issues: string[];
|
|
35
|
-
warnings: string[];
|
|
36
|
-
timestamp: number;
|
|
37
|
-
}
|
|
38
|
-
export interface FullComplianceReport {
|
|
39
|
-
totalSchemas: number;
|
|
40
|
-
compliantSchemas: number;
|
|
41
|
-
overallCompliance: number;
|
|
42
|
-
schemaReports: SchemaComplianceReport[];
|
|
43
|
-
criticalIssues: string[];
|
|
44
|
-
timestamp: number;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Enhanced Schema Verifier with JSON Schema draft-07 support
|
|
48
|
-
*/
|
|
49
|
-
export declare class SchemaVerifierV2 {
|
|
50
|
-
private schemasBaseUrl;
|
|
51
|
-
private schemaCache;
|
|
52
|
-
constructor(options?: {
|
|
53
|
-
schemasBaseUrl?: string;
|
|
54
|
-
});
|
|
55
|
-
/**
|
|
56
|
-
* Verify a single schema against implementation
|
|
57
|
-
*/
|
|
58
|
-
verifySchema(schema: SchemaMetadata, implementation: any): Promise<SchemaComplianceReport>;
|
|
59
|
-
/**
|
|
60
|
-
* Verify all schemas
|
|
61
|
-
*/
|
|
62
|
-
verifyAll(schemas: SchemaMetadata[], implementations: Map<string, any>): Promise<FullComplianceReport>;
|
|
63
|
-
/**
|
|
64
|
-
* Validate implementation against schema recursively
|
|
65
|
-
*/
|
|
66
|
-
private validateAgainstSchema;
|
|
67
|
-
/**
|
|
68
|
-
* Validate against oneOf, anyOf, allOf
|
|
69
|
-
*/
|
|
70
|
-
private validateUnion;
|
|
71
|
-
/**
|
|
72
|
-
* Check if value matches schema (lightweight check)
|
|
73
|
-
*/
|
|
74
|
-
private matchesSchema;
|
|
75
|
-
/**
|
|
76
|
-
* Validate array against schema
|
|
77
|
-
*/
|
|
78
|
-
private validateArray;
|
|
79
|
-
/**
|
|
80
|
-
* Check a single field
|
|
81
|
-
*/
|
|
82
|
-
private checkField;
|
|
83
|
-
/**
|
|
84
|
-
* Get actual JavaScript type
|
|
85
|
-
*/
|
|
86
|
-
private getActualType;
|
|
87
|
-
/**
|
|
88
|
-
* Resolve $ref reference
|
|
89
|
-
*/
|
|
90
|
-
private resolveRef;
|
|
91
|
-
/**
|
|
92
|
-
* Fetch a schema from URL
|
|
93
|
-
*/
|
|
94
|
-
private fetchSchema;
|
|
95
|
-
/**
|
|
96
|
-
* Generate a formatted report
|
|
97
|
-
*/
|
|
98
|
-
generateReport(report: SchemaComplianceReport): string;
|
|
99
|
-
/**
|
|
100
|
-
* Generate full report
|
|
101
|
-
*/
|
|
102
|
-
generateFullReport(report: FullComplianceReport): string;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Create an enhanced schema verifier
|
|
106
|
-
*/
|
|
107
|
-
export declare function createSchemaVerifierV2(options?: {
|
|
108
|
-
schemasBaseUrl?: string;
|
|
109
|
-
}): SchemaVerifierV2;
|
|
110
|
-
//# sourceMappingURL=schema-verifier-v2.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-verifier-v2.d.ts","sourceRoot":"","sources":["../../src/compliance/schema-verifier-v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,cAAc,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,sBAAsB,EAAE,CAAC;IACxC,cAAc,EAAE,M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