Simplifies NIP-05 processing

This commit is contained in:
Vitor Pamplona
2026-01-07 16:38:51 -05:00
parent 882cf6ee59
commit d5ba3ffc04
3 changed files with 3 additions and 10 deletions
@@ -28,15 +28,13 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.coroutines.executeAsync
class Nip05NostrAddressVerifier {
object Nip05NostrAddressVerifier {
suspend fun fetchNip05Json(
nip05: String,
okHttpClient: (String) -> OkHttpClient,
onSuccess: suspend (String) -> Unit,
onError: (String) -> Unit,
) = withContext(Dispatchers.IO) {
checkNotInMainThread()
val url = Nip05().assembleUrl(nip05)
if (url == null) {
@@ -73,15 +71,10 @@ class Nip05NostrAddressVerifier {
onSuccess: suspend (String) -> Unit,
onError: (String) -> Unit,
) {
// check fails on tests
checkNotInMainThread()
fetchNip05Json(
nip05,
okHttpClient,
onSuccess = {
checkNotInMainThread()
Nip05().parseHexKeyFor(nip05, it.lowercase()).fold(
onSuccess = { hexKey ->
if (hexKey == null) {
@@ -214,7 +214,7 @@ class AccountStateViewModel : ViewModel() {
loginSync(newKey, transientAccount, loginWithExternalSigner, packageName, onError)
}
} else if (EMAIL_PATTERN.matcher(key).matches()) {
Nip05NostrAddressVerifier().verifyNip05(
Nip05NostrAddressVerifier.verifyNip05(
key,
okHttpClient = { Amethyst.instance.okHttpClients.getHttpClient(false) },
onSuccess = { publicKey ->
@@ -941,7 +941,7 @@ class AccountViewModel(
val nip05 = userMetadata.nip05?.ifBlank { null } ?: return
viewModelScope.launch(Dispatchers.IO) {
Nip05NostrAddressVerifier()
Nip05NostrAddressVerifier
.verifyNip05(
nip05,
okHttpClient = httpClientBuilder::okHttpClientForNip05,