Page MenuHomePhabricator

D13849.diff
No OneTemporary

D13849.diff

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
@@ -231,8 +231,10 @@
jsi::String backupDataKey,
jsi::String backupLogDataKey,
jsi::String maxVersion) override;
- virtual jsi::Value
- retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret) override;
+ virtual jsi::Value retrieveBackupKeys(
+ jsi::Runtime &rt,
+ jsi::String backupSecret,
+ jsi::String backupID) override;
virtual jsi::Value retrieveLatestBackupInfo(
jsi::Runtime &rt,
jsi::String userIdentifier) override;
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
@@ -2598,14 +2598,20 @@
});
}
-jsi::Value
-CommCoreModule::retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret) {
+jsi::Value CommCoreModule::retrieveBackupKeys(
+ jsi::Runtime &rt,
+ jsi::String backupSecret,
+ jsi::String backupID) {
std::string backupSecretStr = backupSecret.utf8(rt);
+ std::string backupIDStr = backupID.utf8(rt);
return createPromiseAsJSIValue(
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
auto currentID = RustPromiseManager::instance.addPromise(
{promise, this->jsInvoker_, innerRt});
- ::retrieveBackupKeys(rust::string(backupSecretStr), currentID);
+ ::retrieveBackupKeys(
+ rust::string(backupSecretStr),
+ rust::string(backupIDStr),
+ currentID);
});
}
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
@@ -194,7 +194,7 @@
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->restoreBackupData(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt));
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
- return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->retrieveBackupKeys(rt, args[0].asString(rt));
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->retrieveBackupKeys(rt, args[0].asString(rt), args[1].asString(rt));
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveLatestBackupInfo(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->retrieveLatestBackupInfo(rt, args[0].asString(rt));
@@ -302,7 +302,7 @@
methodMap_["createNewSIWEBackup"] = MethodMetadata {2, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_createNewSIWEBackup};
methodMap_["restoreBackup"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackup};
methodMap_["restoreBackupData"] = MethodMetadata {4, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackupData};
- methodMap_["retrieveBackupKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys};
+ methodMap_["retrieveBackupKeys"] = MethodMetadata {2, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys};
methodMap_["retrieveLatestBackupInfo"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveLatestBackupInfo};
methodMap_["setSIWEBackupSecrets"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setSIWEBackupSecrets};
methodMap_["getSIWEBackupSecrets"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets};
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
@@ -78,7 +78,7 @@
virtual jsi::Value createNewSIWEBackup(jsi::Runtime &rt, jsi::String backupSecret, jsi::String siweBackupMsg) = 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 retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret) = 0;
+ virtual jsi::Value retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret, jsi::String backupID) = 0;
virtual jsi::Value retrieveLatestBackupInfo(jsi::Runtime &rt, jsi::String userIdentifier) = 0;
virtual jsi::Value setSIWEBackupSecrets(jsi::Runtime &rt, jsi::Object siweBackupSecrets) = 0;
virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) = 0;
@@ -579,13 +579,13 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::restoreBackupData, jsInvoker_, instance_, std::move(backupID), std::move(backupDataKey), std::move(backupLogDataKey), std::move(maxVersion));
}
- jsi::Value retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret) override {
+ jsi::Value retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret, jsi::String backupID) override {
static_assert(
- bridging::getParameterCount(&T::retrieveBackupKeys) == 2,
- "Expected retrieveBackupKeys(...) to have 2 parameters");
+ bridging::getParameterCount(&T::retrieveBackupKeys) == 3,
+ "Expected retrieveBackupKeys(...) to have 3 parameters");
return bridging::callFromJs<jsi::Value>(
- rt, &T::retrieveBackupKeys, jsInvoker_, instance_, std::move(backupSecret));
+ rt, &T::retrieveBackupKeys, jsInvoker_, instance_, std::move(backupSecret), std::move(backupID));
}
jsi::Value retrieveLatestBackupInfo(jsi::Runtime &rt, jsi::String userIdentifier) override {
static_assert(
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
@@ -120,20 +120,12 @@
});
}
- pub fn retrieve_backup_keys(backup_secret: String, promise_id: u32) {
+ pub fn retrieve_backup_keys(
+ backup_secret: String,
+ backup_id: String,
+ promise_id: u32,
+ ) {
RUNTIME.spawn(async move {
- let latest_backup_id_response = download_latest_backup_id()
- .await
- .map_err(|err| err.to_string());
-
- let backup_id = match latest_backup_id_response {
- Ok(result) => result.backup_id,
- Err(error) => {
- string_callback(error, promise_id, "".to_string());
- return;
- }
- };
-
let result = download_backup_keys(backup_id, backup_secret)
.await
.map_err(|err| err.to_string());
@@ -326,32 +318,6 @@
download_backup_data(backup_keys).await
}
-async fn download_latest_backup_id(
-) -> Result<LatestBackupInfoResponse, Box<dyn Error>> {
- let backup_client = BackupClient::new(BACKUP_SOCKET_ADDR)?;
- let user_identity = get_user_identity_from_secure_store()?;
-
- let latest_backup_descriptor = BackupDescriptor::Latest {
- user_identifier: user_identity.user_id.clone(),
- };
-
- let backup_info_response = backup_client
- .download_backup_data(&latest_backup_descriptor, RequestedData::BackupInfo)
- .await?;
-
- let LatestBackupInfoResponse {
- backup_id,
- user_id,
- siwe_backup_msg,
- } = serde_json::from_slice(&backup_info_response)?;
-
- Ok(LatestBackupInfoResponse {
- backup_id,
- user_id,
- siwe_backup_msg,
- })
-}
-
async fn download_latest_backup_info(
user_identifier: String,
) -> Result<LatestBackupInfoResponse, Box<dyn Error>> {
@@ -383,12 +349,13 @@
let backup_client = BackupClient::new(BACKUP_SOCKET_ADDR)?;
let user_identity = get_user_identity_from_secure_store()?;
- let latest_backup_descriptor = BackupDescriptor::Latest {
- user_identifier: user_identity.user_id.clone(),
+ let backup_descriptor = BackupDescriptor::BackupID {
+ backup_id: backup_id.clone(),
+ user_identity: user_identity.clone(),
};
let mut encrypted_user_keys = backup_client
- .download_backup_data(&latest_backup_descriptor, RequestedData::UserKeys)
+ .download_backup_data(&backup_descriptor, RequestedData::UserKeys)
.await?;
let mut backup_key = compute_backup_key_str(&backup_secret, &backup_id)?;
let user_keys =
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
@@ -454,7 +454,11 @@
);
#[cxx_name = "retrieveBackupKeys"]
- fn retrieve_backup_keys(backup_secret: String, promise_id: u32);
+ fn retrieve_backup_keys(
+ backup_secret: String,
+ backup_id: String,
+ promise_id: u32,
+ );
#[cxx_name = "retrieveLatestBackupInfo"]
fn retrieve_latest_backup_info(user_identifier: String, promise_id: u32);
diff --git a/native/profile/secondary-device-qr-code-scanner.react.js b/native/profile/secondary-device-qr-code-scanner.react.js
--- a/native/profile/secondary-device-qr-code-scanner.react.js
+++ b/native/profile/secondary-device-qr-code-scanner.react.js
@@ -44,6 +44,7 @@
import { assertWithValidator } from 'lib/utils/validation-utils.js';
import type { ProfileNavigationProp } from './profile.react.js';
+import { useClientBackup } from '../backup/use-client-backup.js';
import { useGetBackupSecretForLoggedInUser } from '../backup/use-get-backup-secret.js';
import TextInput from '../components/text-input.react.js';
import { commCoreModule } from '../native-modules.js';
@@ -89,6 +90,7 @@
const ownPeerDevices = useSelector(getOwnPeerDevices);
const keyserverDeviceID = getKeyserverDeviceID(ownPeerDevices);
const getBackupSecret = useGetBackupSecretForLoggedInUser();
+ const { retrieveLatestBackupInfo } = useClientBackup();
const { panelForegroundTertiaryLabel } = useColors();
@@ -159,9 +161,14 @@
return;
}
- const backupSecret = await getBackupSecret();
- const backupKeysResponse =
- await commCoreModule.retrieveBackupKeys(backupSecret);
+ const [backupSecret, latestBackupInfo] = await Promise.all([
+ getBackupSecret(),
+ retrieveLatestBackupInfo(),
+ ]);
+ const backupKeysResponse = await commCoreModule.retrieveBackupKeys(
+ backupSecret,
+ latestBackupInfo.backupID,
+ );
const backupKeys = assertWithValidator<BackupKeys>(
JSON.parse(backupKeysResponse),
backupKeysValidator,
@@ -191,6 +198,7 @@
getBackupSecret,
tunnelbrokerContext,
goBack,
+ retrieveLatestBackupInfo,
],
);
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -172,7 +172,10 @@
backupLogDataKey: string,
maxVersion: string,
) => Promise<void>;
- +retrieveBackupKeys: (backupSecret: string) => Promise<string>;
+ +retrieveBackupKeys: (
+ backupSecret: string,
+ backupID: string,
+ ) => Promise<string>;
+retrieveLatestBackupInfo: (userIdentifier: string) => Promise<string>;
+setSIWEBackupSecrets: (siweBackupSecrets: Object) => Promise<void>;
+getSIWEBackupSecrets: () => Promise<?Object>;

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 1, 8:28 PM (22 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2398749
Default Alt Text
D13849.diff (11 KB)

Event Timeline