Skip to content

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

Update browser extension package config (#2159)

Leendert de Borstb6bd0cadaa04
diff --git a/apps/browser-extension/package-lock.json b/apps/browser-extension/package-lock.json
index 882ae1e63..3c4d34c1d 100644
--- a/apps/browser-extension/package-lock.json
+++ b/apps/browser-extension/package-lock.json
@@ -9,6 +9,9 @@
"version": "0.31.0",
"hasInstallScript": true,
"dependencies": {
+ "@aliasvault/client": "file:../../core/client",
+ "@aliasvault/models": "file:../../core/models",
+ "@aliasvault/vault": "file:../../core/vault",
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
@@ -26,7 +29,6 @@
"react-hook-form": "^7.57.0",
"react-i18next": "^17.0.8",
"react-router-dom": "^7.18.1",
- "sql.js": "^1.12.0",
"vitest": "^4.1.8",
"yup": "^1.6.1"
},
@@ -39,7 +41,6 @@
"@types/qrcode": "^1.5.6",
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
- "@types/sql.js": "^1.4.9",
"@types/yup": "^0.29.14",
"@typescript-eslint/eslint-plugin": "^8.65.0",
"@typescript-eslint/parser": "^8.65.0",
@@ -62,6 +63,58 @@
"wxt": "^0.21.3"
}
},
+ "../../core/client": {
+ "name": "@aliasvault/client",
+ "version": "1.0.0",
+ "license": "AGPL-3.0",
+ "dependencies": {
+ "@aliasvault/models": "file:../models",
+ "@aliasvault/vault": "file:../vault",
+ "otpauth": "^9.3.6",
+ "sql.js": "^1.12.0"
+ },
+ "devDependencies": {
+ "@types/sql.js": "^1.4.9",
+ "@typescript-eslint/eslint-plugin": "^8.65.0",
+ "@typescript-eslint/parser": "^8.65.0",
+ "eslint": "^9.39.5",
+ "eslint-import-resolver-typescript": "^4.4.3",
+ "eslint-plugin-import": "^2.31.0",
+ "eslint-plugin-jsdoc": "^50.6.3",
+ "globals": "^16.5.0",
+ "typescript": "^5.6.3",
+ "vitest": "^4.1.8"
+ }
+ },
+ "../../core/models": {
+ "name": "@aliasvault/models",
+ "version": "1.0.0",
+ "license": "AGPL-3.0",
+ "devDependencies": {
+ "@typescript-eslint/eslint-plugin": "^8.21.0",
+ "@typescript-eslint/parser": "^8.21.0",
+ "eslint": "^9.19.0",
+ "tsup": "^8.4.0",
+ "typescript": "^5.3.3",
+ "vitest": "^4.1.8"
+ }
+ },
+ "../../core/vault": {
+ "name": "@aliasvault/vault",
+ "version": "1.0.0",
+ "license": "AGPL-3.0",
+ "devDependencies": {
+ "@types/sql.js": "^1.4.11",
+ "@typescript-eslint/eslint-plugin": "^8.21.0",
+ "@typescript-eslint/parser": "^8.21.0",
+ "@vitest/coverage-v8": "^4.1.8",
+ "eslint": "^9.19.0",
+ "sql.js": "^1.14.2",
+ "tsup": "^8.4.0",
+ "typescript": "^5.3.3",
+ "vitest": "^4.1.8"
+ }
+ },
"node_modules/@1natsu/wait-element": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/@1natsu/wait-element/-/wait-element-4.1.2.tgz",
@@ -170,6 +223,18 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@aliasvault/client": {
+ "resolved": "../../core/client",
+ "link": true
+ },
+ "node_modules/@aliasvault/models": {
+ "resolved": "../../core/models",
+ "link": true
+ },
+ "node_modules/@aliasvault/vault": {
+ "resolved": "../../core/vault",
+ "link": true
+ },
"node_modules/@alloc/quick-lru": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/@alloc/quick-lru/-/quick-lru-5.2.0.tgz",
@@ -842,12 +907,12 @@
}
},
"node_modules/@noble/hashes": {
- "version": "1.7.1",
- "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.7.1.tgz",
- "integrity": "sha512-B8XBPsn4vT/KJAGqDzbwztd+6Yte3P4V7iafm24bxgDe/mlRuK6xmWPuCNrKt2vDafZ8MfJLlchDG/vYafQEjQ==",
+ "version": "2.4.0",
+ "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.4.0.tgz",
+ "integrity": "sha512-X5XaVWZIBCT7HHZGm5I7ZQXDwLG+bGXuSrMQAW+7Zvl87h1kmc1ZB1VSRJcpUfoUrGQp4Fkoxm5kZ+Ms+aW+eA==",
"license": "MIT",
"engines": {
- "node": "^14.21.3 || >=16"
+ "node": ">= 20.19.0"
},
"funding": {
"url": "https://paulmillr.com/funding/"
@@ -1350,13 +1415,6 @@
"@types/trusted-types": "*"
}
},
- "node_modules/@types/emscripten": {
- "version": "1.40.1",
- "resolved": "https://registry.npmjs.org/@types/emscripten/-/emscripten-1.40.1.tgz",
- "integrity": "sha512-sr53lnYkQNhjHNN0oJDdUm5564biioI5DuOpycufDVK7D3y+GR3oUswe2rlwY1nPNyusHbrJ9WoTyIHl4/Bpwg==",
- "dev": true,
- "license": "MIT"
- },
"node_modules/@types/estree": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
@@ -1453,17 +1511,6 @@
"@types/react": "^19.0.0"
}
},
- "node_modules/@types/sql.js": {
- "version": "1.4.9",
- "resolved": "https://registry.npmjs.org/@types/sql.js/-/sql.js-1.4.9.tgz",
- "integrity": "sha512-ep8b36RKHlgWPqjNG9ToUrPiwkhwh0AEzy883mO5Xnd+cL6VBH1EvSjBAAuxLUFF2Vn/moE3Me6v9E1Lo+48GQ==",
- "dev": true,
- "license": "MIT",
- "dependencies": {
- "@types/emscripten": "*",
- "@types/node": "*"
- }
- },
"node_modules/@types/tough-cookie": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz",
@@ -6836,12 +6883,12 @@
}
},
"node_modules/otpauth": {
- "version": "9.4.0",
- "resolved": "https://registry.npmjs.org/otpauth/-/otpauth-9.4.0.tgz",
- "integrity": "sha512-fHIfzIG5RqCkK9cmV8WU+dPQr9/ebR5QOwGZn2JAr1RQF+lmAuLL2YdtdqvmBjNmgJlYk3KZ4a0XokaEhg1Jsw==",
+ "version": "9.5.2",
+ "resolved": "https://registry.npmjs.org/otpauth/-/otpauth-9.5.2.tgz",
+ "integrity": "sha512-GQ5emWR/x1tcExT62IBT0UfO95wZzJZyxYOJOGVeQF47SYEN9vmh0vISvDZaNMuFJRG+IaWCKtfm+t9Bfoal6w==",
"license": "MIT",
"dependencies": {
- "@noble/hashes": "1.7.1"
+ "@noble/hashes": "2.4.0"
},
"funding": {
"url": "https://github.com/hectorm/otpauth?sponsor=1"
@@ -8367,12 +8414,6 @@
"dev": true,
"license": "CC0-1.0"
},
- "node_modules/sql.js": {
- "version": "1.13.0",
- "resolved": "https://registry.npmjs.org/sql.js/-/sql.js-1.13.0.tgz",
- "integrity": "sha512-RJbVP1HRDlUUXahJ7VMTcu9Rm1Nzw+EBpoPr94vnbD4LwR715F3CcxE2G2k45PewcaZ57pjetYa+LoSJLAASgA==",
- "license": "MIT"
- },
"node_modules/stable-hash-x": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/stable-hash-x/-/stable-hash-x-0.1.1.tgz",
diff --git a/apps/browser-extension/package.json b/apps/browser-extension/package.json
index de1fe2006..71349cfc8 100644
--- a/apps/browser-extension/package.json
+++ b/apps/browser-extension/package.json
@@ -29,6 +29,9 @@
"postinstall": "wxt prepare"
},
"dependencies": {
+ "@aliasvault/client": "file:../../core/client",
+ "@aliasvault/models": "file:../../core/models",
+ "@aliasvault/vault": "file:../../core/vault",
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
@@ -46,7 +49,6 @@
"react-hook-form": "^7.57.0",
"react-i18next": "^17.0.8",
"react-router-dom": "^7.18.1",
- "sql.js": "^1.12.0",
"vitest": "^4.1.8",
"yup": "^1.6.1"
},
@@ -59,7 +61,6 @@
"@types/qrcode": "^1.5.6",
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
- "@types/sql.js": "^1.4.9",
"@types/yup": "^0.29.14",
"@typescript-eslint/eslint-plugin": "^8.65.0",
"@typescript-eslint/parser": "^8.65.0",
diff --git a/apps/browser-extension/src/platform/ClientServices.ts b/apps/browser-extension/src/platform/ClientServices.ts
new file mode 100644
index 000000000..e7bdd3a43
--- /dev/null
+++ b/apps/browser-extension/src/platform/ClientServices.ts
@@ -0,0 +1,17 @@
+/**
+ * Registers the extension platform with the client core.
+ */
+
+import { setPlatform } from '@aliasvault/client/platform';
+import { VaultMergeService } from '@aliasvault/client/sync/VaultMergeService';
+import { VaultSyncService } from '@aliasvault/client/sync/VaultSyncService';
+
+import { extensionPlatform } from '@/platform/ExtensionPlatform';
+
+setPlatform(extensionPlatform);
+
+/** The vault sync service. */
+export const vaultSyncService = new VaultSyncService();
+
+/** The legacy sqlite-blob merge and trash pruning service. TODO: remove this when old sqlite-blob support is removed. */
+export const vaultMergeService = new VaultMergeService();
diff --git a/apps/browser-extension/src/platform/ExtensionPlatform.ts b/apps/browser-extension/src/platform/ExtensionPlatform.ts
new file mode 100644
index 000000000..ca4b76f49
--- /dev/null
+++ b/apps/browser-extension/src/platform/ExtensionPlatform.ts
@@ -0,0 +1,112 @@
+/**
+ * The browser extension's implementations of the client core's platform interfaces (e.g. storage, logger, etc.) which are different per platform.
+ */
+
+import { type IClientPlatform, type IKeyValueStore, type StorageKey, TranslatableMessage } from '@aliasvault/client/platform';
+import { browser } from 'wxt/browser';
+
+import { devError, devLog, devWarn } from '@/utils/devLogger/DevLogger';
+import { readLegacyStorageFallback } from '@/utils/legacy/LegacyStorageKeyFallbacks';
+
+import { t } from '@/i18n/StandaloneI18n';
+
+import { storage } from '#imports';
+
+/**
+ * The current extension version. This should be updated with each release of the extension.
+ */
+export const EXTENSION_VERSION = '0.31.0-alpha';
+
+/**
+ * The client name to use in the X-AliasVault-Client header, detected from the WXT build target.
+ */
+function detectClientName(): 'chrome' | 'firefox' | 'edge' | 'safari' | 'browser' {
+ const env = import.meta.env;
+ if (env.FIREFOX) {
+ return 'firefox';
+ }
+ if (env.CHROME) {
+ return 'chrome';
+ }
+ if (env.EDGE) {
+ return 'edge';
+ }
+ if (env.SAFARI) {
+ return 'safari';
+ }
+ return 'browser';
+}
+
+/**
+ * Which translation key backs each of the core's own messages.
+ * TODO: refactor this to use centralized translation system instead (on to-do list) once that is implemented.
+ */
+const TRANSLATION_KEYS: Record<TranslatableMessage, string> = {
+ [TranslatableMessage.UnnamedSharedVault]: 'sharing.family.unnamedVault',
+ [TranslatableMessage.ClientOutdated]: 'common.errors.browserExtensionOutdated',
+ [TranslatableMessage.SharedFolderDeleteRefused]: 'items.deleteSharedFolderHint',
+};
+
+/**
+ * WXT storage.
+ */
+const extensionStorage: IKeyValueStore = {
+ /**
+ * Read a key, falling back to its legacy location.
+ */
+ get: async <T,>(key: StorageKey): Promise<T | null> => {
+ const value = await storage.getItem<T>(key);
+ if (value !== null) {
+ return value;
+ }
+ return readLegacyStorageFallback<T>(key);
+ },
+ /**
+ * Write a key.
+ */
+ set: (key: StorageKey, value: unknown): Promise<void> => storage.setItem(key, value),
+ /**
+ * Write several keys.
+ */
+ setMany: (entries: { key: StorageKey; value: unknown }[]): Promise<void> => storage.setItems(entries),
+ /**
+ * Remove a key.
+ */
+ remove: (key: StorageKey): Promise<void> => storage.removeItem(key),
+ /**
+ * Remove several keys.
+ */
+ removeMany: (keys: StorageKey[]): Promise<void> => storage.removeItems(keys),
+ /**
+ * Watch a key.
+ */
+ watch: <T,>(key: StorageKey, callback: (value: T | null) => void): (() => void) => storage.watch<T>(key, (value) => callback(value)),
+};
+
+/**
+ * The platform the extension registers with the client core.
+ */
+export const extensionPlatform: IClientPlatform = {
+ storage: extensionStorage,
+ logger: { log: devLog, warn: devWarn, error: devError },
+ app: {
+ version: EXTENSION_VERSION,
+ clientName: detectClientName(),
+ isDevelopment: import.meta.env.DEV,
+ },
+ /**
+ * Fetch the bundled Rust core binary.
+ */
+ loadRustCoreWasm: async (): Promise<BufferSource> => {
+ const wasmUrl = (browser.runtime.getURL as (path: string) => string)('src/aliasvault_core_bg.wasm');
+ return (await fetch(wasmUrl)).arrayBuffer();
+ },
+ /**
+ * Locate the sql.js support file.
+ */
+ locateSqlJsFile: (file: string): string => `src/${file}`,
+ /**
+ * Resolve a core message.
+ */
+ translate: (message: TranslatableMessage): Promise<string> => t(TRANSLATION_KEYS[message]),
+};
diff --git a/apps/browser-extension/wxt.config.ts b/apps/browser-extension/wxt.config.ts
index f823be6a9..87c189bc0 100644
--- a/apps/browser-extension/wxt.config.ts
+++ b/apps/browser-extension/wxt.config.ts
@@ -1,3 +1,5 @@
+import path from 'node:path';
+
import { defineConfig } from 'wxt';
import type { Plugin } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy';
@@ -29,6 +31,8 @@ function asciiOnlyJsPlugin(): Plugin {
};
}
+const CORE_DIR = path.resolve(import.meta.dirname, '../../core');
+
// See https://wxt.dev/api/config.html
export default defineConfig({
manifest: ({ browser, manifestVersion, mode, command }) => {
@@ -78,7 +82,7 @@ export default defineConfig({
web_accessible_resources: [{
resources: [
"webauthn.js",
- "src/sql-wasm.wasm",
+ "src/sql-wasm-browser.wasm",
"src/aliasvault_core_bg.wasm"
],
matches: ["<all_urls>"]
@@ -96,19 +100,26 @@ export default defineConfig({
srcDir: 'src',
outDir: 'dist',
vite: () => ({
+ // Allow to serve files from the shared core directory
+ server: {
+ fs: {
+ allow: [path.resolve('.'), CORE_DIR],
+ },
+ },
optimizeDeps: {
entries: ['src/**/*.html', 'public/**/*.html'],
+ exclude: ['@aliasvault/client', '@aliasvault/models', '@aliasvault/vault'],
},
plugins: [
asciiOnlyJsPlugin(),
viteStaticCopy({
targets: [
{
- src: 'node_modules/sql.js/dist/sql-wasm.wasm',
+ src: path.resolve(CORE_DIR, 'client/node_modules/sql.js/dist/sql-wasm-browser.wasm'),
dest: 'src'
},
{
- src: 'src/utils/dist/core/rust/aliasvault_core_bg.wasm',
+ src: path.resolve(CORE_DIR, 'client/wasm/aliasvault_core_bg.wasm'),
dest: 'src'
}
]
@@ -116,17 +127,27 @@ export default defineConfig({
],
}),
zip: {
- includeSources: ['**/*'],
+ // Firefox source archive (zip) requires all the files the build needs locally inside the archive.
+ sourcesRoot: path.resolve(CORE_DIR, '..'),
+ includeSources: [
+ 'apps/browser-extension/**/*',
+ 'core/client/**/*',
+ 'core/models/**/*',
+ 'core/vault/**/*',
+ ],
excludeSources: [
- 'safari-xcode/build/**',
+ '**/node_modules/**',
+ '**/dist/**',
+ '**/.wxt/**',
+ 'apps/browser-extension/safari-xcode/build/**',
'**/xcuserdata/**',
- 'playwright-report/**',
- 'test-results/**',
- 'tests/**',
- 'stats.html',
- 'stats-*.json',
+ 'apps/browser-extension/playwright-report/**',
+ 'apps/browser-extension/test-results/**',
+ 'apps/browser-extension/tests/**',
+ 'apps/browser-extension/stats.html',
+ 'apps/browser-extension/stats-*.json',
'**/*.log',
- 'build-and-submit.sh'
+ 'apps/browser-extension/build-and-submit.sh'
],
},
});
diff --git a/core/client/src/platform/ClientPlatform.ts b/core/client/src/platform/ClientPlatform.ts
index de68736ad..93e372f2b 100644
--- a/core/client/src/platform/ClientPlatform.ts
+++ b/core/client/src/platform/ClientPlatform.ts
@@ -18,7 +18,7 @@ export interface IClientPlatform {
app: IAppIdentity;
/**
- * Provide the Rust core WebAssembly binary. Called once per realm, lazily, on the first core call.
+ * Provide the Rust core WebAssembly binary.
*/
loadRustCoreWasm(): Promise<BufferSource | Response>;
@@ -37,8 +37,7 @@ export interface IClientPlatform {
let current: IClientPlatform | null = null;
/**
- * Register the host platform. Call once at startup of every JS realm (a service worker and a popup document are
- * separate realms and each need their own call). Calling it again replaces the platform.
+ * Register the host platform.
* @param platform - the host implementation
*/
export function setPlatform(platform: IClientPlatform): void {
diff --git a/core/client/src/rust/RustCore.ts b/core/client/src/rust/RustCore.ts
index 3177fae77..151435337 100644
--- a/core/client/src/rust/RustCore.ts
+++ b/core/client/src/rust/RustCore.ts
@@ -34,7 +34,7 @@ export function initRustCore(): Promise<void> {
initPromise = (async (): Promise<void> => {
await initWasm({ module_or_path: await getPlatform().loadRustCoreWasm() });
})().catch((error: unknown) => {
- // Let the next caller retry instead of pinning a failed load for the realm's lifetime.
+ // Let the next caller retry instead of pinning a failed load for the lifetime of the caller.
initPromise = null;
throw error;
});