11use {
22 crate :: { DomainSeparator , quote:: QuoteSigningScheme } ,
3+ alloy:: primitives:: B256 ,
34 anyhow:: { Context as _, Result , ensure} ,
45 primitive_types:: { H160 , H256 } ,
56 serde:: { Deserialize , Serialize , de} ,
@@ -120,8 +121,8 @@ impl Signature {
120121 . try_into ( )
121122 . context ( "ECDSA signature must be 65 bytes long" ) ?;
122123 EcdsaSignature {
123- r : H256 :: from_slice ( & bytes[ ..32 ] ) ,
124- s : H256 :: from_slice ( & bytes[ 32 ..64 ] ) ,
124+ r : B256 :: from_slice ( & bytes[ ..32 ] ) ,
125+ s : B256 :: from_slice ( & bytes[ 32 ..64 ] ) ,
125126 v : bytes[ 64 ] ,
126127 }
127128 . to_signature (
@@ -258,8 +259,8 @@ impl SigningScheme {
258259
259260#[ derive( Eq , PartialEq , Clone , Copy , Debug , Default , Hash ) ]
260261pub struct EcdsaSignature {
261- pub r : H256 ,
262- pub s : H256 ,
262+ pub r : B256 ,
263+ pub s : B256 ,
263264 pub v : u8 ,
264265}
265266
@@ -306,16 +307,16 @@ impl EcdsaSignature {
306307 /// r + s + v
307308 pub fn to_bytes ( self ) -> [ u8 ; 65 ] {
308309 let mut bytes = [ 0u8 ; 65 ] ;
309- bytes[ ..32 ] . copy_from_slice ( self . r . as_bytes ( ) ) ;
310- bytes[ 32 ..64 ] . copy_from_slice ( self . s . as_bytes ( ) ) ;
310+ bytes[ ..32 ] . copy_from_slice ( self . r . as_slice ( ) ) ;
311+ bytes[ 32 ..64 ] . copy_from_slice ( self . s . as_slice ( ) ) ;
311312 bytes[ 64 ] = self . v ;
312313 bytes
313314 }
314315
315316 pub fn from_bytes ( bytes : & [ u8 ; 65 ] ) -> Self {
316317 EcdsaSignature {
317- r : H256 :: from_slice ( & bytes[ ..32 ] ) ,
318- s : H256 :: from_slice ( & bytes[ 32 ..64 ] ) ,
318+ r : B256 :: from_slice ( & bytes[ ..32 ] ) ,
319+ s : B256 :: from_slice ( & bytes[ 32 ..64 ] ) ,
319320 v : bytes[ 64 ] ,
320321 }
321322 }
@@ -327,7 +328,7 @@ impl EcdsaSignature {
327328 struct_hash : & [ u8 ; 32 ] ,
328329 ) -> Result < Recovered > {
329330 let message = hashed_signing_message ( signing_scheme, domain_separator, struct_hash) ;
330- let recovery = Recovery :: new ( message, self . v as u64 , self . r , self . s ) ;
331+ let recovery = Recovery :: new ( message, self . v as u64 , self . r . 0 . into ( ) , self . s . 0 . into ( ) ) ;
331332 let ( signature, recovery_id) = recovery
332333 . as_signature ( )
333334 . context ( "unexpectedly invalid signature" ) ?;
@@ -350,17 +351,17 @@ impl EcdsaSignature {
350351 let signature = key. sign ( & message, None ) . unwrap ( ) ;
351352 Self {
352353 v : signature. v as u8 ,
353- r : signature. r ,
354- s : signature. s ,
354+ r : signature. r . 0 . into ( ) ,
355+ s : signature. s . 0 . into ( ) ,
355356 }
356357 }
357358
358359 /// Returns an arbitrary non-zero signature that can be used for recovery
359360 /// when you don't actually care about the owner.
360361 pub fn non_zero ( ) -> Self {
361362 Self {
362- r : H256 ( [ 1 ; 32 ] ) ,
363- s : H256 ( [ 2 ; 32 ] ) ,
363+ r : B256 :: repeat_byte ( 1 ) ,
364+ s : B256 :: repeat_byte ( 2 ) ,
364365 v : 27 ,
365366 }
366367 }
@@ -517,8 +518,8 @@ mod tests {
517518 ) ,
518519 (
519520 Signature :: EthSign ( EcdsaSignature {
520- r : H256 ( [ 1 ; 32 ] ) ,
521- s : H256 ( [ 2 ; 32 ] ) ,
521+ r : B256 :: repeat_byte ( 1 ) ,
522+ s : B256 :: repeat_byte ( 2 ) ,
522523 v : 3 ,
523524 } ) ,
524525 json ! ( {
0 commit comments