@kya-os/contracts 1.2.1 → 1.2.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/delegation/constraints.d.ts +982 -0
- package/dist/delegation/constraints.js +205 -0
- package/dist/delegation/index.d.ts +8 -0
- package/dist/delegation/index.js +24 -0
- package/dist/delegation/schemas.d.ts +3787 -0
- package/dist/delegation/schemas.js +230 -0
- package/dist/did/index.d.ts +8 -0
- package/dist/did/index.js +24 -0
- package/dist/did/resolve-contract.d.ts +220 -0
- package/dist/did/resolve-contract.js +32 -0
- package/dist/did/types.d.ts +164 -0
- package/dist/did/types.js +71 -0
- package/dist/env/constants.d.ts +58 -0
- package/dist/env/constants.js +60 -0
- package/dist/env/index.d.ts +5 -0
- package/dist/env/index.js +21 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +17 -2
- package/dist/proof/index.d.ts +9 -0
- package/dist/proof/index.js +25 -0
- package/dist/proof/proof-record.d.ts +838 -0
- package/dist/proof/proof-record.js +134 -0
- package/dist/proof/signing-spec.d.ts +147 -0
- package/dist/proof/signing-spec.js +123 -0
- package/dist/runtime/errors.d.ts +348 -0
- package/dist/runtime/errors.js +120 -0
- package/dist/runtime/headers.d.ts +84 -0
- package/dist/runtime/headers.js +82 -0
- package/dist/runtime/index.d.ts +6 -0
- package/dist/runtime/index.js +22 -0
- package/dist/tlkrc/index.d.ts +5 -0
- package/dist/tlkrc/index.js +21 -0
- package/dist/tlkrc/rotation.d.ts +246 -0
- package/dist/tlkrc/rotation.js +127 -0
- package/dist/vc/index.d.ts +8 -0
- package/dist/vc/index.js +24 -0
- package/dist/vc/schemas.d.ts +2484 -0
- package/dist/vc/schemas.js +225 -0
- package/dist/vc/statuslist.d.ts +494 -0
- package/dist/vc/statuslist.js +133 -0
- package/package.json +51 -6
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/handshake.d.ts.map +0 -1
- package/dist/handshake.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/proof.d.ts.map +0 -1
- package/dist/proof.js.map +0 -1
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js.map +0 -1
- package/dist/test.d.ts.map +0 -1
- package/dist/test.js.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js.map +0 -1
- package/dist/verifier.d.ts.map +0 -1
- package/dist/verifier.js.map +0 -1
|
@@ -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,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,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
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DID Document Types (W3C Compliant)
|
|
3
|
+
*
|
|
4
|
+
* These types conform to the W3C DID Core specification and provide
|
|
5
|
+
* TypeScript parity with the Python implementation.
|
|
6
|
+
*
|
|
7
|
+
* Related Spec: MCP-I §2.1, §2.3
|
|
8
|
+
* Python Reference: DID-Documentation.md, DID-Service.md
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Verification Method Types
|
|
12
|
+
*
|
|
13
|
+
* Supported types for verification methods in DID Documents.
|
|
14
|
+
*/
|
|
15
|
+
export type VerificationMethodType = 'Ed25519VerificationKey2020' | 'JsonWebKey2020' | 'EcdsaSecp256k1VerificationKey2019';
|
|
16
|
+
/**
|
|
17
|
+
* Verification Method
|
|
18
|
+
*
|
|
19
|
+
* A verification method as defined in the W3C DID Core specification.
|
|
20
|
+
* Used for cryptographic verification of signatures and authentication.
|
|
21
|
+
*
|
|
22
|
+
* **kid Derivation Guidelines:**
|
|
23
|
+
* - For did:key: kid = `${did}#${multibaseKey}`
|
|
24
|
+
* - For did:web: kid = `${did}#${keyId}` where keyId is from DID Document
|
|
25
|
+
* - The kid MUST be resolvable to a verification method in the DID Document
|
|
26
|
+
*/
|
|
27
|
+
export interface VerificationMethod {
|
|
28
|
+
/** Verification method identifier (e.g., "#key-1" or full DID URL) */
|
|
29
|
+
id: string;
|
|
30
|
+
/** Type of verification method */
|
|
31
|
+
type: VerificationMethodType;
|
|
32
|
+
/** DID of the controller of this verification method */
|
|
33
|
+
controller: string;
|
|
34
|
+
/**
|
|
35
|
+
* Public key encoded as multibase for Ed25519VerificationKey2020
|
|
36
|
+
* Format: z + base58btc(public key bytes)
|
|
37
|
+
*/
|
|
38
|
+
publicKeyMultibase?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Public key as JSON Web Key for JsonWebKey2020
|
|
41
|
+
* See RFC 7517 for JWK format
|
|
42
|
+
*/
|
|
43
|
+
publicKeyJwk?: {
|
|
44
|
+
kty: string;
|
|
45
|
+
crv: string;
|
|
46
|
+
x: string;
|
|
47
|
+
y?: string;
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* DID Service
|
|
53
|
+
*
|
|
54
|
+
* A service endpoint as defined in the W3C DID Core specification.
|
|
55
|
+
* Services enable discovery of service endpoints for the DID subject.
|
|
56
|
+
*/
|
|
57
|
+
export interface DidService {
|
|
58
|
+
/** Service identifier (e.g., "#service-1") */
|
|
59
|
+
id: string;
|
|
60
|
+
/** Service type (e.g., "LinkedDomains", "CredentialRegistry") */
|
|
61
|
+
type: string | string[];
|
|
62
|
+
/** Service endpoint URL(s) or endpoint descriptor object */
|
|
63
|
+
serviceEndpoint: string | string[] | Record<string, any>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* DID Document
|
|
67
|
+
*
|
|
68
|
+
* A DID Document as defined in the W3C DID Core specification.
|
|
69
|
+
* Represents the full descriptor of a DID, including verification methods
|
|
70
|
+
* and service endpoints.
|
|
71
|
+
*
|
|
72
|
+
* **Supported DID Methods:**
|
|
73
|
+
* - did:key - Self-contained, ephemeral identities
|
|
74
|
+
* - did:web - Domain-bound identities resolved via HTTPS
|
|
75
|
+
* - did:jwk - JWK-based identities
|
|
76
|
+
*
|
|
77
|
+
* **@context:**
|
|
78
|
+
* While the W3C spec requires @context, it's optional in this type to support
|
|
79
|
+
* simplified parsing. Implementations should include "https://www.w3.org/ns/did/v1"
|
|
80
|
+
* as the base context.
|
|
81
|
+
*/
|
|
82
|
+
export interface DidDocument {
|
|
83
|
+
/** JSON-LD context (typically "https://www.w3.org/ns/did/v1") */
|
|
84
|
+
'@context'?: string | string[] | Record<string, any>;
|
|
85
|
+
/** The DID this document describes (e.g., "did:key:z6Mk...") */
|
|
86
|
+
id: string;
|
|
87
|
+
/** Also known as - alternative identifiers for this DID */
|
|
88
|
+
alsoKnownAs?: string[];
|
|
89
|
+
/**
|
|
90
|
+
* Verification methods available for this DID
|
|
91
|
+
* Contains public key information for signature verification
|
|
92
|
+
*/
|
|
93
|
+
verificationMethod?: VerificationMethod[];
|
|
94
|
+
/**
|
|
95
|
+
* Authentication verification relationship
|
|
96
|
+
* References to verification methods or embedded methods
|
|
97
|
+
* Used for authenticating as the DID subject
|
|
98
|
+
*/
|
|
99
|
+
authentication?: (string | VerificationMethod)[];
|
|
100
|
+
/**
|
|
101
|
+
* Assertion method verification relationship
|
|
102
|
+
* References to verification methods or embedded methods
|
|
103
|
+
* Used for issuing verifiable credentials
|
|
104
|
+
*/
|
|
105
|
+
assertionMethod?: (string | VerificationMethod)[];
|
|
106
|
+
/**
|
|
107
|
+
* Key agreement verification relationship
|
|
108
|
+
* References to verification methods or embedded methods
|
|
109
|
+
* Used for encryption and key agreement protocols
|
|
110
|
+
*/
|
|
111
|
+
keyAgreement?: (string | VerificationMethod)[];
|
|
112
|
+
/**
|
|
113
|
+
* Capability invocation verification relationship
|
|
114
|
+
* References to verification methods or embedded methods
|
|
115
|
+
* Used for invoking capabilities
|
|
116
|
+
*/
|
|
117
|
+
capabilityInvocation?: (string | VerificationMethod)[];
|
|
118
|
+
/**
|
|
119
|
+
* Capability delegation verification relationship
|
|
120
|
+
* References to verification methods or embedded methods
|
|
121
|
+
* Used for delegating capabilities
|
|
122
|
+
*/
|
|
123
|
+
capabilityDelegation?: (string | VerificationMethod)[];
|
|
124
|
+
/** Service endpoints for the DID */
|
|
125
|
+
service?: DidService[];
|
|
126
|
+
/** Additional properties allowed for extensibility */
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* DID Method
|
|
131
|
+
*
|
|
132
|
+
* String literal type for supported DID methods
|
|
133
|
+
*/
|
|
134
|
+
export type DidMethod = 'key' | 'web' | 'jwk' | 'ion' | 'ebsi';
|
|
135
|
+
/**
|
|
136
|
+
* Helper type guards
|
|
137
|
+
*/
|
|
138
|
+
/**
|
|
139
|
+
* Type guard to check if a value is a VerificationMethod
|
|
140
|
+
*/
|
|
141
|
+
export declare function isVerificationMethod(value: any): value is VerificationMethod;
|
|
142
|
+
/**
|
|
143
|
+
* Type guard to check if a value is a string reference to a verification method
|
|
144
|
+
*/
|
|
145
|
+
export declare function isVerificationMethodReference(value: any): value is string;
|
|
146
|
+
/**
|
|
147
|
+
* Type guard to check if a DID Document is valid (basic structural check)
|
|
148
|
+
*/
|
|
149
|
+
export declare function isDidDocument(value: any): value is DidDocument;
|
|
150
|
+
/**
|
|
151
|
+
* Extract DID method from a DID string
|
|
152
|
+
*
|
|
153
|
+
* @param did - The DID string (e.g., "did:key:z6Mk...")
|
|
154
|
+
* @returns The method name (e.g., "key") or null if invalid
|
|
155
|
+
*/
|
|
156
|
+
export declare function extractDidMethod(did: string): string | null;
|
|
157
|
+
/**
|
|
158
|
+
* Extract key ID from a DID URL
|
|
159
|
+
*
|
|
160
|
+
* @param didUrl - A DID URL with fragment (e.g., "did:key:z6Mk...#key-1")
|
|
161
|
+
* @returns The fragment part (e.g., "key-1") or null if no fragment
|
|
162
|
+
*/
|
|
163
|
+
export declare function extractKeyId(didUrl: string): string | null;
|
|
164
|
+
//# sourceMappingURL=types.d.ts.map
|