diff --git a/native/native_rust_library/src/identity_client.rs b/native/native_rust_library/src/identity_client.rs index 7d66880a1..3b13d7e4e 100644 --- a/native/native_rust_library/src/identity_client.rs +++ b/native/native_rust_library/src/identity_client.rs @@ -1,32 +1,52 @@ use tonic::Status; use crate::IdentityClient; pub async fn register_user( mut _client: Box, - _user_id: String, - _signing_public_key: String, _username: String, _password: String, + _key_payload: String, + _key_payload_signature: String, + _identity_prekey: String, + _identity_prekey_signature: String, + _notif_prekey: String, + _notif_prekey_signature: String, + _identity_onetime_keys: Vec, + _notif_onetime_keys: Vec, ) -> Result { unimplemented!(); } +// User could be logging in from new device, need to resend device information pub async fn login_user_pake( mut _client: Box, - _user_id: String, - _signing_public_key: String, + _username: String, _password: String, + _key_payload: String, + _key_payload_signature: String, + _identity_prekey: String, + _identity_prekey_signature: String, + _notif_prekey: String, + _notif_prekey_signature: String, + _identity_onetime_keys: Vec, + _notif_onetime_keys: Vec, ) -> Result { unimplemented!(); } pub async fn login_user_wallet( mut _client: Box, - _user_id: String, - _signing_public_key: String, _siwe_message: String, _siwe_signature: String, + _key_payload: String, + _key_payload_signature: String, + _identity_prekey: String, + _identity_prekey_signature: String, + _notif_prekey: String, + _notif_prekey_signature: String, + _identity_onetime_keys: Vec, + _notif_onetime_keys: Vec, ) -> Result { unimplemented!(); } diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs index a875ab191..f8bf31e08 100644 --- a/native/native_rust_library/src/lib.rs +++ b/native/native_rust_library/src/lib.rs @@ -1,157 +1,214 @@ use lazy_static::lazy_static; use std::sync::Arc; use tokio::runtime::{Builder, Runtime}; use tonic::{transport::Channel, Status}; use tracing::instrument; use tunnelbroker::tunnelbroker_service_client::TunnelbrokerServiceClient; mod crypto_tools; mod identity_client; mod identity { tonic::include_proto!("identity.client"); } mod tunnelbroker { tonic::include_proto!("tunnelbroker"); } use crypto_tools::generate_device_id; use identity::identity_client_service_client::IdentityClientServiceClient; 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 = "identityRegisterUserBlocking"] fn identity_register_user_blocking( client: Box, - user_id: String, - signing_public_key: String, username: String, password: String, + key_payload: String, + key_payload_signature: String, + identity_prekey: String, + identity_prekey_signature: String, + notif_prekey: String, + notif_prekey_signature: String, + identity_onetime_keys: Vec, + notif_onetime_keys: Vec, ) -> Result; #[cxx_name = "identityLoginUserPakeBlocking"] fn identity_login_user_pake_blocking( client: Box, - user_id: String, - signing_public_key: String, + username: String, password: String, + key_payload: String, + key_payload_signature: String, + identity_prekey: String, + identity_prekey_signature: String, + notif_prekey: String, + notif_prekey_signature: String, + identity_onetime_keys: Vec, + notif_onetime_keys: Vec, ) -> Result; #[cxx_name = "identityLoginUserWalletBlocking"] fn identity_login_user_wallet_blocking( client: Box, - user_id: String, - signing_public_key: String, siwe_message: String, siwe_signature: String, + key_payload: String, + key_payload_signature: String, + identity_prekey: String, + identity_prekey_signature: String, + notif_prekey: String, + notif_prekey_signature: String, + identity_onetime_keys: Vec, + notif_onetime_keys: Vec, ) -> Result; // Tunnelbroker Service Client type TunnelbrokerClient; #[cxx_name = "TunnelbrokerInitializeClient"] fn initialize_tunnelbroker_client(addr: String) -> Box; // Crypto Tools fn generate_device_id(device_type: DeviceType) -> Result; } } #[derive(Debug)] pub struct IdentityClient { identity_client: IdentityClientServiceClient, } fn initialize_identity_client(addr: String) -> Box { Box::new(IdentityClient { identity_client: RUNTIME .block_on(IdentityClientServiceClient::connect(addr)) .unwrap(), }) } #[instrument] fn identity_register_user_blocking( client: Box, - user_id: String, - signing_public_key: String, username: String, password: String, + key_payload: String, + key_payload_signature: String, + identity_prekey: String, + identity_prekey_signature: String, + notif_prekey: String, + notif_prekey_signature: String, + identity_onetime_keys: Vec, + notif_onetime_keys: Vec, ) -> Result { RUNTIME.block_on(identity_client::register_user( client, - user_id, - signing_public_key, username, password, + key_payload, + key_payload_signature, + identity_prekey, + identity_prekey_signature, + notif_prekey, + notif_prekey_signature, + identity_onetime_keys, + notif_onetime_keys, )) } #[instrument] fn identity_login_user_pake_blocking( client: Box, - user_id: String, - signing_public_key: String, + username: String, password: String, + key_payload: String, + key_payload_signature: String, + identity_prekey: String, + identity_prekey_signature: String, + notif_prekey: String, + notif_prekey_signature: String, + identity_onetime_keys: Vec, + notif_onetime_keys: Vec, ) -> Result { RUNTIME.block_on(identity_client::login_user_pake( client, - user_id, - signing_public_key, + username, password, + key_payload, + key_payload_signature, + identity_prekey, + identity_prekey_signature, + notif_prekey, + notif_prekey_signature, + identity_onetime_keys, + notif_onetime_keys, )) } #[instrument] fn identity_login_user_wallet_blocking( client: Box, - user_id: String, - signing_public_key: String, siwe_message: String, siwe_signature: String, + key_payload: String, + key_payload_signature: String, + identity_prekey: String, + identity_prekey_signature: String, + notif_prekey: String, + notif_prekey_signature: String, + identity_onetime_keys: Vec, + notif_onetime_keys: Vec, ) -> Result { RUNTIME.block_on(identity_client::login_user_wallet( client, - user_id, - signing_public_key, siwe_message, siwe_signature, + key_payload, + key_payload_signature, + identity_prekey, + identity_prekey_signature, + notif_prekey, + notif_prekey_signature, + identity_onetime_keys, + notif_onetime_keys, )) } #[derive(Debug)] pub struct TunnelbrokerClient { tunnelbroker_client: TunnelbrokerServiceClient, } fn initialize_tunnelbroker_client(addr: String) -> Box { Box::new(TunnelbrokerClient { tunnelbroker_client: RUNTIME .block_on(TunnelbrokerServiceClient::connect(addr)) .expect("Failed to create Tokio runtime for the Tunnelbroker client"), }) }