diff --git a/crates/primitives/src/signature/ecdsa_sig.rs b/crates/primitives/src/signature/ecdsa_sig.rs index ff81ef530d..bd88dc199a 100644 --- a/crates/primitives/src/signature/ecdsa_sig.rs +++ b/crates/primitives/src/signature/ecdsa_sig.rs @@ -21,46 +21,54 @@ pub struct EcdsaSignature { } impl EcdsaSignature { + /// Returns the recovery ID. + #[cfg(feature = "k256")] + #[inline] + const fn recid(&self) -> k256::ecdsa::RecoveryId { + self.v.recid() + } + + #[cfg(feature = "k256")] + #[doc(hidden)] + #[deprecated(note = "use `Signature::recid` instead")] + pub const fn recovery_id(&self) -> k256::ecdsa::RecoveryId { + self.recid() + } + + #[doc(hidden)] + fn test_signature() -> Self { + Self::from_scalars_and_parity( + b256!("840cfc572845f5786e702984c2a582528cad4b49b2a10b9db1be7fca90058565"), + b256!("25e7109ceb98168d95b09b18bbf6b685130e0562f233877d492b94eee0c5b6d1"), + false, + ) + .unwrap() + } +} + +impl Signature<'_> for EcdsaSignature { /// Instantiate a new signature from `r`, `s`, and `v` values. - #[allow(clippy::missing_const_for_fn)] - pub fn new(r: U256, s: U256, v: Parity) -> Self { + fn new(r: U256, s: U256, v: Parity) -> Self { Self { r, s, v } } /// Returns the `r` component of this signature. #[inline] - pub const fn r(&self) -> U256 { + fn r(&self) -> U256 { self.r } /// Returns the `s` component of this signature. #[inline] - pub const fn s(&self) -> U256 { + fn s(&self) -> U256 { self.s } /// Returns the recovery ID as a `u8`. #[inline] - pub const fn v(&self) -> Parity { + fn v(&self) -> Parity { self.v } - - /// Returns the recovery ID. - #[cfg(feature = "k256")] - #[inline] - const fn recid(&self) -> k256::ecdsa::RecoveryId { - self.v.recid() - } - - #[cfg(feature = "k256")] - #[doc(hidden)] - #[deprecated(note = "use `Signature::recid` instead")] - pub const fn recovery_id(&self) -> k256::ecdsa::RecoveryId { - self.recid() - } -} - -impl Signature<'_> for EcdsaSignature { #[cfg(feature = "rlp")] fn decode_rlp_vrs(buf: &mut &[u8]) -> Result { use alloy_rlp::Decodable; @@ -73,16 +81,6 @@ impl Signature<'_> for EcdsaSignature { .map_err(|_| alloy_rlp::Error::Custom("attempted to decode invalid field element")) } - #[doc(hidden)] - fn test_signature() -> Self { - Self::from_scalars_and_parity( - b256!("840cfc572845f5786e702984c2a582528cad4b49b2a10b9db1be7fca90058565"), - b256!("25e7109ceb98168d95b09b18bbf6b685130e0562f233877d492b94eee0c5b6d1"), - false, - ) - .unwrap() - } - /// Returns the byte-array representation of this signature. /// /// The first 32 bytes are the `r` value, the second 32 bytes the `s` value diff --git a/crates/primitives/src/signature/sig.rs b/crates/primitives/src/signature/sig.rs index 77409a32a5..b0c29ada01 100644 --- a/crates/primitives/src/signature/sig.rs +++ b/crates/primitives/src/signature/sig.rs @@ -5,17 +5,27 @@ use core::str::FromStr; pub trait Signature<'a>: TryFrom<&'a [u8], Error = SignatureError> + FromStr { + /// Instantiate a new signature from `r`, `s`, and `v` values. + fn new(r: U256, s: U256, v: Parity) -> Self; + + /// Returns the `r` component of this signature. + #[inline] + fn r(&self) -> U256; + + /// Returns the `s` component of this signature. + #[inline] + fn s(&self) -> U256; + + /// Returns the recovery ID as a `u8`. + #[inline] + fn v(&self) -> Parity; + /// Decode an RLP-encoded VRS signature. #[cfg(feature = "rlp")] fn decode_rlp_vrs(buf: &mut &[u8]) -> Result where Self: Sized; - #[doc(hidden)] - fn test_signature() -> Self - where - Self: Sized; - /// Returns the byte-array representation of this signature. fn as_bytes(&self) -> [u8; 65];