Changeset View
Changeset View
Standalone View
Standalone View
native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
#include "CommCoreModule.h" | #include "CommCoreModule.h" | ||||
#include "../CryptoTools/DeviceID.h" | #include "../CryptoTools/DeviceID.h" | ||||
#include "../Notifications/BackgroundDataStorage/NotificationsCryptoModule.h" | |||||
#include "DatabaseManager.h" | #include "DatabaseManager.h" | ||||
#include "DraftStoreOperations.h" | #include "DraftStoreOperations.h" | ||||
#include "InternalModules/GlobalDBSingleton.h" | #include "InternalModules/GlobalDBSingleton.h" | ||||
#include "MessageStoreOperations.h" | #include "MessageStoreOperations.h" | ||||
#include "TerminateApp.h" | #include "TerminateApp.h" | ||||
#include "ThreadStoreOperations.h" | #include "ThreadStoreOperations.h" | ||||
#include <ReactCommon/TurboModuleUtils.h> | #include <ReactCommon/TurboModuleUtils.h> | ||||
▲ Show 20 Lines • Show All 767 Lines • ▼ Show 20 Lines | return createPromiseAsJSIValue( | ||||
} catch (std::system_error &e) { | } catch (std::system_error &e) { | ||||
error = e.what(); | error = e.what(); | ||||
} | } | ||||
this->jsInvoker_->invokeAsync([=]() { | this->jsInvoker_->invokeAsync([=]() { | ||||
if (error.size()) { | if (error.size()) { | ||||
promise->reject(error); | promise->reject(error); | ||||
return; | return; | ||||
} | } | ||||
promise->resolve(jsi::Value::undefined()); | |||||
}); | }); | ||||
}, | }, | ||||
promise, | promise, | ||||
this->jsInvoker_); | this->jsInvoker_); | ||||
} else { | } else { | ||||
this->cryptoModule->restoreFromB64( | this->cryptoModule->restoreFromB64( | ||||
storedSecretKey.value(), persist); | storedSecretKey.value(), persist); | ||||
this->jsInvoker_->invokeAsync([=]() { | this->jsInvoker_->invokeAsync([=]() { | ||||
if (error.size()) { | if (error.size()) { | ||||
promise->reject(error); | promise->reject(error); | ||||
return; | 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( | GlobalDBSingleton::instance.scheduleOrRunCancellable( | ||||
job, promise, this->jsInvoker_); | job, promise, this->jsInvoker_); | ||||
}); | }); | ||||
} | } | ||||
jsi::Value CommCoreModule::getUserPublicKey(jsi::Runtime &rt) { | jsi::Value CommCoreModule::getUserPublicKey(jsi::Runtime &rt) { | ||||
return createPromiseAsJSIValue( | return createPromiseAsJSIValue( | ||||
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) { | rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) { | ||||
taskType job = [=, &innerRt]() { | taskType job = [=, &innerRt]() { | ||||
std::string error; | std::string error; | ||||
std::string result; | std::string primaryKeysResult; | ||||
std::string notificationsKeysResult; | |||||
if (this->cryptoModule == nullptr) { | if (this->cryptoModule == nullptr) { | ||||
error = "user has not been initialized"; | error = "user has not been initialized"; | ||||
} else { | } else { | ||||
result = this->cryptoModule->getIdentityKeys(); | primaryKeysResult = this->cryptoModule->getIdentityKeys(); | ||||
} | |||||
try { | |||||
if (!error.size()) { | |||||
notificationsKeysResult = | |||||
NotificationsCryptoModule::getNotificationsIdentityKeys(); | |||||
ashoat: I believe this call is causing a JNI error, see [ENG-2787](https://linear.app/comm/issue/ENG… | |||||
ashoatUnsubmitted Not Done Inline ActionsIgnore, this was incorrect ashoat: Ignore, this was incorrect | |||||
} | |||||
} catch (const std::exception &e) { | |||||
error = e.what(); | |||||
} | } | ||||
this->jsInvoker_->invokeAsync([=, &innerRt]() { | this->jsInvoker_->invokeAsync([=, &innerRt]() { | ||||
if (error.size()) { | if (error.size()) { | ||||
promise->reject(error); | promise->reject(error); | ||||
return; | return; | ||||
} | } | ||||
folly::dynamic parsed = folly::parseJson(result); | |||||
auto curve25519{jsi::String::createFromUtf8( | folly::dynamic parsedPrimary = folly::parseJson(primaryKeysResult); | ||||
innerRt, parsed["curve25519"].asString())}; | auto primaryCurve25519{jsi::String::createFromUtf8( | ||||
auto ed25519{jsi::String::createFromUtf8( | innerRt, parsedPrimary["curve25519"].asString())}; | ||||
innerRt, parsed["ed25519"].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); | auto jsiClientPublicKeys = jsi::Object(innerRt); | ||||
jsiClientPublicKeys.setProperty(innerRt, "curve25519", curve25519); | jsiClientPublicKeys.setProperty( | ||||
jsiClientPublicKeys.setProperty(innerRt, "ed25519", ed25519); | innerRt, | ||||
"primaryIdentityPublicKeys", | |||||
jsiPrimaryIdentityPublicKeys); | |||||
jsiClientPublicKeys.setProperty( | |||||
innerRt, | |||||
"notificationIdentityPublicKeys", | |||||
jsiNotificationIdentityPublicKeys); | |||||
promise->resolve(std::move(jsiClientPublicKeys)); | promise->resolve(std::move(jsiClientPublicKeys)); | ||||
}); | }); | ||||
}; | }; | ||||
this->cryptoThread->scheduleTask(job); | this->cryptoThread->scheduleTask(job); | ||||
}); | }); | ||||
} | } | ||||
jsi::Value CommCoreModule::getUserOneTimeKeys(jsi::Runtime &rt) { | jsi::Value CommCoreModule::getUserOneTimeKeys(jsi::Runtime &rt) { | ||||
▲ Show 20 Lines • Show All 234 Lines • Show Last 20 Lines |
I believe this call is causing a JNI error, see ENG-2787
We should perhaps avoid calling this from the crypto thread?