Skip to content

GetKey for KeyMapWrapper misses account-xprv path #610

Closed

Description

@ItoroD

Description

We have a number of examples and test in bdk-wallet that use;

 let signer = KeyMapWrapper::from(keymap);

as the signer for a psbt.sign. In the case where you give a descriptor that has an account level xprv key, and its corresponding psbt, it seems the getkey implementation of KeyMapWrapper from mininscript derives the key at the wrong path. For example;

const PSBT_B64: &str = "cHNidP8BAF4CAAAAAU1jsXk14vinaw/FavxEf6I13DTTWcQ3W3qfEO45TulmAAAAAAD/////ASgjAAAAAAAAIlEgXnzxN1lKw2Se0nelATBRTNfinxJWqjQNKLqvwkspeREAAAAAAAEBKxAnAAAAAAAAIlEgXnzxN1lKw2Se0nelATBRTNfinxJWqjQNKLqvwkspeREhFtXKImYR1dqFkU+0ktlTKKLzI4vHT1o4Ukyt7xYanJ5zGQBRWcFzVgAAgAEAAIAAAACAAAAAAAAAAAABFyDVyiJmEdXahZFPtJLZUyii8yOLx09aOFJMre8WGpyecwAA";
const DESCRIPTOR: &str = "tr([5159c173/86h/1h/0h]tprv8gfBCLYgHZLJLhg1DUSY6NN6eNAee3aqt3SE3M1hywpAiFWYGsm6U6B17VDKh8W1SQnatRpZujU5xseJ84nYZmkxPGCngNhmBMVRY2sAZhY/0/*)";

Given the above, with KeyMapWrapper getkey implementation of getkey, the psbt will get signed but when you try to finalize it will fail because the signature is wrong and not what was expected on verification.
I tried the bdk_tx signer with the same constants above and this worked successfully. The problem seems to be that getkey for keymapwrapper is unaware that we have already walked 86h/1h/0h according to the descriptor given and then adds the full path again to derive the key. So

86h/1h/0h/86h/1h/0h/0/0 ❌

instead of

86h/1h/0h/0/0 ✅

This is not exactly a bdk-wallet error but more of a miniscript one. This was pointed out in bdk-ffi by @j-kon on the psbt.sign PR instead of bindings exposing KeyMapWrapper, it might be better to expose bdk_tx::Signer and use that for all getkey operations. Lastly, I noticed rust-miniscript has made some changes to their getkey implementation in latest releases (maybe bdk-wallet needs to bump the version). What I have not tested is if that now handles for account-xprv descriptors.

Activity

  1. j-kon commented on Oct 27, 2026

    @j-kon

    Thanks for opening this issue, @ItoroD.

    This matches what I found while reviewing the PSBT signing changes in bdk-ffi #1051.

    I noticed that rust-miniscript already addressed the origin-path derivation issue in #872, with a backport to 12.x in #867.

    It would be worth testing the same PSBT against that backport to confirm whether it resolves the problem before introducing another fix in bdk-wallet.

    I’ll look into reproducing this and checking whether a dependency update is enough.

  2. ItoroD commented on Oct 27, 2026

    @ItoroD
    Author

    3. Thanks for opening this issue, @ItoroD.
    This matches what I found while reviewing the PSBT signing changes in bdk-ffi #1051.
    I noticed that rust-miniscript already addressed the origin-path derivation issue in #872, with a backport to 12.x in #867.
    It would be worth testing the same PSBT against that backport to confirm whether it resolves the problem before introducing another fix in bdk-wallet.
    I’ll look into reproducing this and checking whether a dependency update is enough.

    Oh ok! Seems the links you have added are not clickable.

    Yes, I am also expecting just an update to right version to resolve this.

  3. noahjoeris commented on Oct 27, 2026

    @noahjoeris
    Contributor

    Yes we still wait for a release of it. I have a PR open for it here
    https://git.rust-bitcoin.org/rust-bitcoin/rust-miniscript/pulls/1035

  4. added this to the Wallet 3.3.0 milestone on Oct 27, 2026
  5. j-kon commented on Oct 27, 2026

    @j-kon

    Thanks for the update, @ItoroD and @noahjoeris.

    Good to see the fix is already included in the upcoming rust-miniscript 12.3.8 release.

    I’ll test the account-level xprv case against the updated code to confirm signing and finalization work as expected.

    Once verified and released, we should be able to resolve this with a dependency update in bdk-wallet.

    Thanks for pointing me to rust-miniscript PR #1035

  6. moved this from Triage to In Progress in BDK Walleton Oct 29, 2026
  7. noahjoeris commented on Oct 29, 2026

    @noahjoeris
    Contributor

    fix was released. I opened a PR

  8. moved this from In Progress to Done in BDK Walleton Oct 29, 2026
  9. added a commit that references this issue on Oct 29, 2026
    e710fff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions