@eluvio/elv-client-js 3.2.2 → 3.2.6

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 (35) hide show
  1. package/dist/ElvClient-min.js +15 -11
  2. package/dist/ElvClient-node-min.js +17 -13
  3. package/dist/ElvFrameClient-min.js +12 -8
  4. package/dist/ElvPermissionsClient-min.js +13 -9
  5. package/dist/ElvWalletClient-min.js +58 -0
  6. package/dist/ElvWalletClient-node-min.js +78 -0
  7. package/dist/src/AuthorizationClient.js +2248 -1990
  8. package/dist/src/ContentObjectVerification.js +164 -173
  9. package/dist/src/Crypto.js +376 -324
  10. package/dist/src/ElvClient.js +1182 -1019
  11. package/dist/src/ElvWallet.js +119 -95
  12. package/dist/src/EthClient.js +1040 -896
  13. package/dist/src/FrameClient.js +331 -300
  14. package/dist/src/HttpClient.js +153 -147
  15. package/dist/src/Id.js +1 -3
  16. package/dist/src/PermissionsClient.js +1294 -1168
  17. package/dist/src/RemoteSigner.js +263 -211
  18. package/dist/src/UserProfileClient.js +1164 -1023
  19. package/dist/src/Utils.js +209 -181
  20. package/dist/src/client/ABRPublishing.js +895 -858
  21. package/dist/src/client/AccessGroups.js +1102 -959
  22. package/dist/src/client/ContentAccess.js +3724 -3431
  23. package/dist/src/client/ContentManagement.js +2252 -2068
  24. package/dist/src/client/Contracts.js +647 -563
  25. package/dist/src/client/Files.js +1886 -1757
  26. package/dist/src/client/NFT.js +126 -112
  27. package/dist/src/client/NTP.js +478 -422
  28. package/dist/src/walletClient/ClientMethods.js +1029 -879
  29. package/dist/src/walletClient/Utils.js +84 -70
  30. package/dist/src/walletClient/index.js +1203 -1087
  31. package/package.json +4 -2
  32. package/src/Utils.js +0 -1
  33. package/src/walletClient/ClientMethods.js +34 -2
  34. package/src/walletClient/index.js +3 -3
  35. package/utilities/ProductionMasterCreate.js +2 -2
@@ -1,5 +1,7 @@
1
1
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
2
2
 
3
+ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
4
+
3
5
  if (typeof Buffer === "undefined") {
4
6
  Buffer = require("buffer/").Buffer;
5
7
  }
