Skip to content

Conversation

oleonardolima
Copy link

fixes #709

Description

I've built upon Tobin's work in #765 (see #765 (comment)) to implement the GetKey trait for KeyMap, a feature that will enable us to entirely remove the signers API from bdk_wallet, see: bitcoindevkit/bdk_wallet#70 and bitcoindevkit/bdk_wallet#235.

Notes to the reviewers

I followed some of Poelstra's previous comments to reduce the number of required matching branches, and also some VM's suggestions on implementing the main GetKey logic for DescriptorSecretKey instead.

Let me know if you have any other suggestions or comments.

Changelog notice

# Added:
 - implemented `GetKey` trait for `KeyMap`
 - implemented `GetKey` trait for `DescriptorSecretKey`

# Changed
 - moved `KeyMap` to it's own `key_map` module, replacing the `BTreeMap` alias.

@tcharding
Copy link
Member

Mad, thanks man. I'm off travelling this week but can help review this when I get a chance if needed. I don't do many reviews in miniscript in general.

@apoelstra
Copy link
Member

In 255a61e:

You need to update Cargo-minimal.lock and Cargo-recent.lock to require bitcoin 0.32.6 since the KeyRequest enum was smaller in 0.32.5 and before.

Relatedly, your unreachable! branch is not actually unreachable. It will be hit by any additions to the KeyRequest enum in the future.

oleonardolima and others added 2 commits August 28, 2025 10:56
- it's required in order to have all the added variants for `KeyRequest`
  type.
- creates a new `key_map` module, and `KeyMap` type to replace the
  existing `BTreeMap` alias.
- it's a commit extracted from superseded PR rust-bitcoin#765.
@oleonardolima oleonardolima force-pushed the feat/impl-getkey-for-keymap branch 2 times, most recently from 5224964 to acc2d04 Compare August 28, 2025 13:57
- add the implementation of GetKey for `KeyMap`, and also implements it
  for the inner type `DescriptorSecretKey` in order to make the match
branching and logic clearer.
@oleonardolima oleonardolima force-pushed the feat/impl-getkey-for-keymap branch from acc2d04 to ab69aac Compare August 28, 2025 14:00
@oleonardolima
Copy link
Author

In 255a61e:

You need to update Cargo-minimal.lock and Cargo-recent.lock to require bitcoin 0.32.6 since the KeyRequest enum was smaller in 0.32.5 and before.

Relatedly, your unreachable! branch is not actually unreachable. It will be hit by any additions to the KeyRequest enum in the future.

Thanks, I've added a new commit 8e05d85 specifically for this version bump.

I also updated unreachable! to unimplemented! instead.

@apoelstra
Copy link
Member

I also updated unreachable! to unimplemented! instead.

This is not sufficient. The code should not panic on key accesses.

Comment on lines +321 to +322
let path = DerivationPath::from_str("84'/1'/0'/0").unwrap();
let expected_pk = xpriv.xkey.derive_priv(&secp, &path).unwrap().to_priv();

Choose a reason for hiding this comment

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

Is this the path derived from the master key or from the tpriv shown above?

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.

Implement GetKey for KeyMap
4 participants