File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,26 @@ impl From<ffi::XOnlyPublicKey> for PublicKey {
324324 }
325325}
326326
327+ impl From < :: key:: PublicKey > for PublicKey {
328+ fn from ( src : :: key:: PublicKey ) -> PublicKey {
329+ let mut pk = ffi:: XOnlyPublicKey :: new ( ) ;
330+
331+ unsafe {
332+ assert_eq ! (
333+ 1 ,
334+ ffi:: secp256k1_xonly_pubkey_from_pubkey(
335+ ffi:: secp256k1_context_no_precomp,
336+ & mut pk,
337+ ptr:: null_mut( ) ,
338+ src. as_c_ptr( ) ,
339+ )
340+ ) ;
341+ }
342+
343+ PublicKey ( pk)
344+ }
345+ }
346+
327347serde_impl_from_slice ! ( PublicKey ) ;
328348
329349impl < C : Signing > Secp256k1 < C > {
@@ -707,4 +727,22 @@ mod tests {
707727 assert_eq ! ( PublicKey :: from_keypair( & s, & kp) , pk) ;
708728 }
709729 }
730+
731+ #[ test]
732+ fn test_from_key_pubkey ( ) {
733+ let kpk1 = :: key:: PublicKey :: from_str (
734+ "02e6642fd69bd211f93f7f1f36ca51a26a5290eb2dd1b0d8279a87bb0d480c8443" ,
735+ )
736+ . unwrap ( ) ;
737+ let kpk2 = :: key:: PublicKey :: from_str (
738+ "0384526253c27c7aef56c7b71a5cd25bebb66dddda437826defc5b2568bde81f07" ,
739+ )
740+ . unwrap ( ) ;
741+
742+ let pk1 = PublicKey :: from ( kpk1) ;
743+ let pk2 = PublicKey :: from ( kpk2) ;
744+
745+ assert_eq ! ( pk1. serialize( ) [ ..] , kpk1. serialize( ) [ 1 ..] ) ;
746+ assert_eq ! ( pk2. serialize( ) [ ..] , kpk2. serialize( ) [ 1 ..] ) ;
747+ }
710748}
You can’t perform that action at this time.
0 commit comments