@super-protocol/sdk-js 0.14.0-beta.0 → 0.14.1-beta.2

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.
@@ -58,6 +58,7 @@ var crypto_1 = __importDefault(require("./crypto"));
58
58
  var Offer_1 = __importDefault(require("./models/Offer"));
59
59
  var Order_1 = __importDefault(require("./models/Order"));
60
60
  var TeeOffer_1 = __importDefault(require("./models/TeeOffer"));
61
+ var TCB_1 = __importDefault(require("./models/TCB"));
61
62
  var dto_js_1 = require("@super-protocol/dto-js");
62
63
  var tee_lib_1 = require("@super-protocol/tee-lib");
63
64
  var TIIGenerator = /** @class */ (function () {
@@ -65,7 +66,7 @@ var TIIGenerator = /** @class */ (function () {
65
66
  }
66
67
  TIIGenerator.generateByOffer = function (offerId, solutionHashes, linkageString, resource, args, encryption) {
67
68
  return __awaiter(this, void 0, void 0, function () {
68
- var teeOffer, teeOfferInfo, linkage, tlb, mac, rawTri, tri, compressedTri, _a, _b, _c, _d;
69
+ var teeOffer, teeOfferInfo, tcbId, tcb, linkage, tlb, mac, rawTri, tri, compressedTri, _a, _b, _c, _d;
69
70
  var _e, _f;
70
71
  return __generator(this, function (_g) {
71
72
  switch (_g.label) {
@@ -74,13 +75,22 @@ var TIIGenerator = /** @class */ (function () {
74
75
  return [4 /*yield*/, teeOffer.getInfo()];
75
76
  case 1:
76
77
  teeOfferInfo = _g.sent();
78
+ return [4 /*yield*/, teeOffer.getActualTcbId()];
79
+ case 2:
80
+ tcbId = _g.sent();
81
+ if (tcbId === "0") {
82
+ throw Error("Tee offer isn't avaliable before added TCB");
83
+ }
84
+ return [4 /*yield*/, new TCB_1.default(tcbId).get()];
85
+ case 3:
86
+ tcb = _g.sent();
77
87
  linkage = linkageString
78
88
  ? JSON.parse(linkageString)
79
89
  : {
80
90
  encoding: dto_js_1.Encoding.base64,
81
91
  mrenclave: "",
82
92
  };
83
- tlb = new tee_lib_1.TLBlockSerializerV1().unserializeTlb(Buffer.from(teeOfferInfo.tlb, "base64"));
93
+ tlb = new tee_lib_1.TLBlockSerializerV1().unserializeTlb(Buffer.from(tcb.quote, "base64"));
84
94
  mac = encryption.authTag || encryption.mac;
85
95
  rawTri = {
86
96
  solutionHashes: solutionHashes.map(function (hash) { return ({
@@ -97,21 +107,21 @@ var TIIGenerator = /** @class */ (function () {
97
107
  _b = (_a = Compression_1.Compression).encode;
98
108
  _e = {};
99
109
  return [4 /*yield*/, (0, node_gzip_1.gzip)(tri)];
100
- case 2:
110
+ case 4:
101
111
  compressedTri = _b.apply(_a, [(_e.data = _g.sent(),
102
112
  _e.type = Compression_1.Compression_TYPE.GZIP,
103
113
  _e)]).finish();
104
114
  _d = (_c = JSON).stringify;
105
115
  _f = {};
106
116
  return [4 /*yield*/, crypto_1.default.encrypt(JSON.stringify(resource), JSON.parse(teeOfferInfo.argsPublicKey))];
107
- case 3:
117
+ case 5:
108
118
  _f.encryptedResource = _g.sent();
109
119
  return [4 /*yield*/, crypto_1.default.encrypt(Buffer.from(compressedTri).toString(dto_js_1.Encoding.base64), {
110
120
  algo: dto_js_1.CryptoAlgorithm.ECIES,
111
121
  key: Buffer.from(tlb.data.teePubKeyData).toString("base64"),
112
122
  encoding: dto_js_1.Encoding.base64,
113
123
  })];
114
- case 4: return [2 /*return*/, _d.apply(_c, [(_f.tri = _g.sent(),
124
+ case 6: return [2 /*return*/, _d.apply(_c, [(_f.tri = _g.sent(),
115
125
  _f)])];
116
126
  }
117
127
  });
@@ -6,3 +6,5 @@ export declare const defaultGasLimitMultiplier = 1.2;
6
6
  export declare const ONE_DAY: number;
7
7
  export declare const BLOCK_SIZE_TO_FETCH_TRANSACTION = 500;
8
8
  export declare const POLYGON_MATIC_EVENT_PATH = "0x0000000000000000000000000000000000001010";
9
+ export declare const BLOCKCHAIN_CALL_RETRY_ATTEMPTS = 10;
10
+ export declare const BLOCKCHAIN_CALL_RETRY_INTERVAL = 3000;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.POLYGON_MATIC_EVENT_PATH = exports.BLOCK_SIZE_TO_FETCH_TRANSACTION = exports.ONE_DAY = exports.defaultGasLimitMultiplier = exports.defaultGasPriceMultiplier = exports.defaultGasPrice = exports.defaultGasLimit = exports.defaultBlockchainUrl = void 0;
3
+ exports.BLOCKCHAIN_CALL_RETRY_INTERVAL = exports.BLOCKCHAIN_CALL_RETRY_ATTEMPTS = exports.POLYGON_MATIC_EVENT_PATH = exports.BLOCK_SIZE_TO_FETCH_TRANSACTION = exports.ONE_DAY = exports.defaultGasLimitMultiplier = exports.defaultGasPriceMultiplier = exports.defaultGasPrice = exports.defaultGasLimit = exports.defaultBlockchainUrl = void 0;
4
4
  exports.defaultBlockchainUrl = "http://127.0.0.1:8545";
5
5
  exports.defaultGasLimit = 7000000;
6
6
  exports.defaultGasPrice = "3000000000";
@@ -9,3 +9,5 @@ exports.defaultGasLimitMultiplier = 1.2;
9
9
  exports.ONE_DAY = 24 * 60 * 60;
10
10
  exports.BLOCK_SIZE_TO_FETCH_TRANSACTION = 500;
11
11
  exports.POLYGON_MATIC_EVENT_PATH = "0x0000000000000000000000000000000000001010";
12
+ exports.BLOCKCHAIN_CALL_RETRY_ATTEMPTS = 10;
13
+ exports.BLOCKCHAIN_CALL_RETRY_INTERVAL = 3000;
@@ -73,6 +73,7 @@ declare class Offer {
73
73
  */
74
74
  getCheapestPrice(): Promise<string>;
75
75
  isOfferExists(): Promise<boolean>;
76
+ private checkIfOfferExistsWithInterval;
76
77
  /**
77
78
  * Function for fetching whether offer slot exists or not
78
79
  * @param slotId - Slot ID
@@ -59,6 +59,8 @@ var OptionInfo_1 = require("../types/OptionInfo");
59
59
  var SlotUsage_1 = require("../types/SlotUsage");
60
60
  var utils_2 = require("ethers/lib/utils");
61
61
  var TeeOffers_1 = __importDefault(require("../staticModels/TeeOffers"));
62
+ var helpers_1 = require("../utils/helpers");
63
+ var constants_1 = require("../constants");
62
64
  var Offer = /** @class */ (function () {
63
65
  function Offer(offerId) {
64
66
  this.id = offerId;
@@ -167,8 +169,13 @@ var Offer = /** @class */ (function () {
167
169
  var _a, offerInfoParams;
168
170
  return __generator(this, function (_b) {
169
171
  switch (_b.label) {
170
- case 0: return [4 /*yield*/, Offer.contract.methods.getValueOffer(this.id).call()];
172
+ case 0: return [4 /*yield*/, this.checkIfOfferExistsWithInterval()];
171
173
  case 1:
174
+ if (!(_b.sent())) {
175
+ throw Error("Offer ".concat(this.id, " does not exist"));
176
+ }
177
+ return [4 /*yield*/, Offer.contract.methods.getValueOffer(this.id).call()];
178
+ case 2:
172
179
  _a = _b.sent(), offerInfoParams = _a[2];
173
180
  this.offerInfo = (0, utils_1.tupleToObject)(offerInfoParams, Offer_1.OfferInfoStructure);
174
181
  return [2 /*return*/, this.offerInfo];
@@ -292,6 +299,29 @@ var Offer = /** @class */ (function () {
292
299
  });
293
300
  });
294
301
  };
302
+ Offer.prototype.checkIfOfferExistsWithInterval = function () {
303
+ return __awaiter(this, void 0, void 0, function () {
304
+ var offerExists;
305
+ var _this = this;
306
+ return __generator(this, function (_a) {
307
+ switch (_a.label) {
308
+ case 0: return [4 /*yield*/, (0, helpers_1.tryWithInterval)({
309
+ handler: function () { return _this.isOfferExists(); },
310
+ checkResult: function (exists) {
311
+ if (!exists)
312
+ _this.logger.debug("Offer ".concat(_this.id, " exists: ").concat(exists));
313
+ return { isResultOk: exists };
314
+ },
315
+ retryInterval: constants_1.BLOCKCHAIN_CALL_RETRY_INTERVAL,
316
+ retryMax: constants_1.BLOCKCHAIN_CALL_RETRY_ATTEMPTS,
317
+ })];
318
+ case 1:
319
+ offerExists = _a.sent();
320
+ return [2 /*return*/, offerExists];
321
+ }
322
+ });
323
+ });
324
+ };
295
325
  /**
296
326
  * Function for fetching whether offer slot exists or not
297
327
  * @param slotId - Slot ID
@@ -38,6 +38,7 @@ declare class Order {
38
38
  * Function for fetching order info from blockchain
39
39
  */
40
40
  getOrderInfo(): Promise<OrderInfo>;
41
+ private checkIfOrderExistsWithInterval;
41
42
  getConsumer(): Promise<string>;
42
43
  /**
43
44
  * Function for fetching order result from blockchain
@@ -68,6 +68,8 @@ var Superpro_1 = __importDefault(require("../staticModels/Superpro"));
68
68
  var TxManager_1 = __importDefault(require("../utils/TxManager"));
69
69
  var BlockchainEventsListener_1 = __importDefault(require("../connectors/BlockchainEventsListener"));
70
70
  var TeeOffers_1 = __importDefault(require("../staticModels/TeeOffers"));
71
+ var helpers_1 = require("../utils/helpers");
72
+ var constants_1 = require("../constants");
71
73
  var Order = /** @class */ (function () {
72
74
  function Order(orderId) {
73
75
  this.id = orderId;
@@ -147,7 +149,7 @@ var Order = /** @class */ (function () {
147
149
  var orderInfoParams;
148
150
  return __generator(this, function (_a) {
149
151
  switch (_a.label) {
150
- case 0: return [4 /*yield*/, this.isExist()];
152
+ case 0: return [4 /*yield*/, this.checkIfOrderExistsWithInterval()];
151
153
  case 1:
152
154
  if (!(_a.sent())) {
153
155
  throw Error("Order ".concat(this.id, " does not exist"));
@@ -160,6 +162,29 @@ var Order = /** @class */ (function () {
160
162
  });
161
163
  });
162
164
  };
165
+ Order.prototype.checkIfOrderExistsWithInterval = function () {
166
+ return __awaiter(this, void 0, void 0, function () {
167
+ var offerExists;
168
+ var _this = this;
169
+ return __generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0: return [4 /*yield*/, (0, helpers_1.tryWithInterval)({
172
+ handler: function () { return _this.isExist(); },
173
+ checkResult: function (exists) {
174
+ if (!exists)
175
+ _this.logger.debug("Order ".concat(_this.id, " exists: ").concat(exists));
176
+ return { isResultOk: exists };
177
+ },
178
+ retryInterval: constants_1.BLOCKCHAIN_CALL_RETRY_INTERVAL,
179
+ retryMax: constants_1.BLOCKCHAIN_CALL_RETRY_ATTEMPTS,
180
+ })];
181
+ case 1:
182
+ offerExists = _a.sent();
183
+ return [2 /*return*/, offerExists];
184
+ }
185
+ });
186
+ });
187
+ };
163
188
  Order.prototype.getConsumer = function () {
164
189
  return __awaiter(this, void 0, void 0, function () {
165
190
  var orderInfoParams;
@@ -8,6 +8,7 @@ import { TeeOfferSlot } from "../types/TeeOfferSlot";
8
8
  import { OptionInfo } from "../types/OptionInfo";
9
9
  import { SlotUsage } from "../types/SlotUsage";
10
10
  import { SlotInfo } from "../types/SlotInfo";
11
+ import { GetTcbRequest } from "@super-protocol/dto-js";
11
12
  declare class TeeOffer {
12
13
  private static contract;
13
14
  private logger;
@@ -95,6 +96,15 @@ declare class TeeOffer {
95
96
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
96
97
  */
97
98
  deleteOption(optionId: string, transactionOptions?: TransactionOptions): Promise<void>;
99
+ initializeTcb(transactionOptions?: TransactionOptions): Promise<void>;
100
+ private initializeTcbAndAssignBlocks;
101
+ /**
102
+ * Function initialize TCB and returns list of anothers' TCB for their checking
103
+ * @param teeOfferId - id of TEE offer
104
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
105
+ * @returns tcbId and lists of anothers' TCB for their checking
106
+ */
107
+ getListsForVerification(transactionOptions?: TransactionOptions): Promise<GetTcbRequest>;
98
108
  /**
99
109
  * Function for fetching whether tee offer slot exists or not
100
110
  * @param slotId - Slot ID
@@ -133,6 +143,17 @@ declare class TeeOffer {
133
143
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
134
144
  */
135
145
  deleteSlot(slotId: string, transactionOptions?: TransactionOptions): Promise<void>;
146
+ /**
147
+ * @param teeOfferId - TEE offer ID
148
+ * @returns {Promise<string>} - Actual TCB ID
149
+ */
150
+ getActualTcbId(): Promise<string>;
151
+ /**
152
+ * Function return last inited TCB of TEE offer
153
+ * @param teeOfferId - id of TEE offer
154
+ * */
155
+ getInitializedTcbId(): Promise<string>;
156
+ isTcbCreationAvailable(): Promise<boolean>;
136
157
  /**
137
158
  * Function for fetching TEE offer provider authority account from blockchain
138
159
  */
@@ -146,22 +167,10 @@ declare class TeeOffer {
146
167
  * Function for fetching TLB provider from blockchain
147
168
  */
148
169
  getTlb(): Promise<string>;
149
- /**
150
- * Function for fetching last TLB addition time for this TEE offer
151
- */
152
- getLastTlbAddedTime(): Promise<number>;
153
- /**
154
- * Function for fetching last TCB addition time for this TEE offer
155
- */
156
- getLastTcbAddedTime(): Promise<number>;
157
170
  /**
158
171
  * Function for fetching violationRate for this TEE offer
159
172
  */
160
173
  getViolationRate(): Promise<number>;
161
- /**
162
- * Function for fetching amount of total locked tokens
163
- */
164
- getTotalLocked(): Promise<number>;
165
174
  /**
166
175
  * Fetch new Origins (createdDate, createdBy, modifiedDate and modifiedBy)
167
176
  */
@@ -61,6 +61,7 @@ var SlotUsage_1 = require("../types/SlotUsage");
61
61
  var utils_2 = require("ethers/lib/utils");
62
62
  var SlotInfo_1 = require("../types/SlotInfo");
63
63
  var TeeOffers_1 = __importDefault(require("../staticModels/TeeOffers"));
64
+ var TCB_1 = __importDefault(require("../models/TCB"));
64
65
  var TeeOffer = /** @class */ (function () {
65
66
  function TeeOffer(offerId) {
66
67
  this.id = offerId;
@@ -308,6 +309,94 @@ var TeeOffer = /** @class */ (function () {
308
309
  });
309
310
  });
310
311
  };
312
+ TeeOffer.prototype.initializeTcb = function (transactionOptions) {
313
+ return __awaiter(this, void 0, void 0, function () {
314
+ var contract;
315
+ return __generator(this, function (_a) {
316
+ switch (_a.label) {
317
+ case 0:
318
+ contract = BlockchainConnector_1.default.getInstance().getContract();
319
+ (0, utils_1.checkIfActionAccountInitialized)();
320
+ return [4 /*yield*/, TxManager_1.default.execute(contract.methods.initializeTcb, [this.id], transactionOptions)];
321
+ case 1:
322
+ _a.sent();
323
+ return [2 /*return*/];
324
+ }
325
+ });
326
+ });
327
+ };
328
+ TeeOffer.prototype.initializeTcbAndAssignBlocks = function (transactionOptions) {
329
+ return __awaiter(this, void 0, void 0, function () {
330
+ var tcbId, tcb;
331
+ return __generator(this, function (_a) {
332
+ switch (_a.label) {
333
+ case 0: return [4 /*yield*/, this.initializeTcb(transactionOptions)];
334
+ case 1:
335
+ _a.sent();
336
+ return [4 /*yield*/, this.getInitializedTcbId()];
337
+ case 2:
338
+ tcbId = _a.sent();
339
+ tcb = new TCB_1.default(tcbId);
340
+ return [4 /*yield*/, tcb.assignLastBlocksToCheck(transactionOptions)];
341
+ case 3:
342
+ _a.sent();
343
+ return [4 /*yield*/, tcb.assignSuspiciousBlocksToCheck(transactionOptions)];
344
+ case 4:
345
+ _a.sent();
346
+ return [2 /*return*/, tcb];
347
+ }
348
+ });
349
+ });
350
+ };
351
+ /**
352
+ * Function initialize TCB and returns list of anothers' TCB for their checking
353
+ * @param teeOfferId - id of TEE offer
354
+ * @param transactionOptions - object what contains alternative action account or gas limit (optional)
355
+ * @returns tcbId and lists of anothers' TCB for their checking
356
+ */
357
+ TeeOffer.prototype.getListsForVerification = function (transactionOptions) {
358
+ return __awaiter(this, void 0, void 0, function () {
359
+ var tcb, blocksIds, tcbsForVerification, blockIndex, tcb_1, tcbInfo;
360
+ return __generator(this, function (_a) {
361
+ switch (_a.label) {
362
+ case 0:
363
+ (0, utils_1.checkIfActionAccountInitialized)();
364
+ return [4 /*yield*/, this.initializeTcbAndAssignBlocks(transactionOptions)];
365
+ case 1:
366
+ tcb = _a.sent();
367
+ return [4 /*yield*/, tcb.getCheckingBlocksMarks()];
368
+ case 2:
369
+ blocksIds = (_a.sent()).blocksIds;
370
+ tcbsForVerification = [];
371
+ blockIndex = 0;
372
+ _a.label = 3;
373
+ case 3:
374
+ if (!(blockIndex < blocksIds.length)) return [3 /*break*/, 6];
375
+ tcb_1 = new TCB_1.default(blocksIds[blockIndex]);
376
+ return [4 /*yield*/, tcb_1.get()];
377
+ case 4:
378
+ tcbInfo = _a.sent();
379
+ tcbsForVerification.push({
380
+ tcbId: blocksIds[blockIndex].toString(),
381
+ deviceId: tcbInfo.publicData.deviceID,
382
+ properties: tcbInfo.publicData.properties,
383
+ benchmark: tcbInfo.publicData.benchmark,
384
+ quote: tcbInfo.quote,
385
+ marks: tcbInfo.utilData.checkingBlockMarks,
386
+ checkingBlocks: tcbInfo.utilData.checkingBlocks,
387
+ });
388
+ _a.label = 5;
389
+ case 5:
390
+ blockIndex++;
391
+ return [3 /*break*/, 3];
392
+ case 6: return [2 /*return*/, {
393
+ tcbId: tcb.tcbId,
394
+ tcbsForVerification: tcbsForVerification,
395
+ }];
396
+ }
397
+ });
398
+ });
399
+ };
311
400
  /**
312
401
  * Function for fetching whether tee offer slot exists or not
313
402
  * @param slotId - Slot ID
@@ -471,6 +560,43 @@ var TeeOffer = /** @class */ (function () {
471
560
  });
472
561
  });
473
562
  };
563
+ /**
564
+ * @param teeOfferId - TEE offer ID
565
+ * @returns {Promise<string>} - Actual TCB ID
566
+ */
567
+ TeeOffer.prototype.getActualTcbId = function () {
568
+ return __awaiter(this, void 0, void 0, function () {
569
+ return __generator(this, function (_a) {
570
+ return [2 /*return*/, TeeOffer.contract.methods.getActualTcbId(this.id).call()];
571
+ });
572
+ });
573
+ };
574
+ /**
575
+ * Function return last inited TCB of TEE offer
576
+ * @param teeOfferId - id of TEE offer
577
+ * */
578
+ TeeOffer.prototype.getInitializedTcbId = function () {
579
+ return __awaiter(this, void 0, void 0, function () {
580
+ return __generator(this, function (_a) {
581
+ return [2 /*return*/, TeeOffer.contract.methods.getInitializedTcbId(this.id).call()];
582
+ });
583
+ });
584
+ };
585
+ TeeOffer.prototype.isTcbCreationAvailable = function () {
586
+ return __awaiter(this, void 0, void 0, function () {
587
+ var _a, offerNotBlocked, newEpochStarted, halfEpochPassed, benchmarkVerified;
588
+ return __generator(this, function (_b) {
589
+ switch (_b.label) {
590
+ case 0: return [4 /*yield*/, TeeOffer.contract.methods
591
+ .isTcbCreationAvailable(this.id)
592
+ .call()];
593
+ case 1:
594
+ _a = _b.sent(), offerNotBlocked = _a[0], newEpochStarted = _a[1], halfEpochPassed = _a[2], benchmarkVerified = _a[3];
595
+ return [2 /*return*/, offerNotBlocked && newEpochStarted && halfEpochPassed && benchmarkVerified];
596
+ }
597
+ });
598
+ });
599
+ };
474
600
  /**
475
601
  * Function for fetching TEE offer provider authority account from blockchain
476
602
  */
@@ -533,37 +659,6 @@ var TeeOffer = /** @class */ (function () {
533
659
  });
534
660
  });
535
661
  };
536
- /**
537
- * Function for fetching last TLB addition time for this TEE offer
538
- */
539
- TeeOffer.prototype.getLastTlbAddedTime = function () {
540
- return __awaiter(this, void 0, void 0, function () {
541
- var _a;
542
- return __generator(this, function (_b) {
543
- switch (_b.label) {
544
- case 0:
545
- _a = this;
546
- return [4 /*yield*/, TeeOffer.contract.methods.getTeeOfferLastTlbAddedTime().call()];
547
- case 1:
548
- _a.tlbAddedTime = _b.sent();
549
- return [2 /*return*/, this.tlbAddedTime];
550
- }
551
- });
552
- });
553
- };
554
- /**
555
- * Function for fetching last TCB addition time for this TEE offer
556
- */
557
- TeeOffer.prototype.getLastTcbAddedTime = function () {
558
- return __awaiter(this, void 0, void 0, function () {
559
- return __generator(this, function (_a) {
560
- // this.tcbAddedTime = await TeeOffer.contract.methods.getLastTcbAddedTime().call();
561
- // return this.tcbAddedTime!;
562
- // TODO: stub
563
- return [2 /*return*/, 0];
564
- });
565
- });
566
- };
567
662
  /**
568
663
  * Function for fetching violationRate for this TEE offer
569
664
  */
@@ -582,19 +677,6 @@ var TeeOffer = /** @class */ (function () {
582
677
  });
583
678
  });
584
679
  };
585
- /**
586
- * Function for fetching amount of total locked tokens
587
- */
588
- TeeOffer.prototype.getTotalLocked = function () {
589
- return __awaiter(this, void 0, void 0, function () {
590
- return __generator(this, function (_a) {
591
- // this.totalLocked = await TeeOffer.contract.methods.getTotalLocked().call();
592
- // return this.totalLocked!;
593
- // TODO: stub
594
- return [2 /*return*/, 0];
595
- });
596
- });
597
- };
598
680
  /**
599
681
  * Fetch new Origins (createdDate, createdBy, modifiedDate and modifiedBy)
600
682
  */
@@ -819,6 +901,15 @@ var TeeOffer = /** @class */ (function () {
819
901
  __decorate([
820
902
  (0, utils_1.incrementMethodCall)()
821
903
  ], TeeOffer.prototype, "deleteOption", null);
904
+ __decorate([
905
+ (0, utils_1.incrementMethodCall)()
906
+ ], TeeOffer.prototype, "initializeTcb", null);
907
+ __decorate([
908
+ (0, utils_1.incrementMethodCall)()
909
+ ], TeeOffer.prototype, "initializeTcbAndAssignBlocks", null);
910
+ __decorate([
911
+ (0, utils_1.incrementMethodCall)()
912
+ ], TeeOffer.prototype, "getListsForVerification", null);
822
913
  __decorate([
823
914
  (0, utils_1.incrementMethodCall)()
824
915
  ], TeeOffer.prototype, "addSlot", null);
@@ -0,0 +1,24 @@
1
+ /// <reference types="node" />
2
+ import IStorageProvider, { DownloadConfig } from "./IStorageProvider";
3
+ import { Readable } from "stream";
4
+ import StorageObject from "../../types/storage/StorageObject";
5
+ export type S3ClientConfig = {
6
+ accessKeyId: string;
7
+ secretAccessKey: string;
8
+ endpoint: string;
9
+ bucket: string;
10
+ };
11
+ export declare class S3StorageProvider implements IStorageProvider {
12
+ private readonly s3Client;
13
+ private readonly bucket;
14
+ private readonly multipartChunkSizeInBytes;
15
+ constructor(storageAccess: S3ClientConfig);
16
+ uploadFile(inputStream: Readable, remotePath: string, contentLength: number, progressListener?: ((total: number, current: number) => void) | undefined): Promise<void>;
17
+ private multipartUpload;
18
+ deleteObject(remotePath: string): Promise<void>;
19
+ downloadFile(remotePath: string, config: DownloadConfig, progressListener?: ((total: number, current: number) => void) | undefined): Promise<Readable>;
20
+ listObjects(remotePath: string): Promise<StorageObject[]>;
21
+ private getMetadata;
22
+ getObjectSize(remotePath: string): Promise<number>;
23
+ getLastModified(remotePath: string): Promise<Date>;
24
+ }
@@ -0,0 +1,357 @@
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 (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
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
39
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
40
+ var m = o[Symbol.asyncIterator], i;
41
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
42
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
43
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.S3StorageProvider = void 0;
47
+ var aws_sdk_1 = require("aws-sdk");
48
+ var S3StorageProvider = /** @class */ (function () {
49
+ function S3StorageProvider(storageAccess) {
50
+ this.multipartChunkSizeInBytes = 64 * 1024 * 1024; // 64MB
51
+ var accessKeyId = storageAccess.accessKeyId, secretAccessKey = storageAccess.secretAccessKey, endpoint = storageAccess.endpoint, bucket = storageAccess.bucket;
52
+ if (!accessKeyId)
53
+ throw new Error("Access key id is undefined");
54
+ if (!secretAccessKey)
55
+ throw new Error("Secret access is undefined");
56
+ if (!endpoint)
57
+ throw new Error("Endpoint is undefined");
58
+ if (!bucket)
59
+ throw new Error("Bucket is undefined");
60
+ this.bucket = bucket;
61
+ this.s3Client = new aws_sdk_1.S3({
62
+ credentials: {
63
+ accessKeyId: accessKeyId,
64
+ secretAccessKey: secretAccessKey,
65
+ },
66
+ endpoint: endpoint,
67
+ s3ForcePathStyle: true,
68
+ signatureVersion: "v4",
69
+ httpOptions: { timeout: 0 },
70
+ });
71
+ }
72
+ S3StorageProvider.prototype.uploadFile = function (inputStream, remotePath, contentLength, progressListener) {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var result;
75
+ return __generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0:
78
+ // For performance & cost optimization
79
+ // https://docs.storj.io/dcs/api-reference/s3-compatible-gateway/multipart-upload/multipart-part-size
80
+ if (inputStream.readableHighWaterMark >= this.multipartChunkSizeInBytes) {
81
+ return [2 /*return*/, this.multipartUpload(inputStream, remotePath, contentLength, progressListener)];
82
+ }
83
+ return [4 /*yield*/, this.s3Client
84
+ .putObject({
85
+ Body: inputStream,
86
+ Bucket: this.bucket,
87
+ Key: remotePath,
88
+ ContentLength: contentLength,
89
+ })
90
+ .on("httpUploadProgress", function (_a) {
91
+ var total = _a.total, loaded = _a.loaded;
92
+ return progressListener === null || progressListener === void 0 ? void 0 : progressListener(total, loaded);
93
+ })
94
+ .promise()];
95
+ case 1:
96
+ result = _a.sent();
97
+ if (result.$response.error) {
98
+ throw result.$response.error;
99
+ }
100
+ return [2 /*return*/];
101
+ }
102
+ });
103
+ });
104
+ };
105
+ S3StorageProvider.prototype.multipartUpload = function (inputStream, remotePath, contentLength, progressListener) {
106
+ var _a, inputStream_1, inputStream_1_1;
107
+ var _b, e_1, _c, _d;
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var multipart, totalWritten, partNumber, uploadId, parts, buffer, response, e_1_1, doneParams, uploadingError_1;
110
+ return __generator(this, function (_e) {
111
+ switch (_e.label) {
112
+ case 0: return [4 /*yield*/, this.s3Client
113
+ .createMultipartUpload({
114
+ Bucket: this.bucket,
115
+ Key: remotePath,
116
+ })
117
+ .promise()];
118
+ case 1:
119
+ multipart = _e.sent();
120
+ if (!multipart.UploadId) {
121
+ throw new Error("UploadId property is empty");
122
+ }
123
+ _e.label = 2;
124
+ case 2:
125
+ _e.trys.push([2, 19, , 21]);
126
+ totalWritten = 0;
127
+ partNumber = 0;
128
+ uploadId = multipart.UploadId;
129
+ parts = [];
130
+ _e.label = 3;
131
+ case 3:
132
+ _e.trys.push([3, 11, 12, 17]);
133
+ _a = true, inputStream_1 = __asyncValues(inputStream);
134
+ _e.label = 4;
135
+ case 4: return [4 /*yield*/, inputStream_1.next()];
136
+ case 5:
137
+ if (!(inputStream_1_1 = _e.sent(), _b = inputStream_1_1.done, !_b)) return [3 /*break*/, 10];
138
+ _d = inputStream_1_1.value;
139
+ _a = false;
140
+ _e.label = 6;
141
+ case 6:
142
+ _e.trys.push([6, , 8, 9]);
143
+ buffer = _d;
144
+ partNumber++;
145
+ return [4 /*yield*/, this.s3Client
146
+ .uploadPart({
147
+ Body: buffer,
148
+ Bucket: this.bucket,
149
+ Key: remotePath,
150
+ UploadId: uploadId,
151
+ PartNumber: partNumber,
152
+ })
153
+ .promise()];
154
+ case 7:
155
+ response = _e.sent();
156
+ parts.push({
157
+ ETag: response.ETag,
158
+ PartNumber: partNumber,
159
+ });
160
+ totalWritten += buffer.length;
161
+ if (!!progressListener) {
162
+ progressListener(contentLength, totalWritten);
163
+ }
164
+ return [3 /*break*/, 9];
165
+ case 8:
166
+ _a = true;
167
+ return [7 /*endfinally*/];
168
+ case 9: return [3 /*break*/, 4];
169
+ case 10: return [3 /*break*/, 17];
170
+ case 11:
171
+ e_1_1 = _e.sent();
172
+ e_1 = { error: e_1_1 };
173
+ return [3 /*break*/, 17];
174
+ case 12:
175
+ _e.trys.push([12, , 15, 16]);
176
+ if (!(!_a && !_b && (_c = inputStream_1.return))) return [3 /*break*/, 14];
177
+ return [4 /*yield*/, _c.call(inputStream_1)];
178
+ case 13:
179
+ _e.sent();
180
+ _e.label = 14;
181
+ case 14: return [3 /*break*/, 16];
182
+ case 15:
183
+ if (e_1) throw e_1.error;
184
+ return [7 /*endfinally*/];
185
+ case 16: return [7 /*endfinally*/];
186
+ case 17:
187
+ doneParams = {
188
+ Bucket: this.bucket,
189
+ Key: remotePath,
190
+ UploadId: multipart.UploadId,
191
+ MultipartUpload: { Parts: parts },
192
+ };
193
+ return [4 /*yield*/, this.s3Client.completeMultipartUpload(doneParams).promise()];
194
+ case 18:
195
+ _e.sent();
196
+ return [3 /*break*/, 21];
197
+ case 19:
198
+ uploadingError_1 = _e.sent();
199
+ return [4 /*yield*/, this.s3Client
200
+ .abortMultipartUpload({
201
+ Bucket: this.bucket,
202
+ Key: remotePath,
203
+ UploadId: multipart.UploadId,
204
+ })
205
+ .promise()];
206
+ case 20:
207
+ _e.sent();
208
+ throw uploadingError_1;
209
+ case 21: return [2 /*return*/];
210
+ }
211
+ });
212
+ });
213
+ };
214
+ S3StorageProvider.prototype.deleteObject = function (remotePath) {
215
+ return __awaiter(this, void 0, void 0, function () {
216
+ var deleteResult;
217
+ return __generator(this, function (_a) {
218
+ switch (_a.label) {
219
+ case 0: return [4 /*yield*/, this.s3Client
220
+ .deleteObject({
221
+ Bucket: this.bucket,
222
+ Key: remotePath,
223
+ })
224
+ .promise()];
225
+ case 1:
226
+ deleteResult = _a.sent();
227
+ if (deleteResult.$response.error) {
228
+ throw deleteResult.$response.error;
229
+ }
230
+ return [2 /*return*/];
231
+ }
232
+ });
233
+ });
234
+ };
235
+ S3StorageProvider.prototype.downloadFile = function (remotePath, config, progressListener) {
236
+ return __awaiter(this, void 0, void 0, function () {
237
+ var getObjectParams, start, end, downloadStream, current, fileBytesSize_1, _a;
238
+ return __generator(this, function (_b) {
239
+ switch (_b.label) {
240
+ case 0:
241
+ getObjectParams = {
242
+ Bucket: this.bucket,
243
+ Key: remotePath,
244
+ };
245
+ if (config) {
246
+ start = config.offset || 0;
247
+ end = start + (config.length || 0);
248
+ getObjectParams.Range = "bytes=".concat(start, "-").concat(end || "");
249
+ }
250
+ downloadStream = this.s3Client.getObject(getObjectParams).createReadStream();
251
+ current = 0;
252
+ if (!progressListener) return [3 /*break*/, 3];
253
+ _a = config.length;
254
+ if (_a) return [3 /*break*/, 2];
255
+ return [4 /*yield*/, this.getObjectSize(remotePath)];
256
+ case 1:
257
+ _a = (_b.sent());
258
+ _b.label = 2;
259
+ case 2:
260
+ fileBytesSize_1 = _a;
261
+ downloadStream.on("data", function (chunk) {
262
+ current += chunk.length;
263
+ progressListener(fileBytesSize_1, current);
264
+ });
265
+ _b.label = 3;
266
+ case 3: return [2 /*return*/, downloadStream];
267
+ }
268
+ });
269
+ });
270
+ };
271
+ S3StorageProvider.prototype.listObjects = function (remotePath) {
272
+ return __awaiter(this, void 0, void 0, function () {
273
+ var prefix, listObjects, result;
274
+ return __generator(this, function (_a) {
275
+ switch (_a.label) {
276
+ case 0:
277
+ prefix = remotePath.endsWith("/") ? remotePath : "".concat(remotePath, "/");
278
+ return [4 /*yield*/, this.s3Client
279
+ .listObjectsV2({
280
+ Bucket: this.bucket,
281
+ Prefix: prefix,
282
+ })
283
+ .promise()];
284
+ case 1:
285
+ listObjects = _a.sent();
286
+ if (listObjects.$response.error) {
287
+ throw listObjects.$response.error;
288
+ }
289
+ result = [];
290
+ if (listObjects.Contents) {
291
+ result = listObjects.Contents.map(function (object) { return ({
292
+ name: object.Key || "",
293
+ createdAt: object.LastModified || new Date(),
294
+ size: object.Size || 0,
295
+ }); });
296
+ }
297
+ return [2 /*return*/, result];
298
+ }
299
+ });
300
+ });
301
+ };
302
+ S3StorageProvider.prototype.getMetadata = function (remotePath) {
303
+ return __awaiter(this, void 0, void 0, function () {
304
+ var getObjectParams, metadata;
305
+ return __generator(this, function (_a) {
306
+ switch (_a.label) {
307
+ case 0:
308
+ getObjectParams = {
309
+ Bucket: this.bucket,
310
+ Key: remotePath,
311
+ };
312
+ return [4 /*yield*/, this.s3Client.headObject(getObjectParams).promise()];
313
+ case 1:
314
+ metadata = _a.sent();
315
+ if (metadata.$response.error) {
316
+ throw metadata.$response.error;
317
+ }
318
+ return [2 /*return*/, metadata];
319
+ }
320
+ });
321
+ });
322
+ };
323
+ S3StorageProvider.prototype.getObjectSize = function (remotePath) {
324
+ return __awaiter(this, void 0, void 0, function () {
325
+ var metadata;
326
+ return __generator(this, function (_a) {
327
+ switch (_a.label) {
328
+ case 0: return [4 /*yield*/, this.getMetadata(remotePath)];
329
+ case 1:
330
+ metadata = _a.sent();
331
+ if (metadata.ContentLength === undefined) {
332
+ throw new Error("ContentLength property is empty");
333
+ }
334
+ return [2 /*return*/, metadata.ContentLength || 0];
335
+ }
336
+ });
337
+ });
338
+ };
339
+ S3StorageProvider.prototype.getLastModified = function (remotePath) {
340
+ return __awaiter(this, void 0, void 0, function () {
341
+ var metadata;
342
+ return __generator(this, function (_a) {
343
+ switch (_a.label) {
344
+ case 0: return [4 /*yield*/, this.getMetadata(remotePath)];
345
+ case 1:
346
+ metadata = _a.sent();
347
+ if (!metadata.LastModified) {
348
+ throw new Error("LastModified property is empty");
349
+ }
350
+ return [2 /*return*/, metadata.LastModified];
351
+ }
352
+ });
353
+ });
354
+ };
355
+ return S3StorageProvider;
356
+ }());
357
+ exports.S3StorageProvider = S3StorageProvider;
@@ -11,7 +11,8 @@ export default class StorJStorageProvider implements IStorageProvider {
11
11
  private _access?;
12
12
  private _project?;
13
13
  private _storj?;
14
- constructor(credentials: any);
14
+ private maximumConcurrent?;
15
+ constructor(credentials: any, maximumConcurrent?: number);
15
16
  uploadFile(inputStream: stream.Readable, remotePath: string, contentLength: number, progressListener?: (total: number, current: number) => void): Promise<void>;
16
17
  downloadFile(remotePath: string, config: DownloadConfig, progressListener?: (total: number, current: number) => void): Promise<stream.Readable>;
17
18
  deleteObject(remotePath: string): Promise<void>;
@@ -63,7 +63,7 @@ var utils_1 = require("../../utils");
63
63
  var stream_1 = __importDefault(require("stream"));
64
64
  var logger_1 = __importDefault(require("../../logger"));
65
65
  var StorJStorageProvider = /** @class */ (function () {
66
- function StorJStorageProvider(credentials) {
66
+ function StorJStorageProvider(credentials, maximumConcurrent) {
67
67
  this.logger = logger_1.default.child({ className: "StorJStorageProvider" });
68
68
  if (!(0, utils_1.isNodeJS)()) {
69
69
  throw Error("StorageProvider: StorJ is supported only in the node.js execution environment");
@@ -79,6 +79,7 @@ var StorJStorageProvider = /** @class */ (function () {
79
79
  this.bucket = credentials.storageId;
80
80
  }
81
81
  this.accessToken = credentials.token;
82
+ this.maximumConcurrent = maximumConcurrent;
82
83
  }
83
84
  StorJStorageProvider.prototype.uploadFile = function (inputStream, remotePath, contentLength, progressListener) {
84
85
  var _a, inputStream_1, inputStream_1_1;
@@ -367,7 +368,7 @@ var StorJStorageProvider = /** @class */ (function () {
367
368
  case 1:
368
369
  access = _b.sent();
369
370
  _a = this;
370
- return [4 /*yield*/, access.openProject()];
371
+ return [4 /*yield*/, access.openProject(this.maximumConcurrent)];
371
372
  case 2:
372
373
  _a._project = _b.sent();
373
374
  _b.label = 3;
@@ -5,11 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var dto_js_1 = require("@super-protocol/dto-js");
7
7
  var StorjStorageProvider_1 = __importDefault(require("./StorjStorageProvider"));
8
+ var S3StorageProvider_1 = require("./S3StorageProvider");
8
9
  exports.default = (function (storageAccess) {
9
10
  var key = storageAccess.storageType;
10
11
  switch (key) {
11
12
  case dto_js_1.StorageType.StorJ:
12
- return new StorjStorageProvider_1.default(storageAccess.credentials);
13
+ return new StorjStorageProvider_1.default(storageAccess.credentials, storageAccess.maximumConcurrent);
14
+ case dto_js_1.StorageType.S3:
15
+ return new S3StorageProvider_1.S3StorageProvider(storageAccess.credentials);
13
16
  default:
14
17
  throw Error("Unsupported storageType ".concat(key));
15
18
  }
@@ -1,39 +1,22 @@
1
1
  import { EpochInfo } from "../types/Consensus";
2
- import { GetTcbRequest } from "@super-protocol/dto-js";
3
2
  import { TransactionOptions, BlockInfo } from "../types/Web3";
4
3
  import { ConsensusConstants } from "../types/Consensus";
5
4
  declare class Consensus {
6
5
  private static readonly logger;
7
6
  private static tcbIds?;
8
7
  static get address(): string;
9
- private static initializeTcbAndAssignBlocks;
10
8
  /**
11
9
  * Function for fetching list of all tcb ids
12
10
  * @returns list of tcb ids
13
11
  */
14
12
  static getAllTcbs(): Promise<string[]>;
15
- static initializeTcb(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<void>;
16
13
  static unlockProfitByTcbList(tcbIds: string[], transactionOptions?: TransactionOptions): Promise<void>;
17
- static isTcbCreationAvailable(teeOfferId: string): Promise<boolean>;
18
- /**
19
- * Function initialize TCB and returns list of anothers' TCB for their checking
20
- * @param teeOfferId - id of TEE offer
21
- * @param transactionOptions - object what contains alternative action account or gas limit (optional)
22
- * @returns tcbId and lists of anothers' TCB for their checking
23
- */
24
- static getListsForVerification(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<GetTcbRequest>;
25
- /**
26
- * Function return last inited TCB of TEE offer
27
- * @param teeOfferId - id of TEE offer
28
- * */
29
- static getInitializedTcbId(teeOfferId: string): Promise<string>;
30
14
  static getEpochTime(time: number): Promise<{
31
15
  epochStart: number;
32
16
  epochEnd: number;
33
17
  epochIndex: number;
34
18
  }>;
35
19
  static getEpoch(epochIndex: number): Promise<EpochInfo>;
36
- static getActualTcbId(teeOfferId: string): Promise<string>;
37
20
  static getSuspiciousBlockTable(): Promise<string[]>;
38
21
  static getSuspiciousBlockTableSize(): Promise<string[]>;
39
22
  static getLastBlockTable(): Promise<string[]>;
@@ -57,29 +57,6 @@ var Consensus = /** @class */ (function () {
57
57
  enumerable: false,
58
58
  configurable: true
59
59
  });
60
- Consensus.initializeTcbAndAssignBlocks = function (teeOfferId, transactionOptions) {
61
- return __awaiter(this, void 0, void 0, function () {
62
- var tcbId, tcb;
63
- return __generator(this, function (_a) {
64
- switch (_a.label) {
65
- case 0: return [4 /*yield*/, this.initializeTcb(teeOfferId, transactionOptions)];
66
- case 1:
67
- _a.sent();
68
- return [4 /*yield*/, this.getInitializedTcbId(teeOfferId)];
69
- case 2:
70
- tcbId = _a.sent();
71
- tcb = new TCB_1.default(tcbId);
72
- return [4 /*yield*/, tcb.assignLastBlocksToCheck(transactionOptions)];
73
- case 3:
74
- _a.sent();
75
- return [4 /*yield*/, tcb.assignSuspiciousBlocksToCheck(transactionOptions)];
76
- case 4:
77
- _a.sent();
78
- return [2 /*return*/, tcb];
79
- }
80
- });
81
- });
82
- };
83
60
  /**
84
61
  * Function for fetching list of all tcb ids
85
62
  * @returns list of tcb ids
@@ -105,22 +82,6 @@ var Consensus = /** @class */ (function () {
105
82
  });
106
83
  });
107
84
  };
108
- Consensus.initializeTcb = function (teeOfferId, transactionOptions) {
109
- return __awaiter(this, void 0, void 0, function () {
110
- var contract;
111
- return __generator(this, function (_a) {
112
- switch (_a.label) {
113
- case 0:
114
- contract = BlockchainConnector_1.default.getInstance().getContract();
115
- (0, utils_1.checkIfActionAccountInitialized)();
116
- return [4 /*yield*/, TxManager_1.default.execute(contract.methods.initializeTcb, [teeOfferId], transactionOptions)];
117
- case 1:
118
- _a.sent();
119
- return [2 /*return*/];
120
- }
121
- });
122
- });
123
- };
124
85
  Consensus.unlockProfitByTcbList = function (tcbIds, transactionOptions) {
125
86
  return __awaiter(this, void 0, void 0, function () {
126
87
  var contract, executedCount, e_1, _i, tcbIds_1, tcbId;
@@ -164,85 +125,6 @@ var Consensus = /** @class */ (function () {
164
125
  });
165
126
  });
166
127
  };
167
- Consensus.isTcbCreationAvailable = function (teeOfferId) {
168
- return __awaiter(this, void 0, void 0, function () {
169
- var contract, _a, offerNotBlocked, newEpochStarted, halfEpochPassed, benchmarkVerified;
170
- return __generator(this, function (_b) {
171
- switch (_b.label) {
172
- case 0:
173
- contract = BlockchainConnector_1.default.getInstance().getContract();
174
- return [4 /*yield*/, contract.methods
175
- .isTcbCreationAvailable(teeOfferId)
176
- .call()];
177
- case 1:
178
- _a = _b.sent(), offerNotBlocked = _a[0], newEpochStarted = _a[1], halfEpochPassed = _a[2], benchmarkVerified = _a[3];
179
- return [2 /*return*/, offerNotBlocked && newEpochStarted && halfEpochPassed && benchmarkVerified];
180
- }
181
- });
182
- });
183
- };
184
- /**
185
- * Function initialize TCB and returns list of anothers' TCB for their checking
186
- * @param teeOfferId - id of TEE offer
187
- * @param transactionOptions - object what contains alternative action account or gas limit (optional)
188
- * @returns tcbId and lists of anothers' TCB for their checking
189
- */
190
- Consensus.getListsForVerification = function (teeOfferId, transactionOptions) {
191
- return __awaiter(this, void 0, void 0, function () {
192
- var tcb, blocksIds, tcbsForVerification, blockIndex, tcb_1, tcbInfo;
193
- return __generator(this, function (_a) {
194
- switch (_a.label) {
195
- case 0:
196
- (0, utils_1.checkIfActionAccountInitialized)();
197
- return [4 /*yield*/, this.initializeTcbAndAssignBlocks(teeOfferId, transactionOptions)];
198
- case 1:
199
- tcb = _a.sent();
200
- return [4 /*yield*/, tcb.getCheckingBlocksMarks()];
201
- case 2:
202
- blocksIds = (_a.sent()).blocksIds;
203
- tcbsForVerification = [];
204
- blockIndex = 0;
205
- _a.label = 3;
206
- case 3:
207
- if (!(blockIndex < blocksIds.length)) return [3 /*break*/, 6];
208
- tcb_1 = new TCB_1.default(blocksIds[blockIndex]);
209
- return [4 /*yield*/, tcb_1.get()];
210
- case 4:
211
- tcbInfo = _a.sent();
212
- tcbsForVerification.push({
213
- tcbId: blocksIds[blockIndex].toString(),
214
- deviceId: tcbInfo.publicData.deviceID,
215
- properties: tcbInfo.publicData.properties,
216
- benchmark: tcbInfo.publicData.benchmark,
217
- quote: tcbInfo.quote,
218
- marks: tcbInfo.utilData.checkingBlockMarks,
219
- checkingBlocks: tcbInfo.utilData.checkingBlocks,
220
- });
221
- _a.label = 5;
222
- case 5:
223
- blockIndex++;
224
- return [3 /*break*/, 3];
225
- case 6: return [2 /*return*/, {
226
- tcbId: tcb.tcbId,
227
- tcbsForVerification: tcbsForVerification,
228
- }];
229
- }
230
- });
231
- });
232
- };
233
- /**
234
- * Function return last inited TCB of TEE offer
235
- * @param teeOfferId - id of TEE offer
236
- * */
237
- Consensus.getInitializedTcbId = function (teeOfferId) {
238
- return __awaiter(this, void 0, void 0, function () {
239
- var contract;
240
- return __generator(this, function (_a) {
241
- contract = BlockchainConnector_1.default.getInstance().getContract();
242
- return [2 /*return*/, contract.methods.getInitializedTcbId(teeOfferId).call()];
243
- });
244
- });
245
- };
246
128
  Consensus.getEpochTime = function (time) {
247
129
  return __awaiter(this, void 0, void 0, function () {
248
130
  var contract, _a, epochStart, epochEnd, epochIndex;
@@ -275,15 +157,6 @@ var Consensus = /** @class */ (function () {
275
157
  });
276
158
  });
277
159
  };
278
- Consensus.getActualTcbId = function (teeOfferId) {
279
- return __awaiter(this, void 0, void 0, function () {
280
- var contract;
281
- return __generator(this, function (_a) {
282
- contract = BlockchainConnector_1.default.getInstance().getContract();
283
- return [2 /*return*/, contract.methods.getActualTcbId(teeOfferId).call()];
284
- });
285
- });
286
- };
287
160
  Consensus.getSuspiciousBlockTable = function () {
288
161
  return __awaiter(this, void 0, void 0, function () {
289
162
  var contract;
@@ -2,5 +2,6 @@ import { StorageType } from "@super-protocol/dto-js";
2
2
  type StorageAccess = {
3
3
  storageType: StorageType;
4
4
  credentials: any;
5
+ maximumConcurrent?: number;
5
6
  };
6
7
  export default StorageAccess;
@@ -1,8 +1,8 @@
1
1
  type StorageObject = {
2
2
  name: string;
3
3
  size: number;
4
- isFolder: boolean;
5
- childrenCount: number;
4
+ isFolder?: boolean;
5
+ childrenCount?: number;
6
6
  createdAt: Date;
7
7
  };
8
8
  export default StorageObject;
@@ -6,6 +6,7 @@ export interface TryWithIntervalParams<T> {
6
6
  checkError?: (err: unknown) => {
7
7
  retryable: boolean;
8
8
  };
9
+ startDelay?: number;
9
10
  retryInterval: number;
10
11
  retryMax: number;
11
12
  }
@@ -38,12 +38,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.tryWithInterval = void 0;
40
40
  var tryWithInterval = function (params) { return __awaiter(void 0, void 0, void 0, function () {
41
- var checkedTimes, handler, checkResult, checkError, retryInterval, retryMax;
42
- return __generator(this, function (_a) {
43
- switch (_a.label) {
41
+ var checkedTimes, handler, checkResult, checkError, _a, startDelay, retryInterval, retryMax;
42
+ return __generator(this, function (_b) {
43
+ switch (_b.label) {
44
44
  case 0:
45
45
  checkedTimes = 0;
46
- handler = params.handler, checkResult = params.checkResult, checkError = params.checkError, retryInterval = params.retryInterval, retryMax = params.retryMax;
46
+ handler = params.handler, checkResult = params.checkResult, checkError = params.checkError, _a = params.startDelay, startDelay = _a === void 0 ? 0 : _a, retryInterval = params.retryInterval, retryMax = params.retryMax;
47
47
  return [4 /*yield*/, new Promise(function (resolve, reject) {
48
48
  var checkTimes = function () {
49
49
  checkedTimes += 1;
@@ -83,9 +83,9 @@ var tryWithInterval = function (params) { return __awaiter(void 0, void 0, void
83
83
  }
84
84
  });
85
85
  }); };
86
- setTimeout(timeoutFn, retryInterval);
86
+ setTimeout(timeoutFn, startDelay);
87
87
  })];
88
- case 1: return [2 /*return*/, _a.sent()];
88
+ case 1: return [2 /*return*/, _b.sent()];
89
89
  }
90
90
  });
91
91
  }); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-protocol/sdk-js",
3
- "version": "0.14.0-beta.0",
3
+ "version": "0.14.1-beta.2",
4
4
  "main": "build/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -52,9 +52,10 @@
52
52
  "typescript": "^4.4.4"
53
53
  },
54
54
  "dependencies": {
55
- "@super-protocol/dto-js": "0.0.24",
55
+ "@super-protocol/dto-js": "0.0.28",
56
56
  "@super-protocol/tee-lib": "^0.1.2",
57
- "@super-protocol/uplink-nodejs": "1.2.12",
57
+ "@super-protocol/uplink-nodejs": "1.2.16",
58
+ "aws-sdk": "^2.1418.0",
58
59
  "ethers": "^5.5.3",
59
60
  "hybrid-crypto-js": "^0.2.4",
60
61
  "lodash": "^4.17.21",
@@ -64,5 +65,8 @@
64
65
  "web3": "^1.7.1",
65
66
  "web3-parse-receipt-events": "^1.0.2"
66
67
  },
67
- "repository": "git://github.com/Super-Protocol/sdk-js.git"
68
+ "repository": "git://github.com/Super-Protocol/sdk-js.git",
69
+ "resolutions": {
70
+ "wrap-ansi": "7.0.0"
71
+ }
68
72
  }