@@ -43,42 +45,50 @@ switch (Utils.Platform()) {
43
45
 
44
46
 
45
47
  var Crypto = {
46
- ElvCrypto: function ElvCrypto() {
47
- return _regeneratorRuntime.async(function ElvCrypto$(_context) {
48
- while (1) {
49
- switch (_context.prev = _context.next) {
50
- case 0:
51
- _context.prev = 0;
52
-
53
- if (Crypto.elvCrypto) {
54
- _context.next = 5;
55
- break;
56
- }
57
-
58
- _context.next = 4;
59
- return _regeneratorRuntime.awrap(new _ElvCrypto().init());
60
-
61
- case 4:
62
- Crypto.elvCrypto = _context.sent;
63
-
64
- case 5:
65
- return _context.abrupt("return", Crypto.elvCrypto);
66
-
67
- case 8:
68
- _context.prev = 8;
69
- _context.t0 = _context["catch"](0);
70
- // eslint-disable-next-line no-console
71
- console.error("Error initializing ElvCrypto:"); // eslint-disable-next-line no-console
72
-
73
- console.error(_context.t0);
74
-
75
- case 12:
76
- case "end":
77
- return _context.stop();
48
+ ElvCrypto: function () {
49
+ var _ElvCrypto2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
50
+ 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
+ }
78
82
  }
79
- }
80
- }, null, null, [[0, 8]]);
81
- },
83
+ }, _callee, null, [[0, 8]]);
84
+ }));
85
+
86
+ function ElvCrypto() {
87
+ return _ElvCrypto2.apply(this, arguments);
88
+ }
89
+
90
+ return ElvCrypto;
91
+ }(),
82
92
  EncryptedSize: function EncryptedSize(clearSize) {
83
93
  var clearBlockSize = 1000000;
84
94
  var blocks = Math.floor(clearSize / clearBlockSize);
@@ -107,117 +117,125 @@ var Crypto = {
107
117
  return reencrypt ? encryptedBlockSize + targetEncBlockOverhead : encryptedBlockSize + primaryEncBlockOverhead;
108
118
  },
109
119
  EncryptConk: function EncryptConk(conk, publicKey) {
110
- var elvCrypto, _ref, data, ephemeralKey, tag, cap;
111
-
112
- return _regeneratorRuntime.async(function EncryptConk$(_context2) {
113
- while (1) {
114
- switch (_context2.prev = _context2.next) {
115
- case 0:
116
- _context2.next = 2;
117
- return _regeneratorRuntime.awrap(Crypto.ElvCrypto());
118
-
119
- case 2:
120
- elvCrypto = _context2.sent;
121
- publicKey = new Uint8Array(Buffer.from(publicKey.replace("0x", ""), "hex"));
122
- conk = new Uint8Array(Buffer.from(JSON.stringify(conk)));
123
- _context2.next = 7;
124
- return _regeneratorRuntime.awrap(elvCrypto.encryptECIES(conk, publicKey));
125
-
126
- case 7:
127
- _ref = _context2.sent;
128
- data = _ref.data;
129
- ephemeralKey = _ref.ephemeralKey;
130
- tag = _ref.tag;
131
- cap = Buffer.concat([Buffer.from(ephemeralKey), Buffer.from(tag), Buffer.from(data)]);
132
- return _context2.abrupt("return", Utils.B64(cap));
133
-
134
- case 13:
135
- case "end":
136
- return _context2.stop();
120
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
121
+ var elvCrypto, _yield$elvCrypto$encr, data, ephemeralKey, tag, cap;
122
+
123
+ 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
+ }
137
149
  }
138
- }
139
- });
150
+ }, _callee2);
151
+ }))();
140
152
  },
141
153
  DecryptCap: function DecryptCap(encryptedCap, privateKey) {
142
- var elvCrypto, ephemeralKey, tag, data, cap;
143
- return _regeneratorRuntime.async(function DecryptCap$(_context3) {
144
- while (1) {
145
- switch (_context3.prev = _context3.next) {
146
- case 0:
147
- _context3.next = 2;
148
- return _regeneratorRuntime.awrap(Crypto.ElvCrypto());
149
-
150
- case 2:
151
- elvCrypto = _context3.sent;
152
- privateKey = new Uint8Array(Buffer.from(privateKey.replace("0x", ""), "hex"));
153
- encryptedCap = Buffer.from(encryptedCap, "base64");
154
- ephemeralKey = encryptedCap.slice(0, 65);
155
- tag = encryptedCap.slice(65, 81);
156
- data = encryptedCap.slice(81);
157
- cap = elvCrypto.decryptECIES(new Uint8Array(data), privateKey, new Uint8Array(ephemeralKey), new Uint8Array(tag));
158
- return _context3.abrupt("return", JSON.parse(Buffer.from(cap).toString()));
159
-
160
- case 10:
161
- case "end":
162
- return _context3.stop();
154
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
155
+ var elvCrypto, ephemeralKey, tag, data, cap;
156
+ 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
+ }
163
177
  }
164
- }
165
- });
178
+ }, _callee3);
179
+ }))();
166
180
  },
167
- GeneratePrimaryConk: function GeneratePrimaryConk(_ref2) {
168
- var spaceId, objectId, elvCrypto, _elvCrypto$generatePr, secretKey, publicKey, symmetricKey;
169
-
170
- return _regeneratorRuntime.async(function GeneratePrimaryConk$(_context4) {
171
- while (1) {
172
- switch (_context4.prev = _context4.next) {
173
- case 0:
174
- spaceId = _ref2.spaceId, objectId = _ref2.objectId;
175
- _context4.next = 3;
176
- return _regeneratorRuntime.awrap(Crypto.ElvCrypto());
177
-
178
- case 3:
179
- elvCrypto = _context4.sent;
180
- _elvCrypto$generatePr = elvCrypto.generatePrimaryKeys(), secretKey = _elvCrypto$generatePr.secretKey, publicKey = _elvCrypto$generatePr.publicKey;
181
- symmetricKey = elvCrypto.generateSymmetricKey().key;
182
- return _context4.abrupt("return", {
183
- symm_key: "kpsy".concat(bs58.encode(Buffer.from(symmetricKey))),
184
- secret_key: "kpsk".concat(bs58.encode(Buffer.from(secretKey))),
185
- public_key: "kppk".concat(bs58.encode(Buffer.from(publicKey))),
186
- sid: spaceId,
187
- qid: objectId
188
- });
189
-
190
- case 7:
191
- case "end":
192
- return _context4.stop();
181
+ GeneratePrimaryConk: function GeneratePrimaryConk(_ref) {
182
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
183
+ var spaceId, objectId, elvCrypto, _elvCrypto$generatePr, secretKey, publicKey, symmetricKey;
184
+
185
+ 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
+ }
193
209
  }
194
- }
195
- });
210
+ }, _callee4);
211
+ }))();
196
212
  },
