diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs --- a/native/native_rust_library/src/lib.rs +++ b/native/native_rust_library/src/lib.rs @@ -16,8 +16,8 @@ UploadOneTimeKeysRequest, }; use grpc_clients::identity::protos::unauth::{ - AuthResponse, DeviceKeyUpload, DeviceType, Empty, IdentityKeyInfo, - OpaqueLoginFinishRequest, OpaqueLoginStartRequest, Prekey, + AuthResponse, DeviceKeyUpload, DeviceType, Empty, ExistingDeviceLoginRequest, + IdentityKeyInfo, OpaqueLoginFinishRequest, OpaqueLoginStartRequest, Prekey, RegistrationFinishRequest, RegistrationStartRequest, SecondaryDeviceKeysUploadRequest, WalletAuthRequest, }; @@ -233,6 +233,14 @@ promise_id: u32, ); + #[cxx_name = "identityLogInExistingDevice"] + fn log_in_existing_device( + user_id: String, + device_id: String, + challenge_response: String, + promise_id: u32, + ); + #[cxx_name = "identityFindUserIDForWalletAddress"] fn find_user_id_for_wallet_address(wallet_address: String, promise_id: u32); @@ -1466,6 +1474,47 @@ Ok(serde_json::to_string(&user_id_and_access_token)?) } +fn log_in_existing_device( + user_id: String, + device_id: String, + challenge_response: String, + promise_id: u32, +) { + RUNTIME.spawn(async move { + let result = + log_in_existing_device_helper(user_id, device_id, challenge_response) + .await; + handle_string_result_as_callback(result, promise_id); + }); +} + +async fn log_in_existing_device_helper( + user_id: String, + device_id: String, + challenge_response: String, +) -> Result { + let mut identity_client = get_unauthenticated_client( + IDENTITY_SOCKET_ADDR, + CODE_VERSION, + DEVICE_TYPE.as_str_name().to_lowercase(), + ) + .await?; + + let request = ExistingDeviceLoginRequest { + user_id, + device_id, + challenge_response, + }; + + let response = identity_client + .log_in_existing_device(request) + .await? + .into_inner(); + + let user_id_and_access_token = UserIDAndDeviceAccessToken::from(response); + Ok(serde_json::to_string(&user_id_and_access_token)?) +} + #[derive( Debug, derive_more::Display, derive_more::From, derive_more::Error, )]