Page MenuHomePhabricator

D11735.id39542.diff
No OneTemporary

D11735.id39542.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
@@ -205,6 +205,7 @@
virtual jsi::Value setSIWEBackupSecrets(
jsi::Runtime &rt,
jsi::Object siweBackupSecrets) override;
+ virtual jsi::Value retrieveLatestSIWEBackupData(jsi::Runtime &rt) override;
virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) override;
public:
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
@@ -1886,6 +1886,15 @@
});
}
+jsi::Value CommCoreModule::retrieveLatestSIWEBackupData(jsi::Runtime &rt) {
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ auto currentID = RustPromiseManager::instance.addPromise(
+ {promise, this->jsInvoker_, innerRt});
+ ::retrieveLatestSIWEBackupData(currentID);
+ });
+}
+
jsi::Value CommCoreModule::setSIWEBackupSecrets(
jsi::Runtime &rt,
jsi::Object siweBackupSecrets) {
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
@@ -196,6 +196,9 @@
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));
}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveLatestSIWEBackupData(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->retrieveLatestSIWEBackupData(rt);
+}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setSIWEBackupSecrets(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->setSIWEBackupSecrets(rt, args[0].asObject(rt));
}
@@ -264,6 +267,7 @@
methodMap_["restoreBackup"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackup};
methodMap_["restoreBackupData"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackupData};
methodMap_["retrieveBackupKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys};
+ methodMap_["retrieveLatestSIWEBackupData"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveLatestSIWEBackupData};
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
@@ -79,6 +79,7 @@
virtual jsi::Value restoreBackup(jsi::Runtime &rt, jsi::String backupSecret) = 0;
virtual jsi::Value restoreBackupData(jsi::Runtime &rt, jsi::String backupID, jsi::String backupDataKey, jsi::String backupLogDataKey) = 0;
virtual jsi::Value retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret) = 0;
+ virtual jsi::Value retrieveLatestSIWEBackupData(jsi::Runtime &rt) = 0;
virtual jsi::Value setSIWEBackupSecrets(jsi::Runtime &rt, jsi::Object siweBackupSecrets) = 0;
virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) = 0;
@@ -574,6 +575,14 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::retrieveBackupKeys, jsInvoker_, instance_, std::move(backupSecret));
}
+ jsi::Value retrieveLatestSIWEBackupData(jsi::Runtime &rt) override {
+ static_assert(
+ bridging::getParameterCount(&T::retrieveLatestSIWEBackupData) == 1,
+ "Expected retrieveLatestSIWEBackupData(...) to have 1 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::retrieveLatestSIWEBackupData, jsInvoker_, instance_);
+ }
jsi::Value setSIWEBackupSecrets(jsi::Runtime &rt, jsi::Object siweBackupSecrets) override {
static_assert(
bridging::getParameterCount(&T::setSIWEBackupSecrets) == 2,
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
@@ -179,6 +179,45 @@
void_callback(String::new(), promise_id);
});
}
+
+ pub fn retrieve_latest_siwe_backup_data(promise_id: u32) {
+ RUNTIME.spawn(async move {
+ let result = download_latest_backup_id()
+ .await
+ .map_err(|err| err.to_string());
+
+ let result = match result {
+ Ok(result) => result,
+ Err(error) => {
+ string_callback(error, promise_id, "".to_string());
+ return;
+ }
+ };
+
+ let LatestBackupIDResponse {
+ backup_id,
+ siwe_backup_msg,
+ } = result;
+
+ let siwe_backup_data = match siwe_backup_msg {
+ Some(siwe_backup_msg_value) => SIWEBackupData {
+ backup_id,
+ siwe_backup_msg: siwe_backup_msg_value,
+ },
+ None => {
+ string_callback(
+ "Backup message unavailable".to_string(),
+ promise_id,
+ "".to_string(),
+ );
+ return;
+ }
+ };
+
+ let serialize_result = serde_json::to_string(&siwe_backup_data);
+ handle_string_result_as_callback(serialize_result, promise_id);
+ });
+ }
}
pub async fn create_userkeys_compaction(
@@ -227,6 +266,30 @@
download_backup_data(backup_keys).await
}
+async fn download_latest_backup_id(
+) -> Result<LatestBackupIDResponse, 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 {
+ username: user_identity.user_id.clone(),
+ };
+
+ let backup_id_response = backup_client
+ .download_backup_data(&latest_backup_descriptor, RequestedData::BackupID)
+ .await?;
+
+ let LatestBackupIDResponse {
+ backup_id,
+ siwe_backup_msg,
+ } = serde_json::from_slice(&backup_id_response)?;
+
+ Ok(LatestBackupIDResponse {
+ backup_id,
+ siwe_backup_msg,
+ })
+}
+
async fn download_backup_keys(
backup_secret: String,
) -> Result<BackupKeysResult, Box<dyn Error>> {
@@ -336,6 +399,12 @@
backup_log_data_key: String,
}
+#[derive(Debug, Serialize)]
+struct SIWEBackupData {
+ backup_id: String,
+ siwe_backup_msg: String,
+}
+
struct CompactionDownloadResult {
backup_id: String,
backup_restoration_path: PathBuf,
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
@@ -363,6 +363,9 @@
#[cxx_name = "retrieveBackupKeys"]
fn retrieve_backup_keys(backup_secret: String, promise_id: u32);
+
+ #[cxx_name = "retrieveLatestSIWEBackupData"]
+ fn retrieve_latest_siwe_backup_data(promise_id: u32);
}
// Secure store
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -161,6 +161,7 @@
backupLogDataKey: string,
) => Promise<void>;
+retrieveBackupKeys: (backupSecret: string) => Promise<string>;
+ +retrieveLatestSIWEBackupData: () => Promise<string>;
+setSIWEBackupSecrets: (siweBackupSecrets: Object) => Promise<void>;
+getSIWEBackupSecrets: () => Promise<?Object>;
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 10:34 PM (14 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577499
Default Alt Text
D11735.id39542.diff (7 KB)

Event Timeline