mirror of
https://github.com/luxfi/bridge.git
synced 2026-09-24 00:26:46 +00:00
Wire-correct BTC release tx assembler that the MPC quorum can threshold-sign and the broadcast driver can push. Mirrors the EVM PreSign/Finalize shape but emits N per-input sighashes (one MPC sign call per input) instead of one EIP-155 digest. Scope (v1): - P2WPKH witness-v0 only (bech32 bc1q.../tb1q...); P2TR deferred - SIGHASH_ALL only (no anyonecanpay / single) - Greedy largest-first UTXO selection — adequate for the bridge's own pool wallet, no churn concerns - Single change output back to the release address (dropped under the 546 sat dust threshold) - BIP143 sighash via btcd/txscript.CalcWitnessSigHash; scriptCode computed from the P2WPKH pkScript via the canonical OP_DUP OP_HASH160 <pkh> OP_EQUALVERIFY OP_CHECKSIG transform - Fee estimation: mempool.space halfHourFee with fastestFee / minimumFee fallback; static fallback rate 10 sat/vB - Low-s canonicalization in Finalize (BIP146); high-s sigs are refused by relay nodes - DER encoding: canonical with 0x00 leading-pad when high bit set - RBF-friendly sequence (0xfffffffd) on every input What's NOT in this commit: - PSBT wire format — we use raw wire internally; PSBT is a hardware-wallet convenience irrelevant in-process - Bitcoin Core RPC — operators can override broadcast URL but the default uses mempool.space's REST API (zero-setup) New types: - BTCNetwork, BTCSpec, BTCUTXO, BTCInputCtx, BTCUnsigned, BTCECDSASig - BTCAssembler with UTXOFetcher / FeeEstimator / BalanceProbe seams - MempoolSpaceClient implements all three from public REST endpoints Tests: 30+ across selectBTCUTXOs (greedy correctness, insufficient funds, fee scaling), p2wpkhScriptCode, chainHashFromTxID round-trip, encodeDERSignature (low-s + high-bit padding + zero rejection), ParseBTCRSV, PreSign happy path + dust handling + insufficient funds + pubkey/address validation, Finalize witness layout + sig count mismatch, MempoolSpaceClient UTXO/fee/balance shape parsing