Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 6 additions & 37 deletions parachain/primitives/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ impl IdentityString {
}
}

impl From<&str> for IdentityString {
fn from(value: &str) -> Self {
IdentityString::new(value.as_bytes().to_vec())
}
}

impl Debug for IdentityString {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
if_development_or!(
Expand Down Expand Up @@ -624,43 +630,6 @@ impl Identity {
pub fn hash(&self) -> H256 {
self.using_encoded(blake2_256).into()
}

pub fn from_web2_account(handle: &str, identity_type: Web2IdentityType) -> Self {
match identity_type {
Web2IdentityType::Twitter => {
Identity::Twitter(IdentityString::new(handle.as_bytes().to_vec()))
},
Web2IdentityType::Discord => {
Identity::Discord(IdentityString::new(handle.as_bytes().to_vec()))
},
Web2IdentityType::Apple => {
Identity::Apple(IdentityString::new(handle.as_bytes().to_vec()))
},
Web2IdentityType::Email => {
Identity::Email(IdentityString::new(handle.as_bytes().to_vec()))
},
Web2IdentityType::Google => {
Identity::Google(IdentityString::new(handle.as_bytes().to_vec()))
},
Web2IdentityType::Pumpx => {
Identity::Pumpx(IdentityString::new(handle.as_bytes().to_vec()))
},
Web2IdentityType::Passkey => {
Identity::Passkey(IdentityString::new(handle.as_bytes().to_vec()))
},
}
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Web2IdentityType {
Twitter,
Discord,
Apple,
Email,
Google,
Pumpx,
Passkey,
}

impl From<ed25519::Public> for Identity {
Expand Down
7 changes: 3 additions & 4 deletions tee-worker/identity/enclave-runtime/src/rpc/common_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use lc_identity_verification::{
};
use litentry_primitives::{
aes_decrypt, decode_hex, if_development, if_development_or, AesRequest, DecryptableRequest,
Identity, Web2IdentityType,
Identity,
};
use log::debug;
use sgx_crypto_helper::rsa3072::Rsa3072PubKey;
Expand Down Expand Up @@ -468,8 +468,7 @@ pub fn add_common_api<Author, GetterExecutor, AccessShieldingKey, OcallApi, Stat
)))
},
};
let google_identity =
Identity::from_web2_account(&google_account, Web2IdentityType::Google);
let google_identity = Identity::Google(google_account.as_str().into());
let state = generate_verification_code();
let authorize_data = google::get_authorize_data(&google_client_id, &redirect_uri);

Expand Down Expand Up @@ -505,7 +504,7 @@ pub fn add_common_api<Author, GetterExecutor, AccessShieldingKey, OcallApi, Stat
data_provider_config.sendgrid_from_email.clone(),
);
let verification_code = generate_verification_code();
let email_identity = Identity::from_web2_account(&email, Web2IdentityType::Email);
let email_identity = Identity::Email(email.as_str().into());

match email::VerificationCodeStore::insert(
omni_account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ pub fn verify(
_ => return Err(Error::LinkIdentityFailed(ErrorDetail::InvalidIdentity)),
};

let email_identity =
Identity::from_web2_account(&email, litentry_primitives::Web2IdentityType::Email);
let email_identity = Identity::Email(email.as_str().into());
let stored_verification_code =
match VerificationCodeStore::get(&account_id, email_identity.hash()) {
Ok(data) => data.ok_or_else(|| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use lc_authentication::jwt;
use lc_data_providers::{google::GoogleOAuth2Client, DataProviderConfig};
use lc_identity_verification::web2::{email::VerificationCodeStore, google};
use lc_omni_account::InMemoryStore as OmniAccountStore;
use litentry_primitives::{hex_encode, Identity, ShardIdentifier, Web2IdentityType};
use litentry_primitives::{hex_encode, Identity, ShardIdentifier};
use sp_core::{blake2_256, crypto::AccountId32 as AccountId, H256};

#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -134,7 +134,7 @@ fn verify_google_oauth2(
})?;
let claims = google::decode_jwt(&token)
.map_err(|e| AuthenticationError::OAuth2Error(format!("Failed to decode JWT: {:?}", e)))?;
let google_identity = Identity::from_web2_account(&claims.email, Web2IdentityType::Google);
let google_identity = Identity::Google(claims.email.as_str().into());
let identity_omni_account = match OmniAccountStore::get_omni_account(google_identity.hash()) {
Ok(Some(account_id)) => account_id,
_ => google_identity.to_omni_account(DEFAULT_CLIENT_ID),
Expand Down
Loading
Loading