diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs index 1f00d12a9..2113a1ec5 100644 --- a/native/native_rust_library/src/lib.rs +++ b/native/native_rust_library/src/lib.rs @@ -1,170 +1,182 @@ use lazy_static::lazy_static; use std::sync::Arc; use tokio::runtime::{Builder, Runtime}; use tonic::{transport::Channel, Status}; use tracing::instrument; mod crypto_tools; mod identity_client; mod identity { tonic::include_proto!("identity"); } use crypto_tools::generate_device_id; use identity::identity_service_client::IdentityServiceClient; lazy_static! { pub static ref RUNTIME: Arc = Arc::new( Builder::new_multi_thread() .worker_threads(1) .max_blocking_threads(1) .enable_all() .build() .unwrap() ); } #[cxx::bridge] mod ffi { enum DeviceType { KEYSERVER, WEB, MOBILE, } extern "Rust" { // Identity Service Client type IdentityClient; + + #[cxx_name = "identityInitializeClient"] fn initialize_identity_client(addr: String) -> Box; + + #[cxx_name = "identityGetUserIdBlocking"] fn identity_get_user_id_blocking( client: Box, auth_type: i32, user_info: String, ) -> Result; + + #[cxx_name = "identityVerifyUserTokenBlocking"] fn identity_verify_user_token_blocking( client: Box, user_id: String, device_id: String, access_token: String, ) -> Result; + + #[cxx_name = "identityRegisterUserBlocking"] fn identity_register_user_blocking( client: Box, user_id: String, device_id: String, username: String, password: String, user_public_key: String, ) -> Result; + + #[cxx_name = "identityLoginUserPakeBlocking"] fn identity_login_user_pake_blocking( client: Box, user_id: String, device_id: String, password: String, user_public_key: String, ) -> Result; + + #[cxx_name = "identityLoginUserWalletBlocking"] fn identity_login_user_wallet_blocking( client: Box, user_id: String, device_id: String, siwe_message: String, siwe_signature: Vec, user_public_key: String, ) -> Result; // Crypto Tools fn generate_device_id(device_type: DeviceType) -> Result; } } #[derive(Debug)] pub struct IdentityClient { identity_client: IdentityServiceClient, } fn initialize_identity_client(addr: String) -> Box { Box::new(IdentityClient { identity_client: RUNTIME .block_on(IdentityServiceClient::connect(addr)) .unwrap(), }) } #[instrument] fn identity_get_user_id_blocking( client: Box, auth_type: i32, user_info: String, ) -> Result { RUNTIME.block_on(identity_client::get_user_id(client, auth_type, user_info)) } #[instrument] fn identity_verify_user_token_blocking( client: Box, user_id: String, device_id: String, access_token: String, ) -> Result { RUNTIME.block_on(identity_client::verify_user_token( client, user_id, device_id, access_token, )) } #[instrument] fn identity_register_user_blocking( client: Box, user_id: String, device_id: String, username: String, password: String, user_public_key: String, ) -> Result { RUNTIME.block_on(identity_client::register_user( client, user_id, device_id, username, password, user_public_key, )) } #[instrument] fn identity_login_user_pake_blocking( client: Box, user_id: String, device_id: String, password: String, user_public_key: String, ) -> Result { RUNTIME.block_on(identity_client::login_user_pake( client, user_id, device_id, password, user_public_key, )) } #[instrument] fn identity_login_user_wallet_blocking( client: Box, user_id: String, device_id: String, siwe_message: String, siwe_signature: Vec, user_public_key: String, ) -> Result { RUNTIME.block_on(identity_client::login_user_wallet( client, user_id, device_id, siwe_message, siwe_signature, user_public_key, )) }