MCPcopy Create free account
hub / github.com/CommE2E/comm / persistCryptoModules

Method persistCryptoModules

native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp:550–590  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

548}
549
550void CommCoreModule::persistCryptoModules(
551 bool persistContentModule,
552 std::optional<std::pair<std::shared_ptr<crypto::CryptoModule>, std::string>>
553 maybeUpdatedNotifsCryptoModule) {
554 std::string storedSecretKey = getAccountDataKey(secureStoreAccountDataKey);
555
556 if (!persistContentModule && !maybeUpdatedNotifsCryptoModule.has_value()) {
557 return;
558 }
559
560 crypto::Persist newContentPersist;
561 if (persistContentModule) {
562 newContentPersist = this->contentCryptoModule->storeAsB64(storedSecretKey);
563 }
564
565 std::promise<void> persistencePromise;
566 std::future<void> persistenceFuture = persistencePromise.get_future();
567 GlobalDBSingleton::instance.scheduleOrRunCancellable(
568 [=, &persistencePromise]() {
569 try {
570 DatabaseManager::getQueryExecutor().beginTransaction();
571 if (persistContentModule) {
572 DatabaseManager::getQueryExecutor().storeOlmPersistData(
573 DatabaseManager::getQueryExecutor().getContentAccountID(),
574 newContentPersist);
575 }
576 if (maybeUpdatedNotifsCryptoModule.has_value()) {
577 NotificationsCryptoModule::persistNotificationsAccount(
578 maybeUpdatedNotifsCryptoModule.value().first,
579 maybeUpdatedNotifsCryptoModule.value().second,
580 true);
581 }
582 DatabaseManager::getQueryExecutor().commitTransaction();
583 persistencePromise.set_value();
584 } catch (std::system_error &e) {
585 DatabaseManager::getQueryExecutor().rollbackTransaction();
586 persistencePromise.set_exception(std::make_exception_ptr(e));
587 }
588 });
589 persistenceFuture.get();
590}
591
592jsi::Value CommCoreModule::initializeCryptoAccount(jsi::Runtime &rt) {
593 folly::Optional<std::string> storedSecretKey =

Calls 9

getAccountDataKeyFunction · 0.85
storeOlmPersistDataMethod · 0.80
getMethod · 0.65
storeAsB64Method · 0.45
beginTransactionMethod · 0.45
getContentAccountIDMethod · 0.45
commitTransactionMethod · 0.45
rollbackTransactionMethod · 0.45

Tested by

no test coverage detected