11//! Attestation types and functions for verifying attestations.
22
3- use alloy_primitives:: { b256, keccak256, Address , ChainId , Signature , B256 } ;
4- use alloy_signer:: SignerSync ;
5- use alloy_sol_types:: { eip712_domain, Eip712Domain , SolStruct } ;
3+ use alloy:: {
4+ primitives:: {
5+ b256, keccak256, normalize_v, Address , ChainId , PrimitiveSignature as Signature , B256 ,
6+ } ,
7+ signers:: SignerSync ,
8+ sol_types:: { eip712_domain, Eip712Domain , SolStruct } ,
9+ } ;
610
711use crate :: { allocation_id:: AllocationId , deployment_id:: DeploymentId } ;
812
@@ -38,7 +42,7 @@ pub struct Attestation {
3842 pub v : u8 ,
3943}
4044
41- alloy_sol_types :: sol! {
45+ alloy :: sol_types :: sol! {
4246 /// EIP-712 receipt struct for attestation signing.
4347 struct Receipt {
4448 bytes32 requestCID;
@@ -144,12 +148,11 @@ pub fn recover_allocation(
144148 domain : & Eip712Domain ,
145149 attestation : & Attestation ,
146150) -> Result < AllocationId , VerificationError > {
147- let signature = Signature :: from_rs_and_parity (
148- attestation. r . into ( ) ,
149- attestation. s . into ( ) ,
150- attestation. v as u64 ,
151- )
152- . map_err ( |_| VerificationError :: FailedSignerRecovery ) ?;
151+ // Recover the signature components
152+ let signature_parity =
153+ normalize_v ( attestation. v as u64 ) . ok_or ( VerificationError :: FailedSignerRecovery ) ?;
154+ let signature_r = attestation. r . into ( ) ;
155+ let signature_s = attestation. s . into ( ) ;
153156
154157 // Calculate the signing hash
155158 let msg = Receipt {
@@ -160,21 +163,22 @@ pub fn recover_allocation(
160163 let signing_hash = msg. eip712_signing_hash ( domain) ;
161164
162165 // Recover the allocation ID from the signature
163- signature
166+ Signature :: new ( signature_r , signature_s , signature_parity )
164167 . recover_address_from_prehash ( & signing_hash)
165168 . map ( Into :: into)
166169 . map_err ( |_| VerificationError :: FailedSignerRecovery )
167170}
168171
169172#[ cfg( test) ]
170173mod tests {
171- use alloy_primitives:: { b256, ChainId , B256 } ;
172- use alloy_signer:: SignerSync ;
173- use alloy_signer_local:: PrivateKeySigner ;
174- use alloy_sol_types:: Eip712Domain ;
174+ use alloy:: {
175+ primitives:: { address, b256, Address , ChainId , B256 } ,
176+ signers:: { local:: PrivateKeySigner , SignerSync } ,
177+ sol_types:: Eip712Domain ,
178+ } ;
175179
176180 use super :: { create, eip712_domain, verify, Attestation } ;
177- use crate :: { address , deployment_id, Address , DeploymentId } ;
181+ use crate :: { deployment_id, DeploymentId } ;
178182
179183 const CHAIN_ID : ChainId = 1337 ;
180184 const DISPUTE_MANAGER_ADDRESS : Address = address ! ( "16def7e0108a5467a106DBd7537F8591F470342e" ) ;
0 commit comments