import { Buffer } from 'buffer'; import { UTXO } from '../utxo/selectUtxos'; /** * Transaction Funding Utility for Peg-in Transactions * * This module funds an unfunded transaction template from the SDK by adding * UTXO inputs and change outputs, creating a transaction ready for wallet signing. * * Transaction Flow: * 1. SDK buildPrePeginPsbt() → unfunded Pre-PegIn tx (0 inputs, HTLC + CPFP outputs) * 2. selectUtxosForPegin() → select UTXOs and calculate fees * 3. fundPeginTransaction() → add inputs/change, create funded transaction * * Technical Note: * We manually extract the vault output from SDK hex instead of using bitcoinjs-lib * parsing because bitcoinjs-lib cannot parse 0-input transactions (even witness format). */ import * as bitcoin from "bitcoinjs-lib"; export interface FundPeginTransactionParams { /** Unfunded transaction hex from SDK (0 inputs, vault + depositor claim outputs) */ unfundedTxHex: string; /** Selected UTXOs to use as inputs */ selectedUTXOs: UTXO[]; /** Change address (from wallet) */ changeAddress: string; /** Change amount in satoshis */ changeAmount: bigint; /** Bitcoin network */ network: bitcoin.Network; } /** A single parsed output from the unfunded WASM transaction */ export interface ParsedOutput { value: number; script: Buffer; } /** Parsed data from an unfunded WASM transaction */ interface ParsedUnfundedTx { version: number; locktime: number; outputs: ParsedOutput[]; } /** * Parses an unfunded transaction hex from WASM. * * WASM produces witness-format transactions with 0 inputs, which bitcoinjs-lib cannot parse. * This function manually extracts the transaction components. * * Format: [version:4bytes][marker:0x00][flag:0x01][inputs:1byte=0x00][outputCount:1byte] * [output1: value:8bytes + scriptLen:1byte + script:N bytes] * [output2: ...] * [locktime:4bytes] * * @param unfundedTxHex - Raw transaction hex from WASM * @returns Parsed transaction components * @throws Error if transaction structure is invalid */ export declare function parseUnfundedWasmTransaction(unfundedTxHex: string): ParsedUnfundedTx; /** * Funds an unfunded peg-in transaction by adding inputs and change output. * * Takes an unfunded transaction template (0 inputs, 1 vault output) from the SDK * and adds UTXO inputs and a change output to create a funded transaction ready * for wallet signing. * * @param params - Transaction funding parameters * @returns Transaction hex string ready for wallet signing */ export declare function fundPeginTransaction(params: FundPeginTransactionParams): string; export { getNetwork } from '../../primitives/utils/bitcoin'; //# sourceMappingURL=fundPeginTransaction.d.ts.map