Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Fix all eslint issues (#541)
Leendert de Borst636e996a17ca
diff --git a/browser-extensions/chrome/src/App.tsx b/browser-extensions/chrome/src/App.tsxindex d846b1212..ee0b3ff5e 100644--- a/browser-extensions/chrome/src/App.tsx+++ b/browser-extensions/chrome/src/App.tsx@@ -8,16 +8,9 @@ import Settings from './pages/Settings';import CredentialsList from './pages/CredentialsList';import './styles/app.css';-interface Credential {- Id: string;- ServiceName: string;- Username: string;- Logo?: any; // Changed from string to any since it's raw buffer data-}-// Add base64Encode function// TODO: this is used in contentScript.ts too.-function base64Encode(buffer: any): string | null {+function base64Encode(buffer: Uint8Array): string | null {if (!buffer || typeof buffer !== 'object') {console.log('Empty or invalid buffer received');return null;diff --git a/browser-extensions/chrome/src/background.ts b/browser-extensions/chrome/src/background.tsindex 260c47947..2a144ec6f 100644--- a/browser-extensions/chrome/src/background.ts+++ b/browser-extensions/chrome/src/background.ts@@ -1,14 +1,13 @@import { Buffer } from 'buffer';import EncryptionUtility from './utils/EncryptionUtility';import SqliteClient from './utils/SqliteClient';+import { Credential } from './types/Credential';console.log('Background script initialized');let vaultState: {- decryptedVault: any | null;sessionKey: string | null;} = {- decryptedVault: null,sessionKey: null};@@ -16,14 +15,11 @@ let vaultState: {chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {console.log('Received message:', message.type);switch (message.type) {- case 'STORE_VAULT':+ case 'STORE_VAULT': {// Generate random session keyconst sessionKey = crypto.getRandomValues(new Uint8Array(32));vaultState.sessionKey = Buffer.from(sessionKey).toString('base64');- console.log('Session key for encryption:', vaultState.sessionKey);- console.log('Vault data being encrypted:', message.vault);-// Re-encrypt vault with session key(async () => {try {@@ -32,8 +28,6 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {vaultState.sessionKey!);- console.log('Encrypted vault (after encryption):', encryptedVault);-// Store in chrome.storage.session and wait for completionchrome.storage.session.set({ encryptedVault }, () => {if (chrome.runtime.lastError) {@@ -49,8 +43,8 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {}})();break;-- case 'GET_VAULT':+ }+ case 'GET_VAULT': {if (!vaultState.sessionKey) {console.log('No session key available');sendResponse({ vault: null });@@ -60,7 +54,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {chrome.storage.session.get(['encryptedVault'], async (result) => {try {if (!result.encryptedVault) {- console.log('No encrypted vault found in storage');+ console.error('No encrypted vault found in storage');sendResponse({ vault: null });return;}@@ -84,14 +78,15 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {}});break;-- case 'CLEAR_VAULT':+ }+ case 'CLEAR_VAULT': {vaultState.sessionKey = null;chrome.storage.session.remove(['encryptedVault']);sendResponse({ success: true });break;+ }- case 'GET_CREDENTIALS_FOR_URL':+ case 'GET_CREDENTIALS_FOR_URL': {console.log('GET_CREDENTIALS_FOR_URL called');if (!vaultState.sessionKey) {sendResponse({ credentials: [] });@@ -105,21 +100,18 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {sendResponse({ credentials: [] });return;}- console.log('encryptedVault:', result.encryptedVault);const decryptedVault = await EncryptionUtility.symmetricDecrypt(result.encryptedVault,vaultState.sessionKey!);- console.log('decryptedVault:', decryptedVault);- const url = new URL(message.url);// Initialize SQLite clientconst sqliteClient = new SqliteClient();await sqliteClient.initializeFromBase64(decryptedVault);// Query credentials with their related service information- const credentials = sqliteClient.executeQuery(`+ const credentials: Credential[] = sqliteClient.executeQuery(`SELECTc.Id,c.Username,@@ -138,26 +130,28 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {console.log('credentials:', credentials);// Filter credentials that match the current domain- const matchingCredentials = credentials.filter(cred => {+ /*const matchingCredentials = credentials.filter(cred => {// TODO: Implement proper URL matchingreturn true;- /*try {+ try {const credentialUrl = new URL(cred.ServiceUrl);return credentialUrl.hostname === url.hostname;} catch {return false;- }*/+ }});console.log('matchingCredentials:', matchingCredentials);+ */- sendResponse({ credentials: matchingCredentials });+ sendResponse({ credentials: credentials });} catch (error) {console.error('Error getting credentials:', error);sendResponse({ credentials: [] });}});break;+ }}return true;});diff --git a/browser-extensions/chrome/src/contentScript.ts b/browser-extensions/chrome/src/contentScript.tsindex 119ab6138..c58dfd9f6 100644--- a/browser-extensions/chrome/src/contentScript.ts+++ b/browser-extensions/chrome/src/contentScript.ts@@ -1,26 +1,18 @@import { detectForms } from './utils/FormDetector';+import { Credential } from './types/Credential';console.log('Content script loaded!'); // This will help verify the script is running-// Track active input field-let activeInput: HTMLInputElement | null = null;-const placeholderBase64 = 'UklGRjoEAABXRUJQVlA4IC4EAAAwFwCdASqAAIAAPpFCm0olo6Ihp5IraLASCWUA0eb/0s56RrLtCnYfLPiBshdXWMx8j1Ez65f169iA4xUDBTEV6ylMQeCIj2b7RngGi7gKZ9WjKdSoy9R8JcgOmjCMlDmLG20KhNo/i/Dc/Ah5GAvGfm8kfniV3AkR6fxN6eKwjDc6xrDgSfS48G5uGV6WzQt24YAVlLSK9BMwndzfHnePK1KFchFrL7O3ulB8cGNCeomu4o+l0SrS/JKblJ4WTzj0DAD++lCUEouSfgRKdiV2TiYCD+H+l3tANKSPQFPQuzi7rbvxqGeRmXB9kDwURaoSTTpYjA9REMUi9uA6aV7PWtBNXgUzMLowYMZeos6Xvyhb34GmufswMHA5ZyYpxzjTphOak4ZjNOiz8aScO5ygiTx99SqwX/uL+HSeVOSraHw8IymrMwm+jLxqN8BS8dGcItLlm/ioulqH2j4V8glDgSut+ExkxiD7m8TGPrrjCQNJbRDzpOFsyCyfBZupvp8QjGKW2KGziSZeIWes4aTB9tRmeEBhnUrmTDZQuXcc67Fg82KHrSfaeeOEq6jjuUjQ8wUnzM4Zz3dhrwSyslVz/WvnKqYkr4V/TTXPFF5EjF4rM1bHZ8bK63EfTnK41+n3n4gEFoYP4mXkNH0hntnYcdTqiE7Gn+q0BpRRxnkpBSZlA6Wa70jpW0FGqkw5e591A5/H+OV+60WAo+4Mi+NlsKrvLZ9EiVaPnoEFZlJQx1fA777AJ2MjXJ4KSsrWDWJi1lE8yPs8V6XvcC0chDTYt8456sKXAagCZyY+fzQriFMaddXyKQdG8qBqcdYjAsiIcjzaRFBBoOK9sU+sFY7N6B6+xtrlu3c37rQKkI3O2EoiJOris54EjJ5OFuumA0M6riNUuBf/MEPFBVx1JRcUEs+upEBsCnwYski7FT3TTqHrx7v5AjgFN97xhPTkmVpu6sxRnWBi1fxIRp8eWZeFM6mUcGgVk1WeVb1yhdV9hoMo2TsNEPE0tHo/wvuSJSzbZo7wibeXM9v/rRfKcx7X93rfiXVnyQ9f/5CaAQ4lxedPp/6uzLtOS4FyL0bCNeZ6L5w+AiuyWCTDFIYaUzhwfG+/YTQpWyeZCdQIKzhV+3GeXI2cxoP0ER/DlOKymf1gm+zRU3sqf1lBVQ0y+mK/Awl9bS3uaaQmI0FUyUwHUKP7PKuXnO+LcwDv4OfPT6hph8smc1EtMe5ib/apar/qZ9dyaEaElALJ1KKxnHziuvVl8atk1fINSQh7OtXDyqbPw9o/nGIpTnv5iFmwmWJLis2oyEgPkJqyx0vYI8rjkVEzKc8eQavAJBYSpjMwM193Swt+yJyjvaGYWPnqExxKiNarpB2WSO7soCAZXhS1uEYHryrK47BH6W1dRiruqT0xpLih3MXiwU3VDwAAAA==';// Listen for input field focusdocument.addEventListener('focusin', (e) => {const target = e.target as HTMLInputElement;if (target.tagName === 'INPUT') {- activeInput = target;showCredentialPopup(target);}});-// Listen for input field blur-document.addEventListener('focusout', (e) => {- activeInput = null;-});-// Create and manage credential popupfunction showCredentialPopup(input: HTMLInputElement) {console.log('showCredentialPopup called');@@ -37,7 +29,7 @@ function showCredentialPopup(input: HTMLInputElement) {});}-function createPopup(input: HTMLInputElement, credentials: any[]) {+function createPopup(input: HTMLInputElement, credentials: Credential[]) {// Remove existing popup if anyremoveExistingPopup();@@ -116,7 +108,7 @@ function removeExistingPopup() {}}-function fillCredential(credential: any) {+function fillCredential(credential: Credential) {const forms = detectForms();if (!forms.length) return;@@ -137,7 +129,7 @@ function triggerInputEvents(element: HTMLInputElement) {}// Remove the Buffer import and replace with a base64 encoding function-function base64Encode(buffer: any): string | null {+function base64Encode(buffer: Uint8Array): string | null {if (!buffer || typeof buffer !== 'object') {console.log('Empty or invalid buffer received');return null;diff --git a/browser-extensions/chrome/src/context/DbContext.tsx b/browser-extensions/chrome/src/context/DbContext.tsxindex 66b74e17f..5fef142c7 100644--- a/browser-extensions/chrome/src/context/DbContext.tsx+++ b/browser-extensions/chrome/src/context/DbContext.tsx@@ -1,4 +1,4 @@-import React, { createContext, useContext, useState, useEffect } from 'react';+import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';import SqliteClient from '../utils/SqliteClient';interface DbContextType {@@ -14,27 +14,45 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }const [sqliteClient, setSqliteClient] = useState<SqliteClient | null>(null);const [isInitialized, setIsInitialized] = useState(false);- const checkStoredVault = async () => {- console.log('Checking for stored vault');+ const initializeDatabase = useCallback(async (blob: string) => {+ const client = new SqliteClient();+ await client.initializeFromBase64(blob);+ setSqliteClient(client);+ setIsInitialized(true);++ // Store in background worker+ chrome.runtime.sendMessage({+ type: 'STORE_VAULT',+ vault: blob+ });+ }, []);++ const checkStoredVault = useCallback(async () => {try {const response = await chrome.runtime.sendMessage({ type: 'GET_VAULT' });if (response && response.vault) {- console.log('Found stored vault');- await initializeDatabase(response.vault);+ const client = new SqliteClient();+ await client.initializeFromBase64(response.vault);+ setSqliteClient(client);+ setIsInitialized(true);++ // Store in background worker+ chrome.runtime.sendMessage({+ type: 'STORE_VAULT',+ vault: response.vault+ });}} catch (error) {- console.log('No stored vault found');console.error('Error retrieving vault from background:', error);}- };+ }, []);useEffect(() => {// Check if database is initialized and try to retrieve vault from background- console.log('Checking if database is initialized');if (!isInitialized) {checkStoredVault();}- }, [isInitialized]);+ }, [isInitialized, checkStoredVault]);// Add a listener for when the popup becomes visibleuseEffect(() => {@@ -48,20 +66,7 @@ export const DbProvider: React.FC<{ children: React.ReactNode }> = ({ children }return () => {document.removeEventListener('visibilitychange', handleVisibilityChange);};- }, [isInitialized]);-- const initializeDatabase = async (blob: string) => {- const client = new SqliteClient();- await client.initializeFromBase64(blob);- setSqliteClient(client);- setIsInitialized(true);-- // Store in background worker- chrome.runtime.sendMessage({- type: 'STORE_VAULT',- vault: blob- });- };+ }, [isInitialized, checkStoredVault]);const clearDatabase = () => {setSqliteClient(null);diff --git a/browser-extensions/chrome/src/context/WebApiContext.tsx b/browser-extensions/chrome/src/context/WebApiContext.tsxindex 295c177ad..99fe58837 100644--- a/browser-extensions/chrome/src/context/WebApiContext.tsx+++ b/browser-extensions/chrome/src/context/WebApiContext.tsx@@ -30,7 +30,7 @@ export const WebApiProvider: React.FC<{ children: React.ReactNode }> = ({ childrreturn () => {chrome.storage.onChanged.removeListener(handleStorageChange);};- }, []);+ }, [getAccessToken, getRefreshToken, updateTokens, logout]);if (!webApiService) {return null;diff --git a/browser-extensions/chrome/src/pages/CredentialsList.tsx b/browser-extensions/chrome/src/pages/CredentialsList.tsxindex 2f3623dd4..830b42ad5 100644--- a/browser-extensions/chrome/src/pages/CredentialsList.tsx+++ b/browser-extensions/chrome/src/pages/CredentialsList.tsx@@ -5,11 +5,11 @@ interface Credential {Id: string;ServiceName: string;Username: string;- Logo?: any;+ Logo?: Uint8Array;}interface CredentialsListProps {- base64Encode: (buffer: any) => string | null;+ base64Encode: (buffer: Uint8Array) => string | null;}const CredentialsList: React.FC<CredentialsListProps> = ({ base64Encode }) => {@@ -17,10 +17,6 @@ const CredentialsList: React.FC<CredentialsListProps> = ({ base64Encode }) => {const [credentials, setCredentials] = useState<Credential[]>([]);useEffect(() => {- loadCredentials();- }, [dbContext.sqliteClient]);-- const loadCredentials = () => {if (!dbContext?.sqliteClient) return;try {@@ -38,7 +34,7 @@ const CredentialsList: React.FC<CredentialsListProps> = ({ base64Encode }) => {} catch (err) {console.error('Error loading credentials:', err);}- };+ }, [dbContext.sqliteClient]);return (<div className="bg-white dark:bg-gray-700 rounded-lg p-4 mb-4 shadow-lg">diff --git a/browser-extensions/chrome/src/pages/Login.tsx b/browser-extensions/chrome/src/pages/Login.tsxindex 1d3fc40ea..7b6067946 100644--- a/browser-extensions/chrome/src/pages/Login.tsx+++ b/browser-extensions/chrome/src/pages/Login.tsx@@ -6,6 +6,7 @@ import { Buffer } from 'buffer';import Button from '../components/Button';import EncryptionUtility from '../utils/EncryptionUtility';import SrpUtility from '../utils/SrpUtility';+import { VaultResponse } from '../types/webapi/VaultResponse';const Login: React.FC = () => {const { login } = useAuth();@@ -59,8 +60,7 @@ const Login: React.FC = () => {}// Make another API call trying to get latest vault- // TODO: can we make webapi response typed?- const vaultResponseJson = await webApi.get('Vault') as any;+ const vaultResponseJson = await webApi.get('Vault') as VaultResponse;console.log('Vault response:')console.log('--------------------------------');diff --git a/browser-extensions/chrome/src/pages/Unlock.tsx b/browser-extensions/chrome/src/pages/Unlock.tsxindex 9a2231e19..f8d270455 100644--- a/browser-extensions/chrome/src/pages/Unlock.tsx+++ b/browser-extensions/chrome/src/pages/Unlock.tsx@@ -6,6 +6,7 @@ import { Buffer } from 'buffer';import Button from '../components/Button';import EncryptionUtility from '../utils/EncryptionUtility';import SrpUtility from '../utils/SrpUtility';+import { VaultResponse } from '../types/webapi/VaultResponse';const Unlock: React.FC = () => {const { username, logout } = useAuth();@@ -36,7 +37,7 @@ const Unlock: React.FC = () => {);// Make API call to get latest vault- const vaultResponseJson = await webApi.get('Vault') as any;+ const vaultResponseJson = await webApi.get('Vault') as VaultResponse;// Attempt to decrypt the blobconst passwordHashBase64 = Buffer.from(passwordHash).toString('base64');diff --git a/browser-extensions/chrome/src/types/Credential.ts b/browser-extensions/chrome/src/types/Credential.tsnew file mode 100644index 000000000..0b6e2c818--- /dev/null+++ b/browser-extensions/chrome/src/types/Credential.ts@@ -0,0 +1,11 @@+// TODO: move query logic to shared dbcontext and reference this type from there+// so we don't have multiple copies or versions of this type with different fields.+export interface Credential {+ Id: string;+ Username: string;+ ServiceId: string;+ ServiceName: string;+ ServiceUrl: string;+ Logo: Uint8Array;+ Password: string;+}\ No newline at end of filediff --git a/browser-extensions/chrome/src/types/webapi/Login.ts b/browser-extensions/chrome/src/types/webapi/Login.tsnew file mode 100644index 000000000..a11481e22--- /dev/null+++ b/browser-extensions/chrome/src/types/webapi/Login.ts@@ -0,0 +1,10 @@+export interface LoginRequest {+ username: string;+}++export interface LoginResponse {+ salt: string;+ serverEphemeral: string;+ encryptionType: string;+ encryptionSettings: string;+}diff --git a/browser-extensions/chrome/src/types/webapi/ValidateLogin.ts b/browser-extensions/chrome/src/types/webapi/ValidateLogin.tsnew file mode 100644index 000000000..e4d9bb3d4--- /dev/null+++ b/browser-extensions/chrome/src/types/webapi/ValidateLogin.ts@@ -0,0 +1,15 @@+export interface ValidateLoginRequest {+ username: string;+ rememberMe: boolean;+ clientPublicEphemeral: string;+ clientSessionProof: string;+}++export interface ValidateLoginResponse {+ requiresTwoFactor: boolean;+ token?: {+ token: string;+ refreshToken: string;+ };+ serverSessionProof: string;+ }\ No newline at end of filediff --git a/browser-extensions/chrome/src/types/webapi/VaultResponse.ts b/browser-extensions/chrome/src/types/webapi/VaultResponse.tsnew file mode 100644index 000000000..106dfedcc--- /dev/null+++ b/browser-extensions/chrome/src/types/webapi/VaultResponse.ts@@ -0,0 +1,16 @@+export interface Vault {+ blob: string;+ createdAt: string;+ credentialsCount: number;+ currentRevisionNumber: number;+ emailAddressList: string[];+ encryptionPublicKey: string;+ updatedAt: string;+ username: string;+ version: string;+ }++ export interface VaultResponse {+ status: number;+ vault: Vault;+ }\ No newline at end of filediff --git a/browser-extensions/chrome/src/utils/SqliteClient.tsx b/browser-extensions/chrome/src/utils/SqliteClient.tsxindex 8c95e3e75..e65ca2165 100644--- a/browser-extensions/chrome/src/utils/SqliteClient.tsx+++ b/browser-extensions/chrome/src/utils/SqliteClient.tsx@@ -1,7 +1,7 @@-import initSqlJs from 'sql.js';+import initSqlJs, { Database } from 'sql.js';class SqliteClient {- private db: any = null;+ private db: Database | null = null;/*** Initialize the SQLite database from a base64 string@@ -31,7 +31,7 @@ class SqliteClient {/*** Execute a SELECT query*/- public executeQuery<T>(query: string, params: any[] = []): T[] {+ public executeQuery<T>(query: string, params: (string | number | null | Uint8Array)[] = []): T[] {if (!this.db) {throw new Error('Database not initialized');}@@ -56,7 +56,7 @@ class SqliteClient {/*** Execute an INSERT, UPDATE, or DELETE query*/- public executeUpdate(query: string, params: any[] = []): number {+ public executeUpdate(query: string, params: (string | number | null | Uint8Array)[] = []): number {if (!this.db) {throw new Error('Database not initialized');}diff --git a/browser-extensions/chrome/src/utils/SrpUtility.tsx b/browser-extensions/chrome/src/utils/SrpUtility.tsxindex 10692974d..edbf535e7 100644--- a/browser-extensions/chrome/src/utils/SrpUtility.tsx+++ b/browser-extensions/chrome/src/utils/SrpUtility.tsx@@ -1,12 +1,7 @@import srp from 'secure-remote-password/client'import { WebApiService } from './WebApiService';--interface LoginInitiateResponse {- salt: string;- serverEphemeral: string;- encryptionType: string;- encryptionSettings: string;-}+import { LoginRequest, LoginResponse } from '../types/webapi/Login';+import { ValidateLoginRequest } from '../types/webapi/ValidateLogin';interface ValidateLoginResponse {requiresTwoFactor: boolean;@@ -27,8 +22,8 @@ class SrpUtility {this.webApiService = webApiService;}- public async initiateLogin(username: string): Promise<LoginInitiateResponse> {- return this.webApiService.post('Auth/login', {+ public async initiateLogin(username: string): Promise<LoginResponse> {+ return this.webApiService.post<LoginRequest, LoginResponse>('Auth/login', {username: username.toLowerCase().trim()});}@@ -37,7 +32,7 @@ class SrpUtility {username: string,passwordHashString: string,rememberMe: boolean,- loginResponse: LoginInitiateResponse+ loginResponse: LoginResponse): Promise<ValidateLoginResponse> {// Generate client ephemeralconst clientEphemeral = srp.generateEphemeral()@@ -54,7 +49,7 @@ class SrpUtility {privateKey);- return this.webApiService.post('Auth/validate', {+ return this.webApiService.post<ValidateLoginRequest, ValidateLoginResponse>('Auth/validate', {username: username.toLowerCase().trim(),rememberMe: rememberMe,clientPublicEphemeral: clientEphemeral.public,diff --git a/browser-extensions/chrome/src/utils/WebApiService.ts b/browser-extensions/chrome/src/utils/WebApiService.tsindex 3ffb57cf0..fc0e06fb2 100644--- a/browser-extensions/chrome/src/utils/WebApiService.ts+++ b/browser-extensions/chrome/src/utils/WebApiService.ts@@ -1,4 +1,4 @@-import { Buffer } from 'buffer';+type RequestInit = globalThis.RequestInit;interface TokenResponse {token: string;@@ -102,7 +102,7 @@ export class WebApiService {const tokenResponse: TokenResponse = await response.json();this.updateTokens(tokenResponse.token, tokenResponse.refreshToken);return tokenResponse.token;- } catch (error) {+ } catch {this.handleLogout();return null;}@@ -113,8 +113,8 @@ export class WebApiService {return this.fetch<T>(endpoint, { method: 'GET' });}- public async post<T>(endpoint: string, data: any): Promise<T> {- return this.fetch<T>(endpoint, {+ public async post<TRequest, TResponse>(endpoint: string, data: TRequest): Promise<TResponse> {+ return this.fetch<TResponse>(endpoint, {method: 'POST',headers: {'Content-Type': 'application/json',@@ -123,8 +123,8 @@ export class WebApiService {});}- public async put<T>(endpoint: string, data: any): Promise<T> {- return this.fetch<T>(endpoint, {+ public async put<TRequest, TResponse>(endpoint: string, data: TRequest): Promise<TResponse> {+ return this.fetch<TResponse>(endpoint, {method: 'PUT',headers: {'Content-Type': 'application/json',