Skip to content

Commit

Permalink
Propagate release v0.9.19 into dev (#3084)
Browse files Browse the repository at this point in the history
* feat: P-1006 add new Assertion enum item LinkedIdentities (#3042) (#3051)

Co-authored-by: higherordertech <higherordertech>

* adding email identity to core primitives (#3063)

* adding email identity to core primitives

* fixing formatting issue

* Handling missing enum branches in match patterns (#3064)

Handling missing variants for LinkedIdentities and Identity in match patterns

* re-apply changes from #3064 after restructure

Signed-off-by: Jonathan Alvarez <[email protected]>

---------

Signed-off-by: Jonathan Alvarez <[email protected]>
Co-authored-by: will.li <[email protected]>
Co-authored-by: Francisco Silva <[email protected]>
  • Loading branch information
3 people authored Sep 23, 2024
1 parent d67e7cb commit b6e8d80
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions common/primitives/core/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,16 @@ pub enum Identity {

#[codec(index = 6)]
Solana(Address32),

#[codec(index = 7)]
Email(IdentityString),
}

impl Identity {
pub fn is_web2(&self) -> bool {
matches!(
self,
Self::Twitter(..) | Self::Discord(..) | Self::Github(..)
Self::Twitter(..) | Self::Discord(..) | Self::Github(..) | Self::Email(..)
)
}

Expand Down Expand Up @@ -333,7 +336,10 @@ impl Identity {
Identity::Evm(_) => all_evm_web3networks(),
Identity::Bitcoin(_) => all_bitcoin_web3networks(),
Identity::Solana(_) => all_solana_web3networks(),
Identity::Twitter(_) | Identity::Discord(_) | Identity::Github(_) => Vec::new(),
Identity::Twitter(_)
| Identity::Discord(_)
| Identity::Github(_)
| Identity::Email(_) => Vec::new(),
}
}

Expand All @@ -346,9 +352,10 @@ impl Identity {
Identity::Evm(_) => !networks.is_empty() && networks.iter().all(|n| n.is_evm()),
Identity::Bitcoin(_) => !networks.is_empty() && networks.iter().all(|n| n.is_bitcoin()),
Identity::Solana(_) => !networks.is_empty() && networks.iter().all(|n| n.is_solana()),
Identity::Twitter(_) | Identity::Discord(_) | Identity::Github(_) => {
networks.is_empty()
}
Identity::Twitter(_)
| Identity::Discord(_)
| Identity::Github(_)
| Identity::Email(_) => networks.is_empty(),
}
}

Expand All @@ -360,7 +367,10 @@ impl Identity {
H160::from_slice(address.as_ref()),
)),
Identity::Bitcoin(address) => Some(blake2_256(address.as_ref()).into()),
Identity::Twitter(_) | Identity::Discord(_) | Identity::Github(_) => None,
Identity::Twitter(_)
| Identity::Discord(_)
| Identity::Github(_)
| Identity::Email(_) => None,
}
}

Expand Down Expand Up @@ -411,6 +421,10 @@ impl Identity {
return Ok(Identity::Twitter(IdentityString::new(
v[1].as_bytes().to_vec(),
)));
} else if v[0] == "email" {
return Ok(Identity::Email(IdentityString::new(
v[1].as_bytes().to_vec(),
)));
} else {
return Err("Unknown did type");
}
Expand Down Expand Up @@ -446,6 +460,11 @@ impl Identity {
str::from_utf8(handle.inner_ref())
.map_err(|_| "github handle conversion error")?
),
Identity::Email(handle) => format!(
"email:{}",
str::from_utf8(handle.inner_ref())
.map_err(|_| "email handle conversion error")?
),
}
))
}
Expand Down Expand Up @@ -520,6 +539,7 @@ mod tests {
Identity::Twitter(..) => true,
Identity::Discord(..) => true,
Identity::Github(..) => true,
Identity::Email(..) => true,
Identity::Substrate(..) => false,
Identity::Evm(..) => false,
Identity::Bitcoin(..) => false,
Expand All @@ -538,6 +558,7 @@ mod tests {
Identity::Twitter(..) => false,
Identity::Discord(..) => false,
Identity::Github(..) => false,
Identity::Email(..) => false,
Identity::Substrate(..) => true,
Identity::Evm(..) => true,
Identity::Bitcoin(..) => true,
Expand All @@ -556,6 +577,7 @@ mod tests {
Identity::Twitter(..) => false,
Identity::Discord(..) => false,
Identity::Github(..) => false,
Identity::Email(..) => false,
Identity::Substrate(..) => true,
Identity::Evm(..) => false,
Identity::Bitcoin(..) => false,
Expand All @@ -574,6 +596,7 @@ mod tests {
Identity::Twitter(..) => false,
Identity::Discord(..) => false,
Identity::Github(..) => false,
Identity::Email(..) => false,
Identity::Substrate(..) => false,
Identity::Evm(..) => true,
Identity::Bitcoin(..) => false,
Expand All @@ -592,6 +615,7 @@ mod tests {
Identity::Twitter(..) => false,
Identity::Discord(..) => false,
Identity::Github(..) => false,
Identity::Email(..) => false,
Identity::Substrate(..) => false,
Identity::Evm(..) => false,
Identity::Bitcoin(..) => true,
Expand All @@ -610,6 +634,7 @@ mod tests {
Identity::Twitter(..) => false,
Identity::Discord(..) => false,
Identity::Github(..) => false,
Identity::Email(..) => false,
Identity::Substrate(..) => false,
Identity::Evm(..) => false,
Identity::Bitcoin(..) => false,
Expand Down Expand Up @@ -725,6 +750,14 @@ mod tests {
assert_eq!(Identity::from_did(did_str).unwrap(), identity);
}

#[test]
fn test_email_did() {
let identity = Identity::Email(IdentityString::new("[email protected]".as_bytes().to_vec()));
let did_str = "did:litentry:email:[email protected]";
assert_eq!(identity.to_did().unwrap(), did_str);
assert_eq!(Identity::from_did(did_str).unwrap(), identity);
}

#[test]
fn test_solana_did() {
let address = "4fuUiYxTQ6QCrdSq9ouBYcTM7bqSwYTSyLueGZLTy4T4";
Expand Down

0 comments on commit b6e8d80

Please sign in to comment.