UNPKG

@pokt-network/pocket-js

Version:

Pocket-js core package with the main functionalities to interact with the Pocket Network.

76 lines 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RelayResponse = void 0; var relay_proof_response_1 = require("./relay-proof-response"); var input_1 = require("../input"); /** * * * @class RelayResponse */ var RelayResponse = /** @class */ (function () { /** * Relay Response. * @constructor * @param {string} signature - Signature. * @param {string} payload - Payload string. */ function RelayResponse(signature, payload, proof, relayRequest) { this.signature = signature; this.payload = payload; this.proof = proof; this.relayRequest = relayRequest; if (!this.isValid()) { throw new TypeError("Invalid RelayResponse properties."); } } /** * * Creates a RelayResponse object using a JSON string * @param {String} json - JSON string. * @returns {RelayResponse} - RelayResponse object. * @memberof RelayResponse */ RelayResponse.fromJSON = function (json) { try { var jsonObject = JSON.parse(json); var proof = relay_proof_response_1.RelayProofResponse.fromJSON(JSON.stringify(jsonObject.request.proof)); var relayRequest = input_1.RelayRequest.fromJSON(JSON.stringify(jsonObject.request)); return new RelayResponse(jsonObject.response.signature, jsonObject.response.response, proof, relayRequest); } catch (error) { throw error; } }; /** * * Creates a JSON object with the RelayResponse properties * @returns {JSON} - JSON Object. * @memberof RelayResponse */ RelayResponse.prototype.toJSON = function () { return { response: { payload: this.payload, signature: this.signature, proof: this.proof.toJSON(), }, request: this.relayRequest.toJSON() }; }; /** * * Check if the RelayResponse object is valid * @returns {boolean} - True or false. * @memberof RelayResponse */ RelayResponse.prototype.isValid = function () { return (this.signature.length !== 0 && this.payload.length !== 0 && this.proof.isValid() && this.relayRequest.isValid()); }; return RelayResponse; }()); exports.RelayResponse = RelayResponse; //# sourceMappingURL=relay-response.js.map