Page MenuHomePhabricator

D14002.id.diff
No OneTemporary

D14002.id.diff

diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
@@ -229,10 +229,7 @@
jsi::String backupDataKey,
jsi::String backupLogDataKey,
jsi::String maxVersion) override;
- virtual jsi::Value retrieveBackupKeys(
- jsi::Runtime &rt,
- jsi::String backupSecret,
- jsi::String backupID) override;
+ virtual jsi::Value retrieveBackupKeys(jsi::Runtime &rt) override;
virtual jsi::Value retrieveLatestBackupInfo(
jsi::Runtime &rt,
jsi::String userIdentifier) override;
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
@@ -2686,20 +2686,62 @@
});
}
-jsi::Value CommCoreModule::retrieveBackupKeys(
- jsi::Runtime &rt,
- jsi::String backupSecret,
- jsi::String backupID) {
- std::string backupSecretStr = backupSecret.utf8(rt);
- std::string backupIDStr = backupID.utf8(rt);
+jsi::Value CommCoreModule::retrieveBackupKeys(jsi::Runtime &rt) {
return createPromiseAsJSIValue(
- rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
- auto currentID = RustPromiseManager::instance.addPromise(
- {promise, this->jsInvoker_, innerRt});
- ::retrieveBackupKeys(
- rust::string(backupSecretStr),
- rust::string(backupIDStr),
- currentID);
+ rt, [this](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [this, &innerRt, promise]() {
+ std::string error;
+ std::string backupID;
+ std::string backupDataKey;
+ std::string backupLogDataKey;
+ try {
+ backupID =
+ DatabaseManager::getQueryExecutor().getMetadata("backupID");
+ folly::Optional<std::string> backupDataKeyOpt =
+ CommSecureStore::get(CommSecureStore::encryptionKey);
+ if (backupDataKeyOpt.hasValue()) {
+ backupDataKey = backupDataKeyOpt.value();
+ } else {
+ throw std::runtime_error("missing backupDataKey");
+ }
+ folly::Optional<std::string> backupLogDataKeyOpt =
+ CommSecureStore::get(CommSecureStore::backupLogsEncryptionKey);
+ if (backupLogDataKeyOpt.hasValue()) {
+ backupLogDataKey = backupLogDataKeyOpt.value();
+ } else {
+ throw std::runtime_error("missing backupLogDataKey");
+ }
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+ this->jsInvoker_->invokeAsync([&innerRt,
+ error,
+ backupID,
+ backupDataKey,
+ backupLogDataKey,
+ promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ } else {
+ auto backupKeys = jsi::Object(innerRt);
+ backupKeys.setProperty(
+ innerRt,
+ "backupID",
+ jsi::String::createFromUtf8(innerRt, backupID));
+ backupKeys.setProperty(
+ innerRt,
+ "backupDataKey",
+ jsi::String::createFromUtf8(innerRt, backupDataKey));
+ backupKeys.setProperty(
+ innerRt,
+ "backupLogDataKey",
+ jsi::String::createFromUtf8(innerRt, backupLogDataKey));
+ promise->resolve(std::move(backupKeys));
+ }
+ });
+ };
+ GlobalDBSingleton::instance.scheduleOrRunCancellable(
+ job, promise, this->jsInvoker_);
});
}
diff --git a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp
--- a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp
+++ b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp
@@ -194,7 +194,7 @@
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->restoreBackupData(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt));
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
- return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->retrieveBackupKeys(rt, args[0].asString(rt), args[1].asString(rt));
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->retrieveBackupKeys(rt);
}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveLatestBackupInfo(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->retrieveLatestBackupInfo(rt, args[0].asString(rt));
@@ -305,7 +305,7 @@
methodMap_["createFullBackup"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_createFullBackup};
methodMap_["restoreBackup"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackup};
methodMap_["restoreBackupData"] = MethodMetadata {4, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackupData};
- methodMap_["retrieveBackupKeys"] = MethodMetadata {2, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys};
+ methodMap_["retrieveBackupKeys"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys};
methodMap_["retrieveLatestBackupInfo"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveLatestBackupInfo};
methodMap_["setSIWEBackupSecrets"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setSIWEBackupSecrets};
methodMap_["getSIWEBackupSecrets"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets};
diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h
--- a/native/cpp/CommonCpp/_generated/commJSI.h
+++ b/native/cpp/CommonCpp/_generated/commJSI.h
@@ -78,7 +78,7 @@
virtual jsi::Value createFullBackup(jsi::Runtime &rt, jsi::String backupSecret) = 0;
virtual jsi::Value restoreBackup(jsi::Runtime &rt, jsi::String backupSecret, jsi::String maxVersion, jsi::String backupID) = 0;
virtual jsi::Value restoreBackupData(jsi::Runtime &rt, jsi::String backupID, jsi::String backupDataKey, jsi::String backupLogDataKey, jsi::String maxVersion) = 0;
- virtual jsi::Value retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret, jsi::String backupID) = 0;
+ virtual jsi::Value retrieveBackupKeys(jsi::Runtime &rt) = 0;
virtual jsi::Value retrieveLatestBackupInfo(jsi::Runtime &rt, jsi::String userIdentifier) = 0;
virtual jsi::Value setSIWEBackupSecrets(jsi::Runtime &rt, jsi::Object siweBackupSecrets) = 0;
virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) = 0;
@@ -580,13 +580,13 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::restoreBackupData, jsInvoker_, instance_, std::move(backupID), std::move(backupDataKey), std::move(backupLogDataKey), std::move(maxVersion));
}
- jsi::Value retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret, jsi::String backupID) override {
+ jsi::Value retrieveBackupKeys(jsi::Runtime &rt) override {
static_assert(
- bridging::getParameterCount(&T::retrieveBackupKeys) == 3,
- "Expected retrieveBackupKeys(...) to have 3 parameters");
+ bridging::getParameterCount(&T::retrieveBackupKeys) == 1,
+ "Expected retrieveBackupKeys(...) to have 1 parameters");
return bridging::callFromJs<jsi::Value>(
- rt, &T::retrieveBackupKeys, jsInvoker_, instance_, std::move(backupSecret), std::move(backupID));
+ rt, &T::retrieveBackupKeys, jsInvoker_, instance_);
}
jsi::Value retrieveLatestBackupInfo(jsi::Runtime &rt, jsi::String userIdentifier) override {
static_assert(
diff --git a/native/profile/secondary-device-qr-code-scanner.react.js b/native/profile/secondary-device-qr-code-scanner.react.js
--- a/native/profile/secondary-device-qr-code-scanner.react.js
+++ b/native/profile/secondary-device-qr-code-scanner.react.js
@@ -14,10 +14,6 @@
import { useDeviceListUpdate } from 'lib/shared/device-list-utils.js';
import { IdentityClientContext } from 'lib/shared/identity-client-context.js';
import { useTunnelbroker } from 'lib/tunnelbroker/tunnelbroker-context.js';
-import {
- backupKeysValidator,
- type BackupKeys,
-} from 'lib/types/backup-types.js';
import {
identityDeviceTypes,
type IdentityDeviceType,
@@ -32,11 +28,8 @@
type PeerToPeerMessage,
} from 'lib/types/tunnelbroker/peer-to-peer-message-types.js';
import { qrCodeAuthMessageTypes } from 'lib/types/tunnelbroker/qr-code-auth-message-types.js';
-import { assertWithValidator } from 'lib/utils/validation-utils.js';
import type { ProfileNavigationProp } from './profile.react.js';
-import { useClientBackup } from '../backup/use-client-backup.js';
-import { useGetBackupSecretForLoggedInUser } from '../backup/use-get-backup-secret.js';
import TextInput from '../components/text-input.react.js';
import { commCoreModule } from '../native-modules.js';
import HeaderRightTextButton from '../navigation/header-right-text-button.react.js';
@@ -78,8 +71,6 @@
const ownPeerDevices = useSelector(getOwnPeerDevices);
const keyserverDeviceID = getKeyserverDeviceID(ownPeerDevices);
- const getBackupSecret = useGetBackupSecretForLoggedInUser();
- const { retrieveLatestBackupInfo } = useClientBackup();
const { panelForegroundTertiaryLabel } = useColors();
@@ -169,18 +160,7 @@
const sendDeviceListUpdateSuccessMessage = async () => {
let backupData = null;
if (deviceType !== identityDeviceTypes.KEYSERVER) {
- const [backupSecret, latestBackupInfo] = await Promise.all([
- getBackupSecret(),
- retrieveLatestBackupInfo(),
- ]);
- const backupKeysResponse = await commCoreModule.retrieveBackupKeys(
- backupSecret,
- latestBackupInfo.backupID,
- );
- backupData = assertWithValidator<BackupKeys>(
- JSON.parse(backupKeysResponse),
- backupKeysValidator,
- );
+ backupData = await commCoreModule.retrieveBackupKeys();
}
const message = await composeTunnelbrokerQRAuthMessage(encryptionKey, {
type: qrCodeAuthMessageTypes.DEVICE_LIST_UPDATE_SUCCESS,
@@ -253,11 +233,9 @@
goBack();
}
}, [
- getBackupSecret,
goBack,
identityContext,
keyserverDeviceID,
- retrieveLatestBackupInfo,
runDeviceListUpdate,
tunnelbrokerContext,
]);
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -8,6 +8,7 @@
import type { ClientDBMessageStoreOperation } from 'lib/ops/message-store-ops.js';
import type { ClientDBReportStoreOperation } from 'lib/ops/report-store-ops.js';
import type { ClientDBThreadStoreOperation } from 'lib/ops/thread-store-ops.js';
+import type { BackupKeys } from 'lib/types/backup-types.js';
import type {
OneTimeKeysResult,
SignedPrekeys,
@@ -169,10 +170,7 @@
backupLogDataKey: string,
maxVersion: string,
) => Promise<void>;
- +retrieveBackupKeys: (
- backupSecret: string,
- backupID: string,
- ) => Promise<string>;
+ +retrieveBackupKeys: () => Promise<Object>;
+retrieveLatestBackupInfo: (userIdentifier: string) => Promise<string>;
+setSIWEBackupSecrets: (siweBackupSecrets: Object) => Promise<void>;
+getSIWEBackupSecrets: () => Promise<?Object>;
@@ -240,6 +238,7 @@
+processDBStoreOperations: (
operations: ClientDBStoreOperations,
) => Promise<void>;
+ +retrieveBackupKeys: () => Promise<BackupKeys>;
}
export default (TurboModuleRegistry.getEnforcing<Spec>(

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 2:46 AM (14 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2698041
Default Alt Text
D14002.id.diff (12 KB)

Event Timeline