@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.
Files changed (79) hide show
  1. package/build/TIIGenerator.js +129 -239
  2. package/build/connectors/BaseConnector.js +17 -47
  3. package/build/connectors/BlockchainConnector.js +222 -348
  4. package/build/connectors/BlockchainEventsListener.js +38 -92
  5. package/build/contracts/app.json +0 -110
  6. package/build/crypto/Crypto.js +63 -135
  7. package/build/crypto/index.js +1 -1
  8. package/build/crypto/nodejs/AES.js +62 -119
  9. package/build/crypto/nodejs/ARIA.js +61 -118
  10. package/build/crypto/nodejs/ECIES.js +51 -87
  11. package/build/crypto/nodejs/NativeCrypto.js +64 -118
  12. package/build/crypto/nodejs/RSA-Hybrid.js +54 -113
  13. package/build/index.d.ts +5 -0
  14. package/build/index.js +14 -2
  15. package/build/logger.d.ts +3 -1
  16. package/build/logger.js +2 -2
  17. package/build/models/EtlModel.js +65 -114
  18. package/build/models/Offer.js +227 -462
  19. package/build/models/Order.js +324 -573
  20. package/build/models/Provider.js +72 -165
  21. package/build/models/TCB.js +67 -171
  22. package/build/models/TeeOffer.d.ts +1 -7
  23. package/build/models/TeeOffer.js +389 -758
  24. package/build/proto/Compression.js +20 -21
  25. package/build/proto/TRI.js +46 -50
  26. package/build/proto/TeeProperties.js +60 -66
  27. package/build/providers/storage/ChunksDownloadDecorator.js +125 -235
  28. package/build/providers/storage/S3StorageProvider.js +173 -298
  29. package/build/providers/storage/StorageAdapter.d.ts +60 -0
  30. package/build/providers/storage/StorageAdapter.js +317 -0
  31. package/build/providers/storage/StorageContentWriter.d.ts +39 -0
  32. package/build/providers/storage/StorageContentWriter.js +181 -0
  33. package/build/providers/storage/StorageKeyValueAdapter.d.ts +20 -0
  34. package/build/providers/storage/StorageKeyValueAdapter.js +152 -0
  35. package/build/providers/storage/StorageMetadataReader.d.ts +19 -0
  36. package/build/providers/storage/StorageMetadataReader.js +65 -0
  37. package/build/providers/storage/StorjAdapter.d.ts +19 -0
  38. package/build/providers/storage/StorjAdapter.js +62 -0
  39. package/build/providers/storage/StorjStorageProvider.js +138 -315
  40. package/build/providers/storage/getStorageProvider.js +7 -7
  41. package/build/providers/storage/types.d.ts +7 -0
  42. package/build/providers/storage/types.js +2 -0
  43. package/build/staticModels/ActiveOffers.js +32 -100
  44. package/build/staticModels/ActiveOrders.js +42 -120
  45. package/build/staticModels/BaseStaticModel.js +7 -10
  46. package/build/staticModels/Consensus.d.ts +2 -2
  47. package/build/staticModels/Consensus.js +157 -280
  48. package/build/staticModels/Deposits.js +109 -201
  49. package/build/staticModels/Marks.js +21 -82
  50. package/build/staticModels/ModelPackager.js +34 -84
  51. package/build/staticModels/Offers.js +140 -266
  52. package/build/staticModels/Orders.js +285 -472
  53. package/build/staticModels/ProviderRegistry.js +114 -225
  54. package/build/staticModels/Superpro.js +17 -63
  55. package/build/staticModels/SuperproToken.js +90 -169
  56. package/build/staticModels/TeeOffers.js +220 -416
  57. package/build/store.js +2 -2
  58. package/build/types/HardwareInfo.js +2 -2
  59. package/build/types/Order.d.ts +0 -6
  60. package/build/types/Order.js +4 -6
  61. package/build/types/Provider.js +1 -1
  62. package/build/types/TeeOfferInfo.js +1 -1
  63. package/build/types/TeeOfferOption.js +2 -2
  64. package/build/types/TeeOfferSlot.js +2 -2
  65. package/build/types/ValueOfferSlot.js +3 -3
  66. package/build/utils/Monitoring.js +24 -28
  67. package/build/utils/NonceTracker.js +56 -121
  68. package/build/utils/PubSub.d.ts +9 -0
  69. package/build/utils/PubSub.js +36 -0
  70. package/build/utils/TxManager.js +121 -215
  71. package/build/utils/compressors/GzipCompressor.js +13 -50
  72. package/build/utils/compressors/UncompressedCompressor.js +10 -13
  73. package/build/utils/helpers/tryWithInterval.js +34 -78
  74. package/build/utils/resourceLoaders/BaseResourceLoader.js +26 -78
  75. package/build/utils/resourceLoaders/StorageProviderLoader.js +33 -97
  76. package/build/utils/resourceLoaders/UrlResourceLoader.js +29 -93
  77. package/build/utils/resourceLoaders/getResourceLoader.js +6 -6
  78. package/build/utils.js +60 -105
  79. 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
