Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3294942
D11037.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D11037.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
@@ -104,6 +104,8 @@
encrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) override;
virtual jsi::Value
decrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) override;
+ virtual jsi::Value
+ signMessage(jsi::Runtime &rt, jsi::String message) override;
virtual void terminate(jsi::Runtime &rt) override;
virtual double getCodeVersion(jsi::Runtime &rt) override;
virtual jsi::Value
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
@@ -1015,6 +1015,33 @@
});
}
+jsi::Value CommCoreModule::signMessage(jsi::Runtime &rt, jsi::String message) {
+ std::string messageStr = message.utf8(rt);
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [=, &innerRt]() {
+ std::string error;
+ std::string signature;
+ try {
+ signature = this->cryptoModule->signMessage(messageStr);
+ } catch (const std::exception &e) {
+ error = "signing message failed with: " + std::string(e.what());
+ }
+
+ this->jsInvoker_->invokeAsync([=, &innerRt]() {
+ if (error.size()) {
+ promise->reject(error);
+ return;
+ }
+
+ auto jsiSignature{jsi::String::createFromUtf8(innerRt, signature)};
+ promise->resolve(std::move(jsiSignature));
+ });
+ };
+ this->cryptoThread->scheduleTask(job);
+ });
+}
+
CommCoreModule::CommCoreModule(
std::shared_ptr<facebook::react::CallInvoker> jsInvoker)
: facebook::react::CommCoreModuleSchemaCxxSpecJSI(jsInvoker),
@@ -1459,5 +1486,4 @@
::restoreBackup(rust::string(backupSecretStr), currentID);
});
}
-
} // 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
@@ -96,6 +96,9 @@
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_decrypt(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->decrypt(rt, args[0].asString(rt), args[1].asString(rt));
}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_signMessage(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->signMessage(rt, args[0].asString(rt));
+}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCodeVersion(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getCodeVersion(rt);
}
@@ -187,6 +190,7 @@
methodMap_["initializeContentInboundSession"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeContentInboundSession};
methodMap_["encrypt"] = MethodMetadata {2, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_encrypt};
methodMap_["decrypt"] = MethodMetadata {2, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_decrypt};
+ methodMap_["signMessage"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_signMessage};
methodMap_["getCodeVersion"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCodeVersion};
methodMap_["terminate"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_terminate};
methodMap_["setNotifyToken"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setNotifyToken};
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
@@ -47,6 +47,7 @@
virtual jsi::Value initializeContentInboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String encryptedMessage, jsi::String deviceID) = 0;
virtual jsi::Value encrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) = 0;
virtual jsi::Value decrypt(jsi::Runtime &rt, jsi::String message, jsi::String deviceID) = 0;
+ virtual jsi::Value signMessage(jsi::Runtime &rt, jsi::String message) = 0;
virtual double getCodeVersion(jsi::Runtime &rt) = 0;
virtual void terminate(jsi::Runtime &rt) = 0;
virtual jsi::Value setNotifyToken(jsi::Runtime &rt, jsi::String token) = 0;
@@ -303,6 +304,14 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::decrypt, jsInvoker_, instance_, std::move(message), std::move(deviceID));
}
+ jsi::Value signMessage(jsi::Runtime &rt, jsi::String message) override {
+ static_assert(
+ bridging::getParameterCount(&T::signMessage) == 2,
+ "Expected signMessage(...) to have 2 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::signMessage, jsInvoker_, instance_, std::move(message));
+ }
double getCodeVersion(jsi::Runtime &rt) override {
static_assert(
bridging::getParameterCount(&T::getCodeVersion) == 1,
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -113,6 +113,7 @@
) => Promise<string>;
+encrypt: (message: string, deviceID: string) => Promise<string>;
+decrypt: (message: string, deviceID: string) => Promise<string>;
+ +signMessage: (message: string) => Promise<string>;
+getCodeVersion: () => number;
+terminate: () => void;
+setNotifyToken: (token: string) => Promise<void>;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 8:39 PM (22 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2531723
Default Alt Text
D11037.diff (5 KB)
Attached To
Mode
D11037: [native] Add Olm account sign function to commCoreModule
Attached
Detach File
Event Timeline
Log In to Comment