You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge #872: fix(key_map): derivation_path for Xprv with key origin info
a2f4497 test(key_map): improve `Xprv` key origin tests (Leonardo Lima)
20ae466 fix(key_map): derivation_path for `Xprv` with key origin info (Leonardo Lima)
Pull request description:
### Description
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`.
--
Also, this PR introduces the test `get_key_xpriv_with_key_origin` covering the scenarios: bare wildcard; single fixed step; fixed step then wildcard, and the matching/non-matching cases build requests from explicit `(fingerprint, path)` key sources.
### Notes
If you'd like an overview on the issue, see: #863 (comment)
### Changelog notice
```
### Fixed
- keymap: fix `GetKey` derivation path for `Xprv` with key origin info [#872](#872)
```
### Checklists
#### Bugfixes:
* [ ] This pull request breaks the existing API
* [x] I've added tests to reproduce the issue which are now passing
* [ ] I'm linking the issue being fixed by this PR
ACKs for top commit:
notmandatory:
ACK a2f4497
noahjoeris:
tACK a2f4497
apoelstra:
ACK a2f4497; successfully ran local tests
Tree-SHA512: 7980e4cfccc8b0b53a054350dd7870122192407c4e17c36f75350093d7be63d4a5e75be40f4e4583c1a1cf0641a469d55842b7108e8bce6e8aa44f519e51b963
@@ -168,7 +174,7 @@ impl GetKey for DescriptorSecretKey {
168
174
mod tests {
169
175
use core::str::FromStr;
170
176
171
-
use bitcoin::bip32::{ChildNumber,DerivationPath,IntoDerivationPath,Xpriv};
177
+
use bitcoin::bip32::{ChildNumber,DerivationPath,Fingerprint,IntoDerivationPath,Xpriv};
172
178
173
179
usesuper::*;
174
180
usecrate::Descriptor;
@@ -305,38 +311,6 @@ mod tests {
305
311
assert_eq!(got_sk, want_sk)
306
312
}
307
313
308
-
#[test]
309
-
fnget_key_xpriv_with_key_origin(){
310
-
let secp = Secp256k1::new();
311
-
312
-
let descriptor_str = "wpkh([d34db33f/84h/1h/0h]tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)";
let descriptor_sk = DescriptorSecretKey::from_str("[d34db33f/84h/1h/0h]tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*").unwrap();
let xpriv = Xpriv::from_str("tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS").unwrap();
// descriptor with a fixed derivation index of `0`.
463
+
let descriptor = "wpkh([d34db33f/84h/1h/0h]tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/0)";
0 commit comments