@bedrock/kms 9.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.
@@ -0,0 +1,241 @@
1
+ /*!
2
+ * Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import * as bedrock from '@bedrock/core';
5
+ import * as helpers from './helpers.js';
6
+ import {createRequire} from 'module';
7
+ import {defaultModuleManager as moduleManager} from '@bedrock/kms';
8
+ import {mockData} from './mock.data.js';
9
+ const require = createRequire(import.meta.url);
10
+ const {runOperation} = require('@digitalbazaar/webkms-switch');
11
+
12
+ const {util: {clone, uuid}} = bedrock;
13
+
14
+ describe('bedrock-kms', () => {
15
+ describe('integration with runOperation API', () => {
16
+ describe('GenerateKeyOperation', () => {
17
+ it('successfully generates a Ed25519VerificationKey2018', async () => {
18
+ const keystore = {
19
+ id: 'https://example.com/keystores/x',
20
+ controller: 'urn:uuid:baa943d2-7338-11ec-b1c4-10bf48838a41',
21
+ kmsModule: 'ssm-v1'
22
+ };
23
+ const operation = clone(
24
+ mockData.operations.generate({type: 'Ed25519VerificationKey2018'}));
25
+ operation.invocationTarget.type = 'Ed25519VerificationKey2018';
26
+ let error;
27
+ let result;
28
+ try {
29
+ result = await runOperation({operation, keystore, moduleManager});
30
+ } catch(e) {
31
+ error = e;
32
+ }
33
+ assertNoError(error);
34
+ should.exist(result);
35
+ result.should.have.keys(['keyId', 'result']);
36
+ result.result.should.have.keys(['keyId', 'keyDescription']);
37
+ const {keyDescription} = result.result;
38
+ keyDescription.should.have.keys(
39
+ ['@context', 'id', 'publicKeyBase58', 'type', 'controller']);
40
+ keyDescription.type.should.equal(operation.invocationTarget.type);
41
+ keyDescription.publicKeyBase58.should.be.a('string');
42
+ });
43
+ it('successfully generates a Ed25519VerificationKey2020', async () => {
44
+ const keystore = {
45
+ id: 'https://example.com/keystores/x',
46
+ controller: 'urn:uuid:baa943d2-7338-11ec-b1c4-10bf48838a41',
47
+ kmsModule: 'ssm-v1'
48
+ };
49
+ const operation = clone(
50
+ mockData.operations.generate({type: 'Ed25519VerificationKey2020'}));
51
+ operation.invocationTarget.type = 'Ed25519VerificationKey2020';
52
+ let error;
53
+ let result;
54
+ try {
55
+ result = await runOperation({operation, keystore, moduleManager});
56
+ } catch(e) {
57
+ error = e;
58
+ }
59
+ assertNoError(error);
60
+ should.exist(result);
61
+ result.should.have.keys(['keyId', 'result']);
62
+ result.result.should.have.keys(['keyId', 'keyDescription']);
63
+ const {keyDescription} = result.result;
64
+ keyDescription.should.have.keys(
65
+ ['@context', 'id', 'publicKeyMultibase', 'type', 'controller']);
66
+ keyDescription.type.should.equal(operation.invocationTarget.type);
67
+ keyDescription.publicKeyMultibase.should.be.a('string');
68
+ });
69
+ it('successfully generates a Sha256HmacKey2019', async () => {
70
+ const keystore = {
71
+ id: 'https://example.com/keystores/x',
72
+ controller: 'urn:uuid:baa943d2-7338-11ec-b1c4-10bf48838a41',
73
+ kmsModule: 'ssm-v1'
74
+ };
75
+ const operation = clone(
76
+ mockData.operations.generate({type: 'Sha256HmacKey2019'}));
77
+ operation.invocationTarget.type = 'Sha256HmacKey2019';
78
+ let error;
79
+ let result;
80
+ try {
81
+ result = await runOperation({operation, keystore, moduleManager});
82
+ } catch(e) {
83
+ error = e;
84
+ }
85
+ assertNoError(error);
86
+ should.exist(result);
87
+ result.should.be.an('object');
88
+ result.should.have.keys(['keyId', 'result']);
89
+ result.result.should.have.keys(['keyId', 'keyDescription']);
90
+ const {keyDescription} = result.result;
91
+ keyDescription.should.have.keys(
92
+ ['@context', 'id', 'type', 'controller']);
93
+ });
94
+ it('successfully generates a AesKeyWrappingKey2019', async () => {
95
+ const keystore = {
96
+ id: 'https://example.com/keystores/x',
97
+ controller: 'urn:uuid:baa943d2-7338-11ec-b1c4-10bf48838a41',
98
+ kmsModule: 'ssm-v1'
99
+ };
100
+ const operation = clone(
101
+ mockData.operations.generate({type: 'AesKeyWrappingKey2019'}));
102
+ operation.invocationTarget.type = 'AesKeyWrappingKey2019';
103
+ let error;
104
+ let result;
105
+ try {
106
+ result = await runOperation({operation, keystore, moduleManager});
107
+ } catch(e) {
108
+ error = e;
109
+ }
110
+ assertNoError(error);
111
+ should.exist(result);
112
+ result.should.be.an('object');
113
+ result.should.have.keys(['keyId', 'result']);
114
+ result.result.should.have.keys(['keyId', 'keyDescription']);
115
+ const {keyDescription} = result.result;
116
+ keyDescription.should.have.keys(
117
+ ['@context', 'id', 'type', 'controller']);
118
+ });
119
+ it('throws on UnknownKeyType', async () => {
120
+ const keystore = {
121
+ id: 'https://example.com/keystores/x',
122
+ controller: 'urn:uuid:baa943d2-7338-11ec-b1c4-10bf48838a41',
123
+ kmsModule: 'ssm-v1'
124
+ };
125
+ const operation = clone(
126
+ mockData.operations.generate({type: 'AesKeyWrappingKey2019'}));
127
+ operation.invocationTarget.type = 'UnknownKeyType';
128
+ let error;
129
+ let result;
130
+ try {
131
+ result = await runOperation({operation, keystore, moduleManager});
132
+ } catch(e) {
133
+ error = e;
134
+ }
135
+ should.exist(error);
136
+ should.not.exist(result);
137
+ error.message.should.include('UnknownKeyType');
138
+ });
139
+ }); // end GenerateKeyOperation
140
+
141
+ describe('SignOperation', () => {
142
+ it('signs a string using Ed25519VerificationKey2018', async () => {
143
+ const {keystore, key: {id: keyId}} = await helpers.generateKey(
144
+ {mockData, type: 'Ed25519VerificationKey2018'});
145
+ const operation = clone(mockData.operations.sign);
146
+ operation.invocationTarget = keyId;
147
+ operation.verifyData = uuid();
148
+ let result;
149
+ let error;
150
+ try {
151
+ result = await runOperation({operation, keystore, moduleManager});
152
+ } catch(e) {
153
+ error = e;
154
+ }
155
+ assertNoError(error);
156
+ should.exist(result);
157
+ result.should.be.an('object');
158
+ result.should.have.keys(['keyId', 'result']);
159
+ result.result.should.have.keys(['signatureValue']);
160
+ should.exist(result.result.signatureValue);
161
+ const {signatureValue} = result.result;
162
+ signatureValue.should.be.a('string');
163
+ });
164
+ it('signs a string using Ed25519VerificationKey2020', async () => {
165
+ const {keystore, key: {id: keyId}} = await helpers.generateKey(
166
+ {mockData, type: 'Ed25519VerificationKey2020'});
167
+ const operation = clone(mockData.operations.sign);
168
+ operation.invocationTarget = keyId;
169
+ operation.verifyData = uuid();
170
+ let result;
171
+ let error;
172
+ try {
173
+ result = await runOperation({operation, keystore, moduleManager});
174
+ } catch(e) {
175
+ error = e;
176
+ }
177
+ assertNoError(error);
178
+ should.exist(result);
179
+ result.should.be.an('object');
180
+ result.should.have.keys(['keyId', 'result']);
181
+ result.result.should.have.keys(['signatureValue']);
182
+ should.exist(result.result.signatureValue);
183
+ const {signatureValue} = result.result;
184
+ signatureValue.should.be.a('string');
185
+ });
186
+ it('signs a string using Sha256HmacKey2019', async () => {
187
+ const {keystore, key: {id: keyId}} = await helpers.generateKey(
188
+ {mockData, type: 'Sha256HmacKey2019'});
189
+ const operation = clone(mockData.operations.sign);
190
+ operation.invocationTarget = keyId;
191
+ operation.verifyData = uuid();
192
+ let result;
193
+ let error;
194
+ try {
195
+ result = await runOperation({operation, keystore, moduleManager});
196
+ } catch(e) {
197
+ error = e;
198
+ }
199
+ assertNoError(error);
200
+ should.exist(result);
201
+ result.should.be.an('object');
202
+ result.should.have.keys(['keyId', 'result']);
203
+ result.result.should.have.keys(['signatureValue']);
204
+ const {signatureValue} = result.result;
205
+ signatureValue.should.be.a('string');
206
+ signatureValue.should.have.length(43);
207
+ });
208
+ }); // end SignOperation
209
+
210
+ describe('VerifyOperation', () => {
211
+ it('verifies a string using Sha256HmacKey2019', async () => {
212
+ const verifyData = uuid();
213
+ const {keystore, key: {id: keyId}} = await helpers.generateKey(
214
+ {mockData, type: 'Sha256HmacKey2019'});
215
+ const signOperation = clone(mockData.operations.sign);
216
+ signOperation.invocationTarget = keyId;
217
+ signOperation.verifyData = verifyData;
218
+ const {result: {signatureValue}} = await runOperation(
219
+ {operation: signOperation, keystore, moduleManager});
220
+ const verifyOperation = clone(mockData.operations.verify);
221
+ verifyOperation.invocationTarget = keyId;
222
+ verifyOperation.verifyData = verifyData;
223
+ verifyOperation.signatureValue = signatureValue;
224
+ let result;
225
+ let error;
226
+ try {
227
+ result = await runOperation(
228
+ {operation: verifyOperation, keystore, moduleManager});
229
+ } catch(e) {
230
+ error = e;
231
+ }
232
+ assertNoError(error);
233
+ should.exist(result);
234
+ result.should.be.an('object');
235
+ result.should.have.keys(['keyId', 'result']);
236
+ result.result.should.have.keys(['verified']);
237
+ result.result.verified.should.be.true;
238
+ });
239
+ }); // end VerifyOperation
240
+ }); // end runOperation API
241
+ }); // end bedrock-kms
@@ -0,0 +1,111 @@
1
+ /*!
2
+ * Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import * as bedrock from '@bedrock/core';
5
+ import * as helpers from './helpers.js';
6
+ import {createRequire} from 'module';
7
+ import {defaultModuleManager as moduleManager} from '@bedrock/kms';
8
+ import {mockData} from './mock.data.js';
9
+ const require = createRequire(import.meta.url);
10
+ const {runOperation} = require('@digitalbazaar/webkms-switch');
11
+
12
+ const {util: {clone, uuid}} = bedrock;
13
+
14
+ describe('bulk operations', () => {
15
+ describe('Ed25519VerificationKey2020', () => {
16
+ let mockKeyId;
17
+ let keystore;
18
+ const operationCount = 10000;
19
+ const vData = [];
20
+ before(async () => {
21
+ for(let i = 0; i < operationCount; ++i) {
22
+ let v = '';
23
+ for(let n = 0; n < 100; ++n) {
24
+ v += uuid();
25
+ }
26
+ vData.push(v);
27
+ }
28
+ });
29
+ before(async () => {
30
+ let err;
31
+ try {
32
+ ({keystore, key: {id: mockKeyId}} = await helpers.generateKey(
33
+ {mockData, type: 'Ed25519VerificationKey2020'}));
34
+ } catch(e) {
35
+ err = e;
36
+ }
37
+ assertNoError(err);
38
+ });
39
+ it(`performs ${operationCount} signatures`, async function() {
40
+ this.timeout(0);
41
+ const promises = [];
42
+ for(let i = 0; i < operationCount; ++i) {
43
+ const operation = clone(mockData.operations.sign);
44
+ operation.invocationTarget = mockKeyId;
45
+ operation.verifyData = vData[i];
46
+ promises.push(runOperation({
47
+ operation, keystore, moduleManager
48
+ }));
49
+ }
50
+ let result;
51
+ let err;
52
+ try {
53
+ result = await Promise.all(promises);
54
+ } catch(e) {
55
+ err = e;
56
+ }
57
+ assertNoError(err);
58
+ should.exist(result);
59
+ result.should.be.an('array');
60
+ result.should.have.length(operationCount);
61
+ });
62
+ });
63
+ describe('Sha256HmacKey2019', () => {
64
+ let mockKeyId;
65
+ let keystore;
66
+ const operationCount = 10000;
67
+ const vData = [];
68
+ before(async () => {
69
+ for(let i = 0; i < operationCount; ++i) {
70
+ let v = '';
71
+ for(let n = 0; n < 100; ++n) {
72
+ v += uuid();
73
+ }
74
+ vData.push(v);
75
+ }
76
+ });
77
+ before(async () => {
78
+ let err;
79
+ try {
80
+ ({keystore, key: {id: mockKeyId}} = await helpers.generateKey(
81
+ {mockData, type: 'Sha256HmacKey2019'}));
82
+ } catch(e) {
83
+ err = e;
84
+ }
85
+ assertNoError(err);
86
+ });
87
+ it(`performs ${operationCount} signatures`, async function() {
88
+ this.timeout(0);
89
+ const promises = [];
90
+ for(let i = 0; i < operationCount; ++i) {
91
+ const operation = clone(mockData.operations.sign);
92
+ operation.invocationTarget = mockKeyId;
93
+ operation.verifyData = vData[i];
94
+ promises.push(runOperation({
95
+ operation, keystore, moduleManager
96
+ }));
97
+ }
98
+ let result;
99
+ let err;
100
+ try {
101
+ result = await Promise.all(promises);
102
+ } catch(e) {
103
+ err = e;
104
+ }
105
+ assertNoError(err);
106
+ should.exist(result);
107
+ result.should.be.an('array');
108
+ result.should.have.length(operationCount);
109
+ });
110
+ });
111
+ });
@@ -0,0 +1,95 @@
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
+ });
@@ -0,0 +1,40 @@
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
+ });
@@ -0,0 +1,22 @@
1
+ /*!
2
+ * Copyright (c) 2021-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import {createRequire} from '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};
@@ -0,0 +1,46 @@
1
+ /*!
2
+ * Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import * as bedrock from '@bedrock/core';
5
+ import * as brKms from '@bedrock/kms';
6
+ import * as database from '@bedrock/mongodb';
7
+ import {createRequire} from 'module';
8
+ const require = createRequire(import.meta.url);
9
+ const {runOperation} = require('@digitalbazaar/webkms-switch');
10
+ const {generateId} = require('bnid');
11
+
12
+ const {util: {clone}} = bedrock;
13
+
14
+ export async function generateKey({mockData, type}) {
15
+ // create a keystore
16
+ const mockKeystoreId = `https://example.com/keystore/${await generateId()}`;
17
+ const keystore = {
18
+ id: mockKeystoreId,
19
+ controller: 'urn:foo',
20
+ kmsModule: 'ssm-v1',
21
+ sequence: 0,
22
+ };
23
+ await brKms.keystores.insert({config: keystore});
24
+
25
+ const keyId = `${mockKeystoreId}/keys/${await generateId()}`;
26
+ const operation = clone(mockData.operations.generate({type}));
27
+ operation.invocationTarget.id = keyId;
28
+ operation.invocationTarget.type = type;
29
+ const moduleManager = brKms.defaultModuleManager;
30
+ const {result} = await runOperation({operation, keystore, moduleManager});
31
+ return {
32
+ keystore,
33
+ key: result.keyDescription
34
+ };
35
+ }
36
+
37
+ export async function prepareDatabase() {
38
+ await removeCollections();
39
+ }
40
+
41
+ export async function removeCollections(collectionNames = ['kms-keystore']) {
42
+ await database.openCollections(collectionNames);
43
+ for(const collectionName of collectionNames) {
44
+ await database.collections[collectionName].deleteMany({});
45
+ }
46
+ }
@@ -0,0 +1,62 @@
1
+ /*!
2
+ * Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import * as webkmsContext from '@digitalbazaar/webkms-context';
5
+ import * as aesContext from 'aes-key-wrapping-2019-context';
6
+ import * as hmacContext from 'sha256-hmac-key-2019-context';
7
+ import {cryptoLd} from './cryptoLd.js';
8
+
9
+ const {CONTEXT_URL: WEBKMS_CONTEXT_URL} = webkmsContext;
10
+ const {CONTEXT_URL: AES_2019_CONTEXT_URL} = aesContext;
11
+ const {CONTEXT_URL: HMAC_2019_CONTEXT_URL} = hmacContext;
12
+
13
+ export const mockData = {};
14
+ const operations = mockData.operations = {};
15
+
16
+ const symmetric = new Map([
17
+ ['AesKeyWrappingKey2019', AES_2019_CONTEXT_URL],
18
+ ['Sha256HmacKey2019', HMAC_2019_CONTEXT_URL]
19
+ ]);
20
+
21
+ operations.generate = ({type}) => {
22
+ let suiteContextUrl = symmetric.get(type);
23
+ if(!suiteContextUrl) {
24
+ ({SUITE_CONTEXT: suiteContextUrl} = cryptoLd.suites.get(type) || {});
25
+ if(!suiteContextUrl) {
26
+ throw new Error(`Unknown key type: "${type}".`);
27
+ }
28
+ }
29
+
30
+ return {
31
+ '@context': [WEBKMS_CONTEXT_URL, suiteContextUrl],
32
+ type: 'GenerateKeyOperation',
33
+ invocationTarget: {
34
+ id: '',
35
+ type: '',
36
+ controller: 'https://example.com/bar'
37
+ },
38
+ proof: {
39
+ verificationMethod: 'https://example.com/bar'
40
+ }
41
+ };
42
+ };
43
+
44
+ operations.sign = {
45
+ '@context': WEBKMS_CONTEXT_URL,
46
+ type: 'SignOperation',
47
+ invocationTarget: '',
48
+ verifyData: '',
49
+ proof: {
50
+ verificationMethod: 'https://example.com/bar'
51
+ }
52
+ };
53
+
54
+ operations.verify = {
55
+ '@context': WEBKMS_CONTEXT_URL,
56
+ type: 'VerifyOperation',
57
+ invocationTarget: '',
58
+ verifyData: '',
59
+ proof: {
60
+ verificationMethod: 'https://example.com/bar'
61
+ }
62
+ };
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "bedrock-kms-test",
3
+ "version": "0.0.1-0",
4
+ "type": "module",
5
+ "description": "Bedrock KMS test",
6
+ "private": true,
7
+ "scripts": {
8
+ "test": "node --preserve-symlinks test.js test",
9
+ "coverage": "cross-env NODE_ENV=test c8 --reporter=lcov --reporter=text-summary npm test",
10
+ "coverage-ci": "cross-env NODE_ENV=test c8 --reporter=lcovonly npm test",
11
+ "coverage-report": "c8 report"
12
+ },
13
+ "dependencies": {
14
+ "@bedrock/core": "^5.0.0",
15
+ "@bedrock/did-context": "^3.0.0",
16
+ "@bedrock/did-io": "^7.0.0",
17
+ "@bedrock/https-agent": "^3.0.0",
18
+ "@bedrock/jsonld-document-loader": "^2.0.0",
19
+ "@bedrock/kms": "file:..",
20
+ "@bedrock/ledger-context": "^22.0.0",
21
+ "@bedrock/mongodb": "^9.0.0",
22
+ "@bedrock/package-manager": "^2.0.0",
23
+ "@bedrock/security-context": "^6.0.0",
24
+ "@bedrock/ssm-mongodb": "^8.0.1",
25
+ "@bedrock/test": "^7.0.0",
26
+ "@bedrock/veres-one-context": "^13.0.0",
27
+ "@digitalbazaar/ed25519-verification-key-2018": "^3.1.1",
28
+ "@digitalbazaar/ed25519-verification-key-2020": "^3.1.0",
29
+ "@digitalbazaar/webkms-context": "^2.0.0",
30
+ "@digitalbazaar/webkms-switch": "^9.0.3",
31
+ "@digitalbazaar/x25519-key-agreement-key-2019": "^5.1.1",
32
+ "@digitalbazaar/x25519-key-agreement-key-2020": "^2.0.0",
33
+ "aes-key-wrapping-2019-context": "^1.0.3",
34
+ "bnid": "^2.0.0",
35
+ "c8": "^7.11.0",
36
+ "cross-env": "^7.0.3",
37
+ "crypto-ld": "^6.0.0",
38
+ "sha256-hmac-key-2019-context": "^1.0.3"
39
+ },
40
+ "c8": {
41
+ "excludeNodeModules": false,
42
+ "include": [
43
+ "node_modules/@bedrock/kms/**"
44
+ ],
45
+ "exclude": [
46
+ "node_modules/@bedrock/kms/node_modules/**"
47
+ ]
48
+ }
49
+ }
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import {config} from '@bedrock/core';
5
+ import {fileURLToPath} from 'url';
6
+ import path from 'path';
7
+ import '@bedrock/mongodb';
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+
11
+ config.mocha.tests.push(path.join(__dirname, 'mocha'));
12
+
13
+ // MongoDB
14
+ config.mongodb.name = 'bedrock_kms_test';
15
+ config.mongodb.dropCollections = {};
16
+ config.mongodb.dropCollections.onInit = true;
17
+ config.mongodb.dropCollections.collections = [];