@takeshape/util 8.206.0 → 8.206.7

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.
@@ -1,15 +1,4 @@
1
1
  /// <reference types="lodash" />
2
- export interface DataKeyConfig {
3
- region?: string;
4
- env: string;
5
- }
6
2
  export declare const encrypt: import("lodash").CurriedFunction2<string, string, string>;
7
- export declare type EncryptionKeys = {
8
- encryptedKey: string;
9
- plaintextKey: string;
10
- };
11
3
  export declare const decrypt: import("lodash").CurriedFunction2<string, string, string>;
12
- export declare function generateDataKey(config: DataKeyConfig): Promise<EncryptionKeys>;
13
- export declare function decryptDataKey(keyStr: string, config: DataKeyConfig): Promise<EncryptionKeys>;
14
- export declare function ensureDataKey(keyStr: string | undefined, config: DataKeyConfig): Promise<EncryptionKeys>;
15
4
  //# sourceMappingURL=encryption.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../src/encryption.ts"],"names":[],"mappings":";AAUA,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,OAAO,2DAOlB,CAAC;AAEH,oBAAY,cAAc,GAAG;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAC,CAAC;AAE1E,eAAO,MAAM,OAAO,2DAalB,CAAC;AAEH,wBAAsB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAepF;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CASnG;AAED,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAU9G"}
1
+ {"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../src/encryption.ts"],"names":[],"mappings":";AASA,eAAO,MAAM,OAAO,2DAOlB,CAAC;AAEH,eAAO,MAAM,OAAO,2DAalB,CAAC"}
@@ -3,16 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.decrypt = void 0;
7
- exports.decryptDataKey = decryptDataKey;
8
- exports.encrypt = void 0;
9
- exports.ensureDataKey = ensureDataKey;
10
- exports.generateDataKey = generateDataKey;
6
+ exports.encrypt = exports.decrypt = void 0;
11
7
 
12
8
  var _crypto = _interopRequireDefault(require("crypto"));
13
9
 
14
- var _kms = _interopRequireDefault(require("aws-sdk/clients/kms"));
15
-
16
10
  var _curry = _interopRequireDefault(require("lodash/curry"));
17
11
 
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -47,49 +41,4 @@ const decrypt = (0, _curry.default)((key, encrypted) => {
47
41
  const cipherText = input.slice(IV_LENGTH);
48
42
  return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(CONTENT_ENCODING);
49
43
  });
50
- exports.decrypt = decrypt;
51
-
52
- async function generateDataKey(config) {
53
- const {
54
- region,
55
- env
56
- } = config;
57
- const kms = new _kms.default({
58
- region
59
- });
60
- const res = await kms.generateDataKey({
61
- KeyId: `alias/takeshape-${env}`,
62
- KeySpec: 'AES_256'
63
- }).promise();
64
- return {
65
- encryptedKey: res.CiphertextBlob.toString(KEY_ENCODING),
66
- plaintextKey: res.Plaintext.toString(KEY_ENCODING)
67
- };
68
- }
69
-
70
- async function decryptDataKey(keyStr, config) {
71
- const {
72
- region
73
- } = config;
74
- const kms = new _kms.default({
75
- region
76
- });
77
- const res = await kms.decrypt({
78
- CiphertextBlob: Buffer.from(keyStr, KEY_ENCODING)
79
- }).promise();
80
- return {
81
- encryptedKey: keyStr,
82
- plaintextKey: res.Plaintext.toString(KEY_ENCODING)
83
- };
84
- }
85
-
86
- async function ensureDataKey(keyStr, config) {
87
- if (keyStr) {
88
- try {
89
- return await decryptDataKey(keyStr, config);
90
- } catch {// Ignore ciphertext error and generate a new key
91
- }
92
- }
93
-
94
- return generateDataKey(config);
95
- }
44
+ exports.decrypt = decrypt;
package/es/encryption.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import crypto from 'crypto';
2
- import KMS from 'aws-sdk/clients/kms';
3
2
  import curry from 'lodash/curry';
4
3
  const CIPHER_ALGORITHM = 'aes-256-ctr';
5
4
  const IV_LENGTH = 16;
@@ -25,46 +24,4 @@ export const decrypt = curry((key, encrypted) => {
25
24
  const decipher = crypto.createDecipheriv(CIPHER_ALGORITHM, Buffer.from(key, KEY_ENCODING), iv);
26
25
  const cipherText = input.slice(IV_LENGTH);
27
26
  return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(CONTENT_ENCODING);
28
- });
29
- export async function generateDataKey(config) {
30
- const {
31
- region,
32
- env
33
- } = config;
34
- const kms = new KMS({
35
- region
36
- });
37
- const res = await kms.generateDataKey({
38
- KeyId: `alias/takeshape-${env}`,
39
- KeySpec: 'AES_256'
40
- }).promise();
41
- return {
42
- encryptedKey: res.CiphertextBlob.toString(KEY_ENCODING),
43
- plaintextKey: res.Plaintext.toString(KEY_ENCODING)
44
- };
45
- }
46
- export async function decryptDataKey(keyStr, config) {
47
- const {
48
- region
49
- } = config;
50
- const kms = new KMS({
51
- region
52
- });
53
- const res = await kms.decrypt({
54
- CiphertextBlob: Buffer.from(keyStr, KEY_ENCODING)
55
- }).promise();
56
- return {
57
- encryptedKey: keyStr,
58
- plaintextKey: res.Plaintext.toString(KEY_ENCODING)
59
- };
60
- }
61
- export async function ensureDataKey(keyStr, config) {
62
- if (keyStr) {
63
- try {
64
- return await decryptDataKey(keyStr, config);
65
- } catch {// Ignore ciphertext error and generate a new key
66
- }
67
- }
68
-
69
- return generateDataKey(config);
70
- }
27
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/util",
3
- "version": "8.206.0",
3
+ "version": "8.206.7",
4
4
  "description": "Shared utilities",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -21,9 +21,8 @@
21
21
  "es"
22
22
  ],
23
23
  "dependencies": {
24
- "@takeshape/routing": "8.206.0",
24
+ "@takeshape/routing": "8.206.7",
25
25
  "@types/url-parse": "^1.4.4",
26
- "aws-sdk": "2.1096.0",
27
26
  "classnames": "^2.2.5",
28
27
  "dom-serializer": "0.2.2",
29
28
  "draft-js": "^0.11.7",