Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3296121
D11905.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D11905.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
@@ -136,6 +136,11 @@
jsi::String messageID) override;
virtual jsi::Value
signMessage(jsi::Runtime &rt, jsi::String message) override;
+ virtual jsi::Value verifySignature(
+ jsi::Runtime &rt,
+ jsi::String publicKey,
+ jsi::String message,
+ jsi::String signature) 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
@@ -1525,6 +1525,37 @@
});
}
+jsi::Value CommCoreModule::verifySignature(
+ jsi::Runtime &rt,
+ jsi::String publicKey,
+ jsi::String message,
+ jsi::String signature) {
+ std::string keyStr = publicKey.utf8(rt);
+ std::string messageStr = message.utf8(rt);
+ std::string signatureStr = signature.utf8(rt);
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [=, &innerRt]() {
+ std::string error;
+ try {
+ crypto::CryptoModule::verifySignature(
+ keyStr, messageStr, signatureStr);
+ } catch (const std::exception &e) {
+ error = "verifying signature failed with: " + std::string(e.what());
+ }
+
+ this->jsInvoker_->invokeAsync([=, &innerRt]() {
+ if (error.size()) {
+ promise->reject(error);
+ return;
+ }
+ promise->resolve(jsi::Value::undefined());
+ });
+ };
+ this->cryptoThread->scheduleTask(job);
+ });
+}
+
CommCoreModule::CommCoreModule(
std::shared_ptr<facebook::react::CallInvoker> jsInvoker)
: facebook::react::CommCoreModuleSchemaCxxSpecJSI(jsInvoker),
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_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_verifySignature(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->verifySignature(rt, args[0].asString(rt), args[1].asString(rt), args[2].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);
}
@@ -214,6 +217,7 @@
methodMap_["decrypt"] = MethodMetadata {2, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_decrypt};
methodMap_["decryptSequentialAndPersist"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_decryptSequentialAndPersist};
methodMap_["signMessage"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_signMessage};
+ methodMap_["verifySignature"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_verifySignature};
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 decrypt(jsi::Runtime &rt, jsi::Object encryptedData, jsi::String deviceID) = 0;
virtual jsi::Value decryptSequentialAndPersist(jsi::Runtime &rt, jsi::Object encryptedData, jsi::String deviceID, jsi::String messageID) = 0;
virtual jsi::Value signMessage(jsi::Runtime &rt, jsi::String message) = 0;
+ virtual jsi::Value verifySignature(jsi::Runtime &rt, jsi::String publicKey, jsi::String message, jsi::String signature) = 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;
@@ -312,6 +313,14 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::signMessage, jsInvoker_, instance_, std::move(message));
}
+ jsi::Value verifySignature(jsi::Runtime &rt, jsi::String publicKey, jsi::String message, jsi::String signature) override {
+ static_assert(
+ bridging::getParameterCount(&T::verifySignature) == 4,
+ "Expected verifySignature(...) to have 4 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::verifySignature, jsInvoker_, instance_, std::move(publicKey), std::move(message), std::move(signature));
+ }
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
@@ -96,6 +96,11 @@
messageID: string,
) => Promise<string>;
+signMessage: (message: string) => Promise<string>;
+ +verifySignature: (
+ publicKey: string,
+ message: string,
+ signature: string,
+ ) => Promise<void>;
+getCodeVersion: () => number;
+terminate: () => void;
+setNotifyToken: (token: string) => Promise<void>;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 18, 12:48 AM (19 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2532517
Default Alt Text
D11905.diff (6 KB)
Attached To
Mode
D11905: [native] Expose verifySignature function via JSI
Attached
Detach File
Event Timeline
Log In to Comment