/** * Withdrawal UTXO selection (Phase 1, btc-withdrawal Step 4.5). * * Selects the representative UTXO recorded in the on-chain authorized spend: * - Single-UTXO path: the SMALLEST confirmed UTXO that alone covers * `totalDeduction` (minimizes change). * - Multi-UTXO consolidation path: entered when NO single UTXO covers the * withdrawal. The AGGREGATE confirmed balance must cover it; the LARGEST * UTXO becomes the representative and Phase 2 (btc-transaction-signer) * consolidates the additional inputs. The representative is legitimately * `< totalDeduction` here — that is the entire reason this path exists, * and it must NOT be treated as an error (the pre-extraction guard that * did so rejected every valid multi-UTXO withdrawal; remediation P0). * * Downstream safety: Phase 2 requires the input set to include the * representative, belong to the vault, and sum to >= the target; the on-chain * `satoshis` figure is the full-balance aggregate reservation and is never * reconciled against the representative's own value. * * Throws ONLY when the aggregate confirmed balance cannot cover * `totalDeduction` (genuine insufficiency), or on empty/invalid input. */ import { UTXO } from "../../interfaces/chunks/vault-balance.i"; import type { TransactionOutput } from "../../interfaces/chunks/bitcoin-data-provider.i"; export interface WithdrawalUtxoSelection { /** Representative UTXO recorded in the on-chain authorization. */ selectedUTXO: UTXO; /** * True when no single UTXO covers the withdrawal and Phase 2 must * consolidate multiple inputs. The representative is the largest UTXO and * is expected to be < totalDeduction. */ multiUtxoConsolidation: boolean; } /** * Spend-safety gate: keep only UTXOs deep enough for the protocol to SPEND. * * `minConf` must be the policy-derived `minBitcoinSpendConfirmations` * (mainnet 6) — never looser than the balance-confirmation threshold stamped * on the resolved Bitcoin provider config. When the thresholds diverge, a * UTXO that already counts toward the confirmed vault balance may still be * too shallow to spend. */ export declare function filterSpendableUtxos(utxos: UTXO[], minConf: number): UTXO[]; /** * Canonicalize the representative UTXO's vout against the funding * transaction's actual outputs. * * Esplora's `/address//utxo` endpoint is known to mis-report the vout * index for some funding transactions on the regtest faucet, so the vout must * be verified against the raw transaction before it is committed on-chain. * (Phase B's cross-provider consensus cannot catch this on regtest, where the * faucet is the only provider — 1-of-1 consensus shares the bug.) * * INVARIANT: a vout correction may only move to an output carrying the * SELECTED VALUE — `(vout, satoshis)` are never decoupled. Matching on * script/address alone corrupted the pair whenever one transaction paid the * vault in two or more outputs (the first vault output won, keeping the other * output's satoshis). * * Match order: * 1. Trust the reported vout when that output pays the vault AND carries the * selected value (resolves identical-value duplicate vault outputs). * 2. Otherwise the UNIQUE vault output whose value equals the selected value. * * Fail-loud (never emit a corrupt triple): * - no output pays the vault at all → wrong transaction; * - vault outputs exist but none carries the selected value → corrupt * `(vout, value)` source data; * - the reported vout is wrong AND more than one vault output carries the * selected value → ambiguous; picking by index order could authorize an * outpoint that collides with authorized-spend bookkeeping (review P2); * - a vault output's value is not a sane satoshi integer → corrupt provider * response (BigInt comparison would otherwise throw or lie). */ export declare function canonicalizeRepresentativeVout(selectedUTXO: UTXO, txOutputs: TransactionOutput[], expectedScriptHex: string, vaultAddress: string): UTXO; export declare function selectWithdrawalUtxo(confirmedUTXOs: UTXO[], totalDeduction: bigint): WithdrawalUtxoSelection; //# sourceMappingURL=utxo-selection.d.ts.map