197
213
  GenerateTargetConk: function GenerateTargetConk() {
198
- var elvCrypto, _elvCrypto$generateTa, secretKey, publicKey;
199
-
200
- return _regeneratorRuntime.async(function GenerateTargetConk$(_context5) {
201
- while (1) {
202
- switch (_context5.prev = _context5.next) {
203
- case 0:
204
- _context5.next = 2;
205
- return _regeneratorRuntime.awrap(Crypto.ElvCrypto());
206
-
207
- case 2:
208
- elvCrypto = _context5.sent;
209
- _elvCrypto$generateTa = elvCrypto.generateTargetKeys(), secretKey = _elvCrypto$generateTa.secretKey, publicKey = _elvCrypto$generateTa.publicKey;
210
- return _context5.abrupt("return", {
211
- secret_key: "kpsk".concat(bs58.encode(Buffer.from(secretKey))),
212
- public_key: "ktpk".concat(bs58.encode(Buffer.from(publicKey)))
213
- });
214
-
215
- case 5:
216
- case "end":
217
- return _context5.stop();
214
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
215
+ var elvCrypto, _elvCrypto$generateTa, secretKey, publicKey;
216
+
217
+ 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
+ }
218
236
  }
219
- }
220
- });
237
+ }, _callee5);
238
+ }))();
221
239
  },
222
240
  CapToConk: function CapToConk(cap) {
223
241
  var keyToBytes = function keyToBytes(key) {
@@ -231,40 +249,42 @@ var Crypto = {
231
249
  };
232
250
  },
233
251
  EncryptionContext: function EncryptionContext(cap) {
234
- var elvCrypto, _Crypto$CapToConk, symmetricKey, secretKey, publicKey, context, type;
235
-
236
- return _regeneratorRuntime.async(function EncryptionContext$(_context6) {
237
- while (1) {
238
- switch (_context6.prev = _context6.next) {
239
- case 0:
240
- _context6.next = 2;
241
- return _regeneratorRuntime.awrap(Crypto.ElvCrypto());
242
-
243
- case 2:
244
- elvCrypto = _context6.sent;
245
- _Crypto$CapToConk = Crypto.CapToConk(cap), symmetricKey = _Crypto$CapToConk.symmetricKey, secretKey = _Crypto$CapToConk.secretKey, publicKey = _Crypto$CapToConk.publicKey;
246
-
247
- if (publicKey.length === elvCrypto.PRIMARY_PK_KEY_SIZE) {
248
- // Primary context
249
- type = elvCrypto.CRYPTO_TYPE_PRIMARY;
250
- context = elvCrypto.newPrimaryContext(publicKey, secretKey, symmetricKey);
251
- } else {
252
- // Target context
253
- type = elvCrypto.CRYPTO_TYPE_TARGET;
254
- context = elvCrypto.newTargetDecryptionContext(secretKey, symmetricKey);
255
- }
256
-
257
- return _context6.abrupt("return", {
258
- context: context,
259
- type: type
260
- });
261
-
262
- case 6:
263
- case "end":
264
- return _context6.stop();
252
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
253
+ var elvCrypto, _Crypto$CapToConk, symmetricKey, secretKey, publicKey, context, type;
254
+
255
+ 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
+ }
265
285
  }
266
- }
267
- });
286
+ }, _callee6);
287
+ }))();
268
288
  },
269
289
 
