@eluvio/elv-client-js 4.0.5 → 4.0.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.
Files changed (43) hide show
  1. package/dist/ElvClient-min.js +12 -11
  2. package/dist/ElvClient-node-min.js +12 -11
  3. package/dist/ElvFrameClient-min.js +12 -11
  4. package/dist/ElvPermissionsClient-min.js +10 -9
  5. package/dist/ElvWalletClient-min.js +12 -11
  6. package/dist/ElvWalletClient-node-min.js +11 -10
  7. package/dist/src/AuthorizationClient.js +1556 -2077
  8. package/dist/src/ContentObjectVerification.js +134 -185
  9. package/dist/src/Crypto.js +225 -322
  10. package/dist/src/ElvClient.js +823 -1117
  11. package/dist/src/ElvWallet.js +64 -106
  12. package/dist/src/EthClient.js +719 -974
  13. package/dist/src/FrameClient.js +222 -318
  14. package/dist/src/HttpClient.js +112 -154
  15. package/dist/src/Id.js +1 -6
  16. package/dist/src/LogMessage.js +4 -8
  17. package/dist/src/PermissionsClient.js +973 -1271
  18. package/dist/src/RemoteSigner.js +161 -232
  19. package/dist/src/UserProfileClient.js +781 -1038
  20. package/dist/src/Utils.js +160 -302
  21. package/dist/src/Validation.js +2 -17
  22. package/dist/src/client/ABRPublishing.js +772 -942
  23. package/dist/src/client/AccessGroups.js +849 -1095
  24. package/dist/src/client/ContentAccess.js +3263 -4132
  25. package/dist/src/client/ContentManagement.js +1811 -2283
  26. package/dist/src/client/Contracts.js +468 -614
  27. package/dist/src/client/Files.js +1505 -1845
  28. package/dist/src/client/NFT.js +94 -116
  29. package/dist/src/client/NTP.js +326 -425
  30. package/dist/src/index.js +2 -5
  31. package/dist/src/walletClient/ClientMethods.js +1348 -1735
  32. package/dist/src/walletClient/Configuration.js +4 -2
  33. package/dist/src/walletClient/Notifications.js +98 -127
  34. package/dist/src/walletClient/Profile.js +184 -246
  35. package/dist/src/walletClient/Utils.js +76 -122
  36. package/dist/src/walletClient/index.js +1168 -1493
  37. package/package.json +2 -2
  38. package/src/Crypto.js +1 -1
  39. package/src/ElvClient.js +1 -3
  40. package/src/Utils.js +1 -1
  41. package/testScripts/Test.js +0 -1
  42. package/utilities/NFTIngest.js +527 -0
  43. package/utilities/lib/concerns/LocalFile.js +2 -1
@@ -1,92 +1,67 @@
1
1
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
2
-
3
2
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
4
-
5
- if (typeof Buffer === "undefined") {
6
- Buffer = require("buffer/").Buffer;
7
- }
8
-
3
+ var Buffer = require("buffer/").Buffer;
9
4
  var bs58 = require("bs58");
10
-
11
5
  var Stream = require("stream");
12
-
13
6
  var Utils = require("./Utils");
14
-
15
7
  if (typeof crypto === "undefined") {
16
8
  var _crypto = require("crypto");
17
-
18
9
  _crypto.getRandomValues = function (arr) {
19
10
  return _crypto.randomBytes(arr.length);
20
11
  };
21
-
22
12
  global.crypto = _crypto;
23
13
  }
24
-
25
14
  var _ElvCrypto;
26
-
27
15
  switch (Utils.Platform()) {
28
16
  case Utils.PLATFORM_REACT_NATIVE:
29
17
  _ElvCrypto = require("@eluvio/crypto/dist/elv-crypto.bundle.externals")["default"];
30
18
  break;
31
-
32
19
  case Utils.PLATFORM_WEB:
33
20
  _ElvCrypto = require("@eluvio/crypto/dist/elv-crypto.bundle.externals")["default"];
34
21
  break;
35
-
36
22
  default:
37
23
  _ElvCrypto = require("@eluvio/crypto/dist/elv-crypto.bundle.node")["default"];
38
24
  break;
39
25
  }
