chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
77 lines • 3.36 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.LegacyUtxoPreparedTransaction = void 0;
const Utils_1 = require("../../../../InternalUtils/Utils");
const btc = __importStar(require("@scure/btc-signer"));
const btc_signer_1 = require("@scure/btc-signer");
const UtxoTransaction_1 = require("../UtxoWallet/UtxoTransaction");
const UtxoUtils_1 = require("../UtxoWallet/UtxoUtils");
class LegacyUtxoPreparedTransaction extends UtxoTransaction_1.UtxoTransaction {
constructor(utils, fromAddress, toAddress, amount, networkParams, privateKeyProvider) {
super(utils, fromAddress, toAddress, amount, networkParams, privateKeyProvider);
}
toLegacyAddress(address) {
return address;
}
async sign(inputs, outputs) {
const txVins = inputs.map((vin) => ({
txid: (0, Utils_1.hexToBytes)(vin.txid),
index: vin.n,
witnessUtxo: {
script: vin.script,
amount: BigInt((0, UtxoUtils_1.toSatoshi)(vin.amount.toString()).toString()),
},
}));
const txVouts = outputs.map((vout) => ({
script: btc_signer_1.OutScript.encode(btc.Address(this.networkParams).decode(vout.address)),
amount: BigInt((0, UtxoUtils_1.toSatoshi)(vout.amount).toString()),
}));
const transaction = new btc.Transaction({
allowLegacyWitnessUtxo: true,
});
for (const txVin of txVins)
transaction.addInput(txVin);
for (const txVout of txVouts)
transaction.addOutput(txVout);
const privateKeyRaw = (await this.privateKeyProvider()).raw;
for (let i = 0; i < transaction.inputsLength; i++)
transaction.signIdx(privateKeyRaw, i);
transaction.finalize();
return (0, Utils_1.hexToBytes)(transaction.hex);
}
}
exports.LegacyUtxoPreparedTransaction = LegacyUtxoPreparedTransaction;
//# sourceMappingURL=LegacyUtxoPreparedTransaction.js.map