@super-protocol/sdk-js 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/TIIGenerator.js +129 -239
- package/build/connectors/BaseConnector.js +17 -47
- package/build/connectors/BlockchainConnector.js +222 -348
- package/build/connectors/BlockchainEventsListener.js +38 -92
- package/build/contracts/app.json +466 -35
- package/build/crypto/Crypto.js +63 -135
- package/build/crypto/index.js +1 -1
- package/build/crypto/nodejs/AES.js +62 -119
- package/build/crypto/nodejs/ARIA.js +61 -118
- package/build/crypto/nodejs/ECIES.js +51 -87
- package/build/crypto/nodejs/NativeCrypto.js +64 -118
- package/build/crypto/nodejs/RSA-Hybrid.js +54 -113
- package/build/index.d.ts +5 -0
- package/build/index.js +14 -2
- package/build/logger.d.ts +3 -1
- package/build/logger.js +2 -2
- package/build/models/EtlModel.js +65 -114
- package/build/models/Offer.js +227 -462
- package/build/models/Order.d.ts +4 -0
- package/build/models/Order.js +326 -559
- package/build/models/Provider.d.ts +2 -0
- package/build/models/Provider.js +74 -153
- package/build/models/TCB.js +67 -171
- package/build/models/TeeOffer.d.ts +1 -0
- package/build/models/TeeOffer.js +389 -731
- package/build/proto/Compression.js +20 -21
- package/build/proto/TRI.js +46 -50
- package/build/proto/TeeProperties.js +60 -66
- package/build/providers/storage/ChunksDownloadDecorator.js +125 -235
- package/build/providers/storage/S3StorageProvider.js +173 -298
- package/build/providers/storage/StorageAdapter.d.ts +60 -0
- package/build/providers/storage/StorageAdapter.js +317 -0
- package/build/providers/storage/StorageContentWriter.d.ts +39 -0
- package/build/providers/storage/StorageContentWriter.js +181 -0
- package/build/providers/storage/StorageKeyValueAdapter.d.ts +20 -0
- package/build/providers/storage/StorageKeyValueAdapter.js +152 -0
- package/build/providers/storage/StorageMetadataReader.d.ts +19 -0
- package/build/providers/storage/StorageMetadataReader.js +65 -0
- package/build/providers/storage/StorjAdapter.d.ts +19 -0
- package/build/providers/storage/StorjAdapter.js +62 -0
- package/build/providers/storage/StorjStorageProvider.js +138 -315
- package/build/providers/storage/getStorageProvider.js +7 -7
- package/build/providers/storage/types.d.ts +7 -0
- package/build/providers/storage/types.js +2 -0
- package/build/staticModels/ActiveOffers.js +32 -100
- package/build/staticModels/ActiveOrders.js +42 -120
- package/build/staticModels/BaseStaticModel.js +7 -10
- package/build/staticModels/Consensus.d.ts +4 -1
- package/build/staticModels/Consensus.js +164 -220
- package/build/staticModels/Deposits.js +109 -201
- package/build/staticModels/Marks.js +21 -82
- package/build/staticModels/ModelPackager.js +34 -84
- package/build/staticModels/Offers.js +140 -266
- package/build/staticModels/Orders.d.ts +1 -0
- package/build/staticModels/Orders.js +286 -429
- package/build/staticModels/ProviderRegistry.js +114 -225
- package/build/staticModels/Superpro.js +17 -63
- package/build/staticModels/SuperproToken.js +90 -169
- package/build/staticModels/TeeOffers.js +220 -416
- package/build/store.js +2 -2
- package/build/types/HardwareInfo.js +2 -2
- package/build/types/Order.js +4 -4
- package/build/types/Provider.js +1 -1
- package/build/types/TeeOfferInfo.js +1 -1
- package/build/types/TeeOfferOption.js +2 -2
- package/build/types/TeeOfferSlot.js +2 -2
- package/build/types/ValueOfferSlot.js +3 -3
- package/build/utils/Monitoring.js +24 -28
- package/build/utils/NonceTracker.js +56 -121
- package/build/utils/PubSub.d.ts +9 -0
- package/build/utils/PubSub.js +36 -0
- package/build/utils/TxManager.js +121 -215
- package/build/utils/compressors/GzipCompressor.js +13 -50
- package/build/utils/compressors/UncompressedCompressor.js +10 -13
- package/build/utils/helpers/tryWithInterval.js +34 -78
- package/build/utils/resourceLoaders/BaseResourceLoader.js +26 -78
- package/build/utils/resourceLoaders/StorageProviderLoader.js +33 -97
- package/build/utils/resourceLoaders/UrlResourceLoader.js +29 -93
- package/build/utils/resourceLoaders/getResourceLoader.js +6 -6
- package/build/utils.js +60 -105
- package/package.json +4 -1
package/build/TIIGenerator.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,244 +8,145 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
13
|
};
|
|
52
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
case 2:
|
|
101
|
-
compressedTri = _b.apply(_a, [(_e.data = _g.sent(),
|
|
102
|
-
_e.type = Compression_1.Compression_TYPE.GZIP,
|
|
103
|
-
_e)]).finish();
|
|
104
|
-
_d = (_c = JSON).stringify;
|
|
105
|
-
_f = {};
|
|
106
|
-
return [4 /*yield*/, crypto_1.default.encrypt(JSON.stringify(resource), JSON.parse(teeOfferInfo.argsPublicKey))];
|
|
107
|
-
case 3:
|
|
108
|
-
_f.encryptedResource = _g.sent();
|
|
109
|
-
return [4 /*yield*/, crypto_1.default.encrypt(Buffer.from(compressedTri).toString(dto_js_1.Encoding.base64), {
|
|
110
|
-
algo: dto_js_1.CryptoAlgorithm.ECIES,
|
|
111
|
-
key: Buffer.from(tlb.data.teePubKeyData).toString("base64"),
|
|
112
|
-
encoding: dto_js_1.Encoding.base64,
|
|
113
|
-
})];
|
|
114
|
-
case 4: return [2 /*return*/, _d.apply(_c, [(_f.tri = _g.sent(),
|
|
115
|
-
_f)])];
|
|
116
|
-
}
|
|
15
|
+
const node_gzip_1 = require("node-gzip");
|
|
16
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
17
|
+
const Compression_1 = require("./proto/Compression");
|
|
18
|
+
const TRI_1 = require("./proto/TRI");
|
|
19
|
+
const crypto_1 = __importDefault(require("./crypto"));
|
|
20
|
+
const Offer_1 = __importDefault(require("./models/Offer"));
|
|
21
|
+
const Order_1 = __importDefault(require("./models/Order"));
|
|
22
|
+
const TeeOffer_1 = __importDefault(require("./models/TeeOffer"));
|
|
23
|
+
const dto_js_1 = require("@super-protocol/dto-js");
|
|
24
|
+
const tee_lib_1 = require("@super-protocol/tee-lib");
|
|
25
|
+
class TIIGenerator {
|
|
26
|
+
static generateByOffer(offerId, solutionHashes, linkageString, resource, args, encryption) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const teeOffer = new TeeOffer_1.default(offerId);
|
|
29
|
+
const teeOfferInfo = yield teeOffer.getInfo();
|
|
30
|
+
const linkage = linkageString
|
|
31
|
+
? JSON.parse(linkageString)
|
|
32
|
+
: {
|
|
33
|
+
encoding: dto_js_1.Encoding.base64,
|
|
34
|
+
mrenclave: "",
|
|
35
|
+
};
|
|
36
|
+
const tlb = new tee_lib_1.TLBlockSerializerV1().unserializeTlb(Buffer.from(teeOfferInfo.tlb, "base64"));
|
|
37
|
+
// TODO: check env with SP-149
|
|
38
|
+
const mac = encryption.authTag || encryption.mac;
|
|
39
|
+
const rawTri = {
|
|
40
|
+
solutionHashes: solutionHashes.map((hash) => ({
|
|
41
|
+
algo: hash.algo,
|
|
42
|
+
hash: Buffer.from(hash.hash, hash.encoding),
|
|
43
|
+
})),
|
|
44
|
+
mrenclave: Buffer.from(linkage.mrenclave, linkage.encoding),
|
|
45
|
+
args: JSON.stringify(args || ""),
|
|
46
|
+
encryption: Object.assign(Object.assign({}, encryption), { ciphertext: encryption.ciphertext ? Buffer.from(encryption.ciphertext, encryption.encoding) : undefined, key: encryption.key ? Buffer.from(encryption.key, encryption.encoding) : undefined, iv: encryption.iv
|
|
47
|
+
? Buffer.from(encryption.iv, encryption.encoding)
|
|
48
|
+
: undefined, mac: mac ? Buffer.from(mac, encryption.encoding) : undefined }),
|
|
49
|
+
};
|
|
50
|
+
const tri = TRI_1.TRI.encode(rawTri).finish();
|
|
51
|
+
const compressedTri = Compression_1.Compression.encode({
|
|
52
|
+
data: yield (0, node_gzip_1.gzip)(tri),
|
|
53
|
+
type: Compression_1.Compression_TYPE.GZIP,
|
|
54
|
+
}).finish();
|
|
55
|
+
return JSON.stringify({
|
|
56
|
+
encryptedResource: yield crypto_1.default.encrypt(JSON.stringify(resource), JSON.parse(teeOfferInfo.argsPublicKey)),
|
|
57
|
+
tri: yield crypto_1.default.encrypt(Buffer.from(compressedTri).toString(dto_js_1.Encoding.base64), {
|
|
58
|
+
algo: dto_js_1.CryptoAlgorithm.ECIES,
|
|
59
|
+
key: Buffer.from(tlb.data.teePubKeyData).toString("base64"),
|
|
60
|
+
encoding: dto_js_1.Encoding.base64,
|
|
61
|
+
}),
|
|
117
62
|
});
|
|
118
63
|
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
case 1:
|
|
129
|
-
parentOrderId = _b.sent();
|
|
130
|
-
parentOrder = new Order_1.default(parentOrderId);
|
|
131
|
-
return [4 /*yield*/, parentOrder.getOrderInfo()];
|
|
132
|
-
case 2:
|
|
133
|
-
parentOrderInfo = _b.sent();
|
|
134
|
-
return [4 /*yield*/, this.getSolutionHashesAndLinkage(parentOrderInfo.args.inputOffers)];
|
|
135
|
-
case 3:
|
|
136
|
-
_a = _b.sent(), hashes = _a.hashes, linkage = _a.linkage;
|
|
137
|
-
return [2 /*return*/, this.generateByOffer(parentOrderInfo.offerId, hashes, linkage, resource, args, encryption)];
|
|
138
|
-
}
|
|
139
|
-
});
|
|
64
|
+
}
|
|
65
|
+
static generate(orderId, resource, args, encryption) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const order = new Order_1.default(orderId);
|
|
68
|
+
const parentOrderId = yield order.getParentOrder();
|
|
69
|
+
const parentOrder = new Order_1.default(parentOrderId);
|
|
70
|
+
const parentOrderInfo = yield parentOrder.getOrderInfo();
|
|
71
|
+
const { hashes, linkage } = yield this.getSolutionHashesAndLinkage(parentOrderInfo.args.inputOffers);
|
|
72
|
+
return this.generateByOffer(parentOrderInfo.offerId, hashes, linkage, resource, args, encryption);
|
|
140
73
|
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return __generator(this, function (_a) {
|
|
153
|
-
switch (_a.label) {
|
|
154
|
-
case 0:
|
|
155
|
-
offer = new Offer_1.default(offerId);
|
|
156
|
-
return [4 /*yield*/, offer.getInfo()];
|
|
157
|
-
case 1:
|
|
158
|
-
offerInfo = _a.sent();
|
|
159
|
-
if (offerInfo.hash) {
|
|
160
|
-
solutionHashes.push(JSON.parse(offerInfo.hash));
|
|
161
|
-
}
|
|
162
|
-
restrictions = lodash_1.default.intersection(offerInfo.restrictions.offers, inputOffers).filter(function (restrictedOfferId) { return restrictedOfferId !== offer.id; });
|
|
163
|
-
if (restrictions.length) {
|
|
164
|
-
solutionLinkage = offerInfo.linkage;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
anyLinkage = offerInfo.linkage;
|
|
168
|
-
}
|
|
169
|
-
return [2 /*return*/];
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}); }))];
|
|
173
|
-
case 1:
|
|
174
|
-
_a.sent();
|
|
175
|
-
return [2 /*return*/, {
|
|
176
|
-
hashes: solutionHashes,
|
|
177
|
-
linkage: solutionLinkage || anyLinkage,
|
|
178
|
-
}];
|
|
74
|
+
}
|
|
75
|
+
static getSolutionHashesAndLinkage(inputOffers) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const solutionHashes = [];
|
|
78
|
+
let solutionLinkage;
|
|
79
|
+
let anyLinkage;
|
|
80
|
+
yield Promise.all(inputOffers.map((offerId) => __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const offer = new Offer_1.default(offerId);
|
|
82
|
+
const offerInfo = yield offer.getInfo();
|
|
83
|
+
if (offerInfo.hash) {
|
|
84
|
+
solutionHashes.push(JSON.parse(offerInfo.hash));
|
|
179
85
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
TIIGenerator.getTRI = function (tii, decryptionKey) {
|
|
184
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
-
var tiiObj, tri, compression, decompressed, _a, decoded;
|
|
186
|
-
return __generator(this, function (_b) {
|
|
187
|
-
switch (_b.label) {
|
|
188
|
-
case 0:
|
|
189
|
-
tiiObj = JSON.parse(tii);
|
|
190
|
-
tiiObj.tri.key = decryptionKey.toString(tiiObj.tri.encoding);
|
|
191
|
-
return [4 /*yield*/, crypto_1.default.decrypt(tiiObj.tri)];
|
|
192
|
-
case 1:
|
|
193
|
-
tri = _b.sent();
|
|
194
|
-
compression = Compression_1.Compression.decode(Buffer.from(tri, tiiObj.tri.encoding));
|
|
195
|
-
_a = compression.type;
|
|
196
|
-
switch (_a) {
|
|
197
|
-
case Compression_1.Compression_TYPE.GZIP: return [3 /*break*/, 2];
|
|
198
|
-
}
|
|
199
|
-
return [3 /*break*/, 4];
|
|
200
|
-
case 2: return [4 /*yield*/, (0, node_gzip_1.ungzip)(compression.data)];
|
|
201
|
-
case 3:
|
|
202
|
-
decompressed = _b.sent();
|
|
203
|
-
return [3 /*break*/, 5];
|
|
204
|
-
case 4: throw Error("Unknown compression method");
|
|
205
|
-
case 5:
|
|
206
|
-
decoded = TRI_1.TRI.decode(decompressed);
|
|
207
|
-
return [2 /*return*/, {
|
|
208
|
-
solutionHashes: decoded.solutionHashes.map(function (hash) { return ({
|
|
209
|
-
hash: Buffer.from(hash.hash).toString(dto_js_1.Encoding.base64),
|
|
210
|
-
algo: hash.algo,
|
|
211
|
-
encoding: dto_js_1.Encoding.base64,
|
|
212
|
-
}); }),
|
|
213
|
-
linkage: {
|
|
214
|
-
encoding: dto_js_1.Encoding.base64,
|
|
215
|
-
mrenclave: Buffer.from(decoded.mrenclave).toString(dto_js_1.Encoding.base64),
|
|
216
|
-
},
|
|
217
|
-
args: decoded.args,
|
|
218
|
-
encryption: {
|
|
219
|
-
algo: decoded.encryption.algo,
|
|
220
|
-
cipher: decoded.encryption.cipher,
|
|
221
|
-
encoding: dto_js_1.Encoding.base64,
|
|
222
|
-
key: Buffer.from(decoded.encryption.key).toString(dto_js_1.Encoding.base64),
|
|
223
|
-
iv: decoded.encryption.iv && Buffer.from(decoded.encryption.iv).toString(dto_js_1.Encoding.base64),
|
|
224
|
-
mac: decoded.encryption.mac && Buffer.from(decoded.encryption.mac).toString(dto_js_1.Encoding.base64),
|
|
225
|
-
},
|
|
226
|
-
}];
|
|
86
|
+
const restrictions = lodash_1.default.intersection(offerInfo.restrictions.offers, inputOffers).filter((restrictedOfferId) => restrictedOfferId !== offer.id);
|
|
87
|
+
if (restrictions.length) {
|
|
88
|
+
solutionLinkage = offerInfo.linkage;
|
|
227
89
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
};
|
|
231
|
-
TIIGenerator.getUrl = function (tii, decryptionKey) {
|
|
232
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
-
var res;
|
|
234
|
-
return __generator(this, function (_a) {
|
|
235
|
-
switch (_a.label) {
|
|
236
|
-
case 0: return [4 /*yield*/, TIIGenerator.getResource(tii, decryptionKey)];
|
|
237
|
-
case 1:
|
|
238
|
-
res = _a.sent();
|
|
239
|
-
return [2 /*return*/, res.url];
|
|
90
|
+
else {
|
|
91
|
+
anyLinkage = offerInfo.linkage;
|
|
240
92
|
}
|
|
241
|
-
});
|
|
93
|
+
})));
|
|
94
|
+
return {
|
|
95
|
+
hashes: solutionHashes,
|
|
96
|
+
linkage: solutionLinkage || anyLinkage,
|
|
97
|
+
};
|
|
242
98
|
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
99
|
+
}
|
|
100
|
+
static getTRI(tii, decryptionKey) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const tiiObj = JSON.parse(tii);
|
|
103
|
+
tiiObj.tri.key = decryptionKey.toString(tiiObj.tri.encoding);
|
|
104
|
+
const tri = yield crypto_1.default.decrypt(tiiObj.tri);
|
|
105
|
+
const compression = Compression_1.Compression.decode(Buffer.from(tri, tiiObj.tri.encoding));
|
|
106
|
+
let decompressed;
|
|
107
|
+
switch (compression.type) {
|
|
108
|
+
case Compression_1.Compression_TYPE.GZIP:
|
|
109
|
+
decompressed = yield (0, node_gzip_1.ungzip)(compression.data);
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
throw Error("Unknown compression method");
|
|
113
|
+
}
|
|
114
|
+
const decoded = TRI_1.TRI.decode(decompressed);
|
|
115
|
+
return {
|
|
116
|
+
solutionHashes: decoded.solutionHashes.map((hash) => ({
|
|
117
|
+
hash: Buffer.from(hash.hash).toString(dto_js_1.Encoding.base64),
|
|
118
|
+
algo: hash.algo,
|
|
119
|
+
encoding: dto_js_1.Encoding.base64,
|
|
120
|
+
})),
|
|
121
|
+
linkage: {
|
|
122
|
+
encoding: dto_js_1.Encoding.base64,
|
|
123
|
+
mrenclave: Buffer.from(decoded.mrenclave).toString(dto_js_1.Encoding.base64),
|
|
124
|
+
},
|
|
125
|
+
args: decoded.args,
|
|
126
|
+
encryption: {
|
|
127
|
+
algo: decoded.encryption.algo,
|
|
128
|
+
cipher: decoded.encryption.cipher,
|
|
129
|
+
encoding: dto_js_1.Encoding.base64,
|
|
130
|
+
key: Buffer.from(decoded.encryption.key).toString(dto_js_1.Encoding.base64),
|
|
131
|
+
iv: decoded.encryption.iv && Buffer.from(decoded.encryption.iv).toString(dto_js_1.Encoding.base64),
|
|
132
|
+
mac: decoded.encryption.mac && Buffer.from(decoded.encryption.mac).toString(dto_js_1.Encoding.base64),
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
static getUrl(tii, decryptionKey) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const res = yield TIIGenerator.getResource(tii, decryptionKey);
|
|
140
|
+
return res.url;
|
|
258
141
|
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
142
|
+
}
|
|
143
|
+
static getResource(tii, decryptionKey) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const encryptedResource = JSON.parse(tii).encryptedResource;
|
|
146
|
+
encryptedResource.key = decryptionKey.toString(encryptedResource.encoding);
|
|
147
|
+
const resource = yield crypto_1.default.decrypt(encryptedResource);
|
|
148
|
+
return JSON.parse(resource);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
262
152
|
exports.default = TIIGenerator;
|
|
@@ -8,77 +8,47 @@ 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
15
|
exports.BaseConnector = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
16
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
17
|
+
class BaseConnector {
|
|
18
|
+
constructor() {
|
|
46
19
|
this.initialized = false;
|
|
47
20
|
this.logger = logger_1.default.child({ className: this.constructor["name"] });
|
|
48
21
|
}
|
|
49
|
-
|
|
22
|
+
isInitialized() {
|
|
50
23
|
return this.initialized;
|
|
51
|
-
}
|
|
52
|
-
|
|
24
|
+
}
|
|
25
|
+
checkIfInitialized() {
|
|
53
26
|
if (!this.initialized)
|
|
54
|
-
throw new Error(
|
|
55
|
-
}
|
|
27
|
+
throw new Error(`${this.constructor["name"]} is not initialized, needs to run '${this.constructor["name"]}.initialize(CONFIG)' first`);
|
|
28
|
+
}
|
|
56
29
|
/**
|
|
57
30
|
*
|
|
58
31
|
* @returns initialized contract
|
|
59
32
|
*/
|
|
60
|
-
|
|
33
|
+
getContract() {
|
|
61
34
|
this.checkIfInitialized();
|
|
62
35
|
return this.contract;
|
|
63
|
-
}
|
|
36
|
+
}
|
|
64
37
|
/**
|
|
65
38
|
* Function for connecting to blockchain
|
|
66
39
|
* Used to setting up settings for blockchain connector
|
|
67
40
|
* Needs to run this function before using blockchain connector
|
|
68
41
|
*/
|
|
69
|
-
|
|
70
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
74
|
-
BaseConnector.prototype.shutdown = function () {
|
|
42
|
+
initialize(config) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
44
|
+
}
|
|
45
|
+
shutdown() {
|
|
75
46
|
var _a;
|
|
76
47
|
if (this.initialized) {
|
|
77
48
|
(_a = this.provider) === null || _a === void 0 ? void 0 : _a.disconnect(0, "");
|
|
78
49
|
this.initialized = false;
|
|
79
|
-
this.logger.trace(
|
|
50
|
+
this.logger.trace(`${this.constructor["name"]} was shutdown`);
|
|
80
51
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
}());
|
|
52
|
+
}
|
|
53
|
+
}
|
|
84
54
|
exports.BaseConnector = BaseConnector;
|