Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling missing branch for Email identity in match patterns #3064

Merged
merged 4 commits into from
Sep 13, 2024
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
1 change: 1 addition & 0 deletions tee-worker/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub enum Command {
#[clap(subcommand)]
NftHolder(NftHolderCommand),
Dynamic(DynamicArg),
LinkedIdentities,
}

#[derive(Args, Debug)]
Expand Down Expand Up @@ -698,6 +699,7 @@ impl Command {
return_log: arg.return_log.unwrap_or_default(),
}))
},
Command::LinkedIdentities => Ok(LinkedIdentities),
}
}
}
1 change: 1 addition & 0 deletions tee-worker/litentry/core/assertion-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ litentry-primitives = { path = "../../primitives", default-features = false }
pallet-parachain-staking = { path = "../../../../pallets/parachain-staking", default-features = false }

[dev-dependencies]
chrono = { version = "0.4.19", default-features = false, features = ["alloc"] }
env_logger = "0.10.0"
lc-mock-server = { path = "../mock-server" }
litentry-hex-utils = { path = "../../../../primitives/hex" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,99 +181,107 @@ impl Domains {
#[cfg(test)]
mod tests {
use super::Domains;
use chrono::{Duration, SecondsFormat, Utc};
use litentry_primitives::BnbDigitDomainType;

const RESPONSE: &'static str = r#"
{
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe1": [
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "1",
"expires": "2024-08-24T00:36:44Z"
},
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "2",
"expires": "2032-08-24T00:15:56Z"
}
],
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe2": [
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "3",
"expires": "2023-08-24T20:36:26Z"
},
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "4",
"expires": "2023-08-24T20:35:59Z"
},
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "win",
"expires": "2023-08-24T20:38:29Z"
}
],
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe3": [
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "5",
"expires": "2024-08-24T06:33:32Z"
},
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "6",
"expires": "2024-08-24T07:57:41Z"
},
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "7",
"expires": "2023-09-16T19:36:14Z"
}
],
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe4": [
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "8",
"expires": "2028-09-18T13:35:38Z"
}
],
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe5": [
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "9",
"expires": "2023-09-03T08:35:40Z"
}
],
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe6": [
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "000",
"expires": "2024-10-30T18:40:51Z"
},
{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "999",
"expires": "2024-03-19T18:16:59Z"
}
]
}
"#;

fn new_domains() -> Domains {
let value: serde_json::Value = serde_json::from_str(RESPONSE).unwrap();
let future_date = Utc::now()
.checked_add_signed(Duration::days(10))
.expect("Failed to add duration")
.to_rfc3339_opts(SecondsFormat::Secs, true);
let response = format!(
r#"
{{
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe1": [
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "1",
"expires": "2024-08-24T00:36:44Z"
}},
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "2",
"expires": "{}"
}}
],
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe2": [
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "3",
"expires": "2023-08-24T20:36:26Z"
}},
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "4",
"expires": "2023-08-24T20:35:59Z"
}},
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "win",
"expires": "2023-08-24T20:38:29Z"
}}
],
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe3": [
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "5",
"expires": "2024-08-24T06:33:32Z"
}},
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "6",
"expires": "2024-08-24T07:57:41Z"
}},
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "7",
"expires": "2023-09-16T19:36:14Z"
}}
],
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe4": [
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "8",
"expires": "{}"
}}
],
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe5": [
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "9",
"expires": "2023-09-03T08:35:40Z"
}}
],
"0xr4b0bf28adfcee93c5069982a895785c9231c1fe6": [
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "000",
"expires": "{}"
}},
{{
"nodeHash": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"bind": "0xr4b0bf28adfcee93c5069982a895785c9231c1fe",
"name": "999",
"expires": "2024-03-19T18:16:59Z"
}}
]
}}
"#,
future_date, future_date, future_date
);

let value: serde_json::Value = serde_json::from_str(response.as_str()).unwrap();
Domains::from_value(&value).unwrap()
}

Expand All @@ -287,7 +295,7 @@ mod tests {
fn non_expired_domain_infos_works() {
let domains = new_domains();
let non_expired_infos = domains.non_expired_domain_infos().unwrap();
assert_eq!(non_expired_infos.len(), 6);
assert_eq!(non_expired_infos.len(), 3);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ pub fn get_schema_url(assertion: &Assertion) -> Option<String> {
Some(format!("{BASE_URL}/25-token-holding-amount/1-1-4.json")),

Assertion::Dynamic(..) => None,
Assertion::LinkedIdentities => todo!(),
}
}
1 change: 1 addition & 0 deletions tee-worker/litentry/core/evm-dynamic-assertions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub fn identity_with_networks_to_token(identity: &IdentityNetworkTuple) -> Token
Identity::Evm(addr) => (4, addr.as_ref().to_vec()),
Identity::Bitcoin(addr) => (5, addr.as_ref().to_vec()),
Identity::Solana(addr) => (6, addr.as_ref().to_vec()),
Identity::Email(addr) => (7, addr.inner_ref().to_vec()),
};
let networks: Vec<Token> = identity.1.iter().map(network_to_token).collect();
Token::Tuple(vec![Token::Uint(type_index.into()), Token::Bytes(value), Token::Array(networks)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ where
vc_logs = Some(result.1);
Ok(result.0)
},
Assertion::LinkedIdentities => todo!(),
}?;

// post-process the credential
Expand Down
2 changes: 2 additions & 0 deletions tee-worker/service/src/prometheus_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ fn handle_stf_call_request(req: RequestType, time: f64) {
Identity::Twitter(_) => "Twitter".into(),
Identity::Discord(_) => "Discord".into(),
Identity::Github(_) => "Github".into(),
Identity::Email(_) => "Email".into(),
Identity::Substrate(_) => "Substrate".into(),
Identity::Evm(_) => "Evm".into(),
Identity::Bitcoin(_) => "Bitcoin".into(),
Expand Down Expand Up @@ -320,6 +321,7 @@ fn assertion_to_string(assertion: Assertion) -> String {
Assertion::Dynamic(param) => {
format!("DynamicAssertion({:?})", param.smart_contract_id)
},
Assertion::LinkedIdentities => "LinkedIdentities".into(),
};
assertion
}
Expand Down
Loading