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