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.

54 lines (53 loc) 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OutPoint = void 0; const blsct_1 = require("./blsct"); const managedObj_1 = require("./managedObj"); /** Represents an outpoint of a confidential transaction. Also known as `COutPoint` on the C++ side. * * Examples: * ```ts * const { OutPoint, CTxId, CTX_ID_SIZE } = require('navio-blsct') * const { randomBytes } = require('crypto') * const cTxIdHex = randomBytes(CTX_ID_SIZE).toString('hex') * const cTxId = CTxId.deserialize(cTxIdHex) * const outIndex = 0 * const outPoint = OutPoint.generate(cTxId, outIndex) * outPoint * const ser = outPoint.serialize() * const deser = OutPoint.deserialize(ser) * ser === deser.serialize() // true * ``` */ class OutPoint extends managedObj_1.ManagedObj { constructor(obj) { super(obj); } /** Generates a new `OutPoint` instance. * * @param ctxId - The transaction ID of the outpoint. * @param outIndex - The output index of the outpoint. * @return A new `OutPoint` instance with the specified transaction ID and output index. */ static generate(ctxId, outIndex) { const rv = (0, blsct_1.genOutPoint)(ctxId.serialize(), outIndex); const obj = rv.value; (0, blsct_1.freeObj)(rv); return new OutPoint(obj); } value() { return (0, blsct_1.castToOutPoint)(this.obj); } serialize() { return (0, blsct_1.serializeOutPoint)(this.value()); } /** Deserializes an `OutPoint` from its hexadecimal representation. * * @param hex - The hexadecimal string to deserialize. * @returns A new `OutPoint` instance. */ static deserialize(hex) { return OutPoint._deserialize(hex, blsct_1.deserializeOutPoint); } } exports.OutPoint = OutPoint;