@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
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
import {keystores, defaultModuleManager as moduleManager} from '@bedrock/kms';
|
|
5
|
-
|
|
6
|
-
describe('keystores APIs', () => {
|
|
7
|
-
describe('getStorageUsage API', () => {
|
|
8
|
-
it('gets storage usage for a keystore', async () => {
|
|
9
|
-
let err;
|
|
10
|
-
let result;
|
|
11
|
-
const config = {
|
|
12
|
-
id: 'https://example.com/keystores/usage-test1',
|
|
13
|
-
controller: 'usage-test',
|
|
14
|
-
kmsModule: 'ssm-v1',
|
|
15
|
-
sequence: 0,
|
|
16
|
-
meterId: 'usage-meter-1'
|
|
17
|
-
};
|
|
18
|
-
try {
|
|
19
|
-
await keystores.insert({config});
|
|
20
|
-
result = await keystores.getStorageUsage({
|
|
21
|
-
meterId: 'usage-meter-1', moduleManager
|
|
22
|
-
});
|
|
23
|
-
} catch(e) {
|
|
24
|
-
err = e;
|
|
25
|
-
}
|
|
26
|
-
assertNoError(err);
|
|
27
|
-
should.exist(result);
|
|
28
|
-
result.should.be.an('object');
|
|
29
|
-
result.should.deep.equal({storage: 1});
|
|
30
|
-
});
|
|
31
|
-
it('gets custom storage usage for a keystore', async () => {
|
|
32
|
-
let err;
|
|
33
|
-
let result;
|
|
34
|
-
const config = {
|
|
35
|
-
id: 'https://example.com/keystores/usage-test2',
|
|
36
|
-
controller: 'usage-test',
|
|
37
|
-
kmsModule: 'ssm-v1',
|
|
38
|
-
sequence: 0,
|
|
39
|
-
meterId: 'usage-meter-2'
|
|
40
|
-
};
|
|
41
|
-
try {
|
|
42
|
-
await keystores.insert({config});
|
|
43
|
-
result = await keystores.getStorageUsage({
|
|
44
|
-
meterId: 'usage-meter-2', moduleManager,
|
|
45
|
-
async aggregate({usage}) {
|
|
46
|
-
usage.storage++;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
} catch(e) {
|
|
50
|
-
err = e;
|
|
51
|
-
}
|
|
52
|
-
assertNoError(err);
|
|
53
|
-
should.exist(result);
|
|
54
|
-
result.should.be.an('object');
|
|
55
|
-
result.should.deep.equal({storage: 2});
|
|
56
|
-
});
|
|
57
|
-
it('gets custom storage usage for a keystore when max concurrency is ' +
|
|
58
|
-
'reached', async () => {
|
|
59
|
-
let err;
|
|
60
|
-
let result;
|
|
61
|
-
// 54 is used in order to have a counters.length of 102 to ensure max
|
|
62
|
-
// concurrency of 100 (`USAGE_COUNTER_MAX_CONCURRENCY`) is reached;
|
|
63
|
-
// if this max concurrency changes, this test will need to change too
|
|
64
|
-
for(let i = 3; i < 54; i++) {
|
|
65
|
-
const config = {
|
|
66
|
-
id: `https://example.com/keystores/usage-test${i}`,
|
|
67
|
-
controller: 'usage-test',
|
|
68
|
-
kmsModule: 'ssm-v1',
|
|
69
|
-
sequence: 0,
|
|
70
|
-
meterId: `usage-meter-3`
|
|
71
|
-
};
|
|
72
|
-
await keystores.insert({config});
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
result = await keystores.getStorageUsage({
|
|
76
|
-
meterId: 'usage-meter-3', moduleManager,
|
|
77
|
-
async aggregate({usage}) {
|
|
78
|
-
usage.storage++;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
} catch(e) {
|
|
82
|
-
err = e;
|
|
83
|
-
}
|
|
84
|
-
assertNoError(err);
|
|
85
|
-
should.exist(result);
|
|
86
|
-
result.should.be.an('object');
|
|
87
|
-
result.should.deep.equal({storage: 102});
|
|
88
|
-
});
|
|
89
|
-
it('aborts computing metered storage', async () => {
|
|
90
|
-
let err;
|
|
91
|
-
let result;
|
|
92
|
-
const config = {
|
|
93
|
-
id: 'https://example.com/keystores/usage-test55',
|
|
94
|
-
controller: 'usage-test',
|
|
95
|
-
kmsModule: 'ssm-v1',
|
|
96
|
-
sequence: 0,
|
|
97
|
-
meterId: 'usage-meter-55'
|
|
98
|
-
};
|
|
99
|
-
try {
|
|
100
|
-
await keystores.insert({config});
|
|
101
|
-
result = await keystores.getStorageUsage({
|
|
102
|
-
signal: {
|
|
103
|
-
abort: true
|
|
104
|
-
},
|
|
105
|
-
meterId: 'usage-meter-55', moduleManager,
|
|
106
|
-
async aggregate({usage}) {
|
|
107
|
-
usage.storage++;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
} catch(e) {
|
|
111
|
-
err = e;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
should.exist(err);
|
|
115
|
-
should.not.exist(result);
|
|
116
|
-
err.name.should.equal('AbortError');
|
|
117
|
-
});
|
|
118
|
-
}); // end getStorageUsage API
|
|
119
|
-
}); // end keystore APIs
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
import * as helpers from './helpers.js';
|
|
5
|
-
import {createRequire} from 'node:module';
|
|
6
|
-
import {defaultModuleManager as moduleManager} from '@bedrock/kms';
|
|
7
|
-
import {klona} from 'klona';
|
|
8
|
-
import {mockData} from './mock.data.js';
|
|
9
|
-
import {v4 as uuid} from 'uuid';
|
|
10
|
-
const require = createRequire(import.meta.url);
|
|
11
|
-
const {runOperation} = require('@digitalbazaar/webkms-switch');
|
|
12
|
-
|
|
13
|
-
describe('bedrock-kms', () => {
|
|
14
|
-
describe('integration with runOperation API', () => {
|
|
15
|
-
describe('GenerateKeyOperation', () => {
|
|
16
|
-
it('successfully generates a Ed25519VerificationKey2018', async () => {
|
|
17
|
-
const keystore = {
|
|
18
|
-
id: 'https://example.com/keystores/x',
|
|
19
|
-
controller: 'urn:uuid:baa943d2-7338-11ec-b1c4-10bf48838a41',
|
|
20
|
-
kmsModule: 'ssm-v1'
|
|
21
|
-
};
|
|
22
|
-
const operation = klona(
|
|
23
|
-
mockData.operations.generate({type: 'Ed25519VerificationKey2018'}));
|
|
24
|
-
operation.invocationTarget.type = 'Ed25519VerificationKey2018';
|
|
25
|
-
let error;
|
|
26
|
-
let result;
|
|
27
|
-
try {
|
|
28
|
-
result = await runOperation({operation, keystore, moduleManager});
|
|
29
|
-
} catch(e) {
|
|
30
|
-
error = e;
|
|
31
|
-
}
|
|
32
|
-
assertNoError(error);
|
|
33
|
-
should.exist(result);
|
|
34
|
-
result.should.have.keys(['keyId', 'result']);
|
|
35
|
-
result.result.should.have.keys(['keyId', 'keyDescription']);
|
|
36
|
-
const {keyDescription} = result.result;
|
|
37
|
-
keyDescription.should.have.keys(
|
|
38
|
-
['@context', 'id', 'publicKeyBase58', 'type', 'controller']);
|
|
39
|
-
keyDescription.type.should.equal(operation.invocationTarget.type);
|
|
40
|
-
keyDescription.publicKeyBase58.should.be.a('string');
|
|
41
|
-
});
|
|
42
|
-
it('successfully generates a Ed25519VerificationKey2020', async () => {
|
|
43
|
-
const keystore = {
|
|
44
|
-
id: 'https://example.com/keystores/x',
|
|
45
|
-
controller: 'urn:uuid:baa943d2-7338-11ec-b1c4-10bf48838a41',
|
|
46
|
-
kmsModule: 'ssm-v1'
|
|
47
|
-
};
|
|
48
|
-
const operation = klona(
|
|
49
|
-
mockData.operations.generate({type: 'Ed25519VerificationKey2020'}));
|
|
50
|
-
operation.invocationTarget.type = 'Ed25519VerificationKey2020';
|
|
51
|
-
let error;
|
|
52
|
-
let result;
|
|
53
|
-
try {
|
|
54
|
-
result = await runOperation({operation, keystore, moduleManager});
|
|
55
|
-
} catch(e) {
|
|
56
|
-
error = e;
|
|
57
|
-
}
|
|
58
|
-
assertNoError(error);
|
|
59
|
-
should.exist(result);
|
|
60
|
-
result.should.have.keys(['keyId', 'result']);
|
|
61
|
-
result.result.should.have.keys(['keyId', 'keyDescription']);
|
|
62
|
-
const {keyDescription} = result.result;
|
|
63
|
-
keyDescription.should.have.keys(
|
|
64
|
-
['@context', 'id', 'publicKeyMultibase', 'type', 'controller']);
|
|
65
|
-
keyDescription.type.should.equal(operation.invocationTarget.type);
|
|
66
|
-
keyDescription.publicKeyMultibase.should.be.a('string');
|
|
67
|
-
});
|
|
68
|
-
it('successfully generates a Sha256HmacKey2019', async () => {
|
|
69
|
-
const keystore = {
|
|
70
|
-
id: 'https://example.com/keystores/x',
|
|
71
|
-
controller: 'urn:uuid:baa943d2-7338-11ec-b1c4-10bf48838a41',
|
|
72
|
-
kmsModule: 'ssm-v1'
|
|
73
|
-
};
|
|
74
|
-
const operation = klona(
|
|
75
|
-
mockData.operations.generate({type: 'Sha256HmacKey2019'}));
|
|
76
|
-
operation.invocationTarget.type = 'Sha256HmacKey2019';
|
|
77
|
-
let error;
|
|
78
|
-
let result;
|
|
79
|
-
try {
|
|
80
|
-
result = await runOperation({operation, keystore, moduleManager});
|
|
81
|
-
} catch(e) {
|
|
82
|
-
error = e;
|
|
83
|
-
}
|
|
84
|
-
assertNoError(error);
|
|
85
|
-
should.exist(result);
|
|
86
|
-
result.should.be.an('object');
|
|
87
|
-
result.should.have.keys(['keyId', 'result']);
|
|
88
|
-
result.result.should.have.keys(['keyId', 'keyDescription']);
|
|
89
|
-
const {keyDescription} = result.result;
|
|
90
|
-
keyDescription.should.have.keys(
|
|
91
|
-
['@context', 'id', 'type', 'controller']);
|
|
92
|
-
});
|
|
93
|
-
it('successfully generates a AesKeyWrappingKey2019', async () => {
|
|
94
|
-
const keystore = {
|
|
95
|
-
id: 'https://example.com/keystores/x',
|
|
96
|
-
controller: 'urn:uuid:baa943d2-7338-11ec-b1c4-10bf48838a41',
|
|
97
|
-
kmsModule: 'ssm-v1'
|
|
98
|
-
};
|
|
99
|
-
const operation = klona(
|
|
100
|
-
mockData.operations.generate({type: 'AesKeyWrappingKey2019'}));
|
|
101
|
-
operation.invocationTarget.type = 'AesKeyWrappingKey2019';
|
|
102
|
-
let error;
|
|
103
|
-
let result;
|
|
104
|
-
try {
|
|
105
|
-
result = await runOperation({operation, keystore, moduleManager});
|
|
106
|
-
} catch(e) {
|
|
107
|
-
error = e;
|
|
108
|
-
}
|
|
109
|
-
assertNoError(error);
|
|
110
|
-
should.exist(result);
|
|
111
|
-
result.should.be.an('object');
|
|
112
|
-
result.should.have.keys(['keyId', 'result']);
|
|
113
|
-
result.result.should.have.keys(['keyId', 'keyDescription']);
|
|
114
|
-
const {keyDescription} = result.result;
|
|
115
|
-
keyDescription.should.have.keys(
|
|
116
|
-
['@context', 'id', 'type', 'controller']);
|
|
117
|
-
});
|
|
118
|
-
it('throws on UnknownKeyType', async () => {
|
|
119
|
-
const keystore = {
|
|
120
|
-
id: 'https://example.com/keystores/x',
|
|
121
|
-
controller: 'urn:uuid:baa943d2-7338-11ec-b1c4-10bf48838a41',
|
|
122
|
-
kmsModule: 'ssm-v1'
|
|
123
|
-
};
|
|
124
|
-
const operation = klona(
|
|
125
|
-
mockData.operations.generate({type: 'AesKeyWrappingKey2019'}));
|
|
126
|
-
operation.invocationTarget.type = 'UnknownKeyType';
|
|
127
|
-
let error;
|
|
128
|
-
let result;
|
|
129
|
-
try {
|
|
130
|
-
result = await runOperation({operation, keystore, moduleManager});
|
|
131
|
-
} catch(e) {
|
|
132
|
-
error = e;
|
|
133
|
-
}
|
|
134
|
-
should.exist(error);
|
|
135
|
-
should.not.exist(result);
|
|
136
|
-
error.message.should.include('UnknownKeyType');
|
|
137
|
-
});
|
|
138
|
-
}); // end GenerateKeyOperation
|
|
139
|
-
|
|
140
|
-
describe('SignOperation', () => {
|
|
141
|
-
it('signs a string using Ed25519VerificationKey2018', async () => {
|
|
142
|
-
const {keystore, key: {id: keyId}} = await helpers.generateKey(
|
|
143
|
-
{mockData, type: 'Ed25519VerificationKey2018'});
|
|
144
|
-
const operation = klona(mockData.operations.sign);
|
|
145
|
-
operation.invocationTarget = keyId;
|
|
146
|
-
operation.verifyData = uuid();
|
|
147
|
-
let result;
|
|
148
|
-
let error;
|
|
149
|
-
try {
|
|
150
|
-
result = await runOperation({operation, keystore, moduleManager});
|
|
151
|
-
} catch(e) {
|
|
152
|
-
error = e;
|
|
153
|
-
}
|
|
154
|
-
assertNoError(error);
|
|
155
|
-
should.exist(result);
|
|
156
|
-
result.should.be.an('object');
|
|
157
|
-
result.should.have.keys(['keyId', 'result']);
|
|
158
|
-
result.result.should.have.keys(['signatureValue']);
|
|
159
|
-
should.exist(result.result.signatureValue);
|
|
160
|
-
const {signatureValue} = result.result;
|
|
161
|
-
signatureValue.should.be.a('string');
|
|
162
|
-
});
|
|
163
|
-
it('signs a string using Ed25519VerificationKey2020', async () => {
|
|
164
|
-
const {keystore, key: {id: keyId}} = await helpers.generateKey(
|
|
165
|
-
{mockData, type: 'Ed25519VerificationKey2020'});
|
|
166
|
-
const operation = klona(mockData.operations.sign);
|
|
167
|
-
operation.invocationTarget = keyId;
|
|
168
|
-
operation.verifyData = uuid();
|
|
169
|
-
let result;
|
|
170
|
-
let error;
|
|
171
|
-
try {
|
|
172
|
-
result = await runOperation({operation, keystore, moduleManager});
|
|
173
|
-
} catch(e) {
|
|
174
|
-
error = e;
|
|
175
|
-
}
|
|
176
|
-
assertNoError(error);
|
|
177
|
-
should.exist(result);
|
|
178
|
-
result.should.be.an('object');
|
|
179
|
-
result.should.have.keys(['keyId', 'result']);
|
|
180
|
-
result.result.should.have.keys(['signatureValue']);
|
|
181
|
-
should.exist(result.result.signatureValue);
|
|
182
|
-
const {signatureValue} = result.result;
|
|
183
|
-
signatureValue.should.be.a('string');
|
|
184
|
-
});
|
|
185
|
-
it('signs a string using Sha256HmacKey2019', async () => {
|
|
186
|
-
const {keystore, key: {id: keyId}} = await helpers.generateKey(
|
|
187
|
-
{mockData, type: 'Sha256HmacKey2019'});
|
|
188
|
-
const operation = klona(mockData.operations.sign);
|
|
189
|
-
operation.invocationTarget = keyId;
|
|
190
|
-
operation.verifyData = uuid();
|
|
191
|
-
let result;
|
|
192
|
-
let error;
|
|
193
|
-
try {
|
|
194
|
-
result = await runOperation({operation, keystore, moduleManager});
|
|
195
|
-
} catch(e) {
|
|
196
|
-
error = e;
|
|
197
|
-
}
|
|
198
|
-
assertNoError(error);
|
|
199
|
-
should.exist(result);
|
|
200
|
-
result.should.be.an('object');
|
|
201
|
-
result.should.have.keys(['keyId', 'result']);
|
|
202
|
-
result.result.should.have.keys(['signatureValue']);
|
|
203
|
-
const {signatureValue} = result.result;
|
|
204
|
-
signatureValue.should.be.a('string');
|
|
205
|
-
signatureValue.should.have.length(43);
|
|
206
|
-
});
|
|
207
|
-
}); // end SignOperation
|
|
208
|
-
|
|
209
|
-
describe('VerifyOperation', () => {
|
|
210
|
-
it('verifies a string using Sha256HmacKey2019', async () => {
|
|
211
|
-
const verifyData = uuid();
|
|
212
|
-
const {keystore, key: {id: keyId}} = await helpers.generateKey(
|
|
213
|
-
{mockData, type: 'Sha256HmacKey2019'});
|
|
214
|
-
const signOperation = klona(mockData.operations.sign);
|
|
215
|
-
signOperation.invocationTarget = keyId;
|
|
216
|
-
signOperation.verifyData = verifyData;
|
|
217
|
-
const {result: {signatureValue}} = await runOperation(
|
|
218
|
-
{operation: signOperation, keystore, moduleManager});
|
|
219
|
-
const verifyOperation = klona(mockData.operations.verify);
|
|
220
|
-
verifyOperation.invocationTarget = keyId;
|
|
221
|
-
verifyOperation.verifyData = verifyData;
|
|
222
|
-
verifyOperation.signatureValue = signatureValue;
|
|
223
|
-
let result;
|
|
224
|
-
let error;
|
|
225
|
-
try {
|
|
226
|
-
result = await runOperation(
|
|
227
|
-
{operation: verifyOperation, keystore, moduleManager});
|
|
228
|
-
} catch(e) {
|
|
229
|
-
error = e;
|
|
230
|
-
}
|
|
231
|
-
assertNoError(error);
|
|
232
|
-
should.exist(result);
|
|
233
|
-
result.should.be.an('object');
|
|
234
|
-
result.should.have.keys(['keyId', 'result']);
|
|
235
|
-
result.result.should.have.keys(['verified']);
|
|
236
|
-
result.result.verified.should.be.true;
|
|
237
|
-
});
|
|
238
|
-
}); // end VerifyOperation
|
|
239
|
-
}); // end runOperation API
|
|
240
|
-
}); // end bedrock-kms
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
import * as helpers from './helpers.js';
|
|
5
|
-
import {createRequire} from 'module';
|
|
6
|
-
import {defaultModuleManager as moduleManager} from '@bedrock/kms';
|
|
7
|
-
import {klona} from 'klona';
|
|
8
|
-
import {mockData} from './mock.data.js';
|
|
9
|
-
import {v4 as uuid} from 'uuid';
|
|
10
|
-
const require = createRequire(import.meta.url);
|
|
11
|
-
const {runOperation} = require('@digitalbazaar/webkms-switch');
|
|
12
|
-
|
|
13
|
-
describe('bulk operations', () => {
|
|
14
|
-
describe('Ed25519VerificationKey2020', () => {
|
|
15
|
-
let mockKeyId;
|
|
16
|
-
let keystore;
|
|
17
|
-
const operationCount = 10000;
|
|
18
|
-
const vData = [];
|
|
19
|
-
before(async () => {
|
|
20
|
-
for(let i = 0; i < operationCount; ++i) {
|
|
21
|
-
let v = '';
|
|
22
|
-
for(let n = 0; n < 100; ++n) {
|
|
23
|
-
v += uuid();
|
|
24
|
-
}
|
|
25
|
-
vData.push(v);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
before(async () => {
|
|
29
|
-
let err;
|
|
30
|
-
try {
|
|
31
|
-
({keystore, key: {id: mockKeyId}} = await helpers.generateKey(
|
|
32
|
-
{mockData, type: 'Ed25519VerificationKey2020'}));
|
|
33
|
-
} catch(e) {
|
|
34
|
-
err = e;
|
|
35
|
-
}
|
|
36
|
-
assertNoError(err);
|
|
37
|
-
});
|
|
38
|
-
it(`performs ${operationCount} signatures`, async function() {
|
|
39
|
-
this.timeout(0);
|
|
40
|
-
const promises = [];
|
|
41
|
-
for(let i = 0; i < operationCount; ++i) {
|
|
42
|
-
const operation = klona(mockData.operations.sign);
|
|
43
|
-
operation.invocationTarget = mockKeyId;
|
|
44
|
-
operation.verifyData = vData[i];
|
|
45
|
-
promises.push(runOperation({
|
|
46
|
-
operation, keystore, moduleManager
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
let result;
|
|
50
|
-
let err;
|
|
51
|
-
try {
|
|
52
|
-
result = await Promise.all(promises);
|
|
53
|
-
} catch(e) {
|
|
54
|
-
err = e;
|
|
55
|
-
}
|
|
56
|
-
assertNoError(err);
|
|
57
|
-
should.exist(result);
|
|
58
|
-
result.should.be.an('array');
|
|
59
|
-
result.should.have.length(operationCount);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe('Sha256HmacKey2019', () => {
|
|
63
|
-
let mockKeyId;
|
|
64
|
-
let keystore;
|
|
65
|
-
const operationCount = 10000;
|
|
66
|
-
const vData = [];
|
|
67
|
-
before(async () => {
|
|
68
|
-
for(let i = 0; i < operationCount; ++i) {
|
|
69
|
-
let v = '';
|
|
70
|
-
for(let n = 0; n < 100; ++n) {
|
|
71
|
-
v += uuid();
|
|
72
|
-
}
|
|
73
|
-
vData.push(v);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
before(async () => {
|
|
77
|
-
let err;
|
|
78
|
-
try {
|
|
79
|
-
({keystore, key: {id: mockKeyId}} = await helpers.generateKey(
|
|
80
|
-
{mockData, type: 'Sha256HmacKey2019'}));
|
|
81
|
-
} catch(e) {
|
|
82
|
-
err = e;
|
|
83
|
-
}
|
|
84
|
-
assertNoError(err);
|
|
85
|
-
});
|
|
86
|
-
it(`performs ${operationCount} signatures`, async function() {
|
|
87
|
-
this.timeout(0);
|
|
88
|
-
const promises = [];
|
|
89
|
-
for(let i = 0; i < operationCount; ++i) {
|
|
90
|
-
const operation = klona(mockData.operations.sign);
|
|
91
|
-
operation.invocationTarget = mockKeyId;
|
|
92
|
-
operation.verifyData = vData[i];
|
|
93
|
-
promises.push(runOperation({
|
|
94
|
-
operation, keystore, moduleManager
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
let result;
|
|
98
|
-
let err;
|
|
99
|
-
try {
|
|
100
|
-
result = await Promise.all(promises);
|
|
101
|
-
} catch(e) {
|
|
102
|
-
err = e;
|
|
103
|
-
}
|
|
104
|
-
assertNoError(err);
|
|
105
|
-
should.exist(result);
|
|
106
|
-
result.should.be.an('array');
|
|
107
|
-
result.should.have.length(operationCount);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2018-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
import * as helpers from './helpers.js';
|
|
5
|
-
import {keystores} from '@bedrock/kms';
|
|
6
|
-
|
|
7
|
-
describe('Keystores Database Tests', () => {
|
|
8
|
-
describe('Indexes', async () => {
|
|
9
|
-
let mockConfigAlpha;
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
await helpers.prepareDatabase();
|
|
12
|
-
mockConfigAlpha = {
|
|
13
|
-
id: 'https://example.com/keystores/' +
|
|
14
|
-
'8b688649-d546-4e88-9027-da434bac495a',
|
|
15
|
-
kmsModule: 'ssm-v1',
|
|
16
|
-
controller: 'caf40b44-0e66-44ef-b331-23f6ca0bb837',
|
|
17
|
-
sequence: 0,
|
|
18
|
-
meterId: '6fb34a1a-e26d-49bc-bd00-66873ab0d147'
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const mockConfigBeta = {
|
|
22
|
-
id: 'https://example.com/keystores/' +
|
|
23
|
-
'6821b4ec-2630-4bf3-9464-39581d2c4499',
|
|
24
|
-
kmsModule: 'ssm-v1',
|
|
25
|
-
controller: 'caf40b44-0e66-44ef-b331-23f6ca0bb837',
|
|
26
|
-
sequence: 0,
|
|
27
|
-
meterId: '6fb34a1a-e26d-49bc-bd00-66873ab0d147'
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
await keystores.insert({config: mockConfigAlpha});
|
|
31
|
-
// second record is inserted here in order to do proper assertions for
|
|
32
|
-
// 'nReturned', 'totalKeysExamined' and 'totalDocsExamined'.
|
|
33
|
-
await keystores.insert({config: mockConfigBeta});
|
|
34
|
-
});
|
|
35
|
-
it(`is properly indexed for 'config.controller' in find()`, async () => {
|
|
36
|
-
// finds all records that match the 'config.controller' query since it is
|
|
37
|
-
// a non unique index.
|
|
38
|
-
const {executionStats} = await keystores.find({
|
|
39
|
-
controller: mockConfigAlpha.controller,
|
|
40
|
-
query: {},
|
|
41
|
-
explain: true
|
|
42
|
-
});
|
|
43
|
-
executionStats.nReturned.should.equal(2);
|
|
44
|
-
executionStats.totalKeysExamined.should.equal(2);
|
|
45
|
-
executionStats.totalDocsExamined.should.equal(2);
|
|
46
|
-
executionStats.executionStages.inputStage.stage.should.equal('IXSCAN');
|
|
47
|
-
executionStats.executionStages.inputStage.keyPattern
|
|
48
|
-
.should.eql({'config.controller': 1});
|
|
49
|
-
});
|
|
50
|
-
it(`is properly indexed for 'config.id' in update()`, async () => {
|
|
51
|
-
mockConfigAlpha.sequence += 1;
|
|
52
|
-
const {executionStats} = await keystores.update({
|
|
53
|
-
config: mockConfigAlpha,
|
|
54
|
-
explain: true
|
|
55
|
-
});
|
|
56
|
-
executionStats.nReturned.should.equal(1);
|
|
57
|
-
executionStats.totalKeysExamined.should.equal(1);
|
|
58
|
-
executionStats.totalDocsExamined.should.equal(1);
|
|
59
|
-
executionStats.executionStages.inputStage.inputStage.stage
|
|
60
|
-
.should.equal('IXSCAN');
|
|
61
|
-
executionStats.executionStages.inputStage.inputStage.keyPattern
|
|
62
|
-
.should.eql({'config.id': 1});
|
|
63
|
-
});
|
|
64
|
-
it(`is properly indexed for 'config.meterId' in getStorageUsage()`,
|
|
65
|
-
async () => {
|
|
66
|
-
// finds all records that match the 'config.meter' query since it is
|
|
67
|
-
// a non unique index.
|
|
68
|
-
const {executionStats} = await keystores.getStorageUsage({
|
|
69
|
-
meterId: mockConfigAlpha.meterId,
|
|
70
|
-
explain: true
|
|
71
|
-
});
|
|
72
|
-
executionStats.nReturned.should.equal(2);
|
|
73
|
-
executionStats.totalKeysExamined.should.equal(2);
|
|
74
|
-
executionStats.totalDocsExamined.should.equal(2);
|
|
75
|
-
executionStats.executionStages.inputStage.inputStage.stage
|
|
76
|
-
.should.equal('IXSCAN');
|
|
77
|
-
executionStats.executionStages.inputStage.inputStage.keyPattern
|
|
78
|
-
.should.eql({'config.meterId': 1});
|
|
79
|
-
});
|
|
80
|
-
it(`is properly indexed for 'config.id' in _getUncachedRecord()`,
|
|
81
|
-
async () => {
|
|
82
|
-
const {executionStats} = await keystores._getUncachedRecord({
|
|
83
|
-
id: mockConfigAlpha.id,
|
|
84
|
-
explain: true
|
|
85
|
-
});
|
|
86
|
-
executionStats.nReturned.should.equal(1);
|
|
87
|
-
executionStats.totalKeysExamined.should.equal(1);
|
|
88
|
-
executionStats.totalDocsExamined.should.equal(1);
|
|
89
|
-
executionStats.executionStages.inputStage.inputStage.inputStage.stage
|
|
90
|
-
.should.equal('IXSCAN');
|
|
91
|
-
executionStats.executionStages.inputStage.inputStage.inputStage
|
|
92
|
-
.keyPattern.should.eql({'config.id': 1});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
import {defaultDocumentLoader as documentLoader} from '@bedrock/kms';
|
|
5
|
-
|
|
6
|
-
describe('defaultDocumentLoader', () => {
|
|
7
|
-
it('returns a did document from the document loader', async () => {
|
|
8
|
-
const url = 'did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH';
|
|
9
|
-
|
|
10
|
-
let err;
|
|
11
|
-
let result;
|
|
12
|
-
try {
|
|
13
|
-
result = await documentLoader(url);
|
|
14
|
-
} catch(e) {
|
|
15
|
-
err = e;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
should.exist(result);
|
|
19
|
-
should.not.exist(err);
|
|
20
|
-
result.should.have.keys(['contextUrl', 'documentUrl', 'document']);
|
|
21
|
-
result.documentUrl.should.equal(url);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('throws NotFoundError on document not found', async () => {
|
|
25
|
-
const url = 'https://example.com/foo.jsonld';
|
|
26
|
-
|
|
27
|
-
let err;
|
|
28
|
-
let result;
|
|
29
|
-
try {
|
|
30
|
-
result = await documentLoader(url);
|
|
31
|
-
} catch(e) {
|
|
32
|
-
err = e;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
should.not.exist(result);
|
|
36
|
-
should.exist(err);
|
|
37
|
-
err.should.be.instanceOf(Error);
|
|
38
|
-
err.message.should.contain(url);
|
|
39
|
-
});
|
|
40
|
-
});
|
package/test/mocha/cryptoLd.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
import {createRequire} from 'node:module';
|
|
5
|
-
const require = createRequire(import.meta.url);
|
|
6
|
-
const {CryptoLD} = require('crypto-ld');
|
|
7
|
-
const {Ed25519VerificationKey2018} =
|
|
8
|
-
require('@digitalbazaar/ed25519-verification-key-2018');
|
|
9
|
-
const {Ed25519VerificationKey2020} =
|
|
10
|
-
require('@digitalbazaar/ed25519-verification-key-2020');
|
|
11
|
-
const {X25519KeyAgreementKey2019} =
|
|
12
|
-
require('@digitalbazaar/x25519-key-agreement-key-2019');
|
|
13
|
-
const {X25519KeyAgreementKey2020} =
|
|
14
|
-
require('@digitalbazaar/x25519-key-agreement-key-2020');
|
|
15
|
-
|
|
16
|
-
const cryptoLd = new CryptoLD();
|
|
17
|
-
cryptoLd.use(Ed25519VerificationKey2018);
|
|
18
|
-
cryptoLd.use(Ed25519VerificationKey2020);
|
|
19
|
-
cryptoLd.use(X25519KeyAgreementKey2019);
|
|
20
|
-
cryptoLd.use(X25519KeyAgreementKey2020);
|
|
21
|
-
|
|
22
|
-
export {cryptoLd};
|
package/test/mocha/helpers.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
import * as brKms from '@bedrock/kms';
|
|
5
|
-
import * as database from '@bedrock/mongodb';
|
|
6
|
-
import {createRequire} from 'node:module';
|
|
7
|
-
import {klona} from 'klona';
|
|
8
|
-
const require = createRequire(import.meta.url);
|
|
9
|
-
const {runOperation} = require('@digitalbazaar/webkms-switch');
|
|
10
|
-
const {generateId} = require('bnid');
|
|
11
|
-
|
|
12
|
-
export async function generateKey({mockData, type}) {
|
|
13
|
-
// create a keystore
|
|
14
|
-
const mockKeystoreId = `https://example.com/keystore/${await generateId()}`;
|
|
15
|
-
const keystore = {
|
|
16
|
-
id: mockKeystoreId,
|
|
17
|
-
controller: 'urn:foo',
|
|
18
|
-
kmsModule: 'ssm-v1',
|
|
19
|
-
sequence: 0,
|
|
20
|
-
};
|
|
21
|
-
await brKms.keystores.insert({config: keystore});
|
|
22
|
-
|
|
23
|
-
const keyId = `${mockKeystoreId}/keys/${await generateId()}`;
|
|
24
|
-
const operation = klona(mockData.operations.generate({type}));
|
|
25
|
-
operation.invocationTarget.id = keyId;
|
|
26
|
-
operation.invocationTarget.type = type;
|
|
27
|
-
const moduleManager = brKms.defaultModuleManager;
|
|
28
|
-
const {result} = await runOperation({operation, keystore, moduleManager});
|
|
29
|
-
return {
|
|
30
|
-
keystore,
|
|
31
|
-
key: result.keyDescription
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function prepareDatabase() {
|
|
36
|
-
await removeCollections();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export async function removeCollections(collectionNames = ['kms-keystore']) {
|
|
40
|
-
await database.openCollections(collectionNames);
|
|
41
|
-
for(const collectionName of collectionNames) {
|
|
42
|
-
await database.collections[collectionName].deleteMany({});
|
|
43
|
-
}
|
|
44
|
-
}
|