add verify steps
This commit is contained in:
@@ -947,4 +947,34 @@ class Nostr {
|
||||
throw IllegalStateException("Failed to search nostr: ${e.message}", e)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun verifyAddress(pubkey: PublicKey, address: String): Boolean {
|
||||
try {
|
||||
val address = Nip05Address.parse(address)
|
||||
val profile = profileFromAddress(HttpClient(), address)
|
||||
|
||||
return profile.publicKey() == pubkey
|
||||
} catch (e: Exception) {
|
||||
throw IllegalStateException("Failed to verify address: ${e.message}", e)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun verifyActivity(pubkey: PublicKey): Timestamp? {
|
||||
try {
|
||||
val filter = Filter().author(pubkey).limit(3u)
|
||||
val target = mutableMapOf<RelayUrl, List<Filter>>()
|
||||
NostrManager.BOOTSTRAP_RELAYS.forEach { relay ->
|
||||
target[RelayUrl.parse(relay)] = listOf(filter)
|
||||
}
|
||||
|
||||
val events = client?.fetchEvents(
|
||||
target = ReqTarget.manual(target),
|
||||
timeout = Duration.parse("3s")
|
||||
)
|
||||
|
||||
return events?.first()?.createdAt()
|
||||
} catch (e: Exception) {
|
||||
throw IllegalStateException("Failed to get latest activity: ${e.message}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import rust.nostr.sdk.PublicKey
|
||||
import rust.nostr.sdk.RelayMetadata
|
||||
import rust.nostr.sdk.RelayUrl
|
||||
import rust.nostr.sdk.Tag
|
||||
import rust.nostr.sdk.Timestamp
|
||||
import rust.nostr.sdk.UnsignedEvent
|
||||
import su.reya.coop.blossom.BlossomClient
|
||||
import su.reya.coop.storage.SecretStorage
|
||||
@@ -820,6 +821,24 @@ class NostrViewModel(
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
suspend fun verifyAddress(pubkey: PublicKey, address: String): Boolean {
|
||||
return try {
|
||||
nostr.verifyAddress(pubkey, address)
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun verifyActivity(pubkey: PublicKey): Timestamp? {
|
||||
return try {
|
||||
nostr.verifyActivity(pubkey)
|
||||
} catch (e: Exception) {
|
||||
showError("Error: ${e.message}")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun PublicKey.short(): String {
|
||||
|
||||
Reference in New Issue
Block a user