@kya-os/contracts 1.2.1 → 1.3.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.
Files changed (69) hide show
  1. package/dist/delegation/constraints.d.ts +982 -0
  2. package/dist/delegation/constraints.d.ts.map +1 -0
  3. package/dist/delegation/constraints.js +205 -0
  4. package/dist/delegation/index.d.ts +8 -0
  5. package/dist/delegation/index.d.ts.map +1 -0
  6. package/dist/delegation/index.js +24 -0
  7. package/dist/delegation/schemas.d.ts +3787 -0
  8. package/dist/delegation/schemas.d.ts.map +1 -0
  9. package/dist/delegation/schemas.js +230 -0
  10. package/dist/did/index.d.ts +8 -0
  11. package/dist/did/index.d.ts.map +1 -0
  12. package/dist/did/index.js +24 -0
  13. package/dist/did/resolve-contract.d.ts +220 -0
  14. package/dist/did/resolve-contract.d.ts.map +1 -0
  15. package/dist/did/resolve-contract.js +32 -0
  16. package/dist/did/types.d.ts +164 -0
  17. package/dist/did/types.d.ts.map +1 -0
  18. package/dist/did/types.js +71 -0
  19. package/dist/env/constants.d.ts +58 -0
  20. package/dist/env/constants.d.ts.map +1 -0
  21. package/dist/env/constants.js +60 -0
  22. package/dist/env/index.d.ts +5 -0
  23. package/dist/env/index.d.ts.map +1 -0
  24. package/dist/env/index.js +21 -0
  25. package/dist/index.d.ts +9 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +17 -2
  28. package/dist/proof/index.d.ts +9 -0
  29. package/dist/proof/index.d.ts.map +1 -0
  30. package/dist/proof/index.js +25 -0
  31. package/dist/proof/proof-record.d.ts +838 -0
  32. package/dist/proof/proof-record.d.ts.map +1 -0
  33. package/dist/proof/proof-record.js +134 -0
  34. package/dist/proof/signing-spec.d.ts +147 -0
  35. package/dist/proof/signing-spec.d.ts.map +1 -0
  36. package/dist/proof/signing-spec.js +123 -0
  37. package/dist/runtime/errors.d.ts +348 -0
  38. package/dist/runtime/errors.d.ts.map +1 -0
  39. package/dist/runtime/errors.js +120 -0
  40. package/dist/runtime/headers.d.ts +84 -0
  41. package/dist/runtime/headers.d.ts.map +1 -0
  42. package/dist/runtime/headers.js +82 -0
  43. package/dist/runtime/index.d.ts +6 -0
  44. package/dist/runtime/index.d.ts.map +1 -0
  45. package/dist/runtime/index.js +22 -0
  46. package/dist/tlkrc/index.d.ts +5 -0
  47. package/dist/tlkrc/index.d.ts.map +1 -0
  48. package/dist/tlkrc/index.js +21 -0
  49. package/dist/tlkrc/rotation.d.ts +246 -0
  50. package/dist/tlkrc/rotation.d.ts.map +1 -0
  51. package/dist/tlkrc/rotation.js +127 -0
  52. package/dist/vc/index.d.ts +8 -0
  53. package/dist/vc/index.d.ts.map +1 -0
  54. package/dist/vc/index.js +24 -0
  55. package/dist/vc/schemas.d.ts +2484 -0
  56. package/dist/vc/schemas.d.ts.map +1 -0
  57. package/dist/vc/schemas.js +225 -0
  58. package/dist/vc/statuslist.d.ts +494 -0
  59. package/dist/vc/statuslist.d.ts.map +1 -0
  60. package/dist/vc/statuslist.js +133 -0
  61. package/package.json +52 -6
  62. package/dist/cli.js.map +0 -1
  63. package/dist/handshake.js.map +0 -1
  64. package/dist/index.js.map +0 -1
  65. package/dist/proof.js.map +0 -1
  66. package/dist/registry.js.map +0 -1
  67. package/dist/test.js.map +0 -1
  68. package/dist/utils/validation.js.map +0 -1
  69. package/dist/verifier.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/delegation/schemas.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,6CAA2C,CAAC;AAC/E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB;IACjC,2CAA2C;;IAG3C,y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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAG3C,gEAAgE;;IAGhE,uCAAuC;;IAGvC,wDAAwD;;IAGxD,oDAAoD;;IAGpD,qCAAqC;;IAGrC,wBAAwB;;iCAuIzB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAErD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAOzE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAO7E;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAchF;AAED;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,gBAA2B,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAAgB,EAAqC,CAAC"}
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ /**
3
+ * Delegation Record Schemas
4
+ *
5
+ * Types and schemas for delegation records that link VCs with CRISP constraints.
6
+ * Delegations represent the transfer of authority from one DID to another.
7
+ *
8
+ * Related Spec: MCP-I §4.1, §4.2
9
+ * Python Reference: Delegation-Documentation.md, Delegation-Service.md
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DELEGATION_STATUSES = exports.DEFAULT_DELEGATION_STATUS = exports.MAX_DELEGATION_CHAIN_DEPTH = exports.DelegationVerificationResultSchema = exports.DelegationCreationRequestSchema = exports.DelegationChainSchema = exports.DelegationChainEntrySchema = exports.DelegationRecordSchema = exports.DelegationStatusSchema = void 0;
13
+ exports.validateDelegationRecord = validateDelegationRecord;
14
+ exports.validateDelegationChain = validateDelegationChain;
15
+ exports.isDelegationExpired = isDelegationExpired;
16
+ exports.isDelegationNotYetValid = isDelegationNotYetValid;
17
+ exports.isDelegationCurrentlyValid = isDelegationCurrentlyValid;
18
+ const zod_1 = require("zod");
19
+ const constraints_js_1 = require("./constraints.js");
20
+ /**
21
+ * Delegation Status
22
+ *
23
+ * Lifecycle status of a delegation
24
+ */
25
+ exports.DelegationStatusSchema = zod_1.z.enum(['active', 'revoked', 'expired']);
26
+ /**
27
+ * Delegation Record Schema
28
+ *
29
+ * Complete delegation record linking issuer (delegator) to subject (delegatee)
30
+ * with backing VC and CRISP constraints.
31
+ *
32
+ * **Key Invariants:**
33
+ * - Delegation MUST reference a live VC via `vcId`
34
+ * - Revocation of VC invalidates all linked delegations
35
+ * - Chain: no cycles allowed
36
+ * - Child `notAfter` ≤ parent `notAfter`
37
+ * - Child scopes ⊆ parent scopes
38
+ * - Child budgets ≤ parent budgets (same unit)
39
+ */
40
+ exports.DelegationRecordSchema = zod_1.z.object({
41
+ /** Unique identifier for the delegation */
42
+ id: zod_1.z.string().min(1),
43
+ /** DID of the delegator (issuer, e.g., merchant/user) */
44
+ issuerDid: zod_1.z.string().min(1),
45
+ /** DID of the delegatee (subject, e.g., agent) */
46
+ subjectDid: zod_1.z.string().min(1),
47
+ /** Optional controller (user account ID or DID) */
48
+ controller: zod_1.z.string().optional(),
49
+ /** ID of the backing Verifiable Credential */
50
+ vcId: zod_1.z.string().min(1),
51
+ /** Optional parent delegation ID for chain tracking */
52
+ parentId: zod_1.z.string().optional(),
53
+ /** CRISP constraints on this delegation */
54
+ constraints: constraints_js_1.DelegationConstraintsSchema,
55
+ /** Detached JWS signature over canonical delegation document */
56
+ signature: zod_1.z.string().min(1),
57
+ /** Current status of the delegation */
58
+ status: exports.DelegationStatusSchema,
59
+ /** Timestamp when created (milliseconds since epoch) */
60
+ createdAt: zod_1.z.number().int().positive().optional(),
61
+ /** Timestamp when revoked (if status is revoked) */
62
+ revokedAt: zod_1.z.number().int().positive().optional(),
63
+ /** Optional reason for revocation */
64
+ revokedReason: zod_1.z.string().optional(),
65
+ /** Optional metadata */
66
+ metadata: zod_1.z.record(zod_1.z.any()).optional(),
67
+ }).passthrough(); // Allow extensibility
68
+ /**
69
+ * Delegation Chain Entry
70
+ *
71
+ * Represents a single link in a delegation chain
72
+ */
73
+ exports.DelegationChainEntrySchema = zod_1.z.object({
74
+ /** Delegation ID */
75
+ delegationId: zod_1.z.string().min(1),
76
+ /** Issuer DID */
77
+ issuerDid: zod_1.z.string().min(1),
78
+ /** Subject DID */
79
+ subjectDid: zod_1.z.string().min(1),
80
+ /** VC ID */
81
+ vcId: zod_1.z.string().min(1),
82
+ /** Depth in chain (0 = root) */
83
+ depth: zod_1.z.number().int().nonnegative(),
84
+ /** Constraints */
85
+ constraints: constraints_js_1.DelegationConstraintsSchema,
86
+ /** Status */
87
+ status: exports.DelegationStatusSchema,
88
+ });
89
+ /**
90
+ * Delegation Chain
91
+ *
92
+ * Represents a complete delegation chain from root to leaf
93
+ */
94
+ exports.DelegationChainSchema = zod_1.z.object({
95
+ /** Root issuer DID */
96
+ rootIssuer: zod_1.z.string().min(1),
97
+ /** Leaf subject DID */
98
+ leafSubject: zod_1.z.string().min(1),
99
+ /** All delegations in the chain, ordered root to leaf */
100
+ chain: zod_1.z.array(exports.DelegationChainEntrySchema).min(1),
101
+ /** Total chain depth */
102
+ depth: zod_1.z.number().int().nonnegative(),
103
+ /** Whether the entire chain is valid */
104
+ valid: zod_1.z.boolean(),
105
+ /** Optional validation errors */
106
+ errors: zod_1.z.array(zod_1.z.string()).optional(),
107
+ });
108
+ /**
109
+ * Delegation Creation Request
110
+ *
111
+ * Input for creating a new delegation
112
+ */
113
+ exports.DelegationCreationRequestSchema = zod_1.z.object({
114
+ /** Delegator DID */
115
+ issuerDid: zod_1.z.string().min(1),
116
+ /** Delegatee DID */
117
+ subjectDid: zod_1.z.string().min(1),
118
+ /** Optional controller */
119
+ controller: zod_1.z.string().optional(),
120
+ /** Constraints */
121
+ constraints: constraints_js_1.DelegationConstraintsSchema,
122
+ /** Optional parent delegation ID */
123
+ parentId: zod_1.z.string().optional(),
124
+ /** Optional VC ID (if not provided, will be created) */
125
+ vcId: zod_1.z.string().optional(),
126
+ });
127
+ /**
128
+ * Delegation Verification Result
129
+ *
130
+ * Result of delegation verification
131
+ */
132
+ exports.DelegationVerificationResultSchema = zod_1.z.object({
133
+ /** Whether delegation is valid */
134
+ valid: zod_1.z.boolean(),
135
+ /** Delegation ID */
136
+ delegationId: zod_1.z.string().min(1),
137
+ /** Status */
138
+ status: exports.DelegationStatusSchema,
139
+ /** Optional reason for invalid status */
140
+ reason: zod_1.z.string().optional(),
141
+ /** Whether backing VC is valid */
142
+ credentialValid: zod_1.z.boolean().optional(),
143
+ /** Whether chain is valid (if part of chain) */
144
+ chainValid: zod_1.z.boolean().optional(),
145
+ /** Timestamp of verification */
146
+ verifiedAt: zod_1.z.number().int().positive(),
147
+ /** Optional verification details */
148
+ details: zod_1.z.record(zod_1.z.any()).optional(),
149
+ });
150
+ /**
151
+ * Validation Helpers
152
+ */
153
+ /**
154
+ * Validate a delegation record
155
+ *
156
+ * @param record - The delegation record to validate
157
+ * @returns Validation result
158
+ */
159
+ function validateDelegationRecord(record) {
160
+ return exports.DelegationRecordSchema.safeParse(record);
161
+ }
162
+ /**
163
+ * Validate a delegation chain
164
+ *
165
+ * @param chain - The delegation chain to validate
166
+ * @returns Validation result
167
+ */
168
+ function validateDelegationChain(chain) {
169
+ return exports.DelegationChainSchema.safeParse(chain);
170
+ }
171
+ /**
172
+ * Check if a delegation is expired based on constraints
173
+ *
174
+ * @param delegation - The delegation to check
175
+ * @returns true if expired
176
+ */
177
+ function isDelegationExpired(delegation) {
178
+ if (!delegation.constraints.notAfter) {
179
+ return false;
180
+ }
181
+ const nowSec = Math.floor(Date.now() / 1000);
182
+ return nowSec > delegation.constraints.notAfter;
183
+ }
184
+ /**
185
+ * Check if a delegation is not yet valid based on constraints
186
+ *
187
+ * @param delegation - The delegation to check
188
+ * @returns true if not yet valid
189
+ */
190
+ function isDelegationNotYetValid(delegation) {
191
+ if (!delegation.constraints.notBefore) {
192
+ return false;
193
+ }
194
+ const nowSec = Math.floor(Date.now() / 1000);
195
+ return nowSec < delegation.constraints.notBefore;
196
+ }
197
+ /**
198
+ * Check if a delegation is currently valid (active and within time bounds)
199
+ *
200
+ * @param delegation - The delegation to check
201
+ * @returns true if currently valid
202
+ */
203
+ function isDelegationCurrentlyValid(delegation) {
204
+ if (delegation.status !== 'active') {
205
+ return false;
206
+ }
207
+ if (isDelegationExpired(delegation)) {
208
+ return false;
209
+ }
210
+ if (isDelegationNotYetValid(delegation)) {
211
+ return false;
212
+ }
213
+ return true;
214
+ }
215
+ /**
216
+ * Constants
217
+ */
218
+ /**
219
+ * Maximum reasonable delegation chain depth
220
+ */
221
+ exports.MAX_DELEGATION_CHAIN_DEPTH = 10;
222
+ /**
223
+ * Default delegation status for new delegations
224
+ */
225
+ exports.DEFAULT_DELEGATION_STATUS = 'active';
226
+ /**
227
+ * Supported delegation statuses
228
+ */
229
+ exports.DELEGATION_STATUSES = ['active', 'revoked', 'expired'];
230
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * DID Module Exports
3
+ *
4
+ * Types and contracts for W3C Decentralized Identifiers (DIDs)
5
+ */
6
+ export * from './types.js';
7
+ export * from './resolve-contract.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/did/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * DID Module Exports
4
+ *
5
+ * Types and contracts for W3C Decentralized Identifiers (DIDs)
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ __exportStar(require("./types.js"), exports);
23
+ __exportStar(require("./resolve-contract.js"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,220 @@
1
+ /**
2
+ * DID Resolver Contract
3
+ *
4
+ * Interface contracts for DID resolution across different implementations.
5
+ * This file contains ONLY interfaces and types - no functional code.
6
+ *
7
+ * Related Spec: MCP-I §2.3
8
+ * Python Reference: DID-Service.md
9
+ */
10
+ import type { DidDocument } from './types.js';
11
+ /**
12
+ * Options for DID resolution
13
+ */
14
+ export interface ResolveOptions {
15
+ /**
16
+ * Maximum time in milliseconds to wait for resolution
17
+ * Default: 500ms (as per env/constants.ts)
18
+ */
19
+ timeoutMs?: number;
20
+ /**
21
+ * Whether to accept cached resolution results
22
+ * If false, forces a fresh resolution
23
+ * Default: true
24
+ */
25
+ acceptCache?: boolean;
26
+ /**
27
+ * Desired cache TTL for this resolution in seconds
28
+ * Implementation may ignore if not applicable
29
+ */
30
+ cacheTtlSec?: number;
31
+ /**
32
+ * Additional metadata to pass to the resolver
33
+ * Used for method-specific resolution options
34
+ */
35
+ metadata?: Record<string, any>;
36
+ }
37
+ /**
38
+ * Result of DID resolution
39
+ *
40
+ * Contains the resolved DID Document and metadata about the resolution.
41
+ */
42
+ export interface ResolveResult {
43
+ /**
44
+ * The resolved DID Document
45
+ */
46
+ doc: DidDocument;
47
+ /**
48
+ * Timestamp (milliseconds since epoch) when the document was fetched
49
+ */
50
+ fetchedAt: number;
51
+ /**
52
+ * Cache TTL in seconds (if applicable)
53
+ * Indicates how long this result may be cached
54
+ */
55
+ cacheTtlSec?: number;
56
+ /**
57
+ * Metadata about the resolution process
58
+ * May include method-specific information
59
+ */
60
+ metadata?: {
61
+ /** Source of the resolution (e.g., "cache", "network", "local") */
62
+ source?: string;
63
+ /** Method used for resolution */
64
+ method?: string;
65
+ /** Whether the document was retrieved from cache */
66
+ fromCache?: boolean;
67
+ /** Additional method-specific metadata */
68
+ [key: string]: any;
69
+ };
70
+ }
71
+ /**
72
+ * Resolution Error Details
73
+ *
74
+ * Structure for errors during DID resolution.
75
+ */
76
+ export interface ResolutionError {
77
+ /** Error code (e.g., "notFound", "invalidDid", "methodNotSupported") */
78
+ code: string;
79
+ /** Human-readable error message */
80
+ message: string;
81
+ /** Original error if available */
82
+ cause?: Error;
83
+ /** Additional error details */
84
+ details?: Record<string, any>;
85
+ }
86
+ /**
87
+ * DID Resolver Interface
88
+ *
89
+ * Defines the contract for resolving DIDs to DID Documents.
90
+ * Implementations must handle different DID methods and provide caching.
91
+ *
92
+ * **Implementation Notes:**
93
+ * - Resolvers SHOULD support caching to improve performance
94
+ * - Resolvers MUST respect timeoutMs to prevent hanging
95
+ * - Resolvers MUST validate DID format before attempting resolution
96
+ * - Resolvers MAY support multiple DID methods via a registry pattern
97
+ *
98
+ * **Edge Compatibility:**
99
+ * Implementations intended for edge environments should:
100
+ * - Minimize dependencies
101
+ * - Support offline resolution where possible (e.g., did:key)
102
+ * - Use efficient caching strategies
103
+ * - Handle network failures gracefully
104
+ */
105
+ export interface DidResolver {
106
+ /**
107
+ * Resolve a DID to its DID Document
108
+ *
109
+ * @param did - The DID to resolve (e.g., "did:key:z6Mk...")
110
+ * @param opts - Resolution options
111
+ * @returns Promise resolving to the DID Document and metadata
112
+ * @throws {ResolutionError} If resolution fails
113
+ */
114
+ resolve(did: string, opts?: ResolveOptions): Promise<ResolveResult>;
115
+ }
116
+ /**
117
+ * DID Method Resolver Interface
118
+ *
119
+ * Interface for method-specific resolvers.
120
+ * A universal resolver delegates to method resolvers based on the DID method.
121
+ */
122
+ export interface DidMethodResolver {
123
+ /**
124
+ * The DID method this resolver handles (e.g., "key", "web")
125
+ */
126
+ readonly method: string;
127
+ /**
128
+ * Resolve a DID using this method
129
+ *
130
+ * @param did - The DID to resolve
131
+ * @param opts - Resolution options
132
+ * @returns Promise resolving to the DID Document and metadata
133
+ * @throws {ResolutionError} If resolution fails
134
+ */
135
+ resolve(did: string, opts?: ResolveOptions): Promise<ResolveResult>;
136
+ /**
137
+ * Check if this resolver supports the given DID
138
+ *
139
+ * @param did - The DID to check
140
+ * @returns true if this resolver can handle the DID
141
+ */
142
+ supports(did: string): boolean;
143
+ }
144
+ /**
145
+ * DID Resolution Cache Interface
146
+ *
147
+ * Interface for caching resolved DID Documents.
148
+ */
149
+ export interface DidResolutionCache {
150
+ /**
151
+ * Get a cached resolution result
152
+ *
153
+ * @param did - The DID to look up
154
+ * @returns Promise resolving to cached result or null if not found/expired
155
+ */
156
+ get(did: string): Promise<ResolveResult | null>;
157
+ /**
158
+ * Store a resolution result in cache
159
+ *
160
+ * @param did - The DID being cached
161
+ * @param result - The resolution result
162
+ * @param ttlSec - TTL in seconds
163
+ * @returns Promise resolving when stored
164
+ */
165
+ set(did: string, result: ResolveResult, ttlSec: number): Promise<void>;
166
+ /**
167
+ * Invalidate cached result for a DID
168
+ *
169
+ * @param did - The DID to invalidate
170
+ * @returns Promise resolving when invalidated
171
+ */
172
+ invalidate(did: string): Promise<void>;
173
+ /**
174
+ * Clear all cached results
175
+ *
176
+ * @returns Promise resolving when cleared
177
+ */
178
+ clear(): Promise<void>;
179
+ }
180
+ /**
181
+ * Universal DID Resolver Configuration
182
+ *
183
+ * Configuration for a universal resolver that delegates to method-specific resolvers.
184
+ */
185
+ export interface UniversalResolverConfig {
186
+ /**
187
+ * Method-specific resolvers
188
+ * Key is the method name (e.g., "key", "web")
189
+ */
190
+ methodResolvers?: Map<string, DidMethodResolver> | Record<string, DidMethodResolver>;
191
+ /**
192
+ * Optional cache implementation
193
+ */
194
+ cache?: DidResolutionCache;
195
+ /**
196
+ * Default resolution options
197
+ */
198
+ defaultOptions?: ResolveOptions;
199
+ }
200
+ /**
201
+ * Common resolution error codes
202
+ */
203
+ export declare const RESOLUTION_ERROR_CODES: {
204
+ /** DID not found */
205
+ readonly NOT_FOUND: "notFound";
206
+ /** Invalid DID format */
207
+ readonly INVALID_DID: "invalidDid";
208
+ /** DID method not supported */
209
+ readonly METHOD_NOT_SUPPORTED: "methodNotSupported";
210
+ /** Resolution timeout */
211
+ readonly TIMEOUT: "timeout";
212
+ /** Network error during resolution */
213
+ readonly NETWORK_ERROR: "networkError";
214
+ /** Invalid DID Document structure */
215
+ readonly INVALID_DOCUMENT: "invalidDocument";
216
+ /** Internal resolver error */
217
+ readonly INTERNAL_ERROR: "internalError";
218
+ };
219
+ export type ResolutionErrorCode = (typeof RESOLUTION_ERROR_CODES)[keyof typeof RESOLUTION_ERROR_CODES];
220
+ //# sourceMappingURL=resolve-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-contract.d.ts","sourceRoot":"","sources":["../../src/did/resolve-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAA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,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;IAEhD;;;;;;;OAOG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvE;;;;;OAKG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAErF;;OAEG;IACH,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAE3B;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB;IACjC,oBAAoB;;IAGpB,yBAAyB;;IAGzB,+BAA+B;;IAG/B,yBAAyB;;IAGzB,sCAAsC;;IAGtC,qCAAqC;;IAGrC,8BAA8B;;CAEtB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAC7B,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * DID Resolver Contract
4
+ *
5
+ * Interface contracts for DID resolution across different implementations.
6
+ * This file contains ONLY interfaces and types - no functional code.
7
+ *
8
+ * Related Spec: MCP-I §2.3
9
+ * Python Reference: DID-Service.md
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RESOLUTION_ERROR_CODES = void 0;
13
+ /**
14
+ * Common resolution error codes
15
+ */
16
+ exports.RESOLUTION_ERROR_CODES = {
17
+ /** DID not found */
18
+ NOT_FOUND: 'notFound',
19
+ /** Invalid DID format */
20
+ INVALID_DID: 'invalidDid',
21
+ /** DID method not supported */
22
+ METHOD_NOT_SUPPORTED: 'methodNotSupported',
23
+ /** Resolution timeout */
24
+ TIMEOUT: 'timeout',
25
+ /** Network error during resolution */
26
+ NETWORK_ERROR: 'networkError',
27
+ /** Invalid DID Document structure */
28
+ INVALID_DOCUMENT: 'invalidDocument',
29
+ /** Internal resolver error */
30
+ INTERNAL_ERROR: 'internalError',
31
+ };
32
+ //# sourceMappingURL=resolve-contract.js.map