@@ -213,8 +213,8 @@ impl KeyPair {
213
213
214
214
/// Serialize the key pair as a secret key byte value
215
215
#[ inline]
216
- pub fn serialize_sec < V : Verification > ( & self , secp : & Secp256k1 < V > ) -> [ u8 ; constants:: SECRET_KEY_SIZE ] {
217
- * SecretKey :: from_keypair ( secp , self ) . as_ref ( )
216
+ pub fn serialize_secret ( & self ) -> [ u8 ; constants:: SECRET_KEY_SIZE ] {
217
+ * SecretKey :: from_keypair ( self ) . as_ref ( )
218
218
}
219
219
220
220
/// Tweak a keypair by adding the given tweak to the secret key and updating the
@@ -456,35 +456,31 @@ impl<'de> ::serde::Deserialize<'de> for PublicKey {
456
456
}
457
457
}
458
458
459
- impl SecretKey {
460
- /// Creates a new secret key using data from BIP-340 [`KeyPair`]
461
- pub fn from_keypair < V : Verification > ( secp : & Secp256k1 < V > , keypair : & KeyPair ) -> Self {
462
- let mut sk = [ 0 ; constants:: SECRET_KEY_SIZE ] ;
463
- unsafe {
464
- let ret = ffi:: secp256k1_keypair_sec (
465
- secp. ctx ,
466
- sk. as_mut_c_ptr ( ) ,
467
- keypair. as_ptr ( )
468
- ) ;
469
- debug_assert_eq ! ( ret, 1 ) ;
470
- }
471
- SecretKey ( sk)
459
+ impl From < KeyPair > for SecretKey {
460
+ #[ inline]
461
+ fn from ( pair : KeyPair ) -> Self {
462
+ SecretKey :: from_keypair ( & pair)
472
463
}
473
464
}
474
465
475
- impl :: key:: PublicKey {
476
- /// Creates a new compressed public key key using data from BIP-340 [`KeyPair`]
477
- pub fn from_keypair < C : Signing > ( secp : & Secp256k1 < C > , keypair : & KeyPair ) -> Self {
478
- unsafe {
479
- let mut pk = ffi:: PublicKey :: new ( ) ;
480
- let ret = ffi:: secp256k1_keypair_pub (
481
- secp. ctx ,
482
- & mut pk,
483
- keypair. as_ptr ( )
484
- ) ;
485
- debug_assert_eq ! ( ret, 1 ) ;
486
- :: key:: PublicKey ( pk)
487
- }
466
+ impl < ' a > From < & ' a KeyPair > for SecretKey {
467
+ #[ inline]
468
+ fn from ( pair : & ' a KeyPair ) -> Self {
469
+ SecretKey :: from_keypair ( pair)
470
+ }
471
+ }
472
+
473
+ impl From < KeyPair > for :: key:: PublicKey {
474
+ #[ inline]
475
+ fn from ( pair : KeyPair ) -> Self {
476
+ :: key:: PublicKey :: from_keypair ( & pair)
477
+ }
478
+ }
479
+
480
+ impl < ' a > From < & ' a KeyPair > for :: key:: PublicKey {
481
+ #[ inline]
482
+ fn from ( pair : & ' a KeyPair ) -> Self {
483
+ :: key:: PublicKey :: from_keypair ( pair)
488
484
}
489
485
}
490
486
@@ -734,9 +730,9 @@ mod tests {
734
730
let secp = Secp256k1 :: new ( ) ;
735
731
let sk_str = "688C77BC2D5AAFF5491CF309D4753B732135470D05B7B2CD21ADD0744FE97BEF" ;
736
732
let keypair = KeyPair :: from_seckey_str ( & secp, sk_str) . unwrap ( ) ;
737
- let sk = SecretKey :: from_keypair ( & secp , & keypair) ;
733
+ let sk = SecretKey :: from_keypair ( & keypair) ;
738
734
assert_eq ! ( SecretKey :: from_str( sk_str) . unwrap( ) , sk) ;
739
- let pk = :: key:: PublicKey :: from_keypair ( & secp , & keypair) ;
735
+ let pk = :: key:: PublicKey :: from_keypair ( & keypair) ;
740
736
assert_eq ! ( :: key:: PublicKey :: from_secret_key( & secp, & sk) , pk) ;
741
737
let xpk = PublicKey :: from_keypair ( & secp, & keypair) ;
742
738
assert_eq ! ( PublicKey :: from( pk) , xpk) ;
0 commit comments