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.
70 lines (69 loc) • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TxIn = void 0;
const blsct_1 = require("./blsct");
const managedObj_1 = require("./managedObj");
const spendingKey_1 = require("./keys/childKeyDesc/txKeyDesc/spendingKey");
const tokenId_1 = require("./tokenId");
const outPoint_1 = require("./outPoint");
class TxIn extends managedObj_1.ManagedObj {
constructor(obj) {
super(obj);
}
static generate(amount, gamma, spendingKey, tokenId, outPoint, isStakedCommitment = false, isRbf = false) {
const rv = (0, blsct_1.buildTxIn)(amount, gamma, spendingKey.value(), tokenId.value(), outPoint.value(), isStakedCommitment, isRbf);
if (rv.result !== 0) {
(0, blsct_1.freeObj)(rv);
throw new Error(`Failed to build TxIn. Error code = ${rv.result}`);
}
const x = new TxIn(rv.value);
x.objSize = rv.value_size;
(0, blsct_1.freeObj)(rv);
return x;
}
value() {
return (0, blsct_1.castToTxIn)(this.obj);
}
getAmount() {
return (0, blsct_1.getTxInAmount)(this.value());
}
getGamma() {
return (0, blsct_1.getTxInGamma)(this.value());
}
getSpendingKey() {
const obj = (0, blsct_1.getTxInSpendingKey)(this.value());
return spendingKey_1.SpendingKey.fromObj(obj);
}
getTokenId() {
const obj = (0, blsct_1.getTxInTokenId)(this.value());
return tokenId_1.TokenId.fromObj(obj);
}
getOutPoint() {
const obj = (0, blsct_1.getTxInOutPoint)(this.value());
return outPoint_1.OutPoint.fromObj(obj);
}
getIsStakedCommitment() {
return (0, blsct_1.getTxInStakedCommitment)(this.value());
}
getIsRbf() {
return (0, blsct_1.getTxInRbf)(this.value());
}
clone() {
const ser = this.serialize();
return TxIn.deserialize(ser);
}
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 TxIn(obj);
x.objSize = hex.length / 2;
return x;
}
}
exports.TxIn = TxIn;