Skip to content

Commit ddc9595

Browse files
authored
Use user_uid over user_email ubiquitously (#3386)
* init * clippy * update * verify email and id matches
1 parent eb5ac80 commit ddc9595

File tree

20 files changed

+192
-68
lines changed

20 files changed

+192
-68
lines changed

common/primitives/core/src/identity.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ impl Identity {
577577
Web2IdentityType::Google => {
578578
Identity::Google(IdentityString::new(handle.as_bytes().to_vec()))
579579
}
580+
Web2IdentityType::Pumpx => {
581+
Identity::Pumpx(IdentityString::new(handle.as_bytes().to_vec()))
582+
}
580583
}
581584
}
582585
}
@@ -588,6 +591,7 @@ pub enum Web2IdentityType {
588591
Github,
589592
Email,
590593
Google,
594+
Pumpx,
591595
}
592596

593597
impl From<ed25519::Public> for Identity {

tee-worker/client-api/parachain-api/prepare-build/interfaces/omniExecutor/definitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ export default {
3434
__Unused17: "Null",
3535
__Unused18: "Null",
3636
__Unused19: "Null",
37-
PumpxRequestJwt: "(Identity, Option<String>, Option<String>, Option<String>)",
37+
PumpxRequestJwt: "(Identity, String, Option<String>, Option<String>, Option<String>)",
3838
},
3939
},
4040
OmniAuth: {
4141
_enum: {
4242
Web3: "(HeimaMultiSignature)",
43-
Email: "(Text)",
43+
Email: "(Text, Text)",
4444
AuthToken: "(Text)",
4545
OAuth2: "(OAuth2Data)",
4646
},

tee-worker/omni-executor/executor-core/src/native_task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub enum NativeTask {
3939

4040
// pumpx specific, starting from index 20
4141
#[codec(index = 20)]
42-
PumpxRequestJwt(Identity, Option<String>, GoogleCode, Option<String>),
42+
PumpxRequestJwt(Identity, String, Option<String>, GoogleCode, Option<String>),
4343
#[codec(index = 21)]
4444
PumpxExportWallet(Identity, GoogleCode, PumpxChainId, PumxWalletIndex, String),
4545
#[codec(index = 22)]

tee-worker/omni-executor/executor-primitives/src/auth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub type VerificationCode = String;
66
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)]
77
pub enum OmniAuth {
88
Web3(HeimaMultiSignature),
9-
Email(VerificationCode),
9+
Email(String, VerificationCode),
1010
AuthToken(String),
1111
OAuth2(OAuth2Data),
1212
}
@@ -15,7 +15,7 @@ impl From<OmniAuth> for OmniAccountAuthType {
1515
fn from(value: OmniAuth) -> Self {
1616
match value {
1717
OmniAuth::Web3(_) => Self::Web3,
18-
OmniAuth::Email(_) => Self::Email,
18+
OmniAuth::Email(..) => Self::Email,
1919
OmniAuth::OAuth2(_) => Self::OAuth2,
2020
OmniAuth::AuthToken(_) => Self::AuthToken,
2121
}

tee-worker/omni-executor/heima/authentication/src/auth_token.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ mod tests {
105105
.expect("Failed to calculate expiration")
106106
.timestamp();
107107

108-
let email_identity = Identity::from_web2_account("test@test.com", Web2IdentityType::Email);
109-
let omni_account = email_identity.to_omni_account();
108+
let uid = Identity::from_web2_account("012345", Web2IdentityType::Pumpx);
109+
let omni_account = uid.to_omni_account();
110110

111111
let claims = AuthTokenClaims::new(
112112
omni_account.to_hex(),
@@ -128,8 +128,8 @@ mod tests {
128128
RsaPrivateKey::new(&mut rng, 2048).expect("Failed to generate private key");
129129
let private_key = rsa_private_key.to_pkcs1_der().unwrap();
130130

131-
let email_identity = Identity::from_web2_account("test@test.com", Web2IdentityType::Email);
132-
let omni_account = email_identity.to_omni_account();
131+
let uid = Identity::from_web2_account("012345", Web2IdentityType::Pumpx);
132+
let omni_account = uid.to_omni_account();
133133

134134
let claims = AuthTokenClaims::new(
135135
omni_account.to_hex(),
@@ -156,8 +156,8 @@ mod tests {
156156
.expect("Failed to calculate expiration")
157157
.timestamp();
158158

159-
let email_identity = Identity::from_web2_account("test@test.com", Web2IdentityType::Email);
160-
let omni_account = email_identity.to_omni_account();
159+
let uid = Identity::from_web2_account("012345", Web2IdentityType::Pumpx);
160+
let omni_account = uid.to_omni_account();
161161

162162
let claims = AuthTokenClaims::new(
163163
omni_account.to_hex(),

tee-worker/omni-executor/native-task-handler/src/lib.rs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use executor_crypto::{
1111
jwt,
1212
};
1313
use executor_primitives::{
14-
utils::hex::ToHexPrefixed, Identity, Intent, MemberAccount, OmniAccountAuthType, ValidationData,
14+
utils::hex::ToHexPrefixed, Identity, Intent, MemberAccount, OmniAccountAuthType,
15+
ValidationData, Web2IdentityType,
1516
};
1617
use executor_storage::{MemberOmniAccountStorage, PumpxJwtStorage, Storage, StorageDB};
1718
use heima_authentication::auth_token::*;
@@ -559,36 +560,29 @@ async fn handle_native_task<
559560
let tx = ctx.transaction_signer.sign(dispatch_as_omni_account_call).await;
560561
(response_sender, tx)
561562
},
562-
NativeTask::PumpxRequestJwt(sender, invite_code, google_code, language) => {
563-
let email = match sender {
564-
Identity::Email(ref identity_string) => {
565-
let Ok(email) = std::str::from_utf8(identity_string.inner_ref()) else {
566-
send_error(
567-
"Invalid email identity".to_string(),
568-
response_sender,
569-
NativeTaskError::InvalidMemberIdentity,
570-
);
571-
return;
572-
};
573-
email.to_string()
574-
},
575-
_ => {
576-
send_error(
577-
"Unsupported identity type".to_string(),
578-
response_sender,
579-
NativeTaskError::UnsupportedIdentityType,
580-
);
581-
return;
582-
},
583-
};
563+
NativeTask::PumpxRequestJwt(_sender, email, invite_code, google_code, language) => {
584564
let expires_at = Utc::now()
585565
.checked_add_days(Days::new(AUTH_TOKEN_EXPIRATION_DAYS))
586566
.expect("Failed to calculate expiration")
587567
.timestamp();
588568
let auth_options = AuthOptions { expires_at };
589569

570+
let Ok(res) = ctx.pumpx_api.get_account_user_id(email.clone()).await else {
571+
send_error(
572+
"Failed to get_account_user_id".to_string(),
573+
response_sender,
574+
NativeTaskError::PumpxApiError(PumpxApiError::GetAccountUserIdFailed),
575+
);
576+
return;
577+
};
578+
579+
let user_id = res.user_id;
580+
log::debug!("get_account_user_id ok, email: {}, user_id: {}", email, user_id);
581+
let omni_account =
582+
Identity::from_web2_account(&user_id, Web2IdentityType::Pumpx).to_omni_account();
583+
590584
let access_token_claims = AuthTokenClaims::new(
591-
sender.to_omni_account().to_hex(),
585+
omni_account.to_hex(),
592586
AUTH_TOKEN_ACCESS_TYPE.to_string(),
593587
auth_options.clone(),
594588
);
@@ -604,7 +598,7 @@ async fn handle_native_task<
604598

605599
let storage = PumpxJwtStorage::new(ctx.storage_db.clone());
606600
if storage
607-
.insert((sender.to_omni_account(), AUTH_TOKEN_ACCESS_TYPE), access_token.clone())
601+
.insert((omni_account.clone(), AUTH_TOKEN_ACCESS_TYPE), access_token.clone())
608602
.is_err()
609603
{
610604
log::error!(
@@ -615,7 +609,14 @@ async fn handle_native_task<
615609

616610
let Ok(backend_response) = ctx
617611
.pumpx_api
618-
.user_connect(&access_token, email.clone(), invite_code, google_code, language)
612+
.user_connect(
613+
&access_token,
614+
user_id.clone(),
615+
email.clone(),
616+
invite_code,
617+
google_code,
618+
language,
619+
)
619620
.await
620621
else {
621622
send_error(
@@ -626,7 +627,7 @@ async fn handle_native_task<
626627
return;
627628
};
628629
let id_token_claims = AuthTokenClaims::new(
629-
sender.to_omni_account().to_hex(),
630+
omni_account.to_hex(),
630631
AUTH_TOKEN_ID_TYPE.to_string(),
631632
auth_options,
632633
);
@@ -639,10 +640,7 @@ async fn handle_native_task<
639640
return;
640641
};
641642

642-
if storage
643-
.insert((sender.to_omni_account(), AUTH_TOKEN_ID_TYPE), id_token.clone())
644-
.is_err()
645-
{
643+
if storage.insert((omni_account, AUTH_TOKEN_ID_TYPE), id_token.clone()).is_err() {
646644
log::error!("Failed to insert pumpx_{}_jwt_token into storage", AUTH_TOKEN_ID_TYPE);
647645
};
648646

tee-worker/omni-executor/native-task-handler/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub enum PumpxApiError {
4949
CreateTransferUnsignedTxFailed,
5050
SendTransferTxFailed,
5151
CreateTransferTxFailed,
52+
GetAccountUserIdFailed,
5253
}
5354

5455
#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)]

tee-worker/omni-executor/pumpx/src/pumpx_api/mod.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use types::{
55
AddWalletResponse, CreateCrossOrderBody, CreateLimitOrderBody, CreateMarketOrderTxBody,
66
CreateMarketOrderTxResponse, CreateMarketOrderUnsignedTxBody,
77
CreateMarketOrderUnsignedTxResponse, CreateTransferTxBody, CreateTransferTxResponse,
8-
CreateTransferUnsignedTxBody, CreateTransferUnsignedTxResponse, CrossFailBody, GetGasInfoBody,
9-
GetGasInfoResponse, GoogleCode, OrderInfoResponse, SendOrderTxBody, SendOrderTxResponse,
10-
SendTransferTxBody, SendTransferTxResponse, UserConnectBody, UserConnectResponse,
11-
UserTradeInfoResponse, VerifyGoogleCodeResponse,
8+
CreateTransferUnsignedTxBody, CreateTransferUnsignedTxResponse, CrossFailBody,
9+
GetAccountUserIdBody, GetAccountUserIdResponseData, GetGasInfoBody, GetGasInfoResponse,
10+
GoogleCode, OrderInfoResponse, SendOrderTxBody, SendOrderTxResponse, SendTransferTxBody,
11+
SendTransferTxResponse, UserConnectBody, UserConnectResponse, UserTradeInfoResponse,
12+
VerifyGoogleCodeResponse,
1213
};
1314
use url::Url;
1415

@@ -37,13 +38,14 @@ impl PumpxApi {
3738
pub async fn user_connect(
3839
&self,
3940
access_token: &str,
41+
user_id: String,
4042
email: String,
4143
invite_code: Option<String>,
4244
google_code: String,
4345
language: Option<String>,
4446
) -> Result<UserConnectResponse, Error> {
4547
let endpoint = format!("{}/v3/account/user_connect", self.base_url);
46-
let body = UserConnectBody { email: email.clone(), invite_code, google_code };
48+
let body = UserConnectBody { email, invite_code, google_code, user_id };
4749

4850
let response = self
4951
.http_client
@@ -426,4 +428,13 @@ impl PumpxApi {
426428
.json()
427429
.await
428430
}
431+
432+
pub async fn get_account_user_id(
433+
&self,
434+
email: String,
435+
) -> Result<GetAccountUserIdResponseData, Error> {
436+
let endpoint = format!("{}/v3/account/get_account_user_id", self.base_url);
437+
let body = GetAccountUserIdBody { email };
438+
self.http_client.get(&endpoint).json(&body).send().await?.json().await
439+
}
429440
}

tee-worker/omni-executor/pumpx/src/pumpx_api/types.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub struct UserConnectBody {
120120
pub email: String,
121121
pub invite_code: Option<String>,
122122
pub google_code: String,
123+
pub user_id: String,
123124
}
124125

125126
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
@@ -333,3 +334,16 @@ pub struct GasInfo {
333334
pub fast_price: String,
334335
pub super_fast_price: String,
335336
}
337+
338+
// /v3/account/get_account_user_id
339+
#[derive(Serialize, Debug)]
340+
#[serde(rename_all = "camelCase")]
341+
pub struct GetAccountUserIdBody {
342+
pub email: String,
343+
}
344+
345+
#[derive(Serialize, Deserialize, Encode, Decode, Debug, PartialEq, Eq, Clone)]
346+
#[serde(rename_all = "camelCase")]
347+
pub struct GetAccountUserIdResponseData {
348+
pub user_id: String,
349+
}

tee-worker/omni-executor/rpc-server/src/error_code.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const AUTH_TOKEN_CREATION_FAILED_CODE: i32 = -32007;
1515
const INVALID_MEMBER_IDENTITY_CODE: i32 = -32008;
1616
const VALIDATION_DATA_VERIFICATION_FAILED_CODE: i32 = -32009;
1717
const UNSUPPORTED_IDENTITY_TYPE_CODE: i32 = -32010;
18+
pub const USER_EMAIL_ID_MISMATCH_CODE: i32 = -32011;
1819

1920
const PUMPX_API_GOOGLE_CODE_VERIFICATION_FAILED_CODE: i32 = -32031;
2021
const PUMPX_API_USER_CONNECTION_FAILED_CODE: i32 = -32032;
@@ -24,6 +25,7 @@ const PUMPX_API_CREATE_TRANSFER_UNSIGNED_TX_FAILED_CODE: i32 = -32035;
2425
const PUMPX_API_SEND_TRANSFER_TX_FAILED_CODE: i32 = -32036;
2526
const PUMPX_API_INVALID_INPUT_FAILED_CODE: i32 = -32037;
2627
const PUMPX_API_CREATE_TRANSFER_TX_FAILED_CODE: i32 = -32038;
28+
pub const PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE: i32 = -32039;
2729

2830
const PUMPX_SIGNER_REQUEST_SIGNATURE_FAILED_CODE: i32 = -32050;
2931

@@ -51,6 +53,7 @@ pub fn get_native_task_error_code(error: &NativeTaskError) -> i32 {
5153
PumpxApiError::SendTransferTxFailed => PUMPX_API_SEND_TRANSFER_TX_FAILED_CODE,
5254
PumpxApiError::InvalidInput => PUMPX_API_INVALID_INPUT_FAILED_CODE,
5355
PumpxApiError::CreateTransferTxFailed => PUMPX_API_CREATE_TRANSFER_TX_FAILED_CODE,
56+
PumpxApiError::GetAccountUserIdFailed => PUMPX_API_GET_ACCOUNT_USER_ID_FAILED_CODE,
5457
},
5558
NativeTaskError::PumpxSignerError(signer_error) => match signer_error {
5659
PumpxSignerError::RequestSignatureFailed => PUMPX_SIGNER_REQUEST_SIGNATURE_FAILED_CODE,

0 commit comments

Comments
 (0)