diff --git a/native/account/siwe-panel.react.js b/native/account/siwe-panel.react.js --- a/native/account/siwe-panel.react.js +++ b/native/account/siwe-panel.react.js @@ -86,7 +86,9 @@ })(), ); await commCoreModule.initializeCryptoAccount(); - const { ed25519 } = await commCoreModule.getUserPublicKey(); + const { + primaryIdentityPublicKeys: { ed25519 }, + } = await commCoreModule.getUserPublicKey(); setPrimaryIdentityPublicKey(ed25519); })(); }, [dispatchActionPromise, getSIWENonceCall]); diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp @@ -1,4 +1,5 @@ #include "DatabaseManager.h" +#include "../Notifications/BackgroundDataStorage/NotificationsCryptoModule.h" #include "../Tools/CommSecureStore.h" #include "Logger.h" #include "SQLiteQueryExecutor.h" @@ -30,6 +31,7 @@ void DatabaseManager::clearSensitiveData() { SQLiteQueryExecutor::clearSensitiveData(); + NotificationsCryptoModule::clearSensitiveData(); DatabaseManager::setDatabaseStatusAsWorkable(); } 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 @@ -1,5 +1,6 @@ #include "CommCoreModule.h" #include "../CryptoTools/DeviceID.h" +#include "../Notifications/BackgroundDataStorage/NotificationsCryptoModule.h" #include "DatabaseManager.h" #include "DraftStoreOperations.h" #include "InternalModules/GlobalDBSingleton.h" @@ -783,7 +784,6 @@ promise->reject(error); return; } - promise->resolve(jsi::Value::undefined()); }); }, promise, @@ -797,9 +797,21 @@ promise->reject(error); return; } - promise->resolve(jsi::Value::undefined()); }); } + try { + NotificationsCryptoModule::initializeNotificationsCryptoAccount( + "Comm"); + } catch (const std::exception &e) { + error = e.what(); + } + this->jsInvoker_->invokeAsync([=]() { + if (error.size()) { + promise->reject(error); + return; + } + promise->resolve(jsi::Value::undefined()); + }); }); }; GlobalDBSingleton::instance.scheduleOrRunCancellable( @@ -812,26 +824,59 @@ rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { taskType job = [=, &innerRt]() { std::string error; - std::string result; + std::string primaryKeysResult; + std::string notificationsKeysResult; if (this->cryptoModule == nullptr) { error = "user has not been initialized"; } else { - result = this->cryptoModule->getIdentityKeys(); + primaryKeysResult = this->cryptoModule->getIdentityKeys(); + } + try { + if (!error.size()) { + notificationsKeysResult = + NotificationsCryptoModule::getNotificationsIdentityKeys(); + } + } catch (const std::exception &e) { + error = e.what(); } this->jsInvoker_->invokeAsync([=, &innerRt]() { if (error.size()) { promise->reject(error); return; } - folly::dynamic parsed = folly::parseJson(result); - auto curve25519{jsi::String::createFromUtf8( - innerRt, parsed["curve25519"].asString())}; - auto ed25519{jsi::String::createFromUtf8( - innerRt, parsed["ed25519"].asString())}; + + folly::dynamic parsedPrimary = folly::parseJson(primaryKeysResult); + auto primaryCurve25519{jsi::String::createFromUtf8( + innerRt, parsedPrimary["curve25519"].asString())}; + auto primaryEd25519{jsi::String::createFromUtf8( + innerRt, parsedPrimary["ed25519"].asString())}; + auto jsiPrimaryIdentityPublicKeys = jsi::Object(innerRt); + jsiPrimaryIdentityPublicKeys.setProperty( + innerRt, "ed25519", primaryEd25519); + jsiPrimaryIdentityPublicKeys.setProperty( + innerRt, "curve25519", primaryCurve25519); + + folly::dynamic parsedNotifications = + folly::parseJson(notificationsKeysResult); + auto notificationsCurve25519{jsi::String::createFromUtf8( + innerRt, parsedNotifications["curve25519"].asString())}; + auto notificationsEd25519{jsi::String::createFromUtf8( + innerRt, parsedNotifications["ed25519"].asString())}; + auto jsiNotificationIdentityPublicKeys = jsi::Object(innerRt); + jsiNotificationIdentityPublicKeys.setProperty( + innerRt, "ed25519", notificationsEd25519); + jsiNotificationIdentityPublicKeys.setProperty( + innerRt, "curve25519", notificationsCurve25519); auto jsiClientPublicKeys = jsi::Object(innerRt); - jsiClientPublicKeys.setProperty(innerRt, "curve25519", curve25519); - jsiClientPublicKeys.setProperty(innerRt, "ed25519", ed25519); + jsiClientPublicKeys.setProperty( + innerRt, + "primaryIdentityPublicKeys", + jsiPrimaryIdentityPublicKeys); + jsiClientPublicKeys.setProperty( + innerRt, + "notificationIdentityPublicKeys", + jsiNotificationIdentityPublicKeys); promise->resolve(std::move(jsiClientPublicKeys)); }); }; diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -25,8 +25,14 @@ }; type ClientPublicKeys = { - +curve25519: string, - +ed25519: string, + +primaryIdentityPublicKeys: { + +ed25519: string, + +curve25519: string, + }, + +notificationIdentityPublicKeys: { + +ed25519: string, + +curve25519: string, + }, }; export interface Spec extends TurboModule { diff --git a/native/selectors/account-selectors.js b/native/selectors/account-selectors.js --- a/native/selectors/account-selectors.js +++ b/native/selectors/account-selectors.js @@ -24,7 +24,9 @@ ) => { const loginExtraFuncWithIdentityKey = async () => { await commCoreModule.initializeCryptoAccount(); - const { ed25519 } = await commCoreModule.getUserPublicKey(); + const { + primaryIdentityPublicKeys: { ed25519 }, + } = await commCoreModule.getUserPublicKey(); return { ...logInExtraInfoFunc(calendarActive), primaryIdentityPublicKey: ed25519,