@interop/zcap 10.0.2 → 11.0.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 (48) hide show
  1. package/README.md +21 -3
  2. package/dist/CapabilityDelegation.d.ts +173 -0
  3. package/dist/CapabilityDelegation.d.ts.map +1 -0
  4. package/dist/CapabilityDelegation.js +372 -0
  5. package/dist/CapabilityDelegation.js.map +1 -0
  6. package/dist/CapabilityInvocation.d.ts +151 -0
  7. package/dist/CapabilityInvocation.d.ts.map +1 -0
  8. package/dist/CapabilityInvocation.js +365 -0
  9. package/dist/CapabilityInvocation.js.map +1 -0
  10. package/dist/CapabilityProofPurpose.d.ts +203 -0
  11. package/dist/CapabilityProofPurpose.d.ts.map +1 -0
  12. package/dist/CapabilityProofPurpose.js +531 -0
  13. package/dist/CapabilityProofPurpose.js.map +1 -0
  14. package/dist/constants.d.ts +11 -0
  15. package/dist/constants.d.ts.map +1 -0
  16. package/dist/constants.js +23 -0
  17. package/dist/constants.js.map +1 -0
  18. package/dist/index.d.ts +25 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +40 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/types.d.ts +224 -0
  23. package/dist/types.d.ts.map +1 -0
  24. package/dist/types.js +2 -0
  25. package/dist/types.js.map +1 -0
  26. package/dist/utils.d.ts +250 -0
  27. package/dist/utils.d.ts.map +1 -0
  28. package/dist/utils.js +591 -0
  29. package/dist/utils.js.map +1 -0
  30. package/package.json +47 -34
  31. package/lib/CapabilityDelegation.js +0 -312
  32. package/lib/CapabilityInvocation.js +0 -343
  33. package/lib/CapabilityProofPurpose.js +0 -538
  34. package/lib/constants.js +0 -32
  35. package/lib/index.js +0 -55
  36. package/lib/utils.js +0 -672
  37. package/types/lib/CapabilityDelegation.d.ts +0 -101
  38. package/types/lib/CapabilityDelegation.d.ts.map +0 -1
  39. package/types/lib/CapabilityInvocation.d.ts +0 -100
  40. package/types/lib/CapabilityInvocation.d.ts.map +0 -1
  41. package/types/lib/CapabilityProofPurpose.d.ts +0 -126
  42. package/types/lib/CapabilityProofPurpose.d.ts.map +0 -1
  43. package/types/lib/constants.d.ts +0 -15
  44. package/types/lib/constants.d.ts.map +0 -1
  45. package/types/lib/index.d.ts +0 -42
  46. package/types/lib/index.d.ts.map +0 -1
  47. package/types/lib/utils.d.ts +0 -304
  48. package/types/lib/utils.d.ts.map +0 -1
