Skip to content

refactor(wallet)!: remove signers and it's APIs, relying on rust-bitcoin's Psbt::sign instead. #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

oleonardolima
Copy link
Contributor

@oleonardolima oleonardolima commented May 19, 2025

fixes #70

Description

It's a work in progress to remove signers from Wallet and all related APIs. Users should use their own signer implementation, which needs to implement the GetKey trait from rust-bitcoin in order to rely on the Psbt::sign method.

Adds a reference implementation of a new SignerWrapper type as a test utility, which is currently being used on existing tests, instead of Wallet::sign.

Notes to the reviewers

Changelog notice

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@oleonardolima oleonardolima self-assigned this May 19, 2025
@oleonardolima oleonardolima added help wanted Extra attention is needed api A breaking API change labels May 19, 2025
@notmandatory notmandatory moved this to In Progress in BDK Wallet May 20, 2025
@oleonardolima oleonardolima added this to the Wallet 3.0.0 milestone May 27, 2025
@oleonardolima oleonardolima force-pushed the refactor/remove-signers branch from 6249eac to b819375 Compare May 30, 2025 14:46
@luisschwab luisschwab self-requested a review June 1, 2025 18:51
@oleonardolima oleonardolima force-pushed the refactor/remove-signers branch 2 times, most recently from 5eccb29 to e8d9c17 Compare June 2, 2025 17:57
@oleonardolima oleonardolima force-pushed the refactor/remove-signers branch 6 times, most recently from d41948b to 6b60d04 Compare June 3, 2025 14:04
@coveralls
Copy link

coveralls commented Jun 3, 2025

Pull Request Test Coverage Report for Build 15396776489

Details

  • 99 of 120 (82.5%) changed or added relevant lines in 3 files are covered.
  • 329 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-1.0%) to 84.584%

Changes Missing Coverage Covered Lines Changed/Added Lines %
wallet/src/wallet/mod.rs 7 12 58.33%
wallet/src/test_utils.rs 73 89 82.02%
Files with Coverage Reduction New Missed Lines %
wallet/src/test_utils.rs 1 93.9%
wallet/src/wallet/export.rs 8 93.51%
wallet/src/wallet/signer.rs 93 68.39%
wallet/src/wallet/mod.rs 227 80.63%
Totals Coverage Status
Change from base Build 15311776581: -1.0%
Covered Lines: 7369
Relevant Lines: 8712

💛 - Coveralls

- bump the `bitcoin` dependency to latest `0.32.6`.
- this bump is required, in order to use the latest implementation and
  support of `GetKey` implementation for new `KeyRequest::XOnlyPubKey`
when signing tr transactions.
- adds a new `SignerWrapper` for `KeyMap` as a test utility, with new
  methods: `get_wallet_signer` and `get_wallet_signer_single`.
- adds an implementation of `GetKey` trait for `SignerWrapper`, in order to
  retrieve the private key for software signers, and successfully use
`Psbt::sign` method.
- the new methods added are necessary, in order to update the existing
  tests and examples to use `Psbt::sign` instead of `Wallet::sign`, as
it further allows the signing APIs and related types to be fully
removed.
- updates the existing tests which use `Wallet::sign` API, to get the
  signer implementation with: `get_wallet_signer_single` or
`get_wallet_signer`.
- FIXME: there are two tests which requires further refactoring,
  discussion and update, being: `test_psbt_sign_with_finalized` and
`test_psbt_multiple_internalkey_signers`.
- updates `example_wallet_{electrum|esplora}` examples to use the
  `SignerWrapper` implementation from test utilities through
`test-utils` feature.
- update examples to parse the used descriptors into a `KeyMap`, and
  using `SignerWrapper` to sign the transaction with `Psbt::sign`
method, it still uses the `Wallet::finalize_psbt` though.
- updates the existing tests that uses the `Wallet::sign` API, to gethe
  signer implementation from test utilities, either:
`get_wallet_signer_single` or `get_wallet_signer`.
- there are a few tests which needs further refactoring, as they rely on
  the use of `Wallet::finalize_psbt`.
- use default empty `SignersContainer::new()` on both wallet
  `create_with_params` and `load_with_params`.
- remove `add_signer`, `set_keymap` and `get_signers` methods.
- updates `FullyNodedExport::export_wallet` to export public descriptors
  only, and updates it's tests accordingly.
- remove test assertions for signers/keymaps creation/load.
- remove both fields `signers` and `change_signers` from `Wallet`.
- all usage of signers for `extract_policy` fns in `create_tx` and
  `policies` methods now rely on the `SignersContainer::default()`.
@oleonardolima oleonardolima force-pushed the refactor/remove-signers branch from 6b60d04 to 399ad6f Compare June 4, 2025 12:55
@oleonardolima oleonardolima changed the title wip(refactor(wallet))!: remove signers and it's APIs, relying on rust-bitcoin's Psbt::sign instead. refactor(wallet)!: remove signers and it's APIs, relying on rust-bitcoin's Psbt::sign instead. Jun 4, 2025
@thunderbiscuit
Copy link
Member

It's funny I was looking at the diff here when I got the notification that you had requested a review! I was like how does he know I'm looking at the files right now??? haha.

Concept ACK. The Wallet type is so much, but signing the PSBTs is really something separate. Added bonus this signing workflow actually already exists and makes sense as part of the rust-bitcoin ecosystem. Let's go!

My only comment is that because this is breaking, even once it's all good to go you might end up having to keep it fresh and rebase for a while because we might not be ready to merge breaking/3.0 features on master before mid-August (as per previous discussions, but that could change of course).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change help wanted Extra attention is needed
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Remove signers from bdk_wallet
3 participants