Page MenuHomePhabricator

D13230.diff
No OneTemporary

D13230.diff

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
@@ -145,6 +145,14 @@
pub initial_device_list: String,
}
+pub struct RestoreUserInfo {
+ pub user_id: String,
+ pub siwe_message: Option<String>,
+ pub siwe_signature: Option<String>,
+ pub device_keys: DeviceKeys,
+ pub device_list: String,
+}
+
/// Counterpart of proto [`AuthResponse`] message
/// that implements the `Serialize` trait.
#[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
@@ -4,14 +4,14 @@
protos::unauth::{
DeviceKeyUpload, ExistingDeviceLoginRequest, IdentityKeyInfo,
OpaqueLoginFinishRequest, OpaqueLoginStartRequest, Prekey,
- SecondaryDeviceKeysUploadRequest, WalletAuthRequest,
+ RestoreUserRequest, SecondaryDeviceKeysUploadRequest, WalletAuthRequest,
},
};
use tracing::instrument;
use super::{
IdentityAuthResult, LogInPasswordUserInfo, LogInWalletUserInfo,
- PLATFORM_METADATA,
+ RestoreUserInfo, PLATFORM_METADATA,
};
use crate::utils::jsi_callbacks::handle_string_result_as_callback;
use crate::{Error, DEVICE_TYPE, IDENTITY_SOCKET_ADDR, RUNTIME};
@@ -88,6 +88,47 @@
});
}
+ // Primary device restore
+ #[instrument]
+ pub fn restore_user(
+ user_id: String,
+ siwe_message: String,
+ siwe_signature: String,
+ key_payload: String,
+ key_payload_signature: String,
+ content_prekey: String,
+ content_prekey_signature: String,
+ notif_prekey: String,
+ notif_prekey_signature: String,
+ content_one_time_keys: Vec<String>,
+ notif_one_time_keys: Vec<String>,
+ device_list: String,
+ promise_id: u32,
+ ) {
+ RUNTIME.spawn(async move {
+ let siwe_message = Some(siwe_message).filter(|it| !it.is_empty());
+ let siwe_signature = Some(siwe_signature).filter(|it| !it.is_empty());
+ let restored_user_info = RestoreUserInfo {
+ user_id,
+ siwe_message,
+ siwe_signature,
+ device_list,
+ 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,
+ },
+ };
+ let result = restore_user_helper(restored_user_info).await;
+ handle_string_result_as_callback(result, promise_id);
+ });
+ }
+
// QR code device log in
pub fn upload_secondary_device_keys_and_log_in(
user_id: String,
@@ -218,6 +259,30 @@
Ok(serde_json::to_string(&auth_result)?)
}
+async fn restore_user_helper(
+ wallet_user_info: RestoreUserInfo,
+) -> Result<String, Error> {
+ let restore_request = RestoreUserRequest {
+ user_id: wallet_user_info.user_id,
+ siwe_message: wallet_user_info.siwe_message,
+ siwe_signature: wallet_user_info.siwe_signature,
+ device_list: wallet_user_info.device_list,
+ device_key_upload: Some(wallet_user_info.device_keys.into()),
+ };
+
+ let mut identity_client =
+ get_unauthenticated_client(IDENTITY_SOCKET_ADDR, PLATFORM_METADATA.clone())
+ .await?;
+
+ let auth_response = identity_client
+ .restore_user(restore_request)
+ .await?
+ .into_inner();
+
+ let auth_result = IdentityAuthResult::from(auth_response);
+ Ok(serde_json::to_string(&auth_result)?)
+}
+
async fn upload_secondary_device_keys_and_log_in_helper(
user_id: String,
nonce: String,
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
@@ -125,6 +125,23 @@
promise_id: u32,
);
+ #[cxx_name = "identityRestoreUser"]
+ fn restore_user(
+ user_id: String,
+ siwe_message: String,
+ siwe_signature: String,
+ key_payload: String,
+ key_payload_signature: String,
+ content_prekey: String,
+ content_prekey_signature: String,
+ notif_prekey: String,
+ notif_prekey_signature: String,
+ content_one_time_keys: Vec<String>,
+ notif_one_time_keys: Vec<String>,
+ device_list: String,
+ promise_id: u32,
+ );
+
#[cxx_name = "identityUpdateUserPassword"]
fn update_user_password(
user_id: String,

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 11:21 AM (21 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2584406
Default Alt Text
D13230.diff (4 KB)

Event Timeline