-
Notifications
You must be signed in to change notification settings - Fork 165
feat: implement GetKey
for KeyMap
and DescriptorSecretKey
#851
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
feat: implement GetKey
for KeyMap
and DescriptorSecretKey
#851
Conversation
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 |
In 255a61e: You need to update Cargo-minimal.lock and Cargo-recent.lock to require Relatedly, your |
acc2d04
to
ab69aac
Compare
Thanks, I've added a new commit 8e05d85 specifically for this version bump. I also updated |
This is not sufficient. The code should not panic on key accesses. |
let path = DerivationPath::from_str("84'/1'/0'/0").unwrap(); | ||
let expected_pk = xpriv.xkey.derive_priv(&secp, &path).unwrap().to_priv(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's from the key origin as per the descriptor above. It's curious because I had to port this test from bdk_wallet
specifically because AFAICT it's a scenario that the default KeyRequest::Bip32
implementation can't cover.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused what the expected key is in this case. If path
is to be derived from the origin, don't we only want to derive one additional step from the xkey
?
- 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.
Alright, thanks! I'll follow the standard that it should return I was wondering if a new error variant should be added, but I don't think that's the case. Please let me know if I should proceed in a other way. |
- 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.
ab69aac
to
e2d934e
Compare
CI failure is because the stable compiler broke our CI. I'll fix this separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK e2d934e; successfully ran local tests
You don't need my review on this do you @apoelstra , its a savage context switch. |
Nope! Was just fighting with my local CI setup (had to tweak a bunch of stuff for rust-bitcoin 0.31.x) and forgot to queue the merge here. Thanks for checking though -- I do usually wait for your review on PRs where you've commented. |
I've been wondering about this one, 13.0.0 is pretty far away from releasing, right ? |
Yeah, 13.0 is a bit of a ways away. Backports are welcome. Though this one will be a little tricky because you can't replace the |
…`KeyMap` and `DescriptorSecretKey` e2d934eb9530ffac3a26cb3c822dd5ed9bc29a85 feat: impl `GetKey` for `KeyMap` and `DescriptorSecretKey` (Leonardo Lima) 6f345d75b03d49a1e606d161656067a7f8331cf2 refactor(keymap): create `KeyMap` type (Tobin C. Harding) 131cf01f318fa9ba98c03da8ea9bab62ce7d44eb chore(deps): bump `bitcoin` to `0.32.6` (Leonardo Lima) Pull request description: fixes rust-bitcoin/rust-miniscript#709 ### Description I've built upon Tobin's work in #765 (see rust-bitcoin/rust-miniscript#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 ```md # 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. ``` ACKs for top commit: apoelstra: ACK e2d934eb9530ffac3a26cb3c822dd5ed9bc29a85; successfully ran local tests Tree-SHA512: 85168f3d6de0527d077674ff4e988ecda9f6237ae1c15018a1cfeb5760fa5a14b700b58a9e78d79b15cffba12b3f1e8de3a5e82c0822a0506aa7fa926bf8a7d8
I'm not sure if there is a more elegant way to do it, but introducing a |
- add `KeyMapWrapper` with `GetKey` trait for PSBT signing - implement `GetKey` for `DescriptorSecretKey` - add `From<KeyMap>` conversion - export new `KeyMapWrapper` for downstream crate usage
- add `KeyMapWrapper` with `GetKey` trait for PSBT signing - implement `GetKey` for `DescriptorSecretKey` - add `From<KeyMap>` conversion - export new `KeyMapWrapper` for downstream crate usage
- add `KeyMapWrapper` with `GetKey` trait for PSBT signing - implement `GetKey` for `DescriptorSecretKey` - add `From<KeyMap>` conversion - export new `KeyMapWrapper` for downstream crate usage
- add `KeyMapWrapper` with `GetKey` trait for PSBT signing - implement `GetKey` for `DescriptorSecretKey` - add `From<KeyMap>` conversion - export new `KeyMapWrapper` for downstream crate usage
- add `KeyMapWrapper` with `GetKey` trait for PSBT signing - implement `GetKey` for `DescriptorSecretKey` - add `From<KeyMap>` conversion - export new `KeyMapWrapper` for downstream crate usage
… keys 89b5048 test: extend unit tests to cover KeyMapWrapper error conditions (Andrew Poelstra) 78cddab key_map: handle lookup errors on multipath xprivs correctly (Andrew Poelstra) Pull request description: Since #851 we return a `NotSupported` error when attempting to request an xpriv from an x-only key. I'm not sure if this is the correct semantics, but it was deliberately written, so we'll keep it. **However** the behavior was different for multipath xprivs. There we returned `None`, i.e. "key not found/mismatch" rather than an error. This PR returns an error in both cases. ACKs for top commit: oleonardolima: ACK 89b5048 Tree-SHA512: e59b4d6877374c7e07ddf282422c42b6735f04514d2cc70610dca15dd4153cd372f9a1ccf86d3ce57ea32e8784229de0288a0e1b196405034065d92e5b134f9c
08fa87a test: extend unit tests to cover KeyMapWrapper error conditions (Andrew Poelstra) 5f089aa key_map: handle lookup errors on multipath xprivs correctly (Andrew Poelstra) c7d4171 feat(descriptor): backport `GetKey` impl from #851 (Leonardo Lima) 58d1df9 chore(deps): bump `bitcoin` to `0.32.6` (Leonardo Lima) Pull request description: backports #851 to release/12.x ### Description It's an initial attempt to backport the implementation of GetKey for KeyMap introduced in #851. ### Notes to the reviewers I noticed that the type `KeyMapWrapper` is already being used internally for parse_descriptor, though, as it's not part of the public API, there's no conflict, but I'm fine with changing it to another name if needed. ### Changelog Notice ``` # Added - add `KeyMapWrapper` with `GetKey` trait for PSBT signing - implement `GetKey` for `DescriptorSecretKey` - add `From<KeyMap>` conversion - export new `KeyMapWrapper` for downstream crate usage ``` ACKs for top commit: apoelstra: ACK 08fa87a; successfully ran local tests Tree-SHA512: 73f100f9b851012debdc1c8bb8b89bc76394865c98f315831168978d0c93038932745ff58ceb52d04c02e50e6c5c6073658e16279abb2b10c5b7b6c346f18ed2
fixes #709
Description
I've built upon Tobin's work in #765 (see #765 (comment)) to implement the
GetKey
trait forKeyMap
, a feature that will enable us to entirely remove the signers API frombdk_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 forDescriptorSecretKey
instead.Let me know if you have any other suggestions or comments.
Changelog notice