use alloy_primitives::{address, Address};
use world_id_core::primitives::Config;
use crate::{error::WalletKitError, Environment, Region};
pub static WORLD_ID_REGISTRY: Address =
address!("0x8556d07D75025f286fe757C7EeEceC40D54FA16D");
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, 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 => todo!("There is no production environment yet"),
}
}
}