diff --git a/native/native_rust_library/src/identity.rs b/native/native_rust_library/src/identity.rs --- a/native/native_rust_library/src/identity.rs +++ b/native/native_rust_library/src/identity.rs @@ -52,9 +52,7 @@ pub access_token: String, } -pub struct PasswordUserInfo { - pub username: String, - pub password: String, +pub struct DeviceKeys { pub key_payload: String, pub key_payload_signature: String, pub content_prekey: String, @@ -63,21 +61,52 @@ pub notif_prekey_signature: String, pub content_one_time_keys: Vec, pub notif_one_time_keys: Vec, +} + +pub struct LogInPasswordUserInfo { + pub username: String, + pub password: String, + pub device_keys: DeviceKeys, +} + +pub struct RegisterPasswordUserInfo { + pub username: String, + pub password: String, + pub device_keys: DeviceKeys, pub farcaster_id: Option, + pub initial_device_list: String, } -pub struct WalletUserInfo { +pub struct RegisterReservedPasswordUserInfo { + pub username: String, + pub password: String, + pub device_keys: DeviceKeys, + pub keyserver_message: String, + pub keyserver_signature: String, + pub initial_device_list: String, +} + +pub struct LogInWalletUserInfo { pub siwe_message: String, pub siwe_signature: String, - pub key_payload: String, - pub key_payload_signature: String, - pub content_prekey: String, - pub content_prekey_signature: String, - pub notif_prekey: String, - pub notif_prekey_signature: String, - pub content_one_time_keys: Vec, - pub notif_one_time_keys: Vec, + pub device_keys: DeviceKeys, +} + +pub struct RegisterWalletUserInfo { + pub siwe_message: String, + pub siwe_signature: String, + pub device_keys: DeviceKeys, pub farcaster_id: Option, + pub initial_device_list: String, +} + +pub struct RegisterReservedWalletUserInfo { + pub siwe_message: String, + pub siwe_signature: String, + pub device_keys: DeviceKeys, + pub keyserver_message: String, + pub keyserver_signature: String, + pub initial_device_list: String, } #[derive(Serialize)] diff --git a/native/native_rust_library/src/identity/login.rs b/native/native_rust_library/src/identity/login.rs --- a/native/native_rust_library/src/identity/login.rs +++ b/native/native_rust_library/src/identity/login.rs @@ -9,11 +9,17 @@ }; use tracing::instrument; -use super::{PasswordUserInfo, UserIDAndDeviceAccessToken, WalletUserInfo}; +use super::{ + LogInPasswordUserInfo, LogInWalletUserInfo, UserIDAndDeviceAccessToken, +}; use crate::utils::jsi_callbacks::handle_string_result_as_callback; use crate::{Error, CODE_VERSION, DEVICE_TYPE, IDENTITY_SOCKET_ADDR, RUNTIME}; pub mod ffi { + use crate::identity::{ + DeviceKeys, LogInPasswordUserInfo, LogInWalletUserInfo, + }; + use super::*; #[instrument] @@ -29,18 +35,19 @@ promise_id: u32, ) { RUNTIME.spawn(async move { - let password_user_info = PasswordUserInfo { + let password_user_info = LogInPasswordUserInfo { username, password, - key_payload, - key_payload_signature, - content_prekey, - content_prekey_signature, - notif_prekey, - notif_prekey_signature, - content_one_time_keys: Vec::new(), - notif_one_time_keys: Vec::new(), - farcaster_id: None, + device_keys: DeviceKeys { + key_payload, + key_payload_signature, + content_prekey, + content_prekey_signature, + notif_prekey, + notif_prekey_signature, + content_one_time_keys: Vec::new(), + notif_one_time_keys: Vec::new(), + }, }; let result = log_in_password_user_helper(password_user_info).await; handle_string_result_as_callback(result, promise_id); @@ -60,18 +67,19 @@ promise_id: u32, ) { RUNTIME.spawn(async move { - let wallet_user_info = WalletUserInfo { + let wallet_user_info = LogInWalletUserInfo { siwe_message, siwe_signature, - key_payload, - key_payload_signature, - content_prekey, - content_prekey_signature, - notif_prekey, - notif_prekey_signature, - content_one_time_keys: Vec::new(), - notif_one_time_keys: Vec::new(), - farcaster_id: None, + device_keys: DeviceKeys { + key_payload, + key_payload_signature, + content_prekey, + content_prekey_signature, + notif_prekey, + notif_prekey_signature, + content_one_time_keys: Vec::new(), + notif_one_time_keys: Vec::new(), + }, }; let result = log_in_wallet_user_helper(wallet_user_info).await; handle_string_result_as_callback(result, promise_id); @@ -144,7 +152,7 @@ } async fn log_in_password_user_helper( - password_user_info: PasswordUserInfo, + password_user_info: LogInPasswordUserInfo, ) -> Result { let mut client_login = Login::new(); let opaque_login_request = client_login @@ -155,19 +163,25 @@ username: password_user_info.username, device_key_upload: Some(DeviceKeyUpload { device_key_info: Some(IdentityKeyInfo { - payload: password_user_info.key_payload, - payload_signature: password_user_info.key_payload_signature, + payload: password_user_info.device_keys.key_payload, + payload_signature: password_user_info.device_keys.key_payload_signature, }), content_upload: Some(Prekey { - prekey: password_user_info.content_prekey, - prekey_signature: password_user_info.content_prekey_signature, + prekey: password_user_info.device_keys.content_prekey, + prekey_signature: password_user_info + .device_keys + .content_prekey_signature, }), notif_upload: Some(Prekey { - prekey: password_user_info.notif_prekey, - prekey_signature: password_user_info.notif_prekey_signature, + prekey: password_user_info.device_keys.notif_prekey, + prekey_signature: password_user_info.device_keys.notif_prekey_signature, }), - one_time_content_prekeys: password_user_info.content_one_time_keys, - one_time_notif_prekeys: password_user_info.notif_one_time_keys, + one_time_content_prekeys: password_user_info + .device_keys + .content_one_time_keys, + one_time_notif_prekeys: password_user_info + .device_keys + .notif_one_time_keys, device_type: DEVICE_TYPE.into(), }), force: None, @@ -205,26 +219,28 @@ } async fn log_in_wallet_user_helper( - wallet_user_info: WalletUserInfo, + wallet_user_info: LogInWalletUserInfo, ) -> Result { let login_request = WalletAuthRequest { siwe_message: wallet_user_info.siwe_message, siwe_signature: wallet_user_info.siwe_signature, device_key_upload: Some(DeviceKeyUpload { device_key_info: Some(IdentityKeyInfo { - payload: wallet_user_info.key_payload, - payload_signature: wallet_user_info.key_payload_signature, + payload: wallet_user_info.device_keys.key_payload, + payload_signature: wallet_user_info.device_keys.key_payload_signature, }), content_upload: Some(Prekey { - prekey: wallet_user_info.content_prekey, - prekey_signature: wallet_user_info.content_prekey_signature, + prekey: wallet_user_info.device_keys.content_prekey, + prekey_signature: wallet_user_info.device_keys.content_prekey_signature, }), notif_upload: Some(Prekey { - prekey: wallet_user_info.notif_prekey, - prekey_signature: wallet_user_info.notif_prekey_signature, + prekey: wallet_user_info.device_keys.notif_prekey, + prekey_signature: wallet_user_info.device_keys.notif_prekey_signature, }), - one_time_content_prekeys: wallet_user_info.content_one_time_keys, - one_time_notif_prekeys: wallet_user_info.notif_one_time_keys, + one_time_content_prekeys: wallet_user_info + .device_keys + .content_one_time_keys, + one_time_notif_prekeys: wallet_user_info.device_keys.notif_one_time_keys, device_type: DEVICE_TYPE.into(), }), farcaster_id: None, diff --git a/native/native_rust_library/src/identity/registration.rs b/native/native_rust_library/src/identity/registration.rs --- a/native/native_rust_library/src/identity/registration.rs +++ b/native/native_rust_library/src/identity/registration.rs @@ -13,11 +13,15 @@ use tracing::instrument; use super::{ - farcaster::farcaster_id_string_to_option, PasswordUserInfo, - UserIDAndDeviceAccessToken, WalletUserInfo, + farcaster::farcaster_id_string_to_option, RegisterPasswordUserInfo, + RegisterWalletUserInfo, UserIDAndDeviceAccessToken, }; pub mod ffi { + use crate::identity::{ + DeviceKeys, RegisterPasswordUserInfo, RegisterWalletUserInfo, + }; + use super::*; #[instrument] @@ -37,22 +41,23 @@ promise_id: u32, ) { RUNTIME.spawn(async move { - let password_user_info = PasswordUserInfo { + let password_user_info = RegisterPasswordUserInfo { username, password, - key_payload, - key_payload_signature, - content_prekey, - content_prekey_signature, - notif_prekey, - notif_prekey_signature, - content_one_time_keys, - notif_one_time_keys, + device_keys: DeviceKeys { + key_payload, + key_payload_signature, + content_prekey, + content_prekey_signature, + notif_prekey, + notif_prekey_signature, + content_one_time_keys, + notif_one_time_keys, + }, farcaster_id: farcaster_id_string_to_option(&farcaster_id), + initial_device_list, }; - let result = - register_password_user_helper(password_user_info, initial_device_list) - .await; + let result = register_password_user_helper(password_user_info).await; handle_string_result_as_callback(result, promise_id); }); } @@ -74,30 +79,30 @@ promise_id: u32, ) { RUNTIME.spawn(async move { - let wallet_user_info = WalletUserInfo { + let wallet_user_info = RegisterWalletUserInfo { siwe_message, siwe_signature, - key_payload, - key_payload_signature, - content_prekey, - content_prekey_signature, - notif_prekey, - notif_prekey_signature, - content_one_time_keys, - notif_one_time_keys, + device_keys: DeviceKeys { + key_payload, + key_payload_signature, + content_prekey, + content_prekey_signature, + notif_prekey, + notif_prekey_signature, + content_one_time_keys, + notif_one_time_keys, + }, farcaster_id: farcaster_id_string_to_option(&farcaster_id), + initial_device_list, }; - let result = - register_wallet_user_helper(wallet_user_info, initial_device_list) - .await; + let result = register_wallet_user_helper(wallet_user_info).await; handle_string_result_as_callback(result, promise_id); }); } } async fn register_password_user_helper( - password_user_info: PasswordUserInfo, - initial_device_list: String, + password_user_info: RegisterPasswordUserInfo, ) -> Result { let mut client_registration = Registration::new(); let opaque_registration_request = client_registration @@ -108,23 +113,29 @@ username: password_user_info.username, device_key_upload: Some(DeviceKeyUpload { device_key_info: Some(IdentityKeyInfo { - payload: password_user_info.key_payload, - payload_signature: password_user_info.key_payload_signature, + payload: password_user_info.device_keys.key_payload, + payload_signature: password_user_info.device_keys.key_payload_signature, }), content_upload: Some(Prekey { - prekey: password_user_info.content_prekey, - prekey_signature: password_user_info.content_prekey_signature, + prekey: password_user_info.device_keys.content_prekey, + prekey_signature: password_user_info + .device_keys + .content_prekey_signature, }), notif_upload: Some(Prekey { - prekey: password_user_info.notif_prekey, - prekey_signature: password_user_info.notif_prekey_signature, + prekey: password_user_info.device_keys.notif_prekey, + prekey_signature: password_user_info.device_keys.notif_prekey_signature, }), - one_time_content_prekeys: password_user_info.content_one_time_keys, - one_time_notif_prekeys: password_user_info.notif_one_time_keys, + one_time_content_prekeys: password_user_info + .device_keys + .content_one_time_keys, + one_time_notif_prekeys: password_user_info + .device_keys + .notif_one_time_keys, device_type: DEVICE_TYPE.into(), }), farcaster_id: password_user_info.farcaster_id, - initial_device_list, + initial_device_list: password_user_info.initial_device_list, }; let mut identity_client = get_unauthenticated_client( @@ -161,31 +172,32 @@ } async fn register_wallet_user_helper( - wallet_user_info: WalletUserInfo, - initial_device_list: String, + wallet_user_info: RegisterWalletUserInfo, ) -> Result { let registration_request = WalletAuthRequest { siwe_message: wallet_user_info.siwe_message, siwe_signature: wallet_user_info.siwe_signature, device_key_upload: Some(DeviceKeyUpload { device_key_info: Some(IdentityKeyInfo { - payload: wallet_user_info.key_payload, - payload_signature: wallet_user_info.key_payload_signature, + payload: wallet_user_info.device_keys.key_payload, + payload_signature: wallet_user_info.device_keys.key_payload_signature, }), content_upload: Some(Prekey { - prekey: wallet_user_info.content_prekey, - prekey_signature: wallet_user_info.content_prekey_signature, + prekey: wallet_user_info.device_keys.content_prekey, + prekey_signature: wallet_user_info.device_keys.content_prekey_signature, }), notif_upload: Some(Prekey { - prekey: wallet_user_info.notif_prekey, - prekey_signature: wallet_user_info.notif_prekey_signature, + prekey: wallet_user_info.device_keys.notif_prekey, + prekey_signature: wallet_user_info.device_keys.notif_prekey_signature, }), - one_time_content_prekeys: wallet_user_info.content_one_time_keys, - one_time_notif_prekeys: wallet_user_info.notif_one_time_keys, + one_time_content_prekeys: wallet_user_info + .device_keys + .content_one_time_keys, + one_time_notif_prekeys: wallet_user_info.device_keys.notif_one_time_keys, device_type: DEVICE_TYPE.into(), }), farcaster_id: wallet_user_info.farcaster_id, - initial_device_list, + initial_device_list: wallet_user_info.initial_device_list, }; let mut identity_client = get_unauthenticated_client(