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.

55 lines (54 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AmountRecoveryRes = void 0; /** The result of recovering a single amount from a non-aggregated range proof. * Refer to `RangeProof` for a usage example. */ class AmountRecoveryRes { isSucc; amount; msg; /** Constructs a new `AmountRecoveryRes` instance. * @param isSucc - Indicates whether the recovery was successful. * @param amount - The recovered amount. * @param msg - The recovered message. */ constructor(isSucc, amount, msg) { this.isSucc = isSucc; this.amount = amount; this.msg = msg; } /** Returns a string representation of the `AmountRecoveryRes`. * @returns a string representation of the `AmountRecoveryRes`. */ toString() { return `${this.constructor.name}(${this.isSucc}, ${this.amount}, ${this.msg})`; } serialize() { const jsonStr = JSON.stringify(this); const buf = Buffer.from(jsonStr, 'utf-8'); return buf.toString('hex'); } /** Deserializes a hexadecimal string into an `AmountRecoveryRes` instance. * @param hex - The hexadecimal string to deserialize. * @returns An instance of `AmountRecoveryRes`. */ deserialize(hex) { let obj; try { const json = Buffer.from(hex, 'hex').toString('utf8'); obj = JSON.parse(json); } catch (e) { throw new Error(`Failed to deserialize to object: ${JSON.stringify(e)}`); } if (typeof obj !== 'object' || typeof obj.isSucc !== 'boolean' || typeof obj.amount !== 'number' || typeof obj.msg !== 'string') { throw new Error(`Deserialize object is not AmountRecoveryRes: ${hex}`); } return new AmountRecoveryRes(obj.isSucc, obj.amount, obj.msg); } } exports.AmountRecoveryRes = AmountRecoveryRes;