diff --git a/native/backup/restore-siwe-backup.react.js b/native/backup/restore-siwe-backup.react.js --- a/native/backup/restore-siwe-backup.react.js +++ b/native/backup/restore-siwe-backup.react.js @@ -31,19 +31,22 @@ const { goBack } = props.navigation; const { route } = props; const { - params: { backupID, siweStatement, siweIssuedAt, siweNonce }, + params: { siweStatement, siweIssuedAt, siweNonce }, } = route; const onSuccessfulWalletSignature = React.useCallback( (result: SIWEResult) => { void (async () => { + // eslint-disable-next-line no-unused-vars const { signature } = result; let message = 'success'; try { - await commCoreModule.restoreBackup( - signature, + //TODO add backup keys + await commCoreModule.restoreBackupData( + '', + '', + '', persistConfig.version.toString(), - backupID, ); } catch (e) { message = `Backup restore error: ${String( @@ -55,7 +58,7 @@ goBack(); })(); }, - [goBack, backupID], + [goBack], ); return ( diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h @@ -218,11 +218,6 @@ createFullBackup(jsi::Runtime &rt, jsi::String backupSecret) override; virtual jsi::Value createUserKeysBackup(jsi::Runtime &rt, jsi::String backupSecret) override; - virtual jsi::Value restoreBackup( - jsi::Runtime &rt, - jsi::String backupSecret, - jsi::String maxVersion, - jsi::String backupID) override; virtual jsi::Value restoreBackupData( jsi::Runtime &rt, jsi::String backupID, diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -2642,27 +2642,6 @@ }); } -jsi::Value CommCoreModule::restoreBackup( - jsi::Runtime &rt, - jsi::String backupSecret, - jsi::String maxVersion, - jsi::String backupID) { - std::string backupSecretStr = backupSecret.utf8(rt); - std::string maxVersionStr = maxVersion.utf8(rt); - std::string backupIDStr = backupID.utf8(rt); - - return createPromiseAsJSIValue( - rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { - auto currentID = RustPromiseManager::instance.addPromise( - {promise, this->jsInvoker_, innerRt}); - ::restoreBackup( - rust::string(backupSecretStr), - rust::string(backupIDStr), - rust::string(maxVersionStr), - currentID); - }); -} - jsi::Value CommCoreModule::restoreBackupData( jsi::Runtime &rt, jsi::String backupID, diff --git a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp --- a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp +++ b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp @@ -187,9 +187,6 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_createFullBackup(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->createFullBackup(rt, args[0].asString(rt)); } -static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackup(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->restoreBackup(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt)); -} static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackupData(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->restoreBackupData(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt)); } @@ -303,7 +300,6 @@ methodMap_["stopBackupHandler"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_stopBackupHandler}; methodMap_["createUserKeysBackup"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_createUserKeysBackup}; methodMap_["createFullBackup"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_createFullBackup}; - methodMap_["restoreBackup"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackup}; methodMap_["restoreBackupData"] = MethodMetadata {4, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackupData}; methodMap_["getQRAuthBackupData"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getQRAuthBackupData}; methodMap_["retrieveLatestBackupInfo"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveLatestBackupInfo}; diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h --- a/native/cpp/CommonCpp/_generated/commJSI.h +++ b/native/cpp/CommonCpp/_generated/commJSI.h @@ -76,7 +76,6 @@ virtual void stopBackupHandler(jsi::Runtime &rt) = 0; virtual jsi::Value createUserKeysBackup(jsi::Runtime &rt, jsi::String backupSecret) = 0; virtual jsi::Value createFullBackup(jsi::Runtime &rt, jsi::String backupSecret) = 0; - virtual jsi::Value restoreBackup(jsi::Runtime &rt, jsi::String backupSecret, jsi::String maxVersion, jsi::String backupID) = 0; virtual jsi::Value restoreBackupData(jsi::Runtime &rt, jsi::String backupID, jsi::String backupDataKey, jsi::String backupLogDataKey, jsi::String maxVersion) = 0; virtual jsi::Value getQRAuthBackupData(jsi::Runtime &rt) = 0; virtual jsi::Value retrieveLatestBackupInfo(jsi::Runtime &rt, jsi::String userIdentifier) = 0; @@ -564,14 +563,6 @@ return bridging::callFromJs( rt, &T::createFullBackup, jsInvoker_, instance_, std::move(backupSecret)); } - jsi::Value restoreBackup(jsi::Runtime &rt, jsi::String backupSecret, jsi::String maxVersion, jsi::String backupID) override { - static_assert( - bridging::getParameterCount(&T::restoreBackup) == 4, - "Expected restoreBackup(...) to have 4 parameters"); - - return bridging::callFromJs( - rt, &T::restoreBackup, jsInvoker_, instance_, std::move(backupSecret), std::move(maxVersion), std::move(backupID)); - } jsi::Value restoreBackupData(jsi::Runtime &rt, jsi::String backupID, jsi::String backupDataKey, jsi::String backupLogDataKey, jsi::String maxVersion) override { static_assert( bridging::getParameterCount(&T::restoreBackupData) == 5, diff --git a/native/native_rust_library/src/backup.rs b/native/native_rust_library/src/backup.rs --- a/native/native_rust_library/src/backup.rs +++ b/native/native_rust_library/src/backup.rs @@ -138,50 +138,6 @@ }); } - pub fn restore_backup( - backup_secret: String, - backup_id: String, - max_version: String, - promise_id: u32, - ) { - RUNTIME.spawn(async move { - let result = download_backup(backup_secret, backup_id) - .await - .map_err(|err| err.to_string()); - - let result = match result { - Ok(result) => result, - Err(error) => { - void_callback(error, promise_id); - return; - } - }; - - let (future_id, future) = future_manager::new_future::<()>().await; - restore_from_main_compaction( - &result.backup_restoration_path.to_string_lossy(), - &result.backup_data_key, - &max_version, - future_id, - ); - - if let Err(error) = future.await { - void_callback(error, promise_id); - return; - } - - if let Err(error) = - download_and_apply_logs(&result.backup_id, result.backup_log_data_key) - .await - { - void_callback(error.to_string(), promise_id); - return; - } - - void_callback(String::new(), promise_id); - }); - } - pub fn retrieve_backup_keys( backup_secret: String, backup_id: String, @@ -213,12 +169,7 @@ promise_id: u32, ) { RUNTIME.spawn(async move { - let backup_keys = BackupKeysResult { - backup_id, - backup_data_key, - backup_log_data_key, - }; - let result = download_backup_data(backup_keys) + let result = download_backup_data(backup_id.clone()) .await .map_err(|err| err.to_string()); @@ -233,7 +184,7 @@ let (future_id, future) = future_manager::new_future::<()>().await; restore_from_main_compaction( &result.backup_restoration_path.to_string_lossy(), - &result.backup_data_key, + &backup_data_key, &max_version, future_id, ); @@ -244,8 +195,7 @@ } if let Err(error) = - download_and_apply_logs(&result.backup_id, result.backup_log_data_key) - .await + download_and_apply_logs(&backup_id, backup_log_data_key).await { void_callback(error.to_string(), promise_id); return; @@ -367,14 +317,6 @@ Ok(()) } -async fn download_backup( - backup_secret: String, - backup_id: String, -) -> Result> { - let backup_keys = download_backup_keys(backup_id, backup_secret).await?; - download_backup_data(backup_keys).await -} - async fn download_latest_backup_info( user_identifier: String, ) -> Result> { @@ -402,7 +344,7 @@ async fn download_backup_keys( backup_id: String, backup_secret: String, -) -> Result> { +) -> Result> { let backup_client = BackupClient::new(BACKUP_SOCKET_ADDR)?; let user_identity = get_user_identity_from_secure_store()?; @@ -415,28 +357,15 @@ .download_backup_data(&backup_descriptor, RequestedData::UserKeys) .await?; let mut backup_key = compute_backup_key_str(&backup_secret, &backup_id)?; - let user_keys = - UserKeys::from_encrypted(&mut encrypted_user_keys, &mut backup_key)?; - - Ok(BackupKeysResult { - backup_id, - backup_data_key: user_keys.backup_data_key, - backup_log_data_key: user_keys.backup_log_data_key, - }) + UserKeys::from_encrypted(&mut encrypted_user_keys, &mut backup_key) } async fn download_backup_data( - backup_keys: BackupKeysResult, + backup_id: String, ) -> Result> { let backup_client = BackupClient::new(BACKUP_SOCKET_ADDR)?; let user_identity = get_user_identity_from_secure_store()?; - let BackupKeysResult { - backup_id, - backup_data_key, - backup_log_data_key, - } = backup_keys; - let backup_data_descriptor = BackupDescriptor::BackupID { backup_id: backup_id.clone(), user_identity: user_identity.clone(), @@ -453,9 +382,6 @@ Ok(CompactionDownloadResult { backup_restoration_path, - backup_id, - backup_data_key, - backup_log_data_key, }) } @@ -494,15 +420,6 @@ }) } -#[derive(Debug, Serialize)] -#[serde(rename_all = "camelCase")] -struct BackupKeysResult { - #[serde(rename = "backupID")] - backup_id: String, - backup_data_key: String, - backup_log_data_key: String, -} - // This struct should match `SIWEBackupData` in `lib/types/backup-types.js` #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -524,10 +441,7 @@ } struct CompactionDownloadResult { - backup_id: String, backup_restoration_path: PathBuf, - backup_data_key: String, - backup_log_data_key: String, } /// Stores the Olm account in `pickled_account`. However, Olm account 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 @@ -446,14 +446,6 @@ promise_id: u32, ); - #[cxx_name = "restoreBackup"] - fn restore_backup( - backup_secret: String, - backup_id: String, - max_version: String, - promise_id: u32, - ); - #[cxx_name = "restoreBackupData"] fn restore_backup_data( backup_id: String, diff --git a/native/profile/backup-menu.react.js b/native/profile/backup-menu.react.js --- a/native/profile/backup-menu.react.js +++ b/native/profile/backup-menu.react.js @@ -69,14 +69,17 @@ const testRestoreForPasswordUser = React.useCallback(async () => { let message = 'success'; try { + // eslint-disable-next-line no-unused-vars const [latestBackupInfo, backupSecret] = await Promise.all([ retrieveLatestBackupInfo(), getBackupSecret(), ]); - await commCoreModule.restoreBackup( - backupSecret, - persistConfig.version.toString(), + //TODO add backup keys + await commCoreModule.restoreBackupData( latestBackupInfo.backupID, + '', + '', + persistConfig.version.toString(), ); console.info('Backup restored.'); } catch (e) { diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -159,11 +159,6 @@ +stopBackupHandler: () => void; +createUserKeysBackup: (backupSecret: string) => Promise; +createFullBackup: (backupSecret: string) => Promise; - +restoreBackup: ( - backupSecret: string, - maxVersion: string, - backupID: string, - ) => Promise; +restoreBackupData: ( backupID: string, backupDataKey: string,