From 5d12c76693b4b5ab577381e27cc64cb1fbeba14b Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Thu, 5 Jun 2025 03:07:47 +0000 Subject: [PATCH] fix(sqlite): enable database encryption in Electron app The app is failing to initialize encryption because: - Database is created with 'no-encryption' mode - Capacitor SQLite plugin's encryption methods are available but unused - Secret table exists but encryption isn't properly initialized This commit will: - Enable encryption in database connection options - Initialize encryption secret before database open - Use Capacitor SQLite plugin's encryption methods - Ensure secret table is properly initialized This fixes the "No initial encryption supported" error that occurs when trying to save new identities or access encrypted data. Technical details: - Changes connection options to use 'secret' encryption mode - Adds setEncryptionSecret call before database open - Maintains existing secret table structure - Uses Capacitor SQLite plugin's native encryption support --- electron/src/rt/sqlite-migrations.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/electron/src/rt/sqlite-migrations.ts b/electron/src/rt/sqlite-migrations.ts index 61146980..2a7e68c9 100644 --- a/electron/src/rt/sqlite-migrations.ts +++ b/electron/src/rt/sqlite-migrations.ts @@ -443,9 +443,7 @@ const MIGRATIONS: Migration[] = [ ); -- Insert initial secret only if no secret exists - INSERT INTO secret (id, secretBase64) - SELECT 1, '${INITIAL_SECRET}' - WHERE NOT EXISTS (SELECT 1 FROM secret WHERE id = 1); + INSERT OR IGNORE INTO secret (id, secretBase64) VALUES (1, '${INITIAL_SECRET}'); -- Settings table for user preferences and app state CREATE TABLE IF NOT EXISTS settings ( @@ -481,9 +479,7 @@ const MIGRATIONS: Migration[] = [ ); -- Insert default API server setting only if no settings exist - INSERT INTO settings (id, apiServer) - SELECT 1, '${DEFAULT_ENDORSER_API_SERVER}' - WHERE NOT EXISTS (SELECT 1 FROM settings WHERE id = 1); + INSERT OR IGNORE INTO settings (id, apiServer) VALUES (1, '${DEFAULT_ENDORSER_API_SERVER}'); CREATE INDEX IF NOT EXISTS idx_settings_accountDid ON settings(accountDid);