Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3408361
D11637.id39410.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D11637.id39410.diff
View Options
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
@@ -194,6 +194,10 @@
jsi::String backupLogDataKey) override;
virtual jsi::Value
retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret) override;
+ virtual jsi::Value setSIWEBackupSecrets(
+ jsi::Runtime &rt,
+ jsi::Object siweBackupSecrets) override;
+ virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) override;
public:
CommCoreModule(std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
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
@@ -1868,4 +1868,81 @@
::retrieveBackupKeys(rust::string(backupSecretStr), currentID);
});
}
+
+jsi::Value CommCoreModule::setSIWEBackupSecrets(
+ jsi::Runtime &rt,
+ jsi::Object siweBackupSecrets) {
+ std::string message =
+ siweBackupSecrets.getProperty(rt, "message").asString(rt).utf8(rt);
+ std::string signature =
+ siweBackupSecrets.getProperty(rt, "signature").asString(rt).utf8(rt);
+ folly::dynamic backupSecretsJSON =
+ folly::dynamic::object("message", message)("signature", signature);
+ std::string backupSecrets = folly::toJson(backupSecretsJSON);
+
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [this, promise, backupSecrets]() {
+ std::string error;
+ try {
+ DatabaseManager::getQueryExecutor().setMetadata(
+ "siweBackupSecrets", backupSecrets);
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+ this->jsInvoker_->invokeAsync([error, promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ } else {
+ promise->resolve(jsi::Value::undefined());
+ }
+ });
+ };
+ GlobalDBSingleton::instance.scheduleOrRunCancellable(
+ job, promise, this->jsInvoker_);
+ });
+}
+
+jsi::Value CommCoreModule::getSIWEBackupSecrets(jsi::Runtime &rt) {
+ return createPromiseAsJSIValue(
+ rt, [this](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [this, &innerRt, promise]() {
+ std::string error;
+ std::string backupSecrets;
+ try {
+ backupSecrets = DatabaseManager::getQueryExecutor().getMetadata(
+ "siweBackupSecrets");
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+ this->jsInvoker_->invokeAsync(
+ [&innerRt, error, backupSecrets, promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ } else if (!backupSecrets.size()) {
+ promise->resolve(jsi::Value::undefined());
+ } else {
+ folly::dynamic backupSecretsJSON =
+ folly::parseJson(backupSecrets);
+ std::string message = backupSecretsJSON["message"].asString();
+ std::string signature =
+ backupSecretsJSON["signature"].asString();
+
+ auto siweBackupSecrets = jsi::Object(innerRt);
+ siweBackupSecrets.setProperty(
+ innerRt,
+ "message",
+ jsi::String::createFromUtf8(innerRt, message));
+ siweBackupSecrets.setProperty(
+ innerRt,
+ "signature",
+ jsi::String::createFromUtf8(innerRt, signature));
+ promise->resolve(std::move(siweBackupSecrets));
+ }
+ });
+ };
+ GlobalDBSingleton::instance.scheduleOrRunCancellable(
+ job, promise, this->jsInvoker_);
+ });
+}
} // namespace comm
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,12 @@
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_setSIWEBackupSecrets(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->setSIWEBackupSecrets(rt, args[0].asObject(rt));
+}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getSIWEBackupSecrets(rt);
+}
CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
: TurboModule("CommTurboModule", jsInvoker) {
@@ -254,6 +260,8 @@
methodMap_["restoreBackup"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackup};
methodMap_["restoreBackupData"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackupData};
methodMap_["retrieveBackupKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys};
+ 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,8 @@
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 setSIWEBackupSecrets(jsi::Runtime &rt, jsi::Object siweBackupSecrets) = 0;
+ virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) = 0;
};
@@ -563,6 +565,22 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::retrieveBackupKeys, jsInvoker_, instance_, std::move(backupSecret));
}
+ jsi::Value setSIWEBackupSecrets(jsi::Runtime &rt, jsi::Object siweBackupSecrets) override {
+ static_assert(
+ bridging::getParameterCount(&T::setSIWEBackupSecrets) == 2,
+ "Expected setSIWEBackupSecrets(...) to have 2 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::setSIWEBackupSecrets, jsInvoker_, instance_, std::move(siweBackupSecrets));
+ }
+ jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) override {
+ static_assert(
+ bridging::getParameterCount(&T::getSIWEBackupSecrets) == 1,
+ "Expected getSIWEBackupSecrets(...) to have 1 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::getSIWEBackupSecrets, jsInvoker_, instance_);
+ }
private:
T *instance_;
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -24,6 +24,7 @@
} from 'lib/types/crypto-types.js';
import type { ClientDBDraftStoreOperation } from 'lib/types/draft-types.js';
import type { ClientDBMessageInfo } from 'lib/types/message-types.js';
+import type { SIWEBackupSecrets } from 'lib/types/siwe-types.js';
import type { ClientDBStore } from 'lib/types/store-ops-types';
import type { ClientDBThreadInfo } from 'lib/types/thread-types.js';
@@ -156,6 +157,8 @@
backupLogDataKey: string,
) => Promise<void>;
+retrieveBackupKeys: (backupSecret: string) => Promise<string>;
+ +setSIWEBackupSecrets: (siweBackupSecrets: Object) => Promise<void>;
+ +getSIWEBackupSecrets: () => Promise<?Object>;
}
export interface CoreModuleSpec extends Spec {
@@ -171,6 +174,10 @@
sessionVersion: number,
overwrite: boolean,
) => Promise<string>;
+ +setSIWEBackupSecrets: (
+ siweBackupSecrets: SIWEBackupSecrets,
+ ) => Promise<void>;
+ +getSIWEBackupSecrets: () => Promise<?SIWEBackupSecrets>;
}
export default (TurboModuleRegistry.getEnforcing<Spec>(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 5, 10:59 AM (16 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2615266
Default Alt Text
D11637.id39410.diff (8 KB)
Attached To
Mode
D11637: Implement JSI getter and setter for siwe backup secrets
Attached
Detach File
Event Timeline
Log In to Comment