@@ -308,7 +308,7 @@ impl FromStr for DescriptorPublicKey {
308
308
309
309
if key_part. contains ( "pub" ) {
310
310
let ( xpub, derivation_path, wildcard) =
311
- DescriptorXKey :: < bip32:: ExtendedPubKey > :: parse_xkey_deriv ( key_part) ?;
311
+ parse_xkey_deriv :: < bip32:: ExtendedPubKey > ( key_part) ?;
312
312
313
313
Ok ( DescriptorPublicKey :: XPub ( DescriptorXKey {
314
314
origin,
@@ -502,7 +502,7 @@ impl FromStr for DescriptorSecretKey {
502
502
} ) )
503
503
} else {
504
504
let ( xprv, derivation_path, wildcard) =
505
- DescriptorXKey :: < bip32:: ExtendedPrivKey > :: parse_xkey_deriv ( key_part) ?;
505
+ parse_xkey_deriv :: < bip32:: ExtendedPrivKey > ( key_part) ?;
506
506
Ok ( DescriptorSecretKey :: XPrv ( DescriptorXKey {
507
507
origin,
508
508
xkey : xprv,
@@ -567,42 +567,42 @@ fn parse_key_origin(s: &str) -> Result<(&str, Option<bip32::KeySource>), Descrip
567
567
}
568
568
}
569
569
570
- impl < K : InnerXKey > DescriptorXKey < K > {
571
- /// Parse an extended key concatenated to a derivation path.
572
- fn parse_xkey_deriv (
573
- key_deriv : & str ,
574
- ) -> Result < ( K , bip32:: DerivationPath , Wildcard ) , DescriptorKeyParseError > {
575
- let mut key_deriv = key_deriv. split ( '/' ) ;
576
- let xkey_str = key_deriv. next ( ) . ok_or ( DescriptorKeyParseError (
577
- "No key found after origin description" ,
578
- ) ) ?;
579
- let xkey = K :: from_str ( xkey_str)
580
- . map_err ( |_| DescriptorKeyParseError ( "Error while parsing xkey." ) ) ?;
581
-
582
- let mut wildcard = Wildcard :: None ;
583
- let derivation_path = key_deriv
584
- . filter_map ( |p| {
585
- if wildcard == Wildcard :: None && p == "*" {
586
- wildcard = Wildcard :: Unhardened ;
587
- None
588
- } else if wildcard == Wildcard :: None && ( p == "*'" || p == "*h" ) {
589
- wildcard = Wildcard :: Hardened ;
590
- None
591
- } else if wildcard != Wildcard :: None {
592
- Some ( Err ( DescriptorKeyParseError (
593
- "'*' may only appear as last element in a derivation path." ,
594
- ) ) )
595
- } else {
596
- Some ( bip32:: ChildNumber :: from_str ( p) . map_err ( |_| {
597
- DescriptorKeyParseError ( "Error while parsing key derivation path" )
598
- } ) )
599
- }
600
- } )
601
- . collect :: < Result < bip32:: DerivationPath , _ > > ( ) ?;
570
+ /// Parse an extended key concatenated to a derivation path.
571
+ fn parse_xkey_deriv < K : InnerXKey > (
572
+ key_deriv : & str ,
573
+ ) -> Result < ( K , bip32:: DerivationPath , Wildcard ) , DescriptorKeyParseError > {
574
+ let mut key_deriv = key_deriv. split ( '/' ) ;
575
+ let xkey_str = key_deriv. next ( ) . ok_or ( DescriptorKeyParseError (
576
+ "No key found after origin description" ,
577
+ ) ) ?;
578
+ let xkey =
579
+ K :: from_str ( xkey_str) . map_err ( |_| DescriptorKeyParseError ( "Error while parsing xkey." ) ) ?;
580
+
581
+ let mut wildcard = Wildcard :: None ;
582
+ let derivation_path = key_deriv
583
+ . filter_map ( |p| {
584
+ if wildcard == Wildcard :: None && p == "*" {
585
+ wildcard = Wildcard :: Unhardened ;
586
+ None
587
+ } else if wildcard == Wildcard :: None && ( p == "*'" || p == "*h" ) {
588
+ wildcard = Wildcard :: Hardened ;
589
+ None
590
+ } else if wildcard != Wildcard :: None {
591
+ Some ( Err ( DescriptorKeyParseError (
592
+ "'*' may only appear as last element in a derivation path." ,
593
+ ) ) )
594
+ } else {
595
+ Some ( bip32:: ChildNumber :: from_str ( p) . map_err ( |_| {
596
+ DescriptorKeyParseError ( "Error while parsing key derivation path" )
597
+ } ) )
598
+ }
599
+ } )
600
+ . collect :: < Result < bip32:: DerivationPath , _ > > ( ) ?;
602
601
603
- Ok ( ( xkey, derivation_path, wildcard) )
604
- }
602
+ Ok ( ( xkey, derivation_path, wildcard) )
603
+ }
605
604
605
+ impl < K : InnerXKey > DescriptorXKey < K > {
606
606
/// Compares this key with a `keysource` and returns the matching derivation path, if any.
607
607
///
608
608
/// For keys that have an origin, the `keysource`'s fingerprint will be compared
0 commit comments