diff --git a/bitacross-worker/docker/docker-compose.yml b/bitacross-worker/docker/docker-compose.yml index 585ca359ff..a077944fdc 100644 --- a/bitacross-worker/docker/docker-compose.yml +++ b/bitacross-worker/docker/docker-compose.yml @@ -134,6 +134,7 @@ services: - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MAGIC_CRAFT_API_KEY= + - DAREN_MARKET_API_URL=http://localhost:19527/daren_market/ - 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 07201dfa90..5b3aa5108f 100644 --- a/bitacross-worker/docker/multiworker-docker-compose.yml +++ b/bitacross-worker/docker/multiworker-docker-compose.yml @@ -135,6 +135,7 @@ services: - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MAGIC_CRAFT_API_KEY= + - DAREN_MARKET_API_URL=http://localhost:19527/daren_market/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 @@ -193,6 +194,7 @@ services: - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MAGIC_CRAFT_API_KEY= + - DAREN_MARKET_API_URL=http://localhost:19527/daren_market/ - 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 d5c1b9cf2f..b01024f9f9 100644 --- a/local-setup/.env.dev +++ b/local-setup/.env.dev @@ -61,4 +61,5 @@ 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/ +DAREN_MARKET_API_URL=http://localhost:19527/daren_market/ 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 fe85afbeb3..e5a5ebc3b1 100644 --- a/primitives/core/src/assertion/platform_user.rs +++ b/primitives/core/src/assertion/platform_user.rs @@ -23,15 +23,17 @@ use crate::assertion::network::{all_evm_web3networks, Web3Network}; #[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, MaxEncodedLen, TypeInfo)] pub enum PlatformUserType { #[codec(index = 0)] - KaratDaoUser, + KaratDao, #[codec(index = 1)] - MagicCraftStakingUser, + MagicCraftStaking, + #[codec(index = 2)] + DarenMarket, } impl PlatformUserType { pub fn get_supported_networks(&self) -> Vec { match self { - Self::KaratDaoUser | Self::MagicCraftStakingUser => all_evm_web3networks(), + Self::KaratDao | Self::MagicCraftStaking | Self::DarenMarket => all_evm_web3networks(), } } } diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index 37b3cb31ff..facd7f0b25 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -36,6 +36,10 @@ function clean_up() { cargo clean cd "$root_dir/tee-worker/enclave-runtime" cargo clean + cd "$root_dir/bitacross-worker" + cargo clean + cd "$root_dir/bitacross-worker/enclave-runtime" + cargo clean } root_dir=$(git rev-parse --show-toplevel) 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 5e4c6f46ce..3c1fa77572 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 @@ -284,8 +284,9 @@ pub enum TokenHoldingAmountCommand { #[derive(Subcommand, Debug)] pub enum PlatformUserCommand { - KaratDaoUser, - MagicCraftStakingUser, + KaratDao, + MagicCraftStaking, + DarenMarket, } #[derive(Subcommand, Debug)] @@ -652,9 +653,10 @@ impl Command { TokenHoldingAmountCommand::Tuna => TokenHoldingAmount(Web3TokenType::Tuna), }), Command::PlatformUser(arg) => Ok(match arg { - PlatformUserCommand::KaratDaoUser => PlatformUser(PlatformUserType::KaratDaoUser), - PlatformUserCommand::MagicCraftStakingUser => - PlatformUser(PlatformUserType::MagicCraftStakingUser), + PlatformUserCommand::KaratDao => PlatformUser(PlatformUserType::KaratDao), + PlatformUserCommand::MagicCraftStaking => + PlatformUser(PlatformUserType::MagicCraftStaking), + PlatformUserCommand::DarenMarket => PlatformUser(PlatformUserType::DarenMarket), }), Command::NftHolder(arg) => Ok(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 2322dfb0b8..06c0715011 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 @@ -242,7 +242,7 @@ export default { }, // PlatformUserType PlatformUserType: { - _enum: ["KaratDaoUser", "MagicCraftStakingUser"], + _enum: ["KaratDao", "MagicCraftStaking", "DarenMarket"], }, // Web3NftType Web3NftType: { diff --git a/tee-worker/docker/docker-compose.yml b/tee-worker/docker/docker-compose.yml index cc6beb8256..8bd55a0958 100644 --- a/tee-worker/docker/docker-compose.yml +++ b/tee-worker/docker/docker-compose.yml @@ -138,6 +138,7 @@ services: - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MAGIC_CRAFT_API_KEY= + - DAREN_MARKET_API_URL=http://localhost:19527/daren_market/ - 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 f5d94c5a2c..7cf162d91a 100644 --- a/tee-worker/docker/multiworker-docker-compose.yml +++ b/tee-worker/docker/multiworker-docker-compose.yml @@ -139,6 +139,7 @@ services: - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MAGIC_CRAFT_API_KEY= + - DAREN_MARKET_API_URL=http://localhost:19527/daren_market/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 @@ -203,6 +204,7 @@ services: - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MAGIC_CRAFT_API_KEY= + - DAREN_MARKET_API_URL=http://localhost:19527/daren_market/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 @@ -267,6 +269,7 @@ services: - KARAT_DAO_API_URL=http://localhost:19527/karat_dao/ - MAGIC_CRAFT_API_URL=http://localhost:19527/magic_craft/ - MAGIC_CRAFT_API_KEY= + - DAREN_MARKET_API_URL=http://localhost:19527/daren_market/ - MORALIS_API_KEY= - NODEREAL_API_KEY=NODEREAL_API_KEY - NODEREAL_API_URL=http://localhost:19527 diff --git a/tee-worker/litentry/core/assertion-build-v2/src/platform_user/mod.rs b/tee-worker/litentry/core/assertion-build-v2/src/platform_user/mod.rs index 2039ca1c44..fe459d74be 100644 --- a/tee-worker/litentry/core/assertion-build-v2/src/platform_user/mod.rs +++ b/tee-worker/litentry/core/assertion-build-v2/src/platform_user/mod.rs @@ -93,12 +93,26 @@ mod tests { use litentry_hex_utils::decode_hex; use litentry_primitives::{Identity, IdentityNetworkTuple}; - fn init() -> DataProviderConfig { + fn init(platform_user_type: PlatformUserType) -> DataProviderConfig { let _ = env_logger::builder().is_test(true).try_init(); - let url = run(0).unwrap() + "/karat_dao/"; let mut config = DataProviderConfig::new().unwrap(); - config.set_karat_dao_api_url(url).unwrap(); + + match platform_user_type { + PlatformUserType::KaratDao => { + let url = run(0).unwrap() + "/karat_dao/"; + config.set_karat_dao_api_url(url).unwrap(); + }, + PlatformUserType::MagicCraftStaking => { + let url = run(0).unwrap() + "/magic_craft/"; + config.set_magic_craft_api_url(url).unwrap(); + }, + PlatformUserType::DarenMarket => { + let url = run(0).unwrap() + "/daren_market/"; + config.set_daren_market_api_url(url).unwrap(); + }, + }; + config } @@ -129,11 +143,11 @@ mod tests { assertion_value: bool, data_provider_config: &DataProviderConfig, ) { - let req = crate_assertion_build_request(PlatformUserType::KaratDaoUser, identities); + let req = crate_assertion_build_request(platform_user_type.clone(), identities); match build(&req, platform_user_type.clone(), &data_provider_config) { Ok(credential) => { - log::info!("build karat dao user done"); + log::info!("build platform user: {:?} done", platform_user_type); assert_eq!( *(credential.credential_subject.assertions.first().unwrap()), AssertionLogic::And { @@ -150,14 +164,85 @@ mod tests { ); }, Err(e) => { - panic!("build karat dao user failed with error {:?}", e); + panic!("build platform user: {:?} failed with error {:?}", platform_user_type, e); }, } } #[test] fn build_karat_dao_user_works() { - let data_provider_config = init(); + let data_provider_config = init(PlatformUserType::KaratDao); + + let mut address = + decode_hex("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".as_bytes().to_vec()) + .unwrap() + .as_slice() + .try_into() + .unwrap(); + let mut identities: Vec = + vec![(Identity::Evm(address), vec![Web3Network::Ethereum])]; + + build_and_assert_result( + identities, + PlatformUserType::KaratDao, + true, + &data_provider_config, + ); + + address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e7c".as_bytes().to_vec()) + .unwrap() + .as_slice() + .try_into() + .unwrap(); + identities = vec![(Identity::Evm(address), vec![Web3Network::Bsc, Web3Network::Ethereum])]; + + build_and_assert_result( + identities, + PlatformUserType::KaratDao, + false, + &data_provider_config, + ); + } + + #[test] + fn build_magic_craft_staking_user_works() { + let data_provider_config = init(PlatformUserType::MagicCraftStaking); + + let mut address = + decode_hex("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".as_bytes().to_vec()) + .unwrap() + .as_slice() + .try_into() + .unwrap(); + let mut identities: Vec = + vec![(Identity::Evm(address), vec![Web3Network::Ethereum])]; + + build_and_assert_result( + identities, + PlatformUserType::MagicCraftStaking, + true, + &data_provider_config, + ); + + address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e7c".as_bytes().to_vec()) + .unwrap() + .as_slice() + .try_into() + .unwrap(); + identities = vec![(Identity::Evm(address), vec![Web3Network::Bsc, Web3Network::Ethereum])]; + + build_and_assert_result( + identities, + PlatformUserType::MagicCraftStaking, + false, + &data_provider_config, + ); + } + + #[test] + fn build_daren_market_user_works() { + let data_provider_config = init(PlatformUserType::DarenMarket); + let mut address = decode_hex("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".as_bytes().to_vec()) .unwrap() @@ -169,7 +254,7 @@ mod tests { build_and_assert_result( identities, - PlatformUserType::KaratDaoUser, + PlatformUserType::DarenMarket, true, &data_provider_config, ); @@ -183,7 +268,7 @@ mod tests { build_and_assert_result( identities, - PlatformUserType::KaratDaoUser, + PlatformUserType::DarenMarket, false, &data_provider_config, ); 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 3b35366042..657d7546bb 100644 --- a/tee-worker/litentry/core/common/src/platform_user/mod.rs +++ b/tee-worker/litentry/core/common/src/platform_user/mod.rs @@ -29,8 +29,9 @@ pub trait PlatformName { impl PlatformName for PlatformUserType { fn get_platform_name(&self) -> &'static str { match self { - Self::KaratDaoUser => "KaratDao", - Self::MagicCraftStakingUser => "MagicCraft", + Self::KaratDao => "KaratDao", + Self::MagicCraftStaking => "MagicCraft", + Self::DarenMarket => "DarenMarket", } } } diff --git a/tee-worker/litentry/core/credentials/src/credential_schema.rs b/tee-worker/litentry/core/credentials/src/credential_schema.rs index 9ca9427483..be4d9019e1 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-1.json")), + Assertion::PlatformUser(_) => Some(format!("{BASE_URL}/24-platform-user/1-1-2.json")), Assertion::NftHolder(_) => Some(format!("{BASE_URL}/26-nft-holder/1-1-2.json")), diff --git a/tee-worker/litentry/core/data-providers/src/daren_market.rs b/tee-worker/litentry/core/data-providers/src/daren_market.rs new file mode 100644 index 0000000000..1da1f3880d --- /dev/null +++ b/tee-worker/litentry/core/data-providers/src/daren_market.rs @@ -0,0 +1,169 @@ +// 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 DarenMarketClient { + retry_option: RetryOption, + client: RestClient>, +} + +#[derive(Debug)] +pub struct DarenMarketRequest { + path: String, + query: Option>, +} + +impl DarenMarketClient { + pub fn new(data_provider_config: &DataProviderConfig) -> Self { + let api_retry_delay = data_provider_config.daren_market_api_retry_delay; + let api_retry_times = data_provider_config.daren_market_api_retry_times; + let api_url = data_provider_config.daren_market_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); + + DarenMarketClient { retry_option, client } + } + + fn get(&mut self, params: DarenMarketRequest, 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 success: bool, + pub created: bool, + pub message: String, +} + +impl<'a> RestPath> for UserVerificationResponse { + fn get_path(path: ReqPath) -> Result { + Ok(path.path.into()) + } +} + +pub trait DarenMarketApi { + fn user_verification( + &mut self, + address: String, + fail_fast: bool, + ) -> Result; +} + +impl DarenMarketApi for DarenMarketClient { + fn user_verification( + &mut self, + address: String, + fail_fast: bool, + ) -> Result { + let query: Vec<(String, String)> = vec![("address".to_string(), address)]; + + let params = DarenMarketRequest { path: "api/talent-asset".into(), query: Some(query) }; + + debug!("DarenMarket user_verification, params: {:?}", params); + + match self.get::(params, fail_fast) { + Ok(resp) => { + debug!("DarenMarket user_verification, response: {:?}", resp); + Ok(resp) + }, + Err(e) => { + debug!("DarenMarket 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() + "/daren_market/"; + + let mut config = DataProviderConfig::new().unwrap(); + config.set_daren_market_api_url(url).unwrap(); + config + } + + #[test] + fn does_user_verification_works() { + let config = init(); + let mut client = DarenMarketClient::new(&config); + let mut response = client + .user_verification("0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee".into(), true) + .unwrap(); + assert_eq!(response.success, true); + assert_eq!(response.created, true); + assert_eq!(response.message, "Talent Asset Found!".to_string()); + + response = client + .user_verification("0x9401518f4ebba857baa879d9f76e1cc8b31ed197".into(), false) + .unwrap(); + assert_eq!(response.success, false); + assert_eq!(response.created, false); + assert_eq!(response.message, "".to_string()); + } +} 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 0a0f6fedc0..e3d78bb83b 100644 --- a/tee-worker/litentry/core/data-providers/src/karat_dao.rs +++ b/tee-worker/litentry/core/data-providers/src/karat_dao.rs @@ -123,15 +123,15 @@ impl KaratDaoApi for KaratDaoClient { let params = KaratDaoRequest { path: "user/verification".into(), query: Some(query) }; - debug!("user_verification, params: {:?}", params); + debug!("KaratDao user_verification, params: {:?}", params); match self.get::(params, fail_fast) { Ok(resp) => { - debug!("user_verification, response: {:?}", resp); + debug!("KaratDao user_verification, response: {:?}", resp); Ok(resp) }, Err(e) => { - debug!("user_verification, error: {:?}", e); + debug!("KaratDao user_verification, error: {:?}", e); Err(e) }, } diff --git a/tee-worker/litentry/core/data-providers/src/lib.rs b/tee-worker/litentry/core/data-providers/src/lib.rs index b4a3af74e3..97eb91ce9c 100644 --- a/tee-worker/litentry/core/data-providers/src/lib.rs +++ b/tee-worker/litentry/core/data-providers/src/lib.rs @@ -64,6 +64,7 @@ compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the sam pub mod achainable; pub mod achainable_names; pub mod blockchain_info; +pub mod daren_market; pub mod discord_litentry; pub mod discord_official; pub mod geniidata; @@ -201,6 +202,9 @@ pub struct DataProviderConfig { pub magic_craft_api_retry_times: u16, pub magic_craft_api_url: String, pub magic_craft_api_key: String, + pub daren_market_api_retry_delay: u64, + pub daren_market_api_retry_times: u16, + pub daren_market_api_url: String, pub moralis_api_url: String, pub moralis_solana_api_url: String, pub moralis_api_retry_delay: u64, @@ -253,6 +257,9 @@ impl DataProviderConfig { magic_craft_api_retry_times: 2, magic_craft_api_url: "https://lobby-api-prod.magiccraft.io/".to_string(), magic_craft_api_key: "".to_string(), + daren_market_api_retry_delay: 5000, + daren_market_api_retry_times: 2, + daren_market_api_url: "https://daren.market/".to_string(), moralis_api_key: "".to_string(), moralis_api_retry_delay: 5000, moralis_api_retry_times: 2, @@ -338,6 +345,15 @@ impl DataProviderConfig { if let Ok(v) = env::var("MAGIC_CRAFT_API_URL") { config.set_magic_craft_api_url(v)?; } + if let Ok(v) = env::var("DAREN_MARKET_API_RETRY_DELAY") { + config.set_daren_market_api_retry_delay(v.parse::().unwrap()); + } + if let Ok(v) = env::var("DAREN_MARKET_API_RETRY_TIMES") { + config.set_daren_market_api_retry_times(v.parse::().unwrap()); + } + if let Ok(v) = env::var("DAREN_MARKET_API_URL") { + config.set_daren_market_api_url(v)?; + } if let Ok(v) = env::var("MORALIS_API_URL") { config.set_moralis_api_url(v)?; } @@ -563,6 +579,20 @@ impl DataProviderConfig { debug!("set_magic_craft_api_key: {:?}", v); self.magic_craft_api_key = v; } + pub fn set_daren_market_api_retry_delay(&mut self, v: u64) { + debug!("set_daren_market_api_retry_delay: {:?}", v); + self.daren_market_api_retry_delay = v; + } + pub fn set_daren_market_api_retry_times(&mut self, v: u16) { + debug!("set_daren_market_api_retry_times: {:?}", v); + self.daren_market_api_retry_times = v; + } + pub fn set_daren_market_api_url(&mut self, v: String) -> Result<(), Error> { + check_url(&v)?; + debug!("set_daren_market_api_url: {:?}", v); + self.daren_market_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 index 4b8bd28396..b959b04e02 100644 --- a/tee-worker/litentry/core/data-providers/src/magic_craft.rs +++ b/tee-worker/litentry/core/data-providers/src/magic_craft.rs @@ -119,15 +119,15 @@ impl MagicCraftApi for MagicCraftClient { let params = MagicCraftRequest { path: "litentry/user".into(), query: Some(query) }; - debug!("user_verification, params: {:?}", params); + debug!("MagicCraft user_verification, params: {:?}", params); match self.get::(params, fail_fast) { Ok(resp) => { - debug!("user_verification, response: {:?}", resp); + debug!("MagicCraft user_verification, response: {:?}", resp); Ok(resp) }, Err(e) => { - debug!("user_verification, error: {:?}", e); + debug!("MagicCraft user_verification, error: {:?}", e); Err(e) }, } diff --git a/tee-worker/litentry/core/mock-server/src/daren_market.rs b/tee-worker/litentry/core/mock-server/src/daren_market.rs new file mode 100644 index 0000000000..cb1b725522 --- /dev/null +++ b/tee-worker/litentry/core/mock-server/src/daren_market.rs @@ -0,0 +1,48 @@ +// 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::daren_market::UserVerificationResponse; + +use warp::{http::Response, Filter}; + +pub(crate) fn query() -> impl Filter + Clone { + warp::get() + .and(warp::path!("daren_market" / "api" / "talent-asset")) + .and(warp::query::>()) + .map(move |p: HashMap| { + let default = String::default(); + let address = p.get("address").unwrap_or(&default); + + if address == "0x49ad262c49c7aa708cc2df262ed53b64a17dd5ee" { + let body = UserVerificationResponse { + success: true, + created: true, + message: "Talent Asset Found!".to_string(), + }; + Response::builder().body(serde_json::to_string(&body).unwrap()) + } else { + let body = UserVerificationResponse { + success: false, + created: false, + message: "".to_string(), + }; + Response::builder().body(serde_json::to_string(&body).unwrap()) + } + }) +} diff --git a/tee-worker/litentry/core/mock-server/src/lib.rs b/tee-worker/litentry/core/mock-server/src/lib.rs index 06d849d420..7337fbe9cb 100644 --- a/tee-worker/litentry/core/mock-server/src/lib.rs +++ b/tee-worker/litentry/core/mock-server/src/lib.rs @@ -26,6 +26,7 @@ use warp::Filter; pub mod achainable; pub mod blockchain_info; +pub mod daren_market; pub mod discord_litentry; pub mod discord_official; pub mod geniidata; @@ -76,6 +77,7 @@ pub fn run(port: u16) -> Result { .or(nodereal_jsonrpc::query()) .or(karat_dao::query()) .or(magic_craft::query()) + .or(daren_market::query()) .or(moralis::query_nft()) .or(moralis::query_erc20()) .or(moralis::query_solana()) diff --git a/tee-worker/litentry/core/service/src/platform_user/daren_market_user.rs b/tee-worker/litentry/core/service/src/platform_user/daren_market_user.rs new file mode 100644 index 0000000000..7591897ddb --- /dev/null +++ b/tee-worker/litentry/core/service/src/platform_user/daren_market_user.rs @@ -0,0 +1,58 @@ +// 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 std::string::ToString; + +use lc_common::abort_strategy::{loop_with_abort_strategy, AbortStrategy, LoopControls}; +use lc_data_providers::{ + daren_market::{DarenMarketApi, DarenMarketClient}, + DataProviderConfig, +}; + +use crate::*; + +pub fn is_user( + addresses: Vec, + data_provider_config: &DataProviderConfig, +) -> Result { + let mut result = false; + let mut client = DarenMarketClient::new(data_provider_config); + + loop_with_abort_strategy( + addresses, + |address| match client.user_verification(address.to_string(), true) { + Ok(response) => + if response.created { + result = true; + Ok(LoopControls::Break) + } else { + Ok(LoopControls::Continue) + }, + Err(err) => Err(err.into_error_detail()), + }, + AbortStrategy::ContinueUntilEnd:: bool>, + ) + .map_err(|errors| errors[0].clone())?; + + Ok(result) +} 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 eb34778bc8..e02f9e5cec 100644 --- a/tee-worker/litentry/core/service/src/platform_user/mod.rs +++ b/tee-worker/litentry/core/service/src/platform_user/mod.rs @@ -27,6 +27,7 @@ use litentry_primitives::PlatformUserType; use crate::*; +mod daren_market_user; mod karat_dao_user; mod magic_craft_staking_user; @@ -36,8 +37,10 @@ pub fn is_user( data_provider_config: &DataProviderConfig, ) -> Result { match platform_user_type { - PlatformUserType::KaratDaoUser => karat_dao_user::is_user(addresses, data_provider_config), - PlatformUserType::MagicCraftStakingUser => + PlatformUserType::KaratDao => karat_dao_user::is_user(addresses, data_provider_config), + PlatformUserType::MagicCraftStaking => magic_craft_staking_user::is_user(addresses, data_provider_config), + PlatformUserType::DarenMarket => + daren_market_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 02ecb577d6..2c3f4daf5b 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 @@ -312,15 +312,21 @@ export const mockAssertions = [ // PlatformUser { - description: 'You are a user of a certain platform', + description: 'You are a user of platform KaratDao', assertion: { - PlatformUser: 'KaratDaoUser', + PlatformUser: 'KaratDao', }, }, { - description: 'You are a user of a certain platform', + description: 'You are a user of platform MagicCraft', assertion: { - PlatformUser: 'MagicCraftStakingUser', + PlatformUser: 'MagicCraftStaking', + }, + }, + { + description: 'You are a user of platform DarenMarket', + assertion: { + PlatformUser: 'DarenMarket', }, },