Skip to content

Commit

Permalink
feat: account salt end point
Browse files Browse the repository at this point in the history
  • Loading branch information
zkfriendly committed Nov 30, 2024
1 parent d47a108 commit c9584c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
21 changes: 20 additions & 1 deletion packages/relayer/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ use crate::{
command::parse_command_template,
mail::{handle_email, handle_email_event, EmailEvent},
model::{create_request, get_request, update_request, RequestStatus},
schema::EmailTxAuthSchema,
schema::{AccountSaltSchema, EmailTxAuthSchema},
RelayerState,
};

use relayer_utils::calculate_account_salt;

pub async fn health_checker_handler() -> impl IntoResponse {
const MESSAGE: &str = "Hello from ZK Email!";

Expand Down Expand Up @@ -278,3 +280,20 @@ pub async fn get_status_handler(

Ok((StatusCode::OK, Json(response)))
}

pub async fn account_salt_handler(
State(relayer_state): State<Arc<RelayerState>>,
Json(body): Json<AccountSaltSchema>,
) -> Result<impl IntoResponse, (StatusCode, Json<Value>)> {
// use relayer_utils::get_account_salt
let account_salt =
relayer_utils::calculate_account_salt(&body.email_address, &body.account_code);

let response = json!({
"email_address": body.email_address,
"account_code": body.account_code,
"account_salt": account_salt,
});

Ok((StatusCode::OK, Json(response)))
}
6 changes: 5 additions & 1 deletion packages/relayer/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ use axum::{
};

use crate::{
handler::{get_status_handler, health_checker_handler, receive_email_handler, submit_handler},
handler::{
account_salt_handler, get_status_handler, health_checker_handler, receive_email_handler,
submit_handler,
},
RelayerState,
};

pub fn create_router(relayer_state: Arc<RelayerState>) -> Router {
Router::new()
.route("/api/healthz", get(health_checker_handler))
.route("/api/submit", post(submit_handler))
.route("/api/accountSalt", post(account_salt_handler))
.route("/api/receiveEmail", post(receive_email_handler))
.route("/api/status/:id", get(get_status_handler))
.with_state(relayer_state)
Expand Down
7 changes: 7 additions & 0 deletions packages/relayer/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ pub struct EmailTxAuthSchema {
pub body: String,
pub chain: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct AccountSaltSchema {
pub account_code: String,
pub email_address: String,
}

0 comments on commit c9584c8

Please sign in to comment.