UNPKG

navio-blsct

Version:

TypeScript bindings for the `libblsct` library used by the [Navio](https://nav.io/) blockchain to construct confidential transactions based on the BLS12-381 curve.

50 lines (49 loc) 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AmountRecoveryReq = void 0; const blsct_1 = require("./blsct"); const point_1 = require("./point"); const rangeProof_1 = require("./rangeProof"); /** A request for recovering a single amount from a non-aggregated range proof. * Refer to `RangeProof` for a usage example. */ class AmountRecoveryReq { rangeProof; nonce; /** Constructs a new `AmountRecoveryReq` instance. * @param rangeProof - The range proof to recover the amount from. * @param nonce - The nonce used to generate the range proof. */ constructor(rangeProof, nonce) { this.rangeProof = rangeProof; this.nonce = nonce; } /** Returns a string representation of the `AmountRecoveryReq`. * @returns a string representation of the `AmountRecoveryReq`. */ toString() { return `${this.constructor.name}(${this.rangeProof}, ${this.nonce})`; } serialize() { const serRangeProof = this.rangeProof.serialize(); const serNonce = this.nonce.serialize(); return `${serRangeProof}${serNonce}`; } /** Deserializes a hexadecimal string into an `AmountRecoveryReq` instance. * @param hex - The hexadecimal string to deserialize. * @returns An instance of `AmountRecoveryReq`. */ static deserialize(hex) { if (hex.length % 2 !== 0) { hex = `0${hex}`; } const nonceHexLen = blsct_1.POINT_SIZE * 2; const rangeProofHexLen = hex.length - nonceHexLen; const rangeProofHex = hex.slice(0, rangeProofHexLen); const nonceHex = hex.slice(rangeProofHexLen); const rangeProof = rangeProof_1.RangeProof.deserialize(rangeProofHex); const nonce = point_1.Point.deserialize(nonceHex); return new AmountRecoveryReq(rangeProof, nonce); } } exports.AmountRecoveryReq = AmountRecoveryReq;