diff --git a/Cargo.lock b/Cargo.lock index b93ce32..da4b307 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1086,6 +1086,19 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blockchain_api" +version = "0.1.0" +source = "git+https://github.com/WalletConnect/WalletConnectRust.git?tag=v0.29.2#593029f0f94c500fdd0390492cf0e00f11a67fd2" +dependencies = [ + "relay_rpc", + "reqwest", + "serde", + "tokio", + "tracing", + "url", +] + [[package]] name = "brotli" version = "3.4.0" @@ -2531,6 +2544,7 @@ dependencies = [ "aws-sdk-s3", "axum", "axum-macros", + "blockchain_api", "bs58", "build-info", "build-info-build", @@ -3488,7 +3502,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "relay_rpc" version = "0.1.0" -source = "git+https://github.com/WalletConnect/WalletConnectRust.git?tag=v0.28.0#f7ff25cae3dec381e5c391a98532dabffd5299d8" +source = "git+https://github.com/WalletConnect/WalletConnectRust.git?tag=v0.29.2#593029f0f94c500fdd0390492cf0e00f11a67fd2" dependencies = [ "alloy-json-abi", "alloy-json-rpc", diff --git a/Cargo.toml b/Cargo.toml index 5c16a72..8c60295 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,13 +6,19 @@ authors = [ "Derek Rein ", "Szymon Rząd ", "Xavier Basty-Kjellberg ", - "Maciej Rak " + "Maciej Rak ", ] build = "build.rs" [dependencies] -wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.7.0", features = ["geoip", "geoblock"] } -relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.28.0", features = ["cacao"] } +wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.7.0", features = [ + "geoip", + "geoblock", +] } +relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.29.2", features = [ + "cacao", +] } +blockchain_api = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.29.2" } aws-config = "0.56" aws-sdk-s3 = "0.31" @@ -20,13 +26,28 @@ aws-sdk-s3 = "0.31" axum = "0.6.1" axum-macros = "0.3.0" tokio = { version = "1.0", features = ["full"] } -tower = { version = "0.4", features = ["util", "timeout", "load-shed", "limit"] } -tower-http = { version = "0.3.0", features = ["add-extension", "auth", "compression-full", "trace", "cors", "request-id", "util"] } +tower = { version = "0.4", features = [ + "util", + "timeout", + "load-shed", + "limit", +] } +tower-http = { version = "0.3.0", features = [ + "add-extension", + "auth", + "compression-full", + "trace", + "cors", + "request-id", + "util", +] } hyper = "0.14" http = "0.2.8" # Database -wither = { git = "https://github.com/WalletConnect/wither.git", rev = "6a70e74", features = ["bson-chrono-0_4"] } +wither = { git = "https://github.com/WalletConnect/wither.git", rev = "6a70e74", features = [ + "bson-chrono-0_4", +] } wither_derive = { git = "https://github.com/WalletConnect/wither.git", rev = "6a70e74" } # Seralisation @@ -48,7 +69,10 @@ opentelemetry-otlp = "0.11" # Logging tracing = "0.1" -tracing-subscriber = { version = "0.3", features = ["env-filter", "parking_lot"] } +tracing-subscriber = { version = "0.3", features = [ + "env-filter", + "parking_lot", +] } tracing-appender = "0.2" tracing-opentelemetry = "0.18" atty = "0.2" @@ -71,3 +95,8 @@ hex = "0.4.3" [build-dependencies] build-info-build = "0.0.29" + +# [patch.'https://github.com/WalletConnect/WalletConnectRust.git'] +# relay_rpc = { path = "../WalletConnectRust/relay_rpc" } +# relay_client = { path = "../WalletConnectRust/relay_client" } +# blockchain_api = { path = "../WalletConnectRust/blockchain_api" } diff --git a/src/config.rs b/src/config.rs index 168f893..b1d0820 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,6 +9,9 @@ pub struct Configuration { pub database_url: String, pub project_id: ProjectId, + #[serde(default = "default_blockchain_api_endpoint")] + pub blockchain_api_endpoint: Option, + // Telemetry pub telemetry_enabled: Option, pub telemetry_grpc_url: Option, @@ -43,3 +46,7 @@ fn default_port() -> u16 { fn default_log_level() -> String { "WARN".to_string() } + +fn default_blockchain_api_endpoint() -> Option { + Some("https://rpc.walletconnect.com".to_string()) +} diff --git a/src/error.rs b/src/error.rs index 87499e0..7cb8bc3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -42,6 +42,9 @@ pub enum Error { #[error(transparent)] Cacao(#[from] CacaoError), + + #[error("Blockchain API error: {0}")] + BlockchainApi(blockchain_api::Error), } impl IntoResponse for Error { diff --git a/src/handlers/identity/register.rs b/src/handlers/identity/register.rs index 2e97c9a..e146789 100644 --- a/src/handlers/identity/register.rs +++ b/src/handlers/identity/register.rs @@ -38,14 +38,17 @@ pub async fn handler( payload.cacao ); - cacao.verify(&state.provider).await.map_err(|error| { - increment_counter!(state.metrics, invalid_identity_register_cacao); - info!( - "Failure - Register identity with cacao: {:?}, error: {:?}", - payload.cacao, error - ); - error - })?; + cacao + .verify(state.provider.as_ref()) + .await + .map_err(|error| { + increment_counter!(state.metrics, invalid_identity_register_cacao); + info!( + "Failure - Register identity with cacao: {:?}, error: {:?}", + payload.cacao, error + ); + error + })?; let identity_key = cacao.p.identity_key()?; let account = cacao.p.caip_10_address()?; diff --git a/src/lib.rs b/src/lib.rs index ca1617b..b3872b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,14 @@ use { - crate::{config::Configuration, log::prelude::*, state::AppState}, + crate::{config::Configuration, error::Error, log::prelude::*, state::AppState}, aws_config::meta::region::RegionProviderChain, aws_sdk_s3::{config::Region, Client as S3Client}, axum::{ routing::{get, post}, Router, }, + blockchain_api::BlockchainApiProvider, http::{HeaderValue, Method}, opentelemetry::{sdk::Resource, KeyValue}, - relay_rpc::auth::cacao::signature::eip1271::blockchain_api::BlockchainApiProvider, std::{net::SocketAddr, sync::Arc}, stores::keys::MongoPersistentStorage, tokio::{select, sync::broadcast}, @@ -46,7 +46,20 @@ pub async fn bootstrap( let s3_client = get_s3_client(&config).await; let geoip_resolver = get_geoip_resolver(&config, &s3_client).await; - let provider = BlockchainApiProvider::new(config.project_id.clone()); + let provider = if let Some(blockchain_api_endpoint) = &config.blockchain_api_endpoint { + Some( + BlockchainApiProvider::new( + config.project_id.clone(), + blockchain_api_endpoint + .parse() + .expect("Error parsing blockchain_api_endpoint"), + ) + .await + .map_err(Error::BlockchainApi)?, + ) + } else { + None + }; let mut state = AppState::new(config, keys_persistent_storage, provider)?; if let Some(prometheus_port) = state.config.telemetry_prometheus_port { diff --git a/src/state.rs b/src/state.rs index ab33a9a..23faf50 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,7 +1,7 @@ use { crate::{config::Configuration, metrics::Metrics, stores::keys::KeysPersistentStorageArc}, + blockchain_api::BlockchainApiProvider, build_info::BuildInfo, - relay_rpc::auth::cacao::signature::eip1271::blockchain_api::BlockchainApiProvider, }; #[derive(Clone)] @@ -10,7 +10,7 @@ pub struct AppState { pub build_info: BuildInfo, pub metrics: Option, pub keys_persitent_storage: KeysPersistentStorageArc, - pub provider: BlockchainApiProvider, + pub provider: Option, } build_info::build_info!(fn build_info); @@ -19,7 +19,7 @@ impl AppState { pub fn new( config: Configuration, keys_persitent_storage: KeysPersistentStorageArc, - provider: BlockchainApiProvider, + provider: Option, ) -> crate::error::Result { let build_info: &BuildInfo = build_info();