Skip to content

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

Add common credentials query (#541)

Leendert de Borst322b5da793aa
diff --git a/browser-extensions/chrome/src/background.ts b/browser-extensions/chrome/src/background.ts
index 002faba2e..fbea2e126 100644
--- a/browser-extensions/chrome/src/background.ts
+++ b/browser-extensions/chrome/src/background.ts
@@ -1,7 +1,6 @@
import { Buffer } from 'buffer';
import EncryptionUtility from './utils/EncryptionUtility';
import SqliteClient from './utils/SqliteClient';
-import { Credential } from './types/Credential';
let vaultState: {
sessionKey: string | null;
@@ -106,21 +105,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
await sqliteClient.initializeFromBase64(decryptedVault);
// Query credentials with their related service information
- const credentials: Credential[] = sqliteClient.executeQuery(`
- SELECT
- c.Id,
- c.Username,
- c.ServiceId,
- s.Name as ServiceName,
- s.Url as ServiceUrl,
- s.Logo as Logo,
- MAX(p.Value) as Password
- FROM Credentials c
- JOIN Services s ON s.Id = c.ServiceId
- LEFT JOIN Passwords p ON p.CredentialId = c.Id
- WHERE c.IsDeleted = 0
- GROUP BY c.Id, c.Username, c.ServiceId, s.Name, s.Url, s.Logo
- `);
+ const credentials = sqliteClient.getAllCredentials();
// Filter credentials that match the current domain
/*
diff --git a/browser-extensions/chrome/src/pages/CredentialsList.tsx b/browser-extensions/chrome/src/pages/CredentialsList.tsx
index 7f047f211..2c7d3c039 100644
--- a/browser-extensions/chrome/src/pages/CredentialsList.tsx
+++ b/browser-extensions/chrome/src/pages/CredentialsList.tsx
@@ -1,14 +1,8 @@
import React, { useState, useEffect } from 'react';
import { useDb } from '../context/DbContext';
+import { Credential } from '../types/Credential';
import { Buffer } from 'buffer';
-type Credential = {
- Id: string;
- ServiceName: string;
- Username: string;
- Logo?: Uint8Array;
-}
-
type CredentialsListProps = {
base64Encode: (buffer: Uint8Array) => string | null;
}
@@ -16,7 +10,7 @@ type CredentialsListProps = {
/**
* Credentials list page
*/
-const CredentialsList: React.FC<CredentialsListProps> = ({ base64Encode }) => {
+const CredentialsList: React.FC<CredentialsListProps> = () => {
const dbContext = useDb();
const [credentials, setCredentials] = useState<Credential[]>([]);
@@ -24,16 +18,7 @@ const CredentialsList: React.FC<CredentialsListProps> = ({ base64Encode }) => {
if (!dbContext?.sqliteClient) return;
try {
- const results = dbContext.sqliteClient.executeQuery<Credential>(
- `SELECT
- c.Id,
- c.Username as Username,
- s.Name as ServiceName,
- s.Logo as Logo
- FROM Credentials c
- JOIN Services s ON s.Id = c.ServiceId
- WHERE c.IsDeleted = 0`
- );
+ const results = dbContext.sqliteClient.getAllCredentials();
setCredentials(results);
} catch (err) {
console.error('Error loading credentials:', err);
diff --git a/browser-extensions/chrome/src/pages/Unlock.tsx b/browser-extensions/chrome/src/pages/Unlock.tsx
index 815e15b2d..3088f987c 100644
--- a/browser-extensions/chrome/src/pages/Unlock.tsx
+++ b/browser-extensions/chrome/src/pages/Unlock.tsx
@@ -30,10 +30,6 @@ const Unlock: React.FC = () => {
try {
// 1. Initiate login to get salt and server ephemeral
- /*
- * TODO: adding encryption settings to vault response would save a call to the server.
- * Check how WASM client does this? Should we store the settings in localstorage instead?
- */
const loginResponse = await srpUtil.initiateLogin(username!);
// Derive key from password using user's encryption settings
diff --git a/browser-extensions/chrome/src/types/Credential.ts b/browser-extensions/chrome/src/types/Credential.ts
index 2f0d816dc..0b6f56687 100644
--- a/browser-extensions/chrome/src/types/Credential.ts
+++ b/browser-extensions/chrome/src/types/Credential.ts
@@ -1,7 +1,3 @@
-/*
- * 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 type Credential = {
Id: string;
Username: string;
diff --git a/browser-extensions/chrome/src/utils/SqliteClient.tsx b/browser-extensions/chrome/src/utils/SqliteClient.tsx
index 410f1c6fb..1a6df0190 100644
--- a/browser-extensions/chrome/src/utils/SqliteClient.tsx
+++ b/browser-extensions/chrome/src/utils/SqliteClient.tsx
@@ -1,4 +1,5 @@
import initSqlJs, { Database } from 'sql.js';
+import { Credential } from '../types/Credential';
/**
* Client for interacting with the SQLite database.
@@ -94,6 +95,28 @@ class SqliteClient {
this.db = null;
}
}
+
+ /**
+ * Fetch all credentials with their associated service information
+ * @returns Array of Credential objects with service details
+ */
+ public getAllCredentials(): Credential[] {
+ return this.executeQuery<Credential>(`
+ SELECT
+ c.Id,
+ c.Username,
+ c.ServiceId,
+ s.Name as ServiceName,
+ s.Url as ServiceUrl,
+ s.Logo as Logo,
+ MAX(p.Value) as Password
+ FROM Credentials c
+ JOIN Services s ON s.Id = c.ServiceId
+ LEFT JOIN Passwords p ON p.CredentialId = c.Id
+ WHERE c.IsDeleted = 0
+ GROUP BY c.Id, c.Username, c.ServiceId, s.Name, s.Url, s.Logo
+ `);
+ }
}
export default SqliteClient;
\ No newline at end of file