Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add credential create scaffolding (#541)
Leendert de Borst254b9c0a4950
diff --git a/browser-extensions/chrome/src/background.ts b/browser-extensions/chrome/src/background.tsindex e09215a8d..9bfde0f7a 100644--- a/browser-extensions/chrome/src/background.ts+++ b/browser-extensions/chrome/src/background.ts@@ -190,6 +190,55 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {});break;}++ case 'CREATE_IDENTITY': {+ if (!vaultState.derivedKey) {+ sendResponse({ success: false, error: 'Vault is locked' });+ return;+ }++ chrome.storage.session.get(['encryptedVault'], async (result) => {+ try {+ if (!result.encryptedVault) {+ sendResponse({ success: false, error: 'No vault found' });+ return;+ }++ const decryptedVault = await EncryptionUtility.symmetricDecrypt(+ result.encryptedVault,+ vaultState.derivedKey!+ );++ // Initialize SQLite client+ const sqliteClient = new SqliteClient();+ await sqliteClient.initializeFromBase64(decryptedVault);++ // Create new credential with random identity+ const credential = message.credential;+ await sqliteClient.createCredential(credential);++ // Instead of sending a message, directly encrypt and store the updated vault+ const updatedVaultData = sqliteClient.exportToBase64();+ const encryptedVault = await EncryptionUtility.symmetricEncrypt(+ updatedVaultData,+ vaultState.derivedKey!+ );++ // Store in chrome.storage.session+ await chrome.storage.session.set({+ encryptedVault,+ publicEmailDomains: vaultState.publicEmailDomains,+ privateEmailDomains: vaultState.privateEmailDomains+ });++ sendResponse({ success: true });+ } catch (error) {+ console.error('Failed to create identity:', error);+ sendResponse({ success: false, error: 'Failed to create identity' });+ }+ });+ break;+ }}return true;});diff --git a/browser-extensions/chrome/src/contentScript.ts b/browser-extensions/chrome/src/contentScript.tsindex 5aa197a91..6dd9ce1ef 100644--- a/browser-extensions/chrome/src/contentScript.ts+++ b/browser-extensions/chrome/src/contentScript.ts@@ -288,14 +288,39 @@ function createPopup(input: HTMLInputElement, credentials: Credential[]) : voidconst passwordGenerator = new PasswordGenerator();const password = passwordGenerator.generateRandomPassword();- // create alert with all identity details+ // Submit new identity to backend to persist in db+ const credential: Credential = {+ Id: '',+ ServiceName: 'AliasVault1',+ ServiceUrl: 'https://aliasvault.com',+ Email: `${identity.emailPrefix}@${domain}`,+ Username: identity.nickName,+ Password: password,+ Notes: '',+ Alias: {+ FirstName: identity.firstName,+ LastName: identity.lastName,+ NickName: identity.nickName,+ BirthDate: identity.birthDate.toISOString(),+ Gender: identity.gender,+ Email: `${identity.emailPrefix}@${domain}`+ }+ };++ chrome.runtime.sendMessage({ type: 'CREATE_IDENTITY', credential });++ // create alert with confirmation messagealert(`+ New identity created successfully!First name: ${identity.firstName}Last name: ${identity.lastName}Gender: ${identity.gender}Email: ${identity.emailPrefix}@${domain}Password: ${password}`);++ // Refresh the popup to show new identity+ showCredentialPopup(input);});// Search buttondiff --git a/browser-extensions/chrome/src/utils/SqliteClient.tsx b/browser-extensions/chrome/src/utils/SqliteClient.tsxindex 973527ba9..633ac3606 100644--- a/browser-extensions/chrome/src/utils/SqliteClient.tsx+++ b/browser-extensions/chrome/src/utils/SqliteClient.tsx@@ -38,6 +38,31 @@ class SqliteClient {}}+ /**+ * Export the SQLite database to a base64 string+ * @returns Base64 encoded string of the database+ */+ public exportToBase64(): string {+ if (!this.db) {+ throw new Error('Database not initialized');+ }++ try {+ // Export database to Uint8Array+ const binaryArray = this.db.export();++ // Convert Uint8Array to base64 string+ let binaryString = '';+ for (let i = 0; i < binaryArray.length; i++) {+ binaryString += String.fromCharCode(binaryArray[i]);+ }+ return btoa(binaryString);+ } catch (error) {+ console.error('Error exporting SQLite database:', error);+ throw error;+ }+ }+/*** Execute a SELECT query*/@@ -153,6 +178,89 @@ class SqliteClient {x.IsPrimaryFROM EncryptionKeys x`);}++ /**+ * Create a new credential with associated entities+ * @param credential The credential object to insert+ * @returns The number of rows modified+ */+ public createCredential(credential: Credential): number {+ if (!this.db) {+ throw new Error('Database not initialized');+ }++ try {+ this.db.run('BEGIN TRANSACTION');++ // 1. Insert Service+ const serviceQuery = `+ INSERT INTO Services (Id, Name, Url, Logo, CreatedAt, UpdatedAt)+ VALUES (?, ?, ?, ?, ?, ?)`;+ const serviceResult = this.executeUpdate(serviceQuery, [+ crypto.randomUUID(),+ credential.ServiceName,+ credential.ServiceUrl ?? null,+ credential.Logo ?? null,+ new Date().toISOString(),+ new Date().toISOString()+ ]);+ const serviceId = this.db.exec('SELECT last_insert_rowid()')[0].values[0][0];++ // 2. Insert Alias+ const aliasQuery = `+ INSERT INTO Aliases (Id, FirstName, LastName, NickName, BirthDate, Gender, Email, CreatedAt, UpdatedAt)+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`;+ const aliasResult = this.executeUpdate(aliasQuery, [+ crypto.randomUUID(),+ credential.Alias.FirstName ?? null,+ credential.Alias.LastName ?? null,+ credential.Alias.NickName ?? null,+ credential.Alias.BirthDate ?? null,+ credential.Alias.Gender ?? null,+ credential.Alias.Email ?? null,+ new Date().toISOString(),+ new Date().toISOString()+ ]);+ const aliasId = this.db.exec('SELECT last_insert_rowid()')[0].values[0][0];++ // 3. Insert Credential+ const credentialQuery = `+ INSERT INTO Credentials (Id, Username, Notes, ServiceId, AliasId, CreatedAt, UpdatedAt)+ VALUES (?, ?, ?, ?, ?, ?, ?)`;+ const credentialResult = this.executeUpdate(credentialQuery, [+ crypto.randomUUID(),+ credential.Username,+ credential.Notes ?? null,+ serviceId,+ aliasId,+ new Date().toISOString(),+ new Date().toISOString()+ ]);+ const credentialId = this.db.exec('SELECT last_insert_rowid()')[0].values[0][0];++ // 4. Insert Password+ if (credential.Password) {+ const passwordQuery = `+ INSERT INTO Passwords (Id, Value, CredentialId, CreatedAt, UpdatedAt)+ VALUES (?, ?, ?, ?, ?)`;+ this.executeUpdate(passwordQuery, [+ crypto.randomUUID(),+ credential.Password,+ credentialId,+ new Date().toISOString(),+ new Date().toISOString()+ ]);+ }++ this.db.run('COMMIT');+ return 1;++ } catch (error) {+ this.db.run('ROLLBACK');+ console.error('Error creating credential:', error);+ throw error;+ }+ }}export default SqliteClient;\ No newline at end of file