@kya-os/mcp-i-core 1.8.0 → 1.8.2
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/conformance/capability-verifier-adapter.d.ts +66 -0
- package/dist/conformance/capability-verifier-adapter.js +61 -0
- package/dist/conformance/index.d.ts +3 -1
- package/dist/conformance/index.js +7 -1
- package/dist/conformance/validate-level2.d.ts +13 -3
- package/dist/conformance/validate-level2.js +15 -5
- 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/index.d.ts +2 -1
- package/dist/index.js +9 -1
- package/package.json +3 -3
- 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
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* IDP Token Resolver
|
|
4
|
-
*
|
|
5
|
-
* Resolves User DID to IDP access token (MH-7 requirement).
|
|
6
|
-
* Handles token lookup, expiration checking, and automatic refresh.
|
|
7
|
-
*
|
|
8
|
-
* Updated for CRED-003: Returns full token data including usage metadata
|
|
9
|
-
* to support credential providers with custom token usage patterns.
|
|
10
|
-
*
|
|
11
|
-
* @package @kya-os/mcp-i-core
|
|
12
|
-
*/
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.IdpTokenResolver = void 0;
|
|
15
|
-
/**
|
|
16
|
-
* Service for resolving User DID to IDP access token
|
|
17
|
-
*
|
|
18
|
-
* MH-7 Requirement: resolveTokenFromDid(userDid: string): Promise<string>
|
|
19
|
-
*
|
|
20
|
-
* This service implements the core MH-7 functionality:
|
|
21
|
-
* - Resolves User DID to IDP access token
|
|
22
|
-
* - Handles token expiration and automatic refresh
|
|
23
|
-
* - Supports multiple IDP providers
|
|
24
|
-
*/
|
|
25
|
-
class IdpTokenResolver {
|
|
26
|
-
config;
|
|
27
|
-
constructor(config) {
|
|
28
|
-
this.config = {
|
|
29
|
-
tokenStorage: config.tokenStorage,
|
|
30
|
-
oauthService: config.oauthService,
|
|
31
|
-
logger: config.logger || (() => { }),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Resolve User DID to IDP access token
|
|
36
|
-
*
|
|
37
|
-
* MH-7 Requirement: resolveTokenFromDid(userDid: string): Promise<string>
|
|
38
|
-
*
|
|
39
|
-
* Flow:
|
|
40
|
-
* 1. Look up token from storage
|
|
41
|
-
* 2. Check expiration
|
|
42
|
-
* 3. Auto-refresh if expired and refresh_token available
|
|
43
|
-
* 4. Update storage after refresh
|
|
44
|
-
* 5. Return access_token or null
|
|
45
|
-
*
|
|
46
|
-
* @param userDid - User DID to resolve
|
|
47
|
-
* @param provider - OAuth provider name (e.g., "github", "google")
|
|
48
|
-
* @param scopes - Required scopes for token
|
|
49
|
-
* @returns Access token or null if not found/expired
|
|
50
|
-
*/
|
|
51
|
-
async resolveTokenFromDid(userDid, provider, scopes) {
|
|
52
|
-
const tokenData = await this.resolveTokenDataFromDid(userDid, provider, scopes);
|
|
53
|
-
return tokenData?.access_token ?? null;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Resolve User DID to full IDP token data (CRED-003)
|
|
57
|
-
*
|
|
58
|
-
* Returns the full token data including usage metadata for credential providers.
|
|
59
|
-
* This allows ToolContextBuilder to construct appropriate headers based on
|
|
60
|
-
* tokenUsage (cookie/bearer/header) and cookieFormat.
|
|
61
|
-
*
|
|
62
|
-
* @param userDid - User DID to resolve
|
|
63
|
-
* @param provider - OAuth provider name or credential provider
|
|
64
|
-
* @param scopes - Required scopes for token
|
|
65
|
-
* @returns Full token data with metadata or null if not found/expired
|
|
66
|
-
*/
|
|
67
|
-
async resolveTokenDataFromDid(userDid, provider, scopes) {
|
|
68
|
-
// 1. Look up token from storage
|
|
69
|
-
const storedToken = await this.config.tokenStorage.getToken(userDid, provider, scopes);
|
|
70
|
-
if (!storedToken) {
|
|
71
|
-
this.config.logger("[IdpTokenResolver] Token not found", {
|
|
72
|
-
userDid: userDid.substring(0, 20) + "...",
|
|
73
|
-
provider,
|
|
74
|
-
scopes,
|
|
75
|
-
});
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
// 2. Check expiration
|
|
79
|
-
const now = Date.now();
|
|
80
|
-
if (storedToken.expires_at < now) {
|
|
81
|
-
this.config.logger("[IdpTokenResolver] Token expired, attempting refresh", {
|
|
82
|
-
userDid: userDid.substring(0, 20) + "...",
|
|
83
|
-
provider,
|
|
84
|
-
expiresAt: new Date(storedToken.expires_at).toISOString(),
|
|
85
|
-
hasRefreshToken: !!storedToken.refresh_token,
|
|
86
|
-
});
|
|
87
|
-
// 3. Refresh if refresh_token available
|
|
88
|
-
// Note: Credential tokens don't support refresh - they require re-authentication
|
|
89
|
-
if (storedToken.refresh_token) {
|
|
90
|
-
const refreshed = await this.config.oauthService.refreshToken(provider, storedToken.refresh_token);
|
|
91
|
-
if (refreshed) {
|
|
92
|
-
// 4. Update storage with new tokens, preserving usage metadata
|
|
93
|
-
const refreshedWithMetadata = {
|
|
94
|
-
...refreshed,
|
|
95
|
-
tokenUsage: storedToken.tokenUsage,
|
|
96
|
-
tokenHeader: storedToken.tokenHeader,
|
|
97
|
-
cookieFormat: storedToken.cookieFormat,
|
|
98
|
-
apiHeaders: storedToken.apiHeaders,
|
|
99
|
-
};
|
|
100
|
-
await this.config.tokenStorage.storeToken(userDid, provider, scopes, refreshedWithMetadata);
|
|
101
|
-
this.config.logger("[IdpTokenResolver] Token refreshed successfully", {
|
|
102
|
-
userDid: userDid.substring(0, 20) + "...",
|
|
103
|
-
provider,
|
|
104
|
-
expiresAt: new Date(refreshed.expires_at).toISOString(),
|
|
105
|
-
});
|
|
106
|
-
// 5. Return new token data
|
|
107
|
-
return refreshedWithMetadata;
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
this.config.logger("[IdpTokenResolver] Token refresh failed", {
|
|
111
|
-
userDid: userDid.substring(0, 20) + "...",
|
|
112
|
-
provider,
|
|
113
|
-
});
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
this.config.logger("[IdpTokenResolver] Token expired and no refresh token", {
|
|
119
|
-
userDid: userDid.substring(0, 20) + "...",
|
|
120
|
-
provider,
|
|
121
|
-
});
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// 4. Return valid token data
|
|
126
|
-
this.config.logger("[IdpTokenResolver] Token resolved successfully", {
|
|
127
|
-
userDid: userDid.substring(0, 20) + "...",
|
|
128
|
-
provider,
|
|
129
|
-
expiresAt: new Date(storedToken.expires_at).toISOString(),
|
|
130
|
-
tokenUsage: storedToken.tokenUsage,
|
|
131
|
-
});
|
|
132
|
-
return storedToken;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.IdpTokenResolver = IdpTokenResolver;
|
|
136
|
-
//# sourceMappingURL=idp-token-resolver.js.map
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IDP Token Storage Interface
|
|
3
|
-
*
|
|
4
|
-
* Platform-agnostic interface for storing and retrieving IDP tokens.
|
|
5
|
-
* Platform-specific implementations (Cloudflare KV, Node.js database, etc.)
|
|
6
|
-
* implement this interface.
|
|
7
|
-
*
|
|
8
|
-
* Supports both OAuth tokens and credential-based session tokens (CRED-003).
|
|
9
|
-
*
|
|
10
|
-
* @package @kya-os/mcp-i-core
|
|
11
|
-
*/
|
|
12
|
-
import type { IdpTokens } from "@kya-os/contracts/config";
|
|
13
|
-
/**
|
|
14
|
-
* Token usage metadata for credential providers (CRED-003)
|
|
15
|
-
*
|
|
16
|
-
* Specifies how the token should be used in subsequent API calls.
|
|
17
|
-
*/
|
|
18
|
-
export interface TokenUsageMetadata {
|
|
19
|
-
/**
|
|
20
|
-
* How to use the token in requests
|
|
21
|
-
* - "cookie": Send as Cookie header
|
|
22
|
-
* - "bearer": Send as Authorization: Bearer xxx
|
|
23
|
-
* - "header": Send as custom header (specify tokenHeader)
|
|
24
|
-
*/
|
|
25
|
-
tokenUsage?: "cookie" | "bearer" | "header";
|
|
26
|
-
/** Custom header name when tokenUsage is "header" */
|
|
27
|
-
tokenHeader?: string;
|
|
28
|
-
/**
|
|
29
|
-
* Cookie format template when tokenUsage is "cookie"
|
|
30
|
-
* Use {{token}} placeholder for the token value
|
|
31
|
-
* @example "CIX={{token}}; customerCookie={{token}}"
|
|
32
|
-
*/
|
|
33
|
-
cookieFormat?: string;
|
|
34
|
-
/** Additional headers to include in API calls */
|
|
35
|
-
apiHeaders?: Record<string, string>;
|
|
36
|
-
/**
|
|
37
|
-
* User ID extracted from credential provider response
|
|
38
|
-
*
|
|
39
|
-
* For credential providers, this is the userId extracted via responseFields.userId.
|
|
40
|
-
* This is passed to tool handlers via ToolExecutionContext.userId.
|
|
41
|
-
*/
|
|
42
|
-
userId?: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Extended IdpTokens with usage metadata (CRED-003)
|
|
46
|
-
*/
|
|
47
|
-
export interface IdpTokensWithMetadata extends IdpTokens, TokenUsageMetadata {
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Interface for IDP token storage
|
|
51
|
-
*/
|
|
52
|
-
export interface IIdpTokenStorage {
|
|
53
|
-
/**
|
|
54
|
-
* Store IDP tokens
|
|
55
|
-
*
|
|
56
|
-
* @param userDid - User DID to associate tokens with
|
|
57
|
-
* @param provider - OAuth provider name or credential provider
|
|
58
|
-
* @param scopes - Scopes granted for these tokens
|
|
59
|
-
* @param tokens - IDP tokens to store (may include usage metadata for credentials)
|
|
60
|
-
*/
|
|
61
|
-
storeToken(userDid: string, provider: string, scopes: string[], tokens: IdpTokens | IdpTokensWithMetadata): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Retrieve IDP tokens
|
|
64
|
-
*
|
|
65
|
-
* @param userDid - User DID to retrieve tokens for
|
|
66
|
-
* @param provider - OAuth provider name or credential provider
|
|
67
|
-
* @param scopes - Scopes to retrieve tokens for
|
|
68
|
-
* @returns IDP tokens with optional usage metadata or null if not found
|
|
69
|
-
*/
|
|
70
|
-
getToken(userDid: string, provider: string, scopes: string[]): Promise<IdpTokensWithMetadata | null>;
|
|
71
|
-
/**
|
|
72
|
-
* Delete IDP tokens
|
|
73
|
-
*
|
|
74
|
-
* @param userDid - User DID
|
|
75
|
-
* @param provider - OAuth provider name or credential provider
|
|
76
|
-
* @param scopes - Scopes
|
|
77
|
-
*/
|
|
78
|
-
deleteToken(userDid: string, provider: string, scopes: string[]): Promise<void>;
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=idp-token-storage.interface.d.ts.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* IDP Token Storage Interface
|
|
4
|
-
*
|
|
5
|
-
* Platform-agnostic interface for storing and retrieving IDP tokens.
|
|
6
|
-
* Platform-specific implementations (Cloudflare KV, Node.js database, etc.)
|
|
7
|
-
* implement this interface.
|
|
8
|
-
*
|
|
9
|
-
* Supports both OAuth tokens and credential-based session tokens (CRED-003).
|
|
10
|
-
*
|
|
11
|
-
* @package @kya-os/mcp-i-core
|
|
12
|
-
*/
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
//# sourceMappingURL=idp-token-storage.interface.js.map
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* User DID Manager
|
|
3
|
-
*
|
|
4
|
-
* Manages user DIDs for MCP-I sessions.
|
|
5
|
-
*
|
|
6
|
-
* Phase 5: Anonymous Sessions Until OAuth
|
|
7
|
-
* - Sessions start anonymous (no userDid) until OAuth completes
|
|
8
|
-
* - User DIDs are resolved via AgentShield identity/resolve after OAuth
|
|
9
|
-
* - Eliminates DID fragmentation (same user = same DID across sessions)
|
|
10
|
-
*
|
|
11
|
-
* DID Resolution Priority:
|
|
12
|
-
* 1. OAuth mapping lookup (persistent)
|
|
13
|
-
* 2. Session storage lookup
|
|
14
|
-
* 3. Return null (session stays anonymous)
|
|
15
|
-
*/
|
|
16
|
-
import { CryptoProvider } from "../providers/base";
|
|
17
|
-
/**
|
|
18
|
-
* OAuth identity for persistent user DID lookup
|
|
19
|
-
*/
|
|
20
|
-
export interface OAuthIdentity {
|
|
21
|
-
/**
|
|
22
|
-
* OAuth provider name (e.g., "google", "github", "microsoft")
|
|
23
|
-
*/
|
|
24
|
-
provider: string;
|
|
25
|
-
/**
|
|
26
|
-
* OAuth subject identifier (unique user ID from provider)
|
|
27
|
-
*/
|
|
28
|
-
subject: string;
|
|
29
|
-
/**
|
|
30
|
-
* User's email address from OAuth provider (optional)
|
|
31
|
-
*/
|
|
32
|
-
email?: string;
|
|
33
|
-
/**
|
|
34
|
-
* User's display name from OAuth provider (optional)
|
|
35
|
-
*/
|
|
36
|
-
name?: string;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* User key pair for signing VCs
|
|
40
|
-
*
|
|
41
|
-
* Contains both public and private keys in base64 format.
|
|
42
|
-
* SECURITY: Private keys should be encrypted at rest.
|
|
43
|
-
*/
|
|
44
|
-
export interface UserKeyPair {
|
|
45
|
-
/**
|
|
46
|
-
* User DID (did:key format)
|
|
47
|
-
*/
|
|
48
|
-
did: string;
|
|
49
|
-
/**
|
|
50
|
-
* Public key in base64 format
|
|
51
|
-
*/
|
|
52
|
-
publicKey: string;
|
|
53
|
-
/**
|
|
54
|
-
* Private key in base64 format
|
|
55
|
-
* SECURITY: Should be encrypted at rest in production
|
|
56
|
-
*/
|
|
57
|
-
privateKey: string;
|
|
58
|
-
/**
|
|
59
|
-
* Key ID (for JWS header)
|
|
60
|
-
*/
|
|
61
|
-
keyId: string;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* User DID storage interface
|
|
65
|
-
*/
|
|
66
|
-
export interface UserDidStorage {
|
|
67
|
-
/**
|
|
68
|
-
* Get user DID for a session
|
|
69
|
-
*/
|
|
70
|
-
get(sessionId: string): Promise<string | null>;
|
|
71
|
-
/**
|
|
72
|
-
* Store user DID for a session
|
|
73
|
-
*/
|
|
74
|
-
set(sessionId: string, did: string, ttl?: number): Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* Delete user DID for a session
|
|
77
|
-
*/
|
|
78
|
-
delete(sessionId: string): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Get user DID by OAuth identity (optional - for persistent user DID lookup)
|
|
81
|
-
* If not implemented, OAuth-based lookup will be skipped
|
|
82
|
-
*/
|
|
83
|
-
getByOAuth?(provider: string, subject: string): Promise<string | null>;
|
|
84
|
-
/**
|
|
85
|
-
* Store user DID mapping for OAuth identity (optional - for persistent user DID storage)
|
|
86
|
-
* If not implemented, OAuth-based storage will be skipped
|
|
87
|
-
*/
|
|
88
|
-
setByOAuth?(provider: string, subject: string, did: string, ttl?: number): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* Get user key pair for a session (optional - for VC signing)
|
|
91
|
-
* If not implemented, VC issuance will not be available for this session
|
|
92
|
-
*/
|
|
93
|
-
getKeyPair?(sessionId: string): Promise<UserKeyPair | null>;
|
|
94
|
-
/**
|
|
95
|
-
* Store user key pair for a session (optional - for VC signing)
|
|
96
|
-
* SECURITY: Implementation should encrypt private keys at rest
|
|
97
|
-
*/
|
|
98
|
-
setKeyPair?(sessionId: string, keyPair: UserKeyPair, ttl?: number): Promise<void>;
|
|
99
|
-
/**
|
|
100
|
-
* Get user key pair by OAuth identity (optional - for persistent key storage)
|
|
101
|
-
* If not implemented, OAuth-based key lookup will be skipped
|
|
102
|
-
*/
|
|
103
|
-
getKeyPairByOAuth?(provider: string, subject: string): Promise<UserKeyPair | null>;
|
|
104
|
-
/**
|
|
105
|
-
* Store user key pair for OAuth identity (optional - for persistent key storage)
|
|
106
|
-
* SECURITY: Implementation should encrypt private keys at rest
|
|
107
|
-
*/
|
|
108
|
-
setKeyPairByOAuth?(provider: string, subject: string, keyPair: UserKeyPair, ttl?: number): Promise<void>;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* User DID Manager configuration
|
|
112
|
-
*/
|
|
113
|
-
export interface UserDidManagerConfig {
|
|
114
|
-
/**
|
|
115
|
-
* Storage provider for user DIDs (optional)
|
|
116
|
-
* If not provided, user DIDs are ephemeral (not persisted)
|
|
117
|
-
*/
|
|
118
|
-
storage?: UserDidStorage;
|
|
119
|
-
/**
|
|
120
|
-
* Crypto provider for DID generation
|
|
121
|
-
*/
|
|
122
|
-
crypto: CryptoProvider;
|
|
123
|
-
/**
|
|
124
|
-
* Generate did:web format instead of did:key (requires additional setup)
|
|
125
|
-
*/
|
|
126
|
-
useDidWeb?: boolean;
|
|
127
|
-
/**
|
|
128
|
-
* Base URL for did:web (required if useDidWeb is true)
|
|
129
|
-
*/
|
|
130
|
-
didWebBaseUrl?: string;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* User DID Manager
|
|
134
|
-
*
|
|
135
|
-
* Generates and manages user DIDs for MCP-I sessions.
|
|
136
|
-
* Supports both ephemeral (did:key) and persistent (did:web) formats.
|
|
137
|
-
*/
|
|
138
|
-
export declare class UserDidManager {
|
|
139
|
-
private config;
|
|
140
|
-
private sessionDidCache;
|
|
141
|
-
private sessionKeyPairCache;
|
|
142
|
-
constructor(config: UserDidManagerConfig);
|
|
143
|
-
/**
|
|
144
|
-
* Get key pair for a session (for VC signing)
|
|
145
|
-
*
|
|
146
|
-
* Returns the key pair if available, null otherwise.
|
|
147
|
-
* Key pairs are stored when DIDs are generated.
|
|
148
|
-
*
|
|
149
|
-
* @param sessionId - MCP session ID
|
|
150
|
-
* @param oauthIdentity - Optional OAuth identity for persistent lookup
|
|
151
|
-
* @returns UserKeyPair or null if not available
|
|
152
|
-
*/
|
|
153
|
-
getKeyPairForSession(sessionId: string, oauthIdentity?: OAuthIdentity | null): Promise<UserKeyPair | null>;
|
|
154
|
-
/**
|
|
155
|
-
* Get user DID for a session (Phase 5: No ephemeral generation)
|
|
156
|
-
*
|
|
157
|
-
* If a user DID already exists for the session, it is returned.
|
|
158
|
-
* If OAuth identity is provided, checks for persistent user DID mapping.
|
|
159
|
-
* Returns null if no DID found - session stays anonymous until OAuth completes.
|
|
160
|
-
*
|
|
161
|
-
* @param sessionId - MCP session ID
|
|
162
|
-
* @param oauthIdentity - Optional OAuth identity for persistent user DID lookup
|
|
163
|
-
* @returns User DID (did:key format) or null if session is anonymous
|
|
164
|
-
*
|
|
165
|
-
* @remarks
|
|
166
|
-
* - Phase 5: Sessions start anonymous, no ephemeral DID generation
|
|
167
|
-
* - User DIDs are resolved via AgentShield after OAuth completes
|
|
168
|
-
* - Returns null if no existing DID found (instead of generating ephemeral)
|
|
169
|
-
*/
|
|
170
|
-
getOrCreateUserDid(sessionId: string, oauthIdentity?: OAuthIdentity | null): Promise<string | null>;
|
|
171
|
-
/**
|
|
172
|
-
* Set user DID for a session (Phase 5: After OAuth resolution)
|
|
173
|
-
*
|
|
174
|
-
* Called after AgentShield identity/resolve returns a persistent user DID.
|
|
175
|
-
* Caches the DID and optionally stores in session storage.
|
|
176
|
-
*
|
|
177
|
-
* @param sessionId - MCP session ID
|
|
178
|
-
* @param userDid - Persistent user DID from AgentShield
|
|
179
|
-
* @param oauthIdentity - OAuth identity for creating persistent mappings
|
|
180
|
-
*/
|
|
181
|
-
setUserDidForSession(sessionId: string, userDid: string, oauthIdentity?: OAuthIdentity | null): Promise<void>;
|
|
182
|
-
/**
|
|
183
|
-
* Generate a new ephemeral user DID
|
|
184
|
-
*
|
|
185
|
-
* Uses did:key format by default for simplicity.
|
|
186
|
-
* did:web can be used if configured, but requires additional setup.
|
|
187
|
-
*/
|
|
188
|
-
private generateUserDid;
|
|
189
|
-
/**
|
|
190
|
-
* Generate a new ephemeral user DID with full key pair
|
|
191
|
-
*
|
|
192
|
-
* Returns the DID along with the key pair for VC signing.
|
|
193
|
-
* Uses did:key format by default.
|
|
194
|
-
*
|
|
195
|
-
* @returns UserKeyPair containing DID, public key, private key, and key ID
|
|
196
|
-
*/
|
|
197
|
-
private generateUserDidWithKeyPair;
|
|
198
|
-
/**
|
|
199
|
-
* Generate did:key from Ed25519 public key bytes
|
|
200
|
-
* Following spec: https://w3c-ccg.github.io/did-method-key/
|
|
201
|
-
*
|
|
202
|
-
* Format: did:key:z<multibase-base58btc(<multicodec-ed25519-pub><publicKey>)>
|
|
203
|
-
*/
|
|
204
|
-
private generateDidKeyFromPublicKey;
|
|
205
|
-
/**
|
|
206
|
-
* Base58 encode (Bitcoin alphabet)
|
|
207
|
-
* Simple implementation for did:key generation
|
|
208
|
-
*/
|
|
209
|
-
private base58Encode;
|
|
210
|
-
/**
|
|
211
|
-
* Convert base64 or base64url string to Uint8Array
|
|
212
|
-
* Handles both standard base64 (+/) and base64url (-_) formats
|
|
213
|
-
*/
|
|
214
|
-
private base64ToBytes;
|
|
215
|
-
/**
|
|
216
|
-
* Get user DID for a session without creating one
|
|
217
|
-
*/
|
|
218
|
-
getUserDid(sessionId: string): Promise<string | null>;
|
|
219
|
-
/**
|
|
220
|
-
* Clear user DID for a session
|
|
221
|
-
*/
|
|
222
|
-
clearUserDid(sessionId: string): Promise<void>;
|
|
223
|
-
/**
|
|
224
|
-
* Clear all cached user DIDs (useful for testing)
|
|
225
|
-
*/
|
|
226
|
-
clearCache(): void;
|
|
227
|
-
}
|
|
228
|
-
//# sourceMappingURL=user-did-manager.d.ts.map
|