| 2438 | } |
| 2439 | |
| 2440 | jsi::Value CommCoreModule::createUserKeysBackup( |
| 2441 | jsi::Runtime &rt, |
| 2442 | jsi::String backupSecret) { |
| 2443 | std::string backupSecretStr = backupSecret.utf8(rt); |
| 2444 | return createPromiseAsJSIValue( |
| 2445 | rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) { |
| 2446 | std::string backupMessage; |
| 2447 | try { |
| 2448 | backupMessage = getSIWEBackupMessage(); |
| 2449 | } catch (std::system_error &e) { |
| 2450 | this->jsInvoker_->invokeAsync( |
| 2451 | [=, &innerRt]() { promise->reject(e.what()); }); |
| 2452 | return; |
| 2453 | } |
| 2454 | |
| 2455 | this->cryptoThread->scheduleTask([=, &innerRt]() { |
| 2456 | std::string error; |
| 2457 | std::string backupID; |
| 2458 | try { |
| 2459 | backupID = crypto::Tools::generateRandomURLSafeString(32); |
| 2460 | } catch (const std::exception &e) { |
| 2461 | error = "Failed to generate backupID"; |
| 2462 | } |
| 2463 | |
| 2464 | std::string pickleKey; |
| 2465 | std::string pickledAccount; |
| 2466 | if (!error.size()) { |
| 2467 | try { |
| 2468 | pickleKey = crypto::Tools::generateRandomString(64); |
| 2469 | pickledAccount = |
| 2470 | this->contentCryptoModule->pickleAccountToString(pickleKey); |
| 2471 | } catch (const std::exception &e) { |
| 2472 | error = "Failed to pickle crypto account"; |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | if (!error.size()) { |
| 2477 | auto currentID = RustPromiseManager::instance.addPromise( |
| 2478 | {promise, this->jsInvoker_, innerRt}); |
| 2479 | ::createUserKeysBackup( |
| 2480 | rust::string(backupID), |
| 2481 | rust::string(backupSecretStr), |
| 2482 | rust::string(pickleKey), |
| 2483 | rust::string(pickledAccount), |
| 2484 | rust::string(backupMessage), |
| 2485 | currentID); |
| 2486 | } else { |
| 2487 | this->jsInvoker_->invokeAsync( |
| 2488 | [=, &innerRt]() { promise->reject(error); }); |
| 2489 | } |
| 2490 | }); |
| 2491 | }); |
| 2492 | } |
| 2493 | |
| 2494 | jsi::Value CommCoreModule::restoreBackupData( |
| 2495 | jsi::Runtime &rt, |
nothing calls this directly
no test coverage detected