diff --git a/common/primitives/core/src/identity.rs b/common/primitives/core/src/identity.rs index 9fd36629d9..6a1c1a5190 100644 --- a/common/primitives/core/src/identity.rs +++ b/common/primitives/core/src/identity.rs @@ -272,19 +272,21 @@ impl Debug for Address33 { Encode, Decode, Clone, Debug, PartialEq, Eq, TypeInfo, MaxEncodedLen, EnumIter, Ord, PartialOrd, )] pub enum Identity { - // web2 #[codec(index = 0)] Twitter(IdentityString), + #[codec(index = 1)] Discord(IdentityString), + #[codec(index = 2)] Github(IdentityString), - // web3 #[codec(index = 3)] Substrate(Address32), + #[codec(index = 4)] Evm(Address20), + // bitcoin addresses are derived (one-way hash) from the pubkey // by using `Address33` as the Identity handle, it requires that pubkey // is retrievable by the wallet API when verifying the bitcoin account. @@ -297,13 +299,20 @@ pub enum Identity { #[codec(index = 7)] Email(IdentityString), + + #[codec(index = 8)] + Google(IdentityString), } impl Identity { pub fn is_web2(&self) -> bool { matches!( self, - Self::Twitter(..) | Self::Discord(..) | Self::Github(..) | Self::Email(..) + Self::Twitter(..) + | Self::Discord(..) + | Self::Github(..) + | Self::Email(..) + | Self::Google(..) ) } @@ -339,7 +348,8 @@ impl Identity { Identity::Twitter(_) | Identity::Discord(_) | Identity::Github(_) - | Identity::Email(_) => Vec::new(), + | Identity::Email(_) + | Identity::Google(_) => Vec::new(), } } @@ -355,7 +365,8 @@ impl Identity { Identity::Twitter(_) | Identity::Discord(_) | Identity::Github(_) - | Identity::Email(_) => networks.is_empty(), + | Identity::Email(_) + | Identity::Google(_) => networks.is_empty(), } } @@ -376,7 +387,8 @@ impl Identity { Identity::Twitter(_) | Identity::Discord(_) | Identity::Github(_) - | Identity::Email(_) => None, + | Identity::Email(_) + | Identity::Google(_) => None, } } @@ -439,6 +451,10 @@ impl Identity { return Ok(Identity::Email(IdentityString::new( v[1].as_bytes().to_vec(), ))); + } else if v[0] == "google" { + return Ok(Identity::Google(IdentityString::new( + v[1].as_bytes().to_vec(), + ))); } else { return Err("Unknown did type"); } @@ -479,6 +495,11 @@ impl Identity { str::from_utf8(handle.inner_ref()) .map_err(|_| "email handle conversion error")? ), + Identity::Google(handle) => format!( + "google:{}", + str::from_utf8(handle.inner_ref()) + .map_err(|_| "google handle conversion error")? + ), } )) } @@ -566,6 +587,7 @@ mod tests { Identity::Evm(..) => false, Identity::Bitcoin(..) => false, Identity::Solana(..) => false, + Identity::Google(..) => true, } ) }) @@ -585,6 +607,7 @@ mod tests { Identity::Evm(..) => true, Identity::Bitcoin(..) => true, Identity::Solana(..) => true, + Identity::Google(..) => false, } ) }) @@ -604,6 +627,7 @@ mod tests { Identity::Evm(..) => false, Identity::Bitcoin(..) => false, Identity::Solana(..) => false, + Identity::Google(..) => false, } ) }) @@ -623,6 +647,7 @@ mod tests { Identity::Evm(..) => true, Identity::Bitcoin(..) => false, Identity::Solana(..) => false, + Identity::Google(..) => false, } ) }) @@ -642,6 +667,7 @@ mod tests { Identity::Evm(..) => false, Identity::Bitcoin(..) => true, Identity::Solana(..) => false, + Identity::Google(..) => false, } ) }) @@ -661,6 +687,7 @@ mod tests { Identity::Evm(..) => false, Identity::Bitcoin(..) => false, Identity::Solana(..) => true, + Identity::Google(..) => false, } ) }) @@ -795,4 +822,12 @@ mod tests { assert_eq!(identity.to_did().unwrap(), did.as_str()); assert_eq!(Identity::from_did(did.as_str()).unwrap(), identity); } + + #[test] + fn test_google_did() { + let identity = Identity::Google(IdentityString::new("test@gmail.com".as_bytes().to_vec())); + let did_str = "did:litentry:google:test@gmail.com"; + assert_eq!(identity.to_did().unwrap(), did_str); + assert_eq!(Identity::from_did(did_str).unwrap(), identity); + } } diff --git a/tee-worker/identity/litentry/core/evm-dynamic-assertions/src/lib.rs b/tee-worker/identity/litentry/core/evm-dynamic-assertions/src/lib.rs index 1499ad1e88..c7f8659d13 100644 --- a/tee-worker/identity/litentry/core/evm-dynamic-assertions/src/lib.rs +++ b/tee-worker/identity/litentry/core/evm-dynamic-assertions/src/lib.rs @@ -204,6 +204,7 @@ pub fn identity_with_networks_to_token(identity: &IdentityNetworkTuple) -> Token Identity::Bitcoin(addr) => (5, addr.as_ref().to_vec()), Identity::Solana(addr) => (6, addr.as_ref().to_vec()), Identity::Email(str) => (7, str.inner_ref().to_vec()), + Identity::Google(str) => (8, str.inner_ref().to_vec()), }; let networks: Vec = identity.1.iter().map(network_to_token).collect(); Token::Tuple(vec![Token::Uint(type_index.into()), Token::Bytes(value), Token::Array(networks)]) diff --git a/tee-worker/identity/service/src/prometheus_metrics.rs b/tee-worker/identity/service/src/prometheus_metrics.rs index e23f2ecdc0..0035d3855f 100644 --- a/tee-worker/identity/service/src/prometheus_metrics.rs +++ b/tee-worker/identity/service/src/prometheus_metrics.rs @@ -293,6 +293,7 @@ fn handle_stf_call_request(req: RequestType, time: f64) { Identity::Evm(_) => "Evm".into(), Identity::Bitcoin(_) => "Bitcoin".into(), Identity::Solana(_) => "Solana".into(), + Identity::Google(_) => "Google".into(), }, }; inc_stf_calls(category, &label);