use alloy_primitives::{address, Address};
use world_id_core::primitives::Config;
use crate::{error::WalletKitError, Environment, Region};
pub static WORLD_ID_REGISTRY: Address =
address!("0x0000000000aE079eB8a274cD51c0f44a9E4d67d4");
pub static STAGING_WORLD_ID_REGISTRY: Address =
address!("0x8556d07D75025f286fe757C7EeEceC40D54FA16D");
pub static POH_RECOVERY_AGENT_ADDRESS_STAGING: Address =
address!("0x8df366ed8ef894f0d1d25dc21b7e36e2d97a7140");
pub static POH_RECOVERY_AGENT_ADDRESS_PRODUCTION: Address =
address!("0x00000000CBBA8Cb46C8CD414B62213F1B334fC59");
pub(crate) fn poh_recovery_agent_address(environment: &Environment) -> Address {
match environment {
Environment::Staging => POH_RECOVERY_AGENT_ADDRESS_STAGING,
Environment::Production => POH_RECOVERY_AGENT_ADDRESS_PRODUCTION,
}
}
const OPRF_NODE_COUNT: usize = 5;
fn oprf_node_urls(region: Region, environment: &Environment) -> Vec<String> {
let env_segment = match environment {
Environment::Staging => ".staging",
Environment::Production => "",
};
(0..OPRF_NODE_COUNT)
.map(|i| {
format!("https://node{i}.{region}{env_segment}.world.oprf.taceo.network")
})
.collect()
}
fn indexer_url(region: Region, environment: &Environment) -> String {
let domain = match environment {
Environment::Staging => "worldcoin.dev",
Environment::Production => "world.org",
};
format!("https://indexer.{region}.id-infra.{domain}")
}
pub trait DefaultConfig {
fn from_environment(
environment: &Environment,
rpc_url: Option<String>,
region: Option<Region>,
) -> Result<Self, WalletKitError>
where
Self: Sized;
}
impl DefaultConfig for Config {
fn from_environment(
environment: &Environment,
rpc_url: Option<String>,
region: Option<Region>,
) -> Result<Self, WalletKitError> {
let region = region.unwrap_or_default();
match environment {
Environment::Staging => Self::new(
rpc_url,
480, STAGING_WORLD_ID_REGISTRY,
indexer_url(region, environment),
"https://gateway.id-infra.worldcoin.dev".to_string(),
oprf_node_urls(region, environment),
3,
)
.map_err(WalletKitError::from),
Environment::Production => Self::new(
rpc_url,
480,
WORLD_ID_REGISTRY,
indexer_url(region, environment),
"https://gateway.id-infra.world.org".to_string(),
oprf_node_urls(region, environment),
3,
)
.map_err(WalletKitError::from),
}
}
}