stratus/eth/primitives/
signature_component.rs

1use alloy_primitives::U256;
2use display_json::DebugAsJson;
3#[cfg(test)]
4use fake::Dummy;
5#[cfg(test)]
6use fake::Faker;
7#[cfg(test)]
8use rand::Rng;
9
10/// A signature component (r or s value)
11#[derive(DebugAsJson, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
12pub struct SignatureComponent(pub U256);
13
14#[cfg(test)]
15impl Dummy<Faker> for SignatureComponent {
16    fn dummy_with_rng<R: Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
17        Self(U256::random_with(rng))
18    }
19}
20
21// -----------------------------------------------------------------------------
22// Conversions: Other -> Self
23// -----------------------------------------------------------------------------
24
25impl From<U256> for SignatureComponent {
26    fn from(value: U256) -> Self {
27        Self(value)
28    }
29}
30
31// -----------------------------------------------------------------------------
32// Conversions: Self -> Other
33// -----------------------------------------------------------------------------
34
35impl From<SignatureComponent> for U256 {
36    fn from(value: SignatureComponent) -> Self {
37        value.0
38    }
39}