diff --git a/native/backup/use-client-backup.js b/native/backup/use-client-backup.js --- a/native/backup/use-client-backup.js +++ b/native/backup/use-client-backup.js @@ -16,6 +16,7 @@ type ClientBackup = { +uploadBackupProtocol: () => Promise, + +createUserKeysBackup: () => Promise, +retrieveLatestBackupInfo: () => Promise, }; @@ -51,6 +52,15 @@ console.info('Backup uploaded.'); }, [loggedIn, currentUserID, currentUserInfo, getBackupSecret]); + const createUserKeysBackup = React.useCallback(async () => { + if (!loggedIn || !currentUserID) { + throw new Error('Attempt to upload User Keys for not logged in user.'); + } + + const backupSecret = await getBackupSecret(); + await commCoreModule.createUserKeysBackup(backupSecret); + }, [loggedIn, currentUserID, getBackupSecret]); + const retrieveLatestBackupInfo = React.useCallback(async () => { if (!loggedIn || !currentUserID || !currentUserInfo?.username) { throw new Error('Attempt to restore backup for not logged in user.'); @@ -69,9 +79,10 @@ return React.useMemo( () => ({ uploadBackupProtocol, + createUserKeysBackup, retrieveLatestBackupInfo, }), - [retrieveLatestBackupInfo, uploadBackupProtocol], + [retrieveLatestBackupInfo, uploadBackupProtocol, createUserKeysBackup], ); } diff --git a/native/profile/backup-menu.react.js b/native/profile/backup-menu.react.js --- a/native/profile/backup-menu.react.js +++ b/native/profile/backup-menu.react.js @@ -39,7 +39,11 @@ state => state.localSettings.isBackupEnabled, ); - const { uploadBackupProtocol, retrieveLatestBackupInfo } = useClientBackup(); + const { + uploadBackupProtocol, + retrieveLatestBackupInfo, + createUserKeysBackup, + } = useClientBackup(); const uploadBackup = React.useCallback(async () => { let message = 'Success'; @@ -52,6 +56,17 @@ Alert.alert('Upload protocol result', message); }, [uploadBackupProtocol]); + const uploadUserKeys = React.useCallback(async () => { + let message = 'Success'; + try { + await createUserKeysBackup(); + } catch (e) { + message = `User Keys upload error: ${String(getMessageForException(e))}`; + console.error(message); + } + Alert.alert('Upload User Keys result', message); + }, [createUserKeysBackup]); + const testRestoreForPasswordUser = React.useCallback(async () => { let message = 'success'; try { @@ -161,6 +176,17 @@ Test backup upload protocol + + +