Changeset View
Changeset View
Standalone View
Standalone View
native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
Show First 20 Lines • Show All 720 Lines • ▼ Show 20 Lines | this->runSyncOrThrowJSError<void>(rt, [&threadStoreOps]() { | ||||
} | } | ||||
}); | }); | ||||
} | } | ||||
void CommCoreModule::terminate(jsi::Runtime &rt) { | void CommCoreModule::terminate(jsi::Runtime &rt) { | ||||
TerminateApp::terminate(); | TerminateApp::terminate(); | ||||
} | } | ||||
jsi::Value | jsi::Value CommCoreModule::initializeCryptoAccount(jsi::Runtime &rt) { | ||||
CommCoreModule::initializeCryptoAccount(jsi::Runtime &rt, jsi::String userId) { | |||||
std::string userIdStr = userId.utf8(rt); | |||||
folly::Optional<std::string> storedSecretKey = | folly::Optional<std::string> storedSecretKey = | ||||
this->secureStore.get(this->secureStoreAccountDataKey); | this->secureStore.get(this->secureStoreAccountDataKey); | ||||
if (!storedSecretKey.hasValue()) { | if (!storedSecretKey.hasValue()) { | ||||
storedSecretKey = crypto::Tools::generateRandomString(64); | storedSecretKey = crypto::Tools::generateRandomString(64); | ||||
this->secureStore.set( | this->secureStore.set( | ||||
this->secureStoreAccountDataKey, storedSecretKey.value()); | this->secureStoreAccountDataKey, storedSecretKey.value()); | ||||
} | } | ||||
Show All 22 Lines | return createPromiseAsJSIValue( | ||||
} | } | ||||
} catch (std::system_error &e) { | } catch (std::system_error &e) { | ||||
error = e.what(); | error = e.what(); | ||||
} | } | ||||
this->cryptoThread->scheduleTask([=]() { | this->cryptoThread->scheduleTask([=]() { | ||||
std::string error; | std::string error; | ||||
this->cryptoModule.reset(new crypto::CryptoModule( | this->cryptoModule.reset(new crypto::CryptoModule( | ||||
userIdStr, storedSecretKey.value(), persist)); | this->publicCryptoAccountID, storedSecretKey.value(), persist)); | ||||
if (persist.isEmpty()) { | if (persist.isEmpty()) { | ||||
crypto::Persist newPersist = | crypto::Persist newPersist = | ||||
this->cryptoModule->storeAsB64(storedSecretKey.value()); | this->cryptoModule->storeAsB64(storedSecretKey.value()); | ||||
GlobalDBSingleton::instance.scheduleOrRunCancellable( | GlobalDBSingleton::instance.scheduleOrRunCancellable( | ||||
[=]() { | [=]() { | ||||
std::string error; | std::string error; | ||||
try { | try { | ||||
DatabaseManager::getQueryExecutor().storeOlmPersistData( | DatabaseManager::getQueryExecutor().storeOlmPersistData( | ||||
▲ Show 20 Lines • Show All 300 Lines • Show Last 20 Lines |