@super-protocol/sdk-js 0.14.2-beta.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 +0 -110
- 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.js +324 -573
- package/build/models/Provider.js +72 -165
- package/build/models/TCB.js +67 -171
- package/build/models/TeeOffer.d.ts +1 -7
- package/build/models/TeeOffer.js +389 -758
- 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 +2 -2
- package/build/staticModels/Consensus.js +157 -280
- 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.js +285 -472
- 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.d.ts +0 -6
- package/build/types/Order.js +4 -6
- 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
|
@@ -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;
|
|
@@ -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 ARIA {
|
|
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.ARIA_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.ARIA,
|
|
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,80 +40,55 @@ var ARIA = /** @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
|
-
algo: dto_js_1.CryptoAlgorithm.ARIA,
|
|
90
|
-
encoding: encryption.encoding,
|
|
91
|
-
cipher: encryption.cipher,
|
|
92
|
-
iv: encrypted.iv,
|
|
93
|
-
mac: encrypted.mac,
|
|
94
|
-
}];
|
|
95
|
-
}
|
|
96
|
-
});
|
|
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.ARIA_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: dto_js_1.CryptoAlgorithm.ARIA,
|
|
52
|
+
encoding: encryption.encoding,
|
|
53
|
+
cipher: encryption.cipher,
|
|
54
|
+
iv: encrypted.iv,
|
|
55
|
+
mac: encrypted.mac,
|
|
56
|
+
};
|
|
97
57
|
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (encryption.mac) {
|
|
112
|
-
params.mac = Buffer.from(encryption.mac, encryption.encoding);
|
|
113
|
-
}
|
|
114
|
-
return [4 /*yield*/, NativeCrypto_1.default.decrypt(key, encryption.ciphertext, encryption.cipher, params, encryption.encoding)];
|
|
115
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
116
|
-
}
|
|
117
|
-
});
|
|
58
|
+
}
|
|
59
|
+
static decrypt(encryption) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
if (!encryption.key)
|
|
62
|
+
throw Error("Decryption key is not provided");
|
|
63
|
+
const key = Buffer.from(encryption.key, encryption.encoding);
|
|
64
|
+
const params = {
|
|
65
|
+
iv: Buffer.from(encryption.iv, encryption.encoding),
|
|
66
|
+
};
|
|
67
|
+
if (encryption.mac) {
|
|
68
|
+
params.mac = Buffer.from(encryption.mac, encryption.encoding);
|
|
69
|
+
}
|
|
70
|
+
return yield NativeCrypto_1.default.decrypt(key, encryption.ciphertext, encryption.cipher, params, encryption.encoding);
|
|
118
71
|
});
|
|
119
|
-
}
|
|
72
|
+
}
|
|
120
73
|
/**
|
|
121
74
|
* Decrypts data stream
|
|
122
75
|
* @param inputStream - stream with data to decrypt
|
|
123
76
|
* @param outputStream - stream where the decrypted data will be written
|
|
124
77
|
* @param encryption – encryption info
|
|
125
78
|
*/
|
|
126
|
-
|
|
127
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (encryption.mac) {
|
|
139
|
-
params.mac = Buffer.from(encryption.mac, encryption.encoding);
|
|
140
|
-
}
|
|
141
|
-
return [4 /*yield*/, NativeCrypto_1.default.decryptStream(key, inputStream, outputStream, encryption.cipher, params)];
|
|
142
|
-
case 1:
|
|
143
|
-
_a.sent();
|
|
144
|
-
return [2 /*return*/];
|
|
145
|
-
}
|
|
146
|
-
});
|
|
79
|
+
static decryptStream(inputStream, outputStream, encryption) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (!encryption.key)
|
|
82
|
+
throw Error("Decryption key is not provided");
|
|
83
|
+
const key = Buffer.from(encryption.key, encryption.encoding);
|
|
84
|
+
const params = {
|
|
85
|
+
iv: Buffer.from(encryption.iv, encryption.encoding),
|
|
86
|
+
};
|
|
87
|
+
if (encryption.mac) {
|
|
88
|
+
params.mac = Buffer.from(encryption.mac, encryption.encoding);
|
|
89
|
+
}
|
|
90
|
+
yield NativeCrypto_1.default.decryptStream(key, inputStream, outputStream, encryption.cipher, params);
|
|
147
91
|
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
}());
|
|
92
|
+
}
|
|
93
|
+
}
|
|
151
94
|
exports.default = ARIA;
|
|
@@ -8,97 +8,61 @@ 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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
mac
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
encoding: encryption.encoding,
|
|
70
|
-
algo: dto_js_1.CryptoAlgorithm.ECIES,
|
|
71
|
-
ciphertext: ct.toString(encryption.encoding),
|
|
72
|
-
}];
|
|
73
|
-
});
|
|
15
|
+
const dto_js_1 = require("@super-protocol/dto-js");
|
|
16
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
17
|
+
class ECIES {
|
|
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
|
+
const ecdh = crypto_1.default.createECDH("secp256k1");
|
|
23
|
+
ecdh.generateKeys("binary", "uncompressed");
|
|
24
|
+
const epk = ecdh.getPublicKey();
|
|
25
|
+
const pk = ecdh.computeSecret(Buffer.from(encryption.key, encryption.encoding));
|
|
26
|
+
const hash = crypto_1.default.createHash("sha512").update(pk).digest();
|
|
27
|
+
const cipherKey = hash.slice(0, 32), macKey = hash.slice(32);
|
|
28
|
+
const iv = crypto_1.default.randomBytes(16);
|
|
29
|
+
const cipher = crypto_1.default.createCipheriv("aes-256-cbc", cipherKey, iv);
|
|
30
|
+
let ct = cipher.update(content);
|
|
31
|
+
ct = Buffer.concat([ct, cipher.final()]);
|
|
32
|
+
const dataToMac = Buffer.concat([iv, epk, ct]);
|
|
33
|
+
const mac = crypto_1.default.createHmac("sha256", macKey).update(dataToMac).digest();
|
|
34
|
+
return {
|
|
35
|
+
iv: iv.toString(encryption.encoding),
|
|
36
|
+
ephemPublicKey: epk.toString(encryption.encoding),
|
|
37
|
+
mac: mac.toString(encryption.encoding),
|
|
38
|
+
encoding: encryption.encoding,
|
|
39
|
+
algo: dto_js_1.CryptoAlgorithm.ECIES,
|
|
40
|
+
ciphertext: ct.toString(encryption.encoding),
|
|
41
|
+
};
|
|
74
42
|
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
result = Buffer.concat([pt, decipher.final()]);
|
|
98
|
-
return [2 /*return*/, result.toString("binary")];
|
|
99
|
-
});
|
|
43
|
+
}
|
|
44
|
+
static decrypt(encryption) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
if (!encryption.key)
|
|
47
|
+
throw Error("Decryption key is not provided");
|
|
48
|
+
const iv = Buffer.from(encryption.iv, encryption.encoding), epk = Buffer.from(encryption.ephemPublicKey, encryption.encoding), ct = Buffer.from(encryption.ciphertext, encryption.encoding), mac = Buffer.from(encryption.mac, encryption.encoding);
|
|
49
|
+
const ecdh = crypto_1.default.createECDH("secp256k1");
|
|
50
|
+
ecdh.setPrivateKey(Buffer.from(encryption.key, encryption.encoding));
|
|
51
|
+
const pk = ecdh.computeSecret(epk);
|
|
52
|
+
const hash = crypto_1.default.createHash("sha512").update(pk).digest();
|
|
53
|
+
const cipherKey = hash.slice(0, 32), macKey = hash.slice(32);
|
|
54
|
+
const m = crypto_1.default
|
|
55
|
+
.createHmac("sha256", macKey)
|
|
56
|
+
.update(Buffer.concat([iv, epk, ct]))
|
|
57
|
+
.digest();
|
|
58
|
+
if (m.compare(mac) !== 0 || mac.compare(m) !== 0) {
|
|
59
|
+
throw new Error("Corrupted Ecies body: unmatched authentication code");
|
|
60
|
+
}
|
|
61
|
+
const decipher = crypto_1.default.createDecipheriv("aes-256-cbc", cipherKey, iv);
|
|
62
|
+
const pt = decipher.update(ct);
|
|
63
|
+
const result = Buffer.concat([pt, decipher.final()]);
|
|
64
|
+
return result.toString("binary");
|
|
100
65
|
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
}());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
104
68
|
exports.default = ECIES;
|