@webex/internal-plugin-encryption 3.0.0-beta.4 → 3.0.0-beta.400

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.
Files changed (42) hide show
  1. package/README.md +1 -3
  2. package/dist/config.js +0 -9
  3. package/dist/config.js.map +1 -1
  4. package/dist/constants.js +14 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/encryption.js +25 -74
  7. package/dist/encryption.js.map +1 -1
  8. package/dist/ensure-buffer.browser.js +0 -12
  9. package/dist/ensure-buffer.browser.js.map +1 -1
  10. package/dist/ensure-buffer.js +5 -12
  11. package/dist/ensure-buffer.js.map +1 -1
  12. package/dist/index.js +7 -33
  13. package/dist/index.js.map +1 -1
  14. package/dist/kms-batcher.js +7 -30
  15. package/dist/kms-batcher.js.map +1 -1
  16. package/dist/kms-certificate-validation.js +24 -90
  17. package/dist/kms-certificate-validation.js.map +1 -1
  18. package/dist/kms-dry-error-interceptor.js +1 -23
  19. package/dist/kms-dry-error-interceptor.js.map +1 -1
  20. package/dist/kms-errors.js +21 -51
  21. package/dist/kms-errors.js.map +1 -1
  22. package/dist/kms.js +88 -218
  23. package/dist/kms.js.map +1 -1
  24. package/package.json +15 -15
  25. package/src/config.js +3 -3
  26. package/src/constants.js +3 -0
  27. package/src/encryption.js +74 -57
  28. package/src/ensure-buffer.browser.js +0 -1
  29. package/src/ensure-buffer.js +5 -5
  30. package/src/index.js +120 -96
  31. package/src/kms-batcher.js +53 -45
  32. package/src/kms-certificate-validation.js +48 -50
  33. package/src/kms-dry-error-interceptor.js +8 -4
  34. package/src/kms-errors.js +47 -16
  35. package/src/kms.js +219 -212
  36. package/test/integration/spec/encryption.js +313 -231
  37. package/test/integration/spec/kms.js +532 -405
  38. package/test/integration/spec/payload-transfom.js +69 -69
  39. package/test/unit/spec/encryption.js +21 -18
  40. package/test/unit/spec/kms-certificate-validation.js +76 -34
  41. package/test/unit/spec/kms-errors.js +70 -0
  42. package/test/unit/spec/kms.js +103 -0
package/README.md CHANGED
@@ -21,14 +21,12 @@ npm install --save @webex/internal-plugin-encryption
21
21
  ## Usage
22
22
 
23
23
  ```js
24
-
25
24
  import '@webex/internal-plugin-encryption';
26
25
 
27
26
  import WebexCore from '@webex/webex-core';
28
27
 
29
28
  const webex = new WebexCore();
30
- webex.internal.encryption.WHATEVER
31
-
29
+ webex.internal.encryption.WHATEVER;
32
30
  ```
33
31
 
34
32
  ## Maintainers
package/dist/config.js CHANGED
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
4
-
5
4
  _Object$defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
-
9
7
  exports.default = void 0;
10
-
11
8
  /*!
12
9
  * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
13
10
  */
@@ -18,38 +15,32 @@ var _default = {
18
15
  contentAlg: 'A256GCM',
19
16
  protect: '*'
20
17
  },
21
-
22
18
  /**
23
19
  * Initial timeout before contacting KMS with a new request
24
20
  * @type {Number}
25
21
  */
26
22
  kmsInitialTimeout: 6000,
27
-
28
23
  /**
29
24
  * Maximum timeout before negotiating a new ECDH key
30
25
  * and contacting KMS with a new request
31
26
  * @type {Number}
32
27
  */
33
28
  kmsMaxTimeout: 32000,
34
-
35
29
  /**
36
30
  * Maximum timeout after negotiating several ECDH keys
37
31
  * @type {Number}
38
32
  */
39
33
  ecdhMaxTimeout: 32000 * 3,
40
-
41
34
  /**
42
35
  * Debounce wait before sending a kms request
43
36
  * @type {Number}
44
37
  */
45
38
  batcherWait: 50,
46
-
47
39
  /**
48
40
  * Maximum queue size before sending a kms request
49
41
  * @type {Number}
50
42
  */
51
43
  batcherMaxCalls: 50,
