Skip to content

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

Refactor pin storage keys to shared constant (#2159)

Leendert de Borst89c7f4180d2c
diff --git a/apps/browser-extension/src/utils/PinUnlockService.ts b/apps/browser-extension/src/utils/PinUnlockService.ts
index c5b5dea05..214917d08 100644
--- a/apps/browser-extension/src/utils/PinUnlockService.ts
+++ b/apps/browser-extension/src/utils/PinUnlockService.ts
@@ -2,7 +2,7 @@ import argon2 from 'argon2-browser/dist/argon2-bundled.min.js';
import { browser } from 'wxt/browser';
import { base64ToBytes, bytesToBase64 } from '@/utils/Base64';
-import { StorageKeys } from '@/utils/constants/storageKeys';
+import { PIN_STORAGE_KEYS, StorageKeys } from '@/utils/constants/storageKeys';
import { storage } from '#imports';
@@ -271,17 +271,12 @@ export async function unlockWithPin(pin: string): Promise<string> {
}
/**
- * Disable PIN unlock and remove all stored (encrypted) data.
+ * Disable PIN unlock and remove all stored (encrypted) data. Logout does not depend on this: the same keys are
+ * part of `vaultDataStorageKeys()`, so every logout path clears them in the background.
*/
export async function removeAndDisablePin(): Promise<void> {
try {
- await Promise.all([
- storage.removeItem(StorageKeys.PIN_ENABLED),
- storage.removeItem(StorageKeys.PIN_ENCRYPTED_KEY),
- storage.removeItem(StorageKeys.PIN_SALT),
- storage.removeItem(StorageKeys.PIN_LENGTH),
- storage.removeItem(StorageKeys.PIN_FAILED_ATTEMPTS)
- ]);
+ await storage.removeItems([...PIN_STORAGE_KEYS]);
} catch (error) {
console.error('[PinUnlockService] Failed to disable PIN:', error);
throw error;
diff --git a/apps/browser-extension/src/utils/constants/storageKeys.ts b/apps/browser-extension/src/utils/constants/storageKeys.ts
index 660a16791..03c1928ab 100644
--- a/apps/browser-extension/src/utils/constants/storageKeys.ts
+++ b/apps/browser-extension/src/utils/constants/storageKeys.ts
@@ -207,6 +207,15 @@ export const AUTH_STORAGE_KEYS: readonly StorageKey[] = [
StorageKeys.CAPABILITIES,
];
+/** Keys holding the PIN unlock material: the PIN-wrapped vault key and the parameters that unwrap it. */
+export const PIN_STORAGE_KEYS: readonly StorageKey[] = [
+ StorageKeys.PIN_ENABLED,
+ StorageKeys.PIN_ENCRYPTED_KEY,
+ StorageKeys.PIN_SALT,
+ StorageKeys.PIN_LENGTH,
+ StorageKeys.PIN_FAILED_ATTEMPTS,
+];
+
/** Keys that must not survive a vault lock: the encryption key plus anything derived from decrypted data. */
export const VAULT_LOCK_STORAGE_KEYS: readonly StorageKey[] = [
StorageKeys.ENCRYPTION_KEY,
@@ -250,9 +259,8 @@ export const LOCAL_PREFERENCE_STORAGE_KEYS: readonly StorageKey[] = [
];
/**
- * Every key holding vault data or state derived from it, including the per-scope dynamic keys. Cleared on ANY
- * logout, forced or user-initiated: a session's vault never outlives it, so no stale blob, revision baseline or
- * dirty flag can meet the vault the next login pulls.
+ * Every key holding vault data or state derived from it, including the per-scope dynamic keys and the PIN
+ * unlock material. Cleared on ANY logout, forced or user-initiated.
*/
export const vaultDataStorageKeys = (): StorageKey[] => [
StorageKeys.ENCRYPTED_VAULT,
@@ -275,6 +283,7 @@ export const vaultDataStorageKeys = (): StorageKey[] => [
StorageKeys.ENCRYPTED_ACCOUNT_KEY,
StorageKeys.ACCOUNT_PUBLIC_KEY,
StorageKeys.ENCRYPTED_ACCOUNT_PRIVATE_KEY,
+ ...PIN_STORAGE_KEYS,
...ALL_VAULT_MUTATION_SCOPES.map(scope => dirtyScopeStorageKey(scope)),
...LEGACY_VAULT_DATA_STORAGE_KEYS,
];