@@ -804,80 +804,18 @@ impl DescriptorKey for DescriptorMultiExtendedPublicKey {
804
804
}
805
805
806
806
impl DescriptorPublicKey {
807
- /// The fingerprint of the master key associated with this key, `0x00000000` if none.
808
- pub fn master_fingerprint ( & self ) -> bip32:: Fingerprint {
809
- match * self {
810
- DescriptorPublicKey :: XPub ( ref xpub) => xpub. master_fingerprint ( ) ,
811
- DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. master_fingerprint ( ) ,
812
- DescriptorPublicKey :: Single ( ref single) => single. master_fingerprint ( ) ,
813
- }
814
- }
815
-
816
- /// Full path, from the master key
817
- ///
818
- /// For wildcard keys this will return the path up to the wildcard, so you
819
- /// can get full paths by appending one additional derivation step, according
820
- /// to the wildcard type (hardened or normal).
821
- ///
822
- /// For multipath extended keys, this returns `None`.
823
- pub fn full_derivation_path ( & self ) -> Option < bip32:: DerivationPath > {
824
- match * self {
825
- DescriptorPublicKey :: XPub ( ref xpub) => xpub. full_derivation_path ( ) ,
826
- DescriptorPublicKey :: Single ( ref single) => single. full_derivation_path ( ) ,
827
- DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. full_derivation_path ( ) ,
828
- }
829
- }
830
-
831
807
/// Whether or not the key has a wildcard
832
808
#[ deprecated( note = "use has_wildcard instead" ) ]
833
809
pub fn is_deriveable ( & self ) -> bool {
834
810
self . has_wildcard ( )
835
811
}
836
812
837
- /// Whether or not the key has a wildcard
838
- pub fn has_wildcard ( & self ) -> bool {
839
- match * self {
840
- DescriptorPublicKey :: Single ( ref single) => single. has_wildcard ( ) ,
841
- DescriptorPublicKey :: XPub ( ref xpub) => xpub. has_wildcard ( ) ,
842
- DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. has_wildcard ( ) ,
843
- }
844
- }
845
-
846
813
#[ deprecated( note = "use at_derivation_index instead" ) ]
847
814
/// Deprecated name for [`Self::at_derivation_index`].
848
815
pub fn derive ( self , index : u32 ) -> Result < DefiniteDescriptorKey , ConversionError > {
849
816
self . at_derivation_index ( index)
850
817
}
851
818
852
- /// Replaces any wildcard (i.e. `/*`) in the key with a particular derivation index, turning it into a
853
- /// *definite* key (i.e. one where all the derivation paths are set).
854
- ///
855
- /// # Returns
856
- ///
857
- /// - If this key is not an xpub, returns `self`.
858
- /// - If this key is an xpub but does not have a wildcard, returns `self`.
859
- /// - Otherwise, returns the xpub at derivation `index` (removing the wildcard).
860
- ///
861
- /// # Errors
862
- ///
863
- /// - If `index` is hardened.
864
- pub fn at_derivation_index ( self , index : u32 ) -> Result < DefiniteDescriptorKey , ConversionError > {
865
- match self {
866
- DescriptorPublicKey :: Single ( single) => single. at_derivation_index ( index) ,
867
- DescriptorPublicKey :: XPub ( xpub) => xpub. at_derivation_index ( index) ,
868
- DescriptorPublicKey :: MultiXPub ( xpub) => xpub. at_derivation_index ( index) ,
869
- }
870
- }
871
-
872
- /// Whether or not this key has multiple derivation paths.
873
- pub fn is_multipath ( & self ) -> bool {
874
- match self {
875
- DescriptorPublicKey :: Single ( single) => single. is_multipath ( ) ,
876
- DescriptorPublicKey :: XPub ( xpub) => xpub. is_multipath ( ) ,
877
- DescriptorPublicKey :: MultiXPub ( xpub) => xpub. is_multipath ( ) ,
878
- }
879
- }
880
-
881
819
/// Get as many keys as derivation paths in this key.
882
820
///
883
821
/// For raw public key and single-path extended keys it will return the key itself.
@@ -910,6 +848,59 @@ impl DescriptorPublicKey {
910
848
}
911
849
}
912
850
851
+ impl DescriptorKey for DescriptorPublicKey {
852
+ fn master_fingerprint ( & self ) -> bip32:: Fingerprint {
853
+ match * self {
854
+ DescriptorPublicKey :: XPub ( ref xpub) => xpub. master_fingerprint ( ) ,
855
+ DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. master_fingerprint ( ) ,
856
+ DescriptorPublicKey :: Single ( ref single) => single. master_fingerprint ( ) ,
857
+ }
858
+ }
859
+
860
+ fn full_derivation_path ( & self ) -> Option < bip32:: DerivationPath > {
861
+ match * self {
862
+ DescriptorPublicKey :: XPub ( ref xpub) => xpub. full_derivation_path ( ) ,
863
+ DescriptorPublicKey :: Single ( ref single) => single. full_derivation_path ( ) ,
864
+ DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. full_derivation_path ( ) ,
865
+ }
866
+ }
867
+
868
+ fn has_wildcard ( & self ) -> bool {
869
+ match * self {
870
+ DescriptorPublicKey :: Single ( ref single) => single. has_wildcard ( ) ,
871
+ DescriptorPublicKey :: XPub ( ref xpub) => xpub. has_wildcard ( ) ,
872
+ DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. has_wildcard ( ) ,
873
+ }
874
+ }
875
+
876
+ fn at_derivation_index ( self , index : u32 ) -> Result < DefiniteDescriptorKey , ConversionError > {
877
+ match self {
878
+ DescriptorPublicKey :: Single ( single) => single. at_derivation_index ( index) ,
879
+ DescriptorPublicKey :: XPub ( xpub) => xpub. at_derivation_index ( index) ,
880
+ DescriptorPublicKey :: MultiXPub ( xpub) => xpub. at_derivation_index ( index) ,
881
+ }
882
+ }
883
+
884
+ fn is_multipath ( & self ) -> bool {
885
+ match self {
886
+ DescriptorPublicKey :: Single ( single) => single. is_multipath ( ) ,
887
+ DescriptorPublicKey :: XPub ( xpub) => xpub. is_multipath ( ) ,
888
+ DescriptorPublicKey :: MultiXPub ( xpub) => xpub. is_multipath ( ) ,
889
+ }
890
+ }
891
+
892
+ fn derive_public_key < C : Verification > (
893
+ & self ,
894
+ secp : & Secp256k1 < C > ,
895
+ ) -> Result < bitcoin:: PublicKey , ConversionError > {
896
+ match self {
897
+ DescriptorPublicKey :: Single ( single) => single. derive_public_key ( secp) ,
898
+ DescriptorPublicKey :: XPub ( xpub) => xpub. derive_public_key ( secp) ,
899
+ DescriptorPublicKey :: MultiXPub ( xpub) => xpub. derive_public_key ( secp) ,
900
+ }
901
+ }
902
+ }
903
+
913
904
impl FromStr for DescriptorSecretKey {
914
905
type Err = DescriptorKeyParseError ;
915
906
@@ -1245,11 +1236,7 @@ impl DefiniteDescriptorKey {
1245
1236
& self ,
1246
1237
secp : & Secp256k1 < C > ,
1247
1238
) -> Result < bitcoin:: PublicKey , ConversionError > {
1248
- match self . 0 {
1249
- DescriptorPublicKey :: Single ( ref pk) => pk. derive_public_key ( secp) ,
1250
- DescriptorPublicKey :: XPub ( ref xpk) => xpk. derive_public_key ( secp) ,
1251
- DescriptorPublicKey :: MultiXPub ( ref xpk) => xpk. derive_public_key ( secp) ,
1252
- }
1239
+ self . 0 . derive_public_key ( secp)
1253
1240
}
1254
1241
1255
1242
/// Construct an instance from a descriptor key and a derivation index
@@ -1386,7 +1373,7 @@ mod test {
1386
1373
1387
1374
use super :: {
1388
1375
DescriptorKeyParseError , DescriptorMultiXKey , DescriptorPublicKey , DescriptorSecretKey ,
1389
- MiniscriptKey , Wildcard ,
1376
+ DescriptorKey , MiniscriptKey , Wildcard ,
1390
1377
} ;
1391
1378
use crate :: prelude:: * ;
1392
1379
0 commit comments