Skip to content

Commit

Permalink
Change the signed message definition in oauth.
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Jul 10, 2024
1 parent 21e8afd commit 3071eab
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 55 deletions.
4 changes: 2 additions & 2 deletions packages/oauth-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zk-email/oauth-sdk",
"version": "0.1.1",
"version": "0.1.2",
"description": "",
"main": "dist",
"scripts": {
Expand All @@ -25,4 +25,4 @@
"axios": "^1.7.2",
"viem": "^2.17.2"
}
}
}
3 changes: 2 additions & 1 deletion packages/oauth-sdk/src/oauthClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export default class OauthClient<chain extends Chain> {
if (this.userEmailAddr === null) {
throw new Error("Not setup yet")
}
const signedMsg = `${this.relayerApis.relayerHost.replace(/^https?:\/\//, '')}/api/epheAddrStatus/${requestId}`;
const relayerEmailAddr = await this.relayerApis.getRelayerEmailAddr();
const signedMsg = `${relayerEmailAddr}:/api/epheAddrStatus/${requestId}`;
console.log(`signedMsg: ${signedMsg}`);
const signature = await this.epheClient.signMessage({
message: signedMsg,
Expand Down
62 changes: 12 additions & 50 deletions packages/oauth-sdk/src/relayerApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ export default class RelayerApis {
}


public async getWalletAddress(
emailAddr: string,
accountCode: string
): Promise<Address> {
const url = `${this.relayerHost}/api/getWalletAddress`;
const res = await axios.post(url, { email_addr: emailAddr, account_code: accountCode });
// public async getWalletAddress(
// emailAddr: string,
// accountCode: string
// ): Promise<Address> {
// const url = `${this.relayerHost}/api/getWalletAddress`;
// const res = await axios.post(url, { email_addr: emailAddr, account_code: accountCode });
// return res.data;
// }

public async getRelayerEmailAddr(): Promise<string> {
const url = `${this.relayerHost}/api/relayerEmailAddr`;
const res = await axios.get(url);
return res.data;
}

Expand All @@ -26,12 +32,6 @@ export default class RelayerApis {
return res.data === "true";
}

// public async recoverAccountCode(
// emailAddr: string,
// ): Promise<void> {
// const url = `${this.relayerHost}/api/recoverAccountCode`;
// await axios.post(url, { email_addr: emailAddr });
// }

public async signupOrIn(
emailAddr: string,
Expand Down Expand Up @@ -79,44 +79,6 @@ export default class RelayerApis {
return res.data;
}

// public async signin(
// emailAddr: string,
// username: string,
// nonce: string,
// expiry_time: number | null,
// token_allowances: [number, string][] | null
// ): Promise<string> {
// const url = `${this.relayerHost}/api/login`;
// const requestData: {
// email_addr: string;
// username: string;
// nonce: string;
// expiry_time?: number;
// token_allowances?: [number, string][];
// } = {
// email_addr: emailAddr,
// username,
// nonce,
// };
// if (expiry_time !== null) {
// requestData.expiry_time = expiry_time;
// }
// if (token_allowances !== null) {
// requestData.token_allowances = token_allowances;
// }
// const res = await axios.post(url, requestData);
// return res.data;
// }

// public async registerEpheAddr(
// walletAddr: Address,
// epheAddr: Address,
// signature: string
// ): Promise<string> {
// const url = `${this.relayerHost}/api/registerEpheAddr`;
// const res = await axios.post(url, { wallet_addr: walletAddr, ephe_addr: epheAddr, signature });
// return res.data;
// }

public async executeEphemeralTx(
walletAddr: Address,
Expand Down
6 changes: 4 additions & 2 deletions packages/relayer/src/modules/web_server/rest_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use lettre::error;

use crate::{
error, handle_email, handle_email_event, render_html, trace, wallet::EphemeralTx, EmailMessage,
EmailWalletEvent,
EmailWalletEvent, RELAYER_EMAIL_ADDRESS,
};
use ethers::{
etherscan::account, types::{Address, Bytes, Signature, U256}, utils::{hash_message, keccak256, to_checksum}
Expand Down Expand Up @@ -500,6 +500,8 @@ pub async fn signup_or_in_api_fn(payload: String) -> Result<(u32, EmailMessage)>
Some(field2hex(&account_code.0)[2..].to_string()),
)
};
trace!(LOG, "Account code: {:?}", account_code);
trace!(LOG, "Code in email: {:?}", code_in_email);
let account_salt = AccountSalt::new(
&PaddedEmailAddr::from_email_addr(&request.email_addr),
account_code,
Expand Down Expand Up @@ -701,7 +703,7 @@ pub async fn ephe_addr_status_api_fn(payload: String) -> Result<EpheAddrStatusRe
let ephe_addr = Address::from_str(&ephe_addr_str)?;
trace!(LOG, "Ephe addr: {}", ephe_addr);
// verify if request.signature
let signed_msg = format!("{}/api/epheAddrStatus/{}", WEB_SERVER_ADDRESS.get().unwrap(),request.request_id);
let signed_msg = format!("{}:/api/epheAddrStatus/{}", RELAYER_EMAIL_ADDRESS.get().unwrap(),request.request_id);
trace!(LOG, "Signed msg: {}", signed_msg);
let signed_msg_hash = hash_message(&signed_msg);
let signature = Signature::from_str(&request.signature)?;
Expand Down
7 changes: 7 additions & 0 deletions packages/relayer/src/modules/web_server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ async fn unclaim(payload: UnclaimRequest) -> Result<String> {
pub async fn run_server() -> Result<()> {
let addr = WEB_SERVER_ADDRESS.get().unwrap();
let mut app = Router::new()
.route(
"/api/relayerEmailAddr",
axum::routing::get(move || async move {
let email_addr = RELAYER_EMAIL_ADDRESS.get().unwrap();
email_addr.clone()
}),
)
.route(
"/api/emailAddrCommit",
axum::routing::post(move |payload: String| async move {
Expand Down

0 comments on commit 3071eab

Please sign in to comment.