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 @@ -85,7 +85,7 @@ setNonce(response); })(), ); - await commCoreModule.initializeCryptoAccount('PLACEHOLDER'); + await commCoreModule.initializeCryptoAccount(); const { ed25519 } = await commCoreModule.getUserPublicKey(); setPrimaryIdentityPublicKey(ed25519); })(); 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 @@ -18,6 +18,7 @@ CommSecureStore secureStore; const std::string secureStoreAccountDataKey = "cryptoAccountDataKey"; + const std::string publicCryptoAccountID = "publicCryptoAccountID"; std::unique_ptr cryptoModule; template @@ -45,8 +46,7 @@ virtual void processThreadStoreOperationsSync( jsi::Runtime &rt, jsi::Array operations) override; - virtual jsi::Value - initializeCryptoAccount(jsi::Runtime &rt, jsi::String userId) 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 void terminate(jsi::Runtime &rt) override; 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 @@ -726,9 +726,7 @@ TerminateApp::terminate(); } -jsi::Value -CommCoreModule::initializeCryptoAccount(jsi::Runtime &rt, jsi::String userId) { - std::string userIdStr = userId.utf8(rt); +jsi::Value CommCoreModule::initializeCryptoAccount(jsi::Runtime &rt) { folly::Optional storedSecretKey = this->secureStore.get(this->secureStoreAccountDataKey); if (!storedSecretKey.hasValue()) { @@ -767,7 +765,7 @@ this->cryptoThread->scheduleTask([=]() { std::string error; this->cryptoModule.reset(new crypto::CryptoModule( - userIdStr, storedSecretKey.value(), persist)); + this->publicCryptoAccountID, storedSecretKey.value(), persist)); if (persist.isEmpty()) { crypto::Persist newPersist = this->cryptoModule->storeAsB64(storedSecretKey.value()); 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 @@ -51,7 +51,7 @@ return jsi::Value::undefined(); } static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeCryptoAccount(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->initializeCryptoAccount(rt, args[0].asString(rt)); + return static_cast(&turboModule)->initializeCryptoAccount(rt); } static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUserPublicKey(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->getUserPublicKey(rt); @@ -109,7 +109,7 @@ methodMap_["getAllThreadsSync"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllThreadsSync}; methodMap_["processThreadStoreOperations"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_processThreadStoreOperations}; methodMap_["processThreadStoreOperationsSync"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_processThreadStoreOperationsSync}; - methodMap_["initializeCryptoAccount"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeCryptoAccount}; + methodMap_["initializeCryptoAccount"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeCryptoAccount}; methodMap_["getUserPublicKey"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUserPublicKey}; methodMap_["getUserOneTimeKeys"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getUserOneTimeKeys}; methodMap_["getCodeVersion"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCodeVersion}; 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 @@ -32,7 +32,7 @@ virtual jsi::Array getAllThreadsSync(jsi::Runtime &rt) = 0; virtual jsi::Value processThreadStoreOperations(jsi::Runtime &rt, jsi::Array operations) = 0; virtual void processThreadStoreOperationsSync(jsi::Runtime &rt, jsi::Array operations) = 0; - virtual jsi::Value initializeCryptoAccount(jsi::Runtime &rt, jsi::String userId) = 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 double getCodeVersion(jsi::Runtime &rt) = 0; @@ -163,13 +163,13 @@ return bridging::callFromJs( rt, &T::processThreadStoreOperationsSync, jsInvoker_, instance_, std::move(operations)); } - jsi::Value initializeCryptoAccount(jsi::Runtime &rt, jsi::String userId) override { + jsi::Value initializeCryptoAccount(jsi::Runtime &rt) override { static_assert( - bridging::getParameterCount(&T::initializeCryptoAccount) == 2, - "Expected initializeCryptoAccount(...) to have 2 parameters"); + bridging::getParameterCount(&T::initializeCryptoAccount) == 1, + "Expected initializeCryptoAccount(...) to have 1 parameters"); return bridging::callFromJs( - rt, &T::initializeCryptoAccount, jsInvoker_, instance_, std::move(userId)); + rt, &T::initializeCryptoAccount, jsInvoker_, instance_); } jsi::Value getUserPublicKey(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 @@ -52,7 +52,7 @@ +processThreadStoreOperationsSync: ( operations: $ReadOnlyArray, ) => void; - +initializeCryptoAccount: (userId: string) => Promise; + +initializeCryptoAccount: () => Promise; +getUserPublicKey: () => Promise; +getUserOneTimeKeys: () => Promise; +getCodeVersion: () => number; 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 @@ -23,7 +23,7 @@ calendarActive: boolean, ) => { const loginExtraFuncWithIdentityKey = async () => { - await commCoreModule.initializeCryptoAccount('PLACEHOLDER'); + await commCoreModule.initializeCryptoAccount(); const { ed25519 } = await commCoreModule.getUserPublicKey(); return { ...logInExtraInfoFunc(calendarActive),