feat(wallet): expose finalize_psbt, cancel_tx, tx_details, descriptor_checksum, next_derivation_index#43
Merged
darioAnongba merged 12 commits intomainfrom Mar 25, 2026
Merged
Conversation
added 2 commits
March 17, 2026 10:07
…_checksum, next_derivation_index Add five new Wallet methods that were available in bdk_wallet but not yet exposed through the WASM bindings: - finalize_psbt: Finalize a PSBT by adding finalized scripts and witnesses to inputs. Essential for multi-sig and watch-only workflows. - cancel_tx: Inform the wallet that a transaction will not be broadcast, freeing reserved change addresses for future transactions. - tx_details: Get comprehensive transaction details including sent, received, fee, fee rate, balance delta, and chain position. - descriptor_checksum: Get the checksum portion of the descriptor string for a given keychain. - next_derivation_index: Get the next unused derivation index, always returning a value (0 if nothing derived yet), unlike derivation_index which returns None. Also adds the TxDetails WASM-compatible wrapper type with getters for all fields, exposing balance_delta as i64 satoshis since SignedAmount has no existing wrapper. Closes #21
darioAnongba
commented
Mar 17, 2026
added 9 commits
March 24, 2026 10:03
Address review feedback on PR #43: - tx_details: Add esplora integration test that verifies all TxDetails fields (txid, sent, received, fee, fee_rate, balance_delta_sat, chain_position, tx) for a known wallet transaction after self-send. Add unit test for fresh wallet returning undefined. - finalize_psbt: Add esplora integration test that signs a PSBT with try_finalize=false, then calls finalize_psbt separately and verifies the PSBT is extractable. Replaces empty stub in unit tests. - cancel_tx: Add esplora integration test that builds a tx (reserving a change address), cancels it, and verifies the internal derivation index stays unchanged. Improve unit test with index assertions.
…t, cancel_tx - tx_details: Find the self-send tx (sent > 0) instead of assuming txs[0] is the self-send (it's the faucet funding tx on regtest) - finalize_psbt/cancel_tx: Create new FeeRate instances instead of reusing the consumed feeRate variable (wasm-bindgen ownership) - Remove unused dummyTxid variable (ESLint no-unused-vars)
SentAndReceived is a tuple struct without named field getters in the wasm-bindgen TypeScript definitions. Use tx_details() which exposes named sent/received getters to find the self-send transaction.
- finalize_psbt: sign() returns false with try_finalize=false because it reports finalization status, not signing success. Assert false then verify finalize_psbt succeeds separately. - cancel_tx: next_derivation_index tracks derived count (not usage). Use list_unused_addresses to verify change addr returns to unused pool after cancel.
- cancel_tx test: use next_derivation_index and list_unused_addresses correctly to verify the change address is freed after cancellation, without depending on shared wallet state from prior tests - events test: wait for the specific funding tx to be indexed by Esplora before running the full scan, fixing intermittent race condition where the block was indexed but the tx wasn't yet queryable
cancel_tx unmarks the change address so it can be reused. The test now verifies this by building a tx (which advances the internal derivation index), cancelling it, then building another tx and confirming the derivation index does not advance further (proving the change address was reused instead of revealing a new one).
…ming - cancel_tx test: create fresh Recipient instances for the second build_tx call to avoid null pointer from wasm-bindgen ownership consumption of ScriptBuf and Amount objects - events test beforeAll: wait for address-level Esplora indexing instead of just tx endpoint, since full_scan queries by script pubkey - events test TxConfirmed after send: wait for tx to be confirmed in Esplora before syncing wallet to avoid race condition
…nge output The cancel_tx test assumed that building a tx with 600 sats would always produce a change output. With small UTXOs, the remaining amount after send + fee can fall below the dust threshold (546 sats for P2WPKH), causing BDK to fold it into fees instead of creating a change output. This meant no new internal address was revealed, failing the derivation index assertion. Fix: send 25% of balance instead of a fixed 600 sats, guaranteeing the remaining ~75% always exceeds the dust threshold and produces a change output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Exposes five
bdk_wallet::Walletmethods that were available upstream but not yet wrapped for WASM consumers. Continues the API surface expansion tracked in #21.New Wallet Methods
finalize_psbt(psbt, options)cancel_tx(tx)tx_details(txid)descriptor_checksum(keychain)next_derivation_index(keychain)derivation_indexwhich returnsNonefor fresh wallets).New Type
TxDetails— WASM-compatible wrapper forbdk_wallet::TxDetailswith getters fortxid,sent,received,fee,fee_rate,balance_delta_sat(i64),chain_position, andtx.balance_deltais exposed asi64satoshis sinceSignedAmounthas no existing WASM wrapper.Tests
descriptor_checksum: Validates non-empty 8-char string, different for external/internal keychains.next_derivation_index: Tests fresh wallet (returns 0), increment after reveal, consistency withderivation_index.cancel_tx: Method existence and callability.finalize_psbt: Method existence check (full PSBT finalization requires funded wallet, covered in esplora integration tests).tx_details: Returnsundefinedfor unknown txid.