@interop/zcap 10.1.0 → 11.0.1

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 +376 -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 -673
  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 -308
  48. package/types/lib/utils.d.ts.map +0 -1
@@ -0,0 +1,203 @@
1
+ import jsigs from '@interop/jsonld-signatures';
2
+ import type { IProofDescription, LinkedDataProof } from '@interop/jsonld-signatures';
3
+ import type { IZcap } from '@interop/data-integrity-core/zcap';
4
+ import type { IDocumentLoader } from '@interop/data-integrity-core/loader';
5
+ import type { CapabilityDelegationOptions, CapabilityMeta, CapabilityProofPurposeOptions, CapabilityValidateResult, InspectCapabilityChain, ValidateOptions } from './types.js';
6
+ declare const ControllerProofPurpose: typeof jsigs.ControllerProofPurpose;
7
+ /**
8
+ * A constructor for the `CapabilityDelegation` class, passed between modules to
9
+ * avoid a circular import.
10
+ */
11
+ export type CapabilityDelegationConstructor = new (options: CapabilityDelegationOptions) => CapabilityProofPurpose;
12
+ export declare class CapabilityProofPurpose extends ControllerProofPurpose {
13
+ allowTargetAttenuation?: boolean;
14
+ expectedRootCapability?: string | string[];
15
+ inspectCapabilityChain?: InspectCapabilityChain;
16
+ maxChainLength?: number;
17
+ maxClockSkew?: number;
18
+ maxDelegationTtl?: number;
19
+ suite?: LinkedDataProof | LinkedDataProof[];
20
+ /**
21
+ * @param options - The options.
22
+ * @param options.allowTargetAttenuation - Allow the invocationTarget of a
23
+ * delegation chain to be increasingly restrictive based on a hierarchical
24
+ * RESTful URL structure.
25
+ * @param options.controller - The description of the controller, if it is not
26
+ * to be dereferenced via a `documentLoader`.
27
+ * @param options.date - Used during proof verification as the expected date
28
+ * for the creation of the proof (within a maximum timestamp delta) and for
29
+ * checking to see if a capability has expired; if not passed the current
30
+ * date will be used.
31
+ * @param options.expectedRootCapability - The expected root capability for
32
+ * the delegation chain (a single root capability ID string, or an array of
33
+ * acceptable root capability ID strings).
34
+ * @param options.inspectCapabilityChain - An async function that can be used
35
+ * to check for revocations related to any of verified capabilities.
36
+ * @param options.maxChainLength - The maximum length of the capability
37
+ * delegation chain.
38
+ * @param options.maxClockSkew - A maximum number of seconds that clocks may
39
+ * be skewed checking capability expiration date-times against `date` and
40
+ * when comparing invocation proof creation time against delegation proof
41
+ * creation time.
42
+ * @param options.maxDelegationTtl - The maximum milliseconds to live for a
43
+ * delegated zcap as measured by the time difference between `expires` and
44
+ * `created` on the delegation proof.
45
+ * @param options.maxTimestampDelta - A maximum number of seconds that a
46
+ * capability invocation proof (only used by this proof type) "created" date
47
+ * can deviate from `date`, defaults to `Infinity`.
48
+ * @param options.suite - The jsonld-signature suite(s) to use to verify the
49
+ * capability chain. Required only when verifying a proof; unused (and
50
+ * omitted) when creating a delegation proof.
51
+ * @param options.term - The term `capabilityInvocation` or
52
+ * `capabilityDelegation` to look for in an LD proof.
53
+ */
54
+ constructor({ allowTargetAttenuation, controller, date, expectedRootCapability, inspectCapabilityChain, maxChainLength, maxDelegationTtl, maxTimestampDelta, maxClockSkew, suite, term }?: CapabilityProofPurposeOptions);
55
+ /**
56
+ * Validates a capability proof by verifying its capability delegation chain
57
+ * from the root outward. Overrides
58
+ * {@link jsigs.ControllerProofPurpose#validate} and is structurally
59
+ * compatible with it.
60
+ *
61
+ * @param proof - The proof to validate.
62
+ * @param validateOptions - The validation options (passed through from
63
+ * `jsigs`), including `document` and `documentLoader`.
64
+ *
65
+ * @returns Resolves to `{valid, error?}` (plus an internal
66
+ * `dereferencedChain` on success).
67
+ */
68
+ validate(proof: IProofDescription, validateOptions: ValidateOptions): Promise<CapabilityValidateResult>;
69
+ /**
70
+ * Dereferences the capability chain for the tail capability of the given
71
+ * proof, using `expectedRootCapability` to gate which root zcap is trusted
72
+ * and `documentLoader` to load it. Delegates to
73
+ * {@link utils.dereferenceCapabilityChain}.
74
+ *
75
+ * @param options - The options.
76
+ * @param options.document - The document the proof is attached to.
77
+ * @param options.documentLoader - The document loader used to load the
78
+ * (trusted) root capability.
79
+ * @param options.proof - The proof whose capability chain is to be
80
+ * dereferenced.
81
+ *
82
+ * @returns Resolves to the full dereferenced chain ordered root to tail.
83
+ */
84
+ _dereferenceChain({ document, documentLoader, proof }: {
85
+ document?: object;
86
+ documentLoader?: IDocumentLoader;
87
+ proof: IProofDescription;
88
+ }): Promise<{
89
+ dereferencedChain: IZcap[];
90
+ }>;
91
+ /**
92
+ * Returns the `CapabilityDelegation` class, passed in by derived classes to
93
+ * avoid a circular import. Abstract; must be overridden.
94
+ *
95
+ * @returns The `CapabilityDelegation` class.
96
+ */
97
+ _getCapabilityDelegationClass(): CapabilityDelegationConstructor;
98
+ /**
99
+ * Resolves the "tail" capability (the one being invoked or delegated) from
100
+ * the document and/or proof. Abstract; must be overridden.
101
+ *
102
+ * @param _options - The options (`document`, `proof`).
103
+ *
104
+ * @returns The tail capability (a root zcap ID string or a full zcap object).
105
+ */
106
+ _getTailCapability(_options: {
107
+ document?: object;
108
+ proof: IProofDescription;
109
+ }): {
110
+ capability: string | IZcap;
111
+ };
112
+ /**
113
+ * Hook for proof-purpose-specific checks run *before* chain verification.
114
+ * Overridden by derived classes.
115
+ *
116
+ * @param _options - The options.
117
+ *
118
+ * @returns The initial capability chain meta array.
119
+ */
120
+ _runChecksBeforeChainVerification(_options: {
121
+ dereferencedChain: IZcap[];
122
+ proof: IProofDescription;
123
+ validateOptions: ValidateOptions;
124
+ }): Promise<{
125
+ capabilityChainMeta: CapabilityMeta[];
126
+ }>;
127
+ /**
128
+ * Hook for proof-purpose-specific checks run *after* chain verification.
129
+ * Abstract; must be overridden.
130
+ *
131
+ * @param _options - The options.
132
+ *
133
+ * @returns The proof validation result.
134
+ */
135
+ _runChecksAfterChainVerification(_options: {
136
+ capabilityChainMeta: CapabilityMeta[];
137
+ dereferencedChain: IZcap[];
138
+ proof: IProofDescription;
139
+ validateOptions: ValidateOptions;
140
+ }): Promise<CapabilityValidateResult>;
141
+ /**
142
+ * Runs the base class (`ControllerProofPurpose`) validation checks for the
143
+ * proof, throwing on failure.
144
+ *
145
+ * @param options - The options.
146
+ * @param options.proof - The proof to validate.
147
+ * @param options.validateOptions - The validation options passed through from
148
+ * `jsigs` (including `document`, `documentLoader`, and `verificationMethod`).
149
+ *
150
+ * @returns Resolves to the base validation result (includes
151
+ * `{valid, controller, ...}`).
152
+ */
153
+ _runBaseProofValidation({ proof, validateOptions }: {
154
+ proof: IProofDescription;
155
+ validateOptions: ValidateOptions;
156
+ }): Promise<CapabilityValidateResult>;
157
+ /**
158
+ * Hook allowing a derived class to short-circuit proof validation (e.g., when
159
+ * a verified parent capability is already available). No-op by default.
160
+ *
161
+ * @param _options - The options (`proof`, `validateOptions`).
162
+ *
163
+ * @returns A proof validation result to short-circuit with, or nothing to
164
+ * continue full validation.
165
+ */
166
+ _shortCircuitValidate(_options?: {
167
+ proof: IProofDescription;
168
+ validateOptions: ValidateOptions;
169
+ }): Promise<CapabilityValidateResult | void>;
170
+ /**
171
+ * Verifies the given dereferenced capability chain. This involves ensuring
172
+ * that the root zcap in the chain is as expected (for the endpoint where an
173
+ * invocation or a simple chain chain is occurring) and that every other zcap
174
+ * in the chain (including any invoked one), has been properly delegated.
175
+ *
176
+ * @param options - The options.
177
+ * @param options.CapabilityDelegation - The CapabilityDelegation class; this
178
+ * must be passed to avoid circular references in this module.
179
+ * @param options.capabilityChainMeta - The array of results for inspecting
180
+ * the capability chain; if this has a value when passed, then it is
181
+ * presumed to be the verify result for the tail capability and that tail
182
+ * capability will not be verified internally by this function to avoid
183
+ * duplicating work; all verification results (including the tail's --
184
+ * either computed locally or reused from what was passed) will be added to
185
+ * this array in order from root => tail.
186
+ * @param options.dereferencedChain - The dereferenced capability chain for
187
+ * `capability`, starting at the root capability and ending at `capability`.
188
+ * @param options.documentLoader - A configured jsonld documentLoader.
189
+ *
190
+ * @returns Resolves to an object with `{verified, error}`.
191
+ */
192
+ _verifyCapabilityChain({ CapabilityDelegation, capabilityChainMeta, dereferencedChain, documentLoader }: {
193
+ CapabilityDelegation: CapabilityDelegationConstructor;
194
+ capabilityChainMeta: CapabilityMeta[];
195
+ dereferencedChain: IZcap[];
196
+ documentLoader?: IDocumentLoader;
197
+ }): Promise<{
198
+ verified: boolean;
199
+ error?: Error;
200
+ }>;
201
+ }
202
+ export {};
203
+ //# sourceMappingURL=CapabilityProofPurpose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CapabilityProofPurpose.d.ts","sourceRoot":"","sources":["../src/CapabilityProofPurpose.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,4BAA4B,CAAA;AAC9C,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EAChB,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EAGV,KAAK,EACN,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAA;AAC1E,OAAO,KAAK,EACV,2BAA2B,EAC3B,cAAc,EACd,6BAA6B,EAC7B,wBAAwB,EACxB,sBAAsB,EACtB,eAAe,EAChB,MAAM,YAAY,CAAA;AACnB,QAAA,MAAQ,sBAAsB,qCAAmB,CAAA;AAKjD;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,KAC5C,OAAO,EAAE,2BAA2B,KACjC,sBAAsB,CAAA;AAE3B,qBAAa,sBAAuB,SAAQ,sBAAsB;IAChE,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,sBAAsB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC1C,sBAAsB,CAAC,EAAE,sBAAsB,CAAA;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,KAAK,CAAC,EAAE,eAAe,GAAG,eAAe,EAAE,CAAA;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