Simplifies NIP-05 processing
This commit is contained in:
+1
-8
@@ -28,15 +28,13 @@ import okhttp3.OkHttpClient
|
|||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.coroutines.executeAsync
|
import okhttp3.coroutines.executeAsync
|
||||||
|
|
||||||
class Nip05NostrAddressVerifier {
|
object Nip05NostrAddressVerifier {
|
||||||
suspend fun fetchNip05Json(
|
suspend fun fetchNip05Json(
|
||||||
nip05: String,
|
nip05: String,
|
||||||
okHttpClient: (String) -> OkHttpClient,
|
okHttpClient: (String) -> OkHttpClient,
|
||||||
onSuccess: suspend (String) -> Unit,
|
onSuccess: suspend (String) -> Unit,
|
||||||
onError: (String) -> Unit,
|
onError: (String) -> Unit,
|
||||||
) = withContext(Dispatchers.IO) {
|
) = withContext(Dispatchers.IO) {
|
||||||
checkNotInMainThread()
|
|
||||||
|
|
||||||
val url = Nip05().assembleUrl(nip05)
|
val url = Nip05().assembleUrl(nip05)
|
||||||
|
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
@@ -73,15 +71,10 @@ class Nip05NostrAddressVerifier {
|
|||||||
onSuccess: suspend (String) -> Unit,
|
onSuccess: suspend (String) -> Unit,
|
||||||
onError: (String) -> Unit,
|
onError: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
// check fails on tests
|
|
||||||
checkNotInMainThread()
|
|
||||||
|
|
||||||
fetchNip05Json(
|
fetchNip05Json(
|
||||||
nip05,
|
nip05,
|
||||||
okHttpClient,
|
okHttpClient,
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
checkNotInMainThread()
|
|
||||||
|
|
||||||
Nip05().parseHexKeyFor(nip05, it.lowercase()).fold(
|
Nip05().parseHexKeyFor(nip05, it.lowercase()).fold(
|
||||||
onSuccess = { hexKey ->
|
onSuccess = { hexKey ->
|
||||||
if (hexKey == null) {
|
if (hexKey == null) {
|
||||||
|
|||||||
+1
-1
@@ -214,7 +214,7 @@ class AccountStateViewModel : ViewModel() {
|
|||||||
loginSync(newKey, transientAccount, loginWithExternalSigner, packageName, onError)
|
loginSync(newKey, transientAccount, loginWithExternalSigner, packageName, onError)
|
||||||
}
|
}
|
||||||
} else if (EMAIL_PATTERN.matcher(key).matches()) {
|
} else if (EMAIL_PATTERN.matcher(key).matches()) {
|
||||||
Nip05NostrAddressVerifier().verifyNip05(
|
Nip05NostrAddressVerifier.verifyNip05(
|
||||||
key,
|
key,
|
||||||
okHttpClient = { Amethyst.instance.okHttpClients.getHttpClient(false) },
|
okHttpClient = { Amethyst.instance.okHttpClients.getHttpClient(false) },
|
||||||
onSuccess = { publicKey ->
|
onSuccess = { publicKey ->
|
||||||
|
|||||||
+1
-1
@@ -941,7 +941,7 @@ class AccountViewModel(
|
|||||||
val nip05 = userMetadata.nip05?.ifBlank { null } ?: return
|
val nip05 = userMetadata.nip05?.ifBlank { null } ?: return
|
||||||
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
Nip05NostrAddressVerifier()
|
Nip05NostrAddressVerifier
|
||||||
.verifyNip05(
|
.verifyNip05(
|
||||||
nip05,
|
nip05,
|
||||||
okHttpClient = httpClientBuilder::okHttpClientForNip05,
|
okHttpClient = httpClientBuilder::okHttpClientForNip05,
|
||||||
|
|||||||
Reference in New Issue
Block a user