Skip to content
This repository was archived by the owner on Oct 22, 2026. It is now read-only.

fix(keymap): backport use of correct derivation_path for keys with origin - #867

Merged
apoelstra merged 2 commits into
rust-bitcoin:release-12.xfrom
oleonardolima:backport-863-to-12.x
Jul 3, 2026
Merged

apoelstra merged 2 commits into
rust-bitcoin:release-12.xfrom
oleonardolima:backport-863-to-12.x

Conversation

@oleonardolima

@oleonardolima oleonardolima commented Oct 17, 2025 •

Copy link
Copy Markdown
Contributor

backports #872

Description

It backports the fix for deriving the private key correctly in scenarios where the key origin is available, see #872.

The GetKey for DescriptorSecretKey (and thus KeyMap) returned the wrong key when an extended private key with key origin info was queried via KeyRequest::Bip32.

The key request path is master-relative, but the xkey is anchored at its origin (e.g. [d34db33f/84h/1h/0h]). The old code stripped the path returned by matches(); the fix strips the origin prefix instead (and uses the full path when there is no origin) before deriving from the xkey.

cherry-picks 20ae466 and a2f4497.

Changelog notice

### Fixed
- keymap: fix `GetKey` derivation path for `Xprv` with key origin info [#872](https://github.com/rust-bitcoin/rust-miniscript/pull/872)

Checklists

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

@tcharding

Copy link
Copy Markdown
Member

Do you want review mate? Why's it draft?

@oleonardolima
oleonardolima marked this pull request as ready for review October 18, 2025 21:19
@oleonardolima

Copy link
Copy Markdown
Contributor Author

Do you want review mate? Why's it draft?

Yeah, I was just waiting for CI, it should be ready to go.

@tcharding tcharding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK 10fd701

@oleonardolima

Copy link
Copy Markdown
Contributor Author

I'll move this one back to draft while I fix the issue mentioned at the summit, and backport all the fixes at once.

@notmandatory

Copy link
Copy Markdown
Contributor

@oleonardolima just a ping, can this be updated and made ready to review now?

@oleonardolima

Copy link
Copy Markdown
Contributor Author

@oleonardolima just a ping, can this be updated and made ready to review now?

I'll rebase it and get it ready for review today.

@oleonardolima

Copy link
Copy Markdown
Contributor Author

@oleonardolima just a ping, can this be updated and made ready to review now?

@notmandatory I updated the original fix in #872 (also needs review), I'm backporting it here now.

@oleonardolima
oleonardolima force-pushed the backport-863-to-12.x branch 2 times, most recently from f3d1b63 to 3f77767 Compare June 16, 2026 21:29
@oleonardolima
oleonardolima marked this pull request as ready for review June 16, 2026 21:45
@oleonardolima

Copy link
Copy Markdown
Contributor Author

@oleonardolima just a ping, can this be updated and made ready to review now?

@notmandatory I updated the original fix in #872 (also needs review), I'm backporting it here now.

I updated this PR and added new test scenarios, it should be ready to review.

cc'in @noahjoeris as you had interest in this and a review would be appreciated.

@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 3f77767

Accurately back ports #872, should be good to go after that one is merged.

@noahjoeris noahjoeris 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 3f77767

@oleonardolima

Copy link
Copy Markdown
Contributor Author

ping @tcharding @apoelstra for awareness.

@oleonardolima

Copy link
Copy Markdown
Contributor Author

@apoelstra thanks for the quick review in #872, let me know if I need to do any update here in the backport.

@apoelstra

Copy link
Copy Markdown
Member

Sorry, the problem is on my end. My local CI is not passing on the 12.x branch and I need to investigate why.

@apoelstra

Copy link
Copy Markdown
Member

Oh, no, the problem is on your end :). In 122105d your original test does not compile:

error[E0599]: no method named `get_key` found for struct `std::collections::BTreeMap<K, V, A>` in the current scope
   --> src/descriptor/key_map.rs:316:14
    |
315 |           let pk = keymap
    |  __________________-
316 | |             .get_key(key_request, &secp)
    | |_____________-^^^^^^^
    |
help: there is a method `get_key_value` with a similar name, but with different arguments
   --> /rustc/ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96/library/alloc/src/collections/btree/map.rs:783:4
    = note: the full name for the type has been written to 'target/lib/miniscript-779a623562.long-type-17215175838718595439.txt'
    = note: consider using `--verbose` to print the full type name to the console

