From 7feece1ff888080efac79e868cf16c03b8d8a688 Mon Sep 17 00:00:00 2001 From: Mateusz Chudkowski Date: Mon, 9 Sep 2024 22:53:16 +0200 Subject: [PATCH] pub key as prefix hex --- prover-sdk/src/sdk_builder.rs | 2 +- prover/src/auth/nonce.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/prover-sdk/src/sdk_builder.rs b/prover-sdk/src/sdk_builder.rs index b5e3db4..0df8a39 100644 --- a/prover-sdk/src/sdk_builder.rs +++ b/prover-sdk/src/sdk_builder.rs @@ -31,7 +31,7 @@ impl ProverSDKBuilder { } pub async fn get_nonce(&self, public_key: &VerifyingKey) -> Result { let nonce_req = GenerateNonceRequest { - public_key: serde_json::to_string(&public_key)?, + public_key: prefix_hex::encode(public_key.to_bytes()), }; let response = self .client diff --git a/prover/src/auth/nonce.rs b/prover/src/auth/nonce.rs index 89a93ac..9526136 100644 --- a/prover/src/auth/nonce.rs +++ b/prover/src/auth/nonce.rs @@ -1,4 +1,5 @@ use super::authorizer::AuthorizationProvider; +use crate::auth::auth_errors::AuthorizerError; use crate::server::AppState; use crate::{auth::auth_errors::AuthError, errors::ProverError}; use axum::{ @@ -60,7 +61,9 @@ pub async fn generate_nonce( State(state): State, Query(params): Query, ) -> Result, ProverError> { - let key: VerifyingKey = serde_json::from_str(¶ms.public_key)?; + let verifying_key_bytes = prefix_hex::decode::>(params.public_key) + .map_err(|e| AuthorizerError::PrefixHexConversionError(e.to_string()))?; + let key = VerifyingKey::from_bytes(&verifying_key_bytes.try_into()?)?; if !state.authorizer.is_authorized(key).await? { return Err(ProverError::Auth(AuthError::Unauthorized)); }