@eluvio/elv-client-js 4.0.10 → 4.0.11

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