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
- fixes the implementation of `GetKey` for `Xprv` with
`KeyRequest::Bip32` and a key_origin information.
- adds a new test for a scenario where no wildcard is used, and an
specific derivation index is used.
Copy file name to clipboardExpand all lines: src/descriptor/key_map.rs
+54-11Lines changed: 54 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -73,18 +73,28 @@ impl GetKey for DescriptorSecretKey {
73
73
return Ok(Some(key));
74
74
}
75
75
76
-
if let Some(matched_path) = descriptor_xkey.matches(key_source, secp) {
76
+
if descriptor_xkey.matches(key_source, secp).is_some() {
77
77
let (_, full_path) = key_source;
78
78
79
-
let derivation_path = &full_path[matched_path.len()..];
80
-
81
-
return Ok(Some(
82
-
descriptor_xkey
83
-
.xkey
84
-
.derive_priv(secp, &derivation_path)
85
-
.map_err(GetKeyError::Bip32)?
86
-
.to_priv(),
87
-
));
79
+
match &descriptor_xkey.origin {
80
+
Some((_, origin_path)) => {
81
+
let derivation_path = &full_path[origin_path.len()..];
82
+
return Ok(Some(
83
+
descriptor_xkey
84
+
.xkey
85
+
.derive_priv(secp, &derivation_path)?
86
+
.to_priv(),
87
+
));
88
+
}
89
+
None => {
90
+
return Ok(Some(
91
+
descriptor_xkey
92
+
.xkey
93
+
.derive_priv(secp, &full_path)?
94
+
.to_priv(),
95
+
))
96
+
}
97
+
};
88
98
}
89
99
90
100
Ok(None)
@@ -255,7 +265,7 @@ mod tests {
255
265
}
256
266
257
267
#[test]
258
-
fn get_key_xpriv_with_key_origin() {
268
+
fn get_key_xpriv_with_key_origin_and_wildcard() {
259
269
let secp = Secp256k1::new();
260
270
261
271
let descriptor_str = "wpkh([d34db33f/84h/1h/0h]tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)";
let descriptor_str = "wpkh([d34db33f/84h/1h/0h]tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/0)";
305
+
let (_descriptor_pk, keymap) = Descriptor::parse_descriptor(&secp, descriptor_str).unwrap();
306
+
let keymap_wrapper = KeyMapWrapper::from(keymap);
307
+
308
+
let descriptor_sk = DescriptorSecretKey::from_str("[d34db33f/84h/1h/0h]tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/0").unwrap();
0 commit comments