@digitalbazaar/ezcap-express 5.1.0 → 6.2.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.
package/lib/authorize.js CHANGED
@@ -106,6 +106,14 @@ export function authorizeZcapInvocationAfterParse({
106
106
  suite: await suiteFactory({req}),
107
107
  headers,
108
108
  expectedHost,
109
+ async beforeValidatePurpose({
110
+ purpose, proof, capability, capabilityAction
111
+ }) {
112
+ // provide access to invocation parameters
113
+ req.ezcap.invocationParameters = {
114
+ purpose, proof, capability, capabilityAction
115
+ };
116
+ },
109
117
  documentLoader: helpers.createRootCapabilityLoader({
110
118
  documentLoader, getRootController, req
111
119
  }),
package/lib/revoke.js CHANGED
@@ -12,9 +12,9 @@ import {CapabilityDelegation} from '@digitalbazaar/zcap';
12
12
  * Authorizes a request to submit a zcap revocation.
13
13
  *
14
14
  * This middleware is opinionated; it MUST be attached to an endpoint that
15
- * terminates in `/revocations/:revocationId`. This to enable the middleware to
16
- * automatically generate expected values for running zcap checks and to
17
- * support a common, conventional revocation API pattern.
15
+ * terminates in `/zcaps/revocations/:revocationId`. This to enable the
16
+ * middleware to automatically generate expected values for running zcap checks
17
+ * and to support a common, conventional revocation API pattern.
18
18
  *
19
19
  * The pattern is in support of controlled objects on a service, aka
20
20
  * "service objects". Each object's controller is used to populate the root
@@ -25,17 +25,17 @@ import {CapabilityDelegation} from '@digitalbazaar/zcap';
25
25
  * Therefore, any route that matches an invocation target for a root zcap for
26
26
  * a service SHOULD attach this middleware to:
27
27
  *
28
- * `<serviceObjectId>/revocations/:revocationId`.
28
+ * `<serviceObjectId>/zcaps/revocations/:revocationId`.
29
29
  *
30
30
  * This middleware will compute `serviceObjectId` by combining the expected
31
31
  * host with the subpath from the request URL that occurs before
32
- * `/revocations/`. It assumes that the request URL will have this pattern
33
- * if the middleware code has been reached. IOW, `serviceObjectId` will
32
+ * `/zcaps/revocations/`. It assumes that the request URL will have this
33
+ * pattern if the middleware code has been reached. IOW, `serviceObjectId` will
34
34
  * be set using:
35
35
  *
36
- * `https://<expectedHost>/<URL subpath before "/revocations/">`.
36
+ * `https://<expectedHost>/<URL subpath before "/zcaps/revocations/">`.
37
37
  *
38
- * Note: This middleware does NOT support having `/revocations/` appear
38
+ * Note: This middleware does NOT support having `/zcaps/revocations/` appear
39
39
  * multiple places in the request URL.
40
40
  *
41
41
  * Attaching this middleware will enable any zcaps delegated from the service
@@ -44,7 +44,7 @@ import {CapabilityDelegation} from '@digitalbazaar/zcap';
44
44
  * supporting the invocation of a dynamically generated root zcap with an
45
45
  * invocation target of:
46
46
  *
47
- * `<serviceObjectId>/revocations/:revocationId`.
47
+ * `<serviceObjectId>/zcaps/revocations/:revocationId`.
48
48
  *
49
49
  * This middleware will set the `controller` of this root zcap to all
50
50
  * controllers in the to-be-revoked zcap's delegation chain, permitting any
@@ -53,9 +53,9 @@ import {CapabilityDelegation} from '@digitalbazaar/zcap';
53
53
  * not have `<serviceObjectId>` as its invocation target (or a prefix of it).
54
54
  * This ensures that the only zcaps that have been delegated from a root zcap
55
55
  * using the service object's ID as part of its invocation target can be
56
- * revoked at its `/revocations` route, i.e., other zcaps intended for other
57
- * service objects -- or entirely other services -- cannot be revoked via this
58
- * middleware.
56
+ * revoked at its `/zcaps/revocations` route, i.e., other zcaps intended for
57
+ * other service objects -- or entirely other services -- cannot be revoked via
58
+ * this middleware.
59
59
  *
60
60
  * This middleware will automatically generate two sets of expects values: one
61
61
  * for checking the invocation to revoke a capability and one for verifying the
@@ -74,7 +74,7 @@ import {CapabilityDelegation} from '@digitalbazaar/zcap';
74
74
  * // with an "id" of `revocationId`; RZ2's controller will be populated
75
75
  * // using all controllers from Z2's chain, enabling any controller in that
76
76
  * // zcap's chain to invoke RZ2 to revoke Z2
77
- * `<serviceObjectId>/revocations/<revocationId>`,
77
+ * `<serviceObjectId>/zcaps/revocations/<revocationId>`,
78
78
  * ],
79
79
  * action: 'write'
80
80
  * .
@@ -124,7 +124,8 @@ export function authorizeZcapRevocation({
124
124
  host: expectedHost,
125
125
  rootInvocationTarget: [
126
126
  serviceObjectId,
127
- `${serviceObjectId}/revocations/${encodeURIComponent(revocationId)}`
127
+ `${serviceObjectId}/zcaps/revocations/` +
128
+ encodeURIComponent(revocationId)
128
129
  ]
129
130
  };
130
131
  }
@@ -150,11 +151,11 @@ export function authorizeZcapRevocation({
150
151
  return [
151
152
  asyncHandler(async function(req, res, next) {
152
153
  // ensure middleware is attached to opinionated route
153
- if(!req.originalUrl.includes('/revocations/') ||
154
+ if(!req.originalUrl.includes('/zcaps/revocations/') ||
154
155
  !req.params.revocationId) {
155
156
  const error = new Error(
156
157
  'Revocation middleware must be attached to a route ending in ' +
157
- '"/revocations/:revocationId".');
158
+ '"/zcaps/revocations/:revocationId".');
158
159
  error.httpStatusCode = 500;
159
160
  return helpers.handleError({res, error, onError});
160
161
  }
@@ -191,6 +192,9 @@ function createCheckRevocationMiddleware({
191
192
  return helpers.handleError({res, error, onError});
192
193
  }
193
194
 
195
+ // set capability to be revoked to enable access in other helpers
196
+ req.ezcap.capabilityToRevoke = capability;
197
+
194
198
  // verify CapabilityDelegation
195
199
  let delegator;
196
200
  const capture = {};
@@ -234,10 +238,6 @@ async function _verifyDelegation({
234
238
  // the expected values for the invocation are the same as those for checking
235
239
  // the revocation delegation chain per the reasoning given in notes above
236
240
  const {expectedRootCapability} = req.ezcap;
237
- /* Note: We build the `expectedRootCapability` for the revoked capability
238
- from the capability invocation expected values here. This is ok because the
239
- revocation middleware feature presumes that the only zcaps that may be
240
- revoked using it are rooted in the same authority... FIXME */
241
241
  const {verified, error, results} = await jsigs.verify(capability, {
242
242
  documentLoader,
243
243
  purpose: new CapabilityDelegation({
@@ -266,8 +266,8 @@ function _wrapGetRootController({expectedHost, getRootController}) {
266
266
  }) {
267
267
  const serviceObjectId = _parseServiceObjectId({req, expectedHost});
268
268
  const {revocationId} = req.params;
269
- const zcapSpecificRootTarget =
270
- `${serviceObjectId}/revocations/${encodeURIComponent(revocationId)}`;
269
+ const zcapSpecificRootTarget = `${serviceObjectId}/zcaps/revocations/` +
270
+ encodeURIComponent(revocationId);
271
271
 
272
272
  // if `rootInvocationTarget` doesn't match the zcap-specific root
273
273
  // invocation target, then use user-provided `getRootController` to provide
@@ -294,9 +294,9 @@ function _wrapGetRootController({expectedHost, getRootController}) {
294
294
  root -> A -> B
295
295
 
296
296
  Any zcap controller in the chain of B may invoke a root zcap with an
297
- `invocationTarget` of `<baseUrl>/revocations/<ID of B>` (and an ID of
298
- `urn:zcap:root:encodeURIComponent(<baseUrl>/revocations/<ID of B>)`). This
299
- means that `root`, `A`, or `B` may revoke `B`.
297
+ `invocationTarget` of `<baseUrl>/zcaps/revocations/<ID of B>` (and an ID of
298
+ `urn:zcap:root:encodeURIComponent(<baseUrl>/zcaps/revocations/<ID of B>)`).
299
+ This means that `root`, `A`, or `B` may revoke `B`.
300
300
 
301
301
  As long no other zcap in the chain of `B` (e.g., `A`) has already been
302
302
  revoked, then `B` will be revoked and stored as a revocation (storage must
@@ -328,8 +328,8 @@ function _getCapabilityControllers({capability}) {
328
328
  }
329
329
 
330
330
  function _parseServiceObjectId({req, expectedHost}) {
331
- // `serviceObjectId` is full URL prior to `/revocations/`
332
- const idx = req.originalUrl.indexOf('/revocations/');
331
+ // `serviceObjectId` is full URL prior to `/zcaps/revocations/`
332
+ const idx = req.originalUrl.indexOf('/zcaps/revocations/');
333
333
  const path = req.originalUrl.substring(0, idx);
334
334
  return `https://${expectedHost}${path}`;
335
335
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalbazaar/ezcap-express",
3
- "version": "5.1.0",
3
+ "version": "6.2.0",
4
4
  "main": "lib",
5
5
  "module": "main.js",
6
6
  "repository": {
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@digitalbazaar/http-digest-header": "^1.0.1",
26
26
  "@digitalbazaar/http-signature-header": "^4.0.1",
27
- "@digitalbazaar/http-signature-zcap-verify": "^10.1.0",
27
+ "@digitalbazaar/http-signature-zcap-verify": "^10.2.0",
28
28
  "@digitalbazaar/zcap": "^7.1.0",
29
29
  "assert-plus": "^1.0.0",
30
30
  "esm": "^3.2.25",
package/CHANGELOG.md DELETED
@@ -1,224 +0,0 @@
1
- # @digitalbazaar/ezcap-express Changelog
2
-
3
- ## 5.1.0 - 2022-01-14
4
-
5
- ### Added
6
- - Use zcap@7.1 and http-signature-zcap-verify@10.1 to include
7
- `dereferencedChain` in verification results and `req.zcap`.
8
-
9
- ## 5.0.1 - 2022-01-11
10
-
11
- ### Changed
12
- - Update dependencies.
13
-
14
- ## 5.0.0 - 2022-01-11
15
-
16
- ### Added
17
- - Add optional parameters `maxChainLength`, `maxDelegationTtl`, and
18
- `maxTimestampDelta` to allow for more fine grained control. These parameters
19
- all have defaults in `@digitalbazaar/zcap` that could previously not be set
20
- to other values at this layer.
21
- - **BREAKING**: Add required `getVerifier` async function parameter. The
22
- function will be passed `{keyId, documentLoader}` to verify an HTTP signature
23
- and must return `{verifier, verificationMethod}`. The `verifier` object must
24
- have a `verify` function that takes `{data, signature}` and returns a
25
- boolean indicating whether the `Uint8Array` `signature` is verified
26
- against the `Uint8Array` `data` -- or throws an error if there is a reason
27
- the cryptographic signature verification check cannot be run.
28
- - Include `capabilityChain` in `req.zcapRevocation` when using revocation
29
- middleware. This property includes the entire dereferenced chain.
30
-
31
- ### Changed
32
- - **BREAKING**: Replace broken-out expected value parameters (e.g.,
33
- `expectedHost`, `expectedTarget`), including duplicative / optional
34
- parameters (e.g., `expectedAction`, `getExpectedAction`) with a single
35
- async function `getExpectedValues({req})` that returns all required (and any
36
- optional) expected values. This removes some optionality and simplifies
37
- function signatures -- also allowing callers to decide how they want
38
- to provide this information (e.g., by calling individual functions from
39
- within `getExpectedValues` or whatever else).
40
- - **BREAKING**: The `authorizeZcapRevocation` middleware may now only be used
41
- on routes ending in `/revocations/:revocationId`. The API params have also
42
- changed as the only expected value that is needed from the user is
43
- `expectedHost`. The rest of the expected values are hard coded according to
44
- a conventional pattern for supporting revocation of any zcaps delegated from
45
- a root capability for a service object. The service object's root capability
46
- MUST have an invocation target that matches the service object's URL (aka its
47
- "ID", `<serviceObjectId>`). So for the absolute URL:
48
-
49
- `<serviceObjectId>/revocations/:revocationId`
50
-
51
- A zcap can only be revoked using the middleware if its chain has a root
52
- zcap with an invocation target that is prefixed with `<serviceObjectId>`.
53
- The middleware will use the `expectedHost` value to construct the absolute
54
- URL.
55
- - **BREAKING**: Require `suiteFactory` parameter, no default cryptosuites are
56
- included with this package to ensure it is decoupled from particular
57
- cryptosuites.
58
-
59
- ### Fixed
60
- - **BREAKING**: HTTP status error codes have been fixed so that client errors
61
- will result in 4xx status codes instead of 5xx status codes.
62
-
63
- ### Remove
64
- - **BREAKING**: Remove `getExpectedRootCapabilityId` as there have been no
65
- use cases that have needed it.
66
- - **BREAKING**: Remove deprecated `suite` param, use `suiteFactory` instead.
67
-
68
- ## 4.5.0 - 2021-12-17
69
-
70
- ### Fixed
71
- - Add `_createGetRevocationRootController` wrapper around
72
- `_getRevocationRootController` and pass `getRootController` to it.
73
-
74
- ### Added
75
- - Add tests for `authorizeZcapRevocation`.
76
-
77
- ## 4.4.0 - 2021-12-15
78
-
79
- ### Added
80
- - Add additional tests.
81
-
82
- ## 4.3.1 - 2021-12-13
83
-
84
- ### Fixed
85
- - Fix `expectedAction` to be `write` for `DELETE` method.
86
- - Throw error when no `expectedAction` is given for a given HTTP method and
87
- provide defaults for all common HTTP methods.
88
-
89
- ## 4.3.0 - 2021-12-10
90
-
91
- ### Added
92
- - Allow any controller in a delegated zcap's chain to revoke it. This authority
93
- is inherent in delegation and is now reflected in code. This feature gives
94
- delegators more fine-grained control to revoke zcaps that they did not
95
- delegate directly but one of their delegates did, allowing them to stop
96
- specific zcap usage without having to revoke more of the chain. It also
97
- gives zcap controllers the ability to revoke their own zcaps (if desired)
98
- and adds a sanity check to prevent the revocation of root zcaps that use
99
- the `urn:zcap:root:` ID scheme.
100
-
101
- ## 4.2.0 - 2021-08-26
102
-
103
- ### Added
104
- - Add `suiteFactory` parameter to middleware creation functions. A
105
- `suiteFactory` function should be passed and return the supported LD proof
106
- suite (or an array of supported LD proof suites) that is supported for
107
- authorizing zcap invocations and verifying capability chains.
108
- - Add `authorizeZcapRevocation` middleware that can be attached to root
109
- container/object endpoints to enable revocation of zcaps that have been
110
- delegated to use them. This version assumes that the revocations endpoint
111
- will follow this RESTful format: `<rootObjectUrl>/revocations/<zcapId>`
112
- and that the body will be JSON and include a `capability` member with
113
- the zcap to revoke. Future versions may allow for greater flexibility.
114
-
115
- ### Changed
116
- - Deprecate passing a `suite` to any middleware creation functions. Instead,
117
- `suiteFactory` should be passed. The next major version will remove `suite`.
118
- This approach allows this library to remove npm dependencies that provide
119
- cryptographic suites preventing this library from being affected when those
120
- dependencies need to change.
121
-
122
- ## 4.1.1 - 2021-07-21
123
-
124
- ### Changed
125
- - Updated dependencies.
126
-
127
- ## 4.1.0 - 2021-07-11
128
-
129
- ### Changed
130
- - Updated http-signature-zcap-verify to 8.1.x to bring in optimizations
131
- for controllers that use DID Documents.
132
-
133
- ## 4.0.1 - 2021-07-10
134
-
135
- ### Fixed
136
- - Fix http-signature-zcap-verify dependency to use 8.x to function
137
- properly with updated ed25519 libs.
138
-
139
- ## 4.0.0 - 2021-07-10
140
-
141
- ### Changed
142
- - **BREAKING**: Updated to use `@digitalbazaar/ed25519-signature-2020` 3.x
143
- and related libraries. These changes include breaking fixes to key
144
- formats.
145
-
146
- ## 3.4.2 - 2021-07-10
147
-
148
- ### Fixed
149
- - Fix bug with erroneously detecting request bodies. Some body
150
- parsing middleware for express/connect (e.g., the main body-parser
151
- npm package) will set a request body to an empty object even when
152
- no body is present. This previously caused an error to be thrown
153
- because no body digest header was present. The code has been updated
154
- to check for http body headers per the spec now (instead of trusting
155
- the `req.body` value) and it will set the `req.body` value to
156
- `undefined` if it is not present.
157
-
158
- ## 3.4.1 - 2021-07-10
159
-
160
- ### Fixed
161
- - Fix error handling bugs. Http signature errors thrown by the
162
- middleware created via `authorizeZcapInvocation` will now be
163
- properly passed to the `onError` handler.
164
-
165
- ## 3.4.0 - 2021-06-28
166
-
167
- ### Added
168
- - Add missing `allowTargetAttenuation` option that defaults to `true`
169
- to support RESTful-based attenuated delegation as the documentation
170
- describes.
171
-
172
- ## 3.3.0 - 2021-05-19
173
-
174
- ### Added
175
- - Verify HTTP "digest" header when a "content-type" header or body is present.
176
-
177
- ## 3.2.0 - 2021-05-13
178
-
179
- ### Added
180
- - Add ability to specify an `inspectCapabilityChain` hook.
181
-
182
- ## 3.1.0 - 2021-05-11
183
-
184
- ### Added
185
- - Add optional `getExpectedAction({req})` hook to provide expected action
186
- based on, e.g., request body vs. HTTP method.
187
-
188
- ## 3.0.1 - 2021-04-06
189
-
190
- ### Fixed
191
- - **BREAKING**: Change the default signature suite in `authorizeZcapInvocation`
192
- to `Ed25519Signature2020` (was `Ed25519Signature2018` before). This change
193
- should have been included in the 3.0 release.
194
-
195
- ### Changed
196
- - Remove `jsonld-signatures` dependency.
197
-
198
- ## 3.0.0 - 2021-04-01
199
-
200
- ### Changed
201
- - **BREAKING**: Use `http-signature-zcap-verify@5` which only supports
202
- `Ed25519Signature2020` proofs.
203
-
204
- ## 2.0.0 - 2021-03-29
205
-
206
- ### Added
207
- - Add optional `onError` handler for customizable error handling.
208
-
209
- ### Changed
210
- - **BREAKING**: Replace `expectedTarget` parameter with `getExpectedTarget`.
211
- `getExpectedTarget` is an async function used to return the expected
212
- target(s) for the invoked capability.
213
- - **BREAKING**: Remove the `logger` parameter. Errors may now be logged by the
214
- `onError` handler.
215
-
216
- ## 1.0.1 - 2021-03-02
217
-
218
- ### Fixed
219
- - Use `http-signature-zcap-verify@4`.
220
-
221
- ## 1.0.0 - 2021-03-02
222
-
223
- ### Added
224
- - Initial commit, see individual commits for history.