| 2367 | } |
| 2368 | |
| 2369 | jsi::Value CommCoreModule::createFullBackup( |
| 2370 | jsi::Runtime &rt, |
| 2371 | jsi::String backupSecret, |
| 2372 | jsi::Function compactionCreationCallback) { |
| 2373 | std::string backupSecretStr = backupSecret.utf8(rt); |
| 2374 | |
| 2375 | auto dummyReject = jsi::Function::createFromHostFunction( |
| 2376 | rt, |
| 2377 | jsi::PropNameID::forAscii(rt, "_reject"), |
| 2378 | 0, |
| 2379 | [](jsi::Runtime &rt, |
| 2380 | const jsi::Value &thisVal, |
| 2381 | const jsi::Value *args, |
| 2382 | size_t count) { return jsi::Value::undefined(); }); |
| 2383 | auto compactionCreationPromise = std::make_shared<Promise>( |
| 2384 | rt, std::move(compactionCreationCallback), std::move(dummyReject)); |
| 2385 | |
| 2386 | return createPromiseAsJSIValue( |
| 2387 | rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) { |
| 2388 | std::string backupMessage; |
| 2389 | try { |
| 2390 | backupMessage = getSIWEBackupMessage(); |
| 2391 | } catch (std::system_error &e) { |
| 2392 | this->jsInvoker_->invokeAsync( |
| 2393 | [=, &innerRt]() { promise->reject(e.what()); }); |
| 2394 | return; |
| 2395 | } |
| 2396 | |
| 2397 | this->cryptoThread->scheduleTask([=, &innerRt]() { |
| 2398 | std::string error; |
| 2399 | std::string backupID; |
| 2400 | try { |
| 2401 | backupID = crypto::Tools::generateRandomURLSafeString(32); |
| 2402 | } catch (const std::exception &e) { |
| 2403 | error = "Failed to generate backupID"; |
| 2404 | } |
| 2405 | |
| 2406 | std::string pickleKey; |
| 2407 | std::string pickledAccount; |
| 2408 | if (!error.size()) { |
| 2409 | try { |
| 2410 | pickleKey = crypto::Tools::generateRandomString(64); |
| 2411 | pickledAccount = |
| 2412 | this->contentCryptoModule->pickleAccountToString(pickleKey); |
| 2413 | } catch (const std::exception &e) { |
| 2414 | error = "Failed to pickle crypto account"; |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | if (!error.size()) { |
| 2419 | |
| 2420 | auto compactionCreationID = RustPromiseManager::instance.addPromise( |
| 2421 | {compactionCreationPromise, this->jsInvoker_, innerRt}); |
| 2422 | auto currentID = RustPromiseManager::instance.addPromise( |
| 2423 | {promise, this->jsInvoker_, innerRt}); |
| 2424 | ::createBackup( |
| 2425 | rust::string(backupID), |
| 2426 | rust::string(backupSecretStr), |
nothing calls this directly
no test coverage detected