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

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
  {
@@ -1,19 +1,18 @@
1
- import { CheckingTcbData, EpochInfo } from "../types/Consensus";
1
+ import { EpochInfo } from "../types/Consensus";
2
+ import { GetTcbRequest } from "@super-protocol/dto-js";
2
3
  import { TransactionOptions } from "../types/Web3";
3
4
  declare class Consensus {
4
5
  static get address(): string;
5
6
  private static initializeTcbAndAssignBlocks;
6
7
  static initializeTcb(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<void>;
8
+ static isTcbCreationAvailable(teeOfferId: string): Promise<boolean>;
7
9
  /**
8
10
  * Function initialize TCB and returns list of anothers' TCB for their checking
9
11
  * @param teeOfferId - id of TEE offer
10
12
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
11
13
  * @returns tcbId and lists of anothers' TCB for their checking
12
14
  */
13
- static getListsForVerification(teeOfferId: string, initializeTcbForce?: boolean, transactionOptions?: TransactionOptions): Promise<{
14
- tcbId: string;
15
- checkingTcbData: CheckingTcbData[];
16
- }>;
15
+ static getListsForVerification(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<GetTcbRequest>;
17
16
  /**
18
17
  * Function return last inited TCB of TEE offer
19
18
  * @param teeOfferId - id 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,14 @@ 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
+ tcbId: blocksIds[blockIndex].toString(),
138
+ deviceId: tcbInfo.publicData.deviceID,
142
139
  properties: tcbInfo.publicData.properties,
143
140
  benchmark: tcbInfo.publicData.benchmark,
144
- tcbQuote: tcbInfo.quote,
145
- tcbMarks: tcbInfo.utilData.checkingBlockMarks,
141
+ quote: tcbInfo.quote,
142
+ marks: tcbInfo.utilData.checkingBlockMarks,
143
+ checkingBlocks: tcbInfo.utilData.checkingBlocks,
146
144
  });
147
145
  _a.label = 5;
148
146
  case 5:
@@ -150,7 +148,7 @@ var Consensus = /** @class */ (function () {
150
148
  return [3 /*break*/, 3];
151
149
  case 6: return [2 /*return*/, {
152
150
  tcbId: tcb.tcbId,
153
- checkingTcbData: checkingTcbData,
151
+ tcbsForVerification: tcbsForVerification,
154
152
  }];
155
153
  }
156
154
  });
@@ -171,18 +169,18 @@ var Consensus = /** @class */ (function () {
171
169
  };
172
170
  Consensus.getEpochTime = function (time) {
173
171
  return __awaiter(this, void 0, void 0, function () {
174
- var contract, result;
175
- return __generator(this, function (_a) {
176
- switch (_a.label) {
172
+ var contract, _a, epochStart, epochEnd, epochIndex;
173
+ return __generator(this, function (_b) {
174
+ switch (_b.label) {
177
175
  case 0:
178
176
  contract = BlockchainConnector_1.default.getInstance().getContract();
179
177
  return [4 /*yield*/, contract.methods.getEpochTime(time).call()];
180
178
  case 1:
181
- result = _a.sent();
179
+ _a = _b.sent(), epochStart = _a[0], epochEnd = _a[1], epochIndex = _a[2];
182
180
  return [2 /*return*/, {
183
- epochStart: result[0],
184
- epochEnd: result[1],
185
- epochIndex: result[2],
181
+ epochStart: epochStart,
182
+ epochEnd: epochEnd,
183
+ epochIndex: epochIndex,
186
184
  }];
187
185
  }
188
186
  });
@@ -1,8 +1,8 @@
1
1
  export declare enum TcbVerifiedStatus {
2
- Valid = "0",
3
- InvalidQuote = "1",
4
- InvalidMrEnclave = "2",
5
- InvalidBcbHash = "3"
2
+ Valid = 0,
3
+ InvalidQuote = 1,
4
+ InvalidMrEnclave = 2,
5
+ InvalidBcbHash = 3
6
6
  }
7
7
  export declare const PublicDataStructure: {
8
8
  teeOffer: StringConstructor;
@@ -11,19 +11,19 @@ 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;
18
18
  };
19
19
  export declare const UtilityDataStructure: {
20
- checkingBlocks: NumberConstructor[];
20
+ checkingBlocks: StringConstructor[];
21
21
  checkingBlockMarks: (typeof TcbVerifiedStatus)[];
22
22
  lastBlocksTakenAmount: NumberConstructor;
23
23
  suspiciousBlocksTakenAmount: NumberConstructor;
24
24
  negative: NumberConstructor;
25
25
  positive: NumberConstructor;
26
- previousTcb: NumberConstructor;
26
+ previousTcb: StringConstructor;
27
27
  lastBlocksTaken: BooleanConstructor;
28
28
  suspiciousBlocksTaken: BooleanConstructor;
29
29
  assignedToEpoch: BooleanConstructor;
@@ -31,13 +31,13 @@ export declare const UtilityDataStructure: {
31
31
  rewardClaimed: BooleanConstructor;
32
32
  };
33
33
  export declare type UtilityData = {
34
- checkingBlocks: [number];
34
+ checkingBlocks: [string];
35
35
  checkingBlockMarks: [TcbVerifiedStatus];
36
36
  lastBlocksTakenAmount: number;
37
37
  suspiciousBlocksTakenAmount: number;
38
38
  negative: number;
39
39
  positive: number;
40
- previousTcb: number;
40
+ previousTcb: string;
41
41
  lastBlocksTaken: boolean;
42
42
  suspiciousBlocksTaken: boolean;
43
43
  assignedToEpoch: boolean;
@@ -71,13 +71,13 @@ export declare const TcbStructure: {
71
71
  properties: StringConstructor;
72
72
  };
73
73
  utilData: {
74
- checkingBlocks: NumberConstructor[];
74
+ checkingBlocks: StringConstructor[];
75
75
  checkingBlockMarks: (typeof TcbVerifiedStatus)[];
76
76
  lastBlocksTakenAmount: NumberConstructor;
77
77
  suspiciousBlocksTakenAmount: NumberConstructor;
78
78
  negative: NumberConstructor;
79
79
  positive: NumberConstructor;
80
- previousTcb: NumberConstructor;
80
+ previousTcb: StringConstructor;
81
81
  lastBlocksTaken: BooleanConstructor;
82
82
  suspiciousBlocksTaken: BooleanConstructor;
83
83
  assignedToEpoch: BooleanConstructor;
@@ -99,10 +99,3 @@ export declare type EpochInfo = {
99
99
  benchmark: number;
100
100
  penaltyBenchmark: number;
101
101
  };
102
- export declare type CheckingTcbData = {
103
- deviceID: string;
104
- properties: string;
105
- benchmark: number;
106
- tcbQuote: string;
107
- tcbMarks: [TcbVerifiedStatus];
108
- };
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TcbStructure = exports.TcbStatus = exports.EpochStructure = exports.UtilityDataStructure = exports.PublicDataStructure = exports.TcbVerifiedStatus = void 0;
4
4
  var TcbVerifiedStatus;
5
5
  (function (TcbVerifiedStatus) {
6
- TcbVerifiedStatus["Valid"] = "0";
7
- TcbVerifiedStatus["InvalidQuote"] = "1";
8
- TcbVerifiedStatus["InvalidMrEnclave"] = "2";
9
- TcbVerifiedStatus["InvalidBcbHash"] = "3";
6
+ TcbVerifiedStatus[TcbVerifiedStatus["Valid"] = 0] = "Valid";
7
+ TcbVerifiedStatus[TcbVerifiedStatus["InvalidQuote"] = 1] = "InvalidQuote";
8
+ TcbVerifiedStatus[TcbVerifiedStatus["InvalidMrEnclave"] = 2] = "InvalidMrEnclave";
9
+ TcbVerifiedStatus[TcbVerifiedStatus["InvalidBcbHash"] = 3] = "InvalidBcbHash";
10
10
  })(TcbVerifiedStatus = exports.TcbVerifiedStatus || (exports.TcbVerifiedStatus = {}));
11
11
  // Order of keys and type conversion functions for this object in blockchain contract
12
12
  exports.PublicDataStructure = {
@@ -16,13 +16,13 @@ exports.PublicDataStructure = {
16
16
  properties: String,
17
17
  };
18
18
  exports.UtilityDataStructure = {
19
- checkingBlocks: [Number],
19
+ checkingBlocks: [String],
20
20
  checkingBlockMarks: [TcbVerifiedStatus],
21
21
  lastBlocksTakenAmount: Number,
22
22
  suspiciousBlocksTakenAmount: Number,
23
23
  negative: Number,
24
24
  positive: Number,
25
- previousTcb: Number,
25
+ previousTcb: String,
26
26
  lastBlocksTaken: Boolean,
27
27
  suspiciousBlocksTaken: Boolean,
28
28
  assignedToEpoch: Boolean,
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.9",
4
4
  "main": "build/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -53,7 +53,7 @@
53
53
  "typescript": "^4.4.4"
54
54
  },
55
55
  "dependencies": {
56
- "@super-protocol/dto-js": "0.0.14",
56
+ "@super-protocol/dto-js": "0.0.22",
57
57
  "@super-protocol/tee-lib": "^0.1.2",
58
58
  "@super-protocol/uplink-nodejs": "1.2.12",
59
59
  "eccrypto": "^1.1.6",