Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3389280
D7395.id26251.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
14 KB
Referenced Files
None
Subscribers
None
D7395.id26251.diff
View Options
diff --git a/lib/types/crypto-types.js b/lib/types/crypto-types.js
--- a/lib/types/crypto-types.js
+++ b/lib/types/crypto-types.js
@@ -5,6 +5,17 @@
+curve25519: string,
};
+export type OLMPrekey = {
+ +curve25519: {
+ +id: string,
+ +key: string,
+ },
+};
+
+export type OLMOneTimeKeys = {
+ +curve25519: { +[string]: string },
+};
+
export type PickledOLMAccount = {
+picklingKey: string,
+pickledAccount: string,
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
@@ -50,7 +50,18 @@
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
+ getPrimaryOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) override;
+ virtual jsi::Value initializeNotificationsSession(
+ jsi::Runtime &rt,
+ jsi::String identityKeys,
+ jsi::String prekey,
+ jsi::String prekeySignature,
+ jsi::String oneTimeKeys) override;
+ virtual jsi::Value
+ isNotificationsSessionInitialized(jsi::Runtime &rt) override;
+ virtual jsi::Value
+ generateInitialNotificationsEncryptedMessage(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
@@ -1002,7 +1002,27 @@
});
}
-jsi::Value CommCoreModule::getUserOneTimeKeys(jsi::Runtime &rt) {
+jsi::Object parseOLMOneTimeKeys(jsi::Runtime &rt, std::string oneTimeKeysBlob) {
+ folly::dynamic parsedOneTimeKeys = folly::parseJson(oneTimeKeysBlob);
+
+ 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()));
+ }
+
+ auto jsiOneTimeKeys = jsi::Object(rt);
+ jsiOneTimeKeys.setProperty(rt, "curve25519", jsiOneTimeKeysInner);
+
+ return jsiOneTimeKeys;
+}
+
+jsi::Value CommCoreModule::getPrimaryOneTimeKeys(
+ jsi::Runtime &rt,
+ double oneTimeKeysAmount) {
return createPromiseAsJSIValue(
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
taskType job = [=, &innerRt]() {
@@ -1011,14 +1031,102 @@
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::initializeNotificationsSession(
+ jsi::Runtime &rt,
+ jsi::String identityKeys,
+ jsi::String prekey,
+ jsi::String prekeySignature,
+ jsi::String oneTimeKeys) {
+ auto identityKeysCpp{identityKeys.utf8(rt)};
+ auto prekeyCpp{prekey.utf8(rt)};
+ auto prekeySignatureCpp{prekeySignature.utf8(rt)};
+ auto oneTimeKeysCpp{oneTimeKeys.utf8(rt)};
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [=, &innerRt]() {
+ std::string error;
+ try {
+ NotificationsCryptoModule::initializeNotificationsSession(
+ identityKeysCpp,
+ prekeyCpp,
+ prekeySignatureCpp,
+ oneTimeKeysCpp,
+ "Comm");
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+ this->jsInvoker_->invokeAsync([=, &innerRt]() {
+ if (error.size()) {
+ promise->reject(error);
+ return;
+ }
+ promise->resolve(jsi::Value::undefined());
+ });
+ };
+ this->cryptoThread->scheduleTask(job);
+ });
+}
+
+jsi::Value CommCoreModule::isNotificationsSessionInitialized(jsi::Runtime &rt) {
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [=, &innerRt]() {
+ std::string error;
+ bool result;
+ try {
+ result =
+ NotificationsCryptoModule::isNotificationsSessionInitialized(
+ "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(result);
+ });
+ };
+ this->cryptoThread->scheduleTask(job);
+ });
+}
+
+jsi::Value
+CommCoreModule::generateInitialNotificationsEncryptedMessage(jsi::Runtime &rt) {
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [=, &innerRt]() {
+ std::string error;
+ crypto::EncryptedData result;
+ try {
+ result = NotificationsCryptoModule::generateInitialEncryptedMessage(
+ "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,
+ std::string{result.message.begin(), result.message.end()}));
});
};
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
@@ -56,8 +56,17 @@
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUserPublicKey(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
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);
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getPrimaryOneTimeKeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getPrimaryOneTimeKeys(rt, args[0].asNumber());
+}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeNotificationsSession(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->initializeNotificationsSession(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt));
+}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_isNotificationsSessionInitialized(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->isNotificationsSessionInitialized(rt);
+}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_generateInitialNotificationsEncryptedMessage(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->generateInitialNotificationsEncryptedMessage(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);
@@ -120,7 +129,10 @@
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_["getPrimaryOneTimeKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getPrimaryOneTimeKeys};
+ methodMap_["initializeNotificationsSession"] = MethodMetadata {4, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeNotificationsSession};
+ methodMap_["isNotificationsSessionInitialized"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_isNotificationsSessionInitialized};
+ methodMap_["generateInitialNotificationsEncryptedMessage"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_generateInitialNotificationsEncryptedMessage};
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,10 @@
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 getPrimaryOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) = 0;
+ virtual jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys) = 0;
+ virtual jsi::Value isNotificationsSessionInitialized(jsi::Runtime &rt) = 0;
+ virtual jsi::Value generateInitialNotificationsEncryptedMessage(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;
@@ -182,13 +185,37 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::getUserPublicKey, jsInvoker_, instance_);
}
- jsi::Value getUserOneTimeKeys(jsi::Runtime &rt) override {
+ jsi::Value getPrimaryOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) override {
static_assert(
- bridging::getParameterCount(&T::getUserOneTimeKeys) == 1,
- "Expected getUserOneTimeKeys(...) to have 1 parameters");
+ bridging::getParameterCount(&T::getPrimaryOneTimeKeys) == 2,
+ "Expected getPrimaryOneTimeKeys(...) to have 2 parameters");
return bridging::callFromJs<jsi::Value>(
- rt, &T::getUserOneTimeKeys, jsInvoker_, instance_);
+ rt, &T::getPrimaryOneTimeKeys, jsInvoker_, instance_, std::move(oneTimeKeysAmount));
+ }
+ jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys) override {
+ static_assert(
+ bridging::getParameterCount(&T::initializeNotificationsSession) == 5,
+ "Expected initializeNotificationsSession(...) to have 5 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::initializeNotificationsSession, jsInvoker_, instance_, std::move(identityKeys), std::move(prekey), std::move(prekeySignature), std::move(oneTimeKeys));
+ }
+ jsi::Value isNotificationsSessionInitialized(jsi::Runtime &rt) override {
+ static_assert(
+ bridging::getParameterCount(&T::isNotificationsSessionInitialized) == 1,
+ "Expected isNotificationsSessionInitialized(...) to have 1 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::isNotificationsSessionInitialized, jsInvoker_, instance_);
+ }
+ jsi::Value generateInitialNotificationsEncryptedMessage(jsi::Runtime &rt) override {
+ static_assert(
+ bridging::getParameterCount(&T::generateInitialNotificationsEncryptedMessage) == 1,
+ "Expected generateInitialNotificationsEncryptedMessage(...) to have 1 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::generateInitialNotificationsEncryptedMessage, 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 } from 'lib/types/crypto-types';
import type { ClientDBDraftStoreOperation } from 'lib/types/draft-types.js';
import type {
ClientDBMessageInfo,
@@ -54,7 +55,17 @@
) => void;
+initializeCryptoAccount: () => Promise<string>;
+getUserPublicKey: () => Promise<ClientPublicKeys>;
- +getUserOneTimeKeys: () => Promise<string>;
+ +getPrimaryOneTimeKeys: (
+ oneTimeKeysAmount: number,
+ ) => Promise<OLMOneTimeKeys>;
+ +initializeNotificationsSession: (
+ identityKeys: string,
+ prekey: string,
+ prekeySignature: string,
+ oneTimeKeys: string,
+ ) => Promise<void>;
+ +isNotificationsSessionInitialized: () => Promise<boolean>;
+ +generateInitialNotificationsEncryptedMessage: () => Promise<string>;
+getCodeVersion: () => number;
+terminate: () => void;
+setNotifyToken: (token: string) => Promise<void>;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 6:23 PM (20 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2601926
Default Alt Text
D7395.id26251.diff (14 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