forked from anoma/ferveo
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
512896d
commit 9215238
Showing
25 changed files
with
608 additions
and
522 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,7 @@ | ||
use std::{cmp::Ordering, fmt::Display, str::FromStr}; | ||
|
||
use ark_ec::pairing::Pairing; | ||
use serde::{Deserialize, Serialize}; | ||
use thiserror::Error; | ||
|
||
pub mod keypair; | ||
pub mod serialization; | ||
pub mod utils; | ||
|
||
pub use keypair::*; | ||
pub use serialization::*; | ||
pub use utils::*; | ||
|
||
#[derive( | ||
Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, Hash, | ||
)] | ||
pub struct EthereumAddress(String); | ||
|
||
#[derive(Debug, Error, Clone, PartialEq, Eq)] | ||
pub enum EthereumAddressParseError { | ||
#[error("Invalid Ethereum address length.")] | ||
InvalidLength, | ||
|
||
#[error("Invalid hex value in Ethereum address.")] | ||
InvalidHex, | ||
} | ||
|
||
impl FromStr for EthereumAddress { | ||
type Err = EthereumAddressParseError; | ||
|
||
fn from_str(s: &str) -> Result<EthereumAddress, EthereumAddressParseError> { | ||
if s.len() != 42 { | ||
return Err(EthereumAddressParseError::InvalidLength); | ||
} | ||
hex::decode(&s[2..]) | ||
.map_err(|_| EthereumAddressParseError::InvalidHex)?; | ||
Ok(EthereumAddress(s.to_string())) | ||
} | ||
} | ||
|
||
impl Display for EthereumAddress { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
/// Represents an external validator | ||
pub struct Validator<E: Pairing> { | ||
/// The established address of the validator | ||
pub address: EthereumAddress, | ||
/// The Public key | ||
pub public_key: PublicKey<E>, | ||
} | ||
|
||
impl<E: Pairing> PartialOrd for Validator<E> { | ||
#[inline] | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
self.address.partial_cmp(&other.address) | ||
} | ||
} | ||
|
||
impl<E: Pairing> Ord for Validator<E> { | ||
#[inline] | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
self.address.cmp(&other.address) | ||
} | ||
} | ||
|
||
impl<E: Pairing> Validator<E> { | ||
pub fn new( | ||
address: String, | ||
public_key: PublicKey<E>, | ||
) -> Result<Self, EthereumAddressParseError> { | ||
Ok(Self { | ||
address: EthereumAddress::from_str(&address)?, | ||
public_key, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.