Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamic chain support #403

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ futures = "0.3.26"
futures-util = "0.3"
dashmap = "5.4.0"

relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.29.1", features = ["cacao"] }
relay_client = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.29.1" }
relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.29.2", features = ["cacao"] }
relay_client = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.29.2" }
blockchain_api = { git = "https://github.com/WalletConnect/WalletConnectRust.git", tag = "v0.29.2" }
x25519-dalek = { version = "2.0.0", features = ["static_secrets"] }
hkdf = "0.12.3"
sha2 = "0.10.6"
Expand Down Expand Up @@ -104,3 +105,4 @@ build-info-build = "0.0"
# [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" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, do we need to maintain these lines commented out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it's easy to un-comment and be able to test local changes easily

30 changes: 15 additions & 15 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ pub async fn verify_identity(
ksu: &str,
sub: &str,
redis: Option<&Arc<Redis>>,
provider: &impl GetRpcUrl,
provider: Option<&impl GetRpcUrl>,
metrics: Option<&Metrics>,
) -> Result<Authorization, IdentityVerificationError> {
let mut url = Url::parse(ksu)
Expand Down Expand Up @@ -1130,13 +1130,13 @@ pub mod test_utils {
let cacao_signature = [&signature.to_bytes()[..], &[recovery.to_byte()]].concat();
cacao.s.t = EIP191.to_owned();
cacao.s.s = hex::encode(cacao_signature);
cacao.verify(&MockGetRpcUrl).await.unwrap();
cacao.verify(Some(&MockGetRpcUrl)).await.unwrap();
cacao
}

pub struct MockGetRpcUrl;
impl GetRpcUrl for MockGetRpcUrl {
fn get_rpc_url(&self, _: String) -> Option<Url> {
async fn get_rpc_url(&self, _: String) -> Option<Url> {
None
}
}
Expand Down Expand Up @@ -1407,7 +1407,7 @@ pub mod test {
keys_server_url.as_ref(),
&account.to_did_pkh(),
None,
&MockGetRpcUrl,
Some(&MockGetRpcUrl),
None,
)
.await
Expand Down Expand Up @@ -1456,7 +1456,7 @@ pub mod test {
keys_server_url.as_ref(),
&account.to_did_pkh(),
None,
&MockGetRpcUrl,
Some(&MockGetRpcUrl),
None,
)
.await
Expand Down Expand Up @@ -1505,7 +1505,7 @@ pub mod test {
keys_server_url.as_ref(),
&account.to_did_pkh(),
None,
&MockGetRpcUrl,
Some(&MockGetRpcUrl),
None,
)
.await
Expand Down Expand Up @@ -1554,7 +1554,7 @@ pub mod test {
keys_server_url.as_ref(),
&account.to_did_pkh(),
None,
&MockGetRpcUrl,
Some(&MockGetRpcUrl),
None,
)
.await
Expand Down Expand Up @@ -1622,7 +1622,7 @@ pub mod test {
let cacao_signature = [&signature.to_bytes()[..], &[recovery.to_byte()]].concat();
cacao.s.t = EIP191.to_owned();
cacao.s.s = hex::encode(cacao_signature);
cacao.verify(&MockGetRpcUrl).await.unwrap();
cacao.verify(Some(&MockGetRpcUrl)).await.unwrap();
cacao
};

Expand All @@ -1634,7 +1634,7 @@ pub mod test {
keys_server_url.as_ref(),
&account.to_did_pkh(),
None,
&MockGetRpcUrl,
Some(&MockGetRpcUrl),
None,
)
.await;
Expand Down Expand Up @@ -1716,7 +1716,7 @@ pub mod test {
let cacao_signature = [&signature.to_bytes()[..], &[recovery.to_byte()]].concat();
cacao.s.t = EIP191.to_owned();
cacao.s.s = hex::encode(cacao_signature);
cacao.verify(&MockGetRpcUrl).await.unwrap();
cacao.verify(Some(&MockGetRpcUrl)).await.unwrap();
cacao
};

Expand All @@ -1728,7 +1728,7 @@ pub mod test {
keys_server_url.as_ref(),
&account.to_did_pkh(),
None,
&MockGetRpcUrl,
Some(&MockGetRpcUrl),
None,
)
.await;
Expand Down Expand Up @@ -1802,7 +1802,7 @@ pub mod test {
let cacao_signature = [&signature.to_bytes()[..], &[recovery.to_byte()]].concat();
cacao.s.t = EIP191.to_owned();
cacao.s.s = hex::encode(cacao_signature);
cacao.verify(&MockGetRpcUrl).await.unwrap();
cacao.verify(Some(&MockGetRpcUrl)).await.unwrap();
cacao
};

Expand All @@ -1814,7 +1814,7 @@ pub mod test {
keys_server_url.as_ref(),
&account.to_did_pkh(),
None,
&MockGetRpcUrl,
Some(&MockGetRpcUrl),
None,
)
.await;
Expand Down Expand Up @@ -1878,7 +1878,7 @@ pub mod test {
let cacao_signature = [&signature.to_bytes()[..], &[recovery.to_byte()]].concat();
cacao.s.t = EIP191.to_owned();
cacao.s.s = hex::encode(cacao_signature);
cacao.verify(&MockGetRpcUrl).await.unwrap();
cacao.verify(Some(&MockGetRpcUrl)).await.unwrap();
cacao
};

Expand All @@ -1890,7 +1890,7 @@ pub mod test {
keys_server_url.as_ref(),
&account.to_did_pkh(),
None,
&MockGetRpcUrl,
Some(&MockGetRpcUrl),
None,
)
.await;
Expand Down
7 changes: 7 additions & 0 deletions src/config/deployed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct DeployedConfiguration {
pub relay_url: Url,
pub relay_public_key: String,
pub notify_url: Url,
#[serde(default = "default_blockchain_api_endpoint")]
pub blockchain_api_endpoint: Option<String>,

pub registry_url: Url,
pub registry_auth_token: String,
Expand Down Expand Up @@ -76,6 +78,10 @@ fn default_redis_pool_size() -> u32 {
64
}

fn default_blockchain_api_endpoint() -> Option<String> {
Some("https://rpc.walletconnect.com".to_string())
}

pub fn get_configuration() -> Result<Configuration, NotifyServerError> {
let config = envy::from_env::<DeployedConfiguration>()?;

Expand All @@ -91,6 +97,7 @@ pub fn get_configuration() -> Result<Configuration, NotifyServerError> {
relay_url: config.relay_url,
relay_public_key: config.relay_public_key,
notify_url: config.notify_url,
blockchain_api_endpoint: config.blockchain_api_endpoint,
registry_url: config.registry_url,
registry_auth_token: config.registry_auth_token,
auth_redis_addr_read: config.auth_redis_addr_read,
Expand Down
7 changes: 7 additions & 0 deletions src/config/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct LocalConfiguration {
pub relay_url: Url,
#[serde(default = "default_registry_url")]
pub registry_url: Url,
#[serde(default = "default_blockchain_api_endpoint")]
pub blockchain_api_endpoint: Option<String>,
}

fn default_bind_ip() -> IpAddr {
Expand Down Expand Up @@ -76,6 +78,10 @@ fn default_registry_url() -> Url {
"https://registry.walletconnect.com".parse().unwrap()
}

fn default_blockchain_api_endpoint() -> Option<String> {
Some("https://rpc.walletconnect.com".to_string())
}

pub async fn get_configuration() -> Result<Configuration, NotifyServerError> {
load_dot_env()?;
let config = envy::from_env::<LocalConfiguration>()?;
Expand All @@ -101,6 +107,7 @@ pub async fn get_configuration() -> Result<Configuration, NotifyServerError> {
project_id: config.project_id,
relay_url: config.relay_url,
relay_public_key,
blockchain_api_endpoint: config.blockchain_api_endpoint,
registry_url: config.registry_url,
registry_auth_token: config.registry_auth_token,
auth_redis_addr_read: None,
Expand Down
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Configuration {
pub postgres_max_connections: u32,
pub keypair_seed: String,
pub project_id: ProjectId,
pub blockchain_api_endpoint: Option<String>,
/// Relay URL e.g. https://relay.walletconnect.com
pub relay_url: Url,
pub relay_public_key: String,
Expand Down
16 changes: 12 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ use {
},
aws_config::meta::region::RegionProviderChain,
aws_sdk_s3::{config::Region, Client as S3Client},
blockchain_api::BlockchainApiProvider,
error::NotifyServerError,
rand::{rngs::StdRng, SeedableRng},
relay_rpc::auth::{
cacao::signature::eip1271::blockchain_api::BlockchainApiProvider, ed25519_dalek::SigningKey,
},
relay_rpc::auth::ed25519_dalek::SigningKey,
sqlx::postgres::PgPoolOptions,
std::sync::Arc,
tokio::{select, sync::broadcast},
Expand Down Expand Up @@ -99,6 +98,15 @@ pub async fn bootstrap(

let (relay_mailbox_clearer_tx, relay_mailbox_clearer_rx) = tokio::sync::mpsc::channel(1000);

let provider = if let Some(blockchain_api_endpoint) = &config.blockchain_api_endpoint {
Some(
BlockchainApiProvider::new(config.project_id.clone(), blockchain_api_endpoint.parse()?)
.await?,
)
} else {
None
};

let state = Arc::new(AppState::new(
analytics.clone(),
config.clone(),
Expand All @@ -111,7 +119,7 @@ pub async fn bootstrap(
registry,
relay_mailbox_clearer_tx,
config.clock,
BlockchainApiProvider::new(config.project_id),
provider,
)?);

let relay_renewal_job = relay_renewal_job::start(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R
&request_auth.ksu,
&request_auth.sub,
state.redis.as_ref(),
&state.provider,
state.provider.as_ref(),
state.metrics.as_ref(),
)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R
&request_auth.ksu,
&request_auth.sub,
state.redis.as_ref(),
&state.provider,
state.provider.as_ref(),
state.metrics.as_ref(),
)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R
&request_auth.ksu,
&request_auth.sub,
state.redis.as_ref(),
&state.provider,
state.provider.as_ref(),
state.metrics.as_ref(),
)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R
&request_auth.ksu,
&request_auth.sub,
state.redis.as_ref(),
&state.provider,
state.provider.as_ref(),
state.metrics.as_ref(),
)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub async fn handle(msg: RelayIncomingMessage, state: &AppState) -> Result<(), R
&request_auth.ksu,
&request_auth.sub,
state.redis.as_ref(),
&state.provider,
state.provider.as_ref(),
state.metrics.as_ref(),
)
.await?
Expand Down
10 changes: 4 additions & 6 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ use {
registry::{storage::redis::Redis, Registry},
Configuration,
},
blockchain_api::BlockchainApiProvider,
build_info::BuildInfo,
relay_client::http::Client,
relay_rpc::{
auth::{
cacao::signature::eip1271::blockchain_api::BlockchainApiProvider,
ed25519_dalek::{SigningKey, VerifyingKey},
},
auth::ed25519_dalek::{SigningKey, VerifyingKey},
domain::{DecodedClientId, DidKey},
rpc::Receipt,
},
Expand All @@ -39,7 +37,7 @@ pub struct AppState {
pub notify_keys: NotifyKeys,
pub relay_mailbox_clearer_tx: Sender<Receipt>,
pub clock: Clock,
pub provider: BlockchainApiProvider,
pub provider: Option<BlockchainApiProvider>,
}

build_info::build_info!(fn build_info);
Expand All @@ -58,7 +56,7 @@ impl AppState {
registry: Arc<Registry>,
relay_mailbox_clearer_tx: Sender<Receipt>,
clock: Clock,
provider: BlockchainApiProvider,
provider: Option<BlockchainApiProvider>,
) -> Result<Self, NotifyServerError> {
let build_info: &BuildInfo = build_info();

Expand Down
1 change: 1 addition & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ impl AsyncTestContext for NotifyServerContext {
relay_url,
relay_public_key,
notify_url: notify_url.clone(),
blockchain_api_endpoint: None,
registry_auth_token: "".to_owned(),
auth_redis_addr_read: Some("redis://localhost:6378/0".to_owned()),
auth_redis_addr_write: Some("redis://localhost:6378/0".to_owned()),
Expand Down
Loading