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.
66 lines (65 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CTxOut = void 0;
const blsct_1 = require("./blsct");
const managedObj_1 = require("./managedObj");
const tokenId_1 = require("./tokenId");
const ctxOutBlsctData_1 = require("./ctxOutBlsctData");
const script_1 = require("./script");
class CTxOut extends managedObj_1.ManagedObj {
blsctDataCache;
constructor(obj) {
super(obj);
}
value() {
return (0, blsct_1.castToCTxOut)(this.obj);
}
getValue() {
return (0, blsct_1.getCTxOutValue)(this.value());
}
getScriptPubKey() {
const obj = (0, blsct_1.getCTxOutScriptPubkey)(this.value());
return script_1.Script.fromObj(obj);
}
blsctData() {
if (this.blsctDataCache !== undefined) {
return this.blsctDataCache;
}
const x = ctxOutBlsctData_1.CTxOutBlsctData.fromObj(this.value());
this.blsctDataCache = x;
return x;
}
getTokenId() {
const obj = (0, blsct_1.getCTxOutTokenId)(this.value());
return tokenId_1.TokenId.fromObj(obj);
}
getVectorPredicate() {
const rv = (0, blsct_1.getCTxOutVectorPredicate)(this.value());
if (rv.result != 0) {
(0, blsct_1.freeObj)(rv);
throw new Error(`Failed to get vector predicate. Error code = ${rv.result}`);
}
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;
}
serialize() {
const buf = (0, blsct_1.castToUint8_tPtr)(this.value());
return (0, blsct_1.toHex)(buf, this.size());
}
static deserialize(hex) {
if (hex.length % 2 !== 0) {
hex = `0${hex}`;
}
const obj = (0, blsct_1.hexToMallocedBuf)(hex);
const x = new CTxOut(obj);
x.objSize = hex.length / 2;
return x;
}
}
exports.CTxOut = CTxOut;