@super-protocol/sdk-js 0.8.1-beta.1 → 0.8.1-beta.4

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.
@@ -20,6 +20,7 @@ declare class BlockchainConnector {
20
20
  * Returns balance of blockchain platform tokens in wei
21
21
  */
22
22
  static getBalance(address: string): Promise<string>;
23
+ static getTimestamp(): Promise<number | string>;
23
24
  /**
24
25
  * Returns transactions events info
25
26
  * @param txHash - transaction hash
@@ -150,6 +150,22 @@ var BlockchainConnector = /** @class */ (function () {
150
150
  });
151
151
  });
152
152
  };
153
+ BlockchainConnector.getTimestamp = function () {
154
+ var _a;
155
+ return __awaiter(this, void 0, void 0, function () {
156
+ var block;
157
+ return __generator(this, function (_b) {
158
+ switch (_b.label) {
159
+ case 0:
160
+ (0, utils_1.checkIfInitialized)();
161
+ return [4 /*yield*/, ((_a = store_1.default.web3) === null || _a === void 0 ? void 0 : _a.eth.getBlock("latest"))];
162
+ case 1:
163
+ block = _b.sent();
164
+ return [2 /*return*/, block.timestamp];
165
+ }
166
+ });
167
+ });
168
+ };
153
169
  /**
154
170
  * Returns transactions events info
155
171
  * @param txHash - transaction hash
@@ -12,6 +12,7 @@ declare class Offer {
12
12
  id: string;
13
13
  disabledAfter?: number;
14
14
  closingPrice?: string;
15
+ holdDeposit?: string;
15
16
  constructor(offerId: string);
16
17
  /**
17
18
  * Checks if contract has been initialized, if not - initialize contract
@@ -49,6 +50,10 @@ declare class Offer {
49
50
  * Fetch new Origins (createdDate, createdBy, modifiedDate and modifiedBy)
50
51
  */
51
52
  getOrigins(): Promise<Origins>;
53
+ /**
54
+ * Function for fetching offer hold deposit
55
+ */
56
+ getHoldDeposit(): Promise<string>;
52
57
  /**
53
58
  * Function for offer closing price calculation
54
59
  */
@@ -200,6 +200,24 @@ var Offer = /** @class */ (function () {
200
200
  });
201
201
  });
202
202
  };
203
+ /**
204
+ * Function for fetching offer hold deposit
205
+ */
206
+ Offer.prototype.getHoldDeposit = function () {
207
+ return __awaiter(this, void 0, void 0, function () {
208
+ var _a;
209
+ return __generator(this, function (_b) {
210
+ switch (_b.label) {
211
+ case 0:
212
+ _a = this;
213
+ return [4 /*yield*/, Offer.contract.methods.getOfferHoldDeposit(this.id).call()];
214
+ case 1:
215
+ _a.holdDeposit = _b.sent();
216
+ return [2 /*return*/, this.holdDeposit];
217
+ }
218
+ });
219
+ });
220
+ };
203
221
  /**
204
222
  * Function for offer closing price calculation
205
223
  */
