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

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.
@@ -38,5 +38,6 @@ declare class Provider {
38
38
  * Fetch new Origins (createdDate, createdBy, modifiedDate and modifiedBy)
39
39
  */
40
40
  getOrigins(): Promise<Origins>;
41
+ isProviderBanned(): Promise<boolean>;
41
42
  }
42
43
  export default Provider;
@@ -47,6 +47,7 @@ var Origins_1 = require("../types/Origins");
47
47
  var Superpro_1 = __importDefault(require("../staticModels/Superpro"));
48
48
  var BlockchainConnector_1 = __importDefault(require("../connectors/BlockchainConnector"));
49
49
  var TxManager_1 = __importDefault(require("../utils/TxManager"));
50
+ var Consensus_1 = __importDefault(require("../staticModels/Consensus"));
50
51
  var Provider = /** @class */ (function () {
51
52
  function Provider(providerId) {
52
53
  this.providerId = providerId;
@@ -182,6 +183,22 @@ var Provider = /** @class */ (function () {
182
183
  });
183
184
  });
184
185
  };
186
+ Provider.prototype.isProviderBanned = function () {
187
+ return __awaiter(this, void 0, void 0, function () {
188
+ var violationRate, CONSENSUS_MAX_PENALTIES;
189
+ return __generator(this, function (_a) {
190
+ switch (_a.label) {
191
+ case 0: return [4 /*yield*/, this.getViolationRate()];
192
+ case 1:
193
+ violationRate = _a.sent();
194
+ return [4 /*yield*/, Consensus_1.default.getConstants()];
195
+ case 2:
196
+ CONSENSUS_MAX_PENALTIES = (_a.sent()).CONSENSUS_MAX_PENALTIES;
197
+ return [2 /*return*/, violationRate >= CONSENSUS_MAX_PENALTIES];
198
+ }
199
+ });
200
+ });
201
+ };
185
202
  return Provider;
186
203
  }());
187
204
  exports.default = Provider;
