Skip to content

feat(bitcoin): Maestro data provider and first-class coin selection#10

Open
jinglescode wants to merge 1 commit into
mainfrom
feature/bitcoin-maestro-provider
Open

feat(bitcoin): Maestro data provider and first-class coin selection#10
jinglescode wants to merge 1 commit into
mainfrom
feature/bitcoin-maestro-provider

Conversation

@jinglescode

Copy link
Copy Markdown
Member

Milestone: standard headless wallet on Bitcoin

Closes the remaining gap for the Bitcoin headless wallet milestone: the wallet, coin selection, and signTransfer already existed in src/, but no concrete data provider did. This PR adds the Maestro provider and promotes coin selection to a first-class, tested module.

A1 — UTXO querying via Maestro

  • MaestroProvider (src/bitcoin/providers/maestro.ts) implements the existing IBitcoinProvider interface against Maestro's Esplora-compatible Bitcoin API: address info/UTXOs, per-tx unspent outputs (via /outspends), paginated tx history, tx status, sat/vB fee estimates (closest-target selection, testnet fallback), and raw-tx broadcast.
  • Uses the platform fetch — zero new runtime dependencies. Shared plumbing in src/bitcoin/providers/common.ts with a typed ProviderHttpError.

A2 — Coin selection on queried UTXOs

  • Extracted the largest-first selector into src/bitcoin/utils/coin-selection.ts and exported it (selectUtxosLargestFirst, DUST_THRESHOLD_P2WPKH). Behavior unchanged: BIP-141 vbyte fee model, 546-sat dust absorption. BitcoinHeadlessWallet.signTransfer now delegates to it.

A3 — Send transfer

  • The existing signTransfer flow (query → select → PSBT → sign → broadcast) runs end-to-end on the Maestro provider; covered by the existing wallet regression tests.

Tests & docs

  • 20 new provider tests (mocked HTTP) + 12 coin-selection tests; full suite green on this branch (231 tests, 19 suites), tsup CJS/ESM/DTS build passes.
  • README "Bitcoin Headless Wallet" section and bitcoin-milestone.md mapping acceptance criteria to code.

🤖 Generated with Claude Code

Milestone: standard headless wallet on Bitcoin.

- MaestroProvider implements IBitcoinProvider against Maestro's
  Esplora-compatible Bitcoin API using platform fetch (no new deps):
  address info/UTXOs/txs, per-tx unspent outputs via outspends,
  tx status, sat/vB fee estimates with closest-target selection,
  and raw-tx broadcast.
- Extract largest-first coin selection from BitcoinHeadlessWallet
  into src/bitcoin/utils/coin-selection.ts and export it; behavior
  unchanged (BIP-141 vbyte model, 546-sat dust handling).
- Unit tests for provider (mocked HTTP) and coin selection.
- README Bitcoin section and bitcoin-milestone.md evidence doc.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant