@super-protocol/sdk-js 0.15.0 → 0.15.1
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/TIIGenerator.js +129 -239
- package/build/connectors/BaseConnector.js +17 -47
- package/build/connectors/BlockchainConnector.js +222 -348
- package/build/connectors/BlockchainEventsListener.js +38 -92
- package/build/contracts/app.json +466 -35
- package/build/crypto/Crypto.js +63 -135
- package/build/crypto/index.js +1 -1
- package/build/crypto/nodejs/AES.js +62 -119
- package/build/crypto/nodejs/ARIA.js +61 -118
- package/build/crypto/nodejs/ECIES.js +51 -87
- package/build/crypto/nodejs/NativeCrypto.js +64 -118
- package/build/crypto/nodejs/RSA-Hybrid.js +54 -113
- package/build/index.d.ts +5 -0
- package/build/index.js +14 -2
- package/build/logger.d.ts +3 -1
- package/build/logger.js +2 -2
- package/build/models/EtlModel.js +65 -114
- package/build/models/Offer.js +227 -462
- package/build/models/Order.d.ts +4 -0
- package/build/models/Order.js +326 -559
- package/build/models/Provider.d.ts +2 -0
- package/build/models/Provider.js +74 -153
- package/build/models/TCB.js +67 -171
- package/build/models/TeeOffer.d.ts +1 -0
- package/build/models/TeeOffer.js +389 -731
- package/build/proto/Compression.js +20 -21
- package/build/proto/TRI.js +46 -50
- package/build/proto/TeeProperties.js +60 -66
- package/build/providers/storage/ChunksDownloadDecorator.js +125 -235
- package/build/providers/storage/S3StorageProvider.js +173 -298
- package/build/providers/storage/StorageAdapter.d.ts +60 -0
- package/build/providers/storage/StorageAdapter.js +317 -0
- package/build/providers/storage/StorageContentWriter.d.ts +39 -0
- package/build/providers/storage/StorageContentWriter.js +181 -0
- package/build/providers/storage/StorageKeyValueAdapter.d.ts +20 -0
- package/build/providers/storage/StorageKeyValueAdapter.js +152 -0
- package/build/providers/storage/StorageMetadataReader.d.ts +19 -0
- package/build/providers/storage/StorageMetadataReader.js +65 -0
- package/build/providers/storage/StorjAdapter.d.ts +19 -0
- package/build/providers/storage/StorjAdapter.js +62 -0
- package/build/providers/storage/StorjStorageProvider.js +138 -315
- package/build/providers/storage/getStorageProvider.js +7 -7
- package/build/providers/storage/types.d.ts +7 -0
- package/build/providers/storage/types.js +2 -0
- package/build/staticModels/ActiveOffers.js +32 -100
- package/build/staticModels/ActiveOrders.js +42 -120
- package/build/staticModels/BaseStaticModel.js +7 -10
- package/build/staticModels/Consensus.d.ts +4 -1
- package/build/staticModels/Consensus.js +164 -220
- package/build/staticModels/Deposits.js +109 -201
- package/build/staticModels/Marks.js +21 -82
- package/build/staticModels/ModelPackager.js +34 -84
- package/build/staticModels/Offers.js +140 -266
- package/build/staticModels/Orders.d.ts +1 -0
- package/build/staticModels/Orders.js +286 -429
- package/build/staticModels/ProviderRegistry.js +114 -225
- package/build/staticModels/Superpro.js +17 -63
- package/build/staticModels/SuperproToken.js +90 -169
- package/build/staticModels/TeeOffers.js +220 -416
- package/build/store.js +2 -2
- package/build/types/HardwareInfo.js +2 -2
- package/build/types/Order.js +4 -4
- package/build/types/Provider.js +1 -1
- package/build/types/TeeOfferInfo.js +1 -1
- package/build/types/TeeOfferOption.js +2 -2
- package/build/types/TeeOfferSlot.js +2 -2
- package/build/types/ValueOfferSlot.js +3 -3
- package/build/utils/Monitoring.js +24 -28
- package/build/utils/NonceTracker.js +56 -121
- package/build/utils/PubSub.d.ts +9 -0
- package/build/utils/PubSub.js +36 -0
- package/build/utils/TxManager.js +121 -215
- package/build/utils/compressors/GzipCompressor.js +13 -50
- package/build/utils/compressors/UncompressedCompressor.js +10 -13
- package/build/utils/helpers/tryWithInterval.js +34 -78
- package/build/utils/resourceLoaders/BaseResourceLoader.js +26 -78
- package/build/utils/resourceLoaders/StorageProviderLoader.js +33 -97
- package/build/utils/resourceLoaders/UrlResourceLoader.js +29 -93
- package/build/utils/resourceLoaders/getResourceLoader.js +6 -6
- package/build/utils.js +60 -105
- package/package.json +4 -1
package/build/utils.js
CHANGED
|
@@ -8,46 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
15
|
exports.packSlotInfo = exports.unpackSlotInfo = exports.unpackDeviceId = exports.packDevicId = exports.incrementMethodCall = exports.objectToTuple = exports.tupleToObjectsArray = exports.tupleToObject = exports.isNodeJS = exports.createTransactionOptions = exports.getGasPrice = exports.checkForUsingExternalTxManager = exports.checkIfActionAccountInitialized = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
16
|
+
const store_1 = __importDefault(require("./store"));
|
|
17
|
+
const lodash_1 = require("lodash");
|
|
18
|
+
const Monitoring_1 = require("./utils/Monitoring");
|
|
46
19
|
/**
|
|
47
20
|
* Function for checking if provider action account initialized (required for set methods)
|
|
48
21
|
* Used in all set methods
|
|
49
22
|
*/
|
|
50
|
-
|
|
23
|
+
const checkIfActionAccountInitialized = (transactionOptions) => {
|
|
51
24
|
if (!store_1.default.actionAccount && !(transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3))
|
|
52
25
|
throw new Error("Provider action account is not initialized, needs to run 'BlockchainConnector.getInstance().initializeActionAccount(SECRET_KEY)' first");
|
|
53
26
|
};
|
|
@@ -55,7 +28,7 @@ exports.checkIfActionAccountInitialized = checkIfActionAccountInitialized;
|
|
|
55
28
|
/**
|
|
56
29
|
* Function for checking if current configuration supposed to use external transaction manager like MetaMask and etc.
|
|
57
30
|
*/
|
|
58
|
-
|
|
31
|
+
const checkForUsingExternalTxManager = (transactionOptions) => {
|
|
59
32
|
// TODO: Agree on more proper way of signaling, that we use an external transaction manager, than just passing a web3 instance.
|
|
60
33
|
return !!(transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3);
|
|
61
34
|
};
|
|
@@ -63,66 +36,54 @@ exports.checkForUsingExternalTxManager = checkForUsingExternalTxManager;
|
|
|
63
36
|
/**
|
|
64
37
|
* Updates gas price determined by the last few blocks median
|
|
65
38
|
*/
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
}); };
|
|
39
|
+
const getGasPrice = (web3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
return web3.eth.getGasPrice();
|
|
41
|
+
});
|
|
71
42
|
exports.getGasPrice = getGasPrice;
|
|
72
43
|
/**
|
|
73
44
|
* Merge transaction options from arguments and from store
|
|
74
45
|
* Used in all set methods
|
|
75
46
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
_b.label = 1;
|
|
93
|
-
case 1:
|
|
94
|
-
_b.trys.push([1, 3, , 4]);
|
|
95
|
-
_a = options;
|
|
96
|
-
return [4 /*yield*/, (0, exports.getGasPrice)(web3)];
|
|
97
|
-
case 2:
|
|
98
|
-
_a.gasPrice = _b.sent();
|
|
99
|
-
return [3 /*break*/, 4];
|
|
100
|
-
case 3:
|
|
101
|
-
e_1 = _b.sent();
|
|
47
|
+
const createTransactionOptions = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
if (!options)
|
|
49
|
+
options = {};
|
|
50
|
+
if (!options.from)
|
|
51
|
+
options.from = store_1.default.actionAccount;
|
|
52
|
+
if (!options.gas)
|
|
53
|
+
options.gas = store_1.default.gasLimit;
|
|
54
|
+
if (!options.gasPriceMultiplier)
|
|
55
|
+
options.gasPriceMultiplier = store_1.default.gasPriceMultiplier;
|
|
56
|
+
if (!options.gasPrice) {
|
|
57
|
+
const web3 = options.web3 || store_1.default.web3Https;
|
|
58
|
+
if (web3) {
|
|
59
|
+
try {
|
|
60
|
+
options.gasPrice = yield (0, exports.getGasPrice)(web3);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
102
63
|
options.gasPrice = store_1.default.gasPrice;
|
|
103
|
-
|
|
104
|
-
case 4: return [3 /*break*/, 6];
|
|
105
|
-
case 5: throw Error("web3 is undefined, define it in transaction options or initialize BlockchainConnector with web3 instance.");
|
|
106
|
-
case 6:
|
|
107
|
-
delete options.web3;
|
|
108
|
-
return [2 /*return*/, options];
|
|
64
|
+
}
|
|
109
65
|
}
|
|
110
|
-
|
|
111
|
-
|
|
66
|
+
else {
|
|
67
|
+
throw Error("web3 is undefined, define it in transaction options or initialize BlockchainConnector with web3 instance.");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
delete options.web3;
|
|
71
|
+
return options;
|
|
72
|
+
});
|
|
112
73
|
exports.createTransactionOptions = createTransactionOptions;
|
|
113
|
-
|
|
74
|
+
const isNodeJS = () => {
|
|
114
75
|
// @ts-ignore
|
|
115
76
|
return typeof window === "undefined";
|
|
116
77
|
};
|
|
117
78
|
exports.isNodeJS = isNodeJS;
|
|
118
|
-
|
|
119
|
-
|
|
79
|
+
const tupleToObject = (data, format) => {
|
|
80
|
+
const processItem = (dataItem, formatItem) => {
|
|
120
81
|
if (formatItem === null || formatItem === void 0 ? void 0 : formatItem.$obj) {
|
|
121
82
|
return formatItem.$obj(dataItem);
|
|
122
83
|
}
|
|
123
84
|
else if (typeof formatItem === "function") {
|
|
124
85
|
if (formatItem.name === "Number") {
|
|
125
|
-
|
|
86
|
+
const value = formatItem(dataItem);
|
|
126
87
|
return value < Number.MAX_SAFE_INTEGER ? value : Number.MAX_SAFE_INTEGER;
|
|
127
88
|
}
|
|
128
89
|
return formatItem(dataItem);
|
|
@@ -135,29 +96,29 @@ var tupleToObject = function (data, format) {
|
|
|
135
96
|
}
|
|
136
97
|
};
|
|
137
98
|
if ((0, lodash_1.isArray)(format)) {
|
|
138
|
-
|
|
139
|
-
|
|
99
|
+
const result = data.map((dataItem, index) => {
|
|
100
|
+
const formatItem = index < format.length ? format[index] : format[format.length - 1];
|
|
140
101
|
return processItem(dataItem, formatItem);
|
|
141
102
|
});
|
|
142
103
|
return result;
|
|
143
104
|
}
|
|
144
105
|
else {
|
|
145
|
-
|
|
146
|
-
Object.keys(format).forEach(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
106
|
+
const result = {};
|
|
107
|
+
Object.keys(format).forEach((key, index) => {
|
|
108
|
+
const formatItem = format[key];
|
|
109
|
+
const dataItem = data[index];
|
|
110
|
+
result[key] = processItem(dataItem, formatItem);
|
|
150
111
|
});
|
|
151
|
-
return
|
|
112
|
+
return result;
|
|
152
113
|
}
|
|
153
114
|
};
|
|
154
115
|
exports.tupleToObject = tupleToObject;
|
|
155
|
-
|
|
156
|
-
return data.map(
|
|
116
|
+
const tupleToObjectsArray = (data, format) => {
|
|
117
|
+
return data.map((item) => (0, exports.tupleToObject)(item, format));
|
|
157
118
|
};
|
|
158
119
|
exports.tupleToObjectsArray = tupleToObjectsArray;
|
|
159
|
-
|
|
160
|
-
|
|
120
|
+
const objectToTuple = (data, format) => {
|
|
121
|
+
const processItem = (dataItem, formatItem) => {
|
|
161
122
|
if (formatItem === null || formatItem === void 0 ? void 0 : formatItem.$tuple) {
|
|
162
123
|
return formatItem.$tuple(dataItem);
|
|
163
124
|
}
|
|
@@ -169,15 +130,15 @@ var objectToTuple = function (data, format) {
|
|
|
169
130
|
}
|
|
170
131
|
};
|
|
171
132
|
if ((0, lodash_1.isArray)(format)) {
|
|
172
|
-
return data.map(
|
|
173
|
-
|
|
133
|
+
return data.map((dataItem, index) => {
|
|
134
|
+
const formatItem = index < format.length ? format[index] : format[format.length - 1];
|
|
174
135
|
return processItem(dataItem, formatItem);
|
|
175
136
|
});
|
|
176
137
|
}
|
|
177
138
|
else {
|
|
178
|
-
return Object.keys(format).map(
|
|
179
|
-
|
|
180
|
-
|
|
139
|
+
return Object.keys(format).map((key) => {
|
|
140
|
+
const dataItem = data[key];
|
|
141
|
+
const formatItem = format[key];
|
|
181
142
|
return processItem(dataItem, formatItem);
|
|
182
143
|
});
|
|
183
144
|
}
|
|
@@ -185,25 +146,19 @@ var objectToTuple = function (data, format) {
|
|
|
185
146
|
exports.objectToTuple = objectToTuple;
|
|
186
147
|
function incrementMethodCall() {
|
|
187
148
|
return function (_target, propertyName, propertyDescriptor) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
propertyDescriptor.value = function () {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
196
|
-
return __generator(this, function (_a) {
|
|
197
|
-
monitoring.incrementCall(propertyName);
|
|
198
|
-
return [2 /*return*/, method.apply(this, args)];
|
|
199
|
-
});
|
|
149
|
+
const monitoring = Monitoring_1.Monitoring.getInstance();
|
|
150
|
+
const method = propertyDescriptor.value;
|
|
151
|
+
propertyDescriptor.value = function (...args) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
monitoring.incrementCall(propertyName);
|
|
154
|
+
return method.apply(this, args);
|
|
200
155
|
});
|
|
201
156
|
};
|
|
202
157
|
return propertyDescriptor;
|
|
203
158
|
};
|
|
204
159
|
}
|
|
205
160
|
exports.incrementMethodCall = incrementMethodCall;
|
|
206
|
-
|
|
161
|
+
const hexRegex = /^[0-9a-fA-F]+$/;
|
|
207
162
|
function packDevicId(hexedDeviceId) {
|
|
208
163
|
if (hexedDeviceId.length !== 64) {
|
|
209
164
|
throw new Error("DeviceId must be equal 64 hex symbols");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@super-protocol/sdk-js",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jest": "^27.0.3",
|
|
35
35
|
"@types/lodash": "^4.14.176",
|
|
36
|
+
"@types/lru-cache": "^7.10.10",
|
|
36
37
|
"@types/node": "^17.0.0",
|
|
37
38
|
"@types/node-gzip": "^1.1.0",
|
|
38
39
|
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
|
@@ -59,7 +60,9 @@
|
|
|
59
60
|
"ethers": "^5.5.3",
|
|
60
61
|
"hybrid-crypto-js": "^0.2.4",
|
|
61
62
|
"lodash": "^4.17.21",
|
|
63
|
+
"lru-cache": "^10.0.0",
|
|
62
64
|
"node-gzip": "^1.1.2",
|
|
65
|
+
"p-queue": "6.6.2",
|
|
63
66
|
"pino": "^7.2.0",
|
|
64
67
|
"protobufjs": "^6.11.2",
|
|
65
68
|
"web3": "^1.7.1",
|