stratus/eth/primitives/
signature_component.rs

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