@@ -0,0 +1,531 @@
1
+ /*!
2
+ * Copyright (c) 2018-2024 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import * as utils from './utils.js';
5
+ import jsigs from '@interop/jsonld-signatures';
6
+ const { ControllerProofPurpose } = jsigs.purposes;
7
+ export class CapabilityProofPurpose extends ControllerProofPurpose {
8
+ allowTargetAttenuation;
9
+ expectedRootCapability;
10
+ inspectCapabilityChain;
11
+ maxChainLength;
12
+ maxClockSkew;
13
+ maxDelegationTtl;
14
+ suite;
15
+ /**
16
+ * @param options - The options.
17
+ * @param options.allowTargetAttenuation - Allow the invocationTarget of a
18
+ * delegation chain to be increasingly restrictive based on a hierarchical
19
+ * RESTful URL structure.
20
+ * @param options.controller - The description of the controller, if it is not
21
+ * to be dereferenced via a `documentLoader`.
22
+ * @param options.date - Used during proof verification as the expected date
23
+ * for the creation of the proof (within a maximum timestamp delta) and for
24
+ * checking to see if a capability has expired; if not passed the current
25
+ * date will be used.
26
+ * @param options.expectedRootCapability - The expected root capability for
27
+ * the delegation chain (a single root capability ID string, or an array of
28
+ * acceptable root capability ID strings).
29
+ * @param options.inspectCapabilityChain - An async function that can be used
30
+ * to check for revocations related to any of verified capabilities.
31
+ * @param options.maxChainLength - The maximum length of the capability
32
+ * delegation chain.
33
+ * @param options.maxClockSkew - A maximum number of seconds that clocks may
34
+ * be skewed checking capability expiration date-times against `date` and
35
+ * when comparing invocation proof creation time against delegation proof
36
+ * creation time.
37
+ * @param options.maxDelegationTtl - The maximum milliseconds to live for a
38
+ * delegated zcap as measured by the time difference between `expires` and
39
+ * `created` on the delegation proof.
40
+ * @param options.maxTimestampDelta - A maximum number of seconds that a
41
+ * capability invocation proof (only used by this proof type) "created" date
42
+ * can deviate from `date`, defaults to `Infinity`.
43
+ * @param options.suite - The jsonld-signature suite(s) to use to verify the
44
+ * capability chain. Required only when verifying a proof; unused (and
45
+ * omitted) when creating a delegation proof.
46
+ * @param options.term - The term `capabilityInvocation` or
47
+ * `capabilityDelegation` to look for in an LD proof.
48
+ */
49
+ constructor({
50
+ // proof verification params (and common to all derived classes)
51
+ allowTargetAttenuation = false, controller, date, expectedRootCapability, inspectCapabilityChain, maxChainLength, maxDelegationTtl = Infinity, maxTimestampDelta = Infinity, maxClockSkew = 300, suite, term } = {}) {
52
+ super({ term, controller, date, maxTimestampDelta });
53
+ // params used to verify a proof
54
+ const hasVerifyProofParams = controller ||
55
+ date ||
56
+ expectedRootCapability ||
57
+ inspectCapabilityChain ||
58
+ suite;
59
+ if (hasVerifyProofParams) {
60
+ if (!(typeof expectedRootCapability === 'string' ||
61
+ Array.isArray(expectedRootCapability))) {
62
+ throw new TypeError('"expectedRootCapability" must be a string or array.');
63
+ }
64
+ // expected root capability values must be absolute URIs
65
+ const expectedRootCapabilities = Array.isArray(expectedRootCapability)
66
+ ? expectedRootCapability
67
+ : [expectedRootCapability];
68
+ for (const erc of expectedRootCapabilities) {
69
+ if (!(typeof erc === 'string' && erc.includes(':'))) {
70
+ throw new Error('"expectedRootCapability" values must be absolute URI strings.');
71
+ }
72
+ }
73
+ if (typeof maxClockSkew !== 'number') {
74
+ throw new TypeError('"maxClockSkew" must be a number.');
75
+ }
76
+ this.allowTargetAttenuation = allowTargetAttenuation;
77
+ this.expectedRootCapability = expectedRootCapability;
78
+ this.inspectCapabilityChain = inspectCapabilityChain;
79
+ this.maxChainLength = maxChainLength;
80
+ this.maxClockSkew = maxClockSkew;
81
+ this.maxDelegationTtl = maxDelegationTtl;
82
+ this.suite = suite;
83
+ }
84
+ }
85
+ /**
86
+ * Validates a capability proof by verifying its capability delegation chain
87
+ * from the root outward. Overrides
88
+ * {@link jsigs.ControllerProofPurpose#validate} and is structurally
89
+ * compatible with it.
90
+ *
91
+ * @param proof - The proof to validate.
92
+ * @param validateOptions - The validation options (passed through from
93
+ * `jsigs`), including `document` and `documentLoader`.
94
+ *
95
+ * @returns Resolves to `{valid, error?}` (plus an internal
96
+ * `dereferencedChain` on success).
97
+ */
98
+ async validate(proof, validateOptions) {
99
+ /* Note: Trust begins at the root zcap, so we start chain validation at
100
+ the root and move forward toward the tail from there. This also helps
101
+ prevent an attacker from wasting time when they submit long zcap chains
102
+ that are extensions of otherwise valid chains.
103
+
104
+ So, each parent zcap must be verified before its child is. This also means
105
+ that we can't simply recursively unwind the chain in reverse; therefore,
106
+ the code is a bit more complex.
107
+
108
+ Note that if a chain is being checked without an invocation, i.e., without
109
+ invoking the tail capability, then the tail's capability delegation *proof*
110
+ will have been cryptographically verified prior to this call. Otherwise,
111
+ it will need to be cryptographically verified. There is a signal described
112
+ below to indicate whether this verification needs to occur. Regardless, the
113
+ tail has not yet been validated as a tail for the chain and won't be until
114
+ the rest of the chain, starting at the root, is validated.
115
+
116
+ The validation process is:
117
+
118
+ 0. Run a short-circuit check to ensure that we only verify the capability
119
+ chain once; that is, we only start checking the chain when we haven't
120
+ verified any parent zcaps yet. Whether we've started checking the chain
121
+ yet or not is handled by a derived class that implements
122
+ `_shortCircuitValidate`, returning the short-circuit validation result
123
+ if the chain check has already started and `undefined` if it hasn't.
124
+ 1. If we haven't been short-circuited, then dereference the capability
125
+ chain referenced in the tail proof to get all zcaps in the chain.
126
+ 2. Run any proof-purpose specific checks prior to checking the rest of
127
+ the chain. This allows shortcuts when checking a capability invocation
128
+ proof, e.g., if an invocation is immediately invalid for some reason,
129
+ there is no need to check that the delegation rules were followed along
130
+ the entire chain. This method also returns the `capabilityChainMeta`
131
+ array to use to hold the capability delegation proof verify results. If
132
+ a capability delegation proof for the tail has already been verified,
133
+ this array will have a placeholder for its full proof validation result
134
+ as a signal to avoid duplicating this work later.
135
+ 3. Verify the chain from root => tail by calling `verifyCapabilityChain`
136
+ just once -- when validating the tail. The short-circuit check above
137
+ ensures we don't call this more than once. Additionally, the
138
+ `capabilityChainMeta` array signals whether we need to cryptographically
139
+ verify the capability delegation proof on the tail or if we must skip
140
+ this to avoid duplicating that work.
141
+ 4. Run any purpose-specific checks after chain verification. This allows
142
+ capability delegation proof checks to be run on the tail against the now
143
+ verified parent, allowing its proof validation result to be fully
144
+ constructed and updated in the `capabilityChainMeta` array (as well
145
+ as the return value for this function).
146
+ 5. Run the `inspectCapabilityChain` hook, if given, to allow for custom
147
+ implementations to check for revoked zcaps in databases or whatever other
148
+ behavior is desired. */
149
+ try {
150
+ // ensure proof has expected context (even though this is called in
151
+ // `match`, it is possible to call `validate` separately without calling
152
+ // `match`, so check here too)
153
+ utils.checkProofContext({ proof });
154
+ const { document, documentLoader } = validateOptions;
155
+ // 0. Run any proof-purpose-specific short-circuit check.
156
+ const shortcircuit = await this._shortCircuitValidate({
157
+ proof,
158
+ validateOptions
159
+ });
160
+ if (shortcircuit) {
161
+ return shortcircuit;
162
+ }
163
+ /* 1. Dereference the capability chain. This involves finding all
164
+ embedded delegated zcaps, using a verifier-trusted hook to dereference
165
+ the root zcap, and putting the full zcaps in order (root => tail) in an
166
+ array. The `tail` is the zcap that was invoked. */
167
+ const { dereferencedChain } = await this._dereferenceChain({
168
+ document,
169
+ documentLoader,
170
+ proof
171
+ });
172
+ /* 2. Run any proof-purpose-specific early checks prior to chain
173
+ verification. */
174
+ const { capabilityChainMeta } = await this._runChecksBeforeChainVerification({
175
+ dereferencedChain,
176
+ proof,
177
+ validateOptions
178
+ });
179
+ /* 3. Verify the capability delegation chain. This will make sure that
180
+ the root zcap in the chain is as expected (for the endpoint where the
181
+ invocation occurred) and that every other zcap in the chain (including
182
+ the invoked one), has been properly delegated. */
183
+ const { verified, error } = await this._verifyCapabilityChain({
184
+ // required to avoid circular dependencies
185
+ CapabilityDelegation: this._getCapabilityDelegationClass(),
186
+ capabilityChainMeta,
187
+ dereferencedChain,
188
+ documentLoader
189
+ });
190
+ if (!verified) {
191
+ throw error;
192
+ }
193
+ /* 4. Run any proof-purpose-specific checks after chain verification
194
+ to get the proof validation result. */
195
+ const validateResult = await this._runChecksAfterChainVerification({
196
+ capabilityChainMeta,
197
+ dereferencedChain,
198
+ proof,
199
+ validateOptions
200
+ });
201
+ // 5. Run `inspectCapabilityChain` hook.
202
+ const { inspectCapabilityChain } = this;
203
+ if (inspectCapabilityChain) {
204
+ const { valid, error } = await inspectCapabilityChain({
205
+ // full chain, including root zcap
206
+ capabilityChain: dereferencedChain,
207
+ // capability chain meta including `null` for root zcap
208
+ capabilityChainMeta: [{ verifyResult: null }, ...capabilityChainMeta]
209
+ });
210
+ if (!valid) {
211
+ throw error;
212
+ }
213
+ }
214
+ // include dereferenced chain result
215
+ validateResult.dereferencedChain = dereferencedChain;
216
+ return validateResult;
217
+ }
218
+ catch (error) {
219
+ return { valid: false, error: error };
220
+ }
221
+ }
222
+ /**
223
+ * Dereferences the capability chain for the tail capability of the given
224
+ * proof, using `expectedRootCapability` to gate which root zcap is trusted
225
+ * and `documentLoader` to load it. Delegates to
226
+ * {@link utils.dereferenceCapabilityChain}.
227
+ *
228
+ * @param options - The options.
229
+ * @param options.document - The document the proof is attached to.
230
+ * @param options.documentLoader - The document loader used to load the
231
+ * (trusted) root capability.
232
+ * @param options.proof - The proof whose capability chain is to be
233
+ * dereferenced.
234
+ *
235
+ * @returns Resolves to the full dereferenced chain ordered root to tail.
236
+ */
237
+ async _dereferenceChain({ document, documentLoader, proof }) {
238
+ const { expectedRootCapability, maxChainLength } = this;
239
+ const { capability } = this._getTailCapability({ document, proof });
240
+ const { dereferencedChain } = await utils.dereferenceCapabilityChain({
241
+ capability: capability,
242
+ async getRootCapability({ id }) {
243
+ // ensure root zcap in chain is as expected
244
+ let match;
245
+ if (typeof expectedRootCapability === 'string') {
246
+ match = expectedRootCapability === id;
247
+ }
248
+ else {
249
+ match = expectedRootCapability?.includes(id);
250
+ }
251
+ if (!match) {
252
+ throw utils.createDetailedError(`Actual root capability (${id}) does not match expected root ` +
253
+ `capability (${String(expectedRootCapability)}).`, { actual: id, expected: expectedRootCapability });
254
+ }
255
+ // load root zcap
256
+ const { document } = await documentLoader(id);
257
+ return { rootCapability: document };
258
+ },
259
+ maxChainLength
260
+ });
261
+ return { dereferencedChain };
262
+ }
263
+ /**
264
+ * Returns the `CapabilityDelegation` class, passed in by derived classes to
265
+ * avoid a circular import. Abstract; must be overridden.
266
+ *
267
+ * @returns The `CapabilityDelegation` class.
268
+ */
269
+ _getCapabilityDelegationClass() {
270
+ throw new Error('Not implemented.');
271
+ }
272
+ /**
273
+ * Resolves the "tail" capability (the one being invoked or delegated) from
274
+ * the document and/or proof. Abstract; must be overridden.
275
+ *
276
+ * @param _options - The options (`document`, `proof`).
277
+ *
278
+ * @returns The tail capability (a root zcap ID string or a full zcap object).
279
+ */
280
+ _getTailCapability(_options) {
281
+ throw new Error('Not implemented.');
282
+ }
283
+ /**
284
+ * Hook for proof-purpose-specific checks run *before* chain verification.
285
+ * Overridden by derived classes.
286
+ *
287
+ * @param _options - The options.
288
+ *
289
+ * @returns The initial capability chain meta array.
290
+ */
291
+ async _runChecksBeforeChainVerification(_options) {
292
+ return { capabilityChainMeta: [] };
293
+ }
294
+ /**
295
+ * Hook for proof-purpose-specific checks run *after* chain verification.
296
+ * Abstract; must be overridden.
297
+ *
298
+ * @param _options - The options.
299
+ *
300
+ * @returns The proof validation result.
301
+ */
302
+ async _runChecksAfterChainVerification(_options) {
303
+ throw new Error('Not implemented.');
304
+ }
305
+ /**
306
+ * Runs the base class (`ControllerProofPurpose`) validation checks for the
307
+ * proof, throwing on failure.
308
+ *
309
+ * @param options - The options.
310
+ * @param options.proof - The proof to validate.
311
+ * @param options.validateOptions - The validation options passed through from
312
+ * `jsigs` (including `document`, `documentLoader`, and `verificationMethod`).
313
+ *
314
+ * @returns Resolves to the base validation result (includes
315
+ * `{valid, controller, ...}`).
316
+ */
317
+ async _runBaseProofValidation({ proof, validateOptions }) {
318
+ // run super class's validation checks
319
+ const result = await super.validate(proof, validateOptions);
320
+ if (!result.valid) {
321
+ throw result.error;
322
+ }
323
+ return result;
324
+ }
325
+ /**
326
+ * Hook allowing a derived class to short-circuit proof validation (e.g., when
327
+ * a verified parent capability is already available). No-op by default.
328
+ *
329
+ * @param _options - The options (`proof`, `validateOptions`).
330
+ *
331
+ * @returns A proof validation result to short-circuit with, or nothing to
332
+ * continue full validation.
333
+ */
334
+ async _shortCircuitValidate(_options) { }
335
+ /**
336
+ * Verifies the given dereferenced capability chain. This involves ensuring
337
+ * that the root zcap in the chain is as expected (for the endpoint where an
338
+ * invocation or a simple chain chain is occurring) and that every other zcap
339
+ * in the chain (including any invoked one), has been properly delegated.
340
+ *
341
+ * @param options - The options.
342
+ * @param options.CapabilityDelegation - The CapabilityDelegation class; this
343
+ * must be passed to avoid circular references in this module.
344
+ * @param options.capabilityChainMeta - The array of results for inspecting
345
+ * the capability chain; if this has a value when passed, then it is
346
+ * presumed to be the verify result for the tail capability and that tail
347
+ * capability will not be verified internally by this function to avoid
348
+ * duplicating work; all verification results (including the tail's --
349
+ * either computed locally or reused from what was passed) will be added to
350
+ * this array in order from root => tail.
351
+ * @param options.dereferencedChain - The dereferenced capability chain for
352
+ * `capability`, starting at the root capability and ending at `capability`.
353
+ * @param options.documentLoader - A configured jsonld documentLoader.
354
+ *
355
+ * @returns Resolves to an object with `{verified, error}`.
356
+ */
357
+ async _verifyCapabilityChain({ CapabilityDelegation, capabilityChainMeta, dereferencedChain, documentLoader }) {
358
+ /* Note: We start verifying a capability chain at its root of trust (the
359
+ root capability) and then move toward the tail. To prevent recursively
360
+ repeating checks, we pass a `verifiedParentCapability` each time we start
361
+ verifying another capability delegation proof in the capability chain.
362
+
363
+ Verification process is:
364
+
365
+ 1. If the chain only as the root capability, exit early.
366
+ 2. For each capability `zcap` in the chain, verify the capability delegation
367
+ proof on `zcap` (if `capabilityChainMeta` has no precomputed result) and
368
+ that all of the delegation rules have been followed. */
369
+ try {
370
+ // 1. If the chain only has the root, exit early.
371
+ if (dereferencedChain.length === 1) {
372
+ return { verified: true };
373
+ }
374
+ // 2. For each capability `zcap` in the chain, verify the capability
375
+ // delegation proof on `zcap` and that the delegation rules have been
376
+ // followed.
377
+ let parentAllowedAction;
378
+ let parentDelegationTime;
379
+ let parentExpirationTime;
380
+ const [root] = dereferencedChain;
381
+ let parentInvocationTarget = root.invocationTarget;
382
+ // track whether `capabilityChainMeta` needs its first result shifted to
383
+ // the end (if a result was present, it is for the last or "tail" zcap,
384
+ // so we set a flag to remember to move it to the end when we're done
385
+ // checking zcaps below)
386
+ const mustShift = capabilityChainMeta.length > 0;
387
+ // get all delegated capabilities (no root zcap since it has no delegation
388
+ // proof to check)
389
+ const delegatedCapabilities = dereferencedChain.slice(1);
390
+ const { allowTargetAttenuation, expectedRootCapability, date, maxClockSkew = 300, maxDelegationTtl = Infinity, suite } = this;
391
+ const currentDate = (date && new Date(date)) || new Date();
392
+ for (let i = 0; i < delegatedCapabilities.length; ++i) {
393
+ const zcap = delegatedCapabilities[i];
394
+ /* Note: Passing `_verifiedParentCapability` will prevent repetitive
395
+ checking of the same segments of the chain (once a parent is verified,
396
+ its chain is not checked again when checking its children). */
397
+ const _verifiedParentCapability = delegatedCapabilities[i - 1] || root;
398
+ // verify proof on zcap if no result has been computed yet (one
399
+ // verify result will be present in `capabilityChainMeta` per
400
+ // delegated capability)
401
+ if (capabilityChainMeta.length < delegatedCapabilities.length) {
402
+ const verifyResult = await jsigs.verify(zcap, {
403
+ suite: suite,
404
+ purpose: new CapabilityDelegation({
405
+ allowTargetAttenuation,
406
+ date: currentDate,
407
+ expectedRootCapability,
408
+ maxDelegationTtl,
409
+ _verifiedParentCapability
410
+ }),
411
+ documentLoader
412
+ });
413
+ if (!verifyResult.verified) {
414
+ throw verifyResult.error;
415
+ }
416
+ // delegation proof verified; save meta data for later inspection
417
+ capabilityChainMeta.push({ verifyResult });
418
+ }
419
+ // ensure `allowedAction` is valid (compared against parent)
420
+ const allowedAction = 'allowedAction' in zcap ? zcap.allowedAction : undefined;
421
+ if (!utils.hasValidAllowedAction({ allowedAction, parentAllowedAction })) {
422
+ throw new Error('The "allowedAction" in a delegated capability ' +
423
+ 'must not be less restrictive than its parent.');
424
+ }
425
+ // ensure `invocationTarget` delegation is acceptable
426
+ const invocationTarget = utils.getTarget({ capability: zcap });
427
+ if (!utils.isValidTarget({
428
+ invocationTarget,
429
+ baseInvocationTarget: parentInvocationTarget,
430
+ allowTargetAttenuation
431
+ })) {
432
+ if (allowTargetAttenuation) {
433
+ throw new Error(`The "invocationTarget" in a delegated capability must not be ` +
434
+ 'less restrictive than its parent.');
435
+ }
436
+ else {
437
+ throw new Error('The "invocationTarget" in a delegated capability ' +
438
+ 'must be equivalent to its parent.');
439
+ }
440
+ }
441
+ // verify expiration dates
442
+ // expires date has been previously validated, so just parse it
443
+ const currentCapabilityExpirationTime = Date.parse('expires' in zcap ? zcap.expires : '');
444
+ // if the parent does not specify an expiration date, then any more
445
+ // restrictive expiration date is acceptable
446
+ if (parentExpirationTime !== undefined) {
447
+ // handle case where `expires` is set in the parent, but the child
448
+ // has an expiration date greater than the parent
449
+ if (currentCapabilityExpirationTime > parentExpirationTime) {
450
+ // `utils.compareTime` intentionally not used; the delegator MUST
451
+ // not use an `expires` value later than what is in the parent,
452
+ // which they have access to (not a decentralized clock problem)
453
+ throw new Error('The `expires` property in a delegated capability must not ' +
454
+ 'be less restrictive than its parent.');
455
+ }
456
+ // use `utils.compareTime` to allow for allow for clock drift because
457
+ // we are comparing against `currentDate`
458
+ if (utils.compareTime({
459
+ t1: currentDate.getTime(),
460
+ t2: parentExpirationTime,
461
+ maxClockSkew
462
+ }) > 0) {
463
+ throw new Error('A capability in the delegation chain has expired.');
464
+ }
465
+ }
466
+ // get delegated date-time
467
+ // note: there can be only one proof here and this has already been
468
+ // validated to be the case during `dereferenceCapabilityChain`
469
+ const [proof] = utils.getDelegationProofs({ capability: zcap });
470
+ const currentCapabilityDelegationTime = Date.parse(proof.created);
471
+ // verify parent capability was not delegated after child
472
+ if (parentDelegationTime !== undefined &&
473
+ parentDelegationTime > currentCapabilityDelegationTime) {
474
+ throw new Error('A capability in the delegation chain was delegated before ' +
475
+ 'its parent.');
476
+ }
477
+ // some systems may require historical verification of zcaps, so
478
+ // allow `maxDelegationTtl` of `Infinity`
479
+ if (maxDelegationTtl < Infinity) {
480
+ /* Note: Here we ensure zcap has a time-to-live (TTL) that is
481
+ sufficiently short. This is to prevent the use of zcaps that, when
482
+ revoked, will have to be stored for long periods of time. We have to
483
+ ensure:
484
+
485
+ 1. The zcap's delegation date is not in the future (this also ensures
486
+ that the zcap's expiration date is not before its delegation date
487
+ as it would have triggered an expiration error in a previous check).
488
+ 2. The zcap's current TTL is <= `maxDelegationTtl`
489
+ 3. The zcap's TTL was never > `maxDelegationTtl`. */
490
+ // use `utils.compareTime` to allow for allow for clock drift because
491
+ // we are comparing against `currentDate`
492
+ if (utils.compareTime({
493
+ t1: currentCapabilityDelegationTime,
494
+ t2: currentDate.getTime(),
495
+ maxClockSkew
496
+ }) > 0) {
497
+ throw new Error('A delegated capability in the delegation chain was delegated ' +
498
+ 'in the future.');
499
+ }
500
+ const currentTtl = currentCapabilityExpirationTime - currentDate.getTime();
501
+ const maxTtl = currentCapabilityExpirationTime - currentCapabilityDelegationTime;
502
+ // use `utils.compareTime` to allow for allow for clock drift because
503
+ // we are comparing against `currentDate`
504
+ const currentTtlComparison = utils.compareTime({
505
+ t1: currentTtl,
506
+ t2: maxDelegationTtl,
507
+ maxClockSkew
508
+ });
509
+ if (currentTtlComparison > 0 || maxTtl > maxDelegationTtl) {
510
+ throw new Error('A delegated capability in the delegation chain has a time to ' +
511
+ 'live that is too long.');
512
+ }
513
+ }
514
+ parentAllowedAction = allowedAction;
515
+ parentExpirationTime = currentCapabilityExpirationTime;
516
+ parentDelegationTime = currentCapabilityDelegationTime;
517
+ parentInvocationTarget = invocationTarget;
518
+ }
519
+ // shift zcap verify result for last zcap to the end of meta array if
520
+ // necessary
521
+ if (mustShift) {
522
+ capabilityChainMeta.push(capabilityChainMeta.shift());
523
+ }
524
+ return { verified: true };
525
+ }
526
+ catch (error) {
527
+ return { verified: false, error: error };
528
+ }
529
+ }
530
+ }
531
+ //# sourceMappingURL=CapabilityProofPurpose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CapabilityProofPurpose.js","sourceRoot":"","sources":["../src/CapabilityProofPurpose.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,4BAA4B,CAAA;AAmB9C,MAAM,EAAE,sBAAsB,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAA;AAajD,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IAChE,sBAAsB,CAAU;IAChC,sBAAsB,CAAoB;IAC1C,sBAAsB,CAAyB;IAC/C,cAAc,CAAS;IACvB,YAAY,CAAS;IACrB,gBAAgB,CAAS;IACzB,KAAK,CAAsC;IAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,YACE;IACE,gEAAgE;IAChE,sBAAsB,GAAG,KAAK,EAC9B,UAAU,EACV,IAAI,EACJ,sBAAsB,EACtB,sBAAsB,EACtB,cAAc,EACd,gBAAgB,GAAG,QAAQ,EAC3B,iBAAiB,GAAG,QAAQ,EAC5B,YAAY,GAAG,GAAG,EAClB,KAAK,EACL,IAAI,KAC6B,EAAmC;QAEtE,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC,CAAA;QAEpD,gCAAgC;QAChC,MAAM,oBAAoB,GACxB,UAAU;YACV,IAAI;YACJ,sBAAsB;YACtB,sBAAsB;YACtB,KAAK,CAAA;QACP,IAAI,oBAAoB,EAAE,CAAC;YACzB,IACE,CAAC,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"}
@@ -0,0 +1,11 @@
1
+ /** The zcap JSON-LD context document. */
2
+ export declare const ZCAP_CONTEXT: object;
3
+ /** The zcap JSON-LD context URL (`https://w3id.org/zcap/v1`). */
4
+ export declare const ZCAP_CONTEXT_URL: string;
5
+ /** URI prefix for root capability IDs (`urn:zcap:root:`). */
6
+ export declare const ZCAP_ROOT_PREFIX = "urn:zcap:root:";
7
+ /**
8
+ * Default maximum capability delegation chain length (inclusive of the tail).
9
+ */
10
+ export declare const MAX_CHAIN_LENGTH = 10;
11
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAYA,yCAAyC;AACzC,eAAO,MAAM,YAAY,EAAE,MAAgB,CAAA;AAE3C,iEAAiE;AACjE,eAAO,MAAM,gBAAgB,EAAE,MAAoB,CAAA;AAEnD,6DAA6D;AAC7D,eAAO,MAAM,gBAAgB,mBAAmB,CAAA;AAEhD;;GAEG;AAGH,eAAO,MAAM,gBAAgB,KAAK,CAAA"}
@@ -0,0 +1,23 @@
1
+ /*!
2
+ * Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import { CONTEXT, CONTEXT_URL } from '@digitalbazaar/zcap-context';
5
+ // Re-exported through local typed bindings (rather than a direct
6
+ // `export ... from`) so the values carry explicit types instead of pointing at
7
+ // `@digitalbazaar/zcap-context`, which ships no types. This lets downstream
8
+ // consumers resolve `ZCAP_CONTEXT`/`ZCAP_CONTEXT_URL` without needing types for
9
+ // that package. The values are `const` in zcap-context, so the snapshot binding
10
+ // is equivalent to a live one.
11
+ /** The zcap JSON-LD context document. */
12
+ export const ZCAP_CONTEXT = CONTEXT;
13
+ /** The zcap JSON-LD context URL (`https://w3id.org/zcap/v1`). */
14
+ export const ZCAP_CONTEXT_URL = CONTEXT_URL;
15
+ /** URI prefix for root capability IDs (`urn:zcap:root:`). */
16
+ export const ZCAP_ROOT_PREFIX = 'urn:zcap:root:';
17
+ /**
18
+ * Default maximum capability delegation chain length (inclusive of the tail).
19
+ */
20
+ // 6 is probably more reasonable for Kevin Bacon reasons? but picking a
21
+ // power of 10
22
+ export const MAX_CHAIN_LENGTH = 10;
23
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAElE,iEAAiE;AACjE,+EAA+E;AAC/E,4EAA4E;AAC5E,gFAAgF;AAChF,gFAAgF;AAChF,+BAA+B;AAE/B,yCAAyC;AACzC,MAAM,CAAC,MAAM,YAAY,GAAW,OAAO,CAAA;AAE3C,iEAAiE;AACjE,MAAM,CAAC,MAAM,gBAAgB,GAAW,WAAW,CAAA;AAEnD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAA;AAEhD;;GAEG;AACH,uEAAuE;AACvE,cAAc;AACd,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAA"}
@@ -0,0 +1,25 @@
1
+ import * as constants from './constants.js';
2
+ import type { IDocumentLoader } from '@interop/data-integrity-core/loader';
3
+ export { CapabilityInvocation } from './CapabilityInvocation.js';
4
+ export { CapabilityDelegation } from './CapabilityDelegation.js';
5
+ export { createRootCapability } from './utils.js';
6
+ export { constants };
7
+ export type { CapabilityChainDetails, CapabilityMeta, InspectCapabilityChain, InspectResult, VerifyResult, VerifyProofResult, VerifyProofPurposeResult, CapabilityInvocationOptions, CapabilityDelegationOptions, CapabilityValidateResult, GetRootCapability } from './types.js';
8
+ /**
9
+ * Wraps an existing document loader so that it also serves the zcap JSON-LD
10
+ * context. The wrapped loader is called for all other URLs.
11
+ *
12
+ * @param documentLoader - An existing JSON-LD document loader to extend.
13
+ *
14
+ * @returns A new document loader that handles the zcap context URL and
15
+ * delegates all other URLs to the wrapped loader.
16
+ */
17
+ export declare function extendDocumentLoader(documentLoader: IDocumentLoader): IDocumentLoader;
18
+ /**
19
+ * A default JSON-LD document loader that serves only the zcap and
20
+ * jsonld-signatures contexts. Suitable for use when no other contexts are
21
+ * needed. Extend it with {@link extendDocumentLoader} if additional contexts
22
+ * are required.
23
+ */
24
+ export declare const documentLoader: IDocumentLoader;
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAG1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,CAAA;AAGpB,YAAY,EACV,sBAAsB,EACtB,cAAc,EACd,sBAAsB,EACtB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,EACxB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,cAAc,EAAE,eAAe,GAC9B,eAAe,CAYjB;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,eAE5B,CAAA"}