Skip to content

Commit

Permalink
Moved unnecessary items outside of retry loop (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaoticTempest authored Oct 5, 2023
1 parent e64f08f commit b35364e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
36 changes: 20 additions & 16 deletions mpc-recovery/src/leader_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,26 @@ async fn process_new_account<T: OAuthTokenVerifier>(
let oidc_token_claims = T::verify_token(&request.oidc_token, &state.partners.oidc_providers())
.await
.map_err(LeaderNodeError::OidcVerificationFailed)?;

let internal_acc_id = oidc_token_claims.get_internal_account_id();

// TODO: move error message from here to this place
let partner = state
.partners
.find(&oidc_token_claims.iss, &oidc_token_claims.aud)?;

let mpc_user_recovery_pk = nar::retry(|| async {
get_user_recovery_pk(
&state.reqwest_client,
&state.sign_nodes,
&request.oidc_token,
&request.user_credentials_frp_signature,
&request.frp_public_key,
)
.await
})
.await?;

// FIXME: waiting on https://github.com/near/mpc-recovery/issues/193
// FRP check to prevent invalid PKs and Sigs from getting through. Used to circumvent the
// atomicity of account creation between relayer and the sign nodes. The atomicity
Expand All @@ -371,15 +389,6 @@ async fn process_new_account<T: OAuthTokenVerifier>(
.await
.map_err(LeaderNodeError::RelayerError)?;

let mpc_user_recovery_pk = get_user_recovery_pk(
&state.reqwest_client,
&state.sign_nodes,
&request.oidc_token,
&request.user_credentials_frp_signature,
&request.frp_public_key,
)
.await?;

// Add recovery key to create account options
let mut new_account_options = request.create_account_options.clone();
match new_account_options.full_access_keys {
Expand Down Expand Up @@ -412,14 +421,9 @@ async fn process_new_account<T: OAuthTokenVerifier>(
signed_delegate_action,
};

// TODO: move error message from here to this place
let partner = state
.partners
.find(&oidc_token_claims.iss, &oidc_token_claims.aud)?;

let result = state
.client
.create_account_atomic(request, partner.relayer)
.create_account_atomic(request, &partner.relayer)
.await;

match result {
Expand All @@ -430,7 +434,7 @@ async fn process_new_account<T: OAuthTokenVerifier>(
);
Ok(NewAccountResponse::Ok {
create_account_options: new_account_options,
user_recovery_public_key: mpc_user_recovery_pk,
user_recovery_public_key: mpc_user_recovery_pk.clone(),
near_account_id: new_user_account_id.clone(),
})
}
Expand Down
4 changes: 2 additions & 2 deletions mpc-recovery/src/relayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ impl NearRpcAndRelayerClient {
pub async fn create_account_atomic(
&self,
request: CreateAccountAtomicRequest,
relayer: DelegateActionRelayer,
relayer: &DelegateActionRelayer,
) -> Result<(), RelayerError> {
let mut req = Request::builder()
.method(Method::POST)
.uri(format!("{}/create_account_atomic", relayer.url))
.header("content-type", "application/json");

if let Some(api_key) = relayer.api_key {
if let Some(api_key) = &relayer.api_key {
req = req.header("x-api-key", api_key);
};

Expand Down

0 comments on commit b35364e

Please sign in to comment.