Skip to content

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

Replace Argon2id browser extension lib with Rust implementation (#2159)

Leendert de Borst9e96897c0388
diff --git a/apps/browser-extension/package-lock.json b/apps/browser-extension/package-lock.json
index 4c177d86f..d32e7eb67 100644
--- a/apps/browser-extension/package-lock.json
+++ b/apps/browser-extension/package-lock.json
@@ -15,7 +15,6 @@
"@hookform/resolvers": "^5.1.1",
"@types/dompurify": "^3.0.5",
"@webext-core/messaging": "^3.0.1",
- "argon2-browser": "^1.18.0",
"buffer": "^6.0.3",
"dompurify": "^3.4.12",
"globals": "^16.0.0",
@@ -47,7 +46,6 @@
"@typescript-eslint/parser": "^8.65.0",
"@vitest/coverage-v8": "^4.1.8",
"@wxt-dev/module-react": "^1.2.2",
- "argon2": "^0.44.0",
"autoprefixer": "^10.4.20",
"better-sqlite3": "^12.5.0",
"eslint": "^9.39.5",
@@ -466,13 +464,6 @@
"tslib": "^2.4.0"
}
},
- "node_modules/@epic-web/invariant": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/@epic-web/invariant/-/invariant-1.0.0.tgz",
- "integrity": "sha512-lrTPqgvfFQtR/eY/qkIzp98OGdNJu0m5ji3q/nJI8v3SXkRKEnWiOxMmbvcSoAIzv/cGiuvRy57k4suKQSAdwA==",
- "dev": true,
- "license": "MIT"
- },
"node_modules/@es-joy/jsdoccomment": {
"version": "0.49.0",
"resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.49.0.tgz",
@@ -910,16 +901,6 @@
"url": "https://github.com/sponsors/Boshen"
}
},
- "node_modules/@phc/format": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/@phc/format/-/format-1.0.0.tgz",
- "integrity": "sha512-m7X9U6BG2+J+R1lSOdCiITLLrxm+cWlNI3HUFA92oLO77ObGNzaKdh8pMLqdZcshtkKuV84olNNXDfMc4FezBQ==",
- "dev": true,
- "license": "MIT",
- "engines": {
- "node": ">=10"
- }
- },
"node_modules/@pkgjs/parseargs": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
@@ -2388,29 +2369,6 @@
"dev": true,
"license": "MIT"
},
- "node_modules/argon2": {
- "version": "0.44.0",
- "resolved": "https://registry.npmjs.org/argon2/-/argon2-0.44.0.tgz",
- "integrity": "sha512-zHPGN3S55sihSQo0dBbK0A5qpi2R31z7HZDZnry3ifOyj8bZZnpZND2gpmhnRGO1V/d555RwBqIK5W4Mrmv3ig==",
- "dev": true,
- "hasInstallScript": true,
- "license": "MIT",
- "dependencies": {
- "@phc/format": "^1.0.0",
- "cross-env": "^10.0.0",
- "node-addon-api": "^8.5.0",
- "node-gyp-build": "^4.8.4"
- },
- "engines": {
- "node": ">=16.17.0"
- }
- },
- "node_modules/argon2-browser": {
- "version": "1.18.0",
- "resolved": "https://registry.npmjs.org/argon2-browser/-/argon2-browser-1.18.0.tgz",
- "integrity": "sha512-ImVAGIItnFnvET1exhsQB7apRztcoC5TnlSqernMJDUjbc/DLq3UEYeXFrLPrlaIl8cVfwnXb6wX2KpFf2zxHw==",
- "license": "MIT"
- },
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
@@ -3295,24 +3253,6 @@
"url": "https://opencollective.com/express"
}
},
- "node_modules/cross-env": {
- "version": "10.1.0",
- "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-10.1.0.tgz",
- "integrity": "sha512-GsYosgnACZTADcmEyJctkJIoqAhHjttw7RsFrVoJNXbsWWqaq6Ym+7kZjq6mS45O0jij6vtiReppKQEtqWy6Dw==",
- "dev": true,
- "license": "MIT",
- "dependencies": {
- "@epic-web/invariant": "^1.0.0",
- "cross-spawn": "^7.0.6"
- },
- "bin": {
- "cross-env": "dist/bin/cross-env.js",
- "cross-env-shell": "dist/bin/cross-env-shell.js"
- },
- "engines": {
- "node": ">=20"
- }
- },
"node_modules/cross-spawn": {
"version": "7.0.6",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
@@ -6675,28 +6615,6 @@
"node": ">=10"
}
},
- "node_modules/node-addon-api": {
- "version": "8.5.0",
- "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.5.0.tgz",
- "integrity": "sha512-/bRZty2mXUIFY/xU5HLvveNHlswNJej+RnxBjOMkidWfwZzgTbPG1E3K5TOxRLOR+5hX7bSofy8yf1hZevMS8A==",
- "dev": true,
- "license": "MIT",
- "engines": {
- "node": "^18 || ^20 || >= 21"
- }
- },
- "node_modules/node-gyp-build": {
- "version": "4.8.4",
- "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz",
- "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==",
- "dev": true,
- "license": "MIT",
- "bin": {
- "node-gyp-build": "bin.js",
- "node-gyp-build-optional": "optional.js",
- "node-gyp-build-test": "build-test.js"
- }
- },
"node_modules/node-releases": {
"version": "2.0.19",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.19.tgz",
diff --git a/apps/browser-extension/package.json b/apps/browser-extension/package.json
index a10a2a864..2e5d34aaa 100644
--- a/apps/browser-extension/package.json
+++ b/apps/browser-extension/package.json
@@ -35,7 +35,6 @@
"@hookform/resolvers": "^5.1.1",
"@types/dompurify": "^3.0.5",
"@webext-core/messaging": "^3.0.1",
- "argon2-browser": "^1.18.0",
"buffer": "^6.0.3",
"dompurify": "^3.4.12",
"globals": "^16.0.0",
@@ -67,7 +66,6 @@
"@typescript-eslint/parser": "^8.65.0",
"@vitest/coverage-v8": "^4.1.8",
"@wxt-dev/module-react": "^1.2.2",
- "argon2": "^0.44.0",
"autoprefixer": "^10.4.20",
"better-sqlite3": "^12.5.0",
"eslint": "^9.39.5",
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
index 03f4988b3..f0a7a232c 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Login.tsx
@@ -235,12 +235,7 @@ const Login: React.FC = () => {
const loginResponse = await srpUtil.initiateLogin(normalizedUsername);
// Derive key from password using Argon2id and prepare credentials
- const { passwordHashString, passwordHashBase64 } = await SrpAuthService.prepareCredentials(
- credentials.password,
- loginResponse.salt,
- loginResponse.encryptionType,
- loginResponse.encryptionSettings
- );
+ const { passwordHashString, passwordHashBase64 } = await SrpAuthService.prepareCredentials(credentials.password, loginResponse.salt, loginResponse.encryptionSettings);
// Validate login with SRP protocol
const validationResponse = await srpUtil.validateLogin(
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
index a06b2fc12..72613e1cf 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/auth/Unlock.tsx
@@ -279,12 +279,7 @@ const Unlock: React.FC = () => {
const loginResponse = await srpUtil.initiateLogin(authContext.username!);
// Derive key from password using user's encryption settings
- const credentials = await SrpAuthService.prepareCredentials(
- password,
- loginResponse.salt,
- loginResponse.encryptionType,
- loginResponse.encryptionSettings
- );
+ const credentials = await SrpAuthService.prepareCredentials(password, loginResponse.salt, loginResponse.encryptionSettings);
// Store encryption params for future offline unlock
await dbContext.storeEncryptionKeyDerivationParams({
salt: loginResponse.salt,
@@ -310,12 +305,7 @@ const Unlock: React.FC = () => {
}
// Derive key from password using stored encryption settings
- const credentials = await SrpAuthService.prepareCredentials(
- password,
- storedParams.salt,
- storedParams.encryptionType,
- storedParams.encryptionSettings
- );
+ const credentials = await SrpAuthService.prepareCredentials(password, storedParams.salt, storedParams.encryptionSettings);
/*
* KEK/VEK offline: decrypt the locally cached encrypted VEK with the derived key. Throws a decrypt-failed
diff --git a/apps/browser-extension/src/utils/EncryptionUtility.ts b/apps/browser-extension/src/utils/EncryptionUtility.ts
index 2e4038947..c1e0167e9 100644
--- a/apps/browser-extension/src/utils/EncryptionUtility.ts
+++ b/apps/browser-extension/src/utils/EncryptionUtility.ts
@@ -1,12 +1,10 @@
import { Buffer } from 'buffer';
-import argon2 from 'argon2-browser/dist/argon2-bundled.min.js';
-
import { base64ToBytes, bytesToBase64 } from '@/utils/Base64';
import { devWarn } from '@/utils/devLogger/DevLogger';
import type { EncryptionKey } from '@/utils/dist/core/models/vault';
import type { Email, EmailDecryptionKey, MailboxEmail } from '@/utils/dist/core/models/webapi';
-import { parseEmailSource, type ParsedEmailAttachment } from '@/utils/RustCore';
+import { argon2DeriveKey, parseEmailSource, type ParsedEmailAttachment } from '@/utils/RustCore';
/**
* A decrypted email. Its metadata (subject, sender) is decrypted from the individually encrypted fields, while
@@ -40,28 +38,10 @@ export class EncryptionUtility {
public static async deriveKeyFromPassword(
password: string,
salt: string,
- encryptionType: string = 'Argon2Id',
encryptionSettings: string = '{"Iterations":2,"MemorySize":19456,"DegreeOfParallelism":1}'
): Promise<Uint8Array> {
- const settings = JSON.parse(encryptionSettings);
-
try {
- if (encryptionType !== 'Argon2Id') {
- throw new Error('Unsupported encryption type');
- }
-
- const hash = await argon2.hash({
- pass: password,
- salt: salt,
- time: settings.Iterations,
- mem: settings.MemorySize,
- parallelism: settings.DegreeOfParallelism,
- hashLen: 32,
- type: 2, // 0 = Argon2d, 1 = Argon2i, 2 = Argon2id
- });
-
- // Return bytes
- return hash.hash;
+ return await argon2DeriveKey(password, salt, encryptionSettings);
} catch (error) {
console.error('Argon2 hashing failed:', error);
throw error;
diff --git a/apps/browser-extension/src/utils/PinUnlockService.ts b/apps/browser-extension/src/utils/PinUnlockService.ts
index 214917d08..b5e9312bc 100644
--- a/apps/browser-extension/src/utils/PinUnlockService.ts
+++ b/apps/browser-extension/src/utils/PinUnlockService.ts
@@ -1,8 +1,8 @@
-import argon2 from 'argon2-browser/dist/argon2-bundled.min.js';
import { browser } from 'wxt/browser';
import { base64ToBytes, bytesToBase64 } from '@/utils/Base64';
import { PIN_STORAGE_KEYS, StorageKeys } from '@/utils/constants/storageKeys';
+import { argon2DeriveKey } from '@/utils/RustCore';
import { storage } from '#imports';
@@ -336,41 +336,28 @@ async function assembleSaltWithPepper(randomSalt: Uint8Array): Promise<Uint8Arra
return combinedSalt;
}
+/**
+ * Argon2id cost parameters for PIN key derivation.
+ */
+const PIN_ARGON2_SETTINGS = '{"MemorySize":65536,"Iterations":3,"DegreeOfParallelism":1}';
+
/**
* Derive encryption key from PIN using Argon2id
- *
- * Uses Argon2id with high memory cost (64 MB) to make brute-force attacks
- * significantly more expensive. This is especially important for PINs which
- * have lower entropy than passwords.
- *
- * The salt parameter should be the COMBINED salt (random salt + extension pepper)
- * created by assembleSaltWithPepper().
- *
- * Parameters chosen for security:
- * - Memory: 65536 KB (64 MB) - makes GPU attacks much harder
- * - Iterations: 3 - standard for Argon2id
- * - Parallelism: 1 - suitable for browser environment
- * - Output: 32 bytes for AES-256-GCM
*/
async function derivePinKey(pin: string, salt: Uint8Array): Promise<CryptoKey> {
- // Convert salt to base64 string (required by argon2-browser)
+ /*
+ * The salt is hashed as the characters of this base64 string, not as the bytes it decodes to.
+ * Every PIN ever set was derived that way, so decoding here would lock users out of their vault.
+ */
const saltBase64 = bytesToBase64(salt);
- // Derive key using Argon2id
- const hash = await argon2.hash({
- pass: pin,
- salt: saltBase64,
- time: 3,
- mem: 65536,
- parallelism: 1,
- hashLen: 32,
- type: 2,
- });
+ // Derive key using Argon2id, stating the PIN cost parameters instead of the account's
+ const hash = await argon2DeriveKey(pin, saltBase64, PIN_ARGON2_SETTINGS);
// Import the derived key into WebCrypto API
const pinKey = await crypto.subtle.importKey(
'raw',
- hash.hash,
+ hash,
{ name: 'AES-GCM', length: 256 },
false,
['encrypt', 'decrypt']
diff --git a/apps/browser-extension/src/utils/RustCore.ts b/apps/browser-extension/src/utils/RustCore.ts
index 5877d1fd0..50e539d41 100644
--- a/apps/browser-extension/src/utils/RustCore.ts
+++ b/apps/browser-extension/src/utils/RustCore.ts
@@ -214,6 +214,14 @@ export async function extractEmailAttachment(source: Uint8Array, index: number,
return core.extractEmailAttachment(source, index, detachedBody) as Uint8Array;
}
+/**
+ * Derive a 32-byte key from a password using Argon2id.
+ */
+export async function argon2DeriveKey(password: string, salt: string, encryptionSettings: string): Promise<Uint8Array> {
+ await initRustCore();
+ return core.argon2DeriveKey(password, salt, encryptionSettings);
+}
+
/**
* Generate a random 32-byte seed as a 64-character hex string, suitable for the
* `seed` argument of {@link generatePassword}.
diff --git a/apps/browser-extension/src/utils/SharingService.ts b/apps/browser-extension/src/utils/SharingService.ts
index 0c058172a..144235d0c 100644
--- a/apps/browser-extension/src/utils/SharingService.ts
+++ b/apps/browser-extension/src/utils/SharingService.ts
@@ -172,7 +172,7 @@ export class SharingService {
*/
public static async deleteSharedManifest(webApi: WebApiService, groupId: string, manifestId: string, password: string): Promise<void> {
const initiate = await webApi.post<object, DeleteSharedManifestInitiateResponse>(`Groups/${groupId}/manifests/${manifestId}/delete/initiate`, {});
- const { passwordHashString } = await SrpAuthService.prepareCredentials(password, initiate.salt, initiate.encryptionType, initiate.encryptionSettings);
+ const { passwordHashString } = await SrpAuthService.prepareCredentials(password, initiate.salt, initiate.encryptionSettings);
const proof = await SrpAuthService.deriveClientProof(initiate.salt, initiate.srpIdentity, passwordHashString, initiate.serverEphemeral);
await webApi.post<DeleteSharedManifestRequest, void>(`Groups/${groupId}/manifests/${manifestId}/delete/confirm`, proof, false);
}
diff --git a/apps/browser-extension/src/utils/auth/SrpAuthService.ts b/apps/browser-extension/src/utils/auth/SrpAuthService.ts
index 78f78ab36..13053e6e6 100644
--- a/apps/browser-extension/src/utils/auth/SrpAuthService.ts
+++ b/apps/browser-extension/src/utils/auth/SrpAuthService.ts
@@ -315,16 +315,10 @@ export class SrpAuthService {
public static async prepareCredentials(
password: string,
salt: string,
- encryptionType: string,
encryptionSettings: string
): Promise<PreparedCredentials> {
// Derive key from password using Argon2Id
- const passwordHash = await EncryptionUtility.deriveKeyFromPassword(
- password,
- salt,
- encryptionType,
- encryptionSettings
- );
+ const passwordHash = await EncryptionUtility.deriveKeyFromPassword(password, salt, encryptionSettings);
return {
passwordHashString: SrpAuthService.bytesToHexString(passwordHash),
@@ -367,12 +361,7 @@ export class SrpAuthService {
const srpIdentity = SrpAuthService.generateSrpIdentity();
// Derive key from password using default Argon2Id settings
- const credentials = await SrpAuthService.prepareCredentials(
- password,
- salt,
- DEFAULT_ENCRYPTION.type,
- DEFAULT_ENCRYPTION.settings
- );
+ const credentials = await SrpAuthService.prepareCredentials(password, salt, DEFAULT_ENCRYPTION.settings);
// Generate SRP private key and verifier using srpIdentity (not username)
const privateKey = await SrpAuthService.derivePrivateKey(salt, srpIdentity, credentials.passwordHashString);
@@ -497,12 +486,7 @@ export class SrpAuthService {
const loginResponse = (await initiateResponse.json()) as LoginResponse;
// Step 2: Prepare credentials
- const credentials = await SrpAuthService.prepareCredentials(
- password,
- loginResponse.salt,
- loginResponse.encryptionType,
- loginResponse.encryptionSettings
- );
+ const credentials = await SrpAuthService.prepareCredentials(password, loginResponse.salt, loginResponse.encryptionSettings);
// Step 3: Generate the SRP proof for this login response
const proof = await SrpAuthService.deriveLoginProof(loginResponse, normalizedUsername, credentials.passwordHashString);
diff --git a/apps/browser-extension/tests/helpers/manifest-v2-api.ts b/apps/browser-extension/tests/helpers/manifest-v2-api.ts
index 2ecfb1610..d7730bc4c 100644
--- a/apps/browser-extension/tests/helpers/manifest-v2-api.ts
+++ b/apps/browser-extension/tests/helpers/manifest-v2-api.ts
@@ -9,11 +9,10 @@
*/
import { createHash } from 'crypto';
-import { readFileSync } from 'fs';
-import { join } from 'path';
-import { initSync, vaultCodecPackPayload, vaultCodecUnpackPayload } from '../../src/utils/dist/core/rust/aliasvault_core.js';
+import { vaultCodecPackPayload, vaultCodecUnpackPayload } from '../../src/utils/dist/core/rust/aliasvault_core.js';
+import { ensureRustCore } from './rust-core';
import { normalizeUsername, symmetricDecryptBytes, symmetricEncryptBytes } from './test-api';
/** One manifest entry in the v2 GET snapshot. */
@@ -45,19 +44,6 @@ export type DecryptedManifest = {
[key: string]: unknown;
};
-let wasmInitialized = false;
-
-/**
- * Initializes the Rust core WASM module from the extension's dist (idempotent).
- */
-function ensureWasm(): void {
- if (!wasmInitialized) {
- const wasmPath = join(process.cwd(), 'src/utils/dist/core/rust/aliasvault_core_bg.wasm');
- initSync({ module: readFileSync(wasmPath) });
- wasmInitialized = true;
- }
-}
-
/**
* Fetches the v2 vault snapshot for the authenticated user.
*
@@ -97,7 +83,7 @@ export function requirePersonalManifest(snapshot: VaultSnapshot): SnapshotManife
* @returns The decrypted manifest object
*/
export async function openManifest(blobBase64: string, encryptionKey: Uint8Array): Promise<DecryptedManifest> {
- ensureWasm();
+ ensureRustCore();
const packedBytes = await symmetricDecryptBytes(blobBase64, encryptionKey);
return JSON.parse(vaultCodecUnpackPayload(packedBytes)) as DecryptedManifest;
}
@@ -126,7 +112,7 @@ export async function pushManifest(
blobReferences: Array<{ hash: string; category: string }>,
encryptionKey: Uint8Array
): Promise<number> {
- ensureWasm();
+ ensureRustCore();
const packedBytes = vaultCodecPackPayload(JSON.stringify(manifest));
const manifestBlob = await symmetricEncryptBytes(packedBytes, encryptionKey);
const manifestCiphertextHash = createHash('sha256').update(Buffer.from(manifestBlob, 'base64')).digest('hex');
diff --git a/apps/browser-extension/tests/helpers/rust-core.ts b/apps/browser-extension/tests/helpers/rust-core.ts
new file mode 100644
index 000000000..702f75f36
--- /dev/null
+++ b/apps/browser-extension/tests/helpers/rust-core.ts
@@ -0,0 +1,21 @@
+/**
+ * Node-side loader for the AliasVault Rust core (WASM).
+ */
+
+import { readFileSync } from 'fs';
+import { join } from 'path';
+
+import { initSync } from '../../src/utils/dist/core/rust/aliasvault_core.js';
+
+let wasmInitialized = false;
+
+/**
+ * Initializes the Rust core WASM module from the extension's dist (idempotent).
+ */
+export function ensureRustCore(): void {
+ if (!wasmInitialized) {
+ const wasmPath = join(process.cwd(), 'src/utils/dist/core/rust/aliasvault_core_bg.wasm');
+ initSync({ module: readFileSync(wasmPath) });
+ wasmInitialized = true;
+ }
+}
diff --git a/apps/browser-extension/tests/helpers/test-api.ts b/apps/browser-extension/tests/helpers/test-api.ts
index e2716c9f1..b2e422e9c 100644
--- a/apps/browser-extension/tests/helpers/test-api.ts
+++ b/apps/browser-extension/tests/helpers/test-api.ts
@@ -3,26 +3,23 @@
*
* This module provides utilities for interacting with the AliasVault API
* during E2E tests, including user registration using SRP protocol.
- *
- * Note: This module uses Node.js native argon2 for password hashing,
- * while the browser extension uses argon2-browser. The SRP protocol
- * logic is shared where possible.
*/
-// Import argon2 for Node.js environment (different from browser version)
import { webcrypto } from 'crypto';
import { readFileSync, unlinkSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
-import argon2 from 'argon2';
import Database from 'better-sqlite3';
import * as OTPAuth from 'otpauth';
import * as srp from 'secure-remote-password/client.js';
+import { argon2DeriveKey } from '../../src/utils/dist/core/rust/aliasvault_core.js';
// Get the vault schema SQL from the core vault package
import { COMPLETE_SCHEMA_SQL, VAULT_VERSIONS } from '../../src/utils/dist/core/vault/index.mjs';
+import { ensureRustCore } from './rust-core';
+
/**
* Token model returned from successful registration/login.
*/
@@ -85,10 +82,6 @@ const DEFAULT_ENCRYPTION = {
MemorySize: 19456,
Iterations: 2,
}),
- // Parsed settings for argon2 usage
- iterations: 2,
- memorySize: 19456,
- parallelism: 1,
};
/**
@@ -131,30 +124,15 @@ function bytesToHexString(bytes: Uint8Array): string {
}
/**
- * Derives a key from password using Argon2Id (Node.js version).
- *
- * Note: This uses the native argon2 module for Node.js, which is different
- * from the argon2-browser WASM module used in the browser extension.
+ * Derives a key from password using Argon2Id, through the extension's own Rust core.
*
* @param password - The password to derive the key from
- * @param salt - The salt string
+ * @param salt - The salt string, hashed as its UTF-8 bytes
* @returns The derived key as Uint8Array
*/
-async function deriveKeyFromPassword(password: string, salt: string): Promise<Uint8Array> {
- // Note: argon2 in Node.js expects salt as Buffer
- const saltBuffer = Buffer.from(salt, 'utf8');
-
- const hash = await argon2.hash(password, {
- type: argon2.argon2id,
- salt: saltBuffer,
- timeCost: DEFAULT_ENCRYPTION.iterations,
- memoryCost: DEFAULT_ENCRYPTION.memorySize,
- parallelism: DEFAULT_ENCRYPTION.parallelism,
- hashLength: 32,
- raw: true,
- });
-
- return new Uint8Array(hash);
+function deriveKeyFromPassword(password: string, salt: string): Uint8Array {
+ ensureRustCore();
+ return argon2DeriveKey(password, salt, DEFAULT_ENCRYPTION.settings);
}
/**
@@ -300,7 +278,7 @@ async function prepareRegistration(
const salt = srp.generateSalt();
// Derive key from password using Argon2Id
- const encryptionKey = await deriveKeyFromPassword(password, salt);
+ const encryptionKey = deriveKeyFromPassword(password, salt);
// Convert to uppercase hex string (expected by server)
const passwordHashString = bytesToHexString(encryptionKey);
diff --git a/apps/browser-extension/wxt.config.ts b/apps/browser-extension/wxt.config.ts
index c16009713..f823be6a9 100644
--- a/apps/browser-extension/wxt.config.ts
+++ b/apps/browser-extension/wxt.config.ts
@@ -79,7 +79,6 @@ export default defineConfig({
resources: [
"webauthn.js",
"src/sql-wasm.wasm",
- "src/argon2.wasm",
"src/aliasvault_core_bg.wasm"
],
matches: ["<all_urls>"]
@@ -104,10 +103,6 @@ export default defineConfig({
asciiOnlyJsPlugin(),
viteStaticCopy({
targets: [
- {
- src: 'node_modules/argon2-browser/dist/argon2.wasm',
- dest: 'src'
- },
{
src: 'node_modules/sql.js/dist/sql-wasm.wasm',
dest: 'src'