26
+
40
27
  /**
41
28
  * @namespace
42
29
  * @description This namespace contains cryptographic helper methods to encrypt and decrypt
43
30
  * data with automatic handling of keys
44
31
  */
45
-
46
-
47
32
  var Crypto = {
48
33
  ElvCrypto: function () {
49
34
  var _ElvCrypto2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
50
35
  return _regeneratorRuntime.wrap(function _callee$(_context) {
51
- while (1) {
52
- switch (_context.prev = _context.next) {
53
- case 0:
54
- _context.prev = 0;
55
-
56
- if (Crypto.elvCrypto) {
57
- _context.next = 5;
58
- break;
59
- }
60
-
61
- _context.next = 4;
62
- return new _ElvCrypto().init();
63
-
64
- case 4:
65
- Crypto.elvCrypto = _context.sent;
66
-
67
- case 5:
68
- return _context.abrupt("return", Crypto.elvCrypto);
69
-
70
- case 8:
71
- _context.prev = 8;
72
- _context.t0 = _context["catch"](0);
73
- // eslint-disable-next-line no-console
74
- console.error("Error initializing ElvCrypto:"); // eslint-disable-next-line no-console
75
-
76
- console.error(_context.t0);
77
-
78
- case 12:
79
- case "end":
80
- return _context.stop();
81
- }
36
+ while (1) switch (_context.prev = _context.next) {
37
+ case 0:
38
+ _context.prev = 0;
39
+ if (Crypto.elvCrypto) {
40
+ _context.next = 5;
41
+ break;
42
+ }
43
+ _context.next = 4;
44
+ return new _ElvCrypto().init();
45
+ case 4:
46
+ Crypto.elvCrypto = _context.sent;
47
+ case 5:
48
+ return _context.abrupt("return", Crypto.elvCrypto);
49
+ case 8:
50
+ _context.prev = 8;
51
+ _context.t0 = _context["catch"](0);
52
+ // eslint-disable-next-line no-console
53
+ console.error("Error initializing ElvCrypto:");
54
+ // eslint-disable-next-line no-console
55
+ console.error(_context.t0);
56
+ case 12:
57
+ case "end":
58
+ return _context.stop();
82
59
  }
83
60
  }, _callee, null, [[0, 8]]);
84
61
  }));
85
-
86
62
  function ElvCrypto() {
87
63
  return _ElvCrypto2.apply(this, arguments);
88
64
  }
89
-
90
65
  return ElvCrypto;
91
66
  }(),