In this project we require that all commits compile and pass unit tests.

Sorry again for the long delay on my part! I had some weird NixOS issues all week and had assumed that the failure here was part of that.

- backports rust-bitcoin#872 fixes for the implementation of `GetKey` for `Xprv` with
  `KeyRequest::Bip32`, when the the key_origin information is available.
- backports introduced rust-bitcoin#872 table-driven test cases for
  `get_key_xpriv_with_key_origin` with named fields
- drop redundant key parsing, and build requests from explicit
  key sources

Assisted-by: Claude Opus 4.8
@oleonardolima
oleonardolima force-pushed the backport-863-to-12.x branch from 3f77767 to d01ee72 Compare July 1, 2026 14:58
@oleonardolima

Copy link
Copy Markdown
Contributor Author

Oh, no, the problem is on your end :). In 122105d your original test does not compile:

error[E0599]: no method named `get_key` found for struct `std::collections::BTreeMap<K, V, A>` in the current scope
   --> src/descriptor/key_map.rs:316:14
    |
315 |           let pk = keymap
    |  __________________-
316 | |             .get_key(key_request, &secp)
    | |_____________-^^^^^^^
    |
help: there is a method `get_key_value` with a similar name, but with different arguments
   --> /rustc/ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96/library/alloc/src/collections/btree/map.rs:783:4
    = note: the full name for the type has been written to 'target/lib/miniscript-779a623562.long-type-17215175838718595439.txt'
    = note: consider using `--verbose` to print the full type name to the console

In this project we require that all commits compile and pass unit tests.

Sorry again for the long delay on my part! I had some weird NixOS issues all week and had assumed that the failure here was part of that.

Oh, sorry for the oversight!

I updated the first commit 1053799 to drop the broken and newly added test as it was being refactored in the second one d01ee72.

Let me know if there's anything else to address.

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK d01ee72; successfully ran local tests

@apoelstra
apoelstra merged commit 78cb727 into rust-bitcoin:release-12.x Jul 3, 2026
13 checks passed
@oleonardolima
oleonardolima deleted the backport-863-to-12.x branch July 3, 2026 17:08
ValuedMammal added a commit to bitcoindevkit/bdk_wallet that referenced this pull request Aug 21, 2026
3a3cd6f deprecate(wallet): wallet-owned signer and policy APIs (Noah Joeris)
6b7a8b2 feat(wallet): add TxBuilder::set_condition (Noah Joeris)
7031448 refactor(wallet): migrate signing to caller-owned keys (Noah Joeris)

Pull request description:

  ### Description

  Partially addresses #70

  Deprecates wallet-owned signing APIs, migrating examples, tests, and documentation toward caller-owned keys using `bitcoin::Psbt::sign` and `Wallet::sign_with_signers`.

  Depends on:

  - rust-bitcoin/rust-miniscript#872
  - rust-bitcoin/rust-miniscript#867

  ### Notes to the reviewers

  - I migrated examples, docs and tests to use `bitcoin::Psbt::sign` where possible. And used `Wallet::sign_with_signers` if we need SignOptions.

  ### Changelog notice

  ```
  - Deprecated `Wallet::{add_signer, set_keymap, set_keymaps, get_signers, sign, policies}`, `CreateParams::keymap`, `LoadParams::{keymap, extract_keys}`, and `TxBuilder::policy_path` in favor of caller-owned keys with `bitcoin::Psbt::sign` / `Wallet::sign_with_signers`, and `TxBuilder::set_condition`.
  - Changed `FullyNodedExport::export_wallet` to not export secret keys anymore.
  - Added `TxBuilder::set_condition` as replacement for `TxBuilder::policy_path`.
  ```

  ### Before submitting

  - [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk_wallet/blob/master/CONTRIBUTING.md)
  - [ ] This PR breaks the existing API

ACKs for top commit:
  ValuedMammal:
    reACK 3a3cd6f
  110CodingP:
    ACK 3a3cd6f

Tree-SHA512: 690039f597d2aab334f6ac8f4623a49c4df9470af8978adbdad8d2061f2fd2582122943e11cec2b5be21a296ef12f9d80113f99e1bf87876aa6b58805fe8ca76
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants