From 96f0ca9d9eae10fb70751b74384eba39b1dacc4f Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Sat, 6 Jun 2026 14:13:38 +0700 Subject: [PATCH] add timeout when switch signer --- shared/src/commonMain/kotlin/su/reya/coop/Signer.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shared/src/commonMain/kotlin/su/reya/coop/Signer.kt b/shared/src/commonMain/kotlin/su/reya/coop/Signer.kt index 5e87674..b89df78 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/Signer.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/Signer.kt @@ -2,10 +2,12 @@ package su.reya.coop import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock +import kotlinx.coroutines.withTimeoutOrNull import rust.nostr.sdk.AsyncNostrSigner import rust.nostr.sdk.Event import rust.nostr.sdk.PublicKey import rust.nostr.sdk.UnsignedEvent +import kotlin.time.Duration.Companion.seconds class UniversalSigner(initialSigner: AsyncNostrSigner) : AsyncNostrSigner { private val mutex = Mutex() @@ -26,7 +28,13 @@ class UniversalSigner(initialSigner: AsyncNostrSigner) : AsyncNostrSigner { */ suspend fun switch(newSigner: AsyncNostrSigner) = mutex.withLock { signer = newSigner - currentUser = newSigner.getPublicKeyAsync() + try { + currentUser = withTimeoutOrNull(20.seconds) { + newSigner.getPublicKeyAsync() + } + } catch (e: Exception) { + throw IllegalStateException("Failed to get public key from signer", e) + } } override suspend fun getPublicKeyAsync(): PublicKey? {