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.
101 lines (100 loc) • 3.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CTxOut = void 0;
const blsct_1 = require("./blsct");
const point_1 = require("./point");
const rangeProof_1 = require("./rangeProof");
const scalar_1 = require("./scalar");
const script_1 = require("./script");
const tokenId_1 = require("./tokenId");
/** Represents a transaction output in a constructed confidential transaction. Also known as `CTxOut` on the C++ side.
*
* For code examples, see the `ctx.ts` class documentation.
*/
class CTxOut {
obj;
rangeProofCache;
constructor(obj) {
this.obj = obj;
}
/** Returns the value of the transaction output.
* * @returns The value of the output.
*/
getValue() {
return (0, blsct_1.getCTxOutValue)(this.obj);
}
/** Returns the `scriptPubKey' of the transaction output.
* * @returns The `scriptPubKey` of the output.
*/
getScriptPubKey() {
const obj = (0, blsct_1.getCTxOutScriptPubkey)(this.obj);
return script_1.Script.fromObj(obj);
}
/** Returns the token ID associated with the transaction output.
* @returns The token ID of the output.
*/
getTokenId() {
const obj = (0, blsct_1.getCTxOutTokenId)(this.obj);
return tokenId_1.TokenId.fromObj(obj);
}
/** Returns the vector predicate of the transaction output.
* * @returns The vector predicate as a hexadecimal string.
*/
getVectorPredicate() {
const rv = (0, blsct_1.getCTxOutVectorPredicate)(this.obj);
if (rv.result != 0) {
const msg = `Failed to get vector predicate. Error code = ${rv.result}`;
(0, blsct_1.freeObj)(rv);
throw new Error(msg);
}
if (rv.value_size !== 0) {
(0, blsct_1.freeObj)(rv);
return "";
}
const buf = (0, blsct_1.castToUint8_tPtr)(rv.value);
const hex = (0, blsct_1.toHex)(buf, rv.value_size);
(0, blsct_1.freeObj)(rv);
return hex;
}
/** Returns the spending key associated with the transaction output.
* @returns The spending key of the output.
*/
getSpendingKey() {
const obj = (0, blsct_1.getCTxOutSpendingKey)(this.obj);
return scalar_1.Scalar.fromObj(obj);
}
/** Returns the ephemeral key associated with the transaction output.
* @returns The ephemeral key of the output.
*/
getEphemeralKey() {
const obj = (0, blsct_1.getCTxOutEphemeralKey)(this.obj);
return point_1.Point.fromObj(obj);
}
/** Returns the blinding key associated with the transaction output.
* @returns The blinding key of the output.
*/
getBlindingKey() {
const obj = (0, blsct_1.getCTxOutBlindingKey)(this.obj);
return scalar_1.Scalar.fromObj(obj);
}
/** Returns the range proof associated with the transaction output.
* @returns The range proof of the output.
*/
getRangeProof() {
if (this.rangeProofCache !== undefined) {
return this.rangeProofCache;
}
const rv = (0, blsct_1.getCTxOutRangeProof)(this.obj);
const x = rangeProof_1.RangeProof.fromObjAndSize(rv.value, rv.value_size);
(0, blsct_1.freeObj)(rv);
this.rangeProofCache = x;
return x;
}
/** Returns the view tag associated with the view of the transaction output.
* @returns The view tag of the output.
*/
getViewTag() {
return (0, blsct_1.getCTxOutViewTag)(this.obj);
}
}
exports.CTxOut = CTxOut;