UNPKG

chaingate

Version:

A complete TypeScript library for connecting to and making transactions on different blockchains

48 lines 2.34 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BitcoinCashPreparedTransaction = void 0; const Utils_1 = require("../../../../InternalUtils/Utils"); const bitcore_lib_cash_1 = __importDefault(require("bitcore-lib-cash")); const bchaddrjs_1 = require("bchaddrjs"); const UtxoTransaction_1 = require("../../abstract/UtxoWallet/UtxoTransaction"); const utils_1 = require("../../abstract/UtxoWallet/utils"); Object.defineProperty(global, '_bitcoreCash', { get() { return undefined; }, set() { }, configurable: true, }); class BitcoinCashPreparedTransaction extends UtxoTransaction_1.UtxoTransaction { constructor(utils, fromAddress, toAddress, amount, privateKeyProvider) { super(utils, fromAddress, toAddress, amount, { bech32: 'bc', pubKeyHash: 0x00, scriptHash: 0x05, wif: 0x80, }, privateKeyProvider, (address) => (0, bchaddrjs_1.toLegacyAddress)(address)); } async sign(inputs, outputs) { let transaction = new bitcore_lib_cash_1.default.Transaction(); transaction = transaction.from(inputs.map((t) => new bitcore_lib_cash_1.default.Transaction.UnspentOutput({ txId: t.txid, outputIndex: t.n, script: bitcore_lib_cash_1.default.Script.fromHex((0, Utils_1.bytesToHex)(t.script, false)), satoshis: (0, utils_1.toSatoshi)(t.amount).toNumber(), }))); outputs.forEach((t) => { transaction = transaction.addOutput(new bitcore_lib_cash_1.default.Transaction.Output({ satoshis: (0, utils_1.toSatoshi)(t.amount).toNumber(), script: bitcore_lib_cash_1.default.Script.fromAddress(bitcore_lib_cash_1.default.Address.fromString((0, bchaddrjs_1.toCashAddress)(t.address))), })); }); const privateKey = (await this.privateKeyProvider()).raw; transaction = transaction.sign((0, Utils_1.bytesToHex)(privateKey, false)); return (0, Utils_1.hexToBytes)(transaction.serialize()); } } exports.BitcoinCashPreparedTransaction = BitcoinCashPreparedTransaction; //# sourceMappingURL=BitcoinCashPreparedTransaction.js.map