From 81604508327abed45979a3217b9b1d8d44f9e4b5 Mon Sep 17 00:00:00 2001 From: Chris Smith <1979423+chris13524@users.noreply.github.com> Date: Mon, 3 Jul 2023 10:59:49 -0400 Subject: [PATCH] chore: update to latest relay_rpc version (#45) * chore: update to latest relay_rpc version * fix(ci): https://github.com/rust-lang/rust/issues/113152#issuecomment-1612580132 --- Cargo.lock | 7 ++++--- Cargo.toml | 2 +- src/error.rs | 2 +- src/handlers/get_registration.rs | 12 ++++++++---- src/handlers/register.rs | 9 +++++++-- tests/integration.rs | 2 +- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7dd6841..866a9e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2069,9 +2069,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.53" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" +checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" dependencies = [ "unicode-ident", ] @@ -2317,7 +2317,7 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "relay_rpc" version = "0.1.0" -source = "git+https://github.com/WalletConnect/WalletConnectRust.git?rev=7f08502440842308cde74bb7f4cddc4bbd7d6fbc#7f08502440842308cde74bb7f4cddc4bbd7d6fbc" +source = "git+https://github.com/WalletConnect/WalletConnectRust.git?rev=5f4dd3cbf4a67e40c47503706f8e0ae8d8bdd435#5f4dd3cbf4a67e40c47503706f8e0ae8d8bdd435" dependencies = [ "bs58", "chrono", @@ -2331,6 +2331,7 @@ dependencies = [ "serde", "serde-aux", "serde_json", + "sha2 0.10.6", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index bbcf9f1..f30efe8 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ tower-http = { version = "0.4.0", features = ["trace", "cors"] } hyper = "0.14" # WalletConnect -relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", rev = "7f08502440842308cde74bb7f4cddc4bbd7d6fbc" } +relay_rpc = { git = "https://github.com/WalletConnect/WalletConnectRust.git", rev = "5f4dd3cbf4a67e40c47503706f8e0ae8d8bdd435" } # Database wither = { git = "https://github.com/WalletConnect/wither.git", rev = "6a70e74", features = ["bson-chrono-0_4"] } diff --git a/src/error.rs b/src/error.rs index 1202efd..065b428 100644 --- a/src/error.rs +++ b/src/error.rs @@ -85,7 +85,7 @@ pub enum Error { InternalServerError, #[error(transparent)] - JwtError(#[from] relay_rpc::auth::JwtVerificationError), + JwtError(#[from] relay_rpc::jwt::JwtError), #[error(transparent)] AuthError(#[from] relay_rpc::auth::Error), diff --git a/src/handlers/get_registration.rs b/src/handlers/get_registration.rs index cfcf6af..06957f1 100644 --- a/src/handlers/get_registration.rs +++ b/src/handlers/get_registration.rs @@ -7,7 +7,10 @@ use { state::{AppState, CachedRegistration}, }, axum::{extract::State, Json}, - relay_rpc::auth::Jwt, + relay_rpc::{ + domain::ClientId, + jwt::{JwtBasicClaims, VerifyableClaims}, + }, std::sync::Arc, }; @@ -15,8 +18,9 @@ pub async fn handler( State(state): State>, AuthBearer(token): AuthBearer, ) -> Result, error::Error> { - let client_id = Jwt(token).decode(&state.auth_aud.clone())?.to_string(); - let client_id: Arc = Arc::from(client_id); + let claims = JwtBasicClaims::try_from_str(&token)?; + claims.verify_basic(&state.auth_aud, None)?; + let client_id = ClientId::from(claims.iss); increment_counter!(state.metrics, registration_cache_invalidation); state @@ -31,7 +35,7 @@ pub async fn handler( state .registration_cache - .insert(client_id, CachedRegistration { + .insert(client_id.into_value(), CachedRegistration { tags: registration.tags.clone(), relay_url: registration.relay_url.clone(), }) diff --git a/src/handlers/register.rs b/src/handlers/register.rs index 5c549db..eb0f4ef 100644 --- a/src/handlers/register.rs +++ b/src/handlers/register.rs @@ -8,7 +8,10 @@ use { state::{AppState, CachedRegistration}, }, axum::{extract::State, Json}, - relay_rpc::auth::Jwt, + relay_rpc::{ + domain::ClientId, + jwt::{JwtBasicClaims, VerifyableClaims}, + }, serde::{Deserialize, Serialize}, std::sync::Arc, }; @@ -25,7 +28,9 @@ pub async fn handler( AuthBearer(token): AuthBearer, Json(body): Json, ) -> error::Result { - let client_id = Jwt(token).decode(&state.auth_aud.clone())?; + let claims = JwtBasicClaims::try_from_str(&token)?; + claims.verify_basic(&state.auth_aud, None)?; + let client_id = ClientId::from(claims.iss); state .registration_store diff --git a/tests/integration.rs b/tests/integration.rs index 2a6c10a..4f81d43 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -35,7 +35,7 @@ fn get_client_jwt() -> (String, ClientId) { let random_client_id = DecodedClientId(*keypair.public_key().as_bytes()); let client_id = ClientId::from(random_client_id); - let jwt = relay_rpc::auth::AuthToken::new(client_id.value().clone()) + let jwt = relay_rpc::auth::AuthToken::new(client_id.to_string()) .aud(TEST_RELAY_URL.to_string()) .as_jwt(&keypair) .unwrap()