Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add vault export feature to browser extension (#2524)

Leendert de Borst2ee8c37f7a5b
diff --git a/apps/browser-extension/src/entrypoints/popup/App.tsx b/apps/browser-extension/src/entrypoints/popup/App.tsx
index a31567791..29528a333 100644
--- a/apps/browser-extension/src/entrypoints/popup/App.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/App.tsx
@@ -35,6 +35,7 @@ import ClipboardSettings from '@/entrypoints/popup/pages/settings/ClipboardSetti
import ContextMenuSettings from '@/entrypoints/popup/pages/settings/ContextMenuSettings';
import FamilySharingSettings from '@/entrypoints/popup/pages/settings/FamilySharingSettings';
import IdentityGeneratorSettings from '@/entrypoints/popup/pages/settings/IdentityGeneratorSettings';
+import ImportExportSettings from '@/entrypoints/popup/pages/settings/ImportExportSettings';
import LanguageSettings from '@/entrypoints/popup/pages/settings/LanguageSettings';
import PasskeySettings from '@/entrypoints/popup/pages/settings/PasskeySettings';
import PasswordGeneratorSettings from '@/entrypoints/popup/pages/settings/PasswordGeneratorSettings';
@@ -225,6 +226,7 @@ const App: React.FC = () => {
{ path: '/settings/identity-generator', element: <IdentityGeneratorSettings />, showBackButton: true, title: t('common.settings') },
{ path: '/settings/password-generator', element: <PasswordGeneratorSettings />, showBackButton: true, title: t('common.settings') },
{ path: '/settings/appearance', element: <AppearanceSettings />, showBackButton: true, title: t('common.settings') },
+ { path: '/settings/import-export', element: <ImportExportSettings />, showBackButton: true, title: t('common.settings') },
{ path: '/settings/family-sharing', element: <RequireCapability capability={CapabilityKeys.VaultSharing}><FamilySharingSettings /></RequireCapability>, showBackButton: true, title: t('common.settings') },
], [t]);
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ConfirmDeleteModal.tsx b/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ConfirmDeleteModal.tsx
index 801584c1c..a34a569d8 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ConfirmDeleteModal.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ConfirmDeleteModal.tsx
@@ -2,20 +2,24 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import ModalWrapper from '@/entrypoints/popup/components/Dialogs/ModalWrapper';
+import Icon from '@/entrypoints/popup/components/Icons/Icon';
type ConfirmDeleteModalProps = {
isOpen: boolean;
onClose: () => void;
onConfirm: () => void;
title: string;
- message: string;
+ /** The explanation; omit when the warning says it all. */
+ message?: string;
confirmText: string;
+ /** Text shown in an amber warning box under the message. */
warning?: string;
+ /** The confirm button color: red for a destructive action (the default), the brand color otherwise. */
+ variant?: 'danger' | 'primary';
}
/**
- * A reusable confirmation modal for delete actions.
- * Uses the danger styling to indicate a destructive action.
+ * A reusable confirmation modal for actions the user should think twice about, destructive ones by default.
*/
const ConfirmDeleteModal: React.FC<ConfirmDeleteModalProps> = ({
isOpen,
@@ -24,7 +28,8 @@ const ConfirmDeleteModal: React.FC<ConfirmDeleteModalProps> = ({
title,
message,
confirmText,
- warning
+ warning,
+ variant = 'danger'
}) => {
const { t } = useTranslation();
@@ -44,21 +49,24 @@ const ConfirmDeleteModal: React.FC<ConfirmDeleteModalProps> = ({
</button>
<button
onClick={onConfirm}
- className="px-4 py-2 text-sm bg-red-600 text-white rounded hover:bg-red-700"
+ className={`px-4 py-2 text-sm text-white rounded ${variant === 'danger' ? 'bg-red-600 hover:bg-red-700' : 'bg-primary-500 hover:bg-primary-600'}`}
>
{confirmText}
</button>
</div>
}
>
- <p className="text-gray-500 dark:text-gray-400">
- {message}
- </p>
- {warning && (
- <p className="mt-3 p-3 border rounded-md text-sm bg-amber-100 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/40 text-amber-900 dark:text-amber-100">
- {warning}
+ {message && (
+ <p className="text-sm text-gray-500 dark:text-gray-400 whitespace-pre-line">
+ {message}
</p>
)}
+ {warning && (
+ <div className={`flex gap-2 p-3 border rounded-md text-sm bg-amber-100 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/40 text-amber-900 dark:text-amber-100 ${message ? 'mt-3' : ''}`}>
+ <Icon name="exclamation" className="w-5 h-5 shrink-0 text-amber-600 dark:text-amber-400" />
+ <p className="whitespace-pre-line">{warning}</p>
+ </div>
+ )}
</ModalWrapper>
);
};
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ConfirmPasswordModal.tsx b/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ConfirmPasswordModal.tsx
index f39937905..8d45d6aee 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ConfirmPasswordModal.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ConfirmPasswordModal.tsx
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import ModalWrapper from '@/entrypoints/popup/components/Dialogs/ModalWrapper';
+import Icon from '@/entrypoints/popup/components/Icons/Icon';
type ConfirmPasswordModalProps = {
isOpen: boolean;
@@ -10,10 +11,12 @@ type ConfirmPasswordModalProps = {
title: string;
message: string;
confirmText: string;
+ /** The confirm button color: red for a destructive action (the default), the brand color otherwise. */
+ variant?: 'danger' | 'primary';
}
/**
- * A reusable confirmation modal for destructive actions that must be confirmed with the user's master password.
+ * A reusable confirmation modal for actions that must be confirmed with the user's master password.
* The password is handed to the caller for verification; a thrown error is shown inside the modal so the user can retry.
*/
const ConfirmPasswordModal: React.FC<ConfirmPasswordModalProps> = ({
@@ -22,7 +25,8 @@ const ConfirmPasswordModal: React.FC<ConfirmPasswordModalProps> = ({
onConfirm,
title,
message,
- confirmText
+ confirmText,
+ variant = 'danger'
}) => {
const { t } = useTranslation();
const [password, setPassword] = useState('');
@@ -65,9 +69,14 @@ const ConfirmPasswordModal: React.FC<ConfirmPasswordModalProps> = ({
maxWidth="max-w-sm"
>
<form onSubmit={handleSubmit} className="space-y-4">
- <p className="text-gray-500 dark:text-gray-400">
- {message}
- </p>
+ <div className="flex items-start gap-3">
+ <div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-primary-100 dark:bg-primary-900/30">
+ <Icon name="lock-closed" className="h-5 w-5 text-primary-600 dark:text-primary-400" />
+ </div>
+ <p className="text-sm text-gray-500 dark:text-gray-400">
+ {message}
+ </p>
+ </div>
<div>
<label htmlFor="confirm-master-password" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
@@ -99,7 +108,7 @@ const ConfirmPasswordModal: React.FC<ConfirmPasswordModalProps> = ({
<button
type="submit"
disabled={isSubmitting || password.length === 0}
- className="px-4 py-2 text-sm bg-red-600 text-white rounded hover:bg-red-700 disabled:opacity-50"
+ className={`px-4 py-2 text-sm text-white rounded disabled:opacity-50 ${variant === 'danger' ? 'bg-red-600 hover:bg-red-700' : 'bg-primary-500 hover:bg-primary-600'}`}
>
{confirmText}
</button>
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ExportPasswordModal.tsx b/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ExportPasswordModal.tsx
new file mode 100644
index 000000000..5266e9c22
--- /dev/null
+++ b/apps/browser-extension/src/entrypoints/popup/components/Dialogs/ExportPasswordModal.tsx
@@ -0,0 +1,84 @@
+import { MIN_ACCEPTED_PASSWORD_LENGTH } from '@aliasvault/client/utilities/PasswordStrength';
+import React, { useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import ModalWrapper from '@/entrypoints/popup/components/Dialogs/ModalWrapper';
+import Icon from '@/entrypoints/popup/components/Icons/Icon';
+import PasswordStrengthIndicator from '@/entrypoints/popup/components/PasswordStrengthIndicator';
+
+type ExportPasswordModalProps = {
+ isOpen: boolean;
+ onClose: () => void;
+ onSubmit: (exportPassword: string) => void;
+};
+
+/**
+ * Asks for the password an encrypted (.avex) export is protected with.
+ */
+const ExportPasswordModal: React.FC<ExportPasswordModalProps> = ({ isOpen, onClose, onSubmit }) => {
+ const { t } = useTranslation();
+ const [exportPassword, setExportPassword] = useState('');
+ const [confirmPassword, setConfirmPassword] = useState('');
+
+ useEffect(() => {
+ if (isOpen) {
+ setExportPassword('');
+ setConfirmPassword('');
+ }
+ }, [isOpen]);
+
+ const isTooShort = exportPassword.length > 0 && exportPassword.length < MIN_ACCEPTED_PASSWORD_LENGTH;
+ const isMismatch = confirmPassword.length > 0 && exportPassword !== confirmPassword;
+ const isValid = exportPassword.length >= MIN_ACCEPTED_PASSWORD_LENGTH && exportPassword === confirmPassword;
+
+ /**
+ * Hand the password to the caller.
+ * @param event - the form submit event.
+ */
+ const handleSubmit = (event: React.FormEvent): void => {
+ event.preventDefault();
+ if (isValid) {
+ onSubmit(exportPassword);
+ }
+ };
+
+ const inputClassName = 'w-full px-3 py-2 text-sm rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white';
+
+ return (
+ <ModalWrapper isOpen={isOpen} onClose={onClose} title={t('importExport.exportEncryptedPasswordTitle')} maxWidth="max-w-sm">
+ <form onSubmit={handleSubmit} className="space-y-4">
+ <div className="flex items-start gap-3">
+ <div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-primary-100 dark:bg-primary-900/30">
+ <Icon name="upload" className="h-5 w-5 text-primary-600 dark:text-primary-400" />
+ </div>
+ <p className="text-sm text-gray-500 dark:text-gray-400">{t('importExport.exportEncryptedPasswordDescription')}</p>
+ </div>
+
+ <div>
+ <label htmlFor="export-password" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{t('importExport.exportPasswordModal.exportPasswordLabel')}</label>
+ <input id="export-password" type="password" autoFocus autoComplete="new-password" value={exportPassword} onChange={event => setExportPassword(event.target.value)} className={inputClassName} />
+ <PasswordStrengthIndicator password={exportPassword} />
+ </div>
+
+ <div>
+ <label htmlFor="confirm-export-password" className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{t('importExport.exportPasswordModal.confirmExportPasswordLabel')}</label>
+ <input id="confirm-export-password" type="password" autoComplete="new-password" value={confirmPassword} onChange={event => setConfirmPassword(event.target.value)} className={inputClassName} />
+ </div>
+
+ {isTooShort && <p className="text-sm text-red-600 dark:text-red-400">{t('settings.securitySettings.changePassword.passwordTooShort', { minLength: MIN_ACCEPTED_PASSWORD_LENGTH })}</p>}
+ {!isTooShort && isMismatch && <p className="text-sm text-red-600 dark:text-red-400">{t('common.errorPasswordMismatch')}</p>}
+
+ <div className="flex justify-end gap-2">
+ <button type="button" onClick={onClose} className="px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 rounded">
+ {t('common.cancel')}
+ </button>
+ <button id="create-encrypted-export-button" type="submit" disabled={!isValid} className="px-4 py-2 text-sm bg-primary-500 text-white rounded hover:bg-primary-600 disabled:opacity-50">
+ {t('importExport.exportPasswordModal.createEncryptedExportButton')}
+ </button>
+ </div>
+ </form>
+ </ModalWrapper>
+ );
+};
+
+export default ExportPasswordModal;
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/ImportExportSettings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/ImportExportSettings.tsx
new file mode 100644
index 000000000..9cd2cb689
--- /dev/null
+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/ImportExportSettings.tsx
@@ -0,0 +1,183 @@
+import { verifyMasterPassword } from '@aliasvault/client/auth/MasterPasswordCheck';
+import { AvexExportService } from '@aliasvault/client/transfer/export/AvexExportService';
+import { AvuxExportService } from '@aliasvault/client/transfer/export/AvuxExportService';
+import { VAULT_EXPORT_MIME_TYPES, vaultExportFileName, type VaultExportFormat } from '@aliasvault/client/transfer/export/VaultExportFile';
+import { downloadBytes } from '@aliasvault/client/utilities/FileDownload';
+import React, { useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import AlertMessage from '@/entrypoints/popup/components/AlertMessage';
+import Button from '@/entrypoints/popup/components/Button';
+import ConfirmDeleteModal from '@/entrypoints/popup/components/Dialogs/ConfirmDeleteModal';
+import ConfirmPasswordModal from '@/entrypoints/popup/components/Dialogs/ConfirmPasswordModal';
+import ExportPasswordModal from '@/entrypoints/popup/components/Dialogs/ExportPasswordModal';
+import PageTitle from '@/entrypoints/popup/components/PageTitle';
+import { useDb } from '@/entrypoints/popup/context/DbContext';
+import { useLoading } from '@/entrypoints/popup/context/LoadingContext';
+
+import { logFailure } from '@/utils/Diagnostics';
+
+/**
+ * The export options, in the order they are shown.
+ */
+const EXPORT_FORMATS: { format: VaultExportFormat; titleKey: string; descriptionKey: string; buttonKey: string; recommended: boolean }[] = [
+ { format: 'avex', titleKey: 'importExport.exportAvexTitle', descriptionKey: 'importExport.exportAvexDescription', buttonKey: 'importExport.exportAvexButton', recommended: true },
+ { format: 'avux', titleKey: 'importExport.exportAvuxTitle', descriptionKey: 'importExport.exportAvuxDescription', buttonKey: 'importExport.exportAvuxButton', recommended: false },
+ { format: 'csv', titleKey: 'importExport.exportCsvTitle', descriptionKey: 'importExport.exportCsvDescription', buttonKey: 'importExport.exportCsvButton', recommended: false },
+];
+
+/** The steps of an export: the warning, the master password check, then (for .avex) the export password. */
+type ExportStep = 'warning' | 'masterPassword' | 'exportPassword';
+
+/**
+ * The import/export settings page: the vault exports, and a pointer to the web app for imports.
+ */
+const ImportExportSettings: React.FC = () => {
+ const { t } = useTranslation();
+ const dbContext = useDb();
+ const { setIsInitialLoading, showLoading, hideLoading } = useLoading();
+ const [pendingExport, setPendingExport] = useState<{ format: VaultExportFormat; step: ExportStep } | null>(null);
+ const [successMessage, setSuccessMessage] = useState<string | null>(null);
+ const [errorMessage, setErrorMessage] = useState<string | null>(null);
+
+ useEffect(() => {
+ setIsInitialLoading(false);
+ }, [setIsInitialLoading]);
+
+ /**
+ * The export bytes of a format, read from the vault.
+ */
+ const buildExport = async (format: VaultExportFormat, exportPassword: string | null): Promise<Uint8Array> => {
+ const sqliteClient = dbContext.sqliteClient;
+ if (!sqliteClient) {
+ throw new Error('Vault is not available');
+ }
+ if (format === 'csv') {
+ return sqliteClient.importExport.exportToCsv();
+ }
+ const avuxBytes = AvuxExportService.exportToAvux(sqliteClient.importExport.getExportData());
+ return format === 'avux' ? avuxBytes : AvexExportService.encryptToAvex(avuxBytes, exportPassword ?? '');
+ };
+
+ /**
+ * Build the export and hand it to the browser as a download.
+ */
+ const runExport = async (format: VaultExportFormat, exportPassword: string | null): Promise<void> => {
+ setSuccessMessage(null);
+ setErrorMessage(null);
+ showLoading(t('importExport.exportingVaultMessage'));
+ try {
+ downloadBytes(vaultExportFileName(format), await buildExport(format, exportPassword), VAULT_EXPORT_MIME_TYPES[format]);
+ setSuccessMessage(t('importExport.exportSuccessMessage'));
+ } catch (error) {
+ logFailure('Error exporting vault', error);
+ setErrorMessage(t('common.errors.unknownErrorTryAgain'));
+ } finally {
+ hideLoading();
+ }
+ };
+
+ /**
+ * The master password was entered: check it, then export (or ask for the export password first for .avex).
+ */
+ const handleMasterPasswordConfirmed = async (password: string): Promise<void> => {
+ const format = pendingExport?.format;
+ if (!format) {
+ return;
+ }
+
+ let isValid: boolean;
+ try {
+ isValid = await verifyMasterPassword(password);
+ } catch (error) {
+ logFailure('Error verifying master password', error);
+ throw new Error(t('importExport.passwordVerificationFailed'));
+ }
+ if (!isValid) {
+ throw new Error(t('importExport.passwordIncorrect'));
+ }
+
+ if (format === 'avex') {
+ setPendingExport({ format, step: 'exportPassword' });
+ return;
+ }
+
+ setPendingExport(null);
+ await runExport(format, null);
+ };
+
+ /**
+ * The export password was entered: create the .avex export.
+ */
+ const handleExportPasswordSubmitted = async (exportPassword: string): Promise<void> => {
+ setPendingExport(null);
+ await runExport('avex', exportPassword);
+ };
+
+ const pendingFormat = pendingExport?.format ?? null;
+
+ return (
+ <div className="space-y-6">
+ <PageTitle>{t('settings.importExport')}</PageTitle>
+
+ {successMessage && <AlertMessage type="success" message={successMessage} />}
+ {errorMessage && <AlertMessage type="error" message={errorMessage} />}
+
+ <section>
+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-4">
+ <p className="font-medium text-gray-900 dark:text-white mb-2">{t('settings.importSectionTitle')}</p>
+ <p className="text-sm text-gray-600 dark:text-gray-400">{t('settings.importWebNote')}</p>
+ </div>
+ </section>
+
+ <section>
+ <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-4 space-y-3">
+ <div>
+ <p className="font-medium text-gray-900 dark:text-white mb-2">{t('settings.exportSectionTitle')}</p>
+ <p className="text-sm text-gray-600 dark:text-gray-400">{t('importExport.exportSectionDescription')}</p>
+ </div>
+
+ {EXPORT_FORMATS.map(option => (
+ <div key={option.format} className={`p-3 rounded-lg border ${option.recommended ? 'border-2 border-amber-300 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-500/10' : 'border-gray-200 dark:border-gray-700'}`}>
+ <div className="flex items-center gap-2 mb-1">
+ <p className="text-sm font-semibold text-gray-900 dark:text-white">{t(option.titleKey)}</p>
+ {option.recommended && <span className="px-1.5 py-0.5 text-xs font-medium text-amber-900 dark:text-amber-100 bg-amber-100 dark:bg-amber-500/20 rounded">{t('importExport.recommendedLabel')}</span>}
+ </div>
+ <p className="text-sm text-gray-600 dark:text-gray-300 mb-3">{t(option.descriptionKey)}</p>
+ <Button id={`export-${option.format}-button`} onClick={() => setPendingExport({ format: option.format, step: 'warning' })}>{t(option.buttonKey)}</Button>
+ </div>
+ ))}
+ </div>
+ </section>
+
+ <ConfirmDeleteModal
+ isOpen={pendingExport?.step === 'warning'}
+ onClose={() => setPendingExport(null)}
+ onConfirm={() => setPendingExport(pendingFormat ? { format: pendingFormat, step: 'masterPassword' } : null)}
+ title={t('settings.exportConfirmTitle')}
+ message={pendingFormat === 'avex' ? t('importExport.exportEncryptedWarningMessage') : undefined}
+ warning={pendingFormat === 'avex' ? undefined : t('importExport.exportWarningMessage')}
+ confirmText={t('common.confirm')}
+ variant={pendingFormat === 'avex' ? 'primary' : 'danger'}
+ />
+
+ <ConfirmPasswordModal
+ isOpen={pendingExport?.step === 'masterPassword'}
+ onClose={() => setPendingExport(null)}
+ onConfirm={handleMasterPasswordConfirmed}
+ title={t('importExport.exportPasswordConfirmTitle')}
+ message={t('settings.passwordConfirm.exportDescription')}
+ confirmText={t('common.confirm')}
+ variant="primary"
+ />
+
+ <ExportPasswordModal
+ isOpen={pendingExport?.step === 'exportPassword'}
+ onClose={() => setPendingExport(null)}
+ onSubmit={exportPassword => void handleExportPasswordSubmitted(exportPassword)}
+ />
+ </div>
+ );
+};
+
+export default ImportExportSettings;
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx b/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx
index 44782786f..277d8f38f 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/settings/Settings.tsx
@@ -296,6 +296,15 @@ const Settings: React.FC = () => {
/>
</SettingsGroup>
+ <SettingsGroup title={t('navigation.vault')}>
+ <SettingsRow
+ id="import-export-settings-button"
+ label={t('settings.importExport')}
+ onClick={() => navigate('/settings/import-export')}
+ icon="switch-horizontal"
+ />
+ </SettingsGroup>
+
<SettingsGroup title={t('settings.groups.general')}>
<SettingsRow
label={t('settings.appearance')}
diff --git a/apps/web/src/utils/MasterPasswordCheck.ts b/core/client/src/auth/MasterPasswordCheck.ts
similarity index 79%
rename from apps/web/src/utils/MasterPasswordCheck.ts
rename to core/client/src/auth/MasterPasswordCheck.ts
index 415e1ad72..9d8c497d7 100644
--- a/apps/web/src/utils/MasterPasswordCheck.ts
+++ b/core/client/src/auth/MasterPasswordCheck.ts
@@ -1,6 +1,7 @@
-import { extractErrorCode } from '@aliasvault/client/api/errors/AppErrorCodes';
-import { MissingDerivationParamsError, UnlockService } from '@aliasvault/client/auth/UnlockService';
-import { VaultKeyService } from '@aliasvault/client/auth/VaultKeyService';
+import { extractErrorCode } from '../api/errors/AppErrorCodes';
+
+import { MissingDerivationParamsError, UnlockService } from './UnlockService';
+import { VaultKeyService } from './VaultKeyService';
/**
* Check the master password offline against the cached key chain, the same way an offline unlock does.
diff --git a/core/client/src/database/index.ts b/core/client/src/database/index.ts
index 304629dcb..d51faa4eb 100644
--- a/core/client/src/database/index.ts
+++ b/core/client/src/database/index.ts
@@ -23,5 +23,6 @@ export { SettingsRepository } from './repositories/SettingsRepository';
export { EncryptionKeyRepository } from './repositories/EncryptionKeyRepository';
export { LogoRepository } from './repositories/LogoRepository';
export { ItemStatsRepository, type ItemUsageAction } from './repositories/ItemStatsRepository';
-export { ImportExportRepository, type VaultExportData } from './repositories/ImportExportRepository';
+export { ImportExportRepository } from './repositories/ImportExportRepository';
+export type { VaultExportData } from '../transfer/shared/VaultEntities';
export { StorageInsightsRepository, type StorageCounts, type AttachmentSizeRow, type LogoSizeRow } from './repositories/StorageInsightsRepository';
diff --git a/core/client/src/database/repositories/ImportExportRepository.ts b/core/client/src/database/repositories/ImportExportRepository.ts
index 3124e870f..17ee3eefc 100644
--- a/core/client/src/database/repositories/ImportExportRepository.ts
+++ b/core/client/src/database/repositories/ImportExportRepository.ts
@@ -6,22 +6,11 @@ import { BaseRepository } from '../BaseRepository';
import { scopedKey } from '../ItemRef';
import { AttachmentQueries, FieldDefinitionQueries, FieldHistoryQueries, FieldValueQueries, TotpCodeQueries } from '../queries/ItemQueries';
-import type { AttachmentEntity, FieldDefinitionEntity, FieldHistoryEntity, FieldValueEntity, FolderEntity, ItemEntity, ItemTagEntity, LogoEntity, PasskeyEntity, TagEntity, TotpCodeEntity } from '../../transfer/shared/VaultEntities';
+import type { AttachmentEntity, FieldDefinitionEntity, FieldHistoryEntity, FieldValueEntity, FolderEntity, ItemEntity, ItemTagEntity, LogoEntity, PasskeyEntity, TagEntity, TotpCodeEntity, VaultExportData } from '../../transfer/shared/VaultEntities';
import type { IDatabaseClient } from '../BaseRepository';
import type { DbOp } from '../DbOp';
import type { LogoRepository } from './LogoRepository';
-/**
- * Everything a full vault export carries.
- */
-export type VaultExportData = {
- items: ItemEntity[];
- folders: FolderEntity[];
- tags: TagEntity[];
- itemTags: ItemTagEntity[];
- fieldDefinitions: FieldDefinitionEntity[];
-};
-
/**
* Keep track of what the import already wrote (shared and reused parent objects).
*/
diff --git a/core/client/src/rust/RustCoreBinding.ts b/core/client/src/rust/RustCoreBinding.ts
index 469932680..868fa848c 100644
--- a/core/client/src/rust/RustCoreBinding.ts
+++ b/core/client/src/rust/RustCoreBinding.ts
@@ -47,6 +47,7 @@ export interface IRustCore {
symmetricDecrypt(base64Ciphertext: string, keyBase64: string): Promise<string>;
symmetricDecryptBytes(encrypted: Uint8Array, keyBase64: string): Promise<Uint8Array>;
+ symmetricEncryptBytes(plaintext: Uint8Array, keyBase64: string): Promise<Uint8Array>;
rsaDecrypt(base64Ciphertext: string, privateKeyJwk: string): Promise<Uint8Array>;
pinGenerateSalt(): Promise<Uint8Array>;
diff --git a/core/client/src/rust/WasmRustCore.ts b/core/client/src/rust/WasmRustCore.ts
index eef58b3fe..edf12e24a 100644
--- a/core/client/src/rust/WasmRustCore.ts
+++ b/core/client/src/rust/WasmRustCore.ts
@@ -72,6 +72,7 @@ export function createWasmRustCore(loadWasm: WasmLoader): IRustCore {
symmetricDecrypt: (base64Ciphertext, keyBase64): Promise<string> => ready(() => core.symmetricDecrypt(base64Ciphertext, keyBase64)),
symmetricDecryptBytes: (encrypted, keyBase64): Promise<Uint8Array> => ready(() => core.symmetricDecryptBytes(encrypted, keyBase64)),
+ symmetricEncryptBytes: (plaintext, keyBase64): Promise<Uint8Array> => ready(() => core.symmetricEncryptBytes(plaintext, keyBase64)),
rsaDecrypt: (base64Ciphertext, privateKeyJwk): Promise<Uint8Array> => ready(() => core.rsaDecrypt(base64Ciphertext, privateKeyJwk)),
/*
diff --git a/core/client/src/transfer/export/AvexExportService.ts b/core/client/src/transfer/export/AvexExportService.ts
index 372eea2ff..430ae44df 100644
--- a/core/client/src/transfer/export/AvexExportService.ts
+++ b/core/client/src/transfer/export/AvexExportService.ts
@@ -1,7 +1,6 @@
-import { EncryptionUtility } from '../../crypto/EncryptionUtility';
import { AppInfo } from '../../platform/AppInfo';
-import { argon2DeriveKey } from '../../rust/RustCore';
-import { base64ToBytes, bytesToBase64 } from '../../utilities/Base64';
+import { argon2DeriveKey, rustCore } from '../../rust/RustCore';
+import { bytesToBase64 } from '../../utilities/Base64';
import { AvexConstants } from './AvexConstants';
@@ -33,7 +32,7 @@ export class AvexExportService {
const key = await argon2DeriveKey(exportPassword, saltBase64, JSON.stringify(ARGON2_KDF_PARAMS));
// 2. AES-256-GCM over the .avux bytes.
- const encryptedPayload = base64ToBytes(await EncryptionUtility.symmetricEncryptBytes(avuxBytes, bytesToBase64(key)));
+ const encryptedPayload = await rustCore().symmetricEncryptBytes(avuxBytes, bytesToBase64(key));
// 3. The header.
const header: AvexHeader = {
diff --git a/core/client/src/transfer/export/AvuxExportService.ts b/core/client/src/transfer/export/AvuxExportService.ts
index 59d2987b9..b5ae5783d 100644
--- a/core/client/src/transfer/export/AvuxExportService.ts
+++ b/core/client/src/transfer/export/AvuxExportService.ts
@@ -2,7 +2,7 @@ import { bytesToBase64 } from '../../utilities/Base64';
import { createZipArchive, textToZipBytes } from '../shared/ZipArchive';
import type { AvuxAttachment, AvuxFieldDefinition, AvuxFieldHistory, AvuxFieldValue, AvuxFolder, AvuxItem, AvuxItemTag, AvuxLogo, AvuxManifest, AvuxPasskey, AvuxTag, AvuxTotpCode } from './AvuxManifest';
-import type { AttachmentEntity, FieldDefinitionEntity, FieldHistoryEntity, FieldValueEntity, FolderEntity, ItemEntity, ItemTagEntity, LogoEntity, PasskeyEntity, TagEntity, TotpCodeEntity } from '../shared/VaultEntities';
+import type { AttachmentEntity, FieldDefinitionEntity, FieldHistoryEntity, FieldValueEntity, FolderEntity, ItemEntity, ItemTagEntity, LogoEntity, PasskeyEntity, TagEntity, TotpCodeEntity, VaultExportData } from '../shared/VaultEntities';
/** The .avux manifest format version this service writes. */
export const AVUX_FORMAT_VERSION = '1.0.0';
@@ -14,14 +14,11 @@ export const AVUX_FORMAT_VERSION = '1.0.0';
export class AvuxExportService {
/**
* Export vault data to .avux.
- * @param items - The items to export
- * @param folders - The folders to export
- * @param tags - The tags to export
- * @param itemTags - The item-tag associations to export
- * @param fieldDefinitions - The custom field definitions to export
+ * @param data - The vault data to export
* @returns The .avux ZIP file bytes
*/
- public static exportToAvux(items: ItemEntity[], folders: FolderEntity[], tags: TagEntity[], itemTags: ItemTagEntity[], fieldDefinitions: FieldDefinitionEntity[]): Uint8Array {
+ public static exportToAvux(data: VaultExportData): Uint8Array {
+ const { items, folders, tags, itemTags, fieldDefinitions } = data;
const logos = AvuxExportService.itemLogos(items);
const manifest = AvuxExportService.createManifest(items, folders, tags, itemTags, fieldDefinitions, logos);
const attachmentMap = AvuxExportService.extractAttachments(items);
diff --git a/core/client/src/transfer/export/VaultExportFile.ts b/core/client/src/transfer/export/VaultExportFile.ts
new file mode 100644
index 000000000..4f3f05ea4
--- /dev/null
+++ b/core/client/src/transfer/export/VaultExportFile.ts
@@ -0,0 +1,20 @@
+/**
+ * The vault export file formats.
+ */
+export type VaultExportFormat = 'csv' | 'avux' | 'avex';
+
+/** The content type each export format is handed to the host with. */
+export const VAULT_EXPORT_MIME_TYPES: Record<VaultExportFormat, string> = {
+ csv: 'text/csv',
+ avux: 'application/zip',
+ avex: 'application/octet-stream',
+};
+
+/**
+ * The file name of a vault export made today, e.g. `aliasvault-export-2026-10-19.avex`.
+ * @param format - The export format
+ * @returns The file name
+ */
+export function vaultExportFileName(format: VaultExportFormat): string {
+ return `aliasvault-export-${new Date().toISOString().substring(0, 10)}.${format}`;
+}
diff --git a/core/client/src/transfer/export/__tests__/AvuxExportService.test.ts b/core/client/src/transfer/export/__tests__/AvuxExportService.test.ts
index 869e2bdbc..4c60d9a14 100644
--- a/core/client/src/transfer/export/__tests__/AvuxExportService.test.ts
+++ b/core/client/src/transfer/export/__tests__/AvuxExportService.test.ts
@@ -24,7 +24,7 @@ describe('AvuxExportService', () => {
const tags: TagEntity[] = [{ Id: crypto.randomUUID(), Name: 'Test Tag', Color: '#FF0000', DisplayOrder: 0, CreatedAt: new Date(), UpdatedAt: new Date(), IsDeleted: false }];
const itemTags: ItemTagEntity[] = [{ ItemId: items[0].Id, TagId: tags[0].Id, IsDeleted: false }];
- const avuxBytes = AvuxExportService.exportToAvux(items, folders, tags, itemTags, []);
+ const avuxBytes = AvuxExportService.exportToAvux({ items, folders, tags, itemTags, fieldDefinitions: [] });
expect(avuxBytes.length).toBeGreaterThan(0);
diff --git a/core/client/src/transfer/export/__tests__/testHelpers.ts b/core/client/src/transfer/export/__tests__/testHelpers.ts
index 615186fb0..a499c411c 100644
--- a/core/client/src/transfer/export/__tests__/testHelpers.ts
+++ b/core/client/src/transfer/export/__tests__/testHelpers.ts
@@ -117,5 +117,5 @@ export function addAttachment(item: ItemEntity, filename: string, content: strin
* @returns The .avux bytes
*/
export function exportItems(items: ItemEntity[], fieldDefinitions: FieldDefinitionEntity[] = []): Uint8Array {
- return AvuxExportService.exportToAvux(items, [], [], [], fieldDefinitions);
+ return AvuxExportService.exportToAvux({ items, folders: [], tags: [], itemTags: [], fieldDefinitions });
}
diff --git a/core/client/src/transfer/import/importers/aliasvault/AvexImportService.ts b/core/client/src/transfer/import/importers/aliasvault/AvexImportService.ts
index ba3152629..d249cf823 100644
--- a/core/client/src/transfer/import/importers/aliasvault/AvexImportService.ts
+++ b/core/client/src/transfer/import/importers/aliasvault/AvexImportService.ts
@@ -1,5 +1,4 @@
-import { EncryptionUtility } from '../../../../crypto/EncryptionUtility';
-import { argon2DeriveKey } from '../../../../rust/RustCore';
+import { argon2DeriveKey, rustCore } from '../../../../rust/RustCore';
import { bytesToBase64 } from '../../../../utilities/Base64';
import { AvexConstants } from '../../../export/AvexConstants';
import { getProperty, isJsonObject, parseJson, readNumber, readObject, readString, requireObject } from '../../readers/JsonReader';
@@ -49,7 +48,7 @@ export class AvexImportService {
const key = await argon2DeriveKey(exportPassword, header.kdf.salt, JSON.stringify(header.kdf.params));
try {
- return await EncryptionUtility.symmetricDecryptBytes(encryptedPayload, bytesToBase64(key));
+ return await rustCore().symmetricDecryptBytes(encryptedPayload, bytesToBase64(key));
} catch (error) {
throw new AvexDecryptionError(error);
}
diff --git a/core/client/src/transfer/shared/VaultEntities.ts b/core/client/src/transfer/shared/VaultEntities.ts
index c32b5a04f..1b96216b8 100644
--- a/core/client/src/transfer/shared/VaultEntities.ts
+++ b/core/client/src/transfer/shared/VaultEntities.ts
@@ -167,3 +167,14 @@ export type LogoEntity = {
FetchedAt: Date | null;
IsDeleted: boolean;
};
+
+/**
+ * Everything a full vault export carries.
+ */
+export type VaultExportData = {
+ items: ItemEntity[];
+ folders: FolderEntity[];
+ tags: TagEntity[];
+ itemTags: ItemTagEntity[];
+ fieldDefinitions: FieldDefinitionEntity[];
+};
diff --git a/core/rust/src/bindings/uniffi_api.rs b/core/rust/src/bindings/uniffi_api.rs
index 211f84c8e..2a47b7fa4 100644
--- a/core/rust/src/bindings/uniffi_api.rs
+++ b/core/rust/src/bindings/uniffi_api.rs
@@ -199,6 +199,12 @@ pub fn symmetric_decrypt_bytes(encrypted: Vec<u8>, key_base64: String) -> Result
crate::crypto::symmetric_decrypt_bytes(&encrypted, &key_base64)
}
+/// AES-256-GCM encrypt bytes with a base64 key (random IV, no AAD) into `IV | ciphertext | tag` bytes.
+#[uniffi::export]
+pub fn symmetric_encrypt_bytes(plaintext: Vec<u8>, key_base64: String) -> Result<Vec<u8>, VaultError> {
+ crate::crypto::symmetric_encrypt_raw_with_aad(&plaintext, &key_base64, &[])
+}
+
/// A fresh random salt for a new PIN wrap.
#[uniffi::export]
pub fn pin_generate_salt() -> Vec<u8> {
diff --git a/core/rust/src/bindings/wasm.rs b/core/rust/src/bindings/wasm.rs
index 1d99a3434..286f3200c 100644
--- a/core/rust/src/bindings/wasm.rs
+++ b/core/rust/src/bindings/wasm.rs
@@ -210,6 +210,12 @@ pub fn symmetric_decrypt_bytes_js(encrypted: &[u8], key_base64: &str) -> Result<
crate::crypto::symmetric_decrypt_bytes(encrypted, key_base64).map_err(js_err)
}
+/// AES-256-GCM encrypt bytes with a base64 key (random IV, no AAD) into `IV | ciphertext | tag` bytes.
+#[wasm_bindgen(js_name = symmetricEncryptBytes)]
+pub fn symmetric_encrypt_bytes_js(plaintext: &[u8], key_base64: &str) -> Result<Vec<u8>, JsValue> {
+ crate::crypto::symmetric_encrypt_raw_with_aad(plaintext, key_base64, &[]).map_err(js_err)
+}
+
/// RSA-OAEP-256 decrypt base64 ciphertext with a JWK private key.
#[wasm_bindgen(js_name = rsaDecrypt)]
pub fn rsa_decrypt_js(base64_ciphertext: &str, private_key_jwk: &str) -> Result<Vec<u8>, JsValue> {