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.

40 lines (39 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AmountRecoveryRes = void 0; class AmountRecoveryRes { isSucc; amount; msg; constructor(isSucc, amount, msg) { this.isSucc = isSucc; this.amount = amount; this.msg = msg; } 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'); } 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;