@eluvio/elv-client-js 3.1.96 → 3.1.97
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.
- package/dist/ElvClient-min.js +11 -15
- package/dist/ElvClient-node-min.js +13 -17
- package/dist/ElvFrameClient-min.js +9 -13
- package/dist/ElvPermissionsClient-min.js +9 -13
- package/dist/src/AuthorizationClient.js +1980 -2238
- package/dist/src/ContentObjectVerification.js +173 -164
- package/dist/src/Crypto.js +324 -376
- package/dist/src/ElvClient.js +1019 -1182
- package/dist/src/ElvWallet.js +95 -119
- package/dist/src/EthClient.js +896 -1040
- package/dist/src/FrameClient.js +300 -331
- package/dist/src/HttpClient.js +147 -153
- package/dist/src/Id.js +3 -1
- package/dist/src/PermissionsClient.js +1168 -1294
- package/dist/src/RemoteSigner.js +211 -263
- package/dist/src/UserProfileClient.js +1023 -1164
- package/dist/src/Utils.js +197 -209
- package/dist/src/client/ABRPublishing.js +858 -895
- package/dist/src/client/AccessGroups.js +959 -1102
- package/dist/src/client/ContentAccess.js +3434 -3727
- package/dist/src/client/ContentManagement.js +2068 -2252
- package/dist/src/client/Contracts.js +563 -647
- package/dist/src/client/Files.js +1757 -1886
- package/dist/src/client/NFT.js +112 -126
- package/dist/src/client/NTP.js +422 -478
- package/package-lock.json +22001 -0
- package/package.json +1 -1
- package/src/Utils.js +22 -0
package/dist/src/Crypto.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
2
2
|
|
|
3
|
-
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
4
|
-
|
|
5
3
|
if (typeof Buffer === "undefined") {
|
|
6
4
|
Buffer = require("buffer/").Buffer;
|
|
7
5
|
}
|
|
@@ -45,50 +43,42 @@ switch (Utils.Platform()) {
|
|
|
45
43
|
|
|
46
44
|
|
|
47
45
|
var Crypto = {
|
|
48
|
-
ElvCrypto: function () {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return _context.stop();
|
|
81
|
-
}
|
|
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();
|
|
82
78
|
}
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
function ElvCrypto() {
|
|
87
|
-
return _ElvCrypto2.apply(this, arguments);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return ElvCrypto;
|
|
91
|
-
}(),
|
|
79
|
+
}
|
|
80
|
+
}, null, null, [[0, 8]]);
|
|
81
|
+
},
|
|
92
82
|
EncryptedSize: function EncryptedSize(clearSize) {
|
|
93
83
|
var clearBlockSize = 1000000;
|
|
94
84
|
var blocks = Math.floor(clearSize / clearBlockSize);
|
|
@@ -117,125 +107,117 @@ var Crypto = {
|
|
|
117
107
|
return reencrypt ? encryptedBlockSize + targetEncBlockOverhead : encryptedBlockSize + primaryEncBlockOverhead;
|
|
118
108
|
},
|
|
119
109
|
EncryptConk: function EncryptConk(conk, publicKey) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return _context2.stop();
|
|
148
|
-
}
|
|
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();
|
|
149
137
|
}
|
|
150
|
-
}
|
|
151
|
-
})
|
|
138
|
+
}
|
|
139
|
+
});
|
|
152
140
|
},
|
|
153
141
|
DecryptCap: function DecryptCap(encryptedCap, privateKey) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return _context3.stop();
|
|
176
|
-
}
|
|
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();
|
|
177
163
|
}
|
|
178
|
-
}
|
|
179
|
-
})
|
|
164
|
+
}
|
|
165
|
+
});
|
|
180
166
|
},
|
|
181
|
-
GeneratePrimaryConk: function GeneratePrimaryConk(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return _context4.stop();
|
|
208
|
-
}
|
|
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();
|
|
209
193
|
}
|
|
210
|
-
}
|
|
211
|
-
})
|
|
194
|
+
}
|
|
195
|
+
});
|
|
212
196
|
},
|
|
213
197
|
GenerateTargetConk: function GenerateTargetConk() {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return _context5.stop();
|
|
235
|
-
}
|
|
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();
|
|
236
218
|
}
|
|
237
|
-
}
|
|
238
|
-
})
|
|
219
|
+
}
|
|
220
|
+
});
|
|
239
221
|
},
|
|
240
222
|
CapToConk: function CapToConk(cap) {
|
|
241
223
|
var keyToBytes = function keyToBytes(key) {
|
|
@@ -249,42 +231,40 @@ var Crypto = {
|
|
|
249
231
|
};
|
|
250
232
|
},
|
|
251
233
|
EncryptionContext: function EncryptionContext(cap) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return _context6.stop();
|
|
284
|
-
}
|
|
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();
|
|
285
265
|
}
|
|
286
|
-
}
|
|
287
|
-
})
|
|
266
|
+
}
|
|
267
|
+
});
|
|
288
268
|
},
|
|
289
269
|
|
|
290
270
|
/**
|
|
@@ -296,111 +276,95 @@ var Crypto = {
|
|
|
296
276
|
*
|
|
297
277
|
* @returns {Promise<Buffer>} - Decrypted data
|
|
298
278
|
*/
|
|
299
|
-
Encrypt: function () {
|
|
300
|
-
var
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
reject(e);
|
|
343
|
-
});
|
|
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);
|
|
344
322
|
});
|
|
323
|
+
}));
|
|
345
324
|
|
|
346
|
-
|
|
347
|
-
|
|
325
|
+
case 15:
|
|
326
|
+
return _context7.abrupt("return", Buffer.concat(encryptedChunks));
|
|
348
327
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
328
|
+
case 16:
|
|
329
|
+
case "end":
|
|
330
|
+
return _context7.stop();
|
|
353
331
|
}
|
|
354
|
-
}
|
|
355
|
-
})
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}).on("error", function (e) {
|
|
387
|
-
throw Error(e);
|
|
388
|
-
}));
|
|
389
|
-
|
|
390
|
-
case 10:
|
|
391
|
-
case "end":
|
|
392
|
-
return _context8.stop();
|
|
393
|
-
}
|
|
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();
|
|
394
364
|
}
|
|
395
|
-
}
|
|
396
|
-
})
|
|
397
|
-
|
|
398
|
-
function OpenEncryptionStream(_x3) {
|
|
399
|
-
return _OpenEncryptionStream.apply(this, arguments);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
return OpenEncryptionStream;
|
|
403
|
-
}(),
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
},
|
|
404
368
|
|
|
405
369
|
/**
|
|
406
370
|
* Decrypt data with headers
|
|
@@ -411,96 +375,80 @@ var Crypto = {
|
|
|
411
375
|
*
|
|
412
376
|
* @returns {Promise<Buffer>} - Decrypted data
|
|
413
377
|
*/
|
|
414
|
-
Decrypt: function () {
|
|
415
|
-
var
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
reject(e);
|
|
443
|
-
});
|
|
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);
|
|
444
406
|
});
|
|
407
|
+
}));
|
|
445
408
|
|
|
446
|
-
|
|
447
|
-
|
|
409
|
+
case 9:
|
|
410
|
+
return _context9.abrupt("return", Buffer.concat(decryptedChunks));
|
|
448
411
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
412
|
+
case 10:
|
|
413
|
+
case "end":
|
|
414
|
+
return _context9.stop();
|
|
453
415
|
}
|
|
454
|
-
}
|
|
455
|
-
})
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}).on("error", function (e) {
|
|
488
|
-
throw Error(e);
|
|
489
|
-
}));
|
|
490
|
-
|
|
491
|
-
case 11:
|
|
492
|
-
case "end":
|
|
493
|
-
return _context10.stop();
|
|
494
|
-
}
|
|
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();
|
|
495
449
|
}
|
|
496
|
-
}
|
|
497
|
-
})
|
|
498
|
-
|
|
499
|
-
function OpenDecryptionStream(_x6) {
|
|
500
|
-
return _OpenDecryptionStream.apply(this, arguments);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return OpenDecryptionStream;
|
|
504
|
-
}()
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
505
453
|
};
|
|
506
454
|
module.exports = Crypto;
|