Skip to content

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

Add sqlite client (#541)

Leendert de Borst483792ebb09c
diff --git a/browser-extensions/chrome/package-lock.json b/browser-extensions/chrome/package-lock.json
index 0646091aa..8da83b41e 100644
--- a/browser-extensions/chrome/package-lock.json
+++ b/browser-extensions/chrome/package-lock.json
@@ -13,11 +13,13 @@
"buffer": "^6.0.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
- "secure-remote-password": "github:LinusU/secure-remote-password#73e5f732b6ca0cdbdc19da1a0c5f48cdbad2cbf0"
+ "secure-remote-password": "github:LinusU/secure-remote-password#73e5f732b6ca0cdbdc19da1a0c5f48cdbad2cbf0",
+ "sql.js": "^1.12.0"
},
"devDependencies": {
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
+ "@types/sql.js": "^1.4.9",
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.20",
"postcss": "^8.5.1",
@@ -1182,6 +1184,13 @@
"@babel/types": "^7.20.7"
}
},
+ "node_modules/@types/emscripten": {
+ "version": "1.40.0",
+ "resolved": "https://registry.npmjs.org/@types/emscripten/-/emscripten-1.40.0.tgz",
+ "integrity": "sha512-MD2JJ25S4tnjnhjWyalMS6K6p0h+zQV6+Ylm+aGbiS8tSn/aHLSGNzBgduj6FB4zH0ax2GRMGYi/8G1uOxhXWA==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/@types/estree": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz",
@@ -1189,6 +1198,16 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@types/node": {
+ "version": "22.10.10",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.10.tgz",
+ "integrity": "sha512-X47y/mPNzxviAGY5TcYPtYL8JsY3kAq2n8fMmKoRCxq/c4v4pyGNCzM2R6+M5/umG4ZfHuT+sgqDYqWc9rJ6ww==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "undici-types": "~6.20.0"
+ }
+ },
"node_modules/@types/react": {
"version": "19.0.7",
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.0.7.tgz",
@@ -1209,6 +1228,17 @@
"@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/@vitejs/plugin-react": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-4.3.4.tgz",
@@ -2756,6 +2786,12 @@
"node": ">=0.10.0"
}
},
+ "node_modules/sql.js": {
+ "version": "1.12.0",
+ "resolved": "https://registry.npmjs.org/sql.js/-/sql.js-1.12.0.tgz",
+ "integrity": "sha512-Bi+43yMx/tUFZVYD4AUscmdL6NHn3gYQ+CM+YheFWLftOmrEC/Mz6Yh7E96Y2WDHYz3COSqT+LP6Z79zgrwJlA==",
+ "license": "MIT"
+ },
"node_modules/string-width": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
@@ -2991,6 +3027,13 @@
"node": ">=14.17"
}
},
+ "node_modules/undici-types": {
+ "version": "6.20.0",
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
+ "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/universalify": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
diff --git a/browser-extensions/chrome/package.json b/browser-extensions/chrome/package.json
index c4d8c8d0a..8c5b281df 100644
--- a/browser-extensions/chrome/package.json
+++ b/browser-extensions/chrome/package.json
@@ -17,11 +17,13 @@
"buffer": "^6.0.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
- "secure-remote-password": "github:LinusU/secure-remote-password#73e5f732b6ca0cdbdc19da1a0c5f48cdbad2cbf0"
+ "secure-remote-password": "github:LinusU/secure-remote-password#73e5f732b6ca0cdbdc19da1a0c5f48cdbad2cbf0",
+ "sql.js": "^1.12.0"
},
"devDependencies": {
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
+ "@types/sql.js": "^1.4.9",
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.20",
"postcss": "^8.5.1",
diff --git a/browser-extensions/chrome/src/components/Login.tsx b/browser-extensions/chrome/src/components/Login.tsx
index 5d5bc20d0..9a289b236 100644
--- a/browser-extensions/chrome/src/components/Login.tsx
+++ b/browser-extensions/chrome/src/components/Login.tsx
@@ -3,6 +3,7 @@ import Button from './Button';
import { Buffer } from 'buffer';
import { srpUtility } from '../utilities/SrpUtility';
import EncryptionUtility from '../utilities/EncryptionUtility';
+import SqliteClient from '../utilities/SqliteClient';
const Login: React.FC = () => {
const [credentials, setCredentials] = useState({
@@ -72,6 +73,17 @@ const Login: React.FC = () => {
console.log('Decrypted blob:');
console.log(decryptedBlob);
+ // Inside your handleSubmit function, after decrypting the blob:
+ const sqliteClient = new SqliteClient();
+ await sqliteClient.initializeFromBase64(decryptedBlob);
+
+ // Example query to test the connection
+ const vaultCredentials = sqliteClient.executeQuery('SELECT * FROM Credentials WHERE IsDeleted = 0');
+ console.log('Credentials:', vaultCredentials);
+
+ // Don't forget to close the connection when done
+ sqliteClient.close();
+
// 3. Handle 2FA if required
/*if (validationResponse.requiresTwoFactor) {
diff --git a/browser-extensions/chrome/src/utilities/SqliteClient.tsx b/browser-extensions/chrome/src/utilities/SqliteClient.tsx
new file mode 100644
index 000000000..c0a4b851e
--- /dev/null
+++ b/browser-extensions/chrome/src/utilities/SqliteClient.tsx
@@ -0,0 +1,88 @@
+import initSqlJs from 'sql.js';
+
+class SqliteClient {
+ private db: any = null;
+
+ /**
+ * Initialize the SQLite database from a base64 string
+ */
+ public async initializeFromBase64(base64String: string): Promise<void> {
+ try {
+ // Convert base64 to Uint8Array
+ const binaryString = window.atob(base64String);
+ const bytes = new Uint8Array(binaryString.length);
+ for (let i = 0; i < binaryString.length; i++) {
+ bytes[i] = binaryString.charCodeAt(i);
+ }
+
+ // Initialize SQL.js
+ const SQL = await initSqlJs({
+ locateFile: file => `https://sql.js.org/dist/${file}`
+ });
+
+ // Create database from the binary data
+ this.db = new SQL.Database(bytes);
+ } catch (error) {
+ console.error('Error initializing SQLite database:', error);
+ throw error;
+ }
+ }
+
+ /**
+ * Execute a SELECT query
+ */
+ public executeQuery<T>(query: string, params: any[] = []): T[] {
+ if (!this.db) {
+ throw new Error('Database not initialized');
+ }
+
+ try {
+ const stmt = this.db.prepare(query);
+ stmt.bind(params);
+
+ const results: T[] = [];
+ while (stmt.step()) {
+ results.push(stmt.getAsObject());
+ }
+ stmt.free();
+
+ return results;
+ } catch (error) {
+ console.error('Error executing query:', error);
+ throw error;
+ }
+ }
+
+ /**
+ * Execute an INSERT, UPDATE, or DELETE query
+ */
+ public executeUpdate(query: string, params: any[] = []): number {
+ if (!this.db) {
+ throw new Error('Database not initialized');
+ }
+
+ try {
+ const stmt = this.db.prepare(query);
+ stmt.bind(params);
+ stmt.step();
+ const changes = this.db.getRowsModified();
+ stmt.free();
+ return changes;
+ } catch (error) {
+ console.error('Error executing update:', error);
+ throw error;
+ }
+ }
+
+ /**
+ * Close the database connection and free resources
+ */
+ public close(): void {
+ if (this.db) {
+ this.db.close();
+ this.db = null;
+ }
+ }
+}
+
+export default SqliteClient;
\ No newline at end of file