stratus/eth/primitives/
ecdsa_rs.rs

1use alloy_primitives::U256;
2use display_json::DebugAsJson;
3use fake::Dummy;
4use fake::Faker;
5
6// Type representing `r` and `s` variables from the ECDSA signature.
7#[derive(DebugAsJson, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
8pub struct EcdsaRs(U256);
9
10impl Dummy<Faker> for EcdsaRs {
11    fn dummy_with_rng<R: rand::prelude::Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
12        Self(U256::random_with(rng))
13    }
14}
15
16// -----------------------------------------------------------------------------
17// Conversions: Other -> Self
18// -----------------------------------------------------------------------------
19
20impl From<u8> for EcdsaRs {
21    fn from(value: u8) -> Self {
22        Self(U256::from(value))
23    }
24}
25
26impl From<u16> for EcdsaRs {
27    fn from(value: u16) -> Self {
28        Self(U256::from(value))
29    }
30}
31
32impl From<u32> for EcdsaRs {
33    fn from(value: u32) -> Self {
34        Self(U256::from(value))
35    }
36}
37
38impl From<u64> for EcdsaRs {
39    fn from(value: u64) -> Self {
40        Self(U256::from(value))
41    }
42}
43
44impl From<u128> for EcdsaRs {
45    fn from(value: u128) -> Self {
46        Self(U256::from(value))
47    }
48}
49
50impl From<U256> for EcdsaRs {
51    fn from(value: U256) -> Self {
52        Self(value)
53    }
54}
55
56impl From<i8> for EcdsaRs {
57    fn from(value: i8) -> Self {
58        Self(U256::from(value as u8))
59    }
60}
61
62impl From<i16> for EcdsaRs {
63    fn from(value: i16) -> Self {
64        Self(U256::from(value as u16))
65    }
66}
67
68impl From<i32> for EcdsaRs {
69    fn from(value: i32) -> Self {
70        Self(U256::from(value as u32))
71    }
72}
73
74impl From<i64> for EcdsaRs {
75    fn from(value: i64) -> Self {
76        Self(U256::from(value as u64))
77    }
78}
79
80impl From<i128> for EcdsaRs {
81    fn from(value: i128) -> Self {
82        Self(U256::from(value as u128))
83    }
84}
85
86impl From<[u8; 32]> for EcdsaRs {
87    fn from(value: [u8; 32]) -> Self {
88        Self(U256::from_be_bytes(value))
89    }
90}
91
92// -----------------------------------------------------------------------------
93// Conversions: Self -> Other
94// -----------------------------------------------------------------------------