UNPKG

chaingate

Version:

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

45 lines 2.44 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("../../../../../Utils/Utils"); const bitcore_lib_cash_1 = __importDefault(require("bitcore-lib-cash")); const bchaddrjs_1 = require("bchaddrjs"); const UtxoPreparedTransaction_1 = require("../../abstract/Utxo/UtxoPreparedTransaction"); const UtxoUtils_1 = require("../../abstract/Utxo/UtxoUtils"); Object.defineProperty(global, '_bitcoreCash', { get() { return undefined; }, set() { }, configurable: true }); class BitcoinCashPreparedTransaction extends UtxoPreparedTransaction_1.UtxoPreparedTransaction { constructor(api, currencyProviders, currencyInfo, fromAddress, toAddress, amount, privateKeyProvider) { super(api, currencyProviders, currencyInfo, fromAddress, toAddress, amount, { bech32: 'bc', pubKeyHash: 0x00, scriptHash: 0x05, wif: 0x80 }, privateKeyProvider); } toLegacyAddress(address) { return (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, UtxoUtils_1.toSatoshi)(t.amount).toNumber() }))); outputs.forEach(t => { transaction = transaction.addOutput(new bitcore_lib_cash_1.default.Transaction.Output({ satoshis: (0, UtxoUtils_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