270
290
  /**
@@ -276,95 +296,111 @@ var Crypto = {
276
296
  *
277
297
  * @returns {Promise<Buffer>} - Decrypted data
278
298
  */
279
- Encrypt: function Encrypt(cap, data) {
280
- var stream, dataArray, i, end, encryptedChunks;
281
- return _regeneratorRuntime.async(function Encrypt$(_context7) {
282
- while (1) {
283
- switch (_context7.prev = _context7.next) {
284
- case 0:
285
- _context7.next = 2;
286
- return _regeneratorRuntime.awrap(Crypto.OpenEncryptionStream(cap));
287
-
288
- case 2:
289
- stream = _context7.sent;
290
-
291
- if (!(!Buffer.isBuffer(data) && !(data instanceof ArrayBuffer))) {
292
- _context7.next = 9;
293
- break;
294
- }
295
-
296
- _context7.t0 = Buffer;
297
- _context7.next = 7;
298
- return _regeneratorRuntime.awrap(new Response(data).arrayBuffer());
299
-
300
- case 7:
301
- _context7.t1 = _context7.sent;
302
- data = _context7.t0.from.call(_context7.t0, _context7.t1);
303
-
304
- case 9:
305
- dataArray = new Uint8Array(data);
306
-
307
- for (i = 0; i < dataArray.length; i += 1000000) {
308
- end = Math.min(dataArray.length, i + 1000000);
309
- stream.write(dataArray.slice(i, end));
310
- }
311
-
312
- stream.end();
313
- encryptedChunks = [];
314
- _context7.next = 15;
315
- return _regeneratorRuntime.awrap(new Promise(function (resolve, reject) {
316
- stream.on("data", function (chunk) {
317
- encryptedChunks.push(chunk);
318
- }).on("finish", function () {
319
- resolve();
320
- }).on("error", function (e) {
321
- reject(e);
299
+ Encrypt: function () {
300
+ var _Encrypt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(cap, data) {
301
+ var stream, dataArray, i, end, encryptedChunks;
302
+ 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
+ });
322
344
  });
323
- }));
324
345
 
325
- case 15:
326
- return _context7.abrupt("return", Buffer.concat(encryptedChunks));
346
+ case 15:
347
+ return _context7.abrupt("return", Buffer.concat(encryptedChunks));
327
348
 
328
- case 16:
329
- case "end":
330
- return _context7.stop();
349
+ case 16:
350
+ case "end":
351
+ return _context7.stop();
352
+ }
331
353
  }
332
- }
333
- });
334
- },
335
- OpenEncryptionStream: function OpenEncryptionStream(cap) {
336
- var elvCrypto, _ref3, context, stream, cipher;
337
-
338
- return _regeneratorRuntime.async(function OpenEncryptionStream$(_context8) {
339
- while (1) {
340
- switch (_context8.prev = _context8.next) {
341
- case 0:
342
- _context8.next = 2;
343
- return _regeneratorRuntime.awrap(Crypto.ElvCrypto());
344
-
345
- case 2:
346
- elvCrypto = _context8.sent;
347
- _context8.next = 5;
348
- return _regeneratorRuntime.awrap(Crypto.EncryptionContext(cap));
349
-
350
- case 5:
351
- _ref3 = _context8.sent;
352
- context = _ref3.context;
353
- stream = new Stream.PassThrough();
354
- cipher = elvCrypto.createCipher(context);
355
- return _context8.abrupt("return", stream.pipe(cipher).on("finish", function () {
356
- context.free();
357
- }).on("error", function (e) {
358
- throw Error(e);
359
- }));
360
-
361
- case 10:
362
- case "end":
363
- return _context8.stop();
354
+ }, _callee7);
355
+ }));
356
+
357
+ function Encrypt(_x, _x2) {
358
+ return _Encrypt.apply(this, arguments);
359
+ }
360
+
361
+ return Encrypt;
362
+ }(),
363
+ OpenEncryptionStream: function () {
364
+ var _OpenEncryptionStream = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(cap) {
365
+ var elvCrypto, _yield$Crypto$Encrypt, context, stream, cipher;
366
+
367
+ 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
+ }
364
394
  }