92
67
  EncryptedSize: function EncryptedSize(clearSize) {
@@ -94,11 +69,9 @@ var Crypto = {
94
69
  var blocks = Math.floor(clearSize / clearBlockSize);
95
70
  var encryptedBlockSize = Crypto.EncryptedBlockSize(clearBlockSize);
96
71
  var encryptedFileSize = blocks * encryptedBlockSize;
97
-
98
72
  if (clearSize % clearBlockSize !== 0) {
99
73
  encryptedFileSize += Crypto.EncryptedBlockSize(clearSize % clearBlockSize);
100
74
  }
101
-
102
75
  return encryptedFileSize;
103
76
  },
104
77
  EncryptedBlockSize: function EncryptedBlockSize(clearSize) {
@@ -109,43 +82,35 @@ var Crypto = {
109
82
  var clearElementByteSize = 12 * (MODBYTES_384_58 - 1);
110
83
  var encElementByteSize = 12 * MODBYTES_384_58;
111
84
  var encryptedBlockSize = Math.floor(clearSize / clearElementByteSize) * encElementByteSize;
112
-
113
85
  if (clearSize % clearElementByteSize !== 0) {
114
86
  encryptedBlockSize += encElementByteSize;
115
87
  }
116
-
117
88
  return reencrypt ? encryptedBlockSize + targetEncBlockOverhead : encryptedBlockSize + primaryEncBlockOverhead;
118
89
  },
119
90
  EncryptConk: function EncryptConk(conk, publicKey) {
120
91
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
121
92
  var elvCrypto, _yield$elvCrypto$encr, data, ephemeralKey, tag, cap;
122
-
123
93
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
124
- while (1) {
125
- switch (_context2.prev = _context2.next) {
126
- case 0:
127
- _context2.next = 2;
128
- return Crypto.ElvCrypto();
129
-
130
- case 2:
131
- elvCrypto = _context2.sent;
132
- publicKey = new Uint8Array(Buffer.from(publicKey.replace("0x", ""), "hex"));
133
- conk = new Uint8Array(Buffer.from(JSON.stringify(conk)));
134
- _context2.next = 7;
135
- return elvCrypto.encryptECIES(conk, publicKey);
136
-
137
- case 7:
138
- _yield$elvCrypto$encr = _context2.sent;
139
- data = _yield$elvCrypto$encr.data;
140
- ephemeralKey = _yield$elvCrypto$encr.ephemeralKey;
141
- tag = _yield$elvCrypto$encr.tag;
142
- cap = Buffer.concat([Buffer.from(ephemeralKey), Buffer.from(tag), Buffer.from(data)]);
143
- return _context2.abrupt("return", Utils.B64(cap));
144
-
145
- case 13:
146
- case "end":
147
- return _context2.stop();
148
- }
94
+ while (1) switch (_context2.prev = _context2.next) {
95
+ case 0:
96
+ _context2.next = 2;
97
+ return Crypto.ElvCrypto();
98
+ case 2:
99
+ elvCrypto = _context2.sent;
100
+ publicKey = new Uint8Array(Buffer.from(publicKey.replace("0x", ""), "hex"));
101
+ conk = new Uint8Array(Buffer.from(JSON.stringify(conk)));
102
+ _context2.next = 7;
103
+ return elvCrypto.encryptECIES(conk, publicKey);
104
+ case 7:
105
+ _yield$elvCrypto$encr = _context2.sent;
106
+ data = _yield$elvCrypto$encr.data;
107
+ ephemeralKey = _yield$elvCrypto$encr.ephemeralKey;
108
+ tag = _yield$elvCrypto$encr.tag;
109
+ cap = Buffer.concat([Buffer.from(ephemeralKey), Buffer.from(tag), Buffer.from(data)]);
110
+ return _context2.abrupt("return", Utils.B64(cap));
111
+ case 13:
112
+ case "end":
113
+ return _context2.stop();
149
114
  }
150
115
  }, _callee2);
151
116
  }))();
@@ -154,26 +119,22 @@ var Crypto = {
154
119
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
155
120
  var elvCrypto, ephemeralKey, tag, data, cap;
156
121
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
157
- while (1) {
158
- switch (_context3.prev = _context3.next) {
159
- case 0:
160
- _context3.next = 2;
161
- return Crypto.ElvCrypto();
162
-
163
- case 2:
164
- elvCrypto = _context3.sent;
165
- privateKey = new Uint8Array(Buffer.from(privateKey.replace("0x", ""), "hex"));
166
- encryptedCap = Buffer.from(encryptedCap, "base64");
167
- ephemeralKey = encryptedCap.slice(0, 65);
168
- tag = encryptedCap.slice(65, 81);
169
- data = encryptedCap.slice(81);
170
- cap = elvCrypto.decryptECIES(new Uint8Array(data), privateKey, new Uint8Array(ephemeralKey), new Uint8Array(tag));
171
- return _context3.abrupt("return", JSON.parse(Buffer.from(cap).toString()));
172
-
173
- case 10:
174
- case "end":
175
- return _context3.stop();
176
- }
122
+ while (1) switch (_context3.prev = _context3.next) {
123
+ case 0:
124
+ _context3.next = 2;
125
+ return Crypto.ElvCrypto();
126
+ case 2:
127
+ elvCrypto = _context3.sent;
128
+ privateKey = new Uint8Array(Buffer.from(privateKey.replace("0x", ""), "hex"));
129
+ encryptedCap = Buffer.from(encryptedCap, "base64");
130
+ ephemeralKey = encryptedCap.slice(0, 65);
131
+ tag = encryptedCap.slice(65, 81);
132
+ data = encryptedCap.slice(81);
133
+ cap = elvCrypto.decryptECIES(new Uint8Array(data), privateKey, new Uint8Array(ephemeralKey), new Uint8Array(tag));
134
+ return _context3.abrupt("return", JSON.parse(Buffer.from(cap).toString()));
135
+ case 10:
136
+ case "end":
137
+ return _context3.stop();
177
138
  }
178
139
  }, _callee3);
