@super-protocol/sdk-js 0.15.0 → 0.15.1
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/build/TIIGenerator.js +129 -239
- package/build/connectors/BaseConnector.js +17 -47
- package/build/connectors/BlockchainConnector.js +222 -348
- package/build/connectors/BlockchainEventsListener.js +38 -92
- package/build/contracts/app.json +466 -35
- package/build/crypto/Crypto.js +63 -135
- package/build/crypto/index.js +1 -1
- package/build/crypto/nodejs/AES.js +62 -119
- package/build/crypto/nodejs/ARIA.js +61 -118
- package/build/crypto/nodejs/ECIES.js +51 -87
- package/build/crypto/nodejs/NativeCrypto.js +64 -118
- package/build/crypto/nodejs/RSA-Hybrid.js +54 -113
- package/build/index.d.ts +5 -0
- package/build/index.js +14 -2
- package/build/logger.d.ts +3 -1
- package/build/logger.js +2 -2
- package/build/models/EtlModel.js +65 -114
- package/build/models/Offer.js +227 -462
- package/build/models/Order.d.ts +4 -0
- package/build/models/Order.js +326 -559
- package/build/models/Provider.d.ts +2 -0
- package/build/models/Provider.js +74 -153
- package/build/models/TCB.js +67 -171
- package/build/models/TeeOffer.d.ts +1 -0
- package/build/models/TeeOffer.js +389 -731
- package/build/proto/Compression.js +20 -21
- package/build/proto/TRI.js +46 -50
- package/build/proto/TeeProperties.js +60 -66
- package/build/providers/storage/ChunksDownloadDecorator.js +125 -235
- package/build/providers/storage/S3StorageProvider.js +173 -298
- package/build/providers/storage/StorageAdapter.d.ts +60 -0
- package/build/providers/storage/StorageAdapter.js +317 -0
- package/build/providers/storage/StorageContentWriter.d.ts +39 -0
- package/build/providers/storage/StorageContentWriter.js +181 -0
- package/build/providers/storage/StorageKeyValueAdapter.d.ts +20 -0
- package/build/providers/storage/StorageKeyValueAdapter.js +152 -0
- package/build/providers/storage/StorageMetadataReader.d.ts +19 -0
- package/build/providers/storage/StorageMetadataReader.js +65 -0
- package/build/providers/storage/StorjAdapter.d.ts +19 -0
- package/build/providers/storage/StorjAdapter.js +62 -0
- package/build/providers/storage/StorjStorageProvider.js +138 -315
- package/build/providers/storage/getStorageProvider.js +7 -7
- package/build/providers/storage/types.d.ts +7 -0
- package/build/providers/storage/types.js +2 -0
- package/build/staticModels/ActiveOffers.js +32 -100
- package/build/staticModels/ActiveOrders.js +42 -120
- package/build/staticModels/BaseStaticModel.js +7 -10
- package/build/staticModels/Consensus.d.ts +4 -1
- package/build/staticModels/Consensus.js +164 -220
- package/build/staticModels/Deposits.js +109 -201
- package/build/staticModels/Marks.js +21 -82
- package/build/staticModels/ModelPackager.js +34 -84
- package/build/staticModels/Offers.js +140 -266
- package/build/staticModels/Orders.d.ts +1 -0
- package/build/staticModels/Orders.js +286 -429
- package/build/staticModels/ProviderRegistry.js +114 -225
- package/build/staticModels/Superpro.js +17 -63
- package/build/staticModels/SuperproToken.js +90 -169
- package/build/staticModels/TeeOffers.js +220 -416
- package/build/store.js +2 -2
- package/build/types/HardwareInfo.js +2 -2
- package/build/types/Order.js +4 -4
- package/build/types/Provider.js +1 -1
- package/build/types/TeeOfferInfo.js +1 -1
- package/build/types/TeeOfferOption.js +2 -2
- package/build/types/TeeOfferSlot.js +2 -2
- package/build/types/ValueOfferSlot.js +3 -3
- package/build/utils/Monitoring.js +24 -28
- package/build/utils/NonceTracker.js +56 -121
- package/build/utils/PubSub.d.ts +9 -0
- package/build/utils/PubSub.js +36 -0
- package/build/utils/TxManager.js +121 -215
- package/build/utils/compressors/GzipCompressor.js +13 -50
- package/build/utils/compressors/UncompressedCompressor.js +10 -13
- package/build/utils/helpers/tryWithInterval.js +34 -78
- package/build/utils/resourceLoaders/BaseResourceLoader.js +26 -78
- package/build/utils/resourceLoaders/StorageProviderLoader.js +33 -97
- package/build/utils/resourceLoaders/UrlResourceLoader.js +29 -93
- package/build/utils/resourceLoaders/getResourceLoader.js +6 -6
- package/build/utils.js +60 -105
- package/package.json +4 -1
package/build/crypto/Crypto.js
CHANGED
|
@@ -8,45 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
function Crypto() {
|
|
49
|
-
}
|
|
15
|
+
const dto_js_1 = require("@super-protocol/dto-js");
|
|
16
|
+
const AES_1 = __importDefault(require("./nodejs/AES"));
|
|
17
|
+
const ARIA_1 = __importDefault(require("./nodejs/ARIA"));
|
|
18
|
+
const ECIES_1 = __importDefault(require("./nodejs/ECIES"));
|
|
19
|
+
const RSA_Hybrid_1 = __importDefault(require("./nodejs/RSA-Hybrid"));
|
|
20
|
+
class Crypto {
|
|
50
21
|
/**
|
|
51
22
|
* Used to encrypt data before sending it to blockchain
|
|
52
23
|
* @param algorithm - encryption algorithm
|
|
@@ -55,33 +26,22 @@ var Crypto = /** @class */ (function () {
|
|
|
55
26
|
* @param encoding - encoding of key and output data
|
|
56
27
|
* @returns {Promise<Encryption>} - object what contains encrypted data, key and spec to decryption
|
|
57
28
|
*/
|
|
58
|
-
|
|
59
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
case 1: return [4 /*yield*/, AES_1.default.encrypt(content, encryption)];
|
|
73
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
74
|
-
case 3: return [4 /*yield*/, ARIA_1.default.encrypt(content, encryption)];
|
|
75
|
-
case 4: return [2 /*return*/, _b.sent()];
|
|
76
|
-
case 5: return [4 /*yield*/, ECIES_1.default.encrypt(content, encryption)];
|
|
77
|
-
case 6: return [2 /*return*/, _b.sent()];
|
|
78
|
-
case 7: return [4 /*yield*/, RSA_Hybrid_1.default.encrypt(content, encryption)];
|
|
79
|
-
case 8: return [2 /*return*/, _b.sent()];
|
|
80
|
-
case 9: throw Error("".concat(encryption.algo, " algorithm not supported"));
|
|
81
|
-
}
|
|
82
|
-
});
|
|
29
|
+
static encrypt(content, encryption) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
switch (encryption.algo) {
|
|
32
|
+
case dto_js_1.CryptoAlgorithm.AES:
|
|
33
|
+
return yield AES_1.default.encrypt(content, encryption);
|
|
34
|
+
case dto_js_1.CryptoAlgorithm.ARIA:
|
|
35
|
+
return yield ARIA_1.default.encrypt(content, encryption);
|
|
36
|
+
case dto_js_1.CryptoAlgorithm.ECIES:
|
|
37
|
+
return yield ECIES_1.default.encrypt(content, encryption);
|
|
38
|
+
case dto_js_1.CryptoAlgorithm.RSAHybrid:
|
|
39
|
+
return yield RSA_Hybrid_1.default.encrypt(content, encryption);
|
|
40
|
+
default:
|
|
41
|
+
throw Error(`${encryption.algo} algorithm not supported`);
|
|
42
|
+
}
|
|
83
43
|
});
|
|
84
|
-
}
|
|
44
|
+
}
|
|
85
45
|
/**
|
|
86
46
|
* Encrypts data stream
|
|
87
47
|
* @param inputStream - path to file that will be encrypted
|
|
@@ -90,92 +50,60 @@ var Crypto = /** @class */ (function () {
|
|
|
90
50
|
* @param key – key that will be used to encrypt data
|
|
91
51
|
* @returns {Promise<Encryption>} - encryption info
|
|
92
52
|
*/
|
|
93
|
-
|
|
94
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return [3 /*break*/, 7];
|
|
106
|
-
case 1: return [4 /*yield*/, AES_1.default.encryptStream(inputStream, outputStream, encryption)];
|
|
107
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
108
|
-
case 3: return [4 /*yield*/, ARIA_1.default.encryptStream(inputStream, outputStream, encryption)];
|
|
109
|
-
case 4: return [2 /*return*/, _b.sent()];
|
|
110
|
-
case 5: return [4 /*yield*/, RSA_Hybrid_1.default.encryptStream(inputStream, outputStream, encryption)];
|
|
111
|
-
case 6: return [2 /*return*/, _b.sent()];
|
|
112
|
-
case 7: throw Error("".concat(encryption.algo, " algorithm not supported"));
|
|
113
|
-
}
|
|
114
|
-
});
|
|
53
|
+
static encryptStream(inputStream, outputStream, encryption) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
switch (encryption.algo) {
|
|
56
|
+
case dto_js_1.CryptoAlgorithm.AES:
|
|
57
|
+
return yield AES_1.default.encryptStream(inputStream, outputStream, encryption);
|
|
58
|
+
case dto_js_1.CryptoAlgorithm.ARIA:
|
|
59
|
+
return yield ARIA_1.default.encryptStream(inputStream, outputStream, encryption);
|
|
60
|
+
case dto_js_1.CryptoAlgorithm.RSAHybrid:
|
|
61
|
+
return yield RSA_Hybrid_1.default.encryptStream(inputStream, outputStream, encryption);
|
|
62
|
+
default:
|
|
63
|
+
throw Error(`${encryption.algo} algorithm not supported`);
|
|
64
|
+
}
|
|
115
65
|
});
|
|
116
|
-
}
|
|
66
|
+
}
|
|
117
67
|
/**
|
|
118
68
|
* Used to decrypt data from blockchain
|
|
119
69
|
* @param encryption - object what contains encrypted data, key and spec to decryption
|
|
120
70
|
* @returns {Promise<string>} - decrypted string
|
|
121
71
|
*/
|
|
122
|
-
|
|
123
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
case 1: return [4 /*yield*/, AES_1.default.decrypt(encryption)];
|
|
137
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
138
|
-
case 3: return [4 /*yield*/, ARIA_1.default.decrypt(encryption)];
|
|
139
|
-
case 4: return [2 /*return*/, _b.sent()];
|
|
140
|
-
case 5: return [4 /*yield*/, ECIES_1.default.decrypt(encryption)];
|
|
141
|
-
case 6: return [2 /*return*/, _b.sent()];
|
|
142
|
-
case 7: return [4 /*yield*/, RSA_Hybrid_1.default.decrypt(encryption)];
|
|
143
|
-
case 8: return [2 /*return*/, _b.sent()];
|
|
144
|
-
case 9: throw Error("".concat(encryption.algo, " algorithm not supported"));
|
|
145
|
-
}
|
|
146
|
-
});
|
|
72
|
+
static decrypt(encryption) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
switch (encryption.algo) {
|
|
75
|
+
case dto_js_1.CryptoAlgorithm.AES:
|
|
76
|
+
return yield AES_1.default.decrypt(encryption);
|
|
77
|
+
case dto_js_1.CryptoAlgorithm.ARIA:
|
|
78
|
+
return yield ARIA_1.default.decrypt(encryption);
|
|
79
|
+
case dto_js_1.CryptoAlgorithm.ECIES:
|
|
80
|
+
return yield ECIES_1.default.decrypt(encryption);
|
|
81
|
+
case dto_js_1.CryptoAlgorithm.RSAHybrid:
|
|
82
|
+
return yield RSA_Hybrid_1.default.decrypt(encryption);
|
|
83
|
+
default:
|
|
84
|
+
throw Error(`${encryption.algo} algorithm not supported`);
|
|
85
|
+
}
|
|
147
86
|
});
|
|
148
|
-
}
|
|
87
|
+
}
|
|
149
88
|
/**
|
|
150
89
|
* Decrypts data stream
|
|
151
90
|
* @param inputStream - stream with data to decrypt
|
|
152
91
|
* @param outputStream - stream where the decrypted data will be written
|
|
153
92
|
* @param encryption – encryption info
|
|
154
93
|
*/
|
|
155
|
-
|
|
156
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return [3 /*break*/, 7];
|
|
168
|
-
case 1: return [4 /*yield*/, AES_1.default.decryptStream(inputStream, outputStream, encryption)];
|
|
169
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
170
|
-
case 3: return [4 /*yield*/, ARIA_1.default.decryptStream(inputStream, outputStream, encryption)];
|
|
171
|
-
case 4: return [2 /*return*/, _b.sent()];
|
|
172
|
-
case 5: return [4 /*yield*/, RSA_Hybrid_1.default.decryptStream(inputStream, outputStream, encryption)];
|
|
173
|
-
case 6: return [2 /*return*/, _b.sent()];
|
|
174
|
-
case 7: throw Error("".concat(encryption.algo, " algorithm not supported"));
|
|
175
|
-
}
|
|
176
|
-
});
|
|
94
|
+
static decryptStream(inputStream, outputStream, encryption) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
switch (encryption.algo) {
|
|
97
|
+
case dto_js_1.CryptoAlgorithm.AES:
|
|
98
|
+
return yield AES_1.default.decryptStream(inputStream, outputStream, encryption);
|
|
99
|
+
case dto_js_1.CryptoAlgorithm.ARIA:
|
|
100
|
+
return yield ARIA_1.default.decryptStream(inputStream, outputStream, encryption);
|
|
101
|
+
case dto_js_1.CryptoAlgorithm.RSAHybrid:
|
|
102
|
+
return yield RSA_Hybrid_1.default.decryptStream(inputStream, outputStream, encryption);
|
|
103
|
+
default:
|
|
104
|
+
throw Error(`${encryption.algo} algorithm not supported`);
|
|
105
|
+
}
|
|
177
106
|
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
}());
|
|
107
|
+
}
|
|
108
|
+
}
|
|
181
109
|
exports.default = Crypto;
|
package/build/crypto/index.js
CHANGED
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const Crypto_1 = __importDefault(require("./Crypto"));
|
|
7
7
|
exports.default = Crypto_1.default;
|
|
@@ -8,62 +8,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
ciphertext: encrypted.ciphertext,
|
|
61
|
-
iv: encrypted.iv,
|
|
62
|
-
mac: encrypted.mac,
|
|
63
|
-
}];
|
|
64
|
-
});
|
|
15
|
+
const dto_js_1 = require("@super-protocol/dto-js");
|
|
16
|
+
const NativeCrypto_1 = __importDefault(require("./NativeCrypto"));
|
|
17
|
+
class AES {
|
|
18
|
+
static encrypt(content, encryption) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
if (!encryption.key)
|
|
21
|
+
throw Error("Encryption key is not provided");
|
|
22
|
+
encryption.cipher = encryption.cipher || dto_js_1.Cipher.AES_256_GCM;
|
|
23
|
+
const keyBuffer = Buffer.from(encryption.key, encryption.encoding);
|
|
24
|
+
const encrypted = NativeCrypto_1.default.encrypt(keyBuffer, content, encryption.cipher);
|
|
25
|
+
return {
|
|
26
|
+
algo: dto_js_1.CryptoAlgorithm.AES,
|
|
27
|
+
encoding: encryption.encoding,
|
|
28
|
+
cipher: encryption.cipher,
|
|
29
|
+
ciphertext: encrypted.ciphertext,
|
|
30
|
+
iv: encrypted.iv,
|
|
31
|
+
mac: encrypted.mac,
|
|
32
|
+
};
|
|
65
33
|
});
|
|
66
|
-
}
|
|
34
|
+
}
|
|
67
35
|
/**
|
|
68
36
|
* Encrypts data stream
|
|
69
37
|
* @param inputStream - path to file that will be encrypted
|
|
@@ -72,81 +40,56 @@ var AES = /** @class */ (function () {
|
|
|
72
40
|
* @param key – key that will be used to encrypt data
|
|
73
41
|
* @returns {Promise<Encryption>} - encryption info
|
|
74
42
|
*/
|
|
75
|
-
|
|
76
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
encoding: encryption.encoding,
|
|
91
|
-
cipher: encryption.cipher,
|
|
92
|
-
ciphertext: encrypted.ciphertext,
|
|
93
|
-
iv: encrypted.iv,
|
|
94
|
-
mac: encrypted.mac,
|
|
95
|
-
}];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
43
|
+
static encryptStream(inputStream, outputStream, encryption) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (!encryption.key)
|
|
46
|
+
throw Error("Encryption key is not provided");
|
|
47
|
+
encryption.cipher = encryption.cipher || dto_js_1.Cipher.AES_256_GCM;
|
|
48
|
+
const keyBuffer = Buffer.from(encryption.key, encryption.encoding);
|
|
49
|
+
const encrypted = yield NativeCrypto_1.default.encryptStream(keyBuffer, inputStream, outputStream, encryption.cipher);
|
|
50
|
+
return {
|
|
51
|
+
algo: encryption.algo,
|
|
52
|
+
encoding: encryption.encoding,
|
|
53
|
+
cipher: encryption.cipher,
|
|
54
|
+
ciphertext: encrypted.ciphertext,
|
|
55
|
+
iv: encrypted.iv,
|
|
56
|
+
mac: encrypted.mac,
|
|
57
|
+
};
|
|
98
58
|
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (encryption.mac) {
|
|
113
|
-
params.mac = Buffer.from(encryption.mac, encryption.encoding);
|
|
114
|
-
}
|
|
115
|
-
return [4 /*yield*/, NativeCrypto_1.default.decrypt(key, encryption.ciphertext, encryption.cipher, params, encryption.encoding)];
|
|
116
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
59
|
+
}
|
|
60
|
+
static decrypt(encryption) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
if (!encryption.key)
|
|
63
|
+
throw Error("Decryption key is not provided");
|
|
64
|
+
const key = Buffer.from(encryption.key, encryption.encoding);
|
|
65
|
+
const params = {
|
|
66
|
+
iv: Buffer.from(encryption.iv, encryption.encoding),
|
|
67
|
+
};
|
|
68
|
+
if (encryption.mac) {
|
|
69
|
+
params.mac = Buffer.from(encryption.mac, encryption.encoding);
|
|
70
|
+
}
|
|
71
|
+
return yield NativeCrypto_1.default.decrypt(key, encryption.ciphertext, encryption.cipher, params, encryption.encoding);
|
|
119
72
|
});
|
|
120
|
-
}
|
|
73
|
+
}
|
|
121
74
|
/**
|
|
122
75
|
* Decrypts data stream
|
|
123
76
|
* @param inputStream - stream with data to decrypt
|
|
124
77
|
* @param outputStream - stream where the decrypted data will be written
|
|
125
78
|
* @param encryption – encryption info
|
|
126
79
|
*/
|
|
127
|
-
|
|
128
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (encryption.mac) {
|
|
140
|
-
params.mac = Buffer.from(encryption.mac, encryption.encoding);
|
|
141
|
-
}
|
|
142
|
-
return [4 /*yield*/, NativeCrypto_1.default.decryptStream(key, inputStream, outputStream, encryption.cipher, params)];
|
|
143
|
-
case 1:
|
|
144
|
-
_a.sent();
|
|
145
|
-
return [2 /*return*/];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
80
|
+
static decryptStream(inputStream, outputStream, encryption) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (!encryption.key)
|
|
83
|
+
throw Error("Decryption key is not provided");
|
|
84
|
+
const key = Buffer.from(encryption.key, encryption.encoding);
|
|
85
|
+
const params = {
|
|
86
|
+
iv: Buffer.from(encryption.iv, encryption.encoding),
|
|
87
|
+
};
|
|
88
|
+
if (encryption.mac) {
|
|
89
|
+
params.mac = Buffer.from(encryption.mac, encryption.encoding);
|
|
90
|
+
}
|
|
91
|
+
yield NativeCrypto_1.default.decryptStream(key, inputStream, outputStream, encryption.cipher, params);
|
|
148
92
|
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
}());
|
|
93
|
+
}
|
|
94
|
+
}
|
|
152
95
|
exports.default = AES;
|