diff --git a/native/cpp/CommonCpp/CryptoTools/CryptoModule.h b/native/cpp/CommonCpp/CryptoTools/CryptoModule.h --- a/native/cpp/CommonCpp/CryptoTools/CryptoModule.h +++ b/native/cpp/CommonCpp/CryptoTools/CryptoModule.h @@ -25,6 +25,7 @@ void createAccount(); void exposePublicIdentityKeys(); void generateOneTimeKeys(size_t oneTimeKeysAmount); + std::string generateAndGetPrekey(); // returns number of published keys size_t publishOneTimeKeys(); bool prekeyExistsAndOlderThan(uint64_t threshold); @@ -50,7 +51,6 @@ std::string getPrekey(); std::string getPrekeySignature(); std::optional getUnpublishedPrekey(); - std::string generateAndGetPrekey(); void markPrekeyAsPublished(); void forgetOldPrekey(); 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 @@ -73,7 +73,6 @@ virtual jsi::Value getUserPublicKey(jsi::Runtime &rt) override; virtual jsi::Value getOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) override; - virtual jsi::Value generateAndGetPrekeys(jsi::Runtime &rt) override; virtual jsi::Value validateAndUploadPrekeys( jsi::Runtime &rt, jsi::String authUserID, 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 @@ -617,64 +617,6 @@ }); } -jsi::Value CommCoreModule::generateAndGetPrekeys(jsi::Runtime &rt) { - return createPromiseAsJSIValue( - rt, [=](jsi::Runtime &innerRt, std::shared_ptr promise) { - taskType job = [=, &innerRt]() { - std::string error; - std::string contentPrekey, contentPrekeySignature, notifPrekey, - notifPrekeySignature; - - if (this->cryptoModule == nullptr) { - error = "user has not been initialized"; - } else { - try { - contentPrekey = this->cryptoModule->generateAndGetPrekey(); - contentPrekeySignature = this->cryptoModule->getPrekeySignature(); - this->persistCryptoModule(); - notifPrekey = - NotificationsCryptoModule::generateAndGetNotificationsPrekey( - "Comm"); - notifPrekeySignature = - NotificationsCryptoModule::getNotificationsPrekeySignature( - "Comm"); - } catch (const std::exception &e) { - error = e.what(); - } - } - - this->jsInvoker_->invokeAsync([=, &innerRt]() { - if (error.size()) { - promise->reject(error); - return; - } - auto contentPrekeyJSI = - jsi::String::createFromUtf8(innerRt, contentPrekey); - auto contentPrekeySignatureJSI = - jsi::String::createFromUtf8(innerRt, contentPrekeySignature); - auto notifPrekeyJSI = - jsi::String::createFromUtf8(innerRt, notifPrekey); - auto notifPrekeySignatureJSI = - jsi::String::createFromUtf8(innerRt, notifPrekeySignature); - - auto signedPrekeysJSI = jsi::Object(innerRt); - signedPrekeysJSI.setProperty( - innerRt, "contentPrekey", contentPrekeyJSI); - signedPrekeysJSI.setProperty( - innerRt, "contentPrekeySignature", contentPrekeySignatureJSI); - signedPrekeysJSI.setProperty( - innerRt, "notifPrekey", notifPrekeyJSI); - signedPrekeysJSI.setProperty( - innerRt, "notifPrekeySignature", notifPrekeySignatureJSI); - - promise->resolve(std::move(signedPrekeysJSI)); - }); - }; - - this->cryptoThread->scheduleTask(job); - }); -} - std::pair getNotificationsPrekeyAndSignature() { // TODO: Implement notifs prekey rotation. // Notifications prekey is not rotated at this moment. It diff --git a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h --- a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h +++ b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h @@ -35,8 +35,6 @@ static std::string getNotificationsPrekey(const std::string &callingProcessName); static std::string - generateAndGetNotificationsPrekey(const std::string &callingProcessName); - static std::string getNotificationsPrekeySignature(const std::string &callingProcessName); static std::string getNotificationsOneTimeKeysForPublishing( const size_t oneTimeKeysAmount, diff --git a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp --- a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp +++ b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp @@ -214,17 +214,6 @@ return prekey; } -std::string NotificationsCryptoModule::generateAndGetNotificationsPrekey( - const std::string &callingProcessName) { - std::string prekey; - auto caller = - [&prekey](const std::unique_ptr &cryptoModule) { - prekey = cryptoModule->generateAndGetPrekey(); - }; - NotificationsCryptoModule::callCryptoModule(caller, callingProcessName); - return prekey; -} - std::string NotificationsCryptoModule::getNotificationsPrekeySignature( const std::string &callingProcessName) { std::string prekeySignature; 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 @@ -72,9 +72,6 @@ static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getOneTimeKeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->getOneTimeKeys(rt, args[0].asNumber()); } -static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_generateAndGetPrekeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->generateAndGetPrekeys(rt); -} static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_validateAndGetPrekeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->validateAndGetPrekeys(rt); } @@ -182,7 +179,6 @@ methodMap_["initializeCryptoAccount"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeCryptoAccount}; methodMap_["getUserPublicKey"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUserPublicKey}; methodMap_["getOneTimeKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getOneTimeKeys}; - methodMap_["generateAndGetPrekeys"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_generateAndGetPrekeys}; methodMap_["validateAndGetPrekeys"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_validateAndGetPrekeys}; methodMap_["validateAndUploadPrekeys"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_validateAndUploadPrekeys}; methodMap_["initializeNotificationsSession"] = MethodMetadata {5, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeNotificationsSession}; 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 @@ -39,7 +39,6 @@ virtual jsi::Value initializeCryptoAccount(jsi::Runtime &rt) = 0; virtual jsi::Value getUserPublicKey(jsi::Runtime &rt) = 0; virtual jsi::Value getOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) = 0; - virtual jsi::Value generateAndGetPrekeys(jsi::Runtime &rt) = 0; virtual jsi::Value validateAndGetPrekeys(jsi::Runtime &rt) = 0; virtual jsi::Value validateAndUploadPrekeys(jsi::Runtime &rt, jsi::String authUserID, jsi::String authDeviceID, jsi::String authAccessToken) = 0; virtual jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys, jsi::String keyserverID) = 0; @@ -240,14 +239,6 @@ return bridging::callFromJs( rt, &T::getOneTimeKeys, jsInvoker_, instance_, std::move(oneTimeKeysAmount)); } - jsi::Value generateAndGetPrekeys(jsi::Runtime &rt) override { - static_assert( - bridging::getParameterCount(&T::generateAndGetPrekeys) == 1, - "Expected generateAndGetPrekeys(...) to have 1 parameters"); - - return bridging::callFromJs( - rt, &T::generateAndGetPrekeys, jsInvoker_, instance_); - } jsi::Value validateAndGetPrekeys(jsi::Runtime &rt) override { static_assert( bridging::getParameterCount(&T::validateAndGetPrekeys) == 1, diff --git a/native/identity-service/identity-service-context-provider.react.js b/native/identity-service/identity-service-context-provider.react.js --- a/native/identity-service/identity-service-context-provider.react.js +++ b/native/identity-service/identity-service-context-provider.react.js @@ -206,7 +206,7 @@ ] = await Promise.all([ commCoreModule.getUserPublicKey(), commCoreModule.getOneTimeKeys(ONE_TIME_KEYS_NUMBER), - commCoreModule.generateAndGetPrekeys(), + commCoreModule.validateAndGetPrekeys(), ]); const registrationResult = await commRustModule.registerUser( username, diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -85,7 +85,6 @@ +initializeCryptoAccount: () => Promise; +getUserPublicKey: () => Promise; +getOneTimeKeys: (oneTimeKeysAmount: number) => Promise; - +generateAndGetPrekeys: () => Promise; +validateAndGetPrekeys: () => Promise; +validateAndUploadPrekeys: ( authUserID: string,