@@ -44,7 +44,7 @@ impl Encode for Secp256k1PrivateKey {
4444impl Decode for Secp256k1PrivateKey {
4545 fn decode < I : serialization:: Input > ( input : & mut I ) -> Result < Self , serialization:: Error > {
4646 let mut v = <[ u8 ; secp256k1:: constants:: SECRET_KEY_SIZE ] >:: decode ( input) ?;
47- let result = secp256k1:: SecretKey :: from_slice ( & v)
47+ let result = secp256k1:: SecretKey :: from_byte_array ( & v)
4848 . map ( |r| Secp256k1PrivateKey { data : r } )
4949 . map_err ( |_| serialization:: Error :: from ( "Private Key deserialization failed" ) ) ;
5050 v. zeroize ( ) ;
@@ -73,9 +73,11 @@ impl Secp256k1PrivateKey {
7373 }
7474
7575 pub fn from_bytes ( bytes : & [ u8 ] ) -> Result < Self , Secp256k1KeyError > {
76- secp256k1:: SecretKey :: from_slice ( bytes)
77- . map ( |r| Secp256k1PrivateKey { data : r } )
78- . map_err ( |_| Secp256k1KeyError :: InvalidData )
76+ secp256k1:: SecretKey :: from_byte_array (
77+ & bytes. try_into ( ) . map_err ( |_| Secp256k1KeyError :: InvalidData ) ?,
78+ )
79+ . map ( |r| Secp256k1PrivateKey { data : r } )
80+ . map_err ( |_| Secp256k1KeyError :: InvalidData )
7981 }
8082
8183 pub fn as_native ( & self ) -> & secp256k1:: SecretKey {
@@ -94,15 +96,14 @@ impl Secp256k1PrivateKey {
9496 let secp = secp256k1:: Secp256k1 :: new ( ) ;
9597 // Hash the message
9698 let e = Blake2b32Stream :: new ( ) . write ( msg) . finalize ( ) ;
97- let msg_hash =
98- secp256k1:: Message :: from_digest_slice ( e. as_slice ( ) ) . expect ( "Blake2b32 is 32 bytes" ) ;
99+ let msg_hash = secp256k1:: Message :: from_digest ( e. into ( ) ) ;
99100 // Sign the hash
100101 // TODO(SECURITY) erase keypair after signing
101102 let keypair = self . data . keypair ( & secp) ;
102103
103104 let aux_data = aux_data_provider. get_secp256k1_schnorr_aux_data ( ) ;
104105
105- secp. sign_schnorr_with_aux_rand ( & msg_hash, & keypair, & aux_data)
106+ secp. sign_schnorr_with_aux_rand ( msg_hash. as_ref ( ) , & keypair, & aux_data)
106107 }
107108}
108109
@@ -168,8 +169,7 @@ impl Secp256k1PublicKey {
168169 ) -> bool {
169170 // Hash the message
170171 let e = Blake2b32Stream :: new ( ) . write ( msg) . finalize ( ) ;
171- let msg_hashed =
172- secp256k1:: Message :: from_digest_slice ( e. as_slice ( ) ) . expect ( "Blake2b32 is 32 bytes" ) ;
172+ let msg_hashed = secp256k1:: Message :: from_digest ( e. into ( ) ) ;
173173 // Verify the signature
174174 self . verify_message_hashed ( signature, & msg_hashed)
175175 }
@@ -182,7 +182,7 @@ impl Secp256k1PublicKey {
182182 let secp = secp256k1:: Secp256k1 :: new ( ) ;
183183 secp. verify_schnorr (
184184 signature,
185- msg_hashed,
185+ msg_hashed. as_ref ( ) ,
186186 & self . pubkey_data . x_only_public_key ( ) . 0 ,
187187 )
188188 . is_ok ( )
@@ -377,7 +377,7 @@ mod test {
377377 assert ! ( pk. verify_message( & sig1, & msg) ) ;
378378 assert ! ( pk. verify_message( & sig2, & msg) ) ;
379379 assert_eq ! ( sig1, sig2) ;
380- assert_eq ! ( sig1. serialize ( ) , sig2. serialize ( ) ) ;
380+ assert_eq ! ( sig1. to_byte_array ( ) , sig2. to_byte_array ( ) ) ;
381381 }
382382
383383 #[ rstest]
0 commit comments