use std::fmt;
use async_trait::async_trait;
mod error;
pub mod evm;
pub use error::WalletError;
pub use evm::EvmWallet;
#[cfg(feature = "x402")]
pub use evm::x402::X402HttpClient;
pub use kobe::Wallet as HdWallet;
pub use kobe_evm::{DerivationStyle, DerivedAddress};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EvmChain {
Ethereum,
Sepolia,
Optimism,
Bsc,
Gnosis,
Polygon,
Fantom,
ZkSync,
Base,
Arbitrum,
Avalanche,
Linea,
Scroll,
Monad,
Custom {
id: u64,
name: String,
},
}
impl EvmChain {
#[must_use]
pub const fn id(&self) -> u64 {
match self {
Self::Ethereum => 1,
Self::Sepolia => 11_155_111,
Self::Optimism => 10,
Self::Bsc => 56,
Self::Gnosis => 100,
Self::Polygon => 137,
Self::Fantom => 250,
Self::ZkSync => 324,
Self::Base => 8453,
Self::Arbitrum => 42_161,
Self::Avalanche => 43_114,
Self::Linea => 59_144,
Self::Scroll => 534_352,
Self::Monad => 143,
Self::Custom { id, .. } => *id,
}
}
#[must_use]
pub fn name(&self) -> &str {
match self {
Self::Ethereum => "ethereum",
Self::Sepolia => "sepolia",
Self::Optimism => "optimism",
Self::Bsc => "bsc",
Self::Gnosis => "gnosis",
Self::Polygon => "polygon",
Self::Fantom => "fantom",
Self::ZkSync => "zksync",
Self::Base => "base",
Self::Arbitrum => "arbitrum",
Self::Avalanche => "avalanche",
Self::Linea => "linea",
Self::Scroll => "scroll",
Self::Monad => "monad",
Self::Custom { name, .. } => name,
}
}
#[must_use]
pub fn from_id(id: u64) -> Self {
match id {
1 => Self::Ethereum,
10 => Self::Optimism,
56 => Self::Bsc,
100 => Self::Gnosis,
137 => Self::Polygon,
250 => Self::Fantom,
324 => Self::ZkSync,
8453 => Self::Base,
42_161 => Self::Arbitrum,
43_114 => Self::Avalanche,
59_144 => Self::Linea,
143 => Self::Monad,
534_352 => Self::Scroll,
11_155_111 => Self::Sepolia,
_ => Self::Custom {
id,
name: format!("evm-{id}"),
},
}
}
}
impl fmt::Display for EvmChain {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} ({})", self.name(), self.id())
}
}
#[async_trait]
pub trait Wallet: Send + Sync + fmt::Debug {
fn address(&self) -> &str;
fn chain(&self) -> &str;
fn chain_id(&self) -> Option<u64> {
None
}
async fn sign_message(&self, message: &[u8]) -> Result<String, WalletError>;
}