stratus/eth/primitives/
ecdsa_rs.rs

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