Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3389562
D7395.id25030.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D7395.id25030.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
@@ -48,7 +48,12 @@
jsi::Array operations) override;
virtual jsi::Value initializeCryptoAccount(jsi::Runtime &rt) override;
virtual jsi::Value getUserPublicKey(jsi::Runtime &rt) override;
- virtual jsi::Value getUserOneTimeKeys(jsi::Runtime &rt) override;
+ virtual jsi::Value
+ getUserOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) override;
+ virtual jsi::Value getNotificationsOneTimeKeys(
+ jsi::Runtime &rt,
+ double oneTimeKeysAmount) override;
+ virtual jsi::Value getNotificationsPrekey(jsi::Runtime &rt) 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
@@ -953,7 +953,26 @@
});
}
-jsi::Value CommCoreModule::getUserOneTimeKeys(jsi::Runtime &rt) {
+jsi::Object parseOLMOneTimeKeys(jsi::Runtime &rt, std::string oneTimeKeysBlob) {
+ folly::dynamic parsedOneTimeKeys = folly::parseJson(oneTimeKeysBlob);
+
+ auto jsiOneTimeKeys = jsi::Object(rt);
+ auto jsiOneTimeKeysInner = jsi::Object(rt);
+
+ for (auto &kvPair : parsedOneTimeKeys["curve25519"].items()) {
+ jsiOneTimeKeysInner.setProperty(
+ rt,
+ kvPair.first.asString().c_str(),
+ jsi::String::createFromUtf8(rt, kvPair.second.asString()));
+ }
+
+ jsiOneTimeKeys.setProperty(rt, "curve25519", jsiOneTimeKeysInner);
+
+ return jsiOneTimeKeys;
+}
+
+jsi::Value
+CommCoreModule::getUserOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) {
return createPromiseAsJSIValue(
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
taskType job = [=, &innerRt]() {
@@ -962,14 +981,88 @@
if (this->cryptoModule == nullptr) {
error = "user has not been initialized";
} else {
- result = this->cryptoModule->getOneTimeKeys();
+ result = this->cryptoModule->getOneTimeKeys(oneTimeKeysAmount);
+ }
+ this->jsInvoker_->invokeAsync([=, &innerRt]() {
+ if (error.size()) {
+ promise->reject(error);
+ return;
+ }
+ promise->resolve(parseOLMOneTimeKeys(innerRt, result));
+ });
+ };
+ this->cryptoThread->scheduleTask(job);
+ });
+}
+
+jsi::Value CommCoreModule::getNotificationsOneTimeKeys(
+ jsi::Runtime &rt,
+ double oneTimeKeysAmount) {
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [=, &innerRt]() {
+ std::string result;
+ std::string error;
+
+ try {
+ result = NotificationsCryptoModule::getNotificationsOneTimeKeys(
+ oneTimeKeysAmount, "Comm");
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+
+ this->jsInvoker_->invokeAsync([=, &innerRt]() {
+ if (error.size()) {
+ promise->reject(error);
+ return;
+ }
+ promise->resolve(parseOLMOneTimeKeys(innerRt, result));
+ });
+ };
+ this->cryptoThread->scheduleTask(job);
+ });
+}
+
+jsi::Object parseOLMPrekey(jsi::Runtime &rt, std::string prekeyBlob) {
+ folly::dynamic parsedPrekey = folly::parseJson(prekeyBlob);
+
+ std::string prekeyId =
+ parsedPrekey["curve25519"].items().begin()->first.asString();
+ std::string prekeyValue =
+ parsedPrekey["curve25519"].items().begin()->second.asString();
+
+ auto jsiPrekey = jsi::Object(rt);
+ auto jsiPrekeyInner = jsi::Object(rt);
+
+ jsiPrekeyInner.setProperty(
+ rt, "id", jsi::String::createFromUtf8(rt, prekeyId));
+ jsiPrekeyInner.setProperty(
+ rt, "key", jsi::String::createFromUtf8(rt, prekeyValue));
+ jsiPrekey.setProperty(rt, "curve25519", jsiPrekeyInner);
+
+ return jsiPrekey;
+}
+
+jsi::Value CommCoreModule::getNotificationsPrekey(jsi::Runtime &rt) {
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [=, &innerRt]() {
+ std::string result;
+ std::string error;
+
+ try {
+ result =
+ NotificationsCryptoModule::generateNotificationsPreKey("Comm");
+ } catch (const std::exception &e) {
+ error = e.what();
}
+
this->jsInvoker_->invokeAsync([=, &innerRt]() {
if (error.size()) {
promise->reject(error);
return;
}
- promise->resolve(jsi::String::createFromUtf8(innerRt, result));
+ promise->resolve(parseOLMPrekey(innerRt, result));
});
};
this->cryptoThread->scheduleTask(job);
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
@@ -57,7 +57,13 @@
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getUserPublicKey(rt);
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUserOneTimeKeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
- return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getUserOneTimeKeys(rt);
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getUserOneTimeKeys(rt, args[0].asNumber());
+}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getNotificationsOneTimeKeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getNotificationsOneTimeKeys(rt, args[0].asNumber());
+}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getNotificationsPrekey(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getNotificationsPrekey(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);
@@ -114,7 +120,9 @@
methodMap_["processThreadStoreOperationsSync"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_processThreadStoreOperationsSync};
methodMap_["initializeCryptoAccount"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeCryptoAccount};
methodMap_["getUserPublicKey"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUserPublicKey};
- methodMap_["getUserOneTimeKeys"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUserOneTimeKeys};
+ methodMap_["getUserOneTimeKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUserOneTimeKeys};
+ methodMap_["getNotificationsOneTimeKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getNotificationsOneTimeKeys};
+ methodMap_["getNotificationsPrekey"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getNotificationsPrekey};
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
@@ -34,7 +34,9 @@
virtual void processThreadStoreOperationsSync(jsi::Runtime &rt, jsi::Array operations) = 0;
virtual jsi::Value initializeCryptoAccount(jsi::Runtime &rt) = 0;
virtual jsi::Value getUserPublicKey(jsi::Runtime &rt) = 0;
- virtual jsi::Value getUserOneTimeKeys(jsi::Runtime &rt) = 0;
+ virtual jsi::Value getUserOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) = 0;
+ virtual jsi::Value getNotificationsOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) = 0;
+ virtual jsi::Value getNotificationsPrekey(jsi::Runtime &rt) = 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;
@@ -180,13 +182,29 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::getUserPublicKey, jsInvoker_, instance_);
}
- jsi::Value getUserOneTimeKeys(jsi::Runtime &rt) override {
+ jsi::Value getUserOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) override {
static_assert(
- bridging::getParameterCount(&T::getUserOneTimeKeys) == 1,
- "Expected getUserOneTimeKeys(...) to have 1 parameters");
+ bridging::getParameterCount(&T::getUserOneTimeKeys) == 2,
+ "Expected getUserOneTimeKeys(...) to have 2 parameters");
return bridging::callFromJs<jsi::Value>(
- rt, &T::getUserOneTimeKeys, jsInvoker_, instance_);
+ rt, &T::getUserOneTimeKeys, jsInvoker_, instance_, std::move(oneTimeKeysAmount));
+ }
+ jsi::Value getNotificationsOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) override {
+ static_assert(
+ bridging::getParameterCount(&T::getNotificationsOneTimeKeys) == 2,
+ "Expected getNotificationsOneTimeKeys(...) to have 2 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::getNotificationsOneTimeKeys, jsInvoker_, instance_, std::move(oneTimeKeysAmount));
+ }
+ jsi::Value getNotificationsPrekey(jsi::Runtime &rt) override {
+ static_assert(
+ bridging::getParameterCount(&T::getNotificationsPrekey) == 1,
+ "Expected getNotificationsPrekey(...) to have 1 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::getNotificationsPrekey, jsInvoker_, instance_);
}
double getCodeVersion(jsi::Runtime &rt) override {
static_assert(
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -5,6 +5,7 @@
import { TurboModuleRegistry } from 'react-native';
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport.js';
+import type { OLMOneTimeKeys, OLMPrekey } from 'lib/types/crypto-types';
import type { ClientDBDraftStoreOperation } from 'lib/types/draft-types.js';
import type {
ClientDBMessageInfo,
@@ -54,7 +55,11 @@
) => void;
+initializeCryptoAccount: () => Promise<string>;
+getUserPublicKey: () => Promise<ClientPublicKeys>;
- +getUserOneTimeKeys: () => Promise<string>;
+ +getUserOneTimeKeys: (oneTimeKeysAmount: number) => Promise<OLMOneTimeKeys>;
+ +getNotificationsOneTimeKeys: (
+ oneTimeKeysAmount: number,
+ ) => Promise<OLMOneTimeKeys>;
+ +getNotificationsPrekey: () => Promise<OLMPrekey>;
+getCodeVersion: () => number;
+terminate: () => void;
+setNotifyToken: (token: string) => Promise<void>;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 7:38 PM (22 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2602151
Default Alt Text
D7395.id25030.diff (11 KB)
Attached To
Mode
D7395: Introduce methods in CommCoreModule to initialize olm session for notifications. Refactor method to get one time keys for primary olm account
Attached
Detach File
Event Timeline
Log In to Comment