179
140
  }))();
@@ -181,31 +142,26 @@ var Crypto = {
181
142
  GeneratePrimaryConk: function GeneratePrimaryConk(_ref) {
182
143
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
183
144
  var spaceId, objectId, elvCrypto, _elvCrypto$generatePr, secretKey, publicKey, symmetricKey;
184
-
185
145
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
186
- while (1) {
187
- switch (_context4.prev = _context4.next) {
188
- case 0:
189
- spaceId = _ref.spaceId, objectId = _ref.objectId;
190
- _context4.next = 3;
191
- return Crypto.ElvCrypto();
192
-
193
- case 3:
194
- elvCrypto = _context4.sent;
195
- _elvCrypto$generatePr = elvCrypto.generatePrimaryKeys(), secretKey = _elvCrypto$generatePr.secretKey, publicKey = _elvCrypto$generatePr.publicKey;
196
- symmetricKey = elvCrypto.generateSymmetricKey().key;
197
- return _context4.abrupt("return", {
198
- symm_key: "kpsy".concat(bs58.encode(Buffer.from(symmetricKey))),
199
- secret_key: "kpsk".concat(bs58.encode(Buffer.from(secretKey))),
200
- public_key: "kppk".concat(bs58.encode(Buffer.from(publicKey))),
201
- sid: spaceId,
202
- qid: objectId
203
- });
204
-
205
- case 7:
206
- case "end":
207
- return _context4.stop();
208
- }
146
+ while (1) switch (_context4.prev = _context4.next) {
147
+ case 0:
148
+ spaceId = _ref.spaceId, objectId = _ref.objectId;
149
+ _context4.next = 3;
150
+ return Crypto.ElvCrypto();
151
+ case 3:
152
+ elvCrypto = _context4.sent;
153
+ _elvCrypto$generatePr = elvCrypto.generatePrimaryKeys(), secretKey = _elvCrypto$generatePr.secretKey, publicKey = _elvCrypto$generatePr.publicKey;
154
+ symmetricKey = elvCrypto.generateSymmetricKey().key;
155
+ return _context4.abrupt("return", {
156
+ symm_key: "kpsy".concat(bs58.encode(Buffer.from(symmetricKey))),
157
+ secret_key: "kpsk".concat(bs58.encode(Buffer.from(secretKey))),
158
+ public_key: "kppk".concat(bs58.encode(Buffer.from(publicKey))),
159
+ sid: spaceId,
160
+ qid: objectId
161
+ });
162
+ case 7:
163
+ case "end":
164
+ return _context4.stop();
209
165
  }
210
166
  }, _callee4);
211
167
  }))();
