@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
97 lines • 3.59 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommitSignature = void 0;
var block_id_1 = require("./block-id");
var hex_1 = require("../../utils/hex");
// CommitSig is a vote included in a Commit.
// For now, it is identical to a vote,
// but in the future it will contain fewer fields
// to eliminate the redundancy in commits.
// See https://github.com/tendermint/tendermint/issues/1648.
/**
*
*
* @class CommitSignature
*/
var CommitSignature = /** @class */ (function () {
/**
* CommitSignature.
* @constructor
* @param {string} type - CommitSignature type.
* @param {BigInt} height - Block height.
* @param {number} round - Equal or greater than 0, number of rounds required for the commit.
* @param {BlockID} blockID - BlockID object.
* @param {string} timestamp - Commit signature timestamp.
* @param {string} validatorAddress - Validator address.
* @param {number} validatorIndex - Validator index.
* @param {string} signature - Signature hash.
*/
function CommitSignature(type, height, round, blockID, timestamp, validatorAddress, validatorIndex, signature) {
this.type = type;
this.height = height;
this.round = round;
this.blockID = blockID;
this.timestamp = timestamp;
this.validatorAddress = validatorAddress;
this.validatorIndex = validatorIndex;
this.signature = signature;
if (!this.isValid()) {
throw new TypeError("Invalid CommitSignature properties.");
}
}
/**
*
* Creates a CommitSignature object using a JSON string
* @param {String} json - JSON string.
* @returns {CommitSignature} - CommitSignature object.
* @memberof CommitSignature
*/
CommitSignature.fromJSON = function (json) {
try {
var jsonObject = JSON.parse(json);
return new CommitSignature(jsonObject.type, BigInt(jsonObject.height), jsonObject.round, block_id_1.BlockID.fromJSON(JSON.stringify(jsonObject.block_id)), jsonObject.timestamp, jsonObject.validator_address, jsonObject.validator_index, jsonObject.signature);
}
catch (error) {
throw error;
}
};
/**
*
* Creates a JSON object with the CommitSignature properties
* @returns {JSON} - JSON Object.
* @memberof CommitSignature
*/
CommitSignature.prototype.toJSON = function () {
return {
block_id: this.blockID.toJSON(),
height: Number(this.height.toString()),
round: this.round,
signature: this.signature,
timestamp: this.timestamp,
type: this.type,
validator_address: this.validatorAddress,
validator_index: this.validatorIndex
};
};
/**
*
* Check if the CommitSignature object is valid
* @returns {boolean} - True or false.
* @memberof CommitSignature
*/
CommitSignature.prototype.isValid = function () {
var validatorAddressIsValid = true;
if (this.validatorAddress) {
validatorAddressIsValid = hex_1.Hex.isHex(this.validatorAddress);
}
return this.blockID.isValid() &&
Number(this.height.toString()) >= 0 &&
this.round >= 0 &&
this.signature.length !== 0 &&
this.timestamp.length !== 0 &&
validatorAddressIsValid;
};
return CommitSignature;
}());
exports.CommitSignature = CommitSignature;
//# sourceMappingURL=commit-signature.js.map