@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.
- package/README.md +21 -3
- package/dist/CapabilityDelegation.d.ts +173 -0
- package/dist/CapabilityDelegation.d.ts.map +1 -0
- package/dist/CapabilityDelegation.js +376 -0
- package/dist/CapabilityDelegation.js.map +1 -0
- package/dist/CapabilityInvocation.d.ts +151 -0
- package/dist/CapabilityInvocation.d.ts.map +1 -0
- package/dist/CapabilityInvocation.js +365 -0
- package/dist/CapabilityInvocation.js.map +1 -0
- package/dist/CapabilityProofPurpose.d.ts +203 -0
- package/dist/CapabilityProofPurpose.d.ts.map +1 -0
- package/dist/CapabilityProofPurpose.js +531 -0
- package/dist/CapabilityProofPurpose.js.map +1 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +23 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +224 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +250 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +591 -0
- package/dist/utils.js.map +1 -0
- package/package.json +47 -34
- package/lib/CapabilityDelegation.js +0 -312
- package/lib/CapabilityInvocation.js +0 -343
- package/lib/CapabilityProofPurpose.js +0 -538
- package/lib/constants.js +0 -32
- package/lib/index.js +0 -55
- package/lib/utils.js +0 -673
- package/types/lib/CapabilityDelegation.d.ts +0 -101
- package/types/lib/CapabilityDelegation.d.ts.map +0 -1
- package/types/lib/CapabilityInvocation.d.ts +0 -100
- package/types/lib/CapabilityInvocation.d.ts.map +0 -1
- package/types/lib/CapabilityProofPurpose.d.ts +0 -126
- package/types/lib/CapabilityProofPurpose.d.ts.map +0 -1
- package/types/lib/constants.d.ts +0 -15
- package/types/lib/constants.d.ts.map +0 -1
- package/types/lib/index.d.ts +0 -42
- package/types/lib/index.d.ts.map +0 -1
- package/types/lib/utils.d.ts +0 -308
- package/types/lib/utils.d.ts.map +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import jsigs from '@interop/jsonld-signatures';
|
|
5
|
+
import * as constants from './constants.js';
|
|
6
|
+
/* Core API */
|
|
7
|
+
export { CapabilityInvocation } from './CapabilityInvocation.js';
|
|
8
|
+
export { CapabilityDelegation } from './CapabilityDelegation.js';
|
|
9
|
+
export { createRootCapability } from './utils.js';
|
|
10
|
+
export { constants };
|
|
11
|
+
/**
|
|
12
|
+
* Wraps an existing document loader so that it also serves the zcap JSON-LD
|
|
13
|
+
* context. The wrapped loader is called for all other URLs.
|
|
14
|
+
*
|
|
15
|
+
* @param documentLoader - An existing JSON-LD document loader to extend.
|
|
16
|
+
*
|
|
17
|
+
* @returns A new document loader that handles the zcap context URL and
|
|
18
|
+
* delegates all other URLs to the wrapped loader.
|
|
19
|
+
*/
|
|
20
|
+
export function extendDocumentLoader(documentLoader) {
|
|
21
|
+
return async function loadZcapContexts(url) {
|
|
22
|
+
if (url === constants.ZCAP_CONTEXT_URL) {
|
|
23
|
+
return {
|
|
24
|
+
contextUrl: null,
|
|
25
|
+
documentUrl: url,
|
|
26
|
+
document: constants.ZCAP_CONTEXT,
|
|
27
|
+
tag: 'static'
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return documentLoader(url);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A default JSON-LD document loader that serves only the zcap and
|
|
35
|
+
* jsonld-signatures contexts. Suitable for use when no other contexts are
|
|
36
|
+
* needed. Extend it with {@link extendDocumentLoader} if additional contexts
|
|
37
|
+
* are required.
|
|
38
|
+
*/
|
|
39
|
+
export const documentLoader = extendDocumentLoader(jsigs.strictDocumentLoader);
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,MAAM,4BAA4B,CAAA;AAC9C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAG3C,cAAc;AACd,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;AAiBpB;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,cAA+B;IAE/B,OAAO,KAAK,UAAU,gBAAgB,CAAC,GAAW;QAChD,IAAI,GAAG,KAAK,SAAS,CAAC,gBAAgB,EAAE,CAAC;YACvC,OAAO;gBACL,UAAU,EAAE,IAAI;gBAChB,WAAW,EAAE,GAAG;gBAChB,QAAQ,EAAE,SAAS,CAAC,YAAY;gBAChC,GAAG,EAAE,QAAQ;aACd,CAAA;QACH,CAAC;QACD,OAAO,cAAc,CAAC,GAAG,CAAC,CAAA;IAC5B,CAAC,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoB,oBAAoB,CACjE,KAAK,CAAC,oBAAoB,CAC3B,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2018-2024 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
import type { IDelegatedZcap, IRootZcap, IZcap } from '@interop/data-integrity-core/zcap';
|
|
5
|
+
import type { IDocumentLoader } from '@interop/data-integrity-core/loader';
|
|
6
|
+
import type { IProofDescription, IVerificationMethod, LinkedDataProof } from '@interop/jsonld-signatures';
|
|
7
|
+
/**
|
|
8
|
+
* A verifier-supplied, trusted hook for dereferencing a root capability. The
|
|
9
|
+
* root zcap has no delegation proof, so it must be resolved in a trusted way
|
|
10
|
+
* (never from untrusted input); the hook throws if the ID is not authorized.
|
|
11
|
+
*/
|
|
12
|
+
export type GetRootCapability = (options: {
|
|
13
|
+
id: string;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
rootCapability: IRootZcap;
|
|
16
|
+
}>;
|
|
17
|
+
/** An inspection function result. */
|
|
18
|
+
export interface InspectResult {
|
|
19
|
+
/** `true` if the chain passed inspection. */
|
|
20
|
+
valid?: boolean;
|
|
21
|
+
/** Set if inspection failed. */
|
|
22
|
+
error?: Error;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The result of running jsonld-signature's verify method for a single
|
|
26
|
+
* capability delegation proof; built up incrementally during chain
|
|
27
|
+
* verification.
|
|
28
|
+
*/
|
|
29
|
+
export interface VerifyResult {
|
|
30
|
+
/** `true` if all the checked proofs were successfully verified. */
|
|
31
|
+
verified?: boolean;
|
|
32
|
+
/** The verify results for each delegation proof. */
|
|
33
|
+
results?: VerifyProofResult[];
|
|
34
|
+
error?: Error;
|
|
35
|
+
}
|
|
36
|
+
/** The result of verifying a capability delegation proof. */
|
|
37
|
+
export interface VerifyProofResult {
|
|
38
|
+
proof: IProofDescription;
|
|
39
|
+
verified: boolean;
|
|
40
|
+
verificationMethod?: IVerificationMethod;
|
|
41
|
+
/** The result from verifying the capability delegation proof purpose. */
|
|
42
|
+
purposeResult?: VerifyProofPurposeResult;
|
|
43
|
+
}
|
|
44
|
+
/** The result of verifying a capability delegation proof purpose. */
|
|
45
|
+
export interface VerifyProofPurposeResult {
|
|
46
|
+
valid: boolean;
|
|
47
|
+
error?: Error;
|
|
48
|
+
/**
|
|
49
|
+
* The party that created the capability delegation proof, i.e., the party
|
|
50
|
+
* that delegated the capability (the controller document/description).
|
|
51
|
+
*/
|
|
52
|
+
delegator?: object;
|
|
53
|
+
/** The controller of the proof's verification method. */
|
|
54
|
+
controller?: object;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The metadata resulting from the verification of a delegated capability.
|
|
58
|
+
*/
|
|
59
|
+
export interface CapabilityMeta {
|
|
60
|
+
/**
|
|
61
|
+
* The capability verify result, which is `null` for the root capability.
|
|
62
|
+
*/
|
|
63
|
+
verifyResult: VerifyResult | null;
|
|
64
|
+
}
|
|
65
|
+
/** The details passed to an {@link InspectCapabilityChain} hook. */
|
|
66
|
+
export interface CapabilityChainDetails {
|
|
67
|
+
/** The capabilities in the chain (root to tail). */
|
|
68
|
+
capabilityChain: IZcap[];
|
|
69
|
+
/**
|
|
70
|
+
* The results returned from jsonld-signatures verify for each capability in
|
|
71
|
+
* the chain. The root capability's entry has a `null` `verifyResult`.
|
|
72
|
+
*/
|
|
73
|
+
capabilityChainMeta: CapabilityMeta[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A capability chain inspection function: the intended extension point for
|
|
77
|
+
* revocation checks. Called with the full chain after verification succeeds.
|
|
78
|
+
*/
|
|
79
|
+
export type InspectCapabilityChain = (details: CapabilityChainDetails) => Promise<InspectResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Options common to both `CapabilityInvocation` and `CapabilityDelegation`
|
|
82
|
+
* (proof-verification and shared params); does not include the internal `term`.
|
|
83
|
+
*/
|
|
84
|
+
export interface CommonProofPurposeOptions {
|
|
85
|
+
/**
|
|
86
|
+
* Allow the invocationTarget of a delegation chain to be increasingly
|
|
87
|
+
* restrictive based on a hierarchical RESTful URL structure.
|
|
88
|
+
*/
|
|
89
|
+
allowTargetAttenuation?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* The description of the controller, if it is not to be dereferenced via a
|
|
92
|
+
* `documentLoader`.
|
|
93
|
+
*/
|
|
94
|
+
controller?: object;
|
|
95
|
+
/**
|
|
96
|
+
* Used during proof verification as the expected date for the creation of the
|
|
97
|
+
* proof (within a maximum timestamp delta) and for checking expiry; if not
|
|
98
|
+
* passed the current date is used.
|
|
99
|
+
*/
|
|
100
|
+
date?: string | Date | number;
|
|
101
|
+
/**
|
|
102
|
+
* The expected root capability for the delegation chain (a single root
|
|
103
|
+
* capability ID string, or an array of acceptable root capability ID
|
|
104
|
+
* strings).
|
|
105
|
+
*/
|
|
106
|
+
expectedRootCapability?: string | string[];
|
|
107
|
+
/**
|
|
108
|
+
* An async function that can be used to check for revocations related to any
|
|
109
|
+
* of the verified capabilities.
|
|
110
|
+
*/
|
|
111
|
+
inspectCapabilityChain?: InspectCapabilityChain;
|
|
112
|
+
/** The maximum length of the capability delegation chain. */
|
|
113
|
+
maxChainLength?: number;
|
|
114
|
+
/**
|
|
115
|
+
* A maximum number of seconds that clocks may be skewed when checking
|
|
116
|
+
* capability expiration date-times against `date` and when comparing
|
|
117
|
+
* invocation proof creation time against delegation proof creation time.
|
|
118
|
+
*/
|
|
119
|
+
maxClockSkew?: number;
|
|
120
|
+
/**
|
|
121
|
+
* The maximum milliseconds to live for a delegated zcap as measured by the
|
|
122
|
+
* time difference between `expires` and `created` on the delegation proof.
|
|
123
|
+
*/
|
|
124
|
+
maxDelegationTtl?: number;
|
|
125
|
+
/**
|
|
126
|
+
* A maximum number of seconds that a capability invocation proof "created"
|
|
127
|
+
* date can deviate from `date`.
|
|
128
|
+
*/
|
|
129
|
+
maxTimestampDelta?: number;
|
|
130
|
+
/**
|
|
131
|
+
* The jsonld-signature suite(s) to use to verify the capability chain.
|
|
132
|
+
* Required only when verifying a proof; unused (and omitted) when creating a
|
|
133
|
+
* proof.
|
|
134
|
+
*/
|
|
135
|
+
suite?: LinkedDataProof | LinkedDataProof[];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The (internal) options accepted by the abstract `CapabilityProofPurpose` base
|
|
139
|
+
* class. The `term` is supplied by the derived class, never by public callers.
|
|
140
|
+
*/
|
|
141
|
+
export interface CapabilityProofPurposeOptions extends CommonProofPurposeOptions {
|
|
142
|
+
/**
|
|
143
|
+
* The term (`capabilityInvocation` or `capabilityDelegation`) to look for in
|
|
144
|
+
* an LD proof.
|
|
145
|
+
*/
|
|
146
|
+
term: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Options for {@link CapabilityInvocation}, instantiated in one of two
|
|
150
|
+
* mutually exclusive modes: create-proof (`capability`, `capabilityAction`,
|
|
151
|
+
* `invocationTarget`) or verify-proof (`expectedAction`, `expectedTarget`,
|
|
152
|
+
* `expectedRootCapability`, `suite`, ...).
|
|
153
|
+
*/
|
|
154
|
+
export interface CapabilityInvocationOptions extends CommonProofPurposeOptions {
|
|
155
|
+
/**
|
|
156
|
+
* The capability to add/reference in a created proof. A root zcap MUST be
|
|
157
|
+
* passed as its ID string; a delegated zcap must be passed as the full
|
|
158
|
+
* object.
|
|
159
|
+
*/
|
|
160
|
+
capability?: string | IDelegatedZcap;
|
|
161
|
+
/** The capability action to add to a proof. */
|
|
162
|
+
capabilityAction?: string;
|
|
163
|
+
/**
|
|
164
|
+
* The invocation target to use; can attenuate the capability's invocation
|
|
165
|
+
* target if the verifier supports target attenuation.
|
|
166
|
+
*/
|
|
167
|
+
invocationTarget?: string;
|
|
168
|
+
/** The capability action expected when validating a proof. */
|
|
169
|
+
expectedAction?: string;
|
|
170
|
+
/** The target(s) a capability is expected to apply to (absolute URI(s)). */
|
|
171
|
+
expectedTarget?: string | string[];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Options for {@link CapabilityDelegation}, instantiated in one of two
|
|
175
|
+
* mutually exclusive modes: create-proof (`parentCapability`) or verify-proof
|
|
176
|
+
* (`expectedRootCapability`, `suite`, ...).
|
|
177
|
+
*/
|
|
178
|
+
export interface CapabilityDelegationOptions extends CommonProofPurposeOptions {
|
|
179
|
+
/**
|
|
180
|
+
* An alternative to passing `_capabilityChain` when creating a proof; passing
|
|
181
|
+
* `parentCapability` enables the capability chain to be auto-computed. Pass a
|
|
182
|
+
* root zcap ID string, or a full root or delegated zcap object.
|
|
183
|
+
*/
|
|
184
|
+
parentCapability?: string | IZcap;
|
|
185
|
+
/** Private: a parent capability that has already been verified. */
|
|
186
|
+
_verifiedParentCapability?: IZcap;
|
|
187
|
+
/** Private: an explicit capability chain override (testing only). */
|
|
188
|
+
_capabilityChain?: Array<string | IDelegatedZcap>;
|
|
189
|
+
/** Private: skip local validation (testing only). */
|
|
190
|
+
_skipLocalValidationForTesting?: boolean;
|
|
191
|
+
}
|
|
192
|
+
/** An `Error` that may carry structured `details`. */
|
|
193
|
+
export interface ZcapError extends Error {
|
|
194
|
+
details?: object;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The options passed through from `jsigs` to a proof purpose's `validate`,
|
|
198
|
+
* `match`, and `update` methods.
|
|
199
|
+
*/
|
|
200
|
+
export interface ValidateOptions {
|
|
201
|
+
document?: object;
|
|
202
|
+
documentLoader?: IDocumentLoader;
|
|
203
|
+
verificationMethod?: IVerificationMethod;
|
|
204
|
+
suite?: LinkedDataProof;
|
|
205
|
+
[key: string]: unknown;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The result of validating a capability proof purpose. Extends the base
|
|
209
|
+
* `jsigs` proof validate result (`{valid, error?, controller?}`) with the
|
|
210
|
+
* zcap-specific fields populated during chain verification.
|
|
211
|
+
*/
|
|
212
|
+
export interface CapabilityValidateResult {
|
|
213
|
+
valid: boolean;
|
|
214
|
+
error?: Error;
|
|
215
|
+
/** The controller of the proof's verification method. */
|
|
216
|
+
controller?: object;
|
|
217
|
+
/** The full dereferenced capability chain (root to tail). */
|
|
218
|
+
dereferencedChain?: IZcap[];
|
|
219
|
+
/** The invoker of the capability (for capability invocation proofs). */
|
|
220
|
+
invoker?: object;
|
|
221
|
+
/** The delegator of the capability (for capability delegation proofs). */
|
|
222
|
+
delegator?: object;
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=types.d.ts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+1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import type { IProofDescription, IVerificationMethod } from '@interop/jsonld-signatures';
|
|
2
|
+
import type { ICapabilityDelegationProof, IDelegatedZcap, IRootZcap, IZcap } from '@interop/data-integrity-core/zcap';
|
|
3
|
+
import type { GetRootCapability, ZcapError } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a root capability from a root controller and a root invocation
|
|
6
|
+
* target.
|
|
7
|
+
*
|
|
8
|
+
* @param options - The options.
|
|
9
|
+
* @param options.controller - The root controller.
|
|
10
|
+
* @param options.invocationTarget - The root invocation target.
|
|
11
|
+
*
|
|
12
|
+
* @returns The root capability.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createRootCapability({ controller, invocationTarget }: {
|
|
15
|
+
controller: string | string[];
|
|
16
|
+
invocationTarget: string;
|
|
17
|
+
}): IRootZcap;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the controller(s) from a capability.
|
|
20
|
+
*
|
|
21
|
+
* @param options - The options.
|
|
22
|
+
* @param options.capability - The authorization capability (zcap).
|
|
23
|
+
*
|
|
24
|
+
* @returns The controller(s) for the capability.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getControllers({ capability }: {
|
|
27
|
+
capability: IZcap;
|
|
28
|
+
}): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Returns true if the given verification method is a controller (or is
|
|
31
|
+
* controlled by a controller) of the given capability.
|
|
32
|
+
*
|
|
33
|
+
* @param options - The options.
|
|
34
|
+
* @param options.capability - The authorization capability (zcap).
|
|
35
|
+
* @param options.verificationMethod - The verification method to check.
|
|
36
|
+
*
|
|
37
|
+
* @returns `true` if the controller matches, `false` if not.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isController({ capability, verificationMethod }: {
|
|
40
|
+
capability: IZcap;
|
|
41
|
+
verificationMethod: IVerificationMethod;
|
|
42
|
+
}): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves the allowed actions from a capability.
|
|
45
|
+
*
|
|
46
|
+
* @param options - The options.
|
|
47
|
+
* @param options.capability - The authorization capability (zcap).
|
|
48
|
+
*
|
|
49
|
+
* @returns Allowed actions.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getAllowedActions({ capability }: {
|
|
52
|
+
capability: IZcap;
|
|
53
|
+
}): string[];
|
|
54
|
+
/**
|
|
55
|
+
* Retrieves the target from a capability.
|
|
56
|
+
*
|
|
57
|
+
* @param options - The options.
|
|
58
|
+
* @param options.capability - The authorization capability (zcap).
|
|
59
|
+
*
|
|
60
|
+
* @returns Capability target.
|
|
61
|
+
*/
|
|
62
|
+
export declare function getTarget({ capability }: {
|
|
63
|
+
capability: IZcap;
|
|
64
|
+
}): string;
|
|
65
|
+
/**
|
|
66
|
+
* Retrieves the delegation proof(s) for a capability that is associated with
|
|
67
|
+
* its parent capability. A capability that has no parent or no associated
|
|
68
|
+
* delegation proofs will cause this function to return an empty array.
|
|
69
|
+
*
|
|
70
|
+
* @param options - The options.
|
|
71
|
+
* @param options.capability - The authorization capability.
|
|
72
|
+
*
|
|
73
|
+
* @returns Any `capabilityDelegation` proof objects attached to the given
|
|
74
|
+
* capability.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getDelegationProofs({ capability }: {
|
|
77
|
+
capability: IZcap;
|
|
78
|
+
}): ICapabilityDelegationProof[];
|
|
79
|
+
/**
|
|
80
|
+
* Gets the `capabilityChain` associated with the given capability.
|
|
81
|
+
*
|
|
82
|
+
* @param options - The options.
|
|
83
|
+
* @param options.capability - The authorization capability.
|
|
84
|
+
*
|
|
85
|
+
* @returns The capability chain entries (root to parent), as stored in the
|
|
86
|
+
* delegation proof.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getCapabilityChain({ capability }: {
|
|
89
|
+
capability: IZcap;
|
|
90
|
+
}): Array<string | IDelegatedZcap>;
|
|
91
|
+
/**
|
|
92
|
+
* Determines if the given `invocationTarget` is valid given a
|
|
93
|
+
* `baseInvocationTarget`.
|
|
94
|
+
*
|
|
95
|
+
* To check for a proper delegation, `invocationTarget` must be the child
|
|
96
|
+
* capability's `invocationTarget` and `baseInvocationTarget` must be the
|
|
97
|
+
* parent capability's `invocationTarget`.
|
|
98
|
+
*
|
|
99
|
+
* To check for a proper invocation, `invocationTarget` must be the value from
|
|
100
|
+
* the invocation proof and `baseInvocationTarget` must be the invoked
|
|
101
|
+
* capability's `invocationTarget`.
|
|
102
|
+
*
|
|
103
|
+
* @param options - The options.
|
|
104
|
+
* @param options.invocationTarget - The invocation target to check.
|
|
105
|
+
* @param options.baseInvocationTarget - The base invocation target.
|
|
106
|
+
* @param options.allowTargetAttenuation - `true` to allow target attenuation.
|
|
107
|
+
*
|
|
108
|
+
* @returns `true` if the target is valid, `false` if not.
|
|
109
|
+
*/
|
|
110
|
+
export declare function isValidTarget({ invocationTarget, baseInvocationTarget, allowTargetAttenuation }: {
|
|
111
|
+
invocationTarget: string;
|
|
112
|
+
baseInvocationTarget: string;
|
|
113
|
+
allowTargetAttenuation?: boolean;
|
|
114
|
+
}): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Creates a capability chain for delegating a capability from the
|
|
117
|
+
* given `parentCapability`.
|
|
118
|
+
*
|
|
119
|
+
* @param options - The options.
|
|
120
|
+
* @param options.parentCapability - The parent capability from which to compute
|
|
121
|
+
* the capability chain (a root zcap ID string, or a full root or delegated
|
|
122
|
+
* zcap object).
|
|
123
|
+
* @param options._skipLocalValidationForTesting - Private.
|
|
124
|
+
*
|
|
125
|
+
* @returns The computed capability chain to be included in a capability
|
|
126
|
+
* delegation proof.
|
|
127
|
+
*/
|
|
128
|
+
export declare function computeCapabilityChain({ parentCapability, _skipLocalValidationForTesting }: {
|
|
129
|
+
parentCapability: string | IZcap;
|
|
130
|
+
_skipLocalValidationForTesting?: boolean;
|
|
131
|
+
}): Array<string | IDelegatedZcap>;
|
|
132
|
+
/**
|
|
133
|
+
* Dereferences the capability chain associated with the given capability,
|
|
134
|
+
* ensuring it passes a number of validation checks.
|
|
135
|
+
*
|
|
136
|
+
* A delegated zcap's chain has a reference to a root zcap. A verifier must
|
|
137
|
+
* provide a hook (`getRootCapability`) to dereference this root zcap since
|
|
138
|
+
* the root zcap has no delegation proof and must therefore be trusted by
|
|
139
|
+
* the verifier. If the root zcap can't be dereferenced by the trusted hook,
|
|
140
|
+
* then an authorization error must be thrown by that hook.
|
|
141
|
+
*
|
|
142
|
+
* This function will dereference the root zcap and then dereference all of
|
|
143
|
+
* the embedded delegated zcaps from the chain, combining them into a single
|
|
144
|
+
* array containing full zcaps ordered from root => tail.
|
|
145
|
+
*
|
|
146
|
+
* The dereferenced chain (result of this function) should then compare the
|
|
147
|
+
* root zcap's ID against a list of expected root capabilities, throwing
|
|
148
|
+
* an error if none of them match. Otherwise, the dereferenced chain should
|
|
149
|
+
* then be processed to ensure that all delegation rules have been followed.
|
|
150
|
+
* If checking an invocation, it should also be ensured that a combination of
|
|
151
|
+
* an expected target and a root zcap is permitted (note it is conceivable that
|
|
152
|
+
* a verifier may accept more than one combination, e.g., a target of `x` could
|
|
153
|
+
* work with both root zcap `a` and `b`).
|
|
154
|
+
*
|
|
155
|
+
* @param options - The options.
|
|
156
|
+
* @param options.capability - The authorization capability to dereference the
|
|
157
|
+
* chain for. Pass a string (the root zcap ID) to dereference a root zcap
|
|
158
|
+
* directly, or a delegated zcap object.
|
|
159
|
+
* @param options.getRootCapability - A function for dereferencing the root
|
|
160
|
+
* capability (the root zcap must be deref'd in a trusted way by the verifier,
|
|
161
|
+
* it must not be untrusted input).
|
|
162
|
+
* @param options.maxChainLength - The maximum length of the capability
|
|
163
|
+
* delegation chain (this is inclusive of `capability` itself).
|
|
164
|
+
*
|
|
165
|
+
* @returns Resolves to an object containing the full dereferenced chain ordered
|
|
166
|
+
* root to tail.
|
|
167
|
+
*/
|
|
168
|
+
export declare function dereferenceCapabilityChain({ capability, getRootCapability, maxChainLength }: {
|
|
169
|
+
capability: string | IDelegatedZcap;
|
|
170
|
+
getRootCapability: GetRootCapability;
|
|
171
|
+
maxChainLength?: number;
|
|
172
|
+
}): Promise<{
|
|
173
|
+
dereferencedChain: IZcap[];
|
|
174
|
+
}>;
|
|
175
|
+
/**
|
|
176
|
+
* Asserts that a proof carries the required zcap JSON-LD context. The context
|
|
177
|
+
* may appear anywhere in the proof's `@context` array (it is protected
|
|
178
|
+
* regardless of position).
|
|
179
|
+
*
|
|
180
|
+
* @param options - The options.
|
|
181
|
+
* @param options.proof - The proof to check; its `@context` must be, or
|
|
182
|
+
* include, the zcap context URL.
|
|
183
|
+
*
|
|
184
|
+
* @throws {Error} If the zcap context is missing from the proof.
|
|
185
|
+
*/
|
|
186
|
+
export declare function checkProofContext({ proof }: {
|
|
187
|
+
proof: IProofDescription;
|
|
188
|
+
}): void;
|
|
189
|
+
/**
|
|
190
|
+
* Determines whether a child capability's `allowedAction` is valid, i.e., no
|
|
191
|
+
* less restrictive than its parent's. If the parent does not restrict actions
|
|
192
|
+
* (its `allowedAction` is absent), any child action is allowed.
|
|
193
|
+
*
|
|
194
|
+
* @param options - The options.
|
|
195
|
+
* @param options.allowedAction - The child capability's allowed action(s).
|
|
196
|
+
* @param options.parentAllowedAction - The parent capability's allowed
|
|
197
|
+
* action(s).
|
|
198
|
+
*
|
|
199
|
+
* @returns `true` if the child's allowed action(s) are valid.
|
|
200
|
+
*/
|
|
201
|
+
export declare function hasValidAllowedAction({ allowedAction, parentAllowedAction }: {
|
|
202
|
+
allowedAction?: string | string[];
|
|
203
|
+
parentAllowedAction?: string | string[];
|
|
204
|
+
}): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Validates the data model of a capability (root or delegated), throwing if it
|
|
207
|
+
* is malformed or if its root/delegated kind does not match `expectRoot`.
|
|
208
|
+
*
|
|
209
|
+
* Checks include: required `@context`, absolute-URI `id` and
|
|
210
|
+
* `invocationTarget`, `allowedAction` shape, and (for delegated zcaps) a valid
|
|
211
|
+
* `parentCapability`, a `capabilityDelegation` proof with a valid `created`
|
|
212
|
+
* date, and a valid `expires` date. Root zcaps must not carry `expires`.
|
|
213
|
+
*
|
|
214
|
+
* @param options - The options.
|
|
215
|
+
* @param options.capability - The capability to check.
|
|
216
|
+
* @param options.expectRoot - `true` if the capability is expected to be a root
|
|
217
|
+
* zcap, `false` if it is expected to be delegated.
|
|
218
|
+
*
|
|
219
|
+
* @throws {Error} If the capability is invalid or of an unexpected kind.
|
|
220
|
+
*/
|
|
221
|
+
export declare function checkCapability({ capability, expectRoot }: {
|
|
222
|
+
capability: IZcap;
|
|
223
|
+
expectRoot: boolean;
|
|
224
|
+
}): void;
|
|
225
|
+
/**
|
|
226
|
+
* Compares two timestamps, allowing for a maximum clock skew. Times within
|
|
227
|
+
* `maxClockSkew` of each other are treated as equal.
|
|
228
|
+
*
|
|
229
|
+
* @param options - The options.
|
|
230
|
+
* @param options.t1 - The first time, in milliseconds since the epoch.
|
|
231
|
+
* @param options.t2 - The second time, in milliseconds since the epoch.
|
|
232
|
+
* @param options.maxClockSkew - The maximum allowed clock skew, in seconds.
|
|
233
|
+
*
|
|
234
|
+
* @returns `0` if equal within the skew, `-1` if `t1 < t2`, otherwise `1`.
|
|
235
|
+
*/
|
|
236
|
+
export declare function compareTime({ t1, t2, maxClockSkew }: {
|
|
237
|
+
t1: number;
|
|
238
|
+
t2: number;
|
|
239
|
+
maxClockSkew: number;
|
|
240
|
+
}): number;
|
|
241
|
+
/**
|
|
242
|
+
* Creates an `Error` carrying a structured `details` object.
|
|
243
|
+
*
|
|
244
|
+
* @param message - The error message.
|
|
245
|
+
* @param details - The structured details to attach.
|
|
246
|
+
*
|
|
247
|
+
* @returns The error with `details` set.
|
|
248
|
+
*/
|
|
249
|
+
export declare function createDetailedError(message: string, details: object): ZcapError;
|
|
250
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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