xmtp_id/associations/ident/
ethereum.rs

1use serde::{Deserialize, Serialize};
2use std::fmt::Display;
3use xmtp_cryptography::signature::{IdentifierValidationError, sanitize_evm_addresses};
4
5#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
6pub struct Ethereum(pub String);
7
8impl Ethereum {
9    #[cfg(any(test, feature = "test-utils"))]
10    pub fn rand() -> Self {
11        Self(xmtp_common::rand_hexstring())
12    }
13
14    pub fn sanitize(self) -> Result<Self, IdentifierValidationError> {
15        let mut sanitized = sanitize_evm_addresses(&[self.0])?;
16        Ok(Self(sanitized.pop().expect("Always should be one")))
17    }
18}
19
20impl Display for Ethereum {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        write!(f, "{}", self.0)
23    }
24}