From 44c39b01eae270e39258febb9c8dd28b85c0cba7 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 26 Mar 2026 11:07:56 -0400 Subject: [PATCH] Defers NIP05 Resolver/NamecoinResolver Builder until needed --- .../com/vitorpamplona/amethyst/AppModules.kt | 49 +++++++++++-------- .../amethyst/ui/actions/EditPostViewModel.kt | 2 +- .../ui/note/NIP05VerificationDisplay.kt | 4 +- .../nip22Comments/CommentPostViewModel.kt | 2 +- .../ui/screen/AccountSessionManager.kt | 4 +- .../ui/screen/loggedIn/AccountViewModel.kt | 10 ++-- .../ui/screen/loggedIn/LoggedInPage.kt | 2 +- .../privateDM/send/ChatNewMessageViewModel.kt | 2 +- .../send/ChannelNewMessageViewModel.kt | 2 +- .../nip23LongForm/LongFormPostViewModel.kt | 2 +- .../nip99Classifieds/NewProductViewModel.kt | 2 +- .../loggedIn/home/ShortNotePostViewModel.kt | 2 +- .../display/lists/PeopleListViewModel.kt | 2 +- .../display/packs/FollowPackViewModel.kt | 2 +- .../ImportFollowListSelectUserScreen.kt | 2 +- .../NewPublicMessageViewModel.kt | 2 +- .../ui/screen/loggedIn/search/SearchScreen.kt | 2 +- .../model/nip05DnsIdentifiers/Nip05State.kt | 4 +- .../quartz/nip05DnsIdentifiers/Nip05Client.kt | 10 ++-- 19 files changed, 57 insertions(+), 50 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt index cf9256dc4..9928ce0a4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt @@ -158,29 +158,36 @@ class AppModules( // Offers easy methods to know when connections are happening through Tor or not val roleBasedHttpClientBuilder = RoleBasedHttpClientBuilder(okHttpClients, torPrefs.value) - // Custom fetcher that considers tor settings and avoids forwarding. - val nip05Fetcher = OkHttpNip05Fetcher(roleBasedHttpClientBuilder::okHttpClientForNip05) - - val namecoinResolver = - NamecoinNameResolver( - electrumxClient = - ElectrumXClient( - socketFactory = { roleBasedHttpClientBuilder.socketFactoryForNip05() }, - ), - serverListProvider = { - // User-configured custom servers take priority - namecoinPrefs.customServersOrNull - ?: if (roleBasedHttpClientBuilder.shouldUseTorForNIP05("https://electrumx.example.com")) { - TOR_ELECTRUMX_SERVERS - } else { - DEFAULT_ELECTRUMX_SERVERS - } - }, - ) - val nip05Client = Nip05Client(nip05Fetcher, namecoinResolver) + val namecoinResolver by + lazy { + Log.d("AppModules", "Namecoin Resolver Init") + NamecoinNameResolver( + electrumxClient = + ElectrumXClient( + socketFactory = { roleBasedHttpClientBuilder.socketFactoryForNip05() }, + ), + serverListProvider = { + // User-configured custom servers take priority + namecoinPrefs.customServersOrNull + ?: if (roleBasedHttpClientBuilder.shouldUseTorForNIP05("https://electrumx.example.com")) { + TOR_ELECTRUMX_SERVERS + } else { + DEFAULT_ELECTRUMX_SERVERS + } + }, + ) + } // Application-wide block height request cache val otsBlockHeightCache by lazy { OtsBlockHeightCache() } + val nip05Client by + lazy { + Log.d("AppModules", "NIP05Client Init") + Nip05Client( + fetcher = OkHttpNip05Fetcher(roleBasedHttpClientBuilder::okHttpClientForNip05), + namecoinResolverBuilder = { namecoinResolver }, + ) + } val otsResolverBuilder: TorAwareOkHttpOtsResolverBuilder = TorAwareOkHttpOtsResolverBuilder( @@ -280,8 +287,8 @@ class AppModules( val sessionManager = AccountSessionManager( accountsCache = accountsCache, - nip05Client = nip05Client, client = client, + nip05ClientBuilder = { nip05Client }, localPreferences = LocalPreferences, scope = applicationIOScope, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostViewModel.kt index 53cd5a131..4219ce80d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/EditPostViewModel.kt @@ -119,7 +119,7 @@ open class EditPostViewModel : ViewModel() { this.editedFromNote = edit this.userSuggestions?.reset() - this.userSuggestions = UserSuggestionState(accountViewModel.account, accountViewModel.nip05Client) + this.userSuggestions = UserSuggestionState(accountViewModel.account, accountViewModel.nip05ClientBuilder()) } fun sendPost() { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt index 85f1e54e0..325005dd8 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt @@ -134,7 +134,7 @@ private fun VerifyAndDisplayNIP05OrStatusLine( if (nip05VerifState.isExpired()) { LaunchedEffect(key1 = nip05VerifState) { accountViewModel.runOnIO { - nip05State.checkAndUpdate(accountViewModel.nip05Client) + nip05State.checkAndUpdate(accountViewModel.nip05ClientBuilder) } } } @@ -442,7 +442,7 @@ fun ObserveAndRenderNIP05VerifiedSymbol( if (state.isExpired()) { LaunchedEffect(key1 = state) { accountViewModel.runOnIO { - nip05State.checkAndUpdate(accountViewModel.nip05Client) + nip05State.checkAndUpdate(accountViewModel.nip05ClientBuilder) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt index b150efe39..da55dd466 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt @@ -209,7 +209,7 @@ open class CommentPostViewModel : this.canAddZapRaiser = hasLnAddress() this.userSuggestions?.reset() - this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05Client) + this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05ClientBuilder()) this.emojiSuggestions?.reset() this.emojiSuggestions = EmojiSuggestionState(accountVM.account) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt index 9e9fcf4b3..07ac0d870 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/AccountSessionManager.kt @@ -93,8 +93,8 @@ sealed class AccountState { @Stable class AccountSessionManager( val accountsCache: AccountCacheState, - val nip05Client: Nip05Client, val client: INostrClient, + val nip05ClientBuilder: () -> Nip05Client, val localPreferences: LocalPreferences, val scope: CoroutineScope, ) { @@ -227,7 +227,7 @@ class AccountSessionManager( onError("Could not parse nip05 address: $nip05") } else { try { - val pubkeyInfo = nip05Client.get(nip05) + val pubkeyInfo = nip05ClientBuilder().get(nip05) if (pubkeyInfo == null) { onError("User not found in the nip05 server: $nip05") } else { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index fbb4beb27..1396e821d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -173,7 +173,7 @@ class AccountViewModel( val torSettings: TorSettingsFlow, val dataSources: RelaySubscriptionsCoordinator, val httpClientBuilder: IRoleBasedHttpClientBuilder, - val nip05Client: INip05Client, + val nip05ClientBuilder: () -> INip05Client, ) : ViewModel(), Dao { var firstRoute: Route? = null @@ -1290,7 +1290,7 @@ class AccountViewModel( val torSettings: TorSettingsFlow, val dataSources: RelaySubscriptionsCoordinator, val okHttpClient: RoleBasedHttpClientBuilder, - val nip05Client: Nip05Client, + val nip05ClientBuilder: () -> Nip05Client, ) : ViewModelProvider.Factory { @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T = @@ -1300,7 +1300,7 @@ class AccountViewModel( torSettings, dataSources, okHttpClient, - nip05Client, + nip05ClientBuilder, ) as T } @@ -1822,7 +1822,7 @@ fun mockAccountViewModel(): AccountViewModel { torSettings = TorSettingsFlow(torType = MutableStateFlow(TorType.OFF)), httpClientBuilder = EmptyRoleBasedHttpClientBuilder(), dataSources = RelaySubscriptionsCoordinator(LocalCache, client, authenticator, failureTracker, scope), - nip05Client = EmptyNip05Client(), + nip05ClientBuilder = { EmptyNip05Client() }, ).also { mockedCache = it } @@ -1873,7 +1873,7 @@ fun mockVitorAccountViewModel(): AccountViewModel { torSettings = TorSettingsFlow(torType = MutableStateFlow(TorType.OFF)), httpClientBuilder = EmptyRoleBasedHttpClientBuilder(), dataSources = RelaySubscriptionsCoordinator(LocalCache, client, authenticator, failureTracker, scope), - nip05Client = EmptyNip05Client(), + nip05ClientBuilder = { EmptyNip05Client() }, ).also { vitorCache = it } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/LoggedInPage.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/LoggedInPage.kt index d1f44cea2..2fef9419e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/LoggedInPage.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/LoggedInPage.kt @@ -72,7 +72,7 @@ fun LoggedInPage( torSettings = Amethyst.instance.torPrefs.value, dataSources = Amethyst.instance.sources, okHttpClient = Amethyst.instance.roleBasedHttpClientBuilder, - nip05Client = Amethyst.instance.nip05Client, + nip05ClientBuilder = { Amethyst.instance.nip05Client }, ), ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt index 19e917bd7..13130e854 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt @@ -260,7 +260,7 @@ class ChatNewMessageViewModel : this.canAddZapRaiser = hasLnAddress() this.userSuggestions?.reset() - this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05Client) + this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05ClientBuilder()) this.emojiSuggestions?.reset() this.emojiSuggestions = EmojiSuggestionState(accountVM.account) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt index 489a744f8..5b293355b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt @@ -186,7 +186,7 @@ open class ChannelNewMessageViewModel : this.canAddZapRaiser = hasLnAddress() this.userSuggestions?.reset() - this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05Client) + this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05ClientBuilder()) this.emojiSuggestions?.reset() this.emojiSuggestions = EmojiSuggestionState(accountVM.account) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/LongFormPostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/LongFormPostViewModel.kt index 49f23cee1..ddbcdc910 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/LongFormPostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/LongFormPostViewModel.kt @@ -211,7 +211,7 @@ class LongFormPostViewModel : this.canAddZapRaiser = hasLnAddress() this.userSuggestions?.reset() - this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05Client) + this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05ClientBuilder()) this.emojiSuggestions?.reset() this.emojiSuggestions = EmojiSuggestionState(accountVM.account) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt index 2908f5a79..826fa4eaa 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt @@ -200,7 +200,7 @@ open class NewProductViewModel : this.canAddZapRaiser = hasLnAddress() this.userSuggestions?.reset() - this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05Client) + this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05ClientBuilder()) this.emojiSuggestions?.reset() this.emojiSuggestions = EmojiSuggestionState(accountVM.account) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt index fc68d621d..e9f106d47 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt @@ -301,7 +301,7 @@ open class ShortNotePostViewModel : this.canAddZapRaiser = hasLnAddress() this.userSuggestions?.reset() - this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05Client) + this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05ClientBuilder()) this.emojiSuggestions?.reset() this.emojiSuggestions = EmojiSuggestionState(accountVM.account) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/display/lists/PeopleListViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/display/lists/PeopleListViewModel.kt index 03db90149..d68148af4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/display/lists/PeopleListViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/display/lists/PeopleListViewModel.kt @@ -72,7 +72,7 @@ class PeopleListViewModel : ViewModel() { ) { if (!this::account.isInitialized || this.account != accountVM.account) { this.account = accountVM.account - this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05Client) + this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05ClientBuilder()) } this.selectedDTag.tryEmit(selectedDTag) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/display/packs/FollowPackViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/display/packs/FollowPackViewModel.kt index eab070de4..9324e8cdf 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/display/packs/FollowPackViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/display/packs/FollowPackViewModel.kt @@ -72,7 +72,7 @@ class FollowPackViewModel : ViewModel() { ) { if (!this::account.isInitialized || this.account != accountVM.account) { this.account = accountVM.account - this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05Client) + this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05ClientBuilder()) } this.selectedDTag.tryEmit(selectedDTag) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/newUser/ImportFollowListSelectUserScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/newUser/ImportFollowListSelectUserScreen.kt index 9b0c9286c..03b156ecf 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/newUser/ImportFollowListSelectUserScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/newUser/ImportFollowListSelectUserScreen.kt @@ -116,7 +116,7 @@ fun ImportFollowListSelectUserScreen( ) { val viewModel: ImportFollowListSelectUserViewModel = viewModel( - factory = ImportFollowListSelectUserViewModel.Factory(accountViewModel.account, accountViewModel.nip05Client), + factory = ImportFollowListSelectUserViewModel.Factory(accountViewModel.account, accountViewModel.nip05ClientBuilder()), ) Scaffold( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt index 35e94f93f..21f567ebb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt @@ -209,7 +209,7 @@ class NewPublicMessageViewModel : this.canAddZapRaiser = hasLnAddress() this.userSuggestions?.reset() - this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05Client) + this.userSuggestions = UserSuggestionState(accountVM.account, accountVM.nip05ClientBuilder()) this.emojiSuggestions?.reset() this.emojiSuggestions = EmojiSuggestionState(accountVM.account) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt index 68d952c01..2dffe5d4c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt @@ -91,7 +91,7 @@ fun SearchScreen( factory = SearchBarViewModel.Factory( accountViewModel.account, - accountViewModel.nip05Client, + accountViewModel.nip05ClientBuilder(), ), ) diff --git a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/nip05DnsIdentifiers/Nip05State.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/nip05DnsIdentifiers/Nip05State.kt index 0bef42b0b..245e7f7a5 100644 --- a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/nip05DnsIdentifiers/Nip05State.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/model/nip05DnsIdentifiers/Nip05State.kt @@ -49,11 +49,11 @@ sealed interface Nip05State { fun reset() = verificationState.tryEmit(Nip05VerifState.NotStarted) - suspend fun checkAndUpdate(nip05Client: INip05Client) { + suspend fun checkAndUpdate(nip05ClientBuilder: () -> INip05Client) { if (verificationState.value.isExpired()) { markAsVerifying() try { - if (nip05Client.verify(nip05, hexKey)) { + if (nip05ClientBuilder().verify(nip05, hexKey)) { markAsVerified() } else { markAsInvalid() diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/Nip05Client.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/Nip05Client.kt index 0ac30f796..c7520138d 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/Nip05Client.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip05DnsIdentifiers/Nip05Client.kt @@ -28,7 +28,7 @@ import kotlinx.coroutines.CancellationException @Stable class Nip05Client( val fetcher: Nip05Fetcher, - val namecoinResolver: NamecoinNameResolver? = null, + val namecoinResolverBuilder: (() -> NamecoinNameResolver)? = null, ) : INip05Client { val parser = Nip05Parser() @@ -37,8 +37,8 @@ class Nip05Client( hexKey: HexKey, ): Boolean { // Namecoin: route .bit domains to blockchain verification - if (namecoinResolver != null && NamecoinNameResolver.isNamecoinIdentifier(nip05.toValue())) { - val result = namecoinResolver.resolve(nip05.toValue()) + if (namecoinResolverBuilder != null && NamecoinNameResolver.isNamecoinIdentifier(nip05.toValue())) { + val result = namecoinResolverBuilder().resolve(nip05.toValue()) return result?.pubkey == hexKey } @@ -61,8 +61,8 @@ class Nip05Client( override suspend fun get(nip05: Nip05Id): Nip05KeyInfo? { // Namecoin: route .bit domains to blockchain resolution - if (namecoinResolver != null && NamecoinNameResolver.isNamecoinIdentifier(nip05.toValue())) { - val result = namecoinResolver.resolve(nip05.toValue()) ?: return null + if (namecoinResolverBuilder != null && NamecoinNameResolver.isNamecoinIdentifier(nip05.toValue())) { + val result = namecoinResolverBuilder().resolve(nip05.toValue()) ?: return null return Nip05KeyInfo(result.pubkey, result.relays) }