diff --git a/crates/consensus/src/signed.rs b/crates/consensus/src/signed.rs index f31b13d0d59..bcaf357e28f 100644 --- a/crates/consensus/src/signed.rs +++ b/crates/consensus/src/signed.rs @@ -227,6 +227,15 @@ impl> Signed { let signer = self.recover_signer()?; Ok(crate::transaction::Recovered::new_unchecked(self.tx, signer)) } + + /// Attempts to recover signer and constructs a [`crate::transaction::Recovered`] with a + /// reference to the transaction `Recovered<&T>` + pub fn try_to_recovered_ref( + &self, + ) -> Result, alloy_primitives::SignatureError> { + let signer = self.recover_signer()?; + Ok(crate::transaction::Recovered::new_unchecked(&self.tx, signer)) + } } #[cfg(all(any(test, feature = "arbitrary"), feature = "k256"))] diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index c80fc922bf7..e3ffed2802d 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -511,6 +511,18 @@ impl EthereumTxEnvelope { Ok(crate::transaction::Recovered::new_unchecked(self, signer)) } + /// Recover the signer of the transaction and returns a `Recovered<&Self>` + #[cfg(feature = "k256")] + pub fn try_to_recovered_ref( + &self, + ) -> Result, alloy_primitives::SignatureError> + where + Eip4844: SignableTransaction, + { + let signer = self.recover_signer()?; + Ok(crate::transaction::Recovered::new_unchecked(self, signer)) + } + /// Calculate the signing hash for the transaction. pub fn signature_hash(&self) -> B256 where