Simplifies NIP-05 processing
This commit is contained in:
+1
-8
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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 ->
|
||||
|
||||
+1
-1
@@ -941,7 +941,7 @@ class AccountViewModel(
|
||||
val nip05 = userMetadata.nip05?.ifBlank { null } ?: return
|
||||
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
Nip05NostrAddressVerifier()
|
||||
Nip05NostrAddressVerifier
|
||||
.verifyNip05(
|
||||
nip05,
|
||||
okHttpClient = httpClientBuilder::okHttpClientForNip05,
|
||||
|
||||
Reference in New Issue
Block a user