365
- }
366
- });
367
- },
395
+ }, _callee8);
396
+ }));
397
+
398
+ function OpenEncryptionStream(_x3) {
399
+ return _OpenEncryptionStream.apply(this, arguments);
400
+ }
401
+
402
+ return OpenEncryptionStream;
403
+ }(),
368
404
 
369
405
  /**
370
406
  * Decrypt data with headers
@@ -375,80 +411,96 @@ var Crypto = {
375
411
  *
376
412
  * @returns {Promise<Buffer>} - Decrypted data
377
413
  */
378
- Decrypt: function Decrypt(cap, encryptedData) {
379
- var stream, dataArray, i, end, decryptedChunks;
380
- return _regeneratorRuntime.async(function Decrypt$(_context9) {
381
- while (1) {
382
- switch (_context9.prev = _context9.next) {
383
- case 0:
384
- _context9.next = 2;
385
- return _regeneratorRuntime.awrap(Crypto.OpenDecryptionStream(cap));
386
-
387
- case 2:
388
- stream = _context9.sent;
389
- dataArray = new Uint8Array(encryptedData);
390
-
391
- for (i = 0; i < dataArray.length; i += 1000000) {
392
- end = Math.min(dataArray.length, i + 1000000);
393
- stream.write(dataArray.slice(i, end));
394
- }
395
-
396
- stream.end();
397
- decryptedChunks = [];
398
- _context9.next = 9;
399
- return _regeneratorRuntime.awrap(new Promise(function (resolve, reject) {
400
- stream.on("data", function (chunk) {
401
- decryptedChunks.push(chunk);
402
- }).on("finish", function () {
403
- resolve();
404
- }).on("error", function (e) {
405
- reject(e);
414
+ Decrypt: function () {
415
+ var _Decrypt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(cap, encryptedData) {
416
+ var stream, dataArray, i, end, decryptedChunks;
417
+ 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
+ });
406
444
  });
407
- }));
408
445
 
409
- case 9:
410
- return _context9.abrupt("return", Buffer.concat(decryptedChunks));
446
+ case 9:
447
+ return _context9.abrupt("return", Buffer.concat(decryptedChunks));
411
448
 
412
- case 10:
413
- case "end":
414
- return _context9.stop();
449
+ case 10:
450
+ case "end":
451
+ return _context9.stop();
452
+ }
415
453
  }
416
- }
417
- });
418
- },
419
- OpenDecryptionStream: function OpenDecryptionStream(cap) {
420
- var elvCrypto, _ref4, context, type, stream, decipher;
421
-
422
- return _regeneratorRuntime.async(function OpenDecryptionStream$(_context10) {
423
- while (1) {
424
- switch (_context10.prev = _context10.next) {
425
- case 0:
426
- _context10.next = 2;
427
- return _regeneratorRuntime.awrap(Crypto.ElvCrypto());
428
-
429
- case 2:
430
- elvCrypto = _context10.sent;
431
- _context10.next = 5;
432
- return _regeneratorRuntime.awrap(Crypto.EncryptionContext(cap));
433
-
434
- case 5:
435
- _ref4 = _context10.sent;
436
- context = _ref4.context;
437
- type = _ref4.type;
438
- stream = new Stream.PassThrough();
439
- decipher = elvCrypto.createDecipher(type, context);
440
- return _context10.abrupt("return", stream.pipe(decipher).on("finish", function () {
441
- context.free();
442
- }).on("error", function (e) {
443
- throw Error(e);
444
- }));
445
-
446
- case 11:
447
- case "end":
448
- return _context10.stop();
454
+ }, _callee9);
455
+ }));
456
+
457
+ function Decrypt(_x4, _x5) {
458
+ return _Decrypt.apply(this, arguments);
459
+ }
460
+
461
+ return Decrypt;
462
+ }(),
463
+ OpenDecryptionStream: function () {
464
+ var _OpenDecryptionStream = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(cap) {
465
+ var elvCrypto, _yield$Crypto$Encrypt2, context, type, stream, decipher;
466
+
467
+ 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
+ }
449
495
  }
450
- }
451
- });
452
- }
496
+ }, _callee10);
497
+ }));
498
+
499
+ function OpenDecryptionStream(_x6) {
500
+ return _OpenDecryptionStream.apply(this, arguments);
501
+ }
502
+
503
+ return OpenDecryptionStream;
504
+ }()
453
505
  };
454
506
  module.exports = Crypto;