@eluvio/elv-client-js 4.0.11 → 4.0.13
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/.keep +0 -0
- package/dist/ElvClient-min.js +11 -10
- package/dist/ElvClient-node-min.js +11 -10
- package/dist/ElvFrameClient-min.js +11 -10
- package/dist/ElvPermissionsClient-min.js +10 -9
- package/dist/ElvWalletClient-min.js +10 -9
- package/dist/ElvWalletClient-node-min.js +10 -9
- package/dist/src/AuthorizationClient.js +1555 -2076
- package/dist/src/ContentObjectVerification.js +134 -185
- package/dist/src/Crypto.js +224 -319
- package/dist/src/ElvClient.js +822 -1114
- package/dist/src/ElvWallet.js +64 -106
- package/dist/src/EthClient.js +719 -974
- package/dist/src/FrameClient.js +223 -319
- package/dist/src/HttpClient.js +117 -156
- package/dist/src/Id.js +1 -6
- package/dist/src/LogMessage.js +4 -8
- package/dist/src/PermissionsClient.js +973 -1271
- package/dist/src/RemoteSigner.js +161 -232
- package/dist/src/UserProfileClient.js +781 -1038
- package/dist/src/Utils.js +159 -299
- package/dist/src/Validation.js +2 -17
- package/dist/src/client/ABRPublishing.js +828 -958
- package/dist/src/client/AccessGroups.js +849 -1095
- package/dist/src/client/ContentAccess.js +3323 -4195
- package/dist/src/client/ContentManagement.js +1818 -2290
- package/dist/src/client/Contracts.js +468 -614
- package/dist/src/client/Files.js +1506 -1846
- package/dist/src/client/NFT.js +94 -116
- package/dist/src/client/NTP.js +326 -425
- package/dist/src/index.js +2 -5
- package/dist/src/walletClient/ClientMethods.js +1368 -1763
- package/dist/src/walletClient/Configuration.js +5 -3
- package/dist/src/walletClient/Notifications.js +98 -127
- package/dist/src/walletClient/Profile.js +184 -246
- package/dist/src/walletClient/Utils.js +76 -122
- package/dist/src/walletClient/index.js +1171 -1496
- package/package.json +4 -21
- package/src/FrameClient.js +1 -0
- package/src/HttpClient.js +4 -2
- package/src/client/ABRPublishing.js +126 -105
- package/src/client/ContentAccess.js +1 -0
- package/src/client/ContentManagement.js +4 -2
- package/src/walletClient/Configuration.js +3 -2
- package/dist/AccessClient-min.js +0 -54
- package/dist/AccessClient-node-min.js +0 -74
- package/dist/src/AccessClient.js +0 -798
- package/dist/src/LimitedMap.js +0 -120
- package/dist/src/client/Access.js +0 -1
- package/dist/src/client/Management.js +0 -1606
- package/dist/src/contracts/AccessIndexor.js +0 -831
- package/dist/src/contracts/Accessible.js +0 -31
- package/dist/src/contracts/AdmgrAdvertisement.js +0 -695
- package/dist/src/contracts/AdmgrCampaign.js +0 -648
- package/dist/src/contracts/AdmgrCampaignManager.js +0 -493
- package/dist/src/contracts/AdmgrCommercialOffering.js +0 -622
- package/dist/src/contracts/AdmgrCommercialOfferingManager.js +0 -413
- package/dist/src/contracts/AdmgrMarketPlace.js +0 -413
- package/dist/src/contracts/AvailsDelivery.js +0 -535
- package/dist/src/contracts/BaseAccessControlGroup.js +0 -1221
- package/dist/src/contracts/BaseAccessWallet.js +0 -1575
- package/dist/src/contracts/BaseAccessWalletFactory.js +0 -93
- package/dist/src/contracts/BaseContent.js +0 -1104
- package/dist/src/contracts/BaseContentFactory.js +0 -99
- package/dist/src/contracts/BaseContentFactoryExt.js +0 -219
- package/dist/src/contracts/BaseContentSpace.js +0 -1346
- package/dist/src/contracts/BaseContentType.js +0 -353
- package/dist/src/contracts/BaseFactory.js +0 -107
- package/dist/src/contracts/BaseGroupFactory.js +0 -93
- package/dist/src/contracts/BaseLibrary.js +0 -1035
- package/dist/src/contracts/BaseLibraryFactory.js +0 -96
- package/dist/src/contracts/Certifyer.js +0 -87
- package/dist/src/contracts/Container.js +0 -543
- package/dist/src/contracts/Content.js +0 -432
- package/dist/src/contracts/Editable.js +0 -295
- package/dist/src/contracts/FactorySpace.js +0 -57
- package/dist/src/contracts/KmsSpace.js +0 -52
- package/dist/src/contracts/LvProvider.js +0 -512
- package/dist/src/contracts/LvRecordableStream.js +0 -1026
- package/dist/src/contracts/LvRecording.js +0 -627
- package/dist/src/contracts/LvStreamRightsHolder.js +0 -551
- package/dist/src/contracts/MetaObject.js +0 -110
- package/dist/src/contracts/Node.js +0 -167
- package/dist/src/contracts/NodeSpace.js +0 -18
- package/dist/src/contracts/NodeSpaceImpl.js +0 -273
- package/dist/src/contracts/Ownable.js +0 -87
- package/dist/src/contracts/PaymentService.js +0 -616
- package/dist/src/contracts/Precompile.js +0 -15
- package/dist/src/contracts/SampleContentAdMarketplace.js +0 -564
- package/dist/src/contracts/SampleContentAdvertising.js +0 -444
- package/dist/src/contracts/SampleContentHelloWorld.js +0 -459
- package/dist/src/contracts/SampleContentLicensing.js +0 -618
- package/dist/src/contracts/SampleContentSigned.js +0 -447
- package/dist/src/contracts/SampleInstance.js +0 -438
- package/dist/src/contracts/SampleInstanceFactory.js +0 -451
- package/dist/src/contracts/Transactable.js +0 -82
- package/dist/src/contracts/UserSpace.js +0 -18
- package/dist/src/contracts/UserSpaceImpl.js +0 -43
- package/dist/src/contracts/Utils.js +0 -18
- package/dist/src/contracts/Verifier.js +0 -53
- package/dist/src/contracts/strings.js +0 -4
- package/dist/src/contracts/v2/BaseContentFactoryExt.js +0 -219
- package/dist/src/contracts/v2/FactorySpace.js +0 -57
- package/dist/src/contracts/v2/KmsSpace.js +0 -52
- package/dist/src/contracts/v2/NodeSpaceImpl.js +0 -273
- package/dist/src/contracts/v2/UserSpaceImpl.js +0 -43
- package/dist/src/marketplaceClient/ClientMethods.js +0 -1918
- package/dist/src/marketplaceClient/Configuration.js +0 -29
- package/dist/src/marketplaceClient/Utils.js +0 -304
- package/dist/src/marketplaceClient/index.js +0 -1553
- package/utilities/ListAccessGroups.js +0 -34
package/dist/src/Crypto.js
CHANGED
|
@@ -1,92 +1,69 @@
|
|
|
1
1
|
var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
2
|
-
|
|
3
2
|
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
4
|
-
|
|
5
3
|
if (typeof globalThis.Buffer === "undefined") {
|
|
6
4
|
globalThis.Buffer = require("buffer/").Buffer;
|
|
7
5
|
}
|
|
8
|
-
|
|
9
6
|
var bs58 = require("bs58");
|
|
10
|
-
|
|
11
7
|
var Stream = require("stream");
|
|
12
|
-
|
|
13
8
|
var Utils = require("./Utils");
|
|
14
|
-
|
|
15
9
|
if (typeof crypto === "undefined") {
|
|
16
10
|
var _crypto = require("crypto");
|
|
17
|
-
|
|
18
11
|
_crypto.getRandomValues = function (arr) {
|
|
19
12
|
return _crypto.randomBytes(arr.length);
|
|
20
13
|
};
|
|
21
|
-
|
|
22
14
|
globalThis.crypto = _crypto;
|
|
23
15
|
}
|
|
24
|
-
|
|
25
16
|
var _ElvCrypto;
|
|
26
|
-
|
|
27
17
|
switch (Utils.Platform()) {
|
|
28
18
|
case Utils.PLATFORM_REACT_NATIVE:
|
|
29
19
|
_ElvCrypto = require("@eluvio/crypto/dist/elv-crypto.bundle.externals")["default"];
|
|
30
20
|
break;
|
|
31
|
-
|
|
32
21
|
case Utils.PLATFORM_WEB:
|
|
33
22
|
_ElvCrypto = require("@eluvio/crypto/dist/elv-crypto.bundle.externals")["default"];
|
|
34
23
|
break;
|
|
35
|
-
|
|
36
24
|
default:
|
|
37
25
|
_ElvCrypto = require("@eluvio/crypto/dist/elv-crypto.bundle.node")["default"];
|
|
38
26
|
break;
|
|
39
27
|
}
|
|
28
|
+
|
|
40
29
|
/**
|
|
41
30
|
* @namespace
|
|
42
31
|
* @description This namespace contains cryptographic helper methods to encrypt and decrypt
|
|
43
32
|
* data with automatic handling of keys
|
|
44
33
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
34
|
var Crypto = {
|
|
48
35
|
ElvCrypto: function () {
|
|
49
36
|
var _ElvCrypto2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
50
37
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
51
|
-
while (1) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
}
|
|
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();
|
|
82
61
|
}
|
|
83
62
|
}, _callee, null, [[0, 8]]);
|
|
84
63
|
}));
|
|
85
|
-
|
|
86
64
|
function ElvCrypto() {
|
|
87
65
|
return _ElvCrypto2.apply(this, arguments);
|
|
88
66
|
}
|
|
89
|
-
|
|
90
67
|
return ElvCrypto;
|
|
91
68
|
}(),
|
|
92
69
|
EncryptedSize: function EncryptedSize(clearSize) {
|
|
@@ -94,11 +71,9 @@ var Crypto = {
|
|
|
94
71
|
var blocks = Math.floor(clearSize / clearBlockSize);
|
|
95
72
|
var encryptedBlockSize = Crypto.EncryptedBlockSize(clearBlockSize);
|
|
96
73
|
var encryptedFileSize = blocks * encryptedBlockSize;
|
|
97
|
-
|
|
98
74
|
if (clearSize % clearBlockSize !== 0) {
|
|
99
75
|
encryptedFileSize += Crypto.EncryptedBlockSize(clearSize % clearBlockSize);
|
|
100
76
|
}
|
|
101
|
-
|
|
102
77
|
return encryptedFileSize;
|
|
103
78
|
},
|
|
104
79
|
EncryptedBlockSize: function EncryptedBlockSize(clearSize) {
|
|
@@ -109,43 +84,35 @@ var Crypto = {
|
|
|
109
84
|
var clearElementByteSize = 12 * (MODBYTES_384_58 - 1);
|
|
110
85
|
var encElementByteSize = 12 * MODBYTES_384_58;
|
|
111
86
|
var encryptedBlockSize = Math.floor(clearSize / clearElementByteSize) * encElementByteSize;
|
|
112
|
-
|
|
113
87
|
if (clearSize % clearElementByteSize !== 0) {
|
|
114
88
|
encryptedBlockSize += encElementByteSize;
|
|
115
89
|
}
|
|
116
|
-
|
|
117
90
|
return reencrypt ? encryptedBlockSize + targetEncBlockOverhead : encryptedBlockSize + primaryEncBlockOverhead;
|
|
118
91
|
},
|
|
119
92
|
EncryptConk: function EncryptConk(conk, publicKey) {
|
|
120
93
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
121
94
|
var elvCrypto, _yield$elvCrypto$encr, data, ephemeralKey, tag, cap;
|
|
122
|
-
|
|
123
95
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
124
|
-
while (1) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
case 13:
|
|
146
|
-
case "end":
|
|
147
|
-
return _context2.stop();
|
|
148
|
-
}
|
|
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();
|
|
149
116
|
}
|
|
150
117
|
}, _callee2);
|
|
151
118
|
}))();
|
|
@@ -154,26 +121,22 @@ var Crypto = {
|
|
|
154
121
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
155
122
|
var elvCrypto, ephemeralKey, tag, data, cap;
|
|
156
123
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
157
|
-
while (1) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
case 10:
|
|
174
|
-
case "end":
|
|
175
|
-
return _context3.stop();
|
|
176
|
-
}
|
|
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();
|
|
177
140
|
}
|
|
178
141
|
}, _callee3);
|
|
179
142
|
}))();
|
|
@@ -181,31 +144,26 @@ var Crypto = {
|
|
|
181
144
|
GeneratePrimaryConk: function GeneratePrimaryConk(_ref) {
|
|
182
145
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
183
146
|
var spaceId, objectId, elvCrypto, _elvCrypto$generatePr, secretKey, publicKey, symmetricKey;
|
|
184
|
-
|
|
185
147
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
186
|
-
while (1) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
case 7:
|
|
206
|
-
case "end":
|
|
207
|
-
return _context4.stop();
|
|
208
|
-
}
|
|
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();
|
|
209
167
|
}
|
|
210
168
|
}, _callee4);
|
|
211
169
|
}))();
|
|
@@ -213,26 +171,21 @@ var Crypto = {
|
|
|
213
171
|
GenerateTargetConk: function GenerateTargetConk() {
|
|
214
172
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
215
173
|
var elvCrypto, _elvCrypto$generateTa, secretKey, publicKey;
|
|
216
|
-
|
|
217
174
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
218
|
-
while (1) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
case 5:
|
|
233
|
-
case "end":
|
|
234
|
-
return _context5.stop();
|
|
235
|
-
}
|
|
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();
|
|
236
189
|
}
|
|
237
190
|
}, _callee5);
|
|
238
191
|
}))();
|
|
@@ -241,7 +194,6 @@ var Crypto = {
|
|
|
241
194
|
var keyToBytes = function keyToBytes(key) {
|
|
242
195
|
return new Uint8Array(bs58.decode(key.slice(4)));
|
|
243
196
|
};
|
|
244
|
-
|
|
245
197
|
return {
|
|
246
198
|
symmetricKey: keyToBytes(cap.symm_key),
|
|
247
199
|
secretKey: keyToBytes(cap.secret_key),
|
|
@@ -251,42 +203,34 @@ var Crypto = {
|
|
|
251
203
|
EncryptionContext: function EncryptionContext(cap) {
|
|
252
204
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
253
205
|
var elvCrypto, _Crypto$CapToConk, symmetricKey, secretKey, publicKey, context, type;
|
|
254
|
-
|
|
255
206
|
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
256
|
-
while (1) {
|
|
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
|
-
case 6:
|
|
282
|
-
case "end":
|
|
283
|
-
return _context6.stop();
|
|
284
|
-
}
|
|
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();
|
|
285
230
|
}
|
|
286
231
|
}, _callee6);
|
|
287
232
|
}))();
|
|
288
233
|
},
|
|
289
|
-
|
|
290
234
|
/**
|
|
291
235
|
* Encrypt data with headers
|
|
292
236
|
*
|
|
@@ -300,108 +244,86 @@ var Crypto = {
|
|
|
300
244
|
var _Encrypt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(cap, data) {
|
|
301
245
|
var stream, dataArray, i, end, encryptedChunks;
|
|
302
246
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
303
|
-
while (1) {
|
|
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
|
-
_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
|
-
});
|
|
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);
|
|
344
279
|
});
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
return _context7.stop();
|
|
352
|
-
}
|
|
280
|
+
});
|
|
281
|
+
case 15:
|
|
282
|
+
return _context7.abrupt("return", Buffer.concat(encryptedChunks));
|
|
283
|
+
case 16:
|
|
284
|
+
case "end":
|
|
285
|
+
return _context7.stop();
|
|
353
286
|
}
|
|
354
287
|
}, _callee7);
|
|
355
288
|
}));
|
|
356
|
-
|
|
357
289
|
function Encrypt(_x, _x2) {
|
|
358
290
|
return _Encrypt.apply(this, arguments);
|
|
359
291
|
}
|
|
360
|
-
|
|
361
292
|
return Encrypt;
|
|
362
293
|
}(),
|
|
363
294
|
OpenEncryptionStream: function () {
|
|
364
295
|
var _OpenEncryptionStream = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(cap) {
|
|
365
296
|
var elvCrypto, _yield$Crypto$Encrypt, context, stream, cipher;
|
|
366
|
-
|
|
367
297
|
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
368
|
-
while (1) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
case 10:
|
|
391
|
-
case "end":
|
|
392
|
-
return _context8.stop();
|
|
393
|
-
}
|
|
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();
|
|
394
319
|
}
|
|
395
320
|
}, _callee8);
|
|
396
321
|
}));
|
|
397
|
-
|
|
398
322
|
function OpenEncryptionStream(_x3) {
|
|
399
323
|
return _OpenEncryptionStream.apply(this, arguments);
|
|
400
324
|
}
|
|
401
|
-
|
|
402
325
|
return OpenEncryptionStream;
|
|
403
326
|
}(),
|
|
404
|
-
|
|
405
327
|
/**
|
|
406
328
|
* Decrypt data with headers
|
|
407
329
|
*
|
|
@@ -415,91 +337,74 @@ var Crypto = {
|
|
|
415
337
|
var _Decrypt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(cap, encryptedData) {
|
|
416
338
|
var stream, dataArray, i, end, decryptedChunks;
|
|
417
339
|
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
418
|
-
while (1) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
stream.
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}).on("finish", function () {
|
|
440
|
-
resolve();
|
|
441
|
-
}).on("error", function (e) {
|
|
442
|
-
reject(e);
|
|
443
|
-
});
|
|
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);
|
|
444
361
|
});
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
return _context9.stop();
|
|
452
|
-
}
|
|
362
|
+
});
|
|
363
|
+
case 9:
|
|
364
|
+
return _context9.abrupt("return", Buffer.concat(decryptedChunks));
|
|
365
|
+
case 10:
|
|
366
|
+
case "end":
|
|
367
|
+
return _context9.stop();
|
|
453
368
|
}
|
|
454
369
|
}, _callee9);
|
|
455
370
|
}));
|
|
456
|
-
|
|
457
371
|
function Decrypt(_x4, _x5) {
|
|
458
372
|
return _Decrypt.apply(this, arguments);
|
|
459
373
|
}
|
|
460
|
-
|
|
461
374
|
return Decrypt;
|
|
462
375
|
}(),
|
|
463
376
|
OpenDecryptionStream: function () {
|
|
464
377
|
var _OpenDecryptionStream = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(cap) {
|
|
465
378
|
var elvCrypto, _yield$Crypto$Encrypt2, context, type, stream, decipher;
|
|
466
|
-
|
|
467
379
|
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
468
|
-
while (1) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
case 11:
|
|
492
|
-
case "end":
|
|
493
|
-
return _context10.stop();
|
|
494
|
-
}
|
|
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();
|
|
495
402
|
}
|
|
496
403
|
}, _callee10);
|
|
497
404
|
}));
|
|
498
|
-
|
|
499
405
|
function OpenDecryptionStream(_x6) {
|
|
500
406
|
return _OpenDecryptionStream.apply(this, arguments);
|
|
501
407
|
}
|
|
502
|
-
|
|
503
408
|
return OpenDecryptionStream;
|
|
504
409
|
}()
|
|
505
410
|
};
|