@verii/db-kms 1.0.0-pre.1752076816 → 1.0.0-pre.1754289942
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/package.json +10 -10
- package/src/db-kms.js +32 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verii/db-kms",
|
|
3
|
-
"version": "1.0.0-pre.
|
|
3
|
+
"version": "1.0.0-pre.1754289942",
|
|
4
4
|
"description": "KMS plugin that uses a db",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -14,19 +14,19 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@spencejs/spence-mongo-repos": "~0.10.2",
|
|
17
|
-
"@verii/crypto": "1.0.0-pre.
|
|
18
|
-
"@verii/jwt": "1.0.0-pre.
|
|
19
|
-
"@verii/spencer-mongo-extensions": "1.0.0-pre.
|
|
17
|
+
"@verii/crypto": "1.0.0-pre.1754289942",
|
|
18
|
+
"@verii/jwt": "1.0.0-pre.1754289942",
|
|
19
|
+
"@verii/spencer-mongo-extensions": "1.0.0-pre.1754289942",
|
|
20
20
|
"fastify-plugin": "^5.0.0",
|
|
21
21
|
"lodash": "~4.17.21",
|
|
22
|
-
"mongodb": "6.
|
|
22
|
+
"mongodb": "6.17.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@spencejs/spence-config": "0.10.2",
|
|
26
26
|
"@typescript-eslint/eslint-plugin": "6.21.0",
|
|
27
27
|
"@typescript-eslint/parser": "6.21.0",
|
|
28
|
-
"@verii/test-regexes": "1.0.0-pre.
|
|
29
|
-
"@verii/tests-helpers": "1.0.0-pre.
|
|
28
|
+
"@verii/test-regexes": "1.0.0-pre.1754289942",
|
|
29
|
+
"@verii/tests-helpers": "1.0.0-pre.1754289942",
|
|
30
30
|
"eslint": "8.57.1",
|
|
31
31
|
"eslint-config-airbnb-base": "14.2.1",
|
|
32
32
|
"eslint-config-prettier": "8.10.0",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"eslint-plugin-prefer-arrow-functions": "3.6.2",
|
|
37
37
|
"eslint-plugin-prettier": "4.2.1",
|
|
38
38
|
"eslint-watch": "7.0.0",
|
|
39
|
-
"fastify": "5.
|
|
39
|
+
"fastify": "5.4.0",
|
|
40
40
|
"jest": "29.7.0",
|
|
41
|
-
"mongodb": "6.
|
|
41
|
+
"mongodb": "6.17.0",
|
|
42
42
|
"prettier": "2.8.8",
|
|
43
43
|
"typescript": "5.8.3"
|
|
44
44
|
},
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"lib"
|
|
48
48
|
]
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "772b121fb3eb2ee0077a1b5c9eec3281215e9e9f"
|
|
51
51
|
}
|
package/src/db-kms.js
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* @import { Context, Id, KMS, KeySpec, KmsKey, KmsSecret, ImportableKey, ImportableSecret } from "../../types/types"
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
const { generateJWAKeyPair } = require('@verii/crypto');
|
|
25
|
-
const { jwtSign, jwtVerify } = require('@verii/jwt');
|
|
24
|
+
const { generateJWAKeyPair, encrypt, decrypt } = require('@verii/crypto');
|
|
25
|
+
const { jwtSign, jwtVerify, hexFromJwk } = require('@verii/jwt');
|
|
26
26
|
const { isEmpty, omit } = require('lodash/fp');
|
|
27
27
|
const kmsRepo = require('./repo');
|
|
28
28
|
const { defaultRepoOptions } = require('./default-repo-options');
|
|
@@ -165,6 +165,34 @@ const initDbKms = (fastify, kmsOptions = {}) => {
|
|
|
165
165
|
);
|
|
166
166
|
};
|
|
167
167
|
|
|
168
|
+
/**
|
|
169
|
+
* encrypt text using a secret
|
|
170
|
+
* @param {Record<string, unknown>} plainText the text to encrypt
|
|
171
|
+
* @param {Id} keyId the key id to encrypt with
|
|
172
|
+
* @returns {string} the encrypted text
|
|
173
|
+
*/
|
|
174
|
+
const encryptString = async (plainText, keyId) => {
|
|
175
|
+
const key = await loadKey(keyId);
|
|
176
|
+
const hex = hexFromJwk(
|
|
177
|
+
key[repoOptions.secretProp] ?? key[repoOptions.keyProp]
|
|
178
|
+
);
|
|
179
|
+
return encrypt(plainText, hex);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Decrypt text using a secret
|
|
184
|
+
* @param {string} encrypted the encrypted text to decrypt
|
|
185
|
+
* @param {Id} keyId the key id to decrypt with
|
|
186
|
+
* @returns {string} the decrypted text
|
|
187
|
+
*/
|
|
188
|
+
const decryptString = async (encrypted, keyId) => {
|
|
189
|
+
const key = await loadKey(keyId);
|
|
190
|
+
const hex = hexFromJwk(
|
|
191
|
+
key[repoOptions.secretProp] ?? key[repoOptions.keyProp]
|
|
192
|
+
);
|
|
193
|
+
return decrypt(encrypted, hex);
|
|
194
|
+
};
|
|
195
|
+
|
|
168
196
|
return {
|
|
169
197
|
createKey,
|
|
170
198
|
importKey,
|
|
@@ -172,6 +200,8 @@ const initDbKms = (fastify, kmsOptions = {}) => {
|
|
|
172
200
|
exportKeyOrSecret,
|
|
173
201
|
signJwt,
|
|
174
202
|
verifyJwt,
|
|
203
|
+
encryptString,
|
|
204
|
+
decryptString,
|
|
175
205
|
};
|
|
176
206
|
};
|
|
177
207
|
};
|