From 21030cd2fb6988bfaa3b1cf06ca9ab5b394b0e3e Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Tue, 5 Nov 2024 09:41:52 +0000 Subject: [PATCH] Revert "Fix relay auth and content resolver" --- app/src/main/AndroidManifest.xml | 5 -- .../koalasat/pokey/models/EncryptedStorage.kt | 10 ---- .../koalasat/pokey/models/ExternalSigner.kt | 47 ++++++++++--------- .../pokey/service/NotificationsService.kt | 1 - 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 987347a..578dc88 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,11 +14,6 @@ - - - - - get() = _notifyResposts private val _notifyFollows = MutableLiveData().apply { DefaultKeys.NOTIFY_FOLLOWS } val notifyFollows: LiveData get() = _notifyFollows - private val _externalSigner = MutableLiveData().apply { DefaultKeys.EXTERNAL_SIGNER } - val externalSigner: LiveData get() = _externalSigner fun init(context: Context) { val masterKey: MasterKey = @@ -86,12 +82,6 @@ object EncryptedStorage { _notifyMentions.value = sharedPreferences.getBoolean(PrefKeys.NOTIFY_MENTIONS, DefaultKeys.NOTIFY_MENTIONS) _notifyResposts.value = sharedPreferences.getBoolean(PrefKeys.NOTIFY_REPOSTS, DefaultKeys.NOTIFY_REPOSTS) _notifyFollows.value = sharedPreferences.getBoolean(PrefKeys.NOTIFY_FOLLOWS, DefaultKeys.NOTIFY_FOLLOWS) - _externalSigner.value = sharedPreferences.getString(PrefKeys.EXTERNAL_SIGNER, DefaultKeys.EXTERNAL_SIGNER) ?: DefaultKeys.EXTERNAL_SIGNER - } - - fun updateExternalSigner(newValue: String) { - sharedPreferences.edit().putString(PrefKeys.EXTERNAL_SIGNER, newValue).apply() - _externalSigner.value = newValue } fun updatePubKey(newValue: String) { diff --git a/app/src/main/java/com/koalasat/pokey/models/ExternalSigner.kt b/app/src/main/java/com/koalasat/pokey/models/ExternalSigner.kt index 1803d75..596e25f 100644 --- a/app/src/main/java/com/koalasat/pokey/models/ExternalSigner.kt +++ b/app/src/main/java/com/koalasat/pokey/models/ExternalSigner.kt @@ -9,9 +9,9 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import com.koalasat.pokey.Pokey import com.koalasat.pokey.R -import com.vitorpamplona.quartz.events.RelayAuthEvent +import com.vitorpamplona.quartz.encoders.toHexKey +import com.vitorpamplona.quartz.events.Event import com.vitorpamplona.quartz.signers.ExternalSignerLauncher -import com.vitorpamplona.quartz.signers.NostrSignerExternal import com.vitorpamplona.quartz.signers.SignerType import com.vitorpamplona.quartz.utils.TimeUtils import java.util.UUID @@ -19,7 +19,7 @@ import kotlin.coroutines.cancellation.CancellationException object ExternalSigner { private lateinit var nostrSignerLauncher: ActivityResultLauncher - private lateinit var externalSignerLauncher: NostrSignerExternal + private lateinit var externalSignerLauncher: ExternalSignerLauncher fun init(activity: AppCompatActivity) { nostrSignerLauncher = activity.registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> @@ -27,7 +27,7 @@ object ExternalSigner { Log.e("Pokey", "ExternalSigner result error: ${result.resultCode}") Toast.makeText(activity, activity.getString(R.string.amber_not_found), Toast.LENGTH_SHORT).show() } else { - result.data?.let { externalSignerLauncher.launcher.newResult(it) } + result.data?.let { externalSignerLauncher.newResult(it) } } } @@ -35,7 +35,7 @@ object ExternalSigner { } fun savePubKey() { - externalSignerLauncher.launcher.openSignerApp( + externalSignerLauncher.openSignerApp( "", SignerType.GET_PUBLIC_KEY, "", @@ -45,15 +45,13 @@ object ExternalSigner { val pubkey = split.first() if (split.first().isNotEmpty()) { EncryptedStorage.updatePubKey(pubkey) - if (split.size > 1) { - EncryptedStorage.updateExternalSigner(split[1]) - } startLauncher() } } } - fun auth(relayUrl: String, challenge: String, onReady: (RelayAuthEvent) -> Unit) { + fun auth(relayUrl: String, challenge: String, onReady: (String) -> Unit) { + val pubKey = Pokey.getInstance().getHexKey() val createdAt = TimeUtils.now() val kind = 22242 val content = "" @@ -62,23 +60,28 @@ object ExternalSigner { arrayOf("relay", relayUrl), arrayOf("challenge", challenge), ) - - externalSignerLauncher.sign( - createdAt = createdAt, - kind = kind, - tags = tags, - content = content, - onReady = onReady, + val id = Event.generateId(pubKey, createdAt, kind, tags, content).toHexKey() + val event = + Event( + id = id, + pubKey = pubKey, + createdAt = createdAt, + kind = kind, + tags = tags, + content = content, + sig = "", + ) + externalSignerLauncher.openSigner( + event, + onReady, ) } private fun startLauncher() { - val pubKey = Pokey.getInstance().getHexKey() - var externalSignerPackage = EncryptedStorage.externalSigner.value - if (externalSignerPackage == null) externalSignerPackage = "" - if (pubKey.isEmpty()) externalSignerPackage = "" - externalSignerLauncher = NostrSignerExternal(pubKey, ExternalSignerLauncher(pubKey, signerPackageName = externalSignerPackage)) - externalSignerLauncher.launcher.registerLauncher( + var pubKey = EncryptedStorage.pubKey.value + if (pubKey == null) pubKey = "" + externalSignerLauncher = ExternalSignerLauncher(pubKey, signerPackageName = "") + externalSignerLauncher.registerLauncher( launcher = { try { nostrSignerLauncher.launch(it) diff --git a/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt b/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt index 8b26571..16228b8 100644 --- a/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt +++ b/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt @@ -64,7 +64,6 @@ class NotificationsService : Service() { override fun onAuth(relay: Relay, challenge: String) { Log.d("Pokey", "Relay on Auth: ${relay.url} : $challenge") ExternalSigner.auth(relay.url, challenge) { result -> - Client.sendIfExists(result, relay) Log.d("Pokey", "Relay on Auth response: ${relay.url} : $result") } }