@kya-os/mcp-i-core 1.7.0 → 1.8.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 +1 -1
- package/dist/conformance/capability-verifier-adapter.d.ts +66 -0
- package/dist/conformance/capability-verifier-adapter.js +61 -0
- package/dist/conformance/index.d.ts +10 -0
- package/dist/conformance/index.js +19 -0
- package/dist/conformance/validate-level2.d.ts +203 -0
- package/dist/conformance/validate-level2.js +294 -0
- package/dist/conformance/vc-jwt-verifier.d.ts +55 -0
- package/dist/conformance/vc-jwt-verifier.js +147 -0
- package/dist/delegation/did-web-resolver.d.ts +60 -0
- package/dist/delegation/did-web-resolver.js +129 -0
- package/dist/delegation/outbound-proof.d.ts +3 -2
- package/dist/delegation/outbound-proof.js +3 -2
- package/dist/delegation/utils.d.ts +3 -1
- package/dist/index.d.ts +9 -63
- package/dist/index.js +22 -161
- package/dist/utils/base58.d.ts +4 -28
- package/dist/utils/base58.js +18 -98
- package/dist/utils/base64.d.ts +4 -29
- package/dist/utils/base64.js +18 -167
- package/dist/utils/did-helpers.d.ts +4 -165
- package/dist/utils/did-helpers.js +18 -217
- package/package.json +5 -7
- package/dist/auth/handshake.d.ts +0 -119
- package/dist/auth/handshake.js +0 -250
- package/dist/auth/index.d.ts +0 -6
- package/dist/auth/index.js +0 -11
- package/dist/auth/types.d.ts +0 -46
- package/dist/auth/types.js +0 -10
- package/dist/cache/oauth-config-cache.d.ts +0 -69
- package/dist/cache/oauth-config-cache.js +0 -76
- package/dist/cache/tool-protection-cache.d.ts +0 -89
- package/dist/cache/tool-protection-cache.js +0 -118
- package/dist/compliance/index.d.ts +0 -8
- package/dist/compliance/index.js +0 -24
- package/dist/compliance/schema-registry.d.ts +0 -50
- package/dist/compliance/schema-registry.js +0 -438
- package/dist/compliance/schema-verifier.d.ts +0 -110
- package/dist/compliance/schema-verifier.js +0 -518
- package/dist/config/remote-config.d.ts +0 -173
- package/dist/config/remote-config.js +0 -253
- package/dist/config.d.ts +0 -182
- package/dist/config.js +0 -148
- package/dist/identity/idp-token-resolver.d.ts +0 -69
- package/dist/identity/idp-token-resolver.js +0 -136
- package/dist/identity/idp-token-storage.interface.d.ts +0 -80
- package/dist/identity/idp-token-storage.interface.js +0 -14
- package/dist/identity/user-did-manager.d.ts +0 -228
- package/dist/identity/user-did-manager.js +0 -356
- package/dist/logging/index.d.ts +0 -5
- package/dist/logging/index.js +0 -10
- package/dist/logging/logger.d.ts +0 -33
- package/dist/logging/logger.js +0 -104
- package/dist/proof/generator.d.ts +0 -109
- package/dist/proof/generator.js +0 -236
- package/dist/proof/index.d.ts +0 -5
- package/dist/proof/index.js +0 -11
- package/dist/providers/base.d.ts +0 -95
- package/dist/providers/base.js +0 -47
- package/dist/providers/memory.d.ts +0 -42
- package/dist/providers/memory.js +0 -121
- package/dist/runtime/audit-logger.d.ts +0 -37
- package/dist/runtime/audit-logger.js +0 -9
- package/dist/runtime/base.d.ts +0 -375
- package/dist/runtime/base.js +0 -1491
- package/dist/runtime/ext-apps-constants.d.ts +0 -14
- package/dist/runtime/ext-apps-constants.js +0 -17
- package/dist/services/access-control.service.d.ts +0 -138
- package/dist/services/access-control.service.js +0 -721
- package/dist/services/authorization/authorization-registry.d.ts +0 -29
- package/dist/services/authorization/authorization-registry.js +0 -58
- package/dist/services/authorization/types.d.ts +0 -53
- package/dist/services/authorization/types.js +0 -10
- package/dist/services/batch-delegation.service.d.ts +0 -53
- package/dist/services/batch-delegation.service.js +0 -95
- package/dist/services/crypto.service.d.ts +0 -69
- package/dist/services/crypto.service.js +0 -225
- package/dist/services/delegation-error-formatter.d.ts +0 -124
- package/dist/services/delegation-error-formatter.js +0 -214
- package/dist/services/errors.d.ts +0 -49
- package/dist/services/errors.js +0 -66
- package/dist/services/index.d.ts +0 -9
- package/dist/services/index.js +0 -15
- package/dist/services/oauth-config.service.d.ts +0 -53
- package/dist/services/oauth-config.service.js +0 -141
- package/dist/services/oauth-provider-registry.d.ts +0 -88
- package/dist/services/oauth-provider-registry.js +0 -128
- package/dist/services/oauth-service.d.ts +0 -122
- package/dist/services/oauth-service.js +0 -442
- package/dist/services/oauth-token-retrieval.service.d.ts +0 -49
- package/dist/services/oauth-token-retrieval.service.js +0 -150
- package/dist/services/policy.service.d.ts +0 -130
- package/dist/services/policy.service.js +0 -399
- package/dist/services/proof-verifier.d.ts +0 -98
- package/dist/services/proof-verifier.js +0 -319
- package/dist/services/provider-resolver.d.ts +0 -89
- package/dist/services/provider-resolver.js +0 -196
- package/dist/services/provider-validator.d.ts +0 -55
- package/dist/services/provider-validator.js +0 -135
- package/dist/services/session-registration.service.d.ts +0 -80
- package/dist/services/session-registration.service.js +0 -174
- package/dist/services/storage.service.d.ts +0 -116
- package/dist/services/storage.service.js +0 -411
- package/dist/services/tool-context-builder.d.ts +0 -74
- package/dist/services/tool-context-builder.js +0 -215
- package/dist/services/tool-protection.service.d.ts +0 -193
- package/dist/services/tool-protection.service.js +0 -736
- package/dist/session/index.d.ts +0 -5
- package/dist/session/index.js +0 -11
- package/dist/session/manager.d.ts +0 -113
- package/dist/session/manager.js +0 -273
- package/dist/types/oauth-required-error.d.ts +0 -46
- package/dist/types/oauth-required-error.js +0 -42
- package/dist/types/tool-protection.d.ts +0 -144
- package/dist/types/tool-protection.js +0 -48
- package/dist/utils/cors.d.ts +0 -44
- package/dist/utils/cors.js +0 -71
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.js +0 -24
- package/dist/utils/storage-keys.d.ts +0 -120
- package/dist/utils/storage-keys.js +0 -217
package/dist/utils/cors.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CORS Header Utilities
|
|
3
|
-
*
|
|
4
|
-
* Centralized CORS header management for MCP-I services.
|
|
5
|
-
* Includes Vary: Origin for cache optimization when origin scoping is implemented.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Type-safe CORS headers
|
|
9
|
-
* Compatible with Response headers and HeadersInit
|
|
10
|
-
*/
|
|
11
|
-
export type CORSHeaders = Record<string, string>;
|
|
12
|
-
/**
|
|
13
|
-
* Standard CORS headers for well-known endpoints (.well-known/*)
|
|
14
|
-
* Includes Vary: Origin for future cache optimization when origin scoping is added
|
|
15
|
-
*/
|
|
16
|
-
export declare const WELL_KNOWN_CORS_HEADERS: CORSHeaders;
|
|
17
|
-
/**
|
|
18
|
-
* CORS headers for MCP protocol responses
|
|
19
|
-
* Includes exposed headers for session management
|
|
20
|
-
*/
|
|
21
|
-
export declare const MCP_CORS_HEADERS: CORSHeaders;
|
|
22
|
-
/**
|
|
23
|
-
* CORS preflight headers for OPTIONS requests
|
|
24
|
-
* Comprehensive header allowlist for MCP protocol
|
|
25
|
-
*/
|
|
26
|
-
export declare const PREFLIGHT_CORS_HEADERS: CORSHeaders;
|
|
27
|
-
/**
|
|
28
|
-
* CORS headers for OAuth endpoints
|
|
29
|
-
* Includes additional headers required for OAuth 2.0 flows
|
|
30
|
-
*/
|
|
31
|
-
export declare const OAUTH_CORS_HEADERS: CORSHeaders;
|
|
32
|
-
/**
|
|
33
|
-
* Merge CORS headers with existing headers
|
|
34
|
-
* Ensures CORS headers take precedence
|
|
35
|
-
*/
|
|
36
|
-
export declare function mergeCORSHeaders(existingHeaders: Record<string, string>, corsHeaders?: CORSHeaders): Record<string, string>;
|
|
37
|
-
/**
|
|
38
|
-
* Apply CORS headers to an Express Response object
|
|
39
|
-
* For use with Express middleware
|
|
40
|
-
*/
|
|
41
|
-
export declare function applyCORSHeaders(res: {
|
|
42
|
-
setHeader: (name: string, value: string) => void;
|
|
43
|
-
}, corsHeaders?: CORSHeaders): void;
|
|
44
|
-
//# sourceMappingURL=cors.d.ts.map
|
package/dist/utils/cors.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* CORS Header Utilities
|
|
4
|
-
*
|
|
5
|
-
* Centralized CORS header management for MCP-I services.
|
|
6
|
-
* Includes Vary: Origin for cache optimization when origin scoping is implemented.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.OAUTH_CORS_HEADERS = exports.PREFLIGHT_CORS_HEADERS = exports.MCP_CORS_HEADERS = exports.WELL_KNOWN_CORS_HEADERS = void 0;
|
|
10
|
-
exports.mergeCORSHeaders = mergeCORSHeaders;
|
|
11
|
-
exports.applyCORSHeaders = applyCORSHeaders;
|
|
12
|
-
/**
|
|
13
|
-
* Standard CORS headers for well-known endpoints (.well-known/*)
|
|
14
|
-
* Includes Vary: Origin for future cache optimization when origin scoping is added
|
|
15
|
-
*/
|
|
16
|
-
exports.WELL_KNOWN_CORS_HEADERS = {
|
|
17
|
-
'Access-Control-Allow-Origin': '*',
|
|
18
|
-
'Vary': 'Origin'
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* CORS headers for MCP protocol responses
|
|
22
|
-
* Includes exposed headers for session management
|
|
23
|
-
*/
|
|
24
|
-
exports.MCP_CORS_HEADERS = {
|
|
25
|
-
'Access-Control-Allow-Origin': '*',
|
|
26
|
-
'Access-Control-Expose-Headers': 'mcp-session-id',
|
|
27
|
-
'Vary': 'Origin'
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* CORS preflight headers for OPTIONS requests
|
|
31
|
-
* Comprehensive header allowlist for MCP protocol
|
|
32
|
-
*/
|
|
33
|
-
exports.PREFLIGHT_CORS_HEADERS = {
|
|
34
|
-
'Access-Control-Allow-Origin': '*',
|
|
35
|
-
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
|
36
|
-
'Access-Control-Allow-Headers': 'Content-Type, Authorization, mcp-session-id, mcp-protocol-version',
|
|
37
|
-
'Vary': 'Origin'
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* CORS headers for OAuth endpoints
|
|
41
|
-
* Includes additional headers required for OAuth 2.0 flows
|
|
42
|
-
*/
|
|
43
|
-
exports.OAUTH_CORS_HEADERS = {
|
|
44
|
-
'Access-Control-Allow-Origin': '*',
|
|
45
|
-
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
|
46
|
-
'Access-Control-Allow-Headers': 'Content-Type, Authorization, Accept, mcp-protocol-version',
|
|
47
|
-
'Access-Control-Expose-Headers': 'Content-Type',
|
|
48
|
-
'Vary': 'Origin'
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Merge CORS headers with existing headers
|
|
52
|
-
* Ensures CORS headers take precedence
|
|
53
|
-
*/
|
|
54
|
-
function mergeCORSHeaders(existingHeaders, corsHeaders = exports.WELL_KNOWN_CORS_HEADERS) {
|
|
55
|
-
return {
|
|
56
|
-
...existingHeaders,
|
|
57
|
-
...corsHeaders
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Apply CORS headers to an Express Response object
|
|
62
|
-
* For use with Express middleware
|
|
63
|
-
*/
|
|
64
|
-
function applyCORSHeaders(res, corsHeaders = exports.MCP_CORS_HEADERS) {
|
|
65
|
-
Object.entries(corsHeaders).forEach(([key, value]) => {
|
|
66
|
-
if (value !== undefined) {
|
|
67
|
-
res.setHeader(key, value);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=cors.js.map
|
package/dist/utils/index.d.ts
DELETED
package/dist/utils/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Utility exports
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
__exportStar(require("./cors"), exports);
|
|
21
|
-
__exportStar(require("./base64"), exports);
|
|
22
|
-
__exportStar(require("./storage-keys"), exports);
|
|
23
|
-
__exportStar(require("./did-helpers"), exports);
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,120 +0,0 @@
|
|
|
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
|
|
@@ -1,217 +0,0 @@
|
|
|
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.error(`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
|