Skip to content

refactor(wallet)!: remove signer and policy modules - #647

Merged
noahjoeris merged 6 commits into
bitcoindevkit:masterfrom
noahjoeris:signer-removal
Dec 2, 2026
Merged

noahjoeris merged 6 commits into
bitcoindevkit:masterfrom
noahjoeris:signer-removal

Conversation

@noahjoeris

@noahjoeris noahjoeris commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #70

Description

Implements the signer removal planned in #70 for v4 alpha 0.

Removes the signer and descriptor policy modules, including wallet signing and keymap management. Wallets retain only public descriptors; callers manage keys and sign through bitcoin::Psbt::sign or an external signer.

Notes to the reviewers

  • Review commits in order.
  • TxBuilder derives timelocks directly from descriptors, removing its dependency on the policy and signer modules. I moved Condition from policy to tx_builder to retain set_condition after removing the policy module.
  • Psbt::sign does not replace all SignOptions behavior at the moment. Callers must handle prevout validation and sighash restrictions previously controlled by trust_witness_utxo and allow_all_sighashes. I added an example of how to do so in examples/signing_checks.rs
  • Also I noticed we remove some non-deprecated functions. But I think we can just deprecate them later on the 3.x release.

Changelog notice

### Added

- `signing_checks` example replacing the `SignOptions` `trust_witness_utxo` and `allow_all_sighashes` checks for `Psbt::sign`.

### Changed

- `CreateTxError` is now `#[non_exhaustive]`.
- `CreateTxError::Policy(PolicyError::MixedTimelockUnits)` is now `CreateTxError::MixedTimelockUnits`.
- `TxBuilder::finish` returns `SpendingPolicyRequired` for descriptors that cannot be lifted to a policy, unless a condition is set.
- `Wallet::finalize_psbt` no longer takes `SignOptions` and returns `Result<bool, IndexOutOfBoundsError>`.

### Removed

- `signer` and `descriptor::policy` modules, wallet signing/keymap APIs, `Wallet::policies` and `TxBuilder::policy_path`. Sign with `Psbt::sign`; see the `signing_checks` example.

Before submitting

@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.10345% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.70%. Comparing base (f6f45f4) to head (2cb97ef).

Files with missing lines Patch % Lines
src/wallet/tx_builder.rs 91.37% 5 Missing ⚠️
src/wallet/error.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #647      +/-   ##
==========================================
- Coverage   82.04%   81.70%   -0.34%     
==========================================
  Files          25       23       -2     
  Lines        6310     5056    -1254     
  Branches      308      217      -91     