@@ -83,7 +83,7 @@ var TCB = /** @class */ (function () {
83
83
  switch (_a.label) {
84
84
  case 0:
85
85
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
86
- fromattedDeviceId = (0, utils_2.formatBytes32String)(Buffer.from(pb.deviceID, "hex").toString("base64"));
86
+ fromattedDeviceId = (0, utils_2.formatBytes32String)(Buffer.from(pb.deviceID).toString("base64"));
87
87
  return [4 /*yield*/, TxManager_1.default.execute(this.contract.methods.setTcbData, [this.tcbId, pb.benchmark, pb.properties, fromattedDeviceId, quote], transactionOptions)];
88
88
  case 1:
89
89
  _a.sent();
@@ -1,4 +1,4 @@
1
- import { CheckingTcbData } from "../types/Consensus";
1
+ import { CheckingTcbData, EpochInfo } from "../types/Consensus";
2
2
  import { TransactionOptions } from "../types/Web3";
3
3
  declare class Consensus {
4
4
  static address: string;
@@ -8,7 +8,8 @@ declare class Consensus {
8
8
  * Checks if contract has been initialized, if not - initialize contract
9
9
  */
10
10
  private static checkInit;
11
- private static initializeTcb;
11
+ private static initializeTcbAndAssignBlocks;
12
+ static initializeTcb(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<void>;
12
13
  /**
13
14
  * Function initialize TCB and returns list of anothers' TCB for their checking
14
15
  * @param teeOfferId - id of TEE offer
@@ -25,8 +26,11 @@ declare class Consensus {
25
26
  * */
26
27
  static getInitializedTcbId(teeOfferId: string): Promise<string>;
27
28
  static getEpochIndex(): Promise<number>;
29
+ static getEpoch(epochIndex: number): Promise<EpochInfo>;
28
30
  static getActualTcbId(teeOfferId: string): Promise<string>;
29
31
  static getSuspiciousBlockTable(): Promise<string[]>;
32
+ static getSuspiciousBlockTableSize(): Promise<string[]>;
30
33
  static getLastBlockTable(): Promise<string[]>;
34
+ static getLastBlockTableSize(): Promise<string[]>;
31
35
  }
32
36
  export default Consensus;
@@ -64,42 +64,54 @@ var Consensus = /** @class */ (function () {
64
64
  this.logger = logger_1.default.child({ className: "Consensus" });
65
65
  return (this.contract = new store_1.default.web3.eth.Contract(app_json_1.default.abi, Superpro_1.default.address));
66
66
  };
67
- Consensus.initializeTcb = function (teeOfferId, transactionOptions) {
67
+ Consensus.initializeTcbAndAssignBlocks = function (teeOfferId, transactionOptions) {
68
68
  return __awaiter(this, void 0, void 0, function () {
69
- var tcbId, tcb, timeInitialized, _a, _b;
70
- return __generator(this, function (_c) {
71
- switch (_c.label) {
69
+ var tcbId, tcb, timeInitialized, isFirstOffersTcb, isCreatedMoreThenOneDayAgo, _a;
70
+ return __generator(this, function (_b) {
71
+ switch (_b.label) {
72
72
  case 0: return [4 /*yield*/, this.getInitializedTcbId(teeOfferId)];
73
73
  case 1:
74
- tcbId = _c.sent();
74
+ tcbId = _b.sent();
75
75
  tcb = new TCB_1.default(tcbId);
76
76
  return [4 /*yield*/, tcb.get()];
77
77
  case 2:
78
- timeInitialized = (_c.sent()).timeInitialized;
79
- _a = timeInitialized == 0;
80
- if (_a) return [3 /*break*/, 4];
81
- _b = timeInitialized;
78
+ timeInitialized = +(_b.sent()).timeInitialized;
79
+ isFirstOffersTcb = timeInitialized == 0;
80
+ _a = timeInitialized + constants_1.ONE_DAY;
82
81
  return [4 /*yield*/, (0, utils_1.getTimestamp)()];
83
82
  case 3:
84
- _a = _b > +(_c.sent()) + constants_1.ONE_DAY;
85
- _c.label = 4;
83
+ isCreatedMoreThenOneDayAgo = _a < +(_b.sent());
84
+ if (!(isFirstOffersTcb || isCreatedMoreThenOneDayAgo)) return [3 /*break*/, 8];
85
+ return [4 /*yield*/, this.initializeTcb(teeOfferId, transactionOptions)];
86
86
  case 4:
87
- if (!_a) return [3 /*break*/, 9];
88
- return [4 /*yield*/, TxManager_1.default.execute(this.contract.methods.initializeTcb, [teeOfferId], transactionOptions)];
89
- case 5:
90
- _c.sent();
87
+ _b.sent();
91
88
  return [4 /*yield*/, this.getInitializedTcbId(teeOfferId)];
92
- case 6:
93
- tcbId = _c.sent();
89
+ case 5:
90
+ tcbId = _b.sent();
94
91
  tcb = new TCB_1.default(tcbId);
95
92
  return [4 /*yield*/, tcb.assignLastBlocksToCheck(transactionOptions)];
96
- case 7:
97
- _c.sent();
93
+ case 6:
94
+ _b.sent();
98
95
  return [4 /*yield*/, tcb.assignSuspiciousBlocksToCheck(transactionOptions)];
99
- case 8:
100
- _c.sent();
101
- _c.label = 9;
102
- case 9: return [2 /*return*/, tcb];
96
+ case 7:
97
+ _b.sent();
98
+ _b.label = 8;
99
+ case 8: return [2 /*return*/, tcb];
100
+ }
101
+ });
102
+ });
103
+ };
104
+ Consensus.initializeTcb = function (teeOfferId, transactionOptions) {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ return __generator(this, function (_a) {
107
+ switch (_a.label) {
108
+ case 0:
109
+ this.checkInit();
110
+ (0, utils_1.checkIfActionAccountInitialized)();
111
+ return [4 /*yield*/, TxManager_1.default.execute(this.contract.methods.initializeTcb, [teeOfferId], transactionOptions)];
112
+ case 1:
113
+ _a.sent();
114
+ return [2 /*return*/];
103
115
  }
104
116
  });
105
117
  });
@@ -118,7 +130,7 @@ var Consensus = /** @class */ (function () {
118
130
  case 0:
119
131
  this.checkInit();
120
132
  (0, utils_1.checkIfActionAccountInitialized)();
121
- return [4 /*yield*/, this.initializeTcb(teeOfferId, transactionOptions)];
133
+ return [4 /*yield*/, this.initializeTcbAndAssignBlocks(teeOfferId, transactionOptions)];
122
134
  case 1:
123
135
  tcb = _a.sent();
124
136
  return [4 /*yield*/, tcb.getCheckingBlocksMarks()];
@@ -134,7 +146,7 @@ var Consensus = /** @class */ (function () {
134
146
  case 4:
135
147
  tcbInfo = _a.sent();
136
148
  checkingTcbData.push({
137
- deviceID: tcbInfo.publicData.deviceId,
149
+ deviceID: tcbInfo.publicData.deviceID,
138
150
  properties: tcbInfo.publicData.properties,
139
151
  benchmark: tcbInfo.publicData.benchmark,
140
152
  tcbQuote: tcbInfo.quote,
@@ -176,6 +188,18 @@ var Consensus = /** @class */ (function () {
176
188
  });
177
189
  });
178
190
  };
191
+ Consensus.getEpoch = function (epochIndex) {
192
+ return __awaiter(this, void 0, void 0, function () {
193
+ return __generator(this, function (_a) {
194
+ switch (_a.label) {
195
+ case 0:
196
+ this.checkInit();
197
+ return [4 /*yield*/, this.contract.methods.getEpoch(epochIndex).call()];
198
+ case 1: return [2 /*return*/, _a.sent()];
199
+ }
200
+ });
201
+ });
202
+ };
179
203
  Consensus.getActualTcbId = function (teeOfferId) {
180
204
  return __awaiter(this, void 0, void 0, function () {
181
205
  return __generator(this, function (_a) {
@@ -192,6 +216,14 @@ var Consensus = /** @class */ (function () {
192
216
  });
193
217
  });
194
218
  };
219
+ Consensus.getSuspiciousBlockTableSize = function () {
220
+ return __awaiter(this, void 0, void 0, function () {
221
+ return __generator(this, function (_a) {
222
+ this.checkInit();
223
+ return [2 /*return*/, this.contract.methods.getSuspiciousBlockTableSize().call()];
224
+ });
225
+ });
226
+ };
195
227
  Consensus.getLastBlockTable = function () {
196
228
  return __awaiter(this, void 0, void 0, function () {
197
229
  return __generator(this, function (_a) {
@@ -200,6 +232,14 @@ var Consensus = /** @class */ (function () {
200
232
  });
201
233
  });
202
234
  };
235
+ Consensus.getLastBlockTableSize = function () {
236
+ return __awaiter(this, void 0, void 0, function () {
237
+ return __generator(this, function (_a) {
238
+ this.checkInit();
239
+ return [2 /*return*/, this.contract.methods.getLastBlockTableSize().call()];
240
+ });
241
+ });
242
+ };
203
243
  return Consensus;
204
244
  }());
205
245
  exports.default = Consensus;
@@ -23,6 +23,12 @@ declare class TeeOffersFactory {
23
23
  */
24
24
  static createTeeOffer(providerAuthorityAccount: string, teeOfferInfo: TeeOfferInfo, externalId?: string, transactionOptions?: TransactionOptions): Promise<void>;
25
25
  static getOffer(creator: string, externalId: string): Promise<OfferCreatedEvent>;
26
+ /**
27
+ * Function for fetching TEE offer id by TEE deviceId
28
+ * @param deviceId - unque TEE device id (unparsed, from blockchain)
29
+ * @return TEE offer id
30
+ */
31
+ static getByDeviceId(deviceId: string): Promise<string>;
26
32
  /**
27
33
  * Function for adding event listeners on TEE offer created event in TEE offers factory contract
28
34
  * @param callback - function for processing created TEE offer
@@ -158,6 +158,15 @@ var TeeOffersFactory = /** @class */ (function () {
158
158
  });
159
159
  });
160
160
  };
161
+ /**
162
+ * Function for fetching TEE offer id by TEE deviceId
163
+ * @param deviceId - unque TEE device id (unparsed, from blockchain)
164
+ * @return TEE offer id
165
+ */
166
+ TeeOffersFactory.getByDeviceId = function (deviceId) {
167
+ var contract = this.checkInit();
168
+ return contract.methods.getTeeOfferByDeviceId(deviceId).call();
169
+ };
161
170
  /**
162
171
  * Function for adding event listeners on TEE offer created event in TEE offers factory contract
163
172
  * @param callback - function for processing created TEE offer
@@ -46,6 +46,13 @@ export declare type TcbEpochInfo = {
46
46
  index: number;
47
47
  valid: boolean;
48
48
  };
49
+ export declare type EpochInfo = {
50
+ startDate: number;
51
+ endDate: number;
52
+ reward: number;
53
+ benchmark: number;
54
+ penaltyBenchmark: number;
55
+ };
49
56
  export declare type CheckingTcbData = {
50
57
  deviceID: string;
51
58
  properties: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-protocol/sdk-js",
3
- "version": "0.8.1-beta.1",
3
+ "version": "0.8.1-beta.4",
4
4
  "main": "build/index.js",
5
5
  "license": "MIT",
6
6
  "files": [