52
-
53
44
  /**
54
45
  * Debounce max wait before sending a kms metric
55
46
  * @type {Number}
@@ -1 +1 @@
1
- {"version":3,"names":["encryption","joseOptions","compact","contentAlg","protect","kmsInitialTimeout","kmsMaxTimeout","ecdhMaxTimeout","batcherWait","batcherMaxCalls","batcherMaxWait"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport default {\n encryption: {\n joseOptions: {\n compact: true,\n contentAlg: 'A256GCM',\n protect: '*'\n },\n\n /**\n * Initial timeout before contacting KMS with a new request\n * @type {Number}\n */\n kmsInitialTimeout: 6000,\n\n /**\n * Maximum timeout before negotiating a new ECDH key\n * and contacting KMS with a new request\n * @type {Number}\n */\n kmsMaxTimeout: 32000,\n\n /**\n * Maximum timeout after negotiating several ECDH keys\n * @type {Number}\n */\n ecdhMaxTimeout: 32000 * 3,\n\n /**\n * Debounce wait before sending a kms request\n * @type {Number}\n */\n batcherWait: 50,\n\n /**\n * Maximum queue size before sending a kms request\n * @type {Number}\n */\n batcherMaxCalls: 50,\n\n /**\n * Debounce max wait before sending a kms metric\n * @type {Number}\n */\n batcherMaxWait: 150\n }\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;eAEe;EACbA,UAAU,EAAE;IACVC,WAAW,EAAE;MACXC,OAAO,EAAE,IADE;MAEXC,UAAU,EAAE,SAFD;MAGXC,OAAO,EAAE;IAHE,CADH;;IAOV;AACJ;AACA;AACA;IACIC,iBAAiB,EAAE,IAXT;;IAaV;AACJ;AACA;AACA;AACA;IACIC,aAAa,EAAE,KAlBL;;IAoBV;AACJ;AACA;AACA;IACIC,cAAc,EAAE,QAAQ,CAxBd;;IA0BV;AACJ;AACA;AACA;IACIC,WAAW,EAAE,EA9BH;;IAgCV;AACJ;AACA;AACA;IACIC,eAAe,EAAE,EApCP;;IAsCV;AACJ;AACA;AACA;IACIC,cAAc,EAAE;EA1CN;AADC,C"}
1
+ {"version":3,"names":["encryption","joseOptions","compact","contentAlg","protect","kmsInitialTimeout","kmsMaxTimeout","ecdhMaxTimeout","batcherWait","batcherMaxCalls","batcherMaxWait"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport default {\n encryption: {\n joseOptions: {\n compact: true,\n contentAlg: 'A256GCM',\n protect: '*',\n },\n\n /**\n * Initial timeout before contacting KMS with a new request\n * @type {Number}\n */\n kmsInitialTimeout: 6000,\n\n /**\n * Maximum timeout before negotiating a new ECDH key\n * and contacting KMS with a new request\n * @type {Number}\n */\n kmsMaxTimeout: 32000,\n\n /**\n * Maximum timeout after negotiating several ECDH keys\n * @type {Number}\n */\n ecdhMaxTimeout: 32000 * 3,\n\n /**\n * Debounce wait before sending a kms request\n * @type {Number}\n */\n batcherWait: 50,\n\n /**\n * Maximum queue size before sending a kms request\n * @type {Number}\n */\n batcherMaxCalls: 50,\n\n /**\n * Debounce max wait before sending a kms metric\n * @type {Number}\n */\n batcherMaxWait: 150,\n },\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AAFA,eAIe;EACbA,UAAU,EAAE;IACVC,WAAW,EAAE;MACXC,OAAO,EAAE,IAAI;MACbC,UAAU,EAAE,SAAS;MACrBC,OAAO,EAAE;IACX,CAAC;IAED;AACJ;AACA;AACA;IACIC,iBAAiB,EAAE,IAAI;IAEvB;AACJ;AACA;AACA;AACA;IACIC,aAAa,EAAE,KAAK;IAEpB;AACJ;AACA;AACA;IACIC,cAAc,EAAE,KAAK,GAAG,CAAC;IAEzB;AACJ;AACA;AACA;IACIC,WAAW,EAAE,EAAE;IAEf;AACJ;AACA;AACA;IACIC,eAAe,EAAE,EAAE;IAEnB;AACJ;AACA;AACA;IACIC,cAAc,EAAE;EAClB;AACF,CAAC;AAAA"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
4
+ _Object$defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.KMS_KEY_REVOKE_FAILURE = exports.KMS_KEY_REVOKE_ERROR_STATUS = exports.KMS_KEY_REVOKE_ERROR_CODES = void 0;
8
+ var KMS_KEY_REVOKE_FAILURE = 'event:kms:key:revoke:encryption:failure';
9
+ exports.KMS_KEY_REVOKE_FAILURE = KMS_KEY_REVOKE_FAILURE;
10
+ var KMS_KEY_REVOKE_ERROR_STATUS = 405;
11
+ exports.KMS_KEY_REVOKE_ERROR_STATUS = KMS_KEY_REVOKE_ERROR_STATUS;
12
+ var KMS_KEY_REVOKE_ERROR_CODES = [405005, 405006];
13
+ exports.KMS_KEY_REVOKE_ERROR_CODES = KMS_KEY_REVOKE_ERROR_CODES;
14
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["KMS_KEY_REVOKE_FAILURE","KMS_KEY_REVOKE_ERROR_STATUS","KMS_KEY_REVOKE_ERROR_CODES"],"sources":["constants.js"],"sourcesContent":["export const KMS_KEY_REVOKE_FAILURE = 'event:kms:key:revoke:encryption:failure';\nexport const KMS_KEY_REVOKE_ERROR_STATUS = 405;\nexport const KMS_KEY_REVOKE_ERROR_CODES = [405005, 405006];\n"],"mappings":";;;;;;;AAAO,IAAMA,sBAAsB,GAAG,yCAAyC;AAAC;AACzE,IAAMC,2BAA2B,GAAG,GAAG;AAAC;AACxC,IAAMC,0BAA0B,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;AAAC"}
@@ -1,51 +1,29 @@
1
1
  "use strict";
2
2
 
3
3
  var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
4
-
5
4
  var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
6
-
7
5
  var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
8
-
9
6
  var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
10
-
11
7
  var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
12
-
13
8
  var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
14
-
15
9
  var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
16
-
17
10
  _Object$defineProperty(exports, "__esModule", {
18
11
  value: true
19
12
  });
20
-
21
13
  exports.default = void 0;
22
-
23
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
24
-
25
15
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
26
-
27
16
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
28
-
29
17
  var _events = require("events");
30
-
31
18
  var _url = _interopRequireDefault(require("url"));
32
-
33
19
  var _webexCore = require("@webex/webex-core");
34
-
35
20
  var _common = require("@webex/common");
36
-
37
21
  var _nodeJose = _interopRequireDefault(require("node-jose"));
38
-
39
22
  var _nodeScr = _interopRequireDefault(require("node-scr"));
40
-
41
23
  var _ensureBuffer = _interopRequireDefault(require("./ensure-buffer"));
42
-
43
24
  var _kms = _interopRequireDefault(require("./kms"));
44
-
45
25
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
46
-
47
26
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
48
-
49
27
  var Encryption = _webexCore.WebexPlugin.extend({
50
28
  children: {
51
29
  kms: _kms.default
@@ -60,11 +38,9 @@ var Encryption = _webexCore.WebexPlugin.extend({
60
38
  if (buffer.length === 0 || buffer.byteLength === 0) {
61
39
  return _promise.default.reject(new Error('Attempted to decrypt zero-length buffer'));
62
40
  }
63
-
64
41
  return scr.decrypt(b);
65
42
  });
66
43
  },
67
-
68
44
  /**
69
45
  * Decrypt a SCR (Secure Content Resource) using the supplied key uri.
70
46
  *
@@ -79,7 +55,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
79
55
  return _nodeScr.default.fromJWE(k.jwk, cipherScr);
80
56
  });
81
57
  },
82
-
83
58
  /**
84
59
  * Decrypt text using the supplied key uri.
85
60
  *
@@ -96,67 +71,55 @@ var Encryption = _webexCore.WebexPlugin.extend({
96
71
  });
97
72
  });
98
73
  },
99
-
100
74
  /**
101
75
  * Validate and initiate a Download request for requested file
102
- *
76
+ * @param {Object} fileUrl - Plaintext
103
77
  * @param {Object} scr - Plaintext
104
78
  * @param {Object} options - optional parameters to download a file
105
79
  * @returns {promise}
106
80
  */
107
- download: function download(scr, options) {
81
+ download: function download(fileUrl, scr, options) {
108
82
  var _this = this;
109
-
110
83
  /* istanbul ignore if */
111
- if (!scr.loc) {
112
- return _promise.default.reject(new Error('`scr.loc` is required'));
84
+ if (!fileUrl || !scr) {
85
+ return _promise.default.reject(new Error('`scr` and `fileUrl` are required'));
113
86
  }
114
-
115
87
  var shunt = new _events.EventEmitter();
116
-
117
- var promise = this._fetchDownloadUrl(scr, options).then(function (uri) {
88
+ var promise = this._fetchDownloadUrl(fileUrl, options).then(function (uri) {
89
+ // eslint-disable-next-line no-shadow
118
90
  var options = {
119
91
  method: 'GET',
120
92
  uri: uri,
121
93
  responseType: 'buffer'
122
94
  };
123
-
124
95
  var ret = _this.request(options);
125
-
126
96
  (0, _common.transferEvents)('progress', options.download, shunt);
127
97
  return ret;
128
98
  }).then(function (res) {
129
99
  return _this.decryptBinary(scr, res.body);
130
100
  });
131
-
132
101
  (0, _common.proxyEvents)(shunt, promise);
133
102
  return promise;
134
103
  },
135
-
136
104
  /**
137
105
  * Fetch Download URL for the requested file
138
- *
139
- * @param {Object} scr - Plaintext
106
+ * @param {Object} fileUrl - Plaintext
140
107
  * @param {Object} options - optional parameters to download a file
141
108
  * @returns {promise} url of the downloadable file
142
109
  */
143
- _fetchDownloadUrl: function _fetchDownloadUrl(scr, options) {
110
+ _fetchDownloadUrl: function _fetchDownloadUrl(fileUrl, options) {
144
111
  var _this2 = this;
145
-
146
112
  this.logger.info('encryption: retrieving download url for encrypted file');
147
-
148
- if (process.env.NODE_ENV !== 'production' && scr.loc.includes('localhost')) {
113
+ if (process.env.NODE_ENV !== 'production' && fileUrl.includes('localhost')) {
149
114
  this.logger.info('encryption: bypassing webex files because this looks to be a test file on localhost');
150
- return _promise.default.resolve(scr.loc);
115
+ return _promise.default.resolve(fileUrl);
151
116
  }
152
-
153
117
  var inputBody = {
154
- endpoints: [scr.loc]
118
+ endpoints: [fileUrl]
155
119
  };
120
+ var endpointUrl = _url.default.parse(fileUrl);
156
121
 
157
- var endpointUrl = _url.default.parse(scr.loc); // hardcode the url to use 'https' and the file service '/v1/download/endpoints' api
158
-
159
-
122
+ // hardcode the url to use 'https' and the file service '/v1/download/endpoints' api
160
123
  endpointUrl.protocol = 'https';
161
124
  endpointUrl.pathname = '/v1/download/endpoints';
162
125
  return this.request({
@@ -166,23 +129,24 @@ var Encryption = _webexCore.WebexPlugin.extend({
166
129
  allow: options.params.allow
167
130
  }) : inputBody
168
131
  }).then(function (res) {
169
- var url = res.body.endpoints[scr.loc];
170
-
132
+ // eslint-disable-next-line no-shadow
133
+ var url = res.body.endpoints[fileUrl];
171
134
  if (!url) {
172
- _this2.logger.warn('encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly');
173
-
174
- return scr.loc;
135
+ _this2.logger.warn('encryption: could not determine download url for `fileUrl`; attempting to download `fileUrl` directly');
136
+ return fileUrl;
175
137
  }
176
-
177
138
  _this2.logger.info('encryption: retrieved download url for encrypted file');
178
-
179
139
  return url;
140
+ }).catch(function (err) {
141
+ _this2.logger.warn("encryption: ".concat(err, " could not determine download url for ").concat(fileUrl, "; attempting to download ").concat(fileUrl, " directly"));
142
+ return fileUrl;
180
143
  });
181
144
  },
182
145
  encryptBinary: function encryptBinary(file) {
183
146
  return (0, _ensureBuffer.default)(file).then(function (buffer) {
184
147
  return _nodeScr.default.create().then(function (scr) {
185
- return scr.encrypt(buffer).then(_ensureBuffer.default) // eslint-disable-next-line max-nested-callbacks
148
+ return scr.encrypt(buffer).then(_ensureBuffer.default)
149
+ // eslint-disable-next-line max-nested-callbacks
186
150
  .then(function (cdata) {
187
151
  return {
188
152
  scr: scr,
@@ -192,7 +156,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
192
156
  });
193
157
  });
194
158
  },
195
-
196
159
  /**
197
160
  * Encrypt a SCR (Secure Content Resource) using the supplied key uri.
198
161
  *
@@ -207,12 +170,10 @@ var Encryption = _webexCore.WebexPlugin.extend({
207
170
  if (!scr.loc) {
208
171
  return _promise.default.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));
209
172
  }
210
-
211
173
  return this.getKey(key, options).then(function (k) {
212
174
  return scr.toJWE(k.jwk);
213
175
  });
214
176
  },
215
-
216
177
  /**
217
178
  * Encrypt plaintext using the supplied key uri.
218
179
  *
@@ -224,7 +185,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
224
185
  */
225
186
  encryptText: function encryptText(key, plaintext, options) {
226
187
  var _this3 = this;
227
-
228
188
  return this.getKey(key, options).then(function (k) {
229
189
  return _nodeJose.default.JWE.createEncrypt(_this3.config.joseOptions, {
230
190
  key: k.jwk,
@@ -235,7 +195,6 @@ var Encryption = _webexCore.WebexPlugin.extend({
235
195
  }).final(plaintext, 'utf8');
236
196
  });
237
197
  },
238
-
239
198
  /**
240
199
  * Fetch the key associated with the supplied KMS uri.
241
200
  *
@@ -246,20 +205,15 @@ var Encryption = _webexCore.WebexPlugin.extend({
246
205
  */
247
206
  getKey: function getKey(uri) {
248
207
  var _this4 = this;
249
-
250
208
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
251
- onBehalfOf = _ref.onBehalfOf;
252
-
209
+ onBehalfOf = _ref.onBehalfOf;
253
210
  if (uri.jwk) {
254
211
  return this.kms.asKey(uri);
255
212
  }
256
-
257
213
  var storageKey = uri;
258
-
259
214
  if (onBehalfOf) {
260
215
  storageKey += "/onBehalfOf/".concat(onBehalfOf);
261
216
  }
262
-
263
217
  return this.unboundedStorage.get(storageKey).then(function (keyString) {
264
218
  return JSON.parse(keyString);
265
219
  }).then(function (keyObject) {
@@ -273,16 +227,15 @@ var Encryption = _webexCore.WebexPlugin.extend({
273
227
  }));
274
228
  });
275
229
  },
276
- version: "3.0.0-beta.4"
230
+ version: "3.0.0-beta.400"
277
231
  });
232
+
278
233
  /**
279
234
  * JSON.stringify replacer that ensures private key data is serialized.
280
235
  * @param {string} k
281
236
  * @param {mixed} v
282
237
  * @returns {mixed}
283
238
  */
284
-
285
-
286
239
  function replacer(k, v) {
287
240
  if (k === 'jwk') {
288
241
  // note: this[k] and v may be different representations of the same value
@@ -290,10 +243,8 @@ function replacer(k, v) {
290
243
  var json = this[k].toJSON(true);
291
244
  return json;
292
245
  }
293
-
294
246
  return v;
295
247
  }
296
-
297
248
  var _default = Encryption;
298
249
  exports.default = _default;
299
250
  //# sourceMappingURL=encryption.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Encryption","WebexPlugin","extend","children","kms","KMS","namespace","processKmsMessageEvent","event","decryptBinary","scr","buffer","ensureBuffer","then","b","length","byteLength","reject","Error","decrypt","decryptScr","key","cipherScr","options","getKey","k","SCR","fromJWE","jwk","decryptText","ciphertext","jose","JWE","createDecrypt","result","plaintext","toString","download","loc","shunt","EventEmitter","promise","_fetchDownloadUrl","uri","method","responseType","ret","request","transferEvents","res","body","proxyEvents","logger","info","process","env","NODE_ENV","includes","resolve","inputBody","endpoints","endpointUrl","url","parse","protocol","pathname","format","allow","params","warn","encryptBinary","file","create","encrypt","cdata","encryptScr","toJWE","encryptText","createEncrypt","config","joseOptions","header","alg","reference","final","onBehalfOf","asKey","storageKey","unboundedStorage","get","keyString","JSON","keyObject","catch","fetchKey","tap","put","replacer","v","json","toJSON"],"sources":["encryption.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {EventEmitter} from 'events';\nimport url from 'url';\n\nimport {WebexPlugin} from '@webex/webex-core';\nimport {proxyEvents, tap, transferEvents} from '@webex/common';\nimport jose from 'node-jose';\nimport SCR from 'node-scr';\n\nimport ensureBuffer from './ensure-buffer';\nimport KMS from './kms';\n\nconst Encryption = WebexPlugin.extend({\n children: {\n kms: KMS\n },\n\n namespace: 'Encryption',\n\n processKmsMessageEvent(event) {\n return this.kms.processKmsMessageEvent(event);\n },\n\n decryptBinary(scr, buffer) {\n return ensureBuffer(buffer)\n .then((b) => {\n /* istanbul ignore if */\n if (buffer.length === 0 || buffer.byteLength === 0) {\n return Promise.reject(new Error('Attempted to decrypt zero-length buffer'));\n }\n\n return scr.decrypt(b);\n });\n },\n\n /**\n * Decrypt a SCR (Secure Content Resource) using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {Object} cipherScr - An encrypted SCR\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {Object} Decrypted SCR\n */\n decryptScr(key, cipherScr, options) {\n return this.getKey(key, options)\n .then((k) => SCR.fromJWE(k.jwk, cipherScr));\n },\n\n /**\n * Decrypt text using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {string} ciphertext - Encrypted text\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Decrypted plaintext\n */\n decryptText(key, ciphertext, options) {\n return this.getKey(key, options)\n .then((k) => jose.JWE\n .createDecrypt(k.jwk)\n .decrypt(ciphertext)\n .then((result) => result.plaintext.toString()));\n },\n\n /**\n * Validate and initiate a Download request for requested file\n *\n * @param {Object} scr - Plaintext\n * @param {Object} options - optional parameters to download a file\n * @returns {promise}\n */\n download(scr, options) {\n /* istanbul ignore if */\n if (!scr.loc) {\n return Promise.reject(new Error('`scr.loc` is required'));\n }\n\n const shunt = new EventEmitter();\n const promise = this._fetchDownloadUrl(scr, options)\n .then((uri) => {\n const options = {\n method: 'GET',\n uri,\n responseType: 'buffer'\n };\n\n const ret = this.request(options);\n\n transferEvents('progress', options.download, shunt);\n\n return ret;\n })\n .then((res) => this.decryptBinary(scr, res.body));\n\n proxyEvents(shunt, promise);\n\n return promise;\n },\n\n /**\n * Fetch Download URL for the requested file\n *\n * @param {Object} scr - Plaintext\n * @param {Object} options - optional parameters to download a file\n * @returns {promise} url of the downloadable file\n */\n _fetchDownloadUrl(scr, options) {\n this.logger.info('encryption: retrieving download url for encrypted file');\n\n if (process.env.NODE_ENV !== 'production' && scr.loc.includes('localhost')) {\n this.logger.info('encryption: bypassing webex files because this looks to be a test file on localhost');\n\n return Promise.resolve(scr.loc);\n }\n\n const inputBody = {\n endpoints: [scr.loc]\n };\n const endpointUrl = url.parse(scr.loc);\n\n // hardcode the url to use 'https' and the file service '/v1/download/endpoints' api\n endpointUrl.protocol = 'https';\n endpointUrl.pathname = '/v1/download/endpoints';\n\n return this.request({\n method: 'POST',\n uri: url.format(endpointUrl),\n body: options ? {\n ...inputBody,\n allow: options.params.allow\n } : inputBody\n })\n .then((res) => {\n const url = res.body.endpoints[scr.loc];\n\n if (!url) {\n this.logger.warn('encryption: could not determine download url for `scr.loc`; attempting to download `scr.loc` directly');\n\n return scr.loc;\n }\n this.logger.info('encryption: retrieved download url for encrypted file');\n\n return url;\n });\n },\n\n encryptBinary(file) {\n return ensureBuffer(file)\n .then((buffer) => SCR.create()\n .then((scr) => scr.encrypt(buffer)\n .then(ensureBuffer)\n // eslint-disable-next-line max-nested-callbacks\n .then((cdata) => ({scr, cdata}))));\n },\n\n /**\n * Encrypt a SCR (Secure Content Resource) using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {Object} scr - Plaintext\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Encrypted SCR\n */\n encryptScr(key, scr, options) {\n /* istanbul ignore if */\n if (!scr.loc) {\n return Promise.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));\n }\n\n return this.getKey(key, options)\n .then((k) => scr.toJWE(k.jwk));\n },\n\n /**\n * Encrypt plaintext using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {string} plaintext\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Encrypted text\n */\n encryptText(key, plaintext, options) {\n return this.getKey(key, options)\n .then((k) => jose.JWE\n .createEncrypt(this.config.joseOptions, {\n key: k.jwk,\n header: {\n alg: 'dir'\n },\n reference: null\n })\n .final(plaintext, 'utf8'));\n },\n\n /**\n * Fetch the key associated with the supplied KMS uri.\n *\n * @param {string} uri - The uri of a key stored in KMS\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Key\n */\n getKey(uri, {onBehalfOf} = {}) {\n if (uri.jwk) {\n return this.kms.asKey(uri);\n }\n\n let storageKey = uri;\n\n if (onBehalfOf) {\n storageKey += `/onBehalfOf/${onBehalfOf}`;\n }\n\n return this.unboundedStorage.get(storageKey)\n .then((keyString) => JSON.parse(keyString))\n .then((keyObject) => this.kms.asKey(keyObject))\n .catch(() => this.kms.fetchKey({uri, onBehalfOf})\n .then(tap((key) => this.unboundedStorage.put(storageKey, JSON.stringify(key, replacer)))));\n }\n});\n\n/**\n * JSON.stringify replacer that ensures private key data is serialized.\n * @param {string} k\n * @param {mixed} v\n * @returns {mixed}\n */\nfunction replacer(k, v) {\n if (k === 'jwk') {\n // note: this[k] and v may be different representations of the same value\n // eslint-disable-next-line no-invalid-this\n const json = this[k].toJSON(true);\n\n return json;\n }\n\n return v;\n}\n\nexport default Encryption;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;AAEA,IAAMA,UAAU,GAAGC,sBAAA,CAAYC,MAAZ,CAAmB;EACpCC,QAAQ,EAAE;IACRC,GAAG,EAAEC;EADG,CAD0B;EAKpCC,SAAS,EAAE,YALyB;EAOpCC,sBAPoC,kCAObC,KAPa,EAON;IAC5B,OAAO,KAAKJ,GAAL,CAASG,sBAAT,CAAgCC,KAAhC,CAAP;EACD,CATmC;EAWpCC,aAXoC,yBAWtBC,GAXsB,EAWjBC,MAXiB,EAWT;IACzB,OAAO,IAAAC,qBAAA,EAAaD,MAAb,EACJE,IADI,CACC,UAACC,CAAD,EAAO;MACX;MACA,IAAIH,MAAM,CAACI,MAAP,KAAkB,CAAlB,IAAuBJ,MAAM,CAACK,UAAP,KAAsB,CAAjD,EAAoD;QAClD,OAAO,iBAAQC,MAAR,CAAe,IAAIC,KAAJ,CAAU,yCAAV,CAAf,CAAP;MACD;;MAED,OAAOR,GAAG,CAACS,OAAJ,CAAYL,CAAZ,CAAP;IACD,CARI,CAAP;EASD,CArBmC;;EAuBpC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEM,UAhCoC,sBAgCzBC,GAhCyB,EAgCpBC,SAhCoB,EAgCTC,OAhCS,EAgCA;IAClC,OAAO,KAAKC,MAAL,CAAYH,GAAZ,EAAiBE,OAAjB,EACJV,IADI,CACC,UAACY,CAAD;MAAA,OAAOC,gBAAA,CAAIC,OAAJ,CAAYF,CAAC,CAACG,GAAd,EAAmBN,SAAnB,CAAP;IAAA,CADD,CAAP;EAED,CAnCmC;;EAqCpC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEO,WA9CoC,uBA8CxBR,GA9CwB,EA8CnBS,UA9CmB,E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;AACA;AACA;;;AACA,SAASA,QAAT,CAAkBxE,CAAlB,EAAqByE,CAArB,EAAwB;EACtB,IAAIzE,CAAC,KAAK,KAAV,EAAiB;IACf;IACA;IACA,IAAM0E,IAAI,GAAG,KAAK1E,CAAL,EAAQ2E,MAAR,CAAe,IAAf,CAAb;IAEA,OAAOD,IAAP;EACD;;EAED,OAAOD,CAAP;AACD;;eAEclG,U"}
1
+ {"version":3,"names":["Encryption","WebexPlugin","extend","children","kms","KMS","namespace","processKmsMessageEvent","event","decryptBinary","scr","buffer","ensureBuffer","then","b","length","byteLength","reject","Error","decrypt","decryptScr","key","cipherScr","options","getKey","k","SCR","fromJWE","jwk","decryptText","ciphertext","jose","JWE","createDecrypt","result","plaintext","toString","download","fileUrl","shunt","EventEmitter","promise","_fetchDownloadUrl","uri","method","responseType","ret","request","transferEvents","res","body","proxyEvents","logger","info","process","env","NODE_ENV","includes","resolve","inputBody","endpoints","endpointUrl","url","parse","protocol","pathname","format","allow","params","warn","catch","err","encryptBinary","file","create","encrypt","cdata","encryptScr","loc","toJWE","encryptText","createEncrypt","config","joseOptions","header","alg","reference","final","onBehalfOf","asKey","storageKey","unboundedStorage","get","keyString","JSON","keyObject","fetchKey","tap","put","replacer","v","json","toJSON"],"sources":["encryption.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {EventEmitter} from 'events';\nimport url from 'url';\n\nimport {WebexPlugin} from '@webex/webex-core';\nimport {proxyEvents, tap, transferEvents} from '@webex/common';\nimport jose from 'node-jose';\nimport SCR from 'node-scr';\n\nimport ensureBuffer from './ensure-buffer';\nimport KMS from './kms';\n\nconst Encryption = WebexPlugin.extend({\n children: {\n kms: KMS,\n },\n\n namespace: 'Encryption',\n\n processKmsMessageEvent(event) {\n return this.kms.processKmsMessageEvent(event);\n },\n\n decryptBinary(scr, buffer) {\n return ensureBuffer(buffer).then((b) => {\n /* istanbul ignore if */\n if (buffer.length === 0 || buffer.byteLength === 0) {\n return Promise.reject(new Error('Attempted to decrypt zero-length buffer'));\n }\n\n return scr.decrypt(b);\n });\n },\n\n /**\n * Decrypt a SCR (Secure Content Resource) using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {Object} cipherScr - An encrypted SCR\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {Object} Decrypted SCR\n */\n decryptScr(key, cipherScr, options) {\n return this.getKey(key, options).then((k) => SCR.fromJWE(k.jwk, cipherScr));\n },\n\n /**\n * Decrypt text using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {string} ciphertext - Encrypted text\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Decrypted plaintext\n */\n decryptText(key, ciphertext, options) {\n return this.getKey(key, options).then((k) =>\n jose.JWE.createDecrypt(k.jwk)\n .decrypt(ciphertext)\n .then((result) => result.plaintext.toString())\n );\n },\n\n /**\n * Validate and initiate a Download request for requested file\n * @param {Object} fileUrl - Plaintext\n * @param {Object} scr - Plaintext\n * @param {Object} options - optional parameters to download a file\n * @returns {promise}\n */\n download(fileUrl, scr, options) {\n /* istanbul ignore if */\n if (!fileUrl || !scr) {\n return Promise.reject(new Error('`scr` and `fileUrl` are required'));\n }\n\n const shunt = new EventEmitter();\n const promise = this._fetchDownloadUrl(fileUrl, options)\n .then((uri) => {\n // eslint-disable-next-line no-shadow\n const options = {\n method: 'GET',\n uri,\n responseType: 'buffer',\n };\n\n const ret = this.request(options);\n\n transferEvents('progress', options.download, shunt);\n\n return ret;\n })\n .then((res) => this.decryptBinary(scr, res.body));\n\n proxyEvents(shunt, promise);\n\n return promise;\n },\n\n /**\n * Fetch Download URL for the requested file\n * @param {Object} fileUrl - Plaintext\n * @param {Object} options - optional parameters to download a file\n * @returns {promise} url of the downloadable file\n */\n _fetchDownloadUrl(fileUrl, options) {\n this.logger.info('encryption: retrieving download url for encrypted file');\n\n if (process.env.NODE_ENV !== 'production' && fileUrl.includes('localhost')) {\n this.logger.info(\n 'encryption: bypassing webex files because this looks to be a test file on localhost'\n );\n\n return Promise.resolve(fileUrl);\n }\n\n const inputBody = {\n endpoints: [fileUrl],\n };\n const endpointUrl = url.parse(fileUrl);\n\n // hardcode the url to use 'https' and the file service '/v1/download/endpoints' api\n endpointUrl.protocol = 'https';\n endpointUrl.pathname = '/v1/download/endpoints';\n\n return this.request({\n method: 'POST',\n uri: url.format(endpointUrl),\n body: options\n ? {\n ...inputBody,\n allow: options.params.allow,\n }\n : inputBody,\n })\n .then((res) => {\n // eslint-disable-next-line no-shadow\n const url = res.body.endpoints[fileUrl];\n\n if (!url) {\n this.logger.warn(\n 'encryption: could not determine download url for `fileUrl`; attempting to download `fileUrl` directly'\n );\n\n return fileUrl;\n }\n this.logger.info('encryption: retrieved download url for encrypted file');\n\n return url;\n })\n .catch((err) => {\n this.logger.warn(\n `encryption: ${err} could not determine download url for ${fileUrl}; attempting to download ${fileUrl} directly`\n );\n\n return fileUrl;\n });\n },\n\n encryptBinary(file) {\n return ensureBuffer(file).then((buffer) =>\n SCR.create().then((scr) =>\n scr\n .encrypt(buffer)\n .then(ensureBuffer)\n // eslint-disable-next-line max-nested-callbacks\n .then((cdata) => ({scr, cdata}))\n )\n );\n },\n\n /**\n * Encrypt a SCR (Secure Content Resource) using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {Object} scr - Plaintext\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Encrypted SCR\n */\n encryptScr(key, scr, options) {\n /* istanbul ignore if */\n if (!scr.loc) {\n return Promise.reject(new Error('Cannot encrypt `scr` without first setting `loc`'));\n }\n\n return this.getKey(key, options).then((k) => scr.toJWE(k.jwk));\n },\n\n /**\n * Encrypt plaintext using the supplied key uri.\n *\n * @param {string} key - The uri of a key stored in KMS\n * @param {string} plaintext\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Encrypted text\n */\n encryptText(key, plaintext, options) {\n return this.getKey(key, options).then((k) =>\n jose.JWE.createEncrypt(this.config.joseOptions, {\n key: k.jwk,\n header: {\n alg: 'dir',\n },\n reference: null,\n }).final(plaintext, 'utf8')\n );\n },\n\n /**\n * Fetch the key associated with the supplied KMS uri.\n *\n * @param {string} uri - The uri of a key stored in KMS\n * @param {Object} options\n * @param {string} options.onBehalfOf - Fetch the KMS key on behalf of another user (using the user's UUID), active user requires the 'spark.kms_orgagent' role\n * @returns {string} Key\n */\n getKey(uri, {onBehalfOf} = {}) {\n if (uri.jwk) {\n return this.kms.asKey(uri);\n }\n\n let storageKey = uri;\n\n if (onBehalfOf) {\n storageKey += `/onBehalfOf/${onBehalfOf}`;\n }\n\n return this.unboundedStorage\n .get(storageKey)\n .then((keyString) => JSON.parse(keyString))\n .then((keyObject) => this.kms.asKey(keyObject))\n .catch(() =>\n this.kms\n .fetchKey({uri, onBehalfOf})\n .then(tap((key) => this.unboundedStorage.put(storageKey, JSON.stringify(key, replacer))))\n );\n },\n});\n\n/**\n * JSON.stringify replacer that ensures private key data is serialized.\n * @param {string} k\n * @param {mixed} v\n * @returns {mixed}\n */\nfunction replacer(k, v) {\n if (k === 'jwk') {\n // note: this[k] and v may be different representations of the same value\n // eslint-disable-next-line no-invalid-this\n const json = this[k].toJSON(true);\n\n return json;\n }\n\n return v;\n}\n\nexport default Encryption;\n"],"mappings":";;;;;;;;;;;;;;;;AAIA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AAAwB;AAAA;AAExB,IAAMA,UAAU,GAAGC,sBAAW,CAACC,MAAM,CAAC;EACpCC,QAAQ,EAAE;IACRC,GAAG,EAAEC;EACP,CAAC;EAEDC,SAAS,EAA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AAE;MACX,OAAO,IAAI,CAACxB,GAAG,CAACqF,KAAK,CAAC9C,GAAG,CAAC;IAC5B;IAEA,IAAI+C,UAAU,GAAG/C,GAAG;IAEpB,IAAI6C,UAAU,EAAE;MACdE,UAAU,0BAAmBF,UAAU,CAAE;IAC3C;IAEA,OAAO,IAAI,CAACG,gBAAgB,CACzBC,GAAG,CAACF,UAAU,CAAC,CACf7E,IAAI,CAAC,UAACgF,SAAS;MAAA,OAAKC,IAAI,CAAC/B,KAAK,CAAC8B,SAAS,CAAC;IAAA,EAAC,CAC1ChF,IAAI,CAAC,UAACkF,SAAS;MAAA,OAAK,MAAI,CAAC3F,GAAG,CAACqF,KAAK,CAACM,SAAS,CAAC;IAAA,EAAC,CAC9CzB,KAAK,CAAC;MAAA,OACL,MAAI,CAAClE,GAAG,CACL4F,QAAQ,CAAC;QAACrD,GAAG,EAAHA,GAAG;QAAE6C,UAAU,EAAVA;MAAU,CAAC,CAAC,CAC3B3E,IAAI,CAAC,IAAAoF,WAAG,EAAC,UAAC5E,GAAG;QAAA,OAAK,MAAI,CAACsE,gBAAgB,CAACO,GAAG,CAACR,UAAU,EAAE,wBAAerE,GAAG,EAAE8E,QAAQ,CAAC,CAAC;MAAA,EAAC,CAAC;IAAA,EAC5F;EACL,CAAC;EAAA;AACH,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAQ,CAAC1E,CAAC,EAAE2E,CAAC,EAAE;EACtB,IAAI3E,CAAC,KAAK,KAAK,EAAE;IACf;IACA;IACA,IAAM4E,IAAI,GAAG,IAAI,CAAC5E,CAAC,CAAC,CAAC6E,MAAM,CAAC,IAAI,CAAC;IAEjC,OAAOD,IAAI;EACb;EAEA,OAAOD,CAAC;AACV;AAAC,eAEcpG,UAAU;AAAA"}
@@ -1,25 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
6
-
7
5
  _Object$defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
-
11
8
  exports.default = ensureBuffer;
12
-
13
9
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
14
-
15
10
  /*!
16
11
  * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
17
12
  */
18
13
 
19
14
  /* eslint-env: browser */
20
15
 
21
- /* global FileReader */
22
-
23
16
  /**
24
17
  * Ensures the provider buffer is, indeed, an ArrayBuffer; converts File and
25
18
  * Blob objects to ArrayBuffers.
@@ -30,22 +23,17 @@ function ensureBuffer(buffer) {
30
23
  if (buffer instanceof ArrayBuffer) {
31
24
  return _promise.default.resolve(buffer);
32
25
  }
33
-
34
26
  if (buffer.toArrayBuffer) {
35
27
  return _promise.default.resolve(buffer.toArrayBuffer());
36
28
  }
37
-
38
29
  if (buffer.buffer) {
39
30
  return _promise.default.resolve(buffer.buffer);
40
31
  }
41
-
42
32
  return new _promise.default(function (resolve, reject) {
43
33
  var fr = new FileReader();
44
-
45
34
  fr.onload = function onload() {
46
35
  resolve(new Uint8Array(this.result));
47
36
  };
48
-
49
37
  fr.onerror = reject;
50
38
  fr.readAsArrayBuffer(buffer);
51
39
  });
@@ -1 +1 @@
1
- {"version":3,"names":["ensureBuffer","buffer","ArrayBuffer","resolve","toArrayBuffer","reject","fr","FileReader","onload","Uint8Array","result","onerror","readAsArrayBuffer"],"sources":["ensure-buffer.browser.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env: browser */\n/* global FileReader */\n\n/**\n * Ensures the provider buffer is, indeed, an ArrayBuffer; converts File and\n * Blob objects to ArrayBuffers.\n * @param {mixed} buffer\n * @returns {Promise<ArrayBuffer>}\n */\nexport default function ensureBuffer(buffer) {\n if (buffer instanceof ArrayBuffer) {\n return Promise.resolve(buffer);\n }\n\n if (buffer.toArrayBuffer) {\n return Promise.resolve(buffer.toArrayBuffer());\n }\n\n if (buffer.buffer) {\n return Promise.resolve(buffer.buffer);\n }\n\n return new Promise((resolve, reject) => {\n const fr = new FileReader();\n\n fr.onload = function onload() {\n resolve(new Uint8Array(this.result));\n };\n\n fr.onerror = reject;\n\n fr.readAsArrayBuffer(buffer);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAT,CAAsBC,MAAtB,EAA8B;EAC3C,IAAIA,MAAM,YAAYC,WAAtB,EAAmC;IACjC,OAAO,iBAAQC,OAAR,CAAgBF,MAAhB,CAAP;EACD;;EAED,IAAIA,MAAM,CAACG,aAAX,EAA0B;IACxB,OAAO,iBAAQD,OAAR,CAAgBF,MAAM,CAACG,aAAP,EAAhB,CAAP;EACD;;EAED,IAAIH,MAAM,CAACA,MAAX,EAAmB;IACjB,OAAO,iBAAQE,OAAR,CAAgBF,MAAM,CAACA,MAAvB,CAAP;EACD;;EAED,OAAO,qBAAY,UAACE,OAAD,EAAUE,MAAV,EAAqB;IACtC,IAAMC,EAAE,GAAG,IAAIC,UAAJ,EAAX;;IAEAD,EAAE,CAACE,MAAH,GAAY,SAASA,MAAT,GAAkB;MAC5BL,OAAO,CAAC,IAAIM,UAAJ,CAAe,KAAKC,MAApB,CAAD,CAAP;IACD,CAFD;;IAIAJ,EAAE,CAACK,OAAH,GAAaN,MAAb;IAEAC,EAAE,CAACM,iBAAH,CAAqBX,MAArB;EACD,CAVM,CAAP;AAWD"}
1
+ {"version":3,"names":["ensureBuffer","buffer","ArrayBuffer","resolve","toArrayBuffer","reject","fr","FileReader","onload","Uint8Array","result","onerror","readAsArrayBuffer"],"sources":["ensure-buffer.browser.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env: browser */\n\n/**\n * Ensures the provider buffer is, indeed, an ArrayBuffer; converts File and\n * Blob objects to ArrayBuffers.\n * @param {mixed} buffer\n * @returns {Promise<ArrayBuffer>}\n */\nexport default function ensureBuffer(buffer) {\n if (buffer instanceof ArrayBuffer) {\n return Promise.resolve(buffer);\n }\n\n if (buffer.toArrayBuffer) {\n return Promise.resolve(buffer.toArrayBuffer());\n }\n\n if (buffer.buffer) {\n return Promise.resolve(buffer.buffer);\n }\n\n return new Promise((resolve, reject) => {\n const fr = new FileReader();\n\n fr.onload = function onload() {\n resolve(new Uint8Array(this.result));\n };\n\n fr.onerror = reject;\n\n fr.readAsArrayBuffer(buffer);\n });\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAY,CAACC,MAAM,EAAE;EAC3C,IAAIA,MAAM,YAAYC,WAAW,EAAE;IACjC,OAAO,iBAAQC,OAAO,CAACF,MAAM,CAAC;EAChC;EAEA,IAAIA,MAAM,CAACG,aAAa,EAAE;IACxB,OAAO,iBAAQD,OAAO,CAACF,MAAM,CAACG,aAAa,EAAE,CAAC;EAChD;EAEA,IAAIH,MAAM,CAACA,MAAM,EAAE;IACjB,OAAO,iBAAQE,OAAO,CAACF,MAAM,CAACA,MAAM,CAAC;EACvC;EAEA,OAAO,qBAAY,UAACE,OAAO,EAAEE,MAAM,EAAK;IACtC,IAAMC,EAAE,GAAG,IAAIC,UAAU,EAAE;IAE3BD,EAAE,CAACE,MAAM,GAAG,SAASA,MAAM,GAAG;MAC5BL,OAAO,CAAC,IAAIM,UAAU,CAAC,IAAI,CAACC,MAAM,CAAC,CAAC;IACtC,CAAC;IAEDJ,EAAE,CAACK,OAAO,GAAGN,MAAM;IAEnBC,EAAE,CAACM,iBAAiB,CAACX,MAAM,CAAC;EAC9B,CAAC,CAAC;AACJ"}
@@ -1,35 +1,28 @@
1
1
  "use strict";
2
2
 
3
3
  var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
6
-
7
5
  _Object$defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
-
11
8
  exports.default = ensureBuffer;
12
-
13
9
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
14
-
15
10
  var _common = require("@webex/common");
16
-
17
11
  /*!
18
12
  * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
19
13
  */
20
14
 
21
15
  /**
22
- * Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be
23
- * byte-arrays instead of proper Buffer objects.
24
- * @param {mixed} buffer
25
- * @returns {Promise<Buffer>}
26
- */
16
+ * Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be
17
+ * byte-arrays instead of proper Buffer objects.
18
+ * @param {mixed} buffer
19
+ * @returns {Promise<Buffer>}
20
+ */
27
21
  function ensureBuffer(buffer) {
28
22
  /* istanbul ignore if */
29
23
  if (!(0, _common.isBuffer)(buffer)) {
30
24
  return _promise.default.reject(new Error('`buffer` must be a buffer'));
31
25
  }
32
-
33
26
  return _promise.default.resolve(buffer);
34
27
  }
35
28
  //# sourceMappingURL=ensure-buffer.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ensureBuffer","buffer","isBuffer","reject","Error","resolve"],"sources":["ensure-buffer.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {isBuffer} from '@webex/common';\n\n/**\n* Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be\n* byte-arrays instead of proper Buffer objects.\n* @param {mixed} buffer\n* @returns {Promise<Buffer>}\n*/\nexport default function ensureBuffer(buffer) {\n /* istanbul ignore if */\n if (!isBuffer(buffer)) {\n return Promise.reject(new Error('`buffer` must be a buffer'));\n }\n\n return Promise.resolve(buffer);\n}\n"],"mappings":";;;;;;;;;;;;;;AAIA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAT,CAAsBC,MAAtB,EAA8B;EAC3C;EACA,IAAI,CAAC,IAAAC,gBAAA,EAASD,MAAT,CAAL,EAAuB;IACrB,OAAO,iBAAQE,MAAR,CAAe,IAAIC,KAAJ,CAAU,2BAAV,CAAf,CAAP;EACD;;EAED,OAAO,iBAAQC,OAAR,CAAgBJ,MAAhB,CAAP;AACD"}
1
+ {"version":3,"names":["ensureBuffer","buffer","isBuffer","reject","Error","resolve"],"sources":["ensure-buffer.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {isBuffer} from '@webex/common';\n\n/**\n * Ensures the provider Buffer is, indeed, a Buffer; sometimes, they seem to be\n * byte-arrays instead of proper Buffer objects.\n * @param {mixed} buffer\n * @returns {Promise<Buffer>}\n */\nexport default function ensureBuffer(buffer) {\n /* istanbul ignore if */\n if (!isBuffer(buffer)) {\n return Promise.reject(new Error('`buffer` must be a buffer'));\n }\n\n return Promise.resolve(buffer);\n}\n"],"mappings":";;;;;;;;;AAIA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAY,CAACC,MAAM,EAAE;EAC3C;EACA,IAAI,CAAC,IAAAC,gBAAQ,EAACD,MAAM,CAAC,EAAE;IACrB,OAAO,iBAAQE,MAAM,CAAC,IAAIC,KAAK,CAAC,2BAA2B,CAAC,CAAC;EAC/D;EAEA,OAAO,iBAAQC,OAAO,CAACJ,MAAM,CAAC;AAChC"}