Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
chore: update to latest relay_rpc version (#45)
Browse files Browse the repository at this point in the history
* chore: update to latest relay_rpc version

* fix(ci): rust-lang/rust#113152 (comment)
  • Loading branch information
chris13524 authored Jul 3, 2023
1 parent 92a2c77 commit 8160450
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
12 changes: 8 additions & 4 deletions src/handlers/get_registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ use {
state::{AppState, CachedRegistration},
},
axum::{extract::State, Json},
relay_rpc::auth::Jwt,
relay_rpc::{
domain::ClientId,
jwt::{JwtBasicClaims, VerifyableClaims},
},
std::sync::Arc,
};

pub async fn handler(
State(state): State<Arc<AppState>>,
AuthBearer(token): AuthBearer,
) -> Result<Json<RegisterPayload>, error::Error> {
let client_id = Jwt(token).decode(&state.auth_aud.clone())?.to_string();
let client_id: Arc<str> = 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
Expand All @@ -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(),
})
Expand Down
9 changes: 7 additions & 2 deletions src/handlers/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -25,7 +28,9 @@ pub async fn handler(
AuthBearer(token): AuthBearer,
Json(body): Json<RegisterPayload>,
) -> error::Result<Response> {
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
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8160450

Please sign in to comment.