@super-protocol/sdk-js 0.6.0
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/BlockchainConnector.d.ts +48 -0
- package/build/BlockchainConnector.js +259 -0
- package/build/TIIGenerator.d.ts +21 -0
- package/build/TIIGenerator.js +251 -0
- package/build/constants.d.ts +7 -0
- package/build/constants.js +10 -0
- package/build/contracts/ActiveOffersList.json +131 -0
- package/build/contracts/ActiveOrdersList.json +74 -0
- package/build/contracts/Marks.json +79 -0
- package/build/contracts/Offers.json +999 -0
- package/build/contracts/Orders.json +984 -0
- package/build/contracts/Providers.json +440 -0
- package/build/contracts/ProvidersOffers.json +254 -0
- package/build/contracts/Staking.json +323 -0
- package/build/contracts/Superpro.json +197 -0
- package/build/contracts/SuperproToken.json +356 -0
- package/build/crypto/Crypto.d.ts +37 -0
- package/build/crypto/Crypto.js +181 -0
- package/build/crypto/index.d.ts +2 -0
- package/build/crypto/index.js +7 -0
- package/build/crypto/nodejs/AES.d.ts +24 -0
- package/build/crypto/nodejs/AES.js +152 -0
- package/build/crypto/nodejs/ARIA.d.ts +24 -0
- package/build/crypto/nodejs/ARIA.js +151 -0
- package/build/crypto/nodejs/ECIES.d.ts +6 -0
- package/build/crypto/nodejs/ECIES.js +94 -0
- package/build/crypto/nodejs/NativeCrypto.d.ts +54 -0
- package/build/crypto/nodejs/NativeCrypto.js +214 -0
- package/build/crypto/nodejs/RSA-Hybrid.d.ts +15 -0
- package/build/crypto/nodejs/RSA-Hybrid.js +153 -0
- package/build/index.d.ts +65 -0
- package/build/index.js +117 -0
- package/build/logger.d.ts +4 -0
- package/build/logger.js +8 -0
- package/build/models/Ballot.d.ts +13 -0
- package/build/models/Ballot.js +76 -0
- package/build/models/Offer.d.ts +70 -0
- package/build/models/Offer.js +273 -0
- package/build/models/Order.d.ts +125 -0
- package/build/models/Order.js +540 -0
- package/build/models/Provider.d.ts +40 -0
- package/build/models/Provider.js +167 -0
- package/build/models/TCB.d.ts +80 -0
- package/build/models/TCB.js +315 -0
- package/build/models/TeeOffer.d.ts +118 -0
- package/build/models/TeeOffer.js +436 -0
- package/build/proto/Compression.d.ts +33 -0
- package/build/proto/Compression.js +146 -0
- package/build/proto/TRI.d.ts +122 -0
- package/build/proto/TRI.js +316 -0
- package/build/providers/storage/ChunksDownloadDecorator.d.ts +38 -0
- package/build/providers/storage/ChunksDownloadDecorator.js +284 -0
- package/build/providers/storage/IStorageProvider.d.ts +17 -0
- package/build/providers/storage/IStorageProvider.js +2 -0
- package/build/providers/storage/StorjStorageProvider.d.ts +26 -0
- package/build/providers/storage/StorjStorageProvider.js +389 -0
- package/build/providers/storage/getStorageProvider.d.ts +4 -0
- package/build/providers/storage/getStorageProvider.js +16 -0
- package/build/staticModels/ActiveOffers.d.ts +29 -0
- package/build/staticModels/ActiveOffers.js +144 -0
- package/build/staticModels/ActiveOrders.d.ts +21 -0
- package/build/staticModels/ActiveOrders.js +120 -0
- package/build/staticModels/Consensus.d.ts +63 -0
- package/build/staticModels/Consensus.js +373 -0
- package/build/staticModels/Epochs.d.ts +23 -0
- package/build/staticModels/Epochs.js +97 -0
- package/build/staticModels/LastBlocks.d.ts +25 -0
- package/build/staticModels/LastBlocks.js +96 -0
- package/build/staticModels/Marks.d.ts +13 -0
- package/build/staticModels/Marks.js +113 -0
- package/build/staticModels/OffersFactory.d.ts +37 -0
- package/build/staticModels/OffersFactory.js +227 -0
- package/build/staticModels/OrdersFactory.d.ts +137 -0
- package/build/staticModels/OrdersFactory.js +539 -0
- package/build/staticModels/ProviderRegistry.d.ts +81 -0
- package/build/staticModels/ProviderRegistry.js +311 -0
- package/build/staticModels/Staking.d.ts +26 -0
- package/build/staticModels/Staking.js +132 -0
- package/build/staticModels/Superpro.d.ts +20 -0
- package/build/staticModels/Superpro.js +99 -0
- package/build/staticModels/SuperproToken.d.ts +30 -0
- package/build/staticModels/SuperproToken.js +125 -0
- package/build/staticModels/Suspicious.d.ts +26 -0
- package/build/staticModels/Suspicious.js +99 -0
- package/build/staticModels/TeeOffersFactory.d.ts +36 -0
- package/build/staticModels/TeeOffersFactory.js +206 -0
- package/build/staticModels/Voting.d.ts +35 -0
- package/build/staticModels/Voting.js +111 -0
- package/build/store.d.ts +12 -0
- package/build/store.js +13 -0
- package/build/types/Ballot.d.ts +75 -0
- package/build/types/Ballot.js +49 -0
- package/build/types/Epoch.d.ts +21 -0
- package/build/types/Epoch.js +18 -0
- package/build/types/Events.d.ts +18 -0
- package/build/types/Events.js +2 -0
- package/build/types/Marks.d.ts +5 -0
- package/build/types/Marks.js +9 -0
- package/build/types/Offer.d.ts +63 -0
- package/build/types/Offer.js +41 -0
- package/build/types/Order.d.ts +61 -0
- package/build/types/Order.js +36 -0
- package/build/types/Origins.d.ts +12 -0
- package/build/types/Origins.js +10 -0
- package/build/types/Provider.d.ts +25 -0
- package/build/types/Provider.js +19 -0
- package/build/types/Staking.d.ts +27 -0
- package/build/types/Staking.js +22 -0
- package/build/types/Superpro.d.ts +24 -0
- package/build/types/Superpro.js +29 -0
- package/build/types/TcbData.d.ts +26 -0
- package/build/types/TcbData.js +21 -0
- package/build/types/TeeOffer.d.ts +22 -0
- package/build/types/TeeOffer.js +15 -0
- package/build/types/Web3.d.ts +26 -0
- package/build/types/Web3.js +2 -0
- package/build/types/blockchainConnector/StorageAccess.d.ts +8 -0
- package/build/types/blockchainConnector/StorageAccess.js +2 -0
- package/build/types/storage/StorageAccess.d.ts +6 -0
- package/build/types/storage/StorageAccess.js +2 -0
- package/build/types/storage/StorageFileAccess.d.ts +5 -0
- package/build/types/storage/StorageFileAccess.js +2 -0
- package/build/types/storage/StorageObject.d.ts +8 -0
- package/build/types/storage/StorageObject.js +2 -0
- package/build/utils/NonceTracker.d.ts +12 -0
- package/build/utils/NonceTracker.js +84 -0
- package/build/utils/TxManager.d.ts +21 -0
- package/build/utils/TxManager.js +159 -0
- package/build/utils.d.ts +38 -0
- package/build/utils.js +195 -0
- package/package.json +68 -0
- package/readme.md +40 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
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 (_) 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var dto_js_1 = require("@super-protocol/dto-js");
|
|
43
|
+
var AES_1 = __importDefault(require("./nodejs/AES"));
|
|
44
|
+
var ARIA_1 = __importDefault(require("./nodejs/ARIA"));
|
|
45
|
+
var ECIES_1 = __importDefault(require("./nodejs/ECIES"));
|
|
46
|
+
var RSA_Hybrid_1 = __importDefault(require("./nodejs/RSA-Hybrid"));
|
|
47
|
+
var Crypto = /** @class */ (function () {
|
|
48
|
+
function Crypto() {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Used to encrypt data before sending it to blockchain
|
|
52
|
+
* @param algorithm - encryption algorithm
|
|
53
|
+
* @param content - string data to encrypt
|
|
54
|
+
* @param key - key in string format (default encoding base64)
|
|
55
|
+
* @param encoding - encoding of key and output data
|
|
56
|
+
* @return {Promise<Encryption>} - object what contains encrypted data, key and spec to decryption
|
|
57
|
+
*/
|
|
58
|
+
Crypto.encrypt = function (content, encryption) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
+
var _a;
|
|
61
|
+
return __generator(this, function (_b) {
|
|
62
|
+
switch (_b.label) {
|
|
63
|
+
case 0:
|
|
64
|
+
_a = encryption.algo;
|
|
65
|
+
switch (_a) {
|
|
66
|
+
case dto_js_1.CryptoAlgorithm.AES: return [3 /*break*/, 1];
|
|
67
|
+
case dto_js_1.CryptoAlgorithm.ARIA: return [3 /*break*/, 3];
|
|
68
|
+
case dto_js_1.CryptoAlgorithm.ECIES: return [3 /*break*/, 5];
|
|
69
|
+
case dto_js_1.CryptoAlgorithm.RSAHybrid: return [3 /*break*/, 7];
|
|
70
|
+
}
|
|
71
|
+
return [3 /*break*/, 9];
|
|
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
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Encrypts data stream
|
|
87
|
+
* @param inputStream - path to file that will be encrypted
|
|
88
|
+
* @param outputStream - place where it will be saved
|
|
89
|
+
* @param algorithm - file encryption algorithm
|
|
90
|
+
* @param key – key that will be used to encrypt data
|
|
91
|
+
* @return {Promise<Encryption>} - encryption info
|
|
92
|
+
*/
|
|
93
|
+
Crypto.encryptStream = function (inputStream, outputStream, encryption) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
95
|
+
var _a;
|
|
96
|
+
return __generator(this, function (_b) {
|
|
97
|
+
switch (_b.label) {
|
|
98
|
+
case 0:
|
|
99
|
+
_a = encryption.algo;
|
|
100
|
+
switch (_a) {
|
|
101
|
+
case dto_js_1.CryptoAlgorithm.AES: return [3 /*break*/, 1];
|
|
102
|
+
case dto_js_1.CryptoAlgorithm.ARIA: return [3 /*break*/, 3];
|
|
103
|
+
case dto_js_1.CryptoAlgorithm.RSAHybrid: return [3 /*break*/, 5];
|
|
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
|
+
});
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Used to decrypt data from blockchain
|
|
119
|
+
* @param encryption - object what contains encrypted data, key and spec to decryption
|
|
120
|
+
* @return {Promise<string>} - decrypted string
|
|
121
|
+
*/
|
|
122
|
+
Crypto.decrypt = function (encryption) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
var _a;
|
|
125
|
+
return __generator(this, function (_b) {
|
|
126
|
+
switch (_b.label) {
|
|
127
|
+
case 0:
|
|
128
|
+
_a = encryption.algo;
|
|
129
|
+
switch (_a) {
|
|
130
|
+
case dto_js_1.CryptoAlgorithm.AES: return [3 /*break*/, 1];
|
|
131
|
+
case dto_js_1.CryptoAlgorithm.ARIA: return [3 /*break*/, 3];
|
|
132
|
+
case dto_js_1.CryptoAlgorithm.ECIES: return [3 /*break*/, 5];
|
|
133
|
+
case dto_js_1.CryptoAlgorithm.RSAHybrid: return [3 /*break*/, 7];
|
|
134
|
+
}
|
|
135
|
+
return [3 /*break*/, 9];
|
|
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
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Decrypts data stream
|
|
151
|
+
* @param inputStream - stream with data to decrypt
|
|
152
|
+
* @param outputStream - stream where the decrypted data will be written
|
|
153
|
+
* @param encryption – encryption info
|
|
154
|
+
*/
|
|
155
|
+
Crypto.decryptStream = function (inputStream, outputStream, encryption) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
+
var _a;
|
|
158
|
+
return __generator(this, function (_b) {
|
|
159
|
+
switch (_b.label) {
|
|
160
|
+
case 0:
|
|
161
|
+
_a = encryption.algo;
|
|
162
|
+
switch (_a) {
|
|
163
|
+
case dto_js_1.CryptoAlgorithm.AES: return [3 /*break*/, 1];
|
|
164
|
+
case dto_js_1.CryptoAlgorithm.ARIA: return [3 /*break*/, 3];
|
|
165
|
+
case dto_js_1.CryptoAlgorithm.RSAHybrid: return [3 /*break*/, 5];
|
|
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
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
return Crypto;
|
|
180
|
+
}());
|
|
181
|
+
exports.default = Crypto;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var Crypto_1 = __importDefault(require("./Crypto"));
|
|
7
|
+
exports.default = Crypto_1.default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AESEncryption, Encryption } from "@super-protocol/dto-js";
|
|
3
|
+
import { ReadStream, WriteStream } from "fs";
|
|
4
|
+
declare class AES {
|
|
5
|
+
static encrypt(content: string, encryption: Encryption): Promise<AESEncryption>;
|
|
6
|
+
/**
|
|
7
|
+
* Encrypts data stream
|
|
8
|
+
* @param inputStream - path to file that will be encrypted
|
|
9
|
+
* @param outputStream - place where it will be saved
|
|
10
|
+
* @param algorithm - file encryption algorithm
|
|
11
|
+
* @param key – key that will be used to encrypt data
|
|
12
|
+
* @return {Promise<Encryption>} - encryption info
|
|
13
|
+
*/
|
|
14
|
+
static encryptStream(inputStream: ReadStream, outputStream: WriteStream, encryption: Encryption): Promise<AESEncryption>;
|
|
15
|
+
static decrypt(encryption: AESEncryption): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Decrypts data stream
|
|
18
|
+
* @param inputStream - stream with data to decrypt
|
|
19
|
+
* @param outputStream - stream where the decrypted data will be written
|
|
20
|
+
* @param encryption – encryption info
|
|
21
|
+
*/
|
|
22
|
+
static decryptStream(inputStream: ReadStream, outputStream: WriteStream, encryption: AESEncryption): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export default AES;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
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 (_) 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
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
|
+
});
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Encrypts data stream
|
|
69
|
+
* @param inputStream - path to file that will be encrypted
|
|
70
|
+
* @param outputStream - place where it will be saved
|
|
71
|
+
* @param algorithm - file encryption algorithm
|
|
72
|
+
* @param key – key that will be used to encrypt data
|
|
73
|
+
* @return {Promise<Encryption>} - encryption info
|
|
74
|
+
*/
|
|
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
|
+
});
|
|
98
|
+
});
|
|
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
|
+
});
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Decrypts data stream
|
|
123
|
+
* @param inputStream - stream with data to decrypt
|
|
124
|
+
* @param outputStream - stream where the decrypted data will be written
|
|
125
|
+
* @param encryption – encryption info
|
|
126
|
+
*/
|
|
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
|
+
});
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
return AES;
|
|
151
|
+
}());
|
|
152
|
+
exports.default = AES;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ARIAEncryption, Encryption } from "@super-protocol/dto-js";
|
|
3
|
+
import { ReadStream, WriteStream } from "fs";
|
|
4
|
+
declare class ARIA {
|
|
5
|
+
static encrypt(content: string, encryption: Encryption): Promise<ARIAEncryption>;
|
|
6
|
+
/**
|
|
7
|
+
* Encrypts data stream
|
|
8
|
+
* @param inputStream - path to file that will be encrypted
|
|
9
|
+
* @param outputStream - place where it will be saved
|
|
10
|
+
* @param algorithm - file encryption algorithm
|
|
11
|
+
* @param key – key that will be used to encrypt data
|
|
12
|
+
* @return {Promise<Encryption>} - encryption info
|
|
13
|
+
*/
|
|
14
|
+
static encryptStream(inputStream: ReadStream, outputStream: WriteStream, encryption: Encryption): Promise<ARIAEncryption>;
|
|
15
|
+
static decrypt(encryption: ARIAEncryption): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Decrypts data stream
|
|
18
|
+
* @param inputStream - stream with data to decrypt
|
|
19
|
+
* @param outputStream - stream where the decrypted data will be written
|
|
20
|
+
* @param encryption – encryption info
|
|
21
|
+
*/
|
|
22
|
+
static decryptStream(inputStream: ReadStream, outputStream: WriteStream, encryption: ARIAEncryption): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export default ARIA;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
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 (_) 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
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
|
+
});
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Encrypts data stream
|
|
69
|
+
* @param inputStream - path to file that will be encrypted
|
|
70
|
+
* @param outputStream - place where it will be saved
|
|
71
|
+
* @param algorithm - file encryption algorithm
|
|
72
|
+
* @param key – key that will be used to encrypt data
|
|
73
|
+
* @return {Promise<Encryption>} - encryption info
|
|
74
|
+
*/
|
|
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
|
+
});
|
|
97
|
+
});
|
|
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
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Decrypts data stream
|
|
122
|
+
* @param inputStream - stream with data to decrypt
|
|
123
|
+
* @param outputStream - stream where the decrypted data will be written
|
|
124
|
+
* @param encryption – encryption info
|
|
125
|
+
*/
|
|
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
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
return ARIA;
|
|
150
|
+
}());
|
|
151
|
+
exports.default = ARIA;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ECIESEncryption, Encryption } from "@super-protocol/dto-js";
|
|
2
|
+
declare class ECIES {
|
|
3
|
+
static encrypt(content: string, encryption: Encryption): Promise<ECIESEncryption>;
|
|
4
|
+
static decrypt(encryption: ECIESEncryption): Promise<string>;
|
|
5
|
+
}
|
|
6
|
+
export default ECIES;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
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 (_) 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var dto_js_1 = require("@super-protocol/dto-js");
|
|
43
|
+
var eccrypto_1 = __importDefault(require("eccrypto"));
|
|
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 result;
|
|
50
|
+
return __generator(this, function (_a) {
|
|
51
|
+
switch (_a.label) {
|
|
52
|
+
case 0:
|
|
53
|
+
if (!encryption.key)
|
|
54
|
+
throw Error('Encryption key is not provided');
|
|
55
|
+
return [4 /*yield*/, eccrypto_1.default.encrypt(Buffer.from(encryption.key, encryption.encoding), Buffer.from(content, "binary"))];
|
|
56
|
+
case 1:
|
|
57
|
+
result = _a.sent();
|
|
58
|
+
return [2 /*return*/, {
|
|
59
|
+
iv: result.iv.toString(encryption.encoding),
|
|
60
|
+
ephemPublicKey: result.ephemPublicKey.toString(encryption.encoding),
|
|
61
|
+
mac: result.mac.toString(encryption.encoding),
|
|
62
|
+
encoding: encryption.encoding,
|
|
63
|
+
algo: dto_js_1.CryptoAlgorithm.ECIES,
|
|
64
|
+
ciphertext: result.ciphertext.toString(encryption.encoding),
|
|
65
|
+
}];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
ECIES.decrypt = function (encryption) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
var encryptedObject, result;
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
if (!encryption.key)
|
|
77
|
+
throw Error('Decryption key is not provided');
|
|
78
|
+
encryptedObject = {
|
|
79
|
+
iv: Buffer.from(encryption.iv, encryption.encoding),
|
|
80
|
+
ephemPublicKey: Buffer.from(encryption.ephemPublicKey, encryption.encoding),
|
|
81
|
+
ciphertext: Buffer.from(encryption.ciphertext, encryption.encoding),
|
|
82
|
+
mac: Buffer.from(encryption.mac, encryption.encoding),
|
|
83
|
+
};
|
|
84
|
+
return [4 /*yield*/, eccrypto_1.default.decrypt(Buffer.from(encryption.key, encryption.encoding), encryptedObject)];
|
|
85
|
+
case 1:
|
|
86
|
+
result = _a.sent();
|
|
87
|
+
return [2 /*return*/, result.toString("binary")];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
return ECIES;
|
|
93
|
+
}());
|
|
94
|
+
exports.default = ECIES;
|