import type { BuildPsbtOptions } from '../types'; import { MempoolApiService } from './MempoolApiService'; /** * Service for building Bitcoin PSBTs */ export declare class PsbtBuilderService { private mempoolApiService; constructor(mempoolApiService: MempoolApiService); /** * Filters out Taproot (P2TR) UTXOs to prevent accidental spending of Ordinals/Runes * Since we only support Native SegWit (P2WPKH), we ensure the account address is not Taproot * @param accountAddress - The account address to check * @param utxos - Array of UTXOs to filter * @returns Filtered array of UTXOs (only P2WPKH compatible) */ private filterTaprootUTXOs; /** * Selects UTXOs using Largest-First (Accumulator) strategy * Sorts UTXOs by value (descending) and selects until we have enough to cover amount + fees * @param utxos - Available UTXOs * @param targetAmount - Target amount including fees and dust limit * @returns Selected UTXOs */ private selectUTXOsLargestFirst; /** * Calculates the total value of UTXOs * @param utxos - Array of UTXOs * @returns Total value in satoshis */ private calculateUTXOTotal; /** * Validates and ensures sufficient funds for the transaction * @param selectedUTXOs - Initially selected UTXOs * @param allUTXOs - All available UTXOs * @param selectedTotal - Total value of selected UTXOs * @param amountInSatoshisNumber - Transaction amount * @param feeEstimate - Estimated fee * @returns Validated selected UTXOs * @throws {DynamicError} If insufficient funds */ private validateAndSelectUTXOs; /** * Calculates fee estimate and change amount, handling dust limit * @param accountAddress - Account address for fee estimation * @param selectedUTXOs - Selected UTXOs * @param selectedTotalValue - Total value of selected UTXOs * @param amountInSatoshis - Transaction amount * @param feePriority - Fee priority level * @returns Object with feeEstimate, changeAmount, changeAmountNumber, and hasChangeOutput */ private calculateFeeAndChange; /** * Adds inputs to PSBT from selected UTXOs * @param psbt - PSBT to add inputs to * @param selectedUTXOs - Selected UTXOs * @param publicKeyPair - ECPair public key pair * @param network - Bitcoin network */ private addInputsToPsbt; /** * Adds outputs to PSBT (recipient and optionally change) * @param psbt - PSBT to add outputs to * @param recipientAddress - Recipient address * @param accountAddress - Account address for change * @param amountInSatoshisNumber - Transaction amount * @param changeAmountNumber - Change amount * @param hasChangeOutput - Whether to include change output * @param network - Bitcoin network */ private addOutputsToPsbt; /** * Builds a PSBT for a Bitcoin transaction with real UTXOs * Uses Largest-First UTXO selection strategy with accurate vSize fee estimation * @param options - Options for building the PSBT * @returns A PSBT in Base64 format * @throws {DynamicError} If insufficient funds, no UTXOs, or other errors */ buildPsbt(options: BuildPsbtOptions): Promise; /** * Helper method to create BuildPsbtOptions from transaction and account details * @param accountAddress - The account address * @param transaction - The Bitcoin transaction (must have amount and recipientAddress) * @param publicKeyHex - The public key in hex format * @param feePriority - Optional fee priority (defaults to 'medium') * @returns BuildPsbtOptions */ static createBuildOptions(accountAddress: string, transaction: { amount: bigint; recipientAddress: string; }, publicKeyHex: string, feePriority?: 'high' | 'medium' | 'low'): BuildPsbtOptions; }