@super-protocol/sdk-js 0.11.9-beta.6 → 0.11.9-beta.8

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.
@@ -1788,6 +1788,40 @@
1788
1788
  "stateMutability": "view",
1789
1789
  "type": "function"
1790
1790
  },
1791
+ {
1792
+ "inputs": [
1793
+ {
1794
+ "internalType": "uint256",
1795
+ "name": "teeOfferId",
1796
+ "type": "uint256"
1797
+ }
1798
+ ],
1799
+ "name": "isTcbCreationAvailable",
1800
+ "outputs": [
1801
+ {
1802
+ "internalType": "bool",
1803
+ "name": "offerNotBlocked",
1804
+ "type": "bool"
1805
+ },
1806
+ {
1807
+ "internalType": "bool",
1808
+ "name": "newEpochStarted",
1809
+ "type": "bool"
1810
+ },
1811
+ {
1812
+ "internalType": "bool",
1813
+ "name": "halfEpochPassed",
1814
+ "type": "bool"
1815
+ },
1816
+ {
1817
+ "internalType": "bool",
1818
+ "name": "benchmarkVerified",
1819
+ "type": "bool"
1820
+ }
1821
+ ],
1822
+ "stateMutability": "view",
1823
+ "type": "function"
1824
+ },
1791
1825
  {
1792
1826
  "inputs": [
1793
1827
  {
@@ -4,15 +4,16 @@ declare class Consensus {
4
4
  static get address(): string;
5
5
  private static initializeTcbAndAssignBlocks;
6
6
  static initializeTcb(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<void>;
7
+ static isTcbCreationAvailable(teeOfferId: string): Promise<boolean>;
7
8
  /**
8
9
  * Function initialize TCB and returns list of anothers' TCB for their checking
9
10
  * @param teeOfferId - id of TEE offer
10
11
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
11
12
  * @returns tcbId and lists of anothers' TCB for their checking
12
13
  */
13
- static getListsForVerification(teeOfferId: string, initializeTcbForce?: boolean, transactionOptions?: TransactionOptions): Promise<{
14
+ static getListsForVerification(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<{
14
15
  tcbId: string;
15
- checkingTcbData: CheckingTcbData[];
16
+ tcbsForVerification: CheckingTcbData[];
16
17
  }>;
17
18
  /**
18
19
  * Function return last inited TCB of TEE offer
@@ -41,7 +41,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var TCB_1 = __importDefault(require("../models/TCB"));
43
43
  var utils_1 = require("../utils");
44
- var constants_1 = require("../constants");
45
44
  var Superpro_1 = __importDefault(require("./Superpro"));
46
45
  var BlockchainConnector_1 = __importDefault(require("../connectors/BlockchainConnector"));
47
46
  var TxManager_1 = __importDefault(require("../utils/TxManager"));
@@ -55,39 +54,25 @@ var Consensus = /** @class */ (function () {
55
54
  enumerable: false,
56
55
  configurable: true
57
56
  });
58
- Consensus.initializeTcbAndAssignBlocks = function (teeOfferId, initializeTcbForce, transactionOptions) {
57
+ Consensus.initializeTcbAndAssignBlocks = function (teeOfferId, transactionOptions) {
59
58
  return __awaiter(this, void 0, void 0, function () {
60
- var tcbId, tcb, timeInitialized, isFirstOffersTcb, isCreatedMoreThenOneDayAgo, _a;
61
- return __generator(this, function (_b) {
62
- switch (_b.label) {
63
- case 0: return [4 /*yield*/, this.getInitializedTcbId(teeOfferId)];
59
+ var tcbId, tcb;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0: return [4 /*yield*/, this.initializeTcb(teeOfferId, transactionOptions)];
64
63
  case 1:
65
- tcbId = _b.sent();
66
- tcb = new TCB_1.default(tcbId);
67
- return [4 /*yield*/, tcb.get()];
68
- case 2:
69
- timeInitialized = +(_b.sent()).timeInitialized;
70
- isFirstOffersTcb = timeInitialized == 0;
71
- _a = timeInitialized + constants_1.ONE_DAY;
72
- return [4 /*yield*/, (0, utils_1.getTimestamp)()];
73
- case 3:
74
- isCreatedMoreThenOneDayAgo = _a < +(_b.sent());
75
- if (!(isFirstOffersTcb || isCreatedMoreThenOneDayAgo || initializeTcbForce)) return [3 /*break*/, 8];
76
- return [4 /*yield*/, this.initializeTcb(teeOfferId, transactionOptions)];
77
- case 4:
78
- _b.sent();
64
+ _a.sent();
79
65
  return [4 /*yield*/, this.getInitializedTcbId(teeOfferId)];
80
- case 5:
81
- tcbId = _b.sent();
66
+ case 2:
67
+ tcbId = _a.sent();
82
68
  tcb = new TCB_1.default(tcbId);
83
69
  return [4 /*yield*/, tcb.assignLastBlocksToCheck(transactionOptions)];
84
- case 6:
85
- _b.sent();
70
+ case 3:
71
+ _a.sent();
86
72
  return [4 /*yield*/, tcb.assignSuspiciousBlocksToCheck(transactionOptions)];
87
- case 7:
88
- _b.sent();
89
- _b.label = 8;
90
- case 8: return [2 /*return*/, tcb];
73
+ case 4:
74
+ _a.sent();
75
+ return [2 /*return*/, tcb];
91
76
  }
92
77
  });
93
78
  });
@@ -108,27 +93,38 @@ var Consensus = /** @class */ (function () {
108
93
  });
109
94
  });
110
95
  };
96
+ Consensus.isTcbCreationAvailable = function (teeOfferId) {
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ var contract, _a, offerNotBlocked, newEpochStarted, halfEpochPassed, benchmarkVerified;
99
+ return __generator(this, function (_b) {
100
+ contract = BlockchainConnector_1.default.getInstance().getContract();
101
+ _a = contract.methods
102
+ .isTcbCreationAvailable(teeOfferId)
103
+ .call(), offerNotBlocked = _a[0], newEpochStarted = _a[1], halfEpochPassed = _a[2], benchmarkVerified = _a[3];
104
+ return [2 /*return*/, offerNotBlocked && newEpochStarted && halfEpochPassed && benchmarkVerified];
105
+ });
106
+ });
107
+ };
111
108
  /**
112
109
  * Function initialize TCB and returns list of anothers' TCB for their checking
113
110
  * @param teeOfferId - id of TEE offer
114
111
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
115
112
  * @returns tcbId and lists of anothers' TCB for their checking
116
113
  */
117
- Consensus.getListsForVerification = function (teeOfferId, initializeTcbForce, transactionOptions) {
118
- if (initializeTcbForce === void 0) { initializeTcbForce = false; }
114
+ Consensus.getListsForVerification = function (teeOfferId, transactionOptions) {
119
115
  return __awaiter(this, void 0, void 0, function () {
120
- var tcb, blocksIds, checkingTcbData, blockIndex, tcb_1, tcbInfo;
116
+ var tcb, blocksIds, tcbsForVerification, blockIndex, tcb_1, tcbInfo;
121
117
  return __generator(this, function (_a) {
122
118
  switch (_a.label) {
123
119
  case 0:
124
120
  (0, utils_1.checkIfActionAccountInitialized)();
125
- return [4 /*yield*/, this.initializeTcbAndAssignBlocks(teeOfferId, initializeTcbForce, transactionOptions)];
121
+ return [4 /*yield*/, this.initializeTcbAndAssignBlocks(teeOfferId, transactionOptions)];
126
122
  case 1:
127
123
  tcb = _a.sent();
128
124
  return [4 /*yield*/, tcb.getCheckingBlocksMarks()];
129
125
  case 2:
130
126
  blocksIds = (_a.sent()).blocksIds;
131
- checkingTcbData = [];
127
+ tcbsForVerification = [];
132
128
  blockIndex = 0;
133
129
  _a.label = 3;
134
130
  case 3:
@@ -137,12 +133,13 @@ var Consensus = /** @class */ (function () {
137
133
  return [4 /*yield*/, tcb_1.get()];
138
134
  case 4:
139
135
  tcbInfo = _a.sent();
140
- checkingTcbData.push({
141
- deviceID: tcbInfo.publicData.deviceID,
136
+ tcbsForVerification.push({
137
+ deviceId: tcbInfo.publicData.deviceID,
142
138
  properties: tcbInfo.publicData.properties,
143
139
  benchmark: tcbInfo.publicData.benchmark,
144
- tcbQuote: tcbInfo.quote,
145
- tcbMarks: tcbInfo.utilData.checkingBlockMarks,
140
+ quote: tcbInfo.quote,
141
+ marks: tcbInfo.utilData.checkingBlockMarks,
142
+ checkingBlocks: tcbInfo.utilData.checkingBlocks,
146
143
  });
147
144
  _a.label = 5;
148
145
  case 5:
@@ -150,7 +147,7 @@ var Consensus = /** @class */ (function () {
150
147
  return [3 /*break*/, 3];
151
148
  case 6: return [2 /*return*/, {
152
149
  tcbId: tcb.tcbId,
153
- checkingTcbData: checkingTcbData,
150
+ tcbsForVerification: tcbsForVerification,
154
151
  }];
155
152
  }
156
153
  });
@@ -171,18 +168,18 @@ var Consensus = /** @class */ (function () {
171
168
  };
172
169
  Consensus.getEpochTime = function (time) {
173
170
  return __awaiter(this, void 0, void 0, function () {
174
- var contract, result;
175
- return __generator(this, function (_a) {
176
- switch (_a.label) {
171
+ var contract, _a, epochStart, epochEnd, epochIndex;
172
+ return __generator(this, function (_b) {
173
+ switch (_b.label) {
177
174
  case 0:
178
175
  contract = BlockchainConnector_1.default.getInstance().getContract();
179
176
  return [4 /*yield*/, contract.methods.getEpochTime(time).call()];
180
177
  case 1:
181
- result = _a.sent();
178
+ _a = _b.sent(), epochStart = _a[0], epochEnd = _a[1], epochIndex = _a[2];
182
179
  return [2 /*return*/, {
183
- epochStart: result[0],
184
- epochEnd: result[1],
185
- epochIndex: result[2],
180
+ epochStart: epochStart,
181
+ epochEnd: epochEnd,
182
+ epochIndex: epochIndex,
186
183
  }];
187
184
  }
188
185
  });
@@ -11,7 +11,7 @@ export declare const PublicDataStructure: {
11
11
  properties: StringConstructor;
12
12
  };
13
13
  export declare type PublicData = {
14
- teeOffer: string;
14
+ teeOffer?: string;
15
15
  deviceID: string;
16
16
  benchmark: number;
17
17
  properties: string;
@@ -100,9 +100,10 @@ export declare type EpochInfo = {
100
100
  penaltyBenchmark: number;
101
101
  };
102
102
  export declare type CheckingTcbData = {
103
- deviceID: string;
103
+ deviceId: string;
104
104
  properties: string;
105
105
  benchmark: number;
106
- tcbQuote: string;
107
- tcbMarks: [TcbVerifiedStatus];
106
+ quote: string;
107
+ marks: [TcbVerifiedStatus];
108
+ checkingBlocks: [number];
108
109
  };
package/build/utils.js CHANGED
@@ -48,7 +48,7 @@ var lodash_1 = require("lodash");
48
48
  */
49
49
  var checkIfActionAccountInitialized = function (transactionOptions) {
50
50
  if (!store_1.default.actionAccount && !(transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3))
51
- throw new Error("Provider action account is not initialized, needs to run 'BlockchainConnector.getInstance().initActionAccount(SECRET_KEY)' first");
51
+ throw new Error("Provider action account is not initialized, needs to run 'BlockchainConnector.getInstance().initializeActionAccount(SECRET_KEY)' first");
52
52
  };
53
53
  exports.checkIfActionAccountInitialized = checkIfActionAccountInitialized;
54
54
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-protocol/sdk-js",
3
- "version": "0.11.9-beta.6",
3
+ "version": "0.11.9-beta.8",
4
4
  "main": "build/index.js",
5
5
  "license": "MIT",
6
6
  "files": [