@@ -213,26 +169,21 @@ var Crypto = {
213
169
  GenerateTargetConk: function GenerateTargetConk() {
214
170
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
215
171
  var elvCrypto, _elvCrypto$generateTa, secretKey, publicKey;
216
-
217
172
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
218
- while (1) {
219
- switch (_context5.prev = _context5.next) {
220
- case 0:
221
- _context5.next = 2;
222
- return Crypto.ElvCrypto();
223
-
224
- case 2:
225
- elvCrypto = _context5.sent;
226
- _elvCrypto$generateTa = elvCrypto.generateTargetKeys(), secretKey = _elvCrypto$generateTa.secretKey, publicKey = _elvCrypto$generateTa.publicKey;
227
- return _context5.abrupt("return", {
228
- secret_key: "kpsk".concat(bs58.encode(Buffer.from(secretKey))),
229
- public_key: "ktpk".concat(bs58.encode(Buffer.from(publicKey)))
230
- });
231
-
232
- case 5:
233
- case "end":
234
- return _context5.stop();
235
- }
173
+ while (1) switch (_context5.prev = _context5.next) {
174
+ case 0:
175
+ _context5.next = 2;
176
+ return Crypto.ElvCrypto();
177
+ case 2:
178
+ elvCrypto = _context5.sent;
179
+ _elvCrypto$generateTa = elvCrypto.generateTargetKeys(), secretKey = _elvCrypto$generateTa.secretKey, publicKey = _elvCrypto$generateTa.publicKey;
180
+ return _context5.abrupt("return", {
181
+ secret_key: "kpsk".concat(bs58.encode(Buffer.from(secretKey))),
182
+ public_key: "ktpk".concat(bs58.encode(Buffer.from(publicKey)))
183
+ });
184
+ case 5:
185
+ case "end":
186
+ return _context5.stop();
236
187
  }
237
188
  }, _callee5);
238
189
  }))();
@@ -241,7 +192,6 @@ var Crypto = {
241
192
  var keyToBytes = function keyToBytes(key) {
242
193
  return new Uint8Array(bs58.decode(key.slice(4)));
243
194
  };
244
-
245
195
  return {
246
196
  symmetricKey: keyToBytes(cap.symm_key),
247
197
  secretKey: keyToBytes(cap.secret_key),
@@ -251,42 +201,34 @@ var Crypto = {
251
201
  EncryptionContext: function EncryptionContext(cap) {
252
202
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
253
203
  var elvCrypto, _Crypto$CapToConk, symmetricKey, secretKey, publicKey, context, type;
254
-
255
204
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
256
- while (1) {
257
- switch (_context6.prev = _context6.next) {
258
- case 0:
259
- _context6.next = 2;
260
- return Crypto.ElvCrypto();
261
-
262
- case 2:
263
- elvCrypto = _context6.sent;
264
- _Crypto$CapToConk = Crypto.CapToConk(cap), symmetricKey = _Crypto$CapToConk.symmetricKey, secretKey = _Crypto$CapToConk.secretKey, publicKey = _Crypto$CapToConk.publicKey;
265
-
266
- if (publicKey.length === elvCrypto.PRIMARY_PK_KEY_SIZE) {
267
- // Primary context
268
- type = elvCrypto.CRYPTO_TYPE_PRIMARY;
269
- context = elvCrypto.newPrimaryContext(publicKey, secretKey, symmetricKey);
270
- } else {
271
- // Target context
272
- type = elvCrypto.CRYPTO_TYPE_TARGET;
273
- context = elvCrypto.newTargetDecryptionContext(secretKey, symmetricKey);
274
- }
275
-
276
- return _context6.abrupt("return", {
277
- context: context,
278
- type: type
279
- });
280
-
281
- case 6:
282
- case "end":
283
- return _context6.stop();
284
- }
205
+ while (1) switch (_context6.prev = _context6.next) {
206
+ case 0:
207
+ _context6.next = 2;
208
+ return Crypto.ElvCrypto();
209
+ case 2:
210
+ elvCrypto = _context6.sent;
211
+ _Crypto$CapToConk = Crypto.CapToConk(cap), symmetricKey = _Crypto$CapToConk.symmetricKey, secretKey = _Crypto$CapToConk.secretKey, publicKey = _Crypto$CapToConk.publicKey;
212
+ if (publicKey.length === elvCrypto.PRIMARY_PK_KEY_SIZE) {
213
+ // Primary context
214
+ type = elvCrypto.CRYPTO_TYPE_PRIMARY;
215
+ context = elvCrypto.newPrimaryContext(publicKey, secretKey, symmetricKey);
216
+ } else {
217
+ // Target context
218
+ type = elvCrypto.CRYPTO_TYPE_TARGET;
219
+ context = elvCrypto.newTargetDecryptionContext(secretKey, symmetricKey);
220
+ }
221
+ return _context6.abrupt("return", {
222
+ context: context,
223
+ type: type
224
+ });
225
+ case 6:
226
+ case "end":
227
+ return _context6.stop();
285
228
  }
286
229
  }, _callee6);
287
230
  }))();
