@super-protocol/sdk-js 0.12.1-beta.3 → 0.12.2-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.
@@ -41,7 +41,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var app_json_1 = __importDefault(require("../contracts/app.json"));
43
43
  var utils_1 = require("../utils");
44
- var utils_2 = require("ethers/lib/utils");
45
44
  var Superpro_1 = __importDefault(require("../staticModels/Superpro"));
46
45
  var TxManager_1 = __importDefault(require("../utils/TxManager"));
47
46
  var BlockchainConnector_1 = __importDefault(require("../connectors/BlockchainConnector"));
@@ -76,7 +75,7 @@ var TCB = /** @class */ (function () {
76
75
  switch (_a.label) {
77
76
  case 0:
78
77
  (0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
79
- fromattedDeviceId = (0, utils_2.formatBytes32String)(Buffer.from(pb.deviceID).toString("base64"));
78
+ fromattedDeviceId = (0, utils_1.formatHexStringToBytes32)(pb.deviceID);
80
79
  return [4 /*yield*/, TxManager_1.default.execute(this.contract.methods.setTcbData, [this.tcbId, pb.benchmark, pb.properties, fromattedDeviceId, quote], transactionOptions)];
81
80
  case 1:
82
81
  _a.sent();
@@ -192,13 +191,15 @@ var TCB = /** @class */ (function () {
192
191
  */
193
192
  TCB.prototype.get = function () {
194
193
  return __awaiter(this, void 0, void 0, function () {
195
- var tcb;
194
+ var tcb, tcbObject;
196
195
  return __generator(this, function (_a) {
197
196
  switch (_a.label) {
198
197
  case 0: return [4 /*yield*/, this.contract.methods.getTcbById(this.tcbId).call()];
199
198
  case 1:
200
199
  tcb = _a.sent();
201
- return [2 /*return*/, (0, utils_1.tupleToObject)(tcb, Consensus_1.TcbStructure)];
200
+ tcbObject = (0, utils_1.tupleToObject)(tcb, Consensus_1.TcbStructure);
201
+ tcbObject.publicData.deviceID = (0, utils_1.parseBytes32toHexString)(tcbObject.publicData.deviceID);
202
+ return [2 /*return*/, tcbObject];
202
203
  }
203
204
  });
204
205
  });
@@ -141,7 +141,7 @@ var Consensus = /** @class */ (function () {
141
141
  tcbInfo = _a.sent();
142
142
  tcbsForVerification.push({
143
143
  tcbId: blocksIds[blockIndex].toString(),
144
- deviceId: tcbInfo.publicData.deviceID,
144
+ deviceId: (0, utils_1.parseBytes32toHexString)(tcbInfo.publicData.deviceID),
145
145
  properties: tcbInfo.publicData.properties,
146
146
  benchmark: tcbInfo.publicData.benchmark,
147
147
  quote: tcbInfo.quote,
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var logger_1 = __importDefault(require("../logger"));
43
43
  var utils_1 = require("../utils");
44
44
  var utils_2 = require("ethers/lib/utils");
45
+ var utils_3 = require("../utils");
45
46
  var TeeOffer_1 = require("../types/TeeOffer");
46
47
  var Offer_1 = require("../types/Offer");
47
48
  var BlockchainConnector_1 = __importDefault(require("../connectors/BlockchainConnector"));
@@ -152,7 +153,8 @@ var TeeOffersFactory = /** @class */ (function () {
152
153
  */
153
154
  TeeOffersFactory.getByDeviceId = function (deviceId) {
154
155
  var contract = BlockchainConnector_1.default.getInstance().getContract();
155
- return contract.methods.getTeeOfferByDeviceId(deviceId).call();
156
+ var fromattedDeviceId = (0, utils_3.formatHexStringToBytes32)(deviceId);
157
+ return contract.methods.getTeeOfferByDeviceId(fromattedDeviceId).call();
156
158
  };
157
159
  /**
158
160
  * Function for adding event listeners on TEE offer created event in TEE offers factory contract
package/build/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { TransactionOptions } from "./types/Web3";
2
2
  import Web3 from "web3";
3
+ import { BytesLike } from "@ethersproject/bytes";
3
4
  /**
4
5
  * Function for checking if provider action account initialized (required for set methods)
5
6
  * Used in all set methods
@@ -30,4 +31,6 @@ type Format = FormatItem[] | {
30
31
  export declare const tupleToObject: <T>(data: unknown[], format: Format) => T;
31
32
  export declare const objectToTuple: (data: unknown, format: Format) => unknown[];
32
33
  export declare function incrementMethodCall(): (_target: any, propertyName: string, propertyDescriptor: PropertyDescriptor) => PropertyDescriptor;
34
+ export declare function formatHexStringToBytes32(text: string): string;
35
+ export declare function parseBytes32toHexString(bytes: BytesLike): string;
33
36
  export {};
package/build/utils.js CHANGED
@@ -39,10 +39,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.incrementMethodCall = exports.objectToTuple = exports.tupleToObject = exports.isNodeJS = exports.createTransactionOptions = exports.getGasPrice = exports.checkForUsingExternalTxManager = exports.checkIfActionAccountInitialized = void 0;
42
+ exports.parseBytes32toHexString = exports.formatHexStringToBytes32 = exports.incrementMethodCall = exports.objectToTuple = exports.tupleToObject = exports.isNodeJS = exports.createTransactionOptions = exports.getGasPrice = exports.checkForUsingExternalTxManager = exports.checkIfActionAccountInitialized = void 0;
43
43
  var store_1 = __importDefault(require("./store"));
44
44
  var lodash_1 = require("lodash");
45
45
  var Monitoring_1 = require("./utils/Monitoring");
46
+ var utils_1 = require("ethers/lib/utils");
47
+ var bytes_1 = require("@ethersproject/bytes");
48
+ var constants_1 = require("@ethersproject/constants");
46
49
  /**
47
50
  * Function for checking if provider action account initialized (required for set methods)
48
51
  * Used in all set methods
@@ -172,9 +175,6 @@ var objectToTuple = function (data, format) {
172
175
  exports.objectToTuple = objectToTuple;
173
176
  function incrementMethodCall() {
174
177
  return function (_target, propertyName, propertyDescriptor) {
175
- if (!(0, exports.isNodeJS)()) {
176
- return propertyDescriptor;
177
- }
178
178
  var monitoring = Monitoring_1.Monitoring.getInstance();
179
179
  var method = propertyDescriptor.value;
180
180
  propertyDescriptor.value = function () {
@@ -193,3 +193,37 @@ function incrementMethodCall() {
193
193
  };
194
194
  }
195
195
  exports.incrementMethodCall = incrementMethodCall;
196
+ var hexRegex = /^[0-9a-fA-F]+$/;
197
+ function formatHexStringToBytes32(text) {
198
+ if (!hexRegex.test(text)) {
199
+ throw new Error("formatted value - is not a hex");
200
+ }
201
+ // Get the bytes
202
+ var bytes = (0, utils_1.toUtf8Bytes)(text);
203
+ // Check we have room for null-termination
204
+ if (bytes.length > 32) {
205
+ throw new Error("bytes32 string must be less or equal than 32 bytes");
206
+ }
207
+ // Zero-pad (implicitly null-terminates)
208
+ return (0, bytes_1.hexlify)((0, bytes_1.concat)([bytes, constants_1.HashZero]).slice(0, 32));
209
+ }
210
+ exports.formatHexStringToBytes32 = formatHexStringToBytes32;
211
+ function parseBytes32toHexString(bytes) {
212
+ var data = (0, bytes_1.arrayify)(bytes);
213
+ // Must be 32 bytes
214
+ if (data.length !== 32) {
215
+ throw new Error("invalid bytes32 - not 32 bytes long");
216
+ }
217
+ // Find the null termination
218
+ var length = 32;
219
+ while (data[length - 1] === 0) {
220
+ length--;
221
+ }
222
+ // Determine the string value
223
+ var decodedValue = (0, utils_1.toUtf8String)(data.slice(0, length));
224
+ if (!hexRegex.test(decodedValue)) {
225
+ throw new Error("parsed value - is not a hex");
226
+ }
227
+ return decodedValue;
228
+ }
229
+ exports.parseBytes32toHexString = parseBytes32toHexString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-protocol/sdk-js",
3
- "version": "0.12.1-beta.3",
3
+ "version": "0.12.2-beta.0",
4
4
  "main": "build/index.js",
5
5
  "license": "MIT",
6
6
  "files": [