@@ -1,5 +1,7 @@
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";
4
+ import { ConsensusConstants } from "../types/Consensus";
3
5
  declare class Consensus {
4
6
  static get address(): string;
5
7
  private static initializeTcbAndAssignBlocks;
@@ -11,10 +13,7 @@ declare class Consensus {
11
13
  * @param transactionOptions - object what contains alternative action account or gas limit (optional)
12
14
  * @returns tcbId and lists of anothers' TCB for their checking
13
15
  */
14
- static getListsForVerification(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<{
15
- tcbId: string;
16
- tcbsForVerification: CheckingTcbData[];
17
- }>;
16
+ static getListsForVerification(teeOfferId: string, transactionOptions?: TransactionOptions): Promise<GetTcbRequest>;
18
17
  /**
19
18
  * Function return last inited TCB of TEE offer
20
19
  * @param teeOfferId - id of TEE offer
@@ -31,5 +30,6 @@ declare class Consensus {
31
30
  static getSuspiciousBlockTableSize(): Promise<string[]>;
32
31
  static getLastBlockTable(): Promise<string[]>;
33
32
  static getLastBlockTableSize(): Promise<string[]>;
33
+ static getConstants(): Promise<ConsensusConstants>;
34
34
  }
35
35
  export default Consensus;
@@ -44,6 +44,7 @@ var utils_1 = require("../utils");
44
44
  var Superpro_1 = __importDefault(require("./Superpro"));
45
45
  var BlockchainConnector_1 = __importDefault(require("../connectors/BlockchainConnector"));
46
46
  var TxManager_1 = __importDefault(require("../utils/TxManager"));
47
+ var Consensus_1 = require("../types/Consensus");
47
48
  var Consensus = /** @class */ (function () {
48
49
  function Consensus() {
49
50
  }
@@ -97,11 +98,16 @@ var Consensus = /** @class */ (function () {
97
98
  return __awaiter(this, void 0, void 0, function () {
98
99
  var contract, _a, offerNotBlocked, newEpochStarted, halfEpochPassed, benchmarkVerified;
99
100
  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];
101
+ switch (_b.label) {
102
+ case 0:
103
+ contract = BlockchainConnector_1.default.getInstance().getContract();
104
+ return [4 /*yield*/, contract.methods
105
+ .isTcbCreationAvailable(teeOfferId)
106
+ .call()];
107
+ case 1:
108
+ _a = _b.sent(), offerNotBlocked = _a[0], newEpochStarted = _a[1], halfEpochPassed = _a[2], benchmarkVerified = _a[3];
109
+ return [2 /*return*/, offerNotBlocked && newEpochStarted && halfEpochPassed && benchmarkVerified];
110
+ }
105
111
  });
106
112
  });
107
113
  };
@@ -134,6 +140,7 @@ var Consensus = /** @class */ (function () {
134
140
  case 4:
135
141
  tcbInfo = _a.sent();
136
142
  tcbsForVerification.push({
143
+ tcbId: blocksIds[blockIndex].toString(),
137
144
  deviceId: tcbInfo.publicData.deviceID,
138
145
  properties: tcbInfo.publicData.properties,
139
146
  benchmark: tcbInfo.publicData.benchmark,
@@ -243,6 +250,21 @@ var Consensus = /** @class */ (function () {
243
250
  });
244
251
  });
245
252
  };
253
+ Consensus.getConstants = function () {
254
+ return __awaiter(this, void 0, void 0, function () {
255
+ var contract, response;
256
+ return __generator(this, function (_a) {
257
+ switch (_a.label) {
258
+ case 0:
259
+ contract = BlockchainConnector_1.default.getInstance().getContract();
260
+ return [4 /*yield*/, contract.methods.getConsensusConstants().call()];
261
+ case 1:
262
+ response = _a.sent();
263
+ return [2 /*return*/, (0, utils_1.tupleToObject)(response, Consensus_1.ConsensusConstantsStructure)];
264
+ }
265
+ });
266
+ });
267
+ };
246
268
  return Consensus;
247
269
  }());
248
270
  exports.default = Consensus;
@@ -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;
@@ -17,13 +17,13 @@ export declare type PublicData = {
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,11 +99,19 @@ 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
- quote: string;
107
- marks: [TcbVerifiedStatus];
108
- checkingBlocks: [number];
102
+ export declare type ConsensusConstants = {
103
+ CONSENSUS_L1: number;
104
+ CONSENSUS_L2: number;
105
+ CONSENSUS_K: number;
106
+ CONSENSUS_MAX_PENALTIES: number;
107
+ MAX_BECHMARK_OVERRUN_PERCENT: number;
108
+ CONSENSUS_EPOCH_DURATION: number;
109
+ };
110
+ export declare const ConsensusConstantsStructure: {
111
+ CONSENSUS_L1: NumberConstructor;
112
+ CONSENSUS_L2: NumberConstructor;
113
+ CONSENSUS_K: NumberConstructor;
114
+ CONSENSUS_MAX_PENALTIES: NumberConstructor;
115
+ MAX_BECHMARK_OVERRUN_PERCENT: NumberConstructor;
116
+ CONSENSUS_EPOCH_DURATION: NumberConstructor;
109
117
  };
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TcbStructure = exports.TcbStatus = exports.EpochStructure = exports.UtilityDataStructure = exports.PublicDataStructure = exports.TcbVerifiedStatus = void 0;
3
+ exports.ConsensusConstantsStructure = 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,
@@ -51,3 +51,11 @@ exports.TcbStructure = {
51
51
  utilData: exports.UtilityDataStructure,
52
52
  status: TcbStatus,
53
53
  };
54
+ exports.ConsensusConstantsStructure = {
55
+ CONSENSUS_L1: Number,
56
+ CONSENSUS_L2: Number,
57
+ CONSENSUS_K: Number,
58
+ CONSENSUS_MAX_PENALTIES: Number,
59
+ MAX_BECHMARK_OVERRUN_PERCENT: Number,
60
+ CONSENSUS_EPOCH_DURATION: Number,
61
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-protocol/sdk-js",
3
- "version": "0.11.9-beta.8",
3
+ "version": "0.11.10-beta.0",
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",