diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt index 227084702..2fc27f7c4 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/NostrDataSource.kt @@ -17,6 +17,7 @@ import com.vitorpamplona.amethyst.service.model.RepostEvent import com.vitorpamplona.amethyst.service.relays.Client import com.vitorpamplona.amethyst.service.relays.Relay import com.vitorpamplona.amethyst.service.relays.Subscription +import com.vitorpamplona.amethyst.service.relays.hasValidSignature import java.util.Date import java.util.UUID import kotlinx.coroutines.CoroutineScope @@ -48,6 +49,8 @@ abstract class NostrDataSource(val debugName: String) { private val clientListener = object : Client.Listener() { override fun onEvent(event: Event, subscriptionId: String, relay: Relay) { if (subscriptionId in subscriptions.keys) { + if (!event.hasValidSignature()) return + val key = "${debugName} ${subscriptionId} ${event.kind}" val keyValue = eventCounter.get(key) if (keyValue != null) { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/relays/EventVerifier.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/relays/EventVerifier.kt new file mode 100644 index 000000000..3bbab0e16 --- /dev/null +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/relays/EventVerifier.kt @@ -0,0 +1,16 @@ +package com.vitorpamplona.amethyst.service.relays + +import fr.acinq.secp256k1.Secp256k1 +import nostr.postr.events.Event +import nostr.postr.events.generateId + +fun Event.hasValidSignature(): Boolean { + if (!id.contentEquals(generateId())) { + return false + } + if (!Secp256k1.get().verifySchnorr(sig, id, pubKey)) { + return false + } + + return true +} \ No newline at end of file