@super-protocol/sdk-js 0.11.4-beta.0 → 0.11.6-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.
- package/build/models/EtlModel.d.ts +30 -0
- package/build/models/EtlModel.js +108 -0
- package/build/models/TCB.d.ts +2 -6
- package/build/models/TCB.js +7 -19
- package/build/models/TeeOffer.d.ts +1 -0
- package/build/models/TeeOffer.js +10 -0
- package/build/proto/Compression.d.ts +2 -1
- package/build/proto/Compression.js +7 -1
- package/build/staticModels/ModelPackager.d.ts +19 -0
- package/build/staticModels/ModelPackager.js +116 -0
- package/build/types/Compressor.d.ts +5 -0
- package/build/types/Compressor.js +2 -0
- package/build/types/Consensus.d.ts +26 -0
- package/build/types/Consensus.js +10 -1
- package/build/types/EtlModel.d.ts +2 -0
- package/build/types/EtlModel.js +2 -0
- package/build/utils/compressors/GzipCompressor.d.ts +8 -0
- package/build/utils/compressors/GzipCompressor.js +65 -0
- package/build/utils/compressors/UncompressedCompressor.d.ts +8 -0
- package/build/utils/compressors/UncompressedCompressor.js +19 -0
- package/build/utils/compressors/index.d.ts +2 -0
- package/build/utils/compressors/index.js +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EtlModel as IEtlModel, EtlModelMetadata } from "@super-protocol/dto-js";
|
|
3
|
+
import { EtlModelType } from "@super-protocol/dto-js/build/enum/EtlModel.enum";
|
|
4
|
+
import { EtlModelSubtype } from "../types/EtlModel";
|
|
5
|
+
export declare class EtlModel {
|
|
6
|
+
private etlModel;
|
|
7
|
+
static logger: import("pino").default.Logger<{
|
|
8
|
+
level: string;
|
|
9
|
+
} & import("pino").default.ChildLoggerOptions>;
|
|
10
|
+
constructor(etlModel: IEtlModel);
|
|
11
|
+
/**
|
|
12
|
+
* Create instance of EtlModel from Buffer
|
|
13
|
+
*
|
|
14
|
+
* @param data - packed EtlModel
|
|
15
|
+
* @returns instance of EtlModel
|
|
16
|
+
*/
|
|
17
|
+
static unpack(data: Buffer): Promise<EtlModel>;
|
|
18
|
+
/**
|
|
19
|
+
* Packing EltModel
|
|
20
|
+
*
|
|
21
|
+
* @returns EltModel in binary format
|
|
22
|
+
*/
|
|
23
|
+
pack(): Promise<Buffer>;
|
|
24
|
+
getType(): EtlModelType;
|
|
25
|
+
setType(type: EtlModelType): void;
|
|
26
|
+
getSubtype(): EtlModelSubtype;
|
|
27
|
+
setSubtype(subtype: EtlModelSubtype | null): void;
|
|
28
|
+
getMetadata(): EtlModelMetadata | void;
|
|
29
|
+
setMetadata(metadata: EtlModelMetadata | undefined): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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 (_) 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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.EtlModel = void 0;
|
|
43
|
+
var logger_1 = __importDefault(require("../logger"));
|
|
44
|
+
var ModelPackager_1 = require("../staticModels/ModelPackager");
|
|
45
|
+
var EtlModel = /** @class */ (function () {
|
|
46
|
+
function EtlModel(etlModel) {
|
|
47
|
+
this.etlModel = etlModel;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create instance of EtlModel from Buffer
|
|
51
|
+
*
|
|
52
|
+
* @param data - packed EtlModel
|
|
53
|
+
* @returns instance of EtlModel
|
|
54
|
+
*/
|
|
55
|
+
EtlModel.unpack = function (data) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var etlModel, error_1;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
_a.trys.push([0, 2, , 3]);
|
|
62
|
+
return [4 /*yield*/, ModelPackager_1.ModelPackager.unpack(data)];
|
|
63
|
+
case 1:
|
|
64
|
+
etlModel = _a.sent();
|
|
65
|
+
return [2 /*return*/, new EtlModel(etlModel)];
|
|
66
|
+
case 2:
|
|
67
|
+
error_1 = _a.sent();
|
|
68
|
+
EtlModel.logger.error("Unable to unpack EtlModel");
|
|
69
|
+
throw error_1;
|
|
70
|
+
case 3: return [2 /*return*/];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Packing EltModel
|
|
77
|
+
*
|
|
78
|
+
* @returns EltModel in binary format
|
|
79
|
+
*/
|
|
80
|
+
EtlModel.prototype.pack = function () {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
return [2 /*return*/, ModelPackager_1.ModelPackager.pack(this.etlModel)];
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
EtlModel.prototype.getType = function () {
|
|
88
|
+
return this.etlModel.type;
|
|
89
|
+
};
|
|
90
|
+
EtlModel.prototype.setType = function (type) {
|
|
91
|
+
this.etlModel.type = type;
|
|
92
|
+
};
|
|
93
|
+
EtlModel.prototype.getSubtype = function () {
|
|
94
|
+
return this.etlModel.subtype;
|
|
95
|
+
};
|
|
96
|
+
EtlModel.prototype.setSubtype = function (subtype) {
|
|
97
|
+
this.etlModel.subtype = subtype;
|
|
98
|
+
};
|
|
99
|
+
EtlModel.prototype.getMetadata = function () {
|
|
100
|
+
return this.etlModel.metadata;
|
|
101
|
+
};
|
|
102
|
+
EtlModel.prototype.setMetadata = function (metadata) {
|
|
103
|
+
this.etlModel.metadata = metadata;
|
|
104
|
+
};
|
|
105
|
+
EtlModel.logger = logger_1.default.child({ name: EtlModel.name });
|
|
106
|
+
return EtlModel;
|
|
107
|
+
}());
|
|
108
|
+
exports.EtlModel = EtlModel;
|
package/build/models/TCB.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TransactionOptions } from "../types/Web3";
|
|
2
|
-
import { TcbStatus, PublicData, TcbEpochInfo, TcbVerifiedStatus } from "../types/Consensus";
|
|
2
|
+
import { TcbData, TcbStatus, PublicData, TcbEpochInfo, TcbVerifiedStatus } from "../types/Consensus";
|
|
3
3
|
declare class TCB {
|
|
4
4
|
tcbId: string;
|
|
5
5
|
private contract;
|
|
@@ -42,7 +42,7 @@ declare class TCB {
|
|
|
42
42
|
/**
|
|
43
43
|
* Function for fetching all TCB data
|
|
44
44
|
*/
|
|
45
|
-
get(): Promise<
|
|
45
|
+
get(): Promise<TcbData>;
|
|
46
46
|
/**
|
|
47
47
|
* Function for fetching the given marks for recruited TCBs from the Tables of Consensus
|
|
48
48
|
*/
|
|
@@ -50,10 +50,6 @@ declare class TCB {
|
|
|
50
50
|
blocksIds: string[];
|
|
51
51
|
marks: TcbVerifiedStatus[];
|
|
52
52
|
}>;
|
|
53
|
-
/**
|
|
54
|
-
* Function for fetching used TCB data
|
|
55
|
-
*/
|
|
56
|
-
getPublicData(): Promise<PublicData>;
|
|
57
53
|
/**
|
|
58
54
|
* Function for fetching TCB status
|
|
59
55
|
*/
|
package/build/models/TCB.js
CHANGED
|
@@ -199,8 +199,14 @@ var TCB = /** @class */ (function () {
|
|
|
199
199
|
*/
|
|
200
200
|
TCB.prototype.get = function () {
|
|
201
201
|
return __awaiter(this, void 0, void 0, function () {
|
|
202
|
+
var tcb;
|
|
202
203
|
return __generator(this, function (_a) {
|
|
203
|
-
|
|
204
|
+
switch (_a.label) {
|
|
205
|
+
case 0: return [4 /*yield*/, this.contract.methods.getTcbById(this.tcbId).call()];
|
|
206
|
+
case 1:
|
|
207
|
+
tcb = _a.sent();
|
|
208
|
+
return [2 /*return*/, (0, utils_1.tupleToObject)(tcb, Consensus_1.TcbStructure)];
|
|
209
|
+
}
|
|
204
210
|
});
|
|
205
211
|
});
|
|
206
212
|
};
|
|
@@ -223,24 +229,6 @@ var TCB = /** @class */ (function () {
|
|
|
223
229
|
});
|
|
224
230
|
});
|
|
225
231
|
};
|
|
226
|
-
/**
|
|
227
|
-
* Function for fetching used TCB data
|
|
228
|
-
*/
|
|
229
|
-
TCB.prototype.getPublicData = function () {
|
|
230
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
231
|
-
var publicDataParams, publicData;
|
|
232
|
-
return __generator(this, function (_a) {
|
|
233
|
-
switch (_a.label) {
|
|
234
|
-
case 0: return [4 /*yield*/, this.contract.methods.getPublicData().call()];
|
|
235
|
-
case 1:
|
|
236
|
-
publicDataParams = _a.sent();
|
|
237
|
-
publicData = (0, utils_1.tupleToObject)(publicDataParams, Consensus_1.PublicDataStructure);
|
|
238
|
-
publicData.deviceID = Buffer.from((0, utils_2.parseBytes32String)(publicData.deviceID), "base64").toString("hex");
|
|
239
|
-
return [2 /*return*/, publicData];
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
};
|
|
244
232
|
/**
|
|
245
233
|
* Function for fetching TCB status
|
|
246
234
|
*/
|
package/build/models/TeeOffer.js
CHANGED
|
@@ -153,6 +153,16 @@ var TeeOffer = /** @class */ (function () {
|
|
|
153
153
|
});
|
|
154
154
|
});
|
|
155
155
|
};
|
|
156
|
+
TeeOffer.prototype.isTeeOfferVerifying = function () {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
+
return __generator(this, function (_a) {
|
|
159
|
+
switch (_a.label) {
|
|
160
|
+
case 0: return [4 /*yield*/, TeeOffer.contract.methods.isTeeOfferVerifying(this.id).call()];
|
|
161
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
156
166
|
/**
|
|
157
167
|
* Function for fetching offer provider from blockchain
|
|
158
168
|
*/
|
|
@@ -5,7 +5,8 @@ export interface Compression {
|
|
|
5
5
|
data: Uint8Array;
|
|
6
6
|
}
|
|
7
7
|
export declare enum Compression_TYPE {
|
|
8
|
-
|
|
8
|
+
Uncompressed = 0,
|
|
9
|
+
GZIP = 1
|
|
9
10
|
}
|
|
10
11
|
export declare function compression_TYPEFromJSON(object: any): Compression_TYPE;
|
|
11
12
|
export declare function compression_TYPEToJSON(object: Compression_TYPE): string;
|
|
@@ -9,11 +9,15 @@ var minimal_1 = __importDefault(require("protobufjs/minimal"));
|
|
|
9
9
|
exports.protobufPackage = "";
|
|
10
10
|
var Compression_TYPE;
|
|
11
11
|
(function (Compression_TYPE) {
|
|
12
|
-
Compression_TYPE[Compression_TYPE["
|
|
12
|
+
Compression_TYPE[Compression_TYPE["Uncompressed"] = 0] = "Uncompressed";
|
|
13
|
+
Compression_TYPE[Compression_TYPE["GZIP"] = 1] = "GZIP";
|
|
13
14
|
})(Compression_TYPE = exports.Compression_TYPE || (exports.Compression_TYPE = {}));
|
|
14
15
|
function compression_TYPEFromJSON(object) {
|
|
15
16
|
switch (object) {
|
|
16
17
|
case 0:
|
|
18
|
+
case "Uncompressed":
|
|
19
|
+
return Compression_TYPE.Uncompressed;
|
|
20
|
+
case 1:
|
|
17
21
|
case "GZIP":
|
|
18
22
|
return Compression_TYPE.GZIP;
|
|
19
23
|
default:
|
|
@@ -23,6 +27,8 @@ function compression_TYPEFromJSON(object) {
|
|
|
23
27
|
exports.compression_TYPEFromJSON = compression_TYPEFromJSON;
|
|
24
28
|
function compression_TYPEToJSON(object) {
|
|
25
29
|
switch (object) {
|
|
30
|
+
case Compression_TYPE.Uncompressed:
|
|
31
|
+
return "Uncompressed";
|
|
26
32
|
case Compression_TYPE.GZIP:
|
|
27
33
|
return "GZIP";
|
|
28
34
|
default:
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare class ModelPackager {
|
|
3
|
+
private static readonly logger;
|
|
4
|
+
private static compressors;
|
|
5
|
+
/**
|
|
6
|
+
* Compressing message with best algorithm
|
|
7
|
+
*
|
|
8
|
+
* @param message - message
|
|
9
|
+
* @returns Compressed message in bytes representation
|
|
10
|
+
*/
|
|
11
|
+
static pack<T = unknown>(message: T): Promise<Buffer>;
|
|
12
|
+
/**
|
|
13
|
+
* Uncompressing message
|
|
14
|
+
*
|
|
15
|
+
* @param message - message with bytes representation
|
|
16
|
+
* @returns original message
|
|
17
|
+
*/
|
|
18
|
+
static unpack<T = unknown>(message: Buffer): Promise<T>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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 (_) 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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.ModelPackager = void 0;
|
|
43
|
+
var logger_1 = __importDefault(require("../logger"));
|
|
44
|
+
var Compression_1 = require("../proto/Compression");
|
|
45
|
+
var compressors_1 = require("../utils/compressors");
|
|
46
|
+
var ModelPackager = /** @class */ (function () {
|
|
47
|
+
function ModelPackager() {
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Compressing message with best algorithm
|
|
51
|
+
*
|
|
52
|
+
* @param message - message
|
|
53
|
+
* @returns Compressed message in bytes representation
|
|
54
|
+
*/
|
|
55
|
+
ModelPackager.pack = function (message) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var promises, options, minimal, encoded;
|
|
58
|
+
var _this = this;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
promises = ModelPackager.compressors.map(function (Compressor) { return __awaiter(_this, void 0, void 0, function () {
|
|
63
|
+
var compressorInstance, data;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
compressorInstance = new Compressor();
|
|
68
|
+
return [4 /*yield*/, compressorInstance.compress(message)];
|
|
69
|
+
case 1:
|
|
70
|
+
data = _a.sent();
|
|
71
|
+
return [2 /*return*/, {
|
|
72
|
+
compressionType: Compressor.type,
|
|
73
|
+
data: data,
|
|
74
|
+
size: data.byteLength,
|
|
75
|
+
}];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}); });
|
|
79
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
80
|
+
case 1:
|
|
81
|
+
options = _a.sent();
|
|
82
|
+
options.sort(function (first, second) { return first.size - second.size; });
|
|
83
|
+
minimal = options[0];
|
|
84
|
+
encoded = Compression_1.Compression.encode({
|
|
85
|
+
type: minimal.compressionType,
|
|
86
|
+
data: minimal.data,
|
|
87
|
+
}).finish();
|
|
88
|
+
return [2 /*return*/, Buffer.from(encoded)];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Uncompressing message
|
|
95
|
+
*
|
|
96
|
+
* @param message - message with bytes representation
|
|
97
|
+
* @returns original message
|
|
98
|
+
*/
|
|
99
|
+
ModelPackager.unpack = function (message) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
+
var decoded, Compressor;
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
decoded = Compression_1.Compression.decode(message);
|
|
104
|
+
Compressor = ModelPackager.compressors.find(function (CompressorClass) { return CompressorClass.type === decoded.type; });
|
|
105
|
+
if (!Compressor) {
|
|
106
|
+
throw new Error("Cannot unpack message. Compressor ".concat(decoded.type, " isn't supported"));
|
|
107
|
+
}
|
|
108
|
+
return [2 /*return*/, new Compressor().decompress(Buffer.from(decoded.data))];
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
ModelPackager.logger = logger_1.default.child({ className: ModelPackager.name });
|
|
113
|
+
ModelPackager.compressors = [compressors_1.GzipCompressor, compressors_1.UncompressedCompressor];
|
|
114
|
+
return ModelPackager;
|
|
115
|
+
}());
|
|
116
|
+
exports.ModelPackager = ModelPackager;
|
|
@@ -46,6 +46,32 @@ export declare type TcbEpochInfo = {
|
|
|
46
46
|
index: number;
|
|
47
47
|
valid: boolean;
|
|
48
48
|
};
|
|
49
|
+
export declare const TcbStructure: {
|
|
50
|
+
quote: StringConstructor;
|
|
51
|
+
timeInitialized: NumberConstructor;
|
|
52
|
+
timeAdded: NumberConstructor;
|
|
53
|
+
publicData: {
|
|
54
|
+
teeOffer: StringConstructor;
|
|
55
|
+
deviceID: StringConstructor;
|
|
56
|
+
benchmark: NumberConstructor;
|
|
57
|
+
properties: StringConstructor;
|
|
58
|
+
};
|
|
59
|
+
utilData: {};
|
|
60
|
+
status: typeof TcbStatus;
|
|
61
|
+
epoch: {
|
|
62
|
+
index: NumberConstructor;
|
|
63
|
+
valid: BooleanConstructor;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export declare type TcbData = {
|
|
67
|
+
quote: string;
|
|
68
|
+
timeInitialized: number;
|
|
69
|
+
timeAdded: number;
|
|
70
|
+
publicData: PublicData;
|
|
71
|
+
utilData: any;
|
|
72
|
+
status: TcbStatus;
|
|
73
|
+
epoch: TcbEpochInfo;
|
|
74
|
+
};
|
|
49
75
|
export declare type EpochInfo = {
|
|
50
76
|
startDate: number;
|
|
51
77
|
endDate: number;
|
package/build/types/Consensus.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TcbEpochInfoStructure = exports.TcbStatus = exports.EpochStructure = exports.PublicDataStructure = exports.TcbVerifiedStatus = void 0;
|
|
3
|
+
exports.TcbStructure = exports.TcbEpochInfoStructure = exports.TcbStatus = exports.EpochStructure = exports.PublicDataStructure = exports.TcbVerifiedStatus = void 0;
|
|
4
4
|
var TcbVerifiedStatus;
|
|
5
5
|
(function (TcbVerifiedStatus) {
|
|
6
6
|
TcbVerifiedStatus["Valid"] = "0";
|
|
@@ -36,3 +36,12 @@ exports.TcbEpochInfoStructure = {
|
|
|
36
36
|
index: Number,
|
|
37
37
|
valid: Boolean,
|
|
38
38
|
};
|
|
39
|
+
exports.TcbStructure = {
|
|
40
|
+
quote: String,
|
|
41
|
+
timeInitialized: Number,
|
|
42
|
+
timeAdded: Number,
|
|
43
|
+
publicData: exports.PublicDataStructure,
|
|
44
|
+
utilData: {},
|
|
45
|
+
status: TcbStatus,
|
|
46
|
+
epoch: exports.TcbEpochInfoStructure,
|
|
47
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Compression_TYPE } from "../../proto/Compression";
|
|
3
|
+
import { Compressor } from "../../types/Compressor";
|
|
4
|
+
export declare class GzipCompressor<T> implements Compressor<T> {
|
|
5
|
+
static type: Compression_TYPE;
|
|
6
|
+
compress(content: T): Promise<Buffer>;
|
|
7
|
+
decompress(bytes: Buffer): Promise<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 (_) 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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.GzipCompressor = void 0;
|
|
40
|
+
var node_gzip_1 = require("node-gzip");
|
|
41
|
+
var Compression_1 = require("../../proto/Compression");
|
|
42
|
+
var GzipCompressor = /** @class */ (function () {
|
|
43
|
+
function GzipCompressor() {
|
|
44
|
+
}
|
|
45
|
+
GzipCompressor.prototype.compress = function (content) {
|
|
46
|
+
var stringified = JSON.stringify(content);
|
|
47
|
+
return (0, node_gzip_1.gzip)(stringified);
|
|
48
|
+
};
|
|
49
|
+
GzipCompressor.prototype.decompress = function (bytes) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
+
var stringified;
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0: return [4 /*yield*/, (0, node_gzip_1.ungzip)(bytes)];
|
|
55
|
+
case 1:
|
|
56
|
+
stringified = _a.sent();
|
|
57
|
+
return [2 /*return*/, JSON.parse(stringified.toString())];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
GzipCompressor.type = Compression_1.Compression_TYPE.GZIP;
|
|
63
|
+
return GzipCompressor;
|
|
64
|
+
}());
|
|
65
|
+
exports.GzipCompressor = GzipCompressor;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Compression_TYPE } from "../../proto/Compression";
|
|
3
|
+
import { Compressor } from "../../types/Compressor";
|
|
4
|
+
export declare class UncompressedCompressor<T = unknown> implements Compressor<T> {
|
|
5
|
+
static type: Compression_TYPE;
|
|
6
|
+
compress(content: T): Promise<Buffer>;
|
|
7
|
+
decompress(bytes: Buffer): Promise<T>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UncompressedCompressor = void 0;
|
|
4
|
+
var Compression_1 = require("../../proto/Compression");
|
|
5
|
+
var UncompressedCompressor = /** @class */ (function () {
|
|
6
|
+
function UncompressedCompressor() {
|
|
7
|
+
}
|
|
8
|
+
UncompressedCompressor.prototype.compress = function (content) {
|
|
9
|
+
var stringified = JSON.stringify(content);
|
|
10
|
+
return Promise.resolve(Buffer.from(stringified));
|
|
11
|
+
};
|
|
12
|
+
UncompressedCompressor.prototype.decompress = function (bytes) {
|
|
13
|
+
var stringified = bytes.toString();
|
|
14
|
+
return Promise.resolve(JSON.parse(stringified));
|
|
15
|
+
};
|
|
16
|
+
UncompressedCompressor.type = Compression_1.Compression_TYPE.Uncompressed;
|
|
17
|
+
return UncompressedCompressor;
|
|
18
|
+
}());
|
|
19
|
+
exports.UncompressedCompressor = UncompressedCompressor;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./GzipCompressor"), exports);
|
|
18
|
+
__exportStar(require("./UncompressedCompressor"), exports);
|