diff --git a/bitacross-worker/docker/docker-compose.yml b/bitacross-worker/docker/docker-compose.yml index 88b349080b..aef69f462b 100644 --- a/bitacross-worker/docker/docker-compose.yml +++ b/bitacross-worker/docker/docker-compose.yml @@ -132,6 +132,7 @@ services: - MORALIS_API_URL=http://localhost:19527/moralis/ - MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/ - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ + - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 diff --git a/bitacross-worker/docker/multiworker-docker-compose.yml b/bitacross-worker/docker/multiworker-docker-compose.yml index d352548703..25c7de03e2 100644 --- a/bitacross-worker/docker/multiworker-docker-compose.yml +++ b/bitacross-worker/docker/multiworker-docker-compose.yml @@ -133,6 +133,7 @@ services: - MORALIS_API_URL=http://localhost:19527/moralis/ - MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/ - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ + - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 @@ -189,6 +190,7 @@ services: - MORALIS_API_URL=http://localhost:19527/moralis/ - MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/ - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ + - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 @@ -245,6 +247,7 @@ services: - MORALIS_API_URL=http://localhost:19527/moralis/ - MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/ - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ + - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 diff --git a/local-setup/.env.dev b/local-setup/.env.dev index 688bee905b..41df7aede8 100644 --- a/local-setup/.env.dev +++ b/local-setup/.env.dev @@ -26,12 +26,12 @@ NODE_ENV=local # The following key/token are MANDATORY to give when running worker. # Otherwise request-vc might suffering from data provider error. TWITTER_AUTH_TOKEN_V2= -TWITTER_CLIENT_ID=twitter_client_id -TWITTER_CLIENT_SECRET=twitter_client_secret +TWITTER_CLIENT_ID= +TWITTER_CLIENT_SECRET= DISCORD_AUTH_TOKEN= ACHAINABLE_AUTH_KEY= -ONEBLOCK_NOTION_KEY=ABCDEFGHIJKLMNOPQRSTUVWXYZ -NODEREAL_API_KEY=NODEREAL_API_KEY +ONEBLOCK_NOTION_KEY= +NODEREAL_API_KEY= GENIIDATA_API_KEY= MORALIS_API_KEY= @@ -57,4 +57,5 @@ LITENTRY_ARCHIVE_URL=http://localhost:19527 MORALIS_API_URL=http://localhost:19527/moralis/ MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/ KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ +MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/ diff --git a/primitives/core/src/assertion/platform_user.rs b/primitives/core/src/assertion/platform_user.rs index bda6328dc1..fe85afbeb3 100644 --- a/primitives/core/src/assertion/platform_user.rs +++ b/primitives/core/src/assertion/platform_user.rs @@ -24,12 +24,14 @@ use crate::assertion::network::{all_evm_web3networks, Web3Network}; pub enum PlatformUserType { #[codec(index = 0)] KaratDaoUser, + #[codec(index = 1)] + MagicCraftStakingUser, } impl PlatformUserType { pub fn get_supported_networks(&self) -> Vec { match self { - Self::KaratDaoUser => all_evm_web3networks(), + Self::KaratDaoUser | Self::MagicCraftStakingUser => all_evm_web3networks(), } } } diff --git a/tee-worker/cli/src/trusted_base_cli/commands/litentry/request_vc.rs b/tee-worker/cli/src/trusted_base_cli/commands/litentry/request_vc.rs index b81b592ec1..98b55ae4cc 100644 --- a/tee-worker/cli/src/trusted_base_cli/commands/litentry/request_vc.rs +++ b/tee-worker/cli/src/trusted_base_cli/commands/litentry/request_vc.rs @@ -278,6 +278,7 @@ pub enum TokenHoldingAmountCommand { #[derive(Subcommand, Debug)] pub enum PlatformUserCommand { KaratDaoUser, + MagicCraftStakingUser, } #[derive(Subcommand, Debug)] @@ -618,6 +619,8 @@ impl Command { }, Command::PlatformUser(arg) => match arg { PlatformUserCommand::KaratDaoUser => PlatformUser(PlatformUserType::KaratDaoUser), + PlatformUserCommand::MagicCraftStakingUser => + PlatformUser(PlatformUserType::MagicCraftStakingUser), }, Command::NftHolder(arg) => match arg { NftHolderCommand::WeirdoGhostGang => NftHolder(Web3NftType::WeirdoGhostGang), diff --git a/tee-worker/client-api/parachain-api/prepare-build/interfaces/vc/definitions.ts b/tee-worker/client-api/parachain-api/prepare-build/interfaces/vc/definitions.ts index 23be1613b9..63d85be87e 100644 --- a/tee-worker/client-api/parachain-api/prepare-build/interfaces/vc/definitions.ts +++ b/tee-worker/client-api/parachain-api/prepare-build/interfaces/vc/definitions.ts @@ -190,7 +190,10 @@ export default { }, // PlatformUserType PlatformUserType: { - _enum: ["KaratDaoUser"], + _enum: [ + "KaratDaoUser", + "MagicCraftStakingUser", + ], }, // Web3NftType Web3NftType: { diff --git a/tee-worker/docker/docker-compose.yml b/tee-worker/docker/docker-compose.yml index 637991f5ba..2ffe01b268 100644 --- a/tee-worker/docker/docker-compose.yml +++ b/tee-worker/docker/docker-compose.yml @@ -134,6 +134,7 @@ services: - MORALIS_API_URL=http://localhost:19527/moralis/ - MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/ - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ + - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 diff --git a/tee-worker/docker/multiworker-docker-compose.yml b/tee-worker/docker/multiworker-docker-compose.yml index f3e980ec71..d715a5a63b 100644 --- a/tee-worker/docker/multiworker-docker-compose.yml +++ b/tee-worker/docker/multiworker-docker-compose.yml @@ -135,6 +135,7 @@ services: - MORALIS_API_URL=http://localhost:19527/moralis/ - MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/ - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ + - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 @@ -195,6 +196,7 @@ services: - MORALIS_API_URL=http://localhost:19527/moralis/ - MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/ - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ + - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 @@ -255,6 +257,7 @@ services: - MORALIS_API_URL=http://localhost:19527/moralis/ - MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/ - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ + - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 diff --git a/tee-worker/litentry/core/common/src/platform_user/mod.rs b/tee-worker/litentry/core/common/src/platform_user/mod.rs index 8cb8b9c21a..3b35366042 100644 --- a/tee-worker/litentry/core/common/src/platform_user/mod.rs +++ b/tee-worker/litentry/core/common/src/platform_user/mod.rs @@ -30,6 +30,7 @@ impl PlatformName for PlatformUserType { fn get_platform_name(&self) -> &'static str { match self { Self::KaratDaoUser => "KaratDao", + Self::MagicCraftStakingUser => "MagicCraft", } } } diff --git a/tee-worker/litentry/core/credentials/src/credential_schema.rs b/tee-worker/litentry/core/credentials/src/credential_schema.rs index f9df56e17f..593f57260a 100644 --- a/tee-worker/litentry/core/credentials/src/credential_schema.rs +++ b/tee-worker/litentry/core/credentials/src/credential_schema.rs @@ -107,7 +107,7 @@ pub fn get_schema_url(assertion: &Assertion) -> Option { Assertion::CryptoSummary => Some(format!("{BASE_URL}/23-crypto-summary/1-1-0.json")), - Assertion::PlatformUser(_) => Some(format!("{BASE_URL}/24-platform-user/1-1-0.json")), + Assertion::PlatformUser(_) => Some(format!("{BASE_URL}/24-platform-user/1-1-1.json")), Assertion::NftHolder(_) => Some(format!("{BASE_URL}/26-nft-holder/1-1-0.json")), diff --git a/tee-worker/litentry/core/data-providers/src/karat_dao.rs b/tee-worker/litentry/core/data-providers/src/karat_dao.rs index 06ad3af180..0a0f6fedc0 100644 --- a/tee-worker/litentry/core/data-providers/src/karat_dao.rs +++ b/tee-worker/litentry/core/data-providers/src/karat_dao.rs @@ -46,7 +46,7 @@ pub struct KaratDaoClient { } #[derive(Debug)] -pub struct KaraDaoRequest { +pub struct KaratDaoRequest { path: String, query: Option>, } @@ -66,7 +66,7 @@ impl KaratDaoClient { KaratDaoClient { retry_option, client } } - fn get(&mut self, params: KaraDaoRequest, fast_fail: bool) -> Result + fn get(&mut self, params: KaratDaoRequest, fast_fail: bool) -> Result where T: serde::de::DeserializeOwned + for<'a> RestPath>, { @@ -105,7 +105,7 @@ pub struct UserVerificationResult { pub is_valid: bool, } -pub trait KaraDaoApi { +pub trait KaratDaoApi { fn user_verification( &mut self, address: String, @@ -113,7 +113,7 @@ pub trait KaraDaoApi { ) -> Result; } -impl KaraDaoApi for KaratDaoClient { +impl KaratDaoApi for KaratDaoClient { fn user_verification( &mut self, address: String, @@ -121,7 +121,7 @@ impl KaraDaoApi for KaratDaoClient { ) -> Result { let query: Vec<(String, String)> = vec![("address".to_string(), address)]; - let params = KaraDaoRequest { path: "user/verification".into(), query: Some(query) }; + let params = KaratDaoRequest { path: "user/verification".into(), query: Some(query) }; debug!("user_verification, params: {:?}", params); diff --git a/tee-worker/litentry/core/data-providers/src/lib.rs b/tee-worker/litentry/core/data-providers/src/lib.rs index 3823550e74..df25728a2f 100644 --- a/tee-worker/litentry/core/data-providers/src/lib.rs +++ b/tee-worker/litentry/core/data-providers/src/lib.rs @@ -68,6 +68,7 @@ pub mod discord_litentry; pub mod discord_official; pub mod geniidata; pub mod karat_dao; +pub mod magic_craft; pub mod moralis; pub mod nodereal; pub mod nodereal_jsonrpc; @@ -194,6 +195,9 @@ pub struct DataProviderConfig { pub karat_dao_api_retry_delay: u64, pub karat_dao_api_retry_times: u16, pub karat_dao_api_url: String, + pub magic_craft_api_retry_delay: u64, + pub magic_craft_api_retry_times: u16, + pub magic_craft_api_url: String, pub moralis_api_url: String, pub moralis_solana_api_url: String, pub moralis_api_retry_delay: u64, @@ -240,6 +244,9 @@ impl DataProviderConfig { karat_dao_api_retry_delay: 5000, karat_dao_api_retry_times: 2, karat_dao_api_url: "https://api.karatdao.com/".to_string(), + magic_craft_api_retry_delay: 5000, + magic_craft_api_retry_times: 2, + magic_craft_api_url: "https://lobby-api-prod.magiccraft.io/".to_string(), moralis_api_key: "".to_string(), moralis_api_retry_delay: 5000, moralis_api_retry_times: 2, @@ -316,6 +323,15 @@ impl DataProviderConfig { if let Ok(v) = env::var("KARAT_DAO_API_URL") { config.set_karat_dao_api_url(v)?; } + if let Ok(v) = env::var("MAGIC_CRAFT_API_RETRY_DELAY") { + config.set_magic_craft_api_retry_delay(v.parse::().unwrap()); + } + if let Ok(v) = env::var("MAGIC_CRAFT_API_RETRY_TIMES") { + config.set_magic_craft_api_retry_times(v.parse::().unwrap()); + } + if let Ok(v) = env::var("MAGIC_CRAFT_API_URL") { + config.set_magic_craft_api_url(v)?; + } if let Ok(v) = env::var("MORALIS_API_URL") { config.set_moralis_api_url(v)?; } @@ -506,6 +522,20 @@ impl DataProviderConfig { self.karat_dao_api_url = v; Ok(()) } + pub fn set_magic_craft_api_retry_delay(&mut self, v: u64) { + debug!("set_magic_craft_api_retry_delay: {:?}", v); + self.magic_craft_api_retry_delay = v; + } + pub fn set_magic_craft_api_retry_times(&mut self, v: u16) { + debug!("set_magic_craft_api_retry_times: {:?}", v); + self.magic_craft_api_retry_times = v; + } + pub fn set_magic_craft_api_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; + debug!("set_magic_craft_api_url: {:?}", v); + self.magic_craft_api_url = v; + Ok(()) + } pub fn set_moralis_api_key(&mut self, v: String) { debug!("set_moralis_api_key: {:?}", v); self.moralis_api_key = v; diff --git a/tee-worker/litentry/core/data-providers/src/magic_craft.rs b/tee-worker/litentry/core/data-providers/src/magic_craft.rs new file mode 100644 index 0000000000..86df8e164d --- /dev/null +++ b/tee-worker/litentry/core/data-providers/src/magic_craft.rs @@ -0,0 +1,163 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +#[cfg(all(not(feature = "std"), feature = "sgx"))] +use crate::sgx_reexport_prelude::*; + +#[cfg(all(not(feature = "std"), feature = "sgx"))] +extern crate sgx_tstd as std; + +use crate::{ + build_client_with_cert, DataProviderConfig, Error, HttpError, ReqPath, RetryOption, + RetryableRestGet, +}; +use http::header::CONNECTION; +use http_req::response::Headers; +use itc_rest_client::{ + http_client::{HttpClient, SendWithCertificateVerification}, + rest_client::RestClient, + RestPath, +}; +use log::debug; +use serde::{Deserialize, Serialize}; +use std::{ + str, + string::{String, ToString}, + vec, + vec::Vec, +}; + +pub struct MagicCraftClient { + retry_option: RetryOption, + client: RestClient>, +} + +#[derive(Debug)] +pub struct MagicCraftRequest { + path: String, + query: Option>, +} + +impl MagicCraftClient { + pub fn new(data_provider_config: &DataProviderConfig) -> Self { + let api_retry_delay = data_provider_config.magic_craft_api_retry_delay; + let api_retry_times = data_provider_config.magic_craft_api_retry_times; + let api_url = data_provider_config.magic_craft_api_url.clone(); + let retry_option = + RetryOption { retry_delay: Some(api_retry_delay), retry_times: Some(api_retry_times) }; + + let mut headers = Headers::new(); + headers.insert(CONNECTION.as_str(), "close"); + let client = build_client_with_cert(api_url.as_str(), headers); + + MagicCraftClient { retry_option, client } + } + + fn get(&mut self, params: MagicCraftRequest, fast_fail: bool) -> Result + where + T: serde::de::DeserializeOwned + for<'a> RestPath>, + { + let retry_option: Option = + if fast_fail { None } else { Some(self.retry_option.clone()) }; + if let Some(query) = params.query { + let transformed_query: Vec<(&str, &str)> = + query.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect(); + self.client.get_with_retry::( + ReqPath::new(params.path.as_str()), + &transformed_query, + retry_option, + ) + } else { + self.client + .get_retry::(ReqPath::new(params.path.as_str()), retry_option) + } + } +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct UserVerificationResponse { + pub user: bool, +} + +impl<'a> RestPath> for UserVerificationResponse { + fn get_path(path: ReqPath) -> Result { + Ok(path.path.into()) + } +} + +pub trait MagicCraftApi { + fn user_verification( + &mut self, + address: String, + fail_fast: bool, + ) -> Result; +} + +impl MagicCraftApi for MagicCraftClient { + fn user_verification( + &mut self, + address: String, + fail_fast: bool, + ) -> Result { + let query: Vec<(String, String)> = vec![("wallet_address".to_string(), address)]; + + let params = MagicCraftRequest { path: "litentry/user".into(), query: Some(query) }; + + debug!("user_verification, params: {:?}", params); + + match self.get::(params, fail_fast) { + Ok(resp) => { + debug!("user_verification, response: {:?}", resp); + Ok(resp) + }, + Err(e) => { + debug!("user_verification, error: {:?}", e); + Err(e) + }, + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use lc_mock_server::run; + + fn init() -> DataProviderConfig { + let _ = env_logger::builder().is_test(true).try_init(); + let url = run(0).unwrap() + "/magic_craft/"; + + let mut config = DataProviderConfig::new().unwrap(); + config.set_magic_craft_api_url(url).unwrap(); + config + } + + #[test] + fn does_user_verification_works() { + let config = init(); + let mut client = MagicCraftClient::new(&config); + let mut response = client + .user_verification("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".into(), true) + .unwrap(); + assert_eq!(response.user, true); + + response = client + .user_verification("0x9401518f4ebba857baa879d9f76e1cc8b31ed197".into(), false) + .unwrap(); + assert_eq!(response.user, false); + } +} diff --git a/tee-worker/litentry/core/mock-server/src/lib.rs b/tee-worker/litentry/core/mock-server/src/lib.rs index c04082f7db..de8e75970c 100644 --- a/tee-worker/litentry/core/mock-server/src/lib.rs +++ b/tee-worker/litentry/core/mock-server/src/lib.rs @@ -28,6 +28,7 @@ pub mod discord_official; pub mod geniidata; pub mod karat_dao; pub mod litentry_archive; +pub mod magic_craft; pub mod moralis; pub mod nodereal; pub mod nodereal_jsonrpc; @@ -69,6 +70,7 @@ pub fn run(port: u16) -> Result { .or(discord_litentry::has_role()) .or(nodereal_jsonrpc::query()) .or(karat_dao::query()) + .or(magic_craft::query()) .or(moralis::query()) .or(moralis::query_solana()) .or(blockchain_info::query_rawaddr()) diff --git a/tee-worker/litentry/core/mock-server/src/magic_craft.rs b/tee-worker/litentry/core/mock-server/src/magic_craft.rs new file mode 100644 index 0000000000..fb939f9556 --- /dev/null +++ b/tee-worker/litentry/core/mock-server/src/magic_craft.rs @@ -0,0 +1,40 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . +#![allow(opaque_hidden_inferred_bound)] + +use std::collections::HashMap; + +use lc_data_providers::magic_craft::UserVerificationResponse; + +use warp::{http::Response, Filter}; + +pub(crate) fn query() -> impl Filter + Clone { + warp::get() + .and(warp::path!("magic_craft" / "litentry" / "user")) + .and(warp::query::>()) + .map(move |p: HashMap| { + let default = String::default(); + let address = p.get("wallet_address").unwrap_or(&default); + + if address == "0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee" { + let body = UserVerificationResponse { user: true }; + Response::builder().body(serde_json::to_string(&body).unwrap()) + } else { + let body = UserVerificationResponse { user: false }; + Response::builder().body(serde_json::to_string(&body).unwrap()) + } + }) +} diff --git a/tee-worker/litentry/core/service/src/platform_user/karat_dao_user.rs b/tee-worker/litentry/core/service/src/platform_user/karat_dao_user.rs index 055fd7d3ea..3e25004ad9 100644 --- a/tee-worker/litentry/core/service/src/platform_user/karat_dao_user.rs +++ b/tee-worker/litentry/core/service/src/platform_user/karat_dao_user.rs @@ -23,7 +23,7 @@ extern crate sgx_tstd as std; use core::result::Result; use lc_data_providers::{ - karat_dao::{KaraDaoApi, KaratDaoClient}, + karat_dao::{KaratDaoApi, KaratDaoClient}, DataProviderConfig, }; diff --git a/tee-worker/litentry/core/service/src/platform_user/magic_craft_staking_user.rs b/tee-worker/litentry/core/service/src/platform_user/magic_craft_staking_user.rs new file mode 100644 index 0000000000..5bffae848a --- /dev/null +++ b/tee-worker/litentry/core/service/src/platform_user/magic_craft_staking_user.rs @@ -0,0 +1,50 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +#[cfg(all(feature = "std", feature = "sgx"))] +compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the same time"); + +#[cfg(all(not(feature = "std"), feature = "sgx"))] +extern crate sgx_tstd as std; + +use core::result::Result; + +use lc_data_providers::{ + magic_craft::{MagicCraftApi, MagicCraftClient}, + DataProviderConfig, +}; + +use crate::*; + +pub fn is_user( + addresses: Vec, + data_provider_config: &DataProviderConfig, +) -> Result { + let mut is_user = false; + let mut client = MagicCraftClient::new(data_provider_config); + for address in addresses { + match client.user_verification(address, true) { + Ok(response) => { + is_user = response.user; + if is_user { + break + } + }, + Err(err) => return Err(err.into_error_detail()), + } + } + Ok(is_user) +} diff --git a/tee-worker/litentry/core/service/src/platform_user/mod.rs b/tee-worker/litentry/core/service/src/platform_user/mod.rs index 5eac7fdd53..eb34778bc8 100644 --- a/tee-worker/litentry/core/service/src/platform_user/mod.rs +++ b/tee-worker/litentry/core/service/src/platform_user/mod.rs @@ -28,6 +28,7 @@ use litentry_primitives::PlatformUserType; use crate::*; mod karat_dao_user; +mod magic_craft_staking_user; pub fn is_user( platform_user_type: PlatformUserType, @@ -36,5 +37,7 @@ pub fn is_user( ) -> Result { match platform_user_type { PlatformUserType::KaratDaoUser => karat_dao_user::is_user(addresses, data_provider_config), + PlatformUserType::MagicCraftStakingUser => + magic_craft_staking_user::is_user(addresses, data_provider_config), } } diff --git a/tee-worker/ts-tests/integration-tests/common/utils/vc-helper.ts b/tee-worker/ts-tests/integration-tests/common/utils/vc-helper.ts index 7bab9f9d88..326b41300e 100644 --- a/tee-worker/ts-tests/integration-tests/common/utils/vc-helper.ts +++ b/tee-worker/ts-tests/integration-tests/common/utils/vc-helper.ts @@ -217,4 +217,11 @@ export const mockAssertions = [ PlatformUser: 'KaratDaoUser', }, }, + + { + description: 'You are a user of a certain platform', + assertion: { + PlatformUser: 'MagicCraftStakingUser', + }, + }, ];