- var dto_js_1 = require("@super-protocol/dto-js");
43
- var NativeCrypto_1 = __importDefault(require("./NativeCrypto"));
44
- var AES = /** @class */ (function () {
45
- function AES() {
46
- }
47
- AES.encrypt = function (content, encryption) {
48
- return __awaiter(this, void 0, void 0, function () {
49
- var keyBuffer, encrypted;
50
- return __generator(this, function (_a) {
51
- if (!encryption.key)
52
- throw Error("Encryption key is not provided");
53
- encryption.cipher = encryption.cipher || dto_js_1.Cipher.AES_256_GCM;
54
- keyBuffer = Buffer.from(encryption.key, encryption.encoding);
55
- encrypted = NativeCrypto_1.default.encrypt(keyBuffer, content, encryption.cipher);
56
- return [2 /*return*/, {
57
- algo: dto_js_1.CryptoAlgorithm.AES,
58
- encoding: encryption.encoding,
59
- cipher: encryption.cipher,
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
- AES.encryptStream = function (inputStream, outputStream, encryption) {
76
- return __awaiter(this, void 0, void 0, function () {
77
- var keyBuffer, encrypted;
78
- return __generator(this, function (_a) {
79
- switch (_a.label) {
80
- case 0:
81
- if (!encryption.key)
82
- throw Error("Encryption key is not provided");
83
- encryption.cipher = encryption.cipher || dto_js_1.Cipher.AES_256_GCM;
84
- keyBuffer = Buffer.from(encryption.key, encryption.encoding);
85
- return [4 /*yield*/, NativeCrypto_1.default.encryptStream(keyBuffer, inputStream, outputStream, encryption.cipher)];
86
- case 1:
87
- encrypted = _a.sent();
88
- return [2 /*return*/, {
89
- algo: encryption.algo,
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
- AES.decrypt = function (encryption) {
101
- return __awaiter(this, void 0, void 0, function () {
102
- var key, params;
103
- return __generator(this, function (_a) {
104
- switch (_a.label) {
105
- case 0:
106
- if (!encryption.key)
107
- throw Error("Decryption key is not provided");
108
- key = Buffer.from(encryption.key, encryption.encoding);
109
- params = {
110
- iv: Buffer.from(encryption.iv, encryption.encoding),
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
- AES.decryptStream = function (inputStream, outputStream, encryption) {
128
- return __awaiter(this, void 0, void 0, function () {
129
- var key, params;
130
- return __generator(this, function (_a) {
131
- switch (_a.label) {
132
- case 0:
133
- if (!encryption.key)
134
- throw Error("Decryption key is not provided");
135
- key = Buffer.from(encryption.key, encryption.encoding);
136
- params = {
137
- iv: Buffer.from(encryption.iv, encryption.encoding),
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
- return AES;
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
- var dto_js_1 = require("@super-protocol/dto-js");
43
- var NativeCrypto_1 = __importDefault(require("./NativeCrypto"));
44
- var ARIA = /** @class */ (function () {
45
- function ARIA() {
46
- }
47
- ARIA.encrypt = function (content, encryption) {
48
- return __awaiter(this, void 0, void 0, function () {
49
- var keyBuffer, encrypted;
50
- return __generator(this, function (_a) {
51
- if (!encryption.key)
52
- throw Error("Encryption key is not provided");
53
- encryption.cipher = encryption.cipher || dto_js_1.Cipher.ARIA_256_GCM;
54
- keyBuffer = Buffer.from(encryption.key, encryption.encoding);
55
- encrypted = NativeCrypto_1.default.encrypt(keyBuffer, content, encryption.cipher);
56
- return [2 /*return*/, {
57
- algo: dto_js_1.CryptoAlgorithm.ARIA,
58
- encoding: encryption.encoding,
59
- cipher: encryption.cipher,
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
- ARIA.encryptStream = function (inputStream, outputStream, encryption) {
76
- return __awaiter(this, void 0, void 0, function () {
77
- var keyBuffer, encrypted;
78
- return __generator(this, function (_a) {
79
- switch (_a.label) {
80
- case 0:
81
- if (!encryption.key)
82
- throw Error("Encryption key is not provided");
83
- encryption.cipher = encryption.cipher || dto_js_1.Cipher.ARIA_256_GCM;
84
- keyBuffer = Buffer.from(encryption.key, encryption.encoding);
85
- return [4 /*yield*/, NativeCrypto_1.default.encryptStream(keyBuffer, inputStream, outputStream, encryption.cipher)];
86
- case 1:
87
- encrypted = _a.sent();
88
- return [2 /*return*/, {
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
- ARIA.decrypt = function (encryption) {
100
- return __awaiter(this, void 0, void 0, function () {
101
- var key, params;
102
- return __generator(this, function (_a) {
103
- switch (_a.label) {
104
- case 0:
105
- if (!encryption.key)
106
- throw Error("Decryption key is not provided");
107
- key = Buffer.from(encryption.key, encryption.encoding);
108
- params = {
109
- iv: Buffer.from(encryption.iv, encryption.encoding),
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
- ARIA.decryptStream = function (inputStream, outputStream, encryption) {
127
- return __awaiter(this, void 0, void 0, function () {
128
- var key, params;
129
- return __generator(this, function (_a) {
130
- switch (_a.label) {
131
- case 0:
132
- if (!encryption.key)
133
- throw Error("Decryption key is not provided");
134
- key = Buffer.from(encryption.key, encryption.encoding);
135
- params = {
136
- iv: Buffer.from(encryption.iv, encryption.encoding),
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
- return ARIA;
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
- var dto_js_1 = require("@super-protocol/dto-js");
43
- var crypto_1 = __importDefault(require("crypto"));
44
- var ECIES = /** @class */ (function () {
45
- function ECIES() {
46
- }
47
- ECIES.encrypt = function (content, encryption) {
48
- return __awaiter(this, void 0, void 0, function () {
49
- var ecdh, epk, pk, hash, cipherKey, macKey, iv, cipher, ct, dataToMac, mac;
50
- return __generator(this, function (_a) {
51
- if (!encryption.key)
52
- throw Error("Encryption key is not provided");
53
- ecdh = crypto_1.default.createECDH("secp256k1");
54
- ecdh.generateKeys("binary", "uncompressed");
55
- epk = ecdh.getPublicKey();
56
- pk = ecdh.computeSecret(Buffer.from(encryption.key, encryption.encoding));
57
- hash = crypto_1.default.createHash("sha512").update(pk).digest();
58
- cipherKey = hash.slice(0, 32), macKey = hash.slice(32);
59
- iv = crypto_1.default.randomBytes(16);
60
- cipher = crypto_1.default.createCipheriv("aes-256-cbc", cipherKey, iv);
61
- ct = cipher.update(content);
62
- ct = Buffer.concat([ct, cipher.final()]);
63
- dataToMac = Buffer.concat([iv, epk, ct]);
64
- mac = crypto_1.default.createHmac("sha256", macKey).update(dataToMac).digest();
65
- return [2 /*return*/, {
66
- iv: iv.toString(encryption.encoding),
67
- ephemPublicKey: epk.toString(encryption.encoding),
68
- mac: mac.toString(encryption.encoding),
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
- ECIES.decrypt = function (encryption) {
77
- return __awaiter(this, void 0, void 0, function () {
78
- var iv, epk, ct, mac, ecdh, pk, hash, cipherKey, macKey, m, decipher, pt, result;
79
- return __generator(this, function (_a) {
80
- if (!encryption.key)
81
- throw Error("Decryption key is not provided");
82
- 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);
83
- ecdh = crypto_1.default.createECDH("secp256k1");
84
- ecdh.setPrivateKey(Buffer.from(encryption.key, encryption.encoding));
85
- pk = ecdh.computeSecret(epk);
86
- hash = crypto_1.default.createHash("sha512").update(pk).digest();
87
- cipherKey = hash.slice(0, 32), macKey = hash.slice(32);
88
- m = crypto_1.default
89
- .createHmac("sha256", macKey)
90
- .update(Buffer.concat([iv, epk, ct]))
91
- .digest();
92
- if (m.compare(mac) !== 0 || mac.compare(m) !== 0) {
93
- throw new Error("Corrupted Ecies body: unmatched authentication code");
94
- }
95
- decipher = crypto_1.default.createDecipheriv("aes-256-cbc", cipherKey, iv);
96
- pt = decipher.update(ct);
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
- return ECIES;
103
- }());
66
+ }
67
+ }
104
68
  exports.default = ECIES;