==========================================
- Hits         5177     4131    -1046     
+ Misses       1030      852     -178     
+ Partials      103       73      -30     
Flag Coverage Δ
rust 81.70% <93.10%> (-0.34%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@noahjoeris noahjoeris moved this from Triage to In Progress in BDK Wallet Nov 10, 2026
@noahjoeris
noahjoeris marked this pull request as ready for review November 12, 2026 20:07
@noahjoeris
noahjoeris requested a review from a team as a code owner November 12, 2026 20:07
@noahjoeris noahjoeris moved this from In Progress to Needs Review in BDK Wallet Nov 12, 2026
@notmandatory

Copy link
Copy Markdown
Contributor

cACK thanks for getting this started!

@noahjoeris
noahjoeris force-pushed the signer-removal branch 2 times, most recently from 2cb132d to 38bb925 Compare November 18, 2026 08:33
@muhahahmad68

Copy link
Copy Markdown
Contributor

Could timelock_condition get a test where it returns None in tx_builder? Also, the Display impl for MixedTimelockUnits is never exercised, test_condition_merge_mixed* only return Err not its message, we can add a small test which would also cover the matching CreateTxError::MixedTimelockUnits in error.rs.

check_sighashes uses one allow list for every input, so an ECDSA input with SIGHASH_DEFAULT (0x00) passes it. I checked: Psbt::sign then rejects it with InvalidSighashType, so nothing unsafe is signed, but the check is looser than the old allow_all_sighashes: false (which returned NonStandardSighash per input context, see #476). Could the example make the check context-aware, or note the difference in its docs? Also, if one input fails in Psbt::sign, are the other inputs still signed?

@KHADEVS

KHADEVS commented Nov 18, 2026

Copy link
Copy Markdown

if one input fails in Psbt::sign, are the other inputs still signed?

Yes. In bitcoin 0.32.102, Psbt::sign goes through every input, writes each signature it can make into the PSBT, and only then returns Err((used, errors)), with the inputs it did sign in used. I checked with a two-input PSBT whose second input asks for sighash 0x00: check_sighashes lets it through, Psbt::sign signs input 0 and fails input 1 with InvalidSighashType, and the PSBT it leaves behind holds input 0's signature. That signature is SIGHASH_ALL over the reviewed transaction, so nothing is lost here, but the example could say that after an Err the PSBT may still carry signatures and should be dropped, not passed on. 3.2.0's Wallet::sign does the same today (it returns NonStandardSighash after signing input 0), which is #519.

I also ran the adversarial PSBTs in https://github.com/KHADEVS/bitcoin-signer-cases through three setups: 3.2.0's Wallet::sign, Psbt::sign on its own, and Psbt::sign after check_prevouts and check_sighashes from this PR, copied unchanged. With the two checks, the results match Wallet::sign on all 19 cases. Without them, Psbt::sign signs a legacy input sent without its previous transaction (the fee shown is 10,000 sats, the real one 4,010,000), two segwit v0 inputs with nothing proving their amounts, and inputs asking for SIGHASH_NONE and SINGLE|ANYONECANPAY. The table is in results/MATRIX.md.

Since every wallet that moves to Psbt::sign needs these exact checks, would it make sense to ship them as public functions, in bdk_wallet::psbt for instance, rather than as an example to copy? A wallet that never sees the example gets no warning from the compiler.

@noahjoeris

Copy link
Copy Markdown
Contributor Author

@muhahahmad68 Thanks, I added more timelock_condition tests.

  • Sighash check: This matches the pre-check on master: 0x00 passes there too, and signing rejects it
  • Partial signing on error: That's intended Psbt::sign behavior, and sign_with_signers also left earlier signatures in the PSBT

@notmandatory notmandatory added the api A breaking API change label Nov 19, 2026
@noahjoeris

Copy link
Copy Markdown
Contributor Author

Since every wallet that moves to Psbt::sign needs these exact checks, would it make sense to ship them as public functions

In one of our last calls we decided against that. Because upcoming versions of rust-psbt will cover the SignOptions.

@nymius nymius left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cACK 54bee8d

I'm not sure how fast this will the example evolve once we have rust-psbt, but it's good to set an intermediate milestone like this one.

Comment thread src/wallet/tx_builder.rs Resolved
Comment thread src/wallet/mod.rs Resolved
@noahjoeris

Copy link
Copy Markdown
Contributor Author

Thanks for the review @nymius. I addressed your comments.

@yanfsb yanfsb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tACK bc322f6

Tested on regtest against master with bitcoind v28.1 across wpkh, taproot, multisig, CSV/CLTV, and an or_d timelock descriptor. Sequences, locktimes, mempool checks, and confirmations all matched master :).

I think it would help to link examples/signing_checks.rs from the electrum, esplora, and fee-bump examples, since those call Psbt::sign directly without mentioning the prevout/sighash checks, maybe.

@nymius nymius left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A final pass with the clanker flagged me the following:

tests/wallet.rs:1063: fn test_create_tx_policy_path_required() — policy_path no longer exists. The test itself is still valid: it asserts builder.finish() fails with SpendingPolicyRequired(External)

@notmandatory notmandatory left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK bc322f6

Looks good, well organized and rips out all the old signing code.

As @noahjoeris noted in the PR description some things still need to be documented and deprecated in the 3.x branch and a future 3.x release. I asked my LLM to help lay out what the TODOs are and it found:

sign_with_signers gap: 3.x deprecation messages say "use Wallet::sign_with_signers with caller-owned SignersContainers." Both sign_with_signers and SignersContainer are removed un-deprecated. If 3.x is meant to guide users off the old API, sign_with_signers and the signer module need deprecations that point to bitcoin::Psbt::sign + wallet.secp_ctx() instead.

…licy paths

When no condition is set via `TxBuilder::set_condition`, `create_tx` now lifts
each keychain's descriptor and applies the default spending-policy rule. If the
timelocks are ambiguous, it returns `SpendingPolicyRequired`.

Remove the deprecated `Wallet::policies` and `TxBuilder::policy_path`.
Drop `signers` and `change_signers` from `Wallet`, discard extracted
secret keys when creating or loading a wallet, and remove the deprecated
`Wallet::sign`, `Wallet::add_signer`, `Wallet::set_keymap`,
`Wallet::set_keymaps`, `Wallet::get_signers`, `CreateParams::keymap`,
`LoadParams::keymap`, and `LoadParams::extract_keys` methods.
Remove `signer.rs`, `Wallet::sign_with_signers`, `SignOptions`, `SignerError`
and their re-exports. Sign PSBTs with `bitcoin::Psbt::sign`.

`Wallet::finalize_psbt` no longer takes `SignOptions` and returns
`IndexOutOfBoundsError` instead of `SignerError`.
@noahjoeris

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews.

  • I pointed to the signing_checks example from the changelog notice.
  • I renamed test_create_tx_policy_path_required to test_create_tx_condition_required.
  • I marked CreateTxError as #[non_exhaustive], since this PR already breaks it.

@notmandatory notmandatory left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

reACK 4ad4917

Adding #[non_exhaustive] on CreateTxError makes sense for this and other Err enums.

@nymius

nymius commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

reACK 4ad4917

Adding #[non_exhaustive] on CreateTxError makes sense for this and other Err enums.

I've mentioned this before in another PR, but we should check if is not convenient for us to do the same for all errors, as rust-bitcoin is doing

@nymius nymius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK 2cb97ef

@noahjoeris
noahjoeris merged commit a34ca30 into bitcoindevkit:master Dec 2, 2026
14 of 15 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in BDK Wallet Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api A breaking API change

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FLAGSHIP FEATURE] Remove signers from Wallet

6 participants