288
231
  },
289
-
290
232
  /**
291
233
  * Encrypt data with headers
292
234
  *
@@ -300,108 +242,86 @@ var Crypto = {
300
242
  var _Encrypt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(cap, data) {
301
243
  var stream, dataArray, i, end, encryptedChunks;
302
244
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
303
- while (1) {
304
- switch (_context7.prev = _context7.next) {
305
- case 0:
306
- _context7.next = 2;
307
- return Crypto.OpenEncryptionStream(cap);
308
-
309
- case 2:
310
- stream = _context7.sent;
311
-
312
- if (!(!Buffer.isBuffer(data) && !(data instanceof ArrayBuffer))) {
313
- _context7.next = 9;
314
- break;
315
- }
316
-
317
- _context7.t0 = Buffer;
318
- _context7.next = 7;
319
- return new Response(data).arrayBuffer();
320
-
321
- case 7:
322
- _context7.t1 = _context7.sent;
323
- data = _context7.t0.from.call(_context7.t0, _context7.t1);
324
-
325
- case 9:
326
- dataArray = new Uint8Array(data);
327
-
328
- for (i = 0; i < dataArray.length; i += 1000000) {
329
- end = Math.min(dataArray.length, i + 1000000);
330
- stream.write(dataArray.slice(i, end));
331
- }
332
-
333
- stream.end();
334
- encryptedChunks = [];
335
- _context7.next = 15;
336
- return new Promise(function (resolve, reject) {
337
- stream.on("data", function (chunk) {
338
- encryptedChunks.push(chunk);
339
- }).on("finish", function () {
340
- resolve();
341
- }).on("error", function (e) {
342
- reject(e);
343
- });
245
+ while (1) switch (_context7.prev = _context7.next) {
246
+ case 0:
247
+ _context7.next = 2;
248
+ return Crypto.OpenEncryptionStream(cap);
249
+ case 2:
250
+ stream = _context7.sent;
251
+ if (!(!Buffer.isBuffer(data) && !(data instanceof ArrayBuffer))) {
252
+ _context7.next = 9;
253
+ break;
254
+ }
255
+ _context7.t0 = Buffer;
256
+ _context7.next = 7;
257
+ return new Response(data).arrayBuffer();
258
+ case 7:
259
+ _context7.t1 = _context7.sent;
260
+ data = _context7.t0.from.call(_context7.t0, _context7.t1);
261
+ case 9:
262
+ dataArray = new Uint8Array(data);
263
+ for (i = 0; i < dataArray.length; i += 1000000) {
264
+ end = Math.min(dataArray.length, i + 1000000);
265
+ stream.write(dataArray.slice(i, end));
266
+ }
267
+ stream.end();
268
+ encryptedChunks = [];
269
+ _context7.next = 15;
270
+ return new Promise(function (resolve, reject) {
271
+ stream.on("data", function (chunk) {
272
+ encryptedChunks.push(chunk);
273
+ }).on("finish", function () {
274
+ resolve();
275
+ }).on("error", function (e) {
276
+ reject(e);
344
277
  });
345
-
346
- case 15:
347
- return _context7.abrupt("return", Buffer.concat(encryptedChunks));
348
-
349
- case 16:
350
- case "end":
351
- return _context7.stop();
352
- }
278
+ });
279
+ case 15:
280
+ return _context7.abrupt("return", Buffer.concat(encryptedChunks));
281
+ case 16:
282
+ case "end":
283
+ return _context7.stop();
353
284
  }
354
285
  }, _callee7);
355
286
  }));
356
-
357
287
  function Encrypt(_x, _x2) {
358
288
  return _Encrypt.apply(this, arguments);
359
289
  }
360
-
361
290
  return Encrypt;
362
291
  }(),
363
292
  OpenEncryptionStream: function () {
364
293
  var _OpenEncryptionStream = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(cap) {
365
294
  var elvCrypto, _yield$Crypto$Encrypt, context, stream, cipher;
366
-
367
295
  return _regeneratorRuntime.wrap(function _callee8$(_context8) {
368
- while (1) {
369
- switch (_context8.prev = _context8.next) {
370
- case 0:
371
- _context8.next = 2;
372
- return Crypto.ElvCrypto();
373
-
374
- case 2:
375
- elvCrypto = _context8.sent;
376
- _context8.next = 5;
377
- return Crypto.EncryptionContext(cap);
378
-
379
- case 5:
380
- _yield$Crypto$Encrypt = _context8.sent;
381
- context = _yield$Crypto$Encrypt.context;
382
- stream = new Stream.PassThrough();
383
- cipher = elvCrypto.createCipher(context);
384
- return _context8.abrupt("return", stream.pipe(cipher).on("finish", function () {
385
- context.free();
386
- }).on("error", function (e) {
387
- throw Error(e);
388
- }));
389
-
390
- case 10:
391
- case "end":
392
- return _context8.stop();
393
- }
296
+ while (1) switch (_context8.prev = _context8.next) {
297
+ case 0:
298
+ _context8.next = 2;
299
+ return Crypto.ElvCrypto();
300
+ case 2:
301
+ elvCrypto = _context8.sent;
302
+ _context8.next = 5;
303
+ return Crypto.EncryptionContext(cap);
304
+ case 5:
305
+ _yield$Crypto$Encrypt = _context8.sent;
306
+ context = _yield$Crypto$Encrypt.context;
307
+ stream = new Stream.PassThrough();
308
+ cipher = elvCrypto.createCipher(context);
309
+ return _context8.abrupt("return", stream.pipe(cipher).on("finish", function () {
310
+ context.free();
311
+ }).on("error", function (e) {
312
+ throw Error(e);
313
+ }));
314
+ case 10:
315
+ case "end":
316
+ return _context8.stop();
394
317
  }
395
318
  }, _callee8);
396
319
  }));
397
-
398
320
  function OpenEncryptionStream(_x3) {
399
321
  return _OpenEncryptionStream.apply(this, arguments);
400
322
  }
401
-
402
323
  return OpenEncryptionStream;
403
324
  }(),
404
-
405
325
  /**
406
326
  * Decrypt data with headers
407
327
  *
@@ -415,91 +335,74 @@ var Crypto = {
415
335
  var _Decrypt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(cap, encryptedData) {
416
336
  var stream, dataArray, i, end, decryptedChunks;
417
337
  return _regeneratorRuntime.wrap(function _callee9$(_context9) {
418
- while (1) {
419
- switch (_context9.prev = _context9.next) {
420
- case 0:
421
- _context9.next = 2;
422
- return Crypto.OpenDecryptionStream(cap);
423
-
424
- case 2:
425
- stream = _context9.sent;
426
- dataArray = new Uint8Array(encryptedData);
427
-
428
- for (i = 0; i < dataArray.length; i += 1000000) {
429
- end = Math.min(dataArray.length, i + 1000000);
430
- stream.write(dataArray.slice(i, end));
431
- }
432
-
433
- stream.end();
434
- decryptedChunks = [];
435
- _context9.next = 9;
436
- return new Promise(function (resolve, reject) {
437
- stream.on("data", function (chunk) {
438
- decryptedChunks.push(chunk);
439
- }).on("finish", function () {
440
- resolve();
441
- }).on("error", function (e) {
442
- reject(e);
443
- });
338
+ while (1) switch (_context9.prev = _context9.next) {
339
+ case 0:
340
+ _context9.next = 2;
341
+ return Crypto.OpenDecryptionStream(cap);
342
+ case 2:
343
+ stream = _context9.sent;
344
+ dataArray = new Uint8Array(encryptedData);
345
+ for (i = 0; i < dataArray.length; i += 1000000) {
346
+ end = Math.min(dataArray.length, i + 1000000);
347
+ stream.write(dataArray.slice(i, end));
348
+ }
349
+ stream.end();
350
+ decryptedChunks = [];
351
+ _context9.next = 9;
352
+ return new Promise(function (resolve, reject) {
353
+ stream.on("data", function (chunk) {
354
+ decryptedChunks.push(chunk);
355
+ }).on("finish", function () {
356
+ resolve();
357
+ }).on("error", function (e) {
358
+ reject(e);
444
359
  });
445
-
446
- case 9:
447
- return _context9.abrupt("return", Buffer.concat(decryptedChunks));
448
-
449
- case 10:
450
- case "end":
451
- return _context9.stop();
452
- }
360
+ });
361
+ case 9:
362
+ return _context9.abrupt("return", Buffer.concat(decryptedChunks));
363
+ case 10:
364
+ case "end":
365
+ return _context9.stop();
453
366
  }
454
367
  }, _callee9);
455
368
  }));
456
-
457
369
  function Decrypt(_x4, _x5) {
458
370
  return _Decrypt.apply(this, arguments);
459
371
  }
460
-
461
372
  return Decrypt;
462
373
  }(),
463
374
  OpenDecryptionStream: function () {
464
375
  var _OpenDecryptionStream = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(cap) {
465
376
  var elvCrypto, _yield$Crypto$Encrypt2, context, type, stream, decipher;
466
-
467
377
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
468
- while (1) {
469
- switch (_context10.prev = _context10.next) {
470
- case 0:
471
- _context10.next = 2;
472
- return Crypto.ElvCrypto();
473
-
474
- case 2:
475
- elvCrypto = _context10.sent;
476
- _context10.next = 5;
477
- return Crypto.EncryptionContext(cap);
478
-
479
- case 5:
480
- _yield$Crypto$Encrypt2 = _context10.sent;
481
- context = _yield$Crypto$Encrypt2.context;
482
- type = _yield$Crypto$Encrypt2.type;
483
- stream = new Stream.PassThrough();
484
- decipher = elvCrypto.createDecipher(type, context);
485
- return _context10.abrupt("return", stream.pipe(decipher).on("finish", function () {
486
- context.free();
487
- }).on("error", function (e) {
488
- throw Error(e);
489
- }));
490
-
491
- case 11:
492
- case "end":
493
- return _context10.stop();
494
- }
378
+ while (1) switch (_context10.prev = _context10.next) {
379
+ case 0:
380
+ _context10.next = 2;
381
+ return Crypto.ElvCrypto();
382
+ case 2:
383
+ elvCrypto = _context10.sent;
384
+ _context10.next = 5;
385
+ return Crypto.EncryptionContext(cap);
386
+ case 5:
387
+ _yield$Crypto$Encrypt2 = _context10.sent;
388
+ context = _yield$Crypto$Encrypt2.context;
389
+ type = _yield$Crypto$Encrypt2.type;
390
+ stream = new Stream.PassThrough();
391
+ decipher = elvCrypto.createDecipher(type, context);
392
+ return _context10.abrupt("return", stream.pipe(decipher).on("finish", function () {
393
+ context.free();
394
+ }).on("error", function (e) {
395
+ throw Error(e);
396
+ }));
397
+ case 11:
398
+ case "end":
399
+ return _context10.stop();
495
400
  }
496
401
  }, _callee10);
497
402
  }));
498
-
499
403
  function OpenDecryptionStream(_x6) {
500
404
  return _OpenDecryptionStream.apply(this, arguments);
501
405
  }
502
-
503
406
  return OpenDecryptionStream;
504
407
  }()
505
408
  };