@bedrock/kms 10.1.0 → 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.
- package/lib/BedrockKmsModuleManager.js +8 -1
- package/lib/keystores.js +12 -6
- package/package.json +13 -9
- package/.eslintrc.cjs +0 -12
- package/.github/workflows/main.yml +0 -77
- package/CHANGELOG.md +0 -238
- package/test/mocha/.eslintrc +0 -9
- package/test/mocha/10-keystores-insert-api.js +0 -275
- package/test/mocha/11-keystores-get-api.js +0 -79
- package/test/mocha/12-keystores-find-api.js +0 -127
- package/test/mocha/13-keystores-update-api.js +0 -202
- package/test/mocha/14-keystores-getStorageUsage-api.js +0 -119
- package/test/mocha/20-key-operations.js +0 -240
- package/test/mocha/30-bulk-operations.js +0 -110
- package/test/mocha/40-database.js +0 -95
- package/test/mocha/50-document-loader.js +0 -40
- package/test/mocha/cryptoLd.js +0 -22
- package/test/mocha/helpers.js +0 -44
- package/test/mocha/mock.data.js +0 -62
- package/test/package.json +0 -51
- package/test/test.config.js +0 -17
- package/test/test.js +0 -9
|
@@ -6,11 +6,18 @@ import * as brPackageManager from '@bedrock/package-manager';
|
|
|
6
6
|
// load config defaults
|
|
7
7
|
import './config.js';
|
|
8
8
|
|
|
9
|
+
const importMap = new Map();
|
|
10
|
+
|
|
9
11
|
export class BedrockKmsModuleManager {
|
|
10
12
|
async get({id}) {
|
|
11
13
|
const {packageName} = brPackageManager.get(
|
|
12
14
|
{alias: id, type: 'webkms-module'});
|
|
13
|
-
|
|
15
|
+
let api = await importMap.get(packageName);
|
|
16
|
+
if(!api) {
|
|
17
|
+
const promise = import(packageName);
|
|
18
|
+
importMap.set(packageName, promise);
|
|
19
|
+
api = await promise;
|
|
20
|
+
}
|
|
14
21
|
return api.default || api;
|
|
15
22
|
}
|
|
16
23
|
}
|
package/lib/keystores.js
CHANGED
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
import * as bedrock from '@bedrock/core';
|
|
5
5
|
import * as database from '@bedrock/mongodb';
|
|
6
6
|
import assert from 'assert-plus';
|
|
7
|
+
import {LruCache} from '@digitalbazaar/lru-memoize';
|
|
7
8
|
import pAll from 'p-all';
|
|
8
|
-
import {createRequire} from 'node:module';
|
|
9
|
-
const require = createRequire(import.meta.url);
|
|
10
|
-
const {LruCache} = require('@digitalbazaar/lru-memoize');
|
|
11
9
|
|
|
12
10
|
const {util: {BedrockError}} = bedrock;
|
|
13
11
|
|
|
@@ -16,6 +14,7 @@ import './config.js';
|
|
|
16
14
|
|
|
17
15
|
const USAGE_COUNTER_MAX_CONCURRENCY = 100;
|
|
18
16
|
let KEYSTORE_CONFIG_CACHE;
|
|
17
|
+
let DISABLE_CLEAR_CACHE_ON_UPDATE = false;
|
|
19
18
|
|
|
20
19
|
// cache only exported for testing purposes
|
|
21
20
|
export {KEYSTORE_CONFIG_CACHE as _KEYSTORE_CONFIG_CACHE};
|
|
@@ -198,8 +197,10 @@ export async function update({config, explain = false} = {}) {
|
|
|
198
197
|
});
|
|
199
198
|
}
|
|
200
199
|
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
if(!DISABLE_CLEAR_CACHE_ON_UPDATE) {
|
|
201
|
+
// delete record from cache
|
|
202
|
+
KEYSTORE_CONFIG_CACHE.delete(config.id);
|
|
203
|
+
}
|
|
203
204
|
|
|
204
205
|
return true;
|
|
205
206
|
}
|
|
@@ -210,7 +211,7 @@ export async function update({config, explain = false} = {}) {
|
|
|
210
211
|
* @param {object} options - The options to use.
|
|
211
212
|
* @param {string} options.id - The ID of the keystore.
|
|
212
213
|
* @param {boolean} [options.fresh=false] - False if it is safe to use a
|
|
213
|
-
* potentially cached value,
|
|
214
|
+
* potentially cached value, true to always get a fresh value.
|
|
214
215
|
*
|
|
215
216
|
* @returns {Promise<object>} Resolves to `{config, meta}`.
|
|
216
217
|
*/
|
|
@@ -335,3 +336,8 @@ export async function _getUncachedRecord({id, explain = false} = {}) {
|
|
|
335
336
|
}
|
|
336
337
|
return record;
|
|
337
338
|
}
|
|
339
|
+
|
|
340
|
+
// exported for testing purposes
|
|
341
|
+
export function _disableClearCacheOnUpdate(disable) {
|
|
342
|
+
DISABLE_CLEAR_CACHE_ON_UPDATE = disable;
|
|
343
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrock/kms",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Key management for Bedrock applications",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**/*.js"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
11
|
"lint": "eslint ."
|
|
9
12
|
},
|
|
@@ -23,30 +26,31 @@
|
|
|
23
26
|
"url": "https://github.com/digitalbazaar/bedrock-kms/issues"
|
|
24
27
|
},
|
|
25
28
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
29
|
+
"node": ">=16"
|
|
27
30
|
},
|
|
28
31
|
"homepage": "https://github.com/digitalbazaar/bedrock-kms",
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@digitalbazaar/lru-memoize": "^
|
|
33
|
+
"@digitalbazaar/lru-memoize": "^3.0.0",
|
|
31
34
|
"p-all": "^4.0.0"
|
|
32
35
|
},
|
|
33
36
|
"peerDependencies": {
|
|
34
|
-
"@bedrock/core": "^6.0.
|
|
37
|
+
"@bedrock/core": "^6.0.1",
|
|
35
38
|
"@bedrock/did-context": "^4.0.0",
|
|
36
|
-
"@bedrock/did-io": "^
|
|
39
|
+
"@bedrock/did-io": "^9.0.1",
|
|
37
40
|
"@bedrock/jsonld-document-loader": "^3.0.0",
|
|
38
41
|
"@bedrock/mongodb": "^10.0.0",
|
|
39
42
|
"@bedrock/package-manager": "^3.0.0",
|
|
40
43
|
"@bedrock/security-context": "^7.0.0",
|
|
41
|
-
"@bedrock/veres-one-context": "^14.0.
|
|
44
|
+
"@bedrock/veres-one-context": "^14.0.1"
|
|
42
45
|
},
|
|
43
46
|
"directories": {
|
|
44
47
|
"lib": "./lib"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
47
|
-
"eslint": "^
|
|
48
|
-
"eslint-config-digitalbazaar": "^
|
|
49
|
-
"eslint-plugin-jsdoc": "^
|
|
50
|
+
"eslint": "^8.18.0",
|
|
51
|
+
"eslint-config-digitalbazaar": "^4.0.1",
|
|
52
|
+
"eslint-plugin-jsdoc": "^39.3.3",
|
|
53
|
+
"eslint-plugin-unicorn": "^43.0.0",
|
|
50
54
|
"jsdoc-to-markdown": "^7.1.1"
|
|
51
55
|
}
|
|
52
56
|
}
|
package/.eslintrc.cjs
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
name: Bedrock Node.js CI
|
|
2
|
-
|
|
3
|
-
on: [push]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
lint:
|
|
7
|
-
runs-on: ubuntu-latest
|
|
8
|
-
timeout-minutes: 10
|
|
9
|
-
strategy:
|
|
10
|
-
matrix:
|
|
11
|
-
node-version: [16.x]
|
|
12
|
-
steps:
|
|
13
|
-
- uses: actions/checkout@v2
|
|
14
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
15
|
-
uses: actions/setup-node@v1
|
|
16
|
-
with:
|
|
17
|
-
node-version: ${{ matrix.node-version }}
|
|
18
|
-
- run: npm install
|
|
19
|
-
- name: Run eslint
|
|
20
|
-
run: npm run lint
|
|
21
|
-
test-node:
|
|
22
|
-
needs: [lint]
|
|
23
|
-
runs-on: ubuntu-latest
|
|
24
|
-
timeout-minutes: 10
|
|
25
|
-
services:
|
|
26
|
-
mongodb:
|
|
27
|
-
image: mongo:4.4
|
|
28
|
-
ports:
|
|
29
|
-
- 27017:27017
|
|
30
|
-
strategy:
|
|
31
|
-
matrix:
|
|
32
|
-
node-version: [14.x, 16.x]
|
|
33
|
-
steps:
|
|
34
|
-
- uses: actions/checkout@v2
|
|
35
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
36
|
-
uses: actions/setup-node@v1
|
|
37
|
-
with:
|
|
38
|
-
node-version: ${{ matrix.node-version }}
|
|
39
|
-
- run: |
|
|
40
|
-
npm install
|
|
41
|
-
cd test
|
|
42
|
-
npm install
|
|
43
|
-
- name: Run test with Node.js ${{ matrix.node-version }}
|
|
44
|
-
run: |
|
|
45
|
-
cd test
|
|
46
|
-
npm test
|
|
47
|
-
coverage:
|
|
48
|
-
needs: [test-node]
|
|
49
|
-
runs-on: ubuntu-latest
|
|
50
|
-
timeout-minutes: 10
|
|
51
|
-
services:
|
|
52
|
-
mongodb:
|
|
53
|
-
image: mongo:4.4
|
|
54
|
-
ports:
|
|
55
|
-
- 27017:27017
|
|
56
|
-
strategy:
|
|
57
|
-
matrix:
|
|
58
|
-
node-version: [16.x]
|
|
59
|
-
steps:
|
|
60
|
-
- uses: actions/checkout@v2
|
|
61
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
62
|
-
uses: actions/setup-node@v1
|
|
63
|
-
with:
|
|
64
|
-
node-version: ${{ matrix.node-version }}
|
|
65
|
-
- run: |
|
|
66
|
-
npm install
|
|
67
|
-
cd test
|
|
68
|
-
npm install
|
|
69
|
-
- name: Generate coverage report
|
|
70
|
-
run: |
|
|
71
|
-
cd test
|
|
72
|
-
npm run coverage-ci
|
|
73
|
-
- name: Upload coverage to Codecov
|
|
74
|
-
uses: codecov/codecov-action@v2
|
|
75
|
-
with:
|
|
76
|
-
file: ./test/coverage/lcov.info
|
|
77
|
-
fail_ci_if_error: true
|
package/CHANGELOG.md
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
# bedrock-kms ChangeLog
|
|
2
|
-
|
|
3
|
-
## 10.1.0 - 2022-05-13
|
|
4
|
-
|
|
5
|
-
### Added
|
|
6
|
-
- Add `fresh` option to `keystores.get()` API to allow for retrieving a fresh
|
|
7
|
-
(not previously cached) keystore config record.
|
|
8
|
-
|
|
9
|
-
## 10.0.0 - 2022-04-29
|
|
10
|
-
|
|
11
|
-
### Changed
|
|
12
|
-
- **BREAKING**: Update peer deps:
|
|
13
|
-
- `@bedrock/core@6`.
|
|
14
|
-
- `@bedrock/did-context@4`
|
|
15
|
-
- `@bedrock/did-io@8`
|
|
16
|
-
- `@bedrock/jsonld-document-loader@3`
|
|
17
|
-
- `@bedrock/mongodb@10`
|
|
18
|
-
- `@bedrock/package-manager@3`
|
|
19
|
-
- `@bedrock/security-context@7`
|
|
20
|
-
- `@bedrock/veres-one-context@14`.
|
|
21
|
-
|
|
22
|
-
## 9.0.0 - 2022-04-05
|
|
23
|
-
|
|
24
|
-
### Changed
|
|
25
|
-
- **BREAKING**: Rename package to `@bedrock/kms`.
|
|
26
|
-
- **BREAKING**: Convert to module (ESM).
|
|
27
|
-
- **BREAKING**: Remove default export.
|
|
28
|
-
- **BREAKING**: Require node 14.x.
|
|
29
|
-
|
|
30
|
-
## 8.3.1 - 2022-03-29
|
|
31
|
-
|
|
32
|
-
### Fixed
|
|
33
|
-
- Use updated `bedrock-security-context` peer dependency.
|
|
34
|
-
|
|
35
|
-
## 8.3.0 - 2022-03-29
|
|
36
|
-
|
|
37
|
-
### Changed
|
|
38
|
-
- Update peer deps:
|
|
39
|
-
- `bedrock@4.5`
|
|
40
|
-
- `bedrock-mongodb@8.5`.
|
|
41
|
-
- `bedrock-did-context@2.1`
|
|
42
|
-
- `bedrock-package-manager@1.2`
|
|
43
|
-
- `bedrock-jsonld-document-loader@1.3`
|
|
44
|
-
- `bedrock-veres-one-context@12.1`.
|
|
45
|
-
- Update internals to use esm style and use `esm.js` to
|
|
46
|
-
transpile to CommonJS.
|
|
47
|
-
|
|
48
|
-
## 8.2.0 - 2022-02-10
|
|
49
|
-
|
|
50
|
-
### Changed
|
|
51
|
-
- Use `bedrock-did-io@6`.
|
|
52
|
-
|
|
53
|
-
## 8.1.0 - 2022-02-08
|
|
54
|
-
|
|
55
|
-
### Changed
|
|
56
|
-
- Update peer dependency `bedrock-veres-one-context@12`.
|
|
57
|
-
|
|
58
|
-
## 8.0.0 - 2022-01-11
|
|
59
|
-
|
|
60
|
-
### Changed
|
|
61
|
-
- **BREAKING**: Require bedrock-did-io@5. This change effectively pulls in
|
|
62
|
-
the latest did-veres-one driver which ultimately uses zcap@7.
|
|
63
|
-
|
|
64
|
-
## 7.4.0 - 2021-12-17
|
|
65
|
-
|
|
66
|
-
### Changed
|
|
67
|
-
- Replace `p-limit` with `p-all`.
|
|
68
|
-
|
|
69
|
-
## 7.3.0 - 2021-12-16
|
|
70
|
-
|
|
71
|
-
### Changed
|
|
72
|
-
- Changed `getStorageUsage` to use `p-limit` for handling max concurrency.
|
|
73
|
-
|
|
74
|
-
## 7.2.0 - 2021-11-22
|
|
75
|
-
|
|
76
|
-
### Added
|
|
77
|
-
- Add `aggregate` function option for `getStorageUsage` to allow custom
|
|
78
|
-
aggregation of additional usage information. This is used, for example,
|
|
79
|
-
by `bedrock-kms-http` to store zcap revocation storage usage.
|
|
80
|
-
|
|
81
|
-
### Fixed
|
|
82
|
-
- Fixed bugs with `keystores.getStorageUsage()`.
|
|
83
|
-
|
|
84
|
-
## 7.1.0 - 2021-11-15
|
|
85
|
-
|
|
86
|
-
### Added
|
|
87
|
-
- Added optional `explain` param to get more details about database performance.
|
|
88
|
-
- Added database tests in order to check database performance.
|
|
89
|
-
|
|
90
|
-
### Changed
|
|
91
|
-
- Exposed helper functions in order to properly test database calls.
|
|
92
|
-
|
|
93
|
-
## 7.0.1 - 2021-09-01
|
|
94
|
-
|
|
95
|
-
### Fixed
|
|
96
|
-
- Fix typo in controller+referenceId index.
|
|
97
|
-
|
|
98
|
-
## 7.0.0 - 2021-07-22
|
|
99
|
-
|
|
100
|
-
### Added
|
|
101
|
-
- Add `getStorageUsage` API. This function can be called with a meter ID,
|
|
102
|
-
WebKMS module manager API and an optional abort signal. It will return the
|
|
103
|
-
current storage usage for all keystores that use the identified meter.
|
|
104
|
-
|
|
105
|
-
### Changed
|
|
106
|
-
- **BREAKING**: Database keystore collection now named `kms-keystore` to match
|
|
107
|
-
modern naming convention. There is no expectation that old systems will
|
|
108
|
-
be able to upgrade in place to this new version, rather existing systems
|
|
109
|
-
that relied on bedrock-kms (typically via bedrock-kms-http) must transition
|
|
110
|
-
to new systems running the new version.
|
|
111
|
-
|
|
112
|
-
### Removed
|
|
113
|
-
- **BREAKING**: Removed deprecated `fields` option from `keystores.find` API.
|
|
114
|
-
Use `options.projection` option instead.
|
|
115
|
-
|
|
116
|
-
## 6.0.0 - 2021-05-20
|
|
117
|
-
|
|
118
|
-
### Changed
|
|
119
|
-
- **BREAKING**: Drop support for node 10.
|
|
120
|
-
- **BREAKING**: Use `ed25519-signature-2020` signature suite. Operations must
|
|
121
|
-
now be signed using the `Ed25519Signature2020` suite.
|
|
122
|
-
- Remove unused `did-veres-one`.
|
|
123
|
-
- Remove use of `jsonld-signatures`.
|
|
124
|
-
- Remove `@digitalbazaar/did-io` and use `bedrock-did-io@2.0`.
|
|
125
|
-
- Remove `did-method-key`.
|
|
126
|
-
- Update dependencies to latest:
|
|
127
|
-
- [bedrock-did-io@2.0](https://github.com/digitalbazaar/bedrock-did-io/blob/main/CHANGELOG.md),
|
|
128
|
-
- [webkms-switch@5.0](https://github.com/digitalbazaar/webkms-switch/blob/main/CHANGELOG.md).
|
|
129
|
-
|
|
130
|
-
## 5.0.0 - 2021-03-11
|
|
131
|
-
|
|
132
|
-
### Fixed
|
|
133
|
-
- **BREAKING**: Fix incorrectly configured MongoDB index on the `kmsKeystore`
|
|
134
|
-
collection. If this software needs to be deployed along with an existing
|
|
135
|
-
database, the index named `controller_1_config.referenceId_1` will need to
|
|
136
|
-
be dropped manually. The index will be recreated automatically on Bedrock
|
|
137
|
-
application startup.
|
|
138
|
-
|
|
139
|
-
## 4.0.1 - 2021-03-09
|
|
140
|
-
|
|
141
|
-
### Fixed
|
|
142
|
-
- Remove obsolete `allowedHost` config.
|
|
143
|
-
|
|
144
|
-
## 4.0.0 - 2021-03-09
|
|
145
|
-
|
|
146
|
-
### Added
|
|
147
|
-
- Keystore configurations may now include an optional `ipAllowList` array. If
|
|
148
|
-
specified, the KMS system will only execute requests originating from IPs
|
|
149
|
-
listed in `ipAllowList`. This applies to key operations for all keys in the
|
|
150
|
-
keystore as well as modification of the configuration itself.
|
|
151
|
-
|
|
152
|
-
### Changed
|
|
153
|
-
- **BREAKING**: Change data model and validation of keystore configs. Configs
|
|
154
|
-
no longer include `invoker` or `delegator` properties.
|
|
155
|
-
|
|
156
|
-
## 3.1.0 - 2020-09-25
|
|
157
|
-
|
|
158
|
-
## Added
|
|
159
|
-
- Add cache for public key records.
|
|
160
|
-
|
|
161
|
-
## 3.0.2 - 2020-07-09
|
|
162
|
-
|
|
163
|
-
## Fixed
|
|
164
|
-
- Fix usage of MongoDB projection API.
|
|
165
|
-
|
|
166
|
-
## 3.0.1 - 2020-06-09
|
|
167
|
-
|
|
168
|
-
## Added
|
|
169
|
-
- Add `delegator` and `invoker` as valid kms config properties.
|
|
170
|
-
|
|
171
|
-
## 3.0.0 - 2020-06-09
|
|
172
|
-
|
|
173
|
-
### Changed
|
|
174
|
-
- **BREAKING**: Upgraded to `bedrock-mongodb` ^7.0.0.
|
|
175
|
-
- Mongodb `update` is now `updateOne`.
|
|
176
|
-
- Mongodb `find` no longer accepts fields.
|
|
177
|
-
|
|
178
|
-
### Added
|
|
179
|
-
- `find` now throws in both options.projection and fields are set.
|
|
180
|
-
|
|
181
|
-
## 2.1.0 - 2020-05-15
|
|
182
|
-
|
|
183
|
-
### Changed
|
|
184
|
-
- Add support for `did:v1` resolution.
|
|
185
|
-
- Add dependency for `did-io`.
|
|
186
|
-
- Add dependency for `did-veres-one`.
|
|
187
|
-
|
|
188
|
-
## 2.0.1 - 2020-05-06
|
|
189
|
-
|
|
190
|
-
### Fixed
|
|
191
|
-
- Fix error handling in `keystore.update` API.
|
|
192
|
-
|
|
193
|
-
## 2.0.0 - 2020-04-02
|
|
194
|
-
|
|
195
|
-
### Changed
|
|
196
|
-
- **BREAKING**: Use webkms-switch@2.
|
|
197
|
-
- Remove unused peer deps.
|
|
198
|
-
|
|
199
|
-
## 1.4.0 - 2020-02-25
|
|
200
|
-
|
|
201
|
-
### Changed
|
|
202
|
-
- Add dependency for `did-key-method`.
|
|
203
|
-
- Add peer dependency for `bedrock-did-context`.
|
|
204
|
-
- Add peer dependency for `bedrock-jsonld-document-loader`.
|
|
205
|
-
|
|
206
|
-
## 1.3.0 - 2020-02-14
|
|
207
|
-
|
|
208
|
-
### Changed
|
|
209
|
-
- Use jsonld-signatures@5.
|
|
210
|
-
|
|
211
|
-
## 1.2.0 - 2020-02-07
|
|
212
|
-
|
|
213
|
-
### Added
|
|
214
|
-
- Add support for `inspectCapabilityChain` handler in `validateOperation`. This
|
|
215
|
-
handler can be used to check for revocations in a capability chain.
|
|
216
|
-
- Handle reading DID key URLs (with `#`) in document loader.
|
|
217
|
-
|
|
218
|
-
## 1.1.0 - 2020-01-22
|
|
219
|
-
|
|
220
|
-
### Changed
|
|
221
|
-
- Specify peer dep bedrock-security-context@3.
|
|
222
|
-
|
|
223
|
-
## 1.0.2 - 2020-01-22
|
|
224
|
-
|
|
225
|
-
### Fixed
|
|
226
|
-
- Add missing jsonld-sigatures dep.
|
|
227
|
-
|
|
228
|
-
## 1.0.1 - 2019-12-20
|
|
229
|
-
|
|
230
|
-
### Fixed
|
|
231
|
-
- Fixed typo in module import.
|
|
232
|
-
|
|
233
|
-
## 1.0.0 - 2019-12-20
|
|
234
|
-
|
|
235
|
-
### Added
|
|
236
|
-
- Add core files.
|
|
237
|
-
|
|
238
|
-
- See git history for changes previous to this release.
|