Skip to content

feat(wallet): expose finalize_psbt, cancel_tx, tx_details, descriptor_checksum, next_derivation_index#43

Open
darioAnongba wants to merge 3 commits intomainfrom
feat/wallet-api-expansion
Open

feat(wallet): expose finalize_psbt, cancel_tx, tx_details, descriptor_checksum, next_derivation_index#43
darioAnongba wants to merge 3 commits intomainfrom
feat/wallet-api-expansion

Conversation

@darioAnongba
Copy link
Collaborator

@darioAnongba darioAnongba commented Mar 17, 2026

Summary

Exposes five bdk_wallet::Wallet methods that were available upstream but not yet wrapped for WASM consumers. Continues the API surface expansion tracked in #21.

New Wallet Methods

Method Description
finalize_psbt(psbt, options) Finalize a PSBT (add finalized scripts/witnesses to inputs). Essential for multi-sig and watch-only workflows.
cancel_tx(tx) Release reserved change addresses when a transaction won't be broadcast.
tx_details(txid) Get comprehensive transaction details: sent, received, fee, fee rate, balance delta, chain position.
descriptor_checksum(keychain) Get the descriptor checksum string (8-char bech32) for a keychain.
next_derivation_index(keychain) Get the next derivation index (always returns a value, unlike derivation_index which returns None for fresh wallets).

New Type

  • TxDetails — WASM-compatible wrapper for bdk_wallet::TxDetails with getters for txid, sent, received, fee, fee_rate, balance_delta_sat (i64), chain_position, and tx.
    • balance_delta is exposed as i64 satoshis since SignedAmount has 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 with derivation_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: Returns undefined for unknown txid.

Toshi 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 darioAnongba marked this pull request as ready for review March 17, 2026 16:00
@darioAnongba darioAnongba self-assigned this Mar 17, 2026
});
});

describe("tx_details", () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a more comprehensive test.

describe("finalize_psbt", () => {
it("is callable with default SignOptions", () => {
expect(typeof wallet.finalize_psbt).toBe("function");
// Full PSBT finalization is tested in esplora integration tests
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add an empty test? where are these esplora tests using finalize_psbt?

it("is callable on the wallet", () => {
// cancel_tx only unmarks change addresses; with an empty wallet it's a no-op.
// We verify the method exists and is callable.
expect(typeof wallet.cancel_tx).toBe("function");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add an empty test? where are these esplora tests using cancel_tx?

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