Page MenuHomePhabricator

D11735.id39392.diff
No OneTemporary

D11735.id39392.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
@@ -199,6 +199,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
@@ -1873,6 +1873,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
@@ -193,6 +193,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));
}
@@ -260,6 +263,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
@@ -78,6 +78,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;
@@ -565,6 +566,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
@@ -183,6 +183,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,
+ msg_backup,
+ } = result;
+
+ let siwe_backup_data = match msg_backup {
+ Some(msg_backup_value) => SIWEBackupData {
+ backup_id,
+ msg_backup: msg_backup_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(
@@ -231,6 +270,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,
+ msg_backup,
+ } = serde_json::from_slice(&backup_id_response)?;
+
+ Ok(LatestBackupIDResponse {
+ backup_id,
+ msg_backup,
+ })
+}
+
async fn download_backup_keys(
backup_secret: String,
) -> Result<BackupKeysResult, Box<dyn Error>> {
@@ -340,6 +403,12 @@
backup_log_data_key: String,
}
+#[derive(Debug, Serialize)]
+struct SIWEBackupData {
+ backup_id: String,
+ msg_backup: 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
@@ -160,6 +160,7 @@
backupLogDataKey: string,
) => Promise<void>;
+retrieveBackupKeys: (backupSecret: string) => Promise<string>;
+ +retrieveLatestSIWEBackupData: () => Promise<void>;
+setSIWEBackupSecrets: (siweBackupSecrets: Object) => Promise<void>;
+getSIWEBackupSecrets: () => Promise<?Object>;
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 7:19 PM (17 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2564352
Default Alt Text
D11735.id39392.diff (7 KB)

Event Timeline