@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
96 lines • 3.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RelayProofResponse = void 0;
var aat_js_1 = require("@pokt-network/aat-js");
var hex_1 = require("../../../utils/hex");
/**
*
*
* @class Proof
*/
var RelayProofResponse = /** @class */ (function () {
/**
* Proof.
* @constructor
* @param {BigInt} entropy - Index entropy value.
* @param {BigInt} sessionBlockHeight - Session Block Height.
* @param {string} servicerPubKey - Service PublicKey.
* @param {string} blockchain - Blockchain hash.
* @param {PocketAAT} token - Application Authentication Token object.
* @param {string} signature - Proof's signature.
* @param {string} requestHash - RequestHash string.
*/
function RelayProofResponse(entropy, sessionBlockHeight, servicerPubKey, blockchain, token, signature, requestHash) {
this.entropy = entropy;
this.sessionBlockHeight = sessionBlockHeight;
this.servicerPubKey = servicerPubKey;
this.blockchain = blockchain;
this.token = token;
this.signature = signature;
this.requestHash = requestHash;
if (!this.isValid()) {
throw new TypeError("Invalid Relay Proof response properties.");
}
}
/**
*
* Creates a Proof object using a JSON string
* @param {string} json - JSON string.
* @returns {RelayProofResponse} - Proof object.
* @memberof Proof
*/
RelayProofResponse.fromJSON = function (json) {
try {
var jsonObject = JSON.parse(json);
var pocketAAT = void 0;
if (jsonObject.aat !== undefined) {
pocketAAT = new aat_js_1.PocketAAT(jsonObject.aat.version, jsonObject.aat.client_pub_key, jsonObject.aat.app_pub_key, jsonObject.aat.signature);
return new RelayProofResponse(jsonObject.entropy, jsonObject.session_block_height, jsonObject.servicer_pub_key, jsonObject.blockchain, pocketAAT, jsonObject.signature, jsonObject.request_hash);
}
else {
throw new Error("Failed to retrieve PocketAAT, property is undefined");
}
}
catch (error) {
throw new Error("Failed to retrieve PocketAAT for Proof with error: " + error);
}
};
/**
*
* Creates a JSON object with the Proof properties
* @returns {JSON} - JSON Object.
* @memberof Proof
*/
RelayProofResponse.prototype.toJSON = function () {
return {
entropy: Number(this.entropy.toString()),
session_block_height: Number(this.sessionBlockHeight.toString()),
servicer_pub_key: this.servicerPubKey,
blockchain: this.blockchain,
aat: {
version: this.token.version,
app_pub_key: this.token.applicationPublicKey,
client_pub_key: this.token.clientPublicKey,
signature: this.token.applicationSignature
},
signature: this.signature,
request_hash: this.requestHash
};
};
/**
*
* Check if the Proof object is valid
* @returns {boolean} - True or false.
* @memberof Proof
*/
RelayProofResponse.prototype.isValid = function () {
return this.blockchain.length !== 0 &&
Number(this.entropy.toString()) !== undefined &&
hex_1.Hex.isHex(this.servicerPubKey) &&
Number(this.sessionBlockHeight) > 0 &&
this.token.isValid();
};
return RelayProofResponse;
}());
exports.RelayProofResponse = RelayProofResponse;
//# sourceMappingURL=relay-proof-response.js.map