From e237853a8fbfc4bc38d29cfe9e31af1f8af0f877 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 5 Aug 2025 16:06:52 -0400 Subject: [PATCH] Making the new signer work for readonly accounts --- .../authCommand/model/AuthCoordinator.kt | 4 +++- .../nip01Core/signers/caches/DecryptCache.kt | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/authCommand/model/AuthCoordinator.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/authCommand/model/AuthCoordinator.kt index b88057692..1c9598817 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/authCommand/model/AuthCoordinator.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/authCommand/model/AuthCoordinator.kt @@ -40,7 +40,9 @@ class AuthCoordinator( val receiver = RelayAuthenticator(client, scope) { challenge, relay -> authWithAccounts.distinct().forEach { - it.sendAuthEvent(relay, challenge) + if (it.isWriteable()) { + it.sendAuthEvent(relay, challenge) + } } } diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/signers/caches/DecryptCache.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/signers/caches/DecryptCache.kt index eb8400249..05fc16b4c 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/signers/caches/DecryptCache.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/nip01Core/signers/caches/DecryptCache.kt @@ -29,6 +29,7 @@ import com.vitorpamplona.quartz.utils.TimeUtils abstract class DecryptCache( val signer: NostrSigner, ) { + val dontTryAgain = CacheResults.DontTryAgain() var cache: CacheResults = CacheResults.CanTryAgain(0) fun preload(result: T) { @@ -45,14 +46,18 @@ abstract class DecryptCache( val response = decryptAndParse(input, signer) cache = CacheResults.Success(response) return response + } catch (e: SignerExceptions.ReadOnlyException) { + // Log.w("DecryptCache", "Read only user", e) + // ciphertext is blank. Cancels everything. + cache = dontTryAgain } catch (e: SignerExceptions.NothingToDecrypt) { Log.w("DecryptCache", "Nothing to decrypt", e) // ciphertext is blank. Cancels everything. - cache = CacheResults.DontTryAgain() + cache = dontTryAgain } catch (e: SignerExceptions.AutomaticallyUnauthorizedException) { Log.w("DecryptCache", "NothAutomaticallyUnauthorizedException", e) // User has rejected this permission. Don't try again. - cache = CacheResults.DontTryAgain() + cache = dontTryAgain } catch (e: SignerExceptions.ManuallyUnauthorizedException) { Log.w("DecryptCache", "ManuallyUnauthorizedException", e) // User has rejected this permission. Don't try again. @@ -64,11 +69,11 @@ abstract class DecryptCache( } catch (e: SignerExceptions.CouldNotPerformException) { // Log.w("DecryptCache", "CouldNotPerformException", e) // Decryption failed. This key might not be able to decrypt anything. Don't try again. - cache = CacheResults.DontTryAgain() + cache = dontTryAgain } catch (e: SignerExceptions.SignerNotFoundException) { Log.w("DecryptCache", "SignerNotFoundException", e) // Signer app was deleted. Not sure what to to. It should probably log off. - cache = CacheResults.DontTryAgain() + cache = dontTryAgain } catch (e: SignerExceptions.RunningOnBackgroundWithoutAutomaticPermissionException) { Log.w("DecryptCache", "RunningOnBackgroundWithoutAutomaticPermissionException", e) // App received a notifications, asked the signer to decrypt but the permission was not automatic. @@ -77,13 +82,13 @@ abstract class DecryptCache( } catch (e: com.fasterxml.jackson.core.JsonParseException) { Log.w("DecryptCache", "JsonParseException", e) // Decryption failed. This key might not be able to decrypt anything. Don't try again. - cache = CacheResults.DontTryAgain() + cache = dontTryAgain } catch (e: IllegalStateException) { Log.w("DecryptCache", "IllegalStateException", e) - cache = CacheResults.DontTryAgain() + cache = dontTryAgain } catch (e: IllegalArgumentException) { Log.w("DecryptCache", "IllegalArgumentException", e) - cache = CacheResults.DontTryAgain() + cache = dontTryAgain } return null }