@@ -619,9 +619,7 @@ impl From<base58::Error> for ParseError {
619619}
620620
621621impl From < InvalidBase58PayloadLengthError > for ParseError {
622- fn from ( e : InvalidBase58PayloadLengthError ) -> Self {
623- Self :: InvalidBase58PayloadLength ( e)
624- }
622+ fn from ( e : InvalidBase58PayloadLengthError ) -> Self { Self :: InvalidBase58PayloadLength ( e) }
625623}
626624
627625/// A BIP-0032 error
@@ -737,9 +735,7 @@ impl Xpriv {
737735 }
738736
739737 /// Constructs a new extended public key from this extended private key.
740- pub fn to_xpub ( self ) -> Xpub {
741- Xpub :: from_xpriv ( & self )
742- }
738+ pub fn to_xpub ( self ) -> Xpub { Xpub :: from_xpriv ( & self ) }
743739
744740 /// Constructs a new BIP-0340 keypair for Schnorr signatures and Taproot use matching the internal
745741 /// secret key representation.
@@ -752,20 +748,14 @@ impl Xpriv {
752748 ///
753749 /// The `path` argument can be both of type `DerivationPath` or `Vec<ChildNumber>`.
754750 #[ deprecated( since = "TBD" , note = "use `derive_xpriv()` instead" ) ]
755- pub fn derive_priv < P : AsRef < [ ChildNumber ] > > (
756- & self ,
757- path : P ,
758- ) -> Result < Self , DerivationError > {
751+ pub fn derive_priv < P : AsRef < [ ChildNumber ] > > ( & self , path : P ) -> Result < Self , DerivationError > {
759752 self . derive_xpriv ( path)
760753 }
761754
762755 /// Derives an extended private key from a path.
763756 ///
764757 /// The `path` argument can be both of type `DerivationPath` or `Vec<ChildNumber>`.
765- pub fn derive_xpriv < P : AsRef < [ ChildNumber ] > > (
766- & self ,
767- path : P ,
768- ) -> Result < Self , DerivationError > {
758+ pub fn derive_xpriv < P : AsRef < [ ChildNumber ] > > ( & self , path : P ) -> Result < Self , DerivationError > {
769759 let mut sk: Self = * self ;
770760 for cnum in path. as_ref ( ) {
771761 sk = sk. ckd_priv ( * cnum) ?;
@@ -774,10 +764,7 @@ impl Xpriv {
774764 }
775765
776766 /// Private->Private child key derivation
777- fn ckd_priv (
778- & self ,
779- i : ChildNumber ,
780- ) -> Result < Self , DerivationError > {
767+ fn ckd_priv ( & self , i : ChildNumber ) -> Result < Self , DerivationError > {
781768 let mut engine = HmacEngine :: < sha512:: HashEngine > :: new ( & self . chain_code [ ..] ) ;
782769 match i {
783770 ChildNumber :: Normal { .. } => {
@@ -795,9 +782,10 @@ impl Xpriv {
795782
796783 engine. input ( & u32:: from ( i) . to_be_bytes ( ) ) ;
797784 let hmac: Hmac < sha512:: Hash > = engine. finalize ( ) ;
798- let sk =
799- secp256k1:: SecretKey :: from_secret_bytes ( * hmac. as_byte_array ( ) . split_array :: < 32 , 32 > ( ) . 0 )
800- . expect ( "statistically impossible to hit" ) ;
785+ let sk = secp256k1:: SecretKey :: from_secret_bytes (
786+ * hmac. as_byte_array ( ) . split_array :: < 32 , 32 > ( ) . 0 ,
787+ )
788+ . expect ( "statistically impossible to hit" ) ;
801789 let tweaked =
802790 sk. add_tweak ( & self . private_key . into ( ) ) . expect ( "statistically impossible to hit" ) ;
803791
@@ -854,9 +842,7 @@ impl Xpriv {
854842 }
855843
856844 /// Returns the HASH160 of the public key belonging to the xpriv
857- pub fn identifier ( & self ) -> XKeyIdentifier {
858- Xpub :: from_xpriv ( self ) . identifier ( )
859- }
845+ pub fn identifier ( & self ) -> XKeyIdentifier { Xpub :: from_xpriv ( self ) . identifier ( ) }
860846
861847 /// Returns the first four bytes of the identifier
862848 pub fn fingerprint ( & self ) -> Fingerprint {
@@ -867,9 +853,7 @@ impl Xpriv {
867853impl Xpub {
868854 /// Constructs a new extended public key from an extended private key.
869855 #[ deprecated( since = "TBD" , note = "use `from_xpriv()` instead" ) ]
870- pub fn from_priv ( sk : & Xpriv ) -> Self {
871- Self :: from_xpriv ( sk)
872- }
856+ pub fn from_priv ( sk : & Xpriv ) -> Self { Self :: from_xpriv ( sk) }
873857
874858 /// Constructs a new extended public key from an extended private key.
875859 pub fn from_xpriv ( xpriv : & Xpriv ) -> Self {
@@ -903,20 +887,14 @@ impl Xpub {
903887 ///
904888 /// The `path` argument can be any type implementing `AsRef<ChildNumber>`, such as `DerivationPath`, for instance.
905889 #[ deprecated( since = "TBD" , note = "use `derive_xpub()` instead" ) ]
906- pub fn derive_pub < P : AsRef < [ ChildNumber ] > > (
907- & self ,
908- path : P ,
909- ) -> Result < Self , DerivationError > {
890+ pub fn derive_pub < P : AsRef < [ ChildNumber ] > > ( & self , path : P ) -> Result < Self , DerivationError > {
910891 self . derive_xpub ( path)
911892 }
912893
913894 /// Attempts to derive an extended public key from a path.
914895 ///
915896 /// The `path` argument can be any type implementing `AsRef<ChildNumber>`, such as `DerivationPath`, for instance.
916- pub fn derive_xpub < P : AsRef < [ ChildNumber ] > > (
917- & self ,
918- path : P ,
919- ) -> Result < Self , DerivationError > {
897+ pub fn derive_xpub < P : AsRef < [ ChildNumber ] > > ( & self , path : P ) -> Result < Self , DerivationError > {
920898 let mut pk: Self = * self ;
921899 for cnum in path. as_ref ( ) {
922900 pk = pk. ckd_pub ( * cnum) ?
@@ -948,10 +926,7 @@ impl Xpub {
948926 }
949927
950928 /// Public->Public child key derivation
951- pub fn ckd_pub (
952- & self ,
953- i : ChildNumber ,
954- ) -> Result < Self , DerivationError > {
929+ pub fn ckd_pub ( & self , i : ChildNumber ) -> Result < Self , DerivationError > {
955930 let ( sk, chain_code) = self . ckd_pub_tweak ( i) ?;
956931 let tweaked =
957932 self . public_key . add_exp_tweak ( & sk. into ( ) ) . expect ( "cryptographically unreachable" ) ;
@@ -1307,10 +1282,7 @@ mod tests {
13071282 // Check derivation convenience method for Xpub, should error
13081283 // appropriately if any ChildNumber is hardened
13091284 if path. 0 . iter ( ) . any ( |cnum| cnum. is_hardened ( ) ) {
1310- assert_eq ! (
1311- pk. derive_xpub( & path) ,
1312- Err ( DerivationError :: CannotDeriveHardenedChild )
1313- ) ;
1285+ assert_eq ! ( pk. derive_xpub( & path) , Err ( DerivationError :: CannotDeriveHardenedChild ) ) ;
13141286 } else {
13151287 assert_eq ! ( & pk. derive_xpub( & path) . unwrap( ) . to_string( ) [ ..] , expected_pk) ;
13161288 }
@@ -1325,10 +1297,7 @@ mod tests {
13251297 assert_eq ! ( pk, pk2) ;
13261298 }
13271299 Hardened { .. } => {
1328- assert_eq ! (
1329- pk. ckd_pub( num) ,
1330- Err ( DerivationError :: CannotDeriveHardenedChild )
1331- ) ;
1300+ assert_eq ! ( pk. ckd_pub( num) , Err ( DerivationError :: CannotDeriveHardenedChild ) ) ;
13321301 pk = Xpub :: from_xpriv ( & sk) ;
13331302 }
13341303 }
@@ -1389,7 +1358,6 @@ mod tests {
13891358
13901359 #[ test]
13911360 fn vector_1 ( ) {
1392-
13931361 let seed = hex ! ( "000102030405060708090a0b0c0d0e0f" ) ;
13941362
13951363 // m
0 commit comments