@kya-os/contracts 1.3.2 → 1.3.4
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/package.json +28 -5
- package/README.md +0 -130
- package/dist/cli.d.ts +0 -378
- package/dist/cli.js +0 -116
- package/dist/delegation/constraints.d.ts +0 -992
- package/dist/delegation/constraints.js +0 -210
- package/dist/delegation/index.d.ts +0 -8
- package/dist/delegation/index.js +0 -24
- package/dist/delegation/schemas.d.ts +0 -8382
- package/dist/delegation/schemas.js +0 -476
- package/dist/did/index.d.ts +0 -9
- package/dist/did/index.js +0 -25
- package/dist/did/resolve-contract.d.ts +0 -220
- package/dist/did/resolve-contract.js +0 -32
- package/dist/did/schemas.d.ts +0 -113
- package/dist/did/schemas.js +0 -173
- package/dist/did/types.d.ts +0 -164
- package/dist/did/types.js +0 -71
- package/dist/env/constants.d.ts +0 -58
- package/dist/env/constants.js +0 -60
- package/dist/env/index.d.ts +0 -5
- package/dist/env/index.js +0 -21
- package/dist/handshake.d.ts +0 -159
- package/dist/handshake.js +0 -58
- package/dist/index.d.ts +0 -26
- package/dist/index.js +0 -53
- package/dist/proof/index.d.ts +0 -9
- package/dist/proof/index.js +0 -25
- package/dist/proof/proof-record.d.ts +0 -838
- package/dist/proof/proof-record.js +0 -134
- package/dist/proof/signing-spec.d.ts +0 -147
- package/dist/proof/signing-spec.js +0 -123
- package/dist/proof.d.ts +0 -400
- package/dist/proof.js +0 -82
- package/dist/registry.d.ts +0 -343
- package/dist/registry.js +0 -119
- package/dist/runtime/errors.d.ts +0 -348
- package/dist/runtime/errors.js +0 -120
- package/dist/runtime/headers.d.ts +0 -84
- package/dist/runtime/headers.js +0 -82
- package/dist/runtime/index.d.ts +0 -6
- package/dist/runtime/index.js +0 -22
- package/dist/test.d.ts +0 -252
- package/dist/test.js +0 -120
- package/dist/tlkrc/index.d.ts +0 -5
- package/dist/tlkrc/index.js +0 -21
- package/dist/tlkrc/rotation.d.ts +0 -246
- package/dist/tlkrc/rotation.js +0 -127
- package/dist/utils/validation.d.ts +0 -31
- package/dist/utils/validation.js +0 -70
- package/dist/vc/index.d.ts +0 -8
- package/dist/vc/index.js +0 -24
- package/dist/vc/schemas.d.ts +0 -2484
- package/dist/vc/schemas.js +0 -225
- package/dist/vc/statuslist.d.ts +0 -494
- package/dist/vc/statuslist.js +0 -133
- package/dist/verifier.d.ts +0 -206
- package/dist/verifier.js +0 -84
|
@@ -1,476 +0,0 @@
|
|
|
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
|
-
* **IMPORTANT**: Per Python POC design (Delegation-Service.md:136-146),
|
|
9
|
-
* delegations SHOULD be issued as W3C Verifiable Credentials, not just reference them.
|
|
10
|
-
* This file provides both:
|
|
11
|
-
* - DelegationRecord: Legacy/internal format (contains delegation data)
|
|
12
|
-
* - DelegationCredential: W3C VC format (delegation as credentialSubject)
|
|
13
|
-
*
|
|
14
|
-
* Related Spec: MCP-I §4.1, §4.2, W3C VC Data Model 1.1
|
|
15
|
-
* Python Reference: Delegation-Documentation.md, Delegation-Service.md
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.DelegationCredentialSchema = exports.DelegationCredentialSubjectSchema = exports.DELEGATION_CREDENTIAL_CONTEXT = 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;
|
|
19
|
-
exports.validateDelegationRecord = validateDelegationRecord;
|
|
20
|
-
exports.validateDelegationChain = validateDelegationChain;
|
|
21
|
-
exports.isDelegationExpired = isDelegationExpired;
|
|
22
|
-
exports.isDelegationNotYetValid = isDelegationNotYetValid;
|
|
23
|
-
exports.isDelegationCurrentlyValid = isDelegationCurrentlyValid;
|
|
24
|
-
exports.validateDelegationCredential = validateDelegationCredential;
|
|
25
|
-
exports.extractDelegationFromVC = extractDelegationFromVC;
|
|
26
|
-
exports.wrapDelegationAsVC = wrapDelegationAsVC;
|
|
27
|
-
exports.isDelegationCredentialExpired = isDelegationCredentialExpired;
|
|
28
|
-
exports.isDelegationCredentialNotYetValid = isDelegationCredentialNotYetValid;
|
|
29
|
-
const zod_1 = require("zod");
|
|
30
|
-
const constraints_js_1 = require("./constraints.js");
|
|
31
|
-
const schemas_js_1 = require("../vc/schemas.js");
|
|
32
|
-
/**
|
|
33
|
-
* Delegation Status
|
|
34
|
-
*
|
|
35
|
-
* Lifecycle status of a delegation
|
|
36
|
-
*/
|
|
37
|
-
exports.DelegationStatusSchema = zod_1.z.enum(['active', 'revoked', 'expired']);
|
|
38
|
-
/**
|
|
39
|
-
* Delegation Record Schema
|
|
40
|
-
*
|
|
41
|
-
* Complete delegation record linking issuer (delegator) to subject (delegatee)
|
|
42
|
-
* with backing VC and CRISP constraints.
|
|
43
|
-
*
|
|
44
|
-
* **Key Invariants:**
|
|
45
|
-
* - Delegation MUST reference a live VC via `vcId`
|
|
46
|
-
* - Revocation of VC invalidates all linked delegations
|
|
47
|
-
* - Chain: no cycles allowed
|
|
48
|
-
* - Child `notAfter` ≤ parent `notAfter`
|
|
49
|
-
* - Child scopes ⊆ parent scopes
|
|
50
|
-
* - Child budgets ≤ parent budgets (same unit)
|
|
51
|
-
*/
|
|
52
|
-
exports.DelegationRecordSchema = zod_1.z.object({
|
|
53
|
-
/** Unique identifier for the delegation */
|
|
54
|
-
id: zod_1.z.string().min(1),
|
|
55
|
-
/** DID of the delegator (issuer, e.g., merchant/user) */
|
|
56
|
-
issuerDid: zod_1.z.string().min(1),
|
|
57
|
-
/** DID of the delegatee (subject, e.g., agent) */
|
|
58
|
-
subjectDid: zod_1.z.string().min(1),
|
|
59
|
-
/** Optional controller (user account ID or DID) */
|
|
60
|
-
controller: zod_1.z.string().optional(),
|
|
61
|
-
/** ID of the backing Verifiable Credential */
|
|
62
|
-
vcId: zod_1.z.string().min(1),
|
|
63
|
-
/** Optional parent delegation ID for chain tracking */
|
|
64
|
-
parentId: zod_1.z.string().optional(),
|
|
65
|
-
/** CRISP constraints on this delegation */
|
|
66
|
-
constraints: constraints_js_1.DelegationConstraintsSchema,
|
|
67
|
-
/** Detached JWS signature over canonical delegation document */
|
|
68
|
-
signature: zod_1.z.string().min(1),
|
|
69
|
-
/** Current status of the delegation */
|
|
70
|
-
status: exports.DelegationStatusSchema,
|
|
71
|
-
/** Timestamp when created (milliseconds since epoch) */
|
|
72
|
-
createdAt: zod_1.z.number().int().positive().optional(),
|
|
73
|
-
/** Timestamp when revoked (if status is revoked) */
|
|
74
|
-
revokedAt: zod_1.z.number().int().positive().optional(),
|
|
75
|
-
/** Optional reason for revocation */
|
|
76
|
-
revokedReason: zod_1.z.string().optional(),
|
|
77
|
-
/** Optional metadata */
|
|
78
|
-
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
79
|
-
}).passthrough(); // Allow extensibility
|
|
80
|
-
/**
|
|
81
|
-
* Delegation Chain Entry
|
|
82
|
-
*
|
|
83
|
-
* Represents a single link in a delegation chain
|
|
84
|
-
*/
|
|
85
|
-
exports.DelegationChainEntrySchema = zod_1.z.object({
|
|
86
|
-
/** Delegation ID */
|
|
87
|
-
delegationId: zod_1.z.string().min(1),
|
|
88
|
-
/** Issuer DID */
|
|
89
|
-
issuerDid: zod_1.z.string().min(1),
|
|
90
|
-
/** Subject DID */
|
|
91
|
-
subjectDid: zod_1.z.string().min(1),
|
|
92
|
-
/** VC ID */
|
|
93
|
-
vcId: zod_1.z.string().min(1),
|
|
94
|
-
/** Depth in chain (0 = root) */
|
|
95
|
-
depth: zod_1.z.number().int().nonnegative(),
|
|
96
|
-
/** Constraints */
|
|
97
|
-
constraints: constraints_js_1.DelegationConstraintsSchema,
|
|
98
|
-
/** Status */
|
|
99
|
-
status: exports.DelegationStatusSchema,
|
|
100
|
-
});
|
|
101
|
-
/**
|
|
102
|
-
* Delegation Chain
|
|
103
|
-
*
|
|
104
|
-
* Represents a complete delegation chain from root to leaf
|
|
105
|
-
*/
|
|
106
|
-
exports.DelegationChainSchema = zod_1.z.object({
|
|
107
|
-
/** Root issuer DID */
|
|
108
|
-
rootIssuer: zod_1.z.string().min(1),
|
|
109
|
-
/** Leaf subject DID */
|
|
110
|
-
leafSubject: zod_1.z.string().min(1),
|
|
111
|
-
/** All delegations in the chain, ordered root to leaf */
|
|
112
|
-
chain: zod_1.z.array(exports.DelegationChainEntrySchema).min(1),
|
|
113
|
-
/** Total chain depth */
|
|
114
|
-
depth: zod_1.z.number().int().nonnegative(),
|
|
115
|
-
/** Whether the entire chain is valid */
|
|
116
|
-
valid: zod_1.z.boolean(),
|
|
117
|
-
/** Optional validation errors */
|
|
118
|
-
errors: zod_1.z.array(zod_1.z.string()).optional(),
|
|
119
|
-
});
|
|
120
|
-
/**
|
|
121
|
-
* Delegation Creation Request
|
|
122
|
-
*
|
|
123
|
-
* Input for creating a new delegation
|
|
124
|
-
*/
|
|
125
|
-
exports.DelegationCreationRequestSchema = zod_1.z.object({
|
|
126
|
-
/** Delegator DID */
|
|
127
|
-
issuerDid: zod_1.z.string().min(1),
|
|
128
|
-
/** Delegatee DID */
|
|
129
|
-
subjectDid: zod_1.z.string().min(1),
|
|
130
|
-
/** Optional controller */
|
|
131
|
-
controller: zod_1.z.string().optional(),
|
|
132
|
-
/** Constraints */
|
|
133
|
-
constraints: constraints_js_1.DelegationConstraintsSchema,
|
|
134
|
-
/** Optional parent delegation ID */
|
|
135
|
-
parentId: zod_1.z.string().optional(),
|
|
136
|
-
/** Optional VC ID (if not provided, will be created) */
|
|
137
|
-
vcId: zod_1.z.string().optional(),
|
|
138
|
-
});
|
|
139
|
-
/**
|
|
140
|
-
* Delegation Verification Result
|
|
141
|
-
*
|
|
142
|
-
* Result of delegation verification
|
|
143
|
-
*/
|
|
144
|
-
exports.DelegationVerificationResultSchema = zod_1.z.object({
|
|
145
|
-
/** Whether delegation is valid */
|
|
146
|
-
valid: zod_1.z.boolean(),
|
|
147
|
-
/** Delegation ID */
|
|
148
|
-
delegationId: zod_1.z.string().min(1),
|
|
149
|
-
/** Status */
|
|
150
|
-
status: exports.DelegationStatusSchema,
|
|
151
|
-
/** Optional reason for invalid status */
|
|
152
|
-
reason: zod_1.z.string().optional(),
|
|
153
|
-
/** Whether backing VC is valid */
|
|
154
|
-
credentialValid: zod_1.z.boolean().optional(),
|
|
155
|
-
/** Whether chain is valid (if part of chain) */
|
|
156
|
-
chainValid: zod_1.z.boolean().optional(),
|
|
157
|
-
/** Timestamp of verification */
|
|
158
|
-
verifiedAt: zod_1.z.number().int().positive(),
|
|
159
|
-
/** Optional verification details */
|
|
160
|
-
details: zod_1.z.record(zod_1.z.any()).optional(),
|
|
161
|
-
});
|
|
162
|
-
/**
|
|
163
|
-
* Validation Helpers
|
|
164
|
-
*/
|
|
165
|
-
/**
|
|
166
|
-
* Validate a delegation record
|
|
167
|
-
*
|
|
168
|
-
* @param record - The delegation record to validate
|
|
169
|
-
* @returns Validation result
|
|
170
|
-
*/
|
|
171
|
-
function validateDelegationRecord(record) {
|
|
172
|
-
return exports.DelegationRecordSchema.safeParse(record);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Validate a delegation chain
|
|
176
|
-
*
|
|
177
|
-
* @param chain - The delegation chain to validate
|
|
178
|
-
* @returns Validation result
|
|
179
|
-
*/
|
|
180
|
-
function validateDelegationChain(chain) {
|
|
181
|
-
return exports.DelegationChainSchema.safeParse(chain);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Check if a delegation is expired based on constraints
|
|
185
|
-
*
|
|
186
|
-
* @param delegation - The delegation to check
|
|
187
|
-
* @returns true if expired
|
|
188
|
-
*/
|
|
189
|
-
function isDelegationExpired(delegation) {
|
|
190
|
-
if (!delegation.constraints.notAfter) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
const nowSec = Math.floor(Date.now() / 1000);
|
|
194
|
-
return nowSec > delegation.constraints.notAfter;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Check if a delegation is not yet valid based on constraints
|
|
198
|
-
*
|
|
199
|
-
* @param delegation - The delegation to check
|
|
200
|
-
* @returns true if not yet valid
|
|
201
|
-
*/
|
|
202
|
-
function isDelegationNotYetValid(delegation) {
|
|
203
|
-
if (!delegation.constraints.notBefore) {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
const nowSec = Math.floor(Date.now() / 1000);
|
|
207
|
-
return nowSec < delegation.constraints.notBefore;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Check if a delegation is currently valid (active and within time bounds)
|
|
211
|
-
*
|
|
212
|
-
* @param delegation - The delegation to check
|
|
213
|
-
* @returns true if currently valid
|
|
214
|
-
*/
|
|
215
|
-
function isDelegationCurrentlyValid(delegation) {
|
|
216
|
-
if (delegation.status !== 'active') {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
if (isDelegationExpired(delegation)) {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
if (isDelegationNotYetValid(delegation)) {
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
return true;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Constants
|
|
229
|
-
*/
|
|
230
|
-
/**
|
|
231
|
-
* Maximum reasonable delegation chain depth
|
|
232
|
-
*/
|
|
233
|
-
exports.MAX_DELEGATION_CHAIN_DEPTH = 10;
|
|
234
|
-
/**
|
|
235
|
-
* Default delegation status for new delegations
|
|
236
|
-
*/
|
|
237
|
-
exports.DEFAULT_DELEGATION_STATUS = 'active';
|
|
238
|
-
/**
|
|
239
|
-
* Supported delegation statuses
|
|
240
|
-
*/
|
|
241
|
-
exports.DELEGATION_STATUSES = ['active', 'revoked', 'expired'];
|
|
242
|
-
// ============================================================================
|
|
243
|
-
// W3C VC-BASED DELEGATION CREDENTIALS (Phase 3 Implementation)
|
|
244
|
-
// ============================================================================
|
|
245
|
-
/**
|
|
246
|
-
* Delegation Credential Context
|
|
247
|
-
*
|
|
248
|
-
* Additional JSON-LD context for delegation credentials
|
|
249
|
-
*/
|
|
250
|
-
exports.DELEGATION_CREDENTIAL_CONTEXT = 'https://schemas.kya-os.ai/xmcp-i/credentials/delegation.v1.0.0.json';
|
|
251
|
-
/**
|
|
252
|
-
* Delegation Credential Subject Schema
|
|
253
|
-
*
|
|
254
|
-
* The credentialSubject of a DelegationCredential contains:
|
|
255
|
-
* - id: The delegatee DID (subject of the delegation)
|
|
256
|
-
* - delegation: The complete delegation record
|
|
257
|
-
*
|
|
258
|
-
* Per Python POC (Delegation-Service.md:136-146), delegations are issued AS
|
|
259
|
-
* W3C VCs, with the delegation data embedded in the credentialSubject.
|
|
260
|
-
*/
|
|
261
|
-
exports.DelegationCredentialSubjectSchema = zod_1.z.object({
|
|
262
|
-
/** Subject DID (delegatee) */
|
|
263
|
-
id: zod_1.z.string().min(1),
|
|
264
|
-
/** The delegation information */
|
|
265
|
-
delegation: zod_1.z.object({
|
|
266
|
-
/** Unique identifier for the delegation */
|
|
267
|
-
id: zod_1.z.string().min(1),
|
|
268
|
-
/** DID of the delegator (issuer, e.g., merchant/user) */
|
|
269
|
-
issuerDid: zod_1.z.string().min(1),
|
|
270
|
-
/** DID of the delegatee (subject, e.g., agent) */
|
|
271
|
-
subjectDid: zod_1.z.string().min(1),
|
|
272
|
-
/** Optional controller (user account ID or DID) */
|
|
273
|
-
controller: zod_1.z.string().optional(),
|
|
274
|
-
/** Optional parent delegation ID for chain tracking */
|
|
275
|
-
parentId: zod_1.z.string().optional(),
|
|
276
|
-
/** CRISP constraints on this delegation */
|
|
277
|
-
constraints: constraints_js_1.DelegationConstraintsSchema,
|
|
278
|
-
/** Current status of the delegation */
|
|
279
|
-
status: exports.DelegationStatusSchema.default('active'),
|
|
280
|
-
/** Timestamp when created (milliseconds since epoch) */
|
|
281
|
-
createdAt: zod_1.z.number().int().positive().optional(),
|
|
282
|
-
/** Optional metadata */
|
|
283
|
-
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
284
|
-
}),
|
|
285
|
-
});
|
|
286
|
-
/**
|
|
287
|
-
* Delegation Credential Schema
|
|
288
|
-
*
|
|
289
|
-
* W3C Verifiable Credential for delegations.
|
|
290
|
-
* This is the PRIMARY format for delegation issuance and verification.
|
|
291
|
-
*
|
|
292
|
-
* Structure:
|
|
293
|
-
* - @context: [...W3C VC contexts, delegation context]
|
|
294
|
-
* - type: ['VerifiableCredential', 'DelegationCredential']
|
|
295
|
-
* - issuer: Delegator DID
|
|
296
|
-
* - issuanceDate: When delegation was created
|
|
297
|
-
* - expirationDate: Maps to delegation.constraints.notAfter
|
|
298
|
-
* - credentialSubject: Contains delegatee DID + delegation data
|
|
299
|
-
* - credentialStatus: StatusList2021Entry for revocation checking
|
|
300
|
-
* - proof: Ed25519Signature2020
|
|
301
|
-
*
|
|
302
|
-
* Per Python POC design (Delegation-Service.md:136-163):
|
|
303
|
-
* - Every delegation MUST be issued as a VC
|
|
304
|
-
* - Verification checks BOTH the VC signature AND delegation constraints
|
|
305
|
-
* - Revocation updates the StatusList2021
|
|
306
|
-
*
|
|
307
|
-
* Related Spec: MCP-I §4.1, §4.2, W3C VC Data Model 1.1
|
|
308
|
-
*/
|
|
309
|
-
exports.DelegationCredentialSchema = schemas_js_1.VerifiableCredentialSchema.extend({
|
|
310
|
-
/** @context MUST include delegation context */
|
|
311
|
-
'@context': zod_1.z
|
|
312
|
-
.array(zod_1.z.union([zod_1.z.string().url(), zod_1.z.record(zod_1.z.any())]))
|
|
313
|
-
.refine((contexts) => {
|
|
314
|
-
// Check for W3C VC context (first)
|
|
315
|
-
const firstContext = contexts[0];
|
|
316
|
-
if (typeof firstContext !== 'string' ||
|
|
317
|
-
firstContext !== 'https://www.w3.org/2018/credentials/v1') {
|
|
318
|
-
return false;
|
|
319
|
-
}
|
|
320
|
-
// Optionally include delegation context (recommended)
|
|
321
|
-
return true;
|
|
322
|
-
}, {
|
|
323
|
-
message: 'First @context must be W3C VC context',
|
|
324
|
-
}),
|
|
325
|
-
/** type MUST include both VerifiableCredential and DelegationCredential */
|
|
326
|
-
type: zod_1.z
|
|
327
|
-
.array(zod_1.z.string())
|
|
328
|
-
.refine((types) => types.includes('VerifiableCredential') &&
|
|
329
|
-
types.includes('DelegationCredential'), {
|
|
330
|
-
message: 'type must include both "VerifiableCredential" and "DelegationCredential"',
|
|
331
|
-
}),
|
|
332
|
-
/** issuer is the delegator DID */
|
|
333
|
-
issuer: schemas_js_1.IssuerSchema,
|
|
334
|
-
/** issuanceDate maps to delegation creation time */
|
|
335
|
-
issuanceDate: zod_1.z.string().datetime(),
|
|
336
|
-
/** expirationDate maps to delegation.constraints.notAfter */
|
|
337
|
-
expirationDate: zod_1.z.string().datetime().optional(),
|
|
338
|
-
/** credentialSubject contains delegatee DID + delegation data */
|
|
339
|
-
credentialSubject: exports.DelegationCredentialSubjectSchema,
|
|
340
|
-
/** credentialStatus for StatusList2021 revocation checking */
|
|
341
|
-
credentialStatus: schemas_js_1.CredentialStatusSchema.optional(),
|
|
342
|
-
/** proof is Ed25519Signature2020 */
|
|
343
|
-
proof: schemas_js_1.ProofSchema.optional(),
|
|
344
|
-
});
|
|
345
|
-
/**
|
|
346
|
-
* Validate a delegation credential
|
|
347
|
-
*
|
|
348
|
-
* @param credential - The delegation credential to validate
|
|
349
|
-
* @returns Validation result
|
|
350
|
-
*/
|
|
351
|
-
function validateDelegationCredential(credential) {
|
|
352
|
-
return exports.DelegationCredentialSchema.safeParse(credential);
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Extract DelegationRecord from DelegationCredential
|
|
356
|
-
*
|
|
357
|
-
* Utility to extract the legacy DelegationRecord format from a W3C VC.
|
|
358
|
-
* Useful for backward compatibility and internal processing.
|
|
359
|
-
*
|
|
360
|
-
* @param vc - The delegation credential
|
|
361
|
-
* @returns DelegationRecord
|
|
362
|
-
*/
|
|
363
|
-
function extractDelegationFromVC(vc) {
|
|
364
|
-
const delegation = vc.credentialSubject.delegation;
|
|
365
|
-
// Extract signature from proof (may be in different formats)
|
|
366
|
-
let signature = '';
|
|
367
|
-
if (vc.proof) {
|
|
368
|
-
const proof = vc.proof;
|
|
369
|
-
signature = proof.proofValue || proof.jws || proof.signatureValue || '';
|
|
370
|
-
}
|
|
371
|
-
return {
|
|
372
|
-
id: delegation.id,
|
|
373
|
-
issuerDid: delegation.issuerDid,
|
|
374
|
-
subjectDid: delegation.subjectDid,
|
|
375
|
-
controller: delegation.controller,
|
|
376
|
-
vcId: vc.id || `vc:${delegation.id}`, // VC id becomes vcId
|
|
377
|
-
parentId: delegation.parentId,
|
|
378
|
-
constraints: delegation.constraints,
|
|
379
|
-
signature,
|
|
380
|
-
status: delegation.status,
|
|
381
|
-
createdAt: delegation.createdAt,
|
|
382
|
-
revokedAt: undefined, // Revocation status comes from credentialStatus
|
|
383
|
-
revokedReason: undefined,
|
|
384
|
-
metadata: delegation.metadata,
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Create DelegationCredential from DelegationRecord (unsigned)
|
|
389
|
-
*
|
|
390
|
-
* Wraps a DelegationRecord in a W3C VC structure (without proof).
|
|
391
|
-
* The caller must sign this to create a valid DelegationCredential.
|
|
392
|
-
*
|
|
393
|
-
* @param delegation - The delegation record
|
|
394
|
-
* @param options - Optional VC options (id, issuanceDate, etc.)
|
|
395
|
-
* @returns Unsigned DelegationCredential
|
|
396
|
-
*/
|
|
397
|
-
function wrapDelegationAsVC(delegation, options) {
|
|
398
|
-
const now = new Date().toISOString();
|
|
399
|
-
const expirationDate = delegation.constraints.notAfter
|
|
400
|
-
? new Date(delegation.constraints.notAfter * 1000).toISOString()
|
|
401
|
-
: options?.expirationDate;
|
|
402
|
-
// Compute issuanceDate
|
|
403
|
-
let issuanceDate = options?.issuanceDate || now;
|
|
404
|
-
if (!options?.issuanceDate && delegation.createdAt) {
|
|
405
|
-
issuanceDate = new Date(delegation.createdAt).toISOString();
|
|
406
|
-
}
|
|
407
|
-
return {
|
|
408
|
-
'@context': [
|
|
409
|
-
'https://www.w3.org/2018/credentials/v1',
|
|
410
|
-
exports.DELEGATION_CREDENTIAL_CONTEXT,
|
|
411
|
-
],
|
|
412
|
-
id: options?.id || delegation.vcId || `urn:uuid:${delegation.id}`,
|
|
413
|
-
type: ['VerifiableCredential', 'DelegationCredential'],
|
|
414
|
-
issuer: delegation.issuerDid,
|
|
415
|
-
issuanceDate,
|
|
416
|
-
expirationDate,
|
|
417
|
-
credentialSubject: {
|
|
418
|
-
id: delegation.subjectDid,
|
|
419
|
-
delegation: {
|
|
420
|
-
id: delegation.id,
|
|
421
|
-
issuerDid: delegation.issuerDid,
|
|
422
|
-
subjectDid: delegation.subjectDid,
|
|
423
|
-
controller: delegation.controller,
|
|
424
|
-
parentId: delegation.parentId,
|
|
425
|
-
constraints: delegation.constraints,
|
|
426
|
-
status: delegation.status,
|
|
427
|
-
createdAt: delegation.createdAt,
|
|
428
|
-
metadata: delegation.metadata,
|
|
429
|
-
},
|
|
430
|
-
},
|
|
431
|
-
credentialStatus: options?.credentialStatus,
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Check if a delegation credential is expired
|
|
436
|
-
*
|
|
437
|
-
* @param vc - The delegation credential
|
|
438
|
-
* @returns true if expired
|
|
439
|
-
*/
|
|
440
|
-
function isDelegationCredentialExpired(vc) {
|
|
441
|
-
// Check VC expiration
|
|
442
|
-
if (vc.expirationDate) {
|
|
443
|
-
const expirationDate = new Date(vc.expirationDate);
|
|
444
|
-
const now = new Date();
|
|
445
|
-
if (expirationDate < now) {
|
|
446
|
-
return true;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
// Check delegation constraints notAfter
|
|
450
|
-
const delegation = vc.credentialSubject.delegation;
|
|
451
|
-
if (delegation.constraints.notAfter) {
|
|
452
|
-
const nowSec = Math.floor(Date.now() / 1000);
|
|
453
|
-
if (nowSec > delegation.constraints.notAfter) {
|
|
454
|
-
return true;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
return false;
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Check if a delegation credential is not yet valid
|
|
461
|
-
*
|
|
462
|
-
* @param vc - The delegation credential
|
|
463
|
-
* @returns true if not yet valid
|
|
464
|
-
*/
|
|
465
|
-
function isDelegationCredentialNotYetValid(vc) {
|
|
466
|
-
const delegation = vc.credentialSubject.delegation;
|
|
467
|
-
// Check delegation constraints notBefore
|
|
468
|
-
if (delegation.constraints.notBefore) {
|
|
469
|
-
const nowSec = Math.floor(Date.now() / 1000);
|
|
470
|
-
if (nowSec < delegation.constraints.notBefore) {
|
|
471
|
-
return true;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
return false;
|
|
475
|
-
}
|
|
476
|
-
//# sourceMappingURL=schemas.js.map
|
package/dist/did/index.d.ts
DELETED
package/dist/did/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
__exportStar(require("./schemas.js"), exports);
|
|
25
|
-
//# sourceMappingURL=index.js.map
|