mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-29 12:02:45 +02:00
Making the new signer work for readonly accounts
This commit is contained in:
@@ -40,7 +40,9 @@ class AuthCoordinator(
|
|||||||
val receiver =
|
val receiver =
|
||||||
RelayAuthenticator(client, scope) { challenge, relay ->
|
RelayAuthenticator(client, scope) { challenge, relay ->
|
||||||
authWithAccounts.distinct().forEach {
|
authWithAccounts.distinct().forEach {
|
||||||
it.sendAuthEvent(relay, challenge)
|
if (it.isWriteable()) {
|
||||||
|
it.sendAuthEvent(relay, challenge)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@ import com.vitorpamplona.quartz.utils.TimeUtils
|
|||||||
abstract class DecryptCache<I : Any, T : Any>(
|
abstract class DecryptCache<I : Any, T : Any>(
|
||||||
val signer: NostrSigner,
|
val signer: NostrSigner,
|
||||||
) {
|
) {
|
||||||
|
val dontTryAgain = CacheResults.DontTryAgain<T>()
|
||||||
var cache: CacheResults<T> = CacheResults.CanTryAgain(0)
|
var cache: CacheResults<T> = CacheResults.CanTryAgain(0)
|
||||||
|
|
||||||
fun preload(result: T) {
|
fun preload(result: T) {
|
||||||
@@ -45,14 +46,18 @@ abstract class DecryptCache<I : Any, T : Any>(
|
|||||||
val response = decryptAndParse(input, signer)
|
val response = decryptAndParse(input, signer)
|
||||||
cache = CacheResults.Success(response)
|
cache = CacheResults.Success(response)
|
||||||
return 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) {
|
} catch (e: SignerExceptions.NothingToDecrypt) {
|
||||||
Log.w("DecryptCache", "Nothing to decrypt", e)
|
Log.w("DecryptCache", "Nothing to decrypt", e)
|
||||||
// ciphertext is blank. Cancels everything.
|
// ciphertext is blank. Cancels everything.
|
||||||
cache = CacheResults.DontTryAgain()
|
cache = dontTryAgain
|
||||||
} catch (e: SignerExceptions.AutomaticallyUnauthorizedException) {
|
} catch (e: SignerExceptions.AutomaticallyUnauthorizedException) {
|
||||||
Log.w("DecryptCache", "NothAutomaticallyUnauthorizedException", e)
|
Log.w("DecryptCache", "NothAutomaticallyUnauthorizedException", e)
|
||||||
// User has rejected this permission. Don't try again.
|
// User has rejected this permission. Don't try again.
|
||||||
cache = CacheResults.DontTryAgain<T>()
|
cache = dontTryAgain
|
||||||
} catch (e: SignerExceptions.ManuallyUnauthorizedException) {
|
} catch (e: SignerExceptions.ManuallyUnauthorizedException) {
|
||||||
Log.w("DecryptCache", "ManuallyUnauthorizedException", e)
|
Log.w("DecryptCache", "ManuallyUnauthorizedException", e)
|
||||||
// User has rejected this permission. Don't try again.
|
// User has rejected this permission. Don't try again.
|
||||||
@@ -64,11 +69,11 @@ abstract class DecryptCache<I : Any, T : Any>(
|
|||||||
} catch (e: SignerExceptions.CouldNotPerformException) {
|
} catch (e: SignerExceptions.CouldNotPerformException) {
|
||||||
// Log.w("DecryptCache", "CouldNotPerformException", e)
|
// Log.w("DecryptCache", "CouldNotPerformException", e)
|
||||||
// Decryption failed. This key might not be able to decrypt anything. Don't try again.
|
// Decryption failed. This key might not be able to decrypt anything. Don't try again.
|
||||||
cache = CacheResults.DontTryAgain<T>()
|
cache = dontTryAgain
|
||||||
} catch (e: SignerExceptions.SignerNotFoundException) {
|
} catch (e: SignerExceptions.SignerNotFoundException) {
|
||||||
Log.w("DecryptCache", "SignerNotFoundException", e)
|
Log.w("DecryptCache", "SignerNotFoundException", e)
|
||||||
// Signer app was deleted. Not sure what to to. It should probably log off.
|
// Signer app was deleted. Not sure what to to. It should probably log off.
|
||||||
cache = CacheResults.DontTryAgain<T>()
|
cache = dontTryAgain
|
||||||
} catch (e: SignerExceptions.RunningOnBackgroundWithoutAutomaticPermissionException) {
|
} catch (e: SignerExceptions.RunningOnBackgroundWithoutAutomaticPermissionException) {
|
||||||
Log.w("DecryptCache", "RunningOnBackgroundWithoutAutomaticPermissionException", e)
|
Log.w("DecryptCache", "RunningOnBackgroundWithoutAutomaticPermissionException", e)
|
||||||
// App received a notifications, asked the signer to decrypt but the permission was not automatic.
|
// App received a notifications, asked the signer to decrypt but the permission was not automatic.
|
||||||
@@ -77,13 +82,13 @@ abstract class DecryptCache<I : Any, T : Any>(
|
|||||||
} catch (e: com.fasterxml.jackson.core.JsonParseException) {
|
} catch (e: com.fasterxml.jackson.core.JsonParseException) {
|
||||||
Log.w("DecryptCache", "JsonParseException", e)
|
Log.w("DecryptCache", "JsonParseException", e)
|
||||||
// Decryption failed. This key might not be able to decrypt anything. Don't try again.
|
// Decryption failed. This key might not be able to decrypt anything. Don't try again.
|
||||||
cache = CacheResults.DontTryAgain()
|
cache = dontTryAgain
|
||||||
} catch (e: IllegalStateException) {
|
} catch (e: IllegalStateException) {
|
||||||
Log.w("DecryptCache", "IllegalStateException", e)
|
Log.w("DecryptCache", "IllegalStateException", e)
|
||||||
cache = CacheResults.DontTryAgain()
|
cache = dontTryAgain
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
Log.w("DecryptCache", "IllegalArgumentException", e)
|
Log.w("DecryptCache", "IllegalArgumentException", e)
|
||||||
cache = CacheResults.DontTryAgain()
|
cache = dontTryAgain
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user