diff --git a/AGENTS.md b/AGENTS.md index a8659a16a..3913a9aee 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -164,7 +164,8 @@ suspend fun getData(): Result = withContext(Dispatchers.IO) { - ALWAYS when fixing lint or test failures prefer to do the minimal amount of changes to fix the issues - USE single-line commit messages under 50 chars; use conventional commit messages template format: `feat: add something new` - USE `git diff HEAD sourceFilePath` to diff an uncommitted file against the last commit -- ALWAYS run `git status` to check ALL uncommitted changes after completing any code edits, then provide exactly 3 commit message suggestions covering the ENTIRE uncommitted diff +- NEVER capitalize words in commit messages +- ALWAYS run `git status` to check ALL uncommitted changes after completing any code edits, then reply with 3 commit message suggestions covering the ENTIRE uncommitted diff - ALWAYS check existing code patterns before implementing new features - USE existing extensions and utilities rather than creating new ones - ALWAYS consider applying YAGNI (You Ain't Gonna Need It) principle for new code diff --git a/app/src/main/java/to/bitkit/data/keychain/AndroidKeyStore.kt b/app/src/main/java/to/bitkit/data/keychain/AndroidKeyStore.kt index 8f9226669..3391df16e 100644 --- a/app/src/main/java/to/bitkit/data/keychain/AndroidKeyStore.kt +++ b/app/src/main/java/to/bitkit/data/keychain/AndroidKeyStore.kt @@ -28,7 +28,7 @@ class AndroidKeyStore( generateKey() } - private fun generateKey() { + private fun generateKey(alias: String = this.alias) { if (!keyStore.containsAlias(alias)) { try { val generator = KeyGenerator.getInstance(algorithm, type) @@ -80,4 +80,11 @@ class AndroidKeyStore( val decryptedDataBytes = cipher.doFinal(actualEncryptedData) return decryptedDataBytes } + + fun resetEncryptionKey() { + if (keyStore.containsAlias(alias)) { + keyStore.deleteEntry(alias) + } + generateKey() + } } diff --git a/app/src/main/java/to/bitkit/data/keychain/Keychain.kt b/app/src/main/java/to/bitkit/data/keychain/Keychain.kt index ad6e82997..9b777174a 100644 --- a/app/src/main/java/to/bitkit/data/keychain/Keychain.kt +++ b/app/src/main/java/to/bitkit/data/keychain/Keychain.kt @@ -96,8 +96,10 @@ class Keychain @Inject constructor( suspend fun wipe() { val keys = snapshot.asMap().keys keychain.edit { it.clear() } + keyStore.resetEncryptionKey() + val count = keys.size - Logger.info("Deleted all keychain entries: ${keys.joinToString()}") + Logger.info("Reset keychain encryption key and deleted all '$count' entries") } private val String.indexed: Preferences.Key