diff --git a/common/src/main/res/values-ku/strings.xml b/common/src/main/res/values-ku/strings.xml
index 29dee488..eec3c75d 100644
--- a/common/src/main/res/values-ku/strings.xml
+++ b/common/src/main/res/values-ku/strings.xml
@@ -2129,4 +2129,47 @@
- %d Sepan
- %d Sepan
+ Navê .kurd
+ Bi zincîrê tê çareserkirin · ji motora lêgerînê re nayê şandin
+ Fermî
+ Tomarkirî
+ Nehat piştrastkirin
+ Ev malper nayê vekirin
+ Navên fermî tenê piştî ku bi zincîrê hatin piştrastkirin vedibin. Niha girêdana bi zincîrê re çênebû.
+ Nehat piştrastkirin
+ Ev nav bi zincîrê nehat kontrolkirin. Dibe ku malper ne ya xwediyê navî be. Li vir agahiyên xwe yên taybet nenivîse û tiştekî îmze neke.
+ Vegere
+ Dîsa jî veke
+ Navekî wiha tune ye
+ %s ne tomarkirî ye, an jî dema wê qediyaye.
+ Li ser vî navî malper tune
+ Nav tomarkirî ye, lê xwediyê wê malperek ku cîzdan dikare veke belav nekiriye.
+ Nehat barkirin
+ Ne zincîr ne jî neynik bi naverokeke ku bê piştrastkirin bersiv dan.
+ Fermî · navê dewletê
+ Li zincîrê tomarkirî ye
+ Bê piştrastkirin hate vekirin
+ Ji aliyê Meclîsê ve hatiye dayîn. Naveroka wê tenê piştî demeke li bendê diguhere; di wê demê de Meclîs dikare guhertinê rawestîne.
+ Ev nav hatiye kirîn. Naverok bi zincîrê hate piştrastkirin, lê kê ew malper çêkiriye nehat piştrastkirin.
+ Te hilbijart ku vî navî vekî, her çend bi zincîrê nehat kontrolkirin. Tiştê ku nîşan dide li ser gotina du girêkan e, ne li ser delîlekê.
+ Piştrastkirin
+ Bi zincîrê · blok #%s
+ Bi zincîrê
+ Du girêk li hev kirin, delîl tune
+ Xwedî
+ Saziya dewletê (multisig)
+ Naverok
+ Daneyên vê malperê jê bibe
+ Ev nav dişibe navekî fermî
+ Te nivîsî
+ Navê fermî
+ Malperên sexte navên nêzîkî navên fermî bi kar tînin da ku te bixapînin.
+ Biçe %s
+ Dîsa jî %s veke
+ Fermî
+ Kirî · ne fermî
+ Nehat piştrastkirin
+ Navê tevahî kontrol bike. Ev nav ji aliyê dewletê ve nehatiye dayîn.
+ Ev nav bi zincîrê nehat kontrolkirin. Tenê îmze bike heke tu bawer î ku ev malpera kê ye.
+ Guhertoyeke nûtir nehat dîtin — guhertoya li zincîrê tê nîşandan
diff --git a/common/src/main/res/values-tr/strings.xml b/common/src/main/res/values-tr/strings.xml
index a9199f3d..dc4b13b7 100644
--- a/common/src/main/res/values-tr/strings.xml
+++ b/common/src/main/res/values-tr/strings.xml
@@ -2126,4 +2126,47 @@ Referral kısmına bu adresi yapıştır:
Müzik
Rewshenbir
Davet
+ .kurd adı
+ Zincirden çözülür · arama motoruna gönderilmez
+ Resmî
+ Kayıtlı
+ Doğrulanmadı
+ Bu site açılamaz
+ Resmî adlar yalnızca zincirde doğrulandıktan sonra açılır. Şu an zincire bağlanılamadı.
+ Doğrulanamadı
+ Bu ad zincirde denetlenemedi. Site, adın sahibine ait olmayabilir. Burada özel bilgilerini girme ve hiçbir şey imzalama.
+ Geri dön
+ Yine de aç
+ Böyle bir ad yok
+ %s kayıtlı değil ya da kaydının süresi doldu.
+ Bu adda site yok
+ Ad kayıtlı, ama sahibi cüzdanın açabileceği bir site yayımlamamış.
+ Yüklenemedi
+ Ne zincir ne de aynalar doğrulanabilir bir içerikle yanıt verdi.
+ Resmî · devlet adı
+ Zincirde kayıtlı
+ Doğrulanmadan açıldı
+ Meclis tarafından verildi. İçeriği yalnızca bir bekleme süresinden sonra değişir; bu sürede Meclis değişikliği durdurabilir.
+ Bu ad satın alındı. İçerik zincirde doğrulandı, ama siteyi kimin yaptığı doğrulanmadı.
+ Zincirde denetlenemese de bu adı açmayı seçtin. Gösterdiği yer bir kanıta değil, iki düğümün sözüne dayanıyor.
+ Doğrulama
+ Zincirde · blok #%s
+ Zincirde
+ İki düğüm uyuştu, kanıt yok
+ Sahip
+ Devlet kurumu (çoklu imza)
+ İçerik
+ Bu sitenin verilerini sil
+ Bu ad resmî bir ada benziyor
+ Yazdığın
+ Resmî ad
+ Sahte siteler seni kandırmak için resmî adlara yakın adlar kullanır.
+ %s adresine git
+ Yine de %s adresini aç
+ Resmî
+ Satın alınmış · resmî değil
+ Doğrulanmadı
+ Adın tamamını kontrol et. Bu ad devlet tarafından verilmedi.
+ Bu ad zincirde denetlenemedi. Yalnızca sitenin kime ait olduğundan eminsen imzala.
+ Daha yeni sürüm bulunamadı — zincirdeki sürüm gösteriliyor
diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml
index 068a37b5..736db432 100644
--- a/common/src/main/res/values/strings.xml
+++ b/common/src/main/res/values/strings.xml
@@ -2854,4 +2854,47 @@
Music
Rewshenbir
Referral
+ .kurd name
+ Resolved on chain · never sent to a search engine
+ Official
+ Registered
+ Not verified
+ This site cannot be opened
+ Official names open only once they are verified on chain. The chain could not be reached just now.
+ Not verified
+ This name could not be checked on chain. The site may not be its owner\'s. Do not enter private information or sign anything here.
+ Go back
+ Open anyway
+ No such name
+ %s is not registered, or its registration has ended.
+ No site at this name
+ The name is registered, but its owner has not published a site the wallet can open.
+ Could not be loaded
+ Neither the chain nor the mirrors answered with content that could be verified.
+ Official · a state name
+ Registered on chain
+ Opened without verification
+ Given by Parliament. Its content changes only after a waiting period during which Parliament can stop the change.
+ This name was bought. Its content was verified on chain, but who made the site was not.
+ You chose to open this name although it could not be checked on chain. What it points to rests on two nodes\' word, not on a proof.
+ Verification
+ On chain · block #%s
+ On chain
+ Two nodes agreed, no proof
+ Owner
+ State institution (multisig)
+ Content
+ Clear this site\'s data
+ This name looks like an official one
+ You typed
+ Official name
+ Fake sites use names close to official ones to deceive you.
+ Go to %s
+ Open %s anyway
+ Official
+ Bought · not official
+ Not verified
+ Check the full name. This name was not given by the state.
+ This name could not be checked on chain. Sign only if you are sure whose site this is.
+ No newer version found — showing the version on chain
diff --git a/feature-dapp-api/src/main/java/io/novafoundation/nova/feature_dapp_api/presentation/view/DAppView.kt b/feature-dapp-api/src/main/java/io/novafoundation/nova/feature_dapp_api/presentation/view/DAppView.kt
index 8e044a0b..dd507e0d 100644
--- a/feature-dapp-api/src/main/java/io/novafoundation/nova/feature_dapp_api/presentation/view/DAppView.kt
+++ b/feature-dapp-api/src/main/java/io/novafoundation/nova/feature_dapp_api/presentation/view/DAppView.kt
@@ -63,6 +63,12 @@ class DAppView @JvmOverloads constructor(
binder.itemDAppIcon.showDAppIcon(iconUrl, imageLoader)
}
+ /** A bundled icon instead of a DApp's own, for entries that are not catalogue DApps. */
+ fun setIconResource(@DrawableRes iconRes: Int, @ColorRes tintRes: Int?) {
+ binder.itemDAppIcon.setImageResource(iconRes)
+ binder.itemDAppIcon.setImageTintRes(tintRes)
+ }
+
fun setFavoriteIconVisible(visible: Boolean) {
binder.itemDappFavorite.setVisible(visible)
}
diff --git a/feature-dapp-impl/build.gradle b/feature-dapp-impl/build.gradle
index 1eeb7e1e..53928dd6 100644
--- a/feature-dapp-impl/build.gradle
+++ b/feature-dapp-impl/build.gradle
@@ -67,6 +67,7 @@ dependencies {
implementation project(':feature-external-sign-api')
implementation project(':feature-banners-api')
implementation project(':runtime')
+ implementation androidxWebKit
implementation project(':feature-deep-linking')
implementation kotlinDep
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/DAppFeatureDependencies.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/DAppFeatureDependencies.kt
index a07968bb..5cf440f3 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/DAppFeatureDependencies.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/DAppFeatureDependencies.kt
@@ -40,6 +40,8 @@ import io.novafoundation.nova.feature_wallet_connect_api.presentation.WalletConn
import io.novafoundation.nova.runtime.di.ExtrinsicSerialization
import io.novafoundation.nova.runtime.multiNetwork.ChainRegistry
import io.novafoundation.nova.runtime.multiNetwork.runtime.repository.RuntimeVersionsRepository
+import io.novafoundation.nova.runtime.names.KurdNameResolver
+import io.novafoundation.nova.runtime.names.content.KurdSiteServer
interface DAppFeatureDependencies {
@@ -101,6 +103,10 @@ interface DAppFeatureDependencies {
fun chainRegistry(): ChainRegistry
+ fun kurdSiteServer(): KurdSiteServer
+
+ fun kurdNameResolver(): KurdNameResolver
+
fun imageLoader(): ImageLoader
fun feeLoaderMixinFactory(): FeeLoaderMixin.Factory
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/modules/BrowserTabsModule.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/modules/BrowserTabsModule.kt
index 7b9fe5b1..55049768 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/modules/BrowserTabsModule.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/modules/BrowserTabsModule.kt
@@ -1,5 +1,6 @@
package io.novafoundation.nova.feature_dapp_impl.di.modules
+import io.novafoundation.nova.runtime.names.content.KurdSiteServer
import android.content.Context
import dagger.Module
import dagger.Provides
@@ -84,9 +85,10 @@ class BrowserTabsModule {
fun providePageSessionFactory(
compoundWeb3Injector: CompoundWeb3Injector,
contextManager: ContextManager,
- integrityCheckJSBridgeFactory: IntegrityCheckJSBridgeFactory
+ integrityCheckJSBridgeFactory: IntegrityCheckJSBridgeFactory,
+ kurdSiteServer: KurdSiteServer,
): BrowserTabSessionFactory {
- return BrowserTabSessionFactory(compoundWeb3Injector, contextManager, integrityCheckJSBridgeFactory)
+ return BrowserTabSessionFactory(compoundWeb3Injector, contextManager, integrityCheckJSBridgeFactory, kurdSiteServer)
}
@FeatureScope
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/modules/web3/PolkadotJsModule.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/modules/web3/PolkadotJsModule.kt
index e7775347..15d869e5 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/modules/web3/PolkadotJsModule.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/di/modules/web3/PolkadotJsModule.kt
@@ -14,6 +14,7 @@ import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.PolkadotJsInject
import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.PolkadotJsResponder
import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.PolkadotJsTransportFactory
import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.di.PolkadotJs
+import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.rpc.ChainRegistryRpc
import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.states.PolkadotJsStateFactory
import io.novafoundation.nova.feature_dapp_impl.web3.session.Web3Session
import io.novafoundation.nova.feature_dapp_impl.web3.webview.WebViewHolder
@@ -74,6 +75,7 @@ class PolkadotJsModule {
addressIconGenerator: AddressIconGenerator,
web3Session: Web3Session,
walletUiUseCase: WalletUiUseCase,
+ chainRegistry: ChainRegistry,
): PolkadotJsStateFactory {
return PolkadotJsStateFactory(
interactor = interactor,
@@ -81,7 +83,8 @@ class PolkadotJsModule {
resourceManager = resourceManager,
addressIconGenerator = addressIconGenerator,
web3Session = web3Session,
- walletUiUseCase = walletUiUseCase
+ walletUiUseCase = walletUiUseCase,
+ chainRpc = ChainRegistryRpc(chainRegistry),
)
}
}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/DappSearchGroup.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/DappSearchGroup.kt
index 1009fd2a..bc7eb4d5 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/DappSearchGroup.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/DappSearchGroup.kt
@@ -1,5 +1,5 @@
package io.novafoundation.nova.feature_dapp_impl.domain.search
enum class DappSearchGroup {
- DAPPS, SEARCH
+ KURD_NAME, DAPPS, SEARCH
}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/DappSearchResult.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/DappSearchResult.kt
index ea634ff0..8c36943c 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/DappSearchResult.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/DappSearchResult.kt
@@ -12,6 +12,13 @@ sealed interface DappSearchResult {
override val isTrustedByNova: Boolean = false
}
+ /** A `.kurd` name: resolved on chain when opened, never looked up on the web. */
+ class KurdName(val name: io.novafoundation.nova.runtime.names.KurdName) : DappSearchResult {
+ override val isTrustedByNova: Boolean = true
+
+ val url: String get() = "https://${name.name}/"
+ }
+
class Dapp(val dapp: DApp) : DappSearchResult {
override val isTrustedByNova: Boolean = true
}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/SearchDappInteractor.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/SearchDappInteractor.kt
index 4c96be0f..423a827e 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/SearchDappInteractor.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/domain/search/SearchDappInteractor.kt
@@ -8,10 +8,12 @@ import io.novafoundation.nova.feature_dapp_api.data.repository.DAppMetadataRepos
import io.novafoundation.nova.feature_dapp_impl.data.repository.FavouritesDAppRepository
import io.novafoundation.nova.feature_dapp_impl.domain.common.buildUrlToDappMapping
import io.novafoundation.nova.feature_dapp_impl.domain.common.createDAppComparator
+import io.novafoundation.nova.runtime.names.KurdName
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
+import java.net.URLEncoder
class SearchDappInteractor(
private val dAppMetadataRepository: DAppMetadataRepository,
@@ -31,8 +33,12 @@ class SearchDappInteractor(
.sortedWith(createDAppComparator())
.map(DappSearchResult::Dapp)
+ // A .kurd name is resolved on chain by the wallet: never a web address, never a search query
+ val kurdName = KurdName.parse(query).takeIf { KurdName.mentionsKurd(query) }
+
val searchGroupContent = when {
query.isEmpty() -> null
+ KurdName.mentionsKurd(query) -> null
Urls.isValidWebUrl(query) -> {
val searchUrl = Urls.ensureHttpsProtocol(query)
val searchUrlDomain = Urls.domainOf(searchUrl)
@@ -44,6 +50,10 @@ class SearchDappInteractor(
}
buildMap {
+ kurdName?.let {
+ put(DappSearchGroup.KURD_NAME, listOf(DappSearchResult.KurdName(it)))
+ }
+
searchGroupContent?.let {
put(DappSearchGroup.SEARCH, listOf(searchGroupContent))
}
@@ -54,7 +64,7 @@ class SearchDappInteractor(
}
}
- private fun searchUrlFor(query: String): String = "https://duckduckgo.com/?q=$query"
+ private fun searchUrlFor(query: String): String = "https://duckduckgo.com/?q=" + URLEncoder.encode(query, Charsets.UTF_8.name())
private suspend fun getDapps(categoryId: String?): Collection {
val dApps = dAppMetadataRepository.getDAppCatalog()
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/DAppBrowserFragment.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/DAppBrowserFragment.kt
index 10ebd6b0..03c7f8ec 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/DAppBrowserFragment.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/DAppBrowserFragment.kt
@@ -5,21 +5,31 @@ import android.graphics.Bitmap
import android.os.Bundle
import android.transition.TransitionInflater
import android.view.View
+import android.webkit.CookieManager
+import android.webkit.GeolocationPermissions
import android.webkit.WebResourceRequest
+import android.webkit.WebStorage
import android.webkit.WebView
import android.widget.ImageView
import androidx.activity.OnBackPressedCallback
import androidx.core.app.SharedElementCallback
import androidx.core.os.bundleOf
import androidx.core.transition.addListener
+import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewModelScope
import coil.ImageLoader
import io.novafoundation.nova.common.base.BaseFragment
import io.novafoundation.nova.common.di.FeatureUtils
+import io.novafoundation.nova.common.utils.browser.fileChoosing.WebViewFileChooser
+import io.novafoundation.nova.common.utils.browser.permissions.WebViewPermissionAsker
import io.novafoundation.nova.common.utils.insets.applyNavigationBarInsets
import io.novafoundation.nova.common.utils.insets.applyStatusBarInsets
import io.novafoundation.nova.common.utils.makeGone
import io.novafoundation.nova.common.utils.makeVisible
+import io.novafoundation.nova.common.utils.setImageTintRes
+import io.novafoundation.nova.common.utils.setVisible
+import io.novafoundation.nova.common.utils.webView.WebViewRequestInterceptor
+import io.novafoundation.nova.common.view.dialog.infoDialog
import io.novafoundation.nova.feature_dapp_api.di.DAppFeatureApi
import io.novafoundation.nova.feature_dapp_api.presentation.browser.main.DAppBrowserPayload
import io.novafoundation.nova.feature_dapp_impl.R
@@ -27,21 +37,21 @@ import io.novafoundation.nova.feature_dapp_impl.databinding.FragmentDappBrowserB
import io.novafoundation.nova.feature_dapp_impl.di.DAppFeatureComponent
import io.novafoundation.nova.feature_dapp_impl.domain.browser.isSecure
import io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.DappPendingConfirmation.Action
+import io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.kurd.KurdDetailsSheet
+import io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.kurd.KurdPageUi
import io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.sheets.AcknowledgePhishingBottomSheet
import io.novafoundation.nova.feature_dapp_impl.presentation.browser.options.OptionsBottomSheetDialog
import io.novafoundation.nova.feature_dapp_impl.presentation.common.favourites.setupRemoveFavouritesConfirmation
import io.novafoundation.nova.feature_dapp_impl.utils.tabs.models.BrowserTabSession
-import io.novafoundation.nova.feature_dapp_impl.web3.webview.Web3ChromeClient
-import io.novafoundation.nova.feature_dapp_impl.web3.webview.CompoundWeb3Injector
-import io.novafoundation.nova.feature_dapp_impl.web3.webview.Web3WebViewClient
-import io.novafoundation.nova.common.utils.browser.fileChoosing.WebViewFileChooser
-import io.novafoundation.nova.feature_dapp_impl.web3.webview.WebViewHolder
-import io.novafoundation.nova.common.utils.browser.permissions.WebViewPermissionAsker
-import io.novafoundation.nova.common.utils.webView.WebViewRequestInterceptor
-import io.novafoundation.nova.common.view.dialog.infoDialog
import io.novafoundation.nova.feature_dapp_impl.utils.tabs.models.SessionCallback
+import io.novafoundation.nova.feature_dapp_impl.web3.webview.CompoundWeb3Injector
+import io.novafoundation.nova.feature_dapp_impl.web3.webview.Web3ChromeClient
+import io.novafoundation.nova.feature_dapp_impl.web3.webview.Web3WebViewClient
+import io.novafoundation.nova.feature_dapp_impl.web3.webview.WebViewHolder
import io.novafoundation.nova.feature_external_sign_api.presentation.externalSign.AuthorizeDappBottomSheet
+import io.novafoundation.nova.runtime.names.KurdName
import javax.inject.Inject
+import kotlinx.coroutines.launch
private const val OVERFLOW_TABS_COUNT = 100
@@ -222,11 +232,27 @@ class DAppBrowserFragment : BaseFragment
+ lifecycleScope.launch {
+ val owner = when (val owner = page.details.owner) {
+ KurdPageUi.Owner.Institution -> getString(R.string.dapp_kurd_owner_institution)
+ is KurdPageUi.Owner.Account -> viewModel.kurdOwnerAddress(owner.accountId)
+ }
+ KurdDetailsSheet(requireContext(), page, owner) { clearKurdSiteData(page.name) }.show()
+ }
+ }
+
+ binder.dappBrowserKurdNotice.kurdNoticeSecondary.setOnClickListener { viewModel.kurdOpenAnyway() }
+ binder.dappBrowserKurdOnChainVersionRetry.setOnClickListener { viewModel.kurdRetry() }
+
viewModel.tabsCountFlow.observe {
if (it >= OVERFLOW_TABS_COUNT) {
binder.dappBrowserTabsIcon.makeVisible()
@@ -335,4 +361,92 @@ class DAppBrowserFragment : BaseFragment Unit)
+
+ val look = when (kind) {
+ KurdPageUi.NoticeKind.REFUSED -> Look(
+ R.drawable.ic_close_circle,
+ R.color.icon_negative,
+ R.string.dapp_kurd_refused_title,
+ getString(R.string.dapp_kurd_refused_message),
+ R.string.common_retry,
+ viewModel::kurdRetry
+ )
+ KurdPageUi.NoticeKind.NEEDS_CONSENT -> Look(
+ R.drawable.ic_warning_filled,
+ R.color.icon_warning,
+ R.string.dapp_kurd_unverified_title,
+ getString(R.string.dapp_kurd_unverified_message),
+ R.string.dapp_kurd_back,
+ viewModel::kurdBack
+ )
+ KurdPageUi.NoticeKind.NOT_REGISTERED -> Look(
+ R.drawable.ic_info,
+ R.color.icon_secondary,
+ R.string.dapp_kurd_not_registered_title,
+ getString(R.string.dapp_kurd_not_registered_message, page.name.name),
+ R.string.dapp_kurd_back,
+ viewModel::kurdBack
+ )
+ KurdPageUi.NoticeKind.NO_SITE -> Look(
+ R.drawable.ic_info,
+ R.color.icon_secondary,
+ R.string.dapp_kurd_no_site_title,
+ getString(R.string.dapp_kurd_no_site_message),
+ R.string.dapp_kurd_back,
+ viewModel::kurdBack
+ )
+ KurdPageUi.NoticeKind.UNAVAILABLE -> Look(
+ R.drawable.ic_warning_filled,
+ R.color.icon_warning,
+ R.string.dapp_kurd_unavailable_title,
+ getString(R.string.dapp_kurd_unavailable_message),
+ R.string.common_retry,
+ viewModel::kurdRetry
+ )
+ }
+
+ notice.kurdNoticeName.text = page.name.name
+ notice.kurdNoticeIcon.setImageResource(look.icon)
+ notice.kurdNoticeIcon.setImageTintRes(look.tint)
+ notice.kurdNoticeTitle.setText(look.title)
+ notice.kurdNoticeMessage.text = look.message
+ notice.kurdNoticePrimary.setText(look.primary)
+ notice.kurdNoticePrimary.setOnClickListener { look.primaryAction() }
+ notice.kurdNoticeSecondary.setVisible(kind == KurdPageUi.NoticeKind.NEEDS_CONSENT)
+ notice.kurdNoticeSecondary.setText(R.string.dapp_kurd_open_anyway)
+ }
+
+ /** Storage, cookies and permissions the page kept under its name; then it loads afresh. */
+ private fun clearKurdSiteData(name: KurdName) {
+ val origin = "https://${name.name}"
+ WebStorage.getInstance().deleteOrigin(origin)
+ GeolocationPermissions.getInstance().clear(origin)
+
+ val cookies = CookieManager.getInstance()
+ cookies.getCookie(origin)?.split(';')?.map { it.substringBefore('=').trim() }?.filter { it.isNotEmpty() }?.forEach { cookieName ->
+ cookies.setCookie(origin, "$cookieName=; Max-Age=0")
+ }
+ cookies.flush()
+
+ viewModel.reloadPage()
+ }
}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/DAppBrowserViewModel.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/DAppBrowserViewModel.kt
index 381b44ec..e53415df 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/DAppBrowserViewModel.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/DAppBrowserViewModel.kt
@@ -12,13 +12,14 @@ import io.novafoundation.nova.common.utils.removeHexPrefix
import io.novafoundation.nova.common.utils.singleReplaySharedFlow
import io.novafoundation.nova.feature_account_api.domain.interfaces.SelectedAccountUseCase
import io.novafoundation.nova.feature_dapp_api.data.model.BrowserHostSettings
-import io.novafoundation.nova.feature_dapp_impl.presentation.DAppRouter
+import io.novafoundation.nova.feature_dapp_api.presentation.addToFavorites.AddToFavouritesPayload
+import io.novafoundation.nova.feature_dapp_api.presentation.browser.main.DAppBrowserPayload
import io.novafoundation.nova.feature_dapp_impl.domain.DappInteractor
import io.novafoundation.nova.feature_dapp_impl.domain.browser.BrowserPage
import io.novafoundation.nova.feature_dapp_impl.domain.browser.BrowserPageAnalyzed
import io.novafoundation.nova.feature_dapp_impl.domain.browser.DappBrowserInteractor
-import io.novafoundation.nova.feature_dapp_api.presentation.addToFavorites.AddToFavouritesPayload
-import io.novafoundation.nova.feature_dapp_api.presentation.browser.main.DAppBrowserPayload
+import io.novafoundation.nova.feature_dapp_impl.presentation.DAppRouter
+import io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.kurd.KurdPageUi
import io.novafoundation.nova.feature_dapp_impl.presentation.browser.options.DAppOptionsPayload
import io.novafoundation.nova.feature_dapp_impl.presentation.common.favourites.RemoveFavouritesPayload
import io.novafoundation.nova.feature_dapp_impl.presentation.search.DAppSearchCommunicator
@@ -33,6 +34,7 @@ import io.novafoundation.nova.feature_dapp_impl.web3.states.ExtensionStoreFactor
import io.novafoundation.nova.feature_dapp_impl.web3.states.Web3ExtensionStateMachine.ExternalEvent
import io.novafoundation.nova.feature_dapp_impl.web3.states.Web3StateMachineHost
import io.novafoundation.nova.feature_dapp_impl.web3.states.hostApi.ConfirmTxResponse
+import io.novafoundation.nova.feature_dapp_impl.web3.webview.WebViewWeb3JavaScriptInterface
import io.novafoundation.nova.feature_external_sign_api.model.ExternalSignCommunicator
import io.novafoundation.nova.feature_external_sign_api.model.ExternalSignRequester
import io.novafoundation.nova.feature_external_sign_api.model.awaitConfirmation
@@ -40,12 +42,19 @@ import io.novafoundation.nova.feature_external_sign_api.model.signPayload.Extern
import io.novafoundation.nova.feature_external_sign_api.model.signPayload.ExternalSignRequest
import io.novafoundation.nova.feature_external_sign_api.model.signPayload.ExternalSignWallet
import io.novafoundation.nova.feature_external_sign_api.model.signPayload.SigningDappMetadata
+import io.novafoundation.nova.feature_external_sign_api.model.signPayload.SiteNameKind
import io.novafoundation.nova.feature_external_sign_api.model.signPayload.polkadot.genesisHash
import io.novafoundation.nova.feature_external_sign_api.presentation.externalSign.AuthorizeDappBottomSheet
+import io.novafoundation.nova.runtime.ext.addressOf
import io.novafoundation.nova.runtime.ext.isDisabled
import io.novafoundation.nova.runtime.multiNetwork.ChainRegistry
import io.novafoundation.nova.runtime.multiNetwork.chainsById
+import io.novafoundation.nova.runtime.multiNetwork.connection.light.LightClients
+import io.novafoundation.nova.runtime.names.content.KurdSiteServer
+import kotlin.coroutines.resume
+import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChangedBy
@@ -53,13 +62,12 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
+import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
-import kotlin.coroutines.resume
-import kotlin.coroutines.suspendCoroutine
enum class ConfirmationState {
ALLOWED, REJECTED, CANCELLED
@@ -78,7 +86,8 @@ class DAppBrowserViewModel(
private val selectedAccountUseCase: SelectedAccountUseCase,
private val actionAwaitableMixinFactory: ActionAwaitableMixin.Factory,
private val chainRegistry: ChainRegistry,
- private val browserTabService: BrowserTabService
+ private val browserTabService: BrowserTabService,
+ private val kurdSiteServer: KurdSiteServer,
) : BaseViewModel(), Web3StateMachineHost {
val removeFromFavouritesConfirmation = actionAwaitableMixinFactory.confirmingAction()
@@ -97,6 +106,16 @@ class DAppBrowserViewModel(
override val externalEvents = singleReplaySharedFlow()
+ /** The `.kurd` name the tab shows and how: a badge on an open page, or a notice in its place. */
+ val kurdPage: Flow = currentPage
+ .map { KurdPageUi.nameOf(it.url) }
+ .distinctUntilChanged()
+ .flatMapLatest { name -> if (name == null) flowOf(null) else kurdSiteServer.pageStates.map { KurdPageUi.from(name, it[name]) } }
+ .shareInBackground()
+
+ private val _kurdDetailsEvent = MutableLiveData>()
+ val kurdDetailsEvent: LiveData> = _kurdDetailsEvent
+
private val _browserCommandEvent = MutableLiveData>()
val browserCommandEvent: LiveData> = _browserCommandEvent
@@ -151,7 +170,10 @@ class DAppBrowserViewModel(
return mapConfirmationStateToAuthorizationState(confirmationState)
}
- override suspend fun confirmTx(request: ExternalSignRequest): ConfirmTxResponse {
+ override suspend fun confirmTx(request: ExternalSignRequest, origin: String): ConfirmTxResponse {
+ val pageUrl = currentPageAnalyzed.first().url
+ if (!WebViewWeb3JavaScriptInterface.sameOrigin(pageUrl, origin)) return ConfirmTxResponse.Rejected(request.id)
+
val chainId = request.extractChainId()
val chain = chainRegistry.chainsById()[chainId]
@@ -160,7 +182,7 @@ class DAppBrowserViewModel(
}
val response = withContext(Dispatchers.Main) {
- signRequester.awaitConfirmation(mapSignExtrinsicRequestToPayload(request))
+ signRequester.awaitConfirmation(mapSignExtrinsicRequestToPayload(request, origin, pageUrl))
}
return when (response) {
@@ -175,6 +197,32 @@ class DAppBrowserViewModel(
_browserCommandEvent.postValue(BrowserCommand.Reload.event())
}
+ fun kurdRetry() = launch {
+ kurdPage.first()?.let { kurdSiteServer.forget(it.name) }
+ reloadPage()
+ }
+
+ /** Only from the unverified notice: a refused name has no way past it. */
+ fun kurdOpenAnyway() = launch {
+ val notice = kurdPage.first() as? KurdPageUi.Notice ?: return@launch
+ if (notice.kind != KurdPageUi.NoticeKind.NEEDS_CONSENT) return@launch
+
+ kurdSiteServer.allowUnverified(notice.name)
+ reloadPage()
+ }
+
+ fun kurdBack() {
+ _browserCommandEvent.value = BrowserCommand.GoBack.event()
+ }
+
+ fun kurdBadgeClicked() = launch {
+ (kurdPage.first() as? KurdPageUi.Open)?.let { _kurdDetailsEvent.value = it.event() }
+ }
+
+ suspend fun kurdOwnerAddress(accountId: ByteArray): String {
+ return chainRegistry.getChain(LightClients.ZAGROS_PEOPLE).addressOf(accountId)
+ }
+
fun detachCurrentSession() {
browserTabService.detachCurrentSession()
}
@@ -296,15 +344,31 @@ class DAppBrowserViewModel(
currentPage.emit(BrowserPage(url, title, synchronizedWithBrowser))
}
- private suspend fun mapSignExtrinsicRequestToPayload(request: ExternalSignRequest): ExternalSignPayload {
+ private suspend fun mapSignExtrinsicRequestToPayload(request: ExternalSignRequest, origin: String, pageUrl: String): ExternalSignPayload {
return ExternalSignPayload(
signRequest = request,
- dappMetadata = getDAppSignMetadata(currentPageAnalyzed.first().url),
+ dappMetadata = getDAppSignMetadata(origin, pageUrl),
wallet = ExternalSignWallet.Current
)
}
- private suspend fun getDAppSignMetadata(dAppUrl: String): SigningDappMetadata {
+ /** Named after the page that asked ([origin]), never after whatever the tab shows by now. */
+ private suspend fun getDAppSignMetadata(origin: String, dAppUrl: String): SigningDappMetadata {
+ val kurdName = KurdPageUi.nameOf(origin)
+ val kurdPage = kurdName?.let { KurdPageUi.from(it, kurdSiteServer.pageStates.value[it]) }
+ if (kurdName != null && kurdPage !is KurdPageUi.Open) {
+ // A .kurd page that is not open has no content that could have asked; say nothing official
+ return SigningDappMetadata(icon = null, name = kurdName.name, url = kurdName.name, siteNameKind = SiteNameKind.UNVERIFIED)
+ }
+ if (kurdPage is KurdPageUi.Open) {
+ val kind = when (kurdPage.badge) {
+ KurdPageUi.Badge.OFFICIAL -> SiteNameKind.OFFICIAL
+ KurdPageUi.Badge.REGISTERED -> SiteNameKind.REGISTERED
+ KurdPageUi.Badge.UNVERIFIED -> SiteNameKind.UNVERIFIED
+ }
+ return SigningDappMetadata(icon = null, name = kurdPage.name.name, url = kurdPage.name.name, siteNameKind = kind)
+ }
+
val dappMetadata = dAppInteractor.getDAppInfo(dAppUrl)
return SigningDappMetadata(
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/di/DAppBrowserModule.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/di/DAppBrowserModule.kt
index 4f555dd6..f98ebf28 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/di/DAppBrowserModule.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/di/DAppBrowserModule.kt
@@ -12,29 +12,30 @@ import io.novafoundation.nova.common.di.viewmodel.ViewModelModule
import io.novafoundation.nova.common.mixin.actionAwaitable.ActionAwaitableMixin
import io.novafoundation.nova.common.resources.ContextManager
import io.novafoundation.nova.common.utils.ToastMessageManager
+import io.novafoundation.nova.common.utils.browser.fileChoosing.WebViewFileChooserFactory
+import io.novafoundation.nova.common.utils.browser.permissions.WebViewPermissionAskerFactory
+import io.novafoundation.nova.common.utils.webView.WebViewRequestInterceptor
+import io.novafoundation.nova.common.utils.webView.interceptors.CompoundWebViewRequestInterceptor
import io.novafoundation.nova.core_db.dao.BrowserHostSettingsDao
import io.novafoundation.nova.feature_account_api.domain.interfaces.SelectedAccountUseCase
import io.novafoundation.nova.feature_dapp_api.data.repository.BrowserHostSettingsRepository
-import io.novafoundation.nova.feature_dapp_impl.presentation.DAppRouter
import io.novafoundation.nova.feature_dapp_api.presentation.browser.main.DAppBrowserPayload
import io.novafoundation.nova.feature_dapp_impl.data.repository.FavouritesDAppRepository
import io.novafoundation.nova.feature_dapp_impl.data.repository.PhishingSitesRepository
import io.novafoundation.nova.feature_dapp_impl.data.repository.RealBrowserHostSettingsRepository
import io.novafoundation.nova.feature_dapp_impl.domain.DappInteractor
import io.novafoundation.nova.feature_dapp_impl.domain.browser.DappBrowserInteractor
+import io.novafoundation.nova.feature_dapp_impl.presentation.DAppRouter
import io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.DAppBrowserViewModel
import io.novafoundation.nova.feature_dapp_impl.presentation.search.DAppSearchCommunicator
import io.novafoundation.nova.feature_dapp_impl.utils.tabs.BrowserTabService
import io.novafoundation.nova.feature_dapp_impl.web3.states.ExtensionStoreFactory
-import io.novafoundation.nova.common.utils.browser.fileChoosing.WebViewFileChooserFactory
-import io.novafoundation.nova.common.utils.browser.permissions.WebViewPermissionAskerFactory
-import io.novafoundation.nova.common.utils.webView.WebViewRequestInterceptor
-import io.novafoundation.nova.common.utils.webView.interceptors.CompoundWebViewRequestInterceptor
import io.novafoundation.nova.feature_dapp_impl.web3.webview.interceptors.WalletConnectPairingInterceptor
import io.novafoundation.nova.feature_dapp_impl.web3.webview.interceptors.Web3FallbackInterceptor
import io.novafoundation.nova.feature_external_sign_api.model.ExternalSignCommunicator
import io.novafoundation.nova.feature_wallet_connect_api.presentation.WalletConnectService
import io.novafoundation.nova.runtime.multiNetwork.ChainRegistry
+import io.novafoundation.nova.runtime.names.content.KurdSiteServer
@Module(includes = [ViewModelModule::class])
class DAppBrowserModule {
@@ -103,7 +104,8 @@ class DAppBrowserModule {
dAppInteractor: DappInteractor,
actionAwaitableMixinFactory: ActionAwaitableMixin.Factory,
chainRegistry: ChainRegistry,
- browserTabService: BrowserTabService
+ browserTabService: BrowserTabService,
+ kurdSiteServer: KurdSiteServer,
): ViewModel {
return DAppBrowserViewModel(
router = router,
@@ -116,7 +118,8 @@ class DAppBrowserModule {
extensionStoreFactory = extensionStoreFactory,
actionAwaitableMixinFactory = actionAwaitableMixinFactory,
chainRegistry = chainRegistry,
- browserTabService = browserTabService
+ browserTabService = browserTabService,
+ kurdSiteServer = kurdSiteServer,
)
}
}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/kurd/KurdDetailsSheet.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/kurd/KurdDetailsSheet.kt
new file mode 100644
index 00000000..27cd4312
--- /dev/null
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/kurd/KurdDetailsSheet.kt
@@ -0,0 +1,73 @@
+package io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.kurd
+
+import android.content.Context
+import android.os.Bundle
+import android.view.LayoutInflater
+import io.novafoundation.nova.common.utils.WithContextExtensions
+import io.novafoundation.nova.common.utils.setImageTintRes
+import io.novafoundation.nova.common.utils.setTextColorRes
+import io.novafoundation.nova.common.view.bottomSheet.BaseBottomSheet
+import io.novafoundation.nova.feature_dapp_impl.R
+import io.novafoundation.nova.feature_dapp_impl.databinding.SheetKurdDetailsBinding
+
+/** What was verified about the `.kurd` page the tab shows, from its address bar badge. */
+class KurdDetailsSheet(
+ context: Context,
+ private val page: KurdPageUi.Open,
+ private val ownerText: String,
+ private val onClearSiteData: () -> Unit,
+) : BaseBottomSheet(context, R.style.BottomSheetDialog), WithContextExtensions by WithContextExtensions(context) {
+
+ override val binder: SheetKurdDetailsBinding = SheetKurdDetailsBinding.inflate(LayoutInflater.from(context))
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ val details = page.details
+ binder.kurdDetailsName.text = page.name.name
+
+ when (details.badge) {
+ KurdPageUi.Badge.OFFICIAL -> {
+ binder.kurdDetailsIcon.setImageResource(R.drawable.shield_checkmark_outline)
+ binder.kurdDetailsIcon.setImageTintRes(R.color.icon_positive)
+ binder.kurdDetailsKind.setText(R.string.dapp_kurd_kind_official)
+ binder.kurdDetailsKind.setTextColorRes(R.color.text_positive)
+ binder.kurdDetailsExplanation.setText(R.string.dapp_kurd_official_explanation)
+ }
+ KurdPageUi.Badge.REGISTERED -> {
+ binder.kurdDetailsIcon.setImageResource(R.drawable.ic_lock)
+ binder.kurdDetailsIcon.setImageTintRes(R.color.icon_secondary)
+ binder.kurdDetailsKind.setText(R.string.dapp_kurd_kind_registered)
+ binder.kurdDetailsKind.setTextColorRes(R.color.text_secondary)
+ binder.kurdDetailsExplanation.setText(R.string.dapp_kurd_registered_explanation)
+ }
+ KurdPageUi.Badge.UNVERIFIED -> {
+ binder.kurdDetailsIcon.setImageResource(R.drawable.ic_warning_filled)
+ binder.kurdDetailsIcon.setImageTintRes(R.color.icon_warning)
+ binder.kurdDetailsKind.setText(R.string.dapp_kurd_kind_unverified)
+ binder.kurdDetailsKind.setTextColorRes(R.color.text_warning)
+ binder.kurdDetailsExplanation.setText(R.string.dapp_kurd_unverified_explanation)
+ }
+ }
+
+ binder.kurdDetailsVerification.setTitle(R.string.dapp_kurd_details_verification)
+ binder.kurdDetailsVerification.showValue(verificationText(details))
+ binder.kurdDetailsOwner.setTitle(R.string.dapp_kurd_details_owner)
+ binder.kurdDetailsOwner.showValue(ownerText)
+ binder.kurdDetailsContent.setTitle(R.string.dapp_kurd_details_content)
+ binder.kurdDetailsContent.showValue(shortened(details.contentId))
+
+ binder.kurdDetailsClearData.setOnClickListener {
+ onClearSiteData()
+ dismiss()
+ }
+ }
+
+ private fun verificationText(details: KurdPageUi.Details): String = when {
+ details.badge == KurdPageUi.Badge.UNVERIFIED -> context.getString(R.string.dapp_kurd_verified_by_nodes)
+ details.provenAtBlock != null -> context.getString(R.string.dapp_kurd_verified_at_block, details.provenAtBlock.toString())
+ else -> context.getString(R.string.dapp_kurd_verified_on_chain)
+ }
+
+ private fun shortened(cid: String) = if (cid.length > 12) cid.take(4) + "…" + cid.takeLast(4) else cid
+}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/kurd/KurdPageUi.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/kurd/KurdPageUi.kt
new file mode 100644
index 00000000..e655f47a
--- /dev/null
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/kurd/KurdPageUi.kt
@@ -0,0 +1,79 @@
+package io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.kurd
+
+import io.novafoundation.nova.runtime.names.KurdName
+import io.novafoundation.nova.runtime.names.NameRecord
+import io.novafoundation.nova.runtime.names.content.KurdSiteServer.PageState
+import java.net.URI
+
+/** What the browser shows for a `.kurd` page: a badge on an open page, or a notice in its place. */
+sealed interface KurdPageUi {
+
+ val name: KurdName
+
+ /** [onChainVersion]: a feed showing the release the chain names, as no newer one could be confirmed. */
+ class Open(override val name: KurdName, val badge: Badge, val details: Details, val onChainVersion: Boolean = false) : KurdPageUi
+
+ class Notice(override val name: KurdName, val kind: NoticeKind) : KurdPageUi
+
+ enum class Badge {
+ /** Granted by Parliament, or under such a name: the state's own. */
+ OFFICIAL,
+
+ /** Bought: the content is verified, who made it is not. */
+ REGISTERED,
+
+ /** Opened by the reader's choice, on two RPC nodes' word. */
+ UNVERIFIED,
+ }
+
+ enum class NoticeKind { REFUSED, NEEDS_CONSENT, NOT_REGISTERED, NO_SITE, UNAVAILABLE }
+
+ class Details(
+ val badge: Badge,
+ /** The finalized block the name was proven at; null when read through RPC or not reported. */
+ val provenAtBlock: Long?,
+ val owner: Owner,
+ val contentId: String,
+ )
+
+ sealed interface Owner {
+ /** Parliament or an office: a state institution, acting through its multisig. */
+ object Institution : Owner
+
+ class Account(val accountId: ByteArray) : Owner
+ }
+
+ companion object {
+
+ /** The name a page URL is on, or null for any other page. */
+ fun nameOf(pageUrl: String?): KurdName? {
+ val host = runCatching { URI(pageUrl ?: return null).host }.getOrNull() ?: return null
+ return if (KurdName.isKurdHost(host)) KurdName.parse(host) else null
+ }
+
+ /** Null while the page's document has not been answered yet. */
+ fun from(name: KurdName, state: PageState?): KurdPageUi? = when (state) {
+ null -> null
+ is PageState.Open -> {
+ val resolution = state.resolution
+ val badge = when {
+ !resolution.verified -> Badge.UNVERIFIED
+ resolution.official -> Badge.OFFICIAL
+ else -> Badge.REGISTERED
+ }
+ val owner = when (val owner = resolution.record.owner) {
+ is NameRecord.Owner.Account -> Owner.Account(owner.accountId)
+ is NameRecord.Owner.Office, NameRecord.Owner.Governance -> Owner.Institution
+ }
+ val provenAt = resolution.block.takeIf { resolution.verified }
+
+ Open(name, badge, Details(badge, provenAt, owner, state.root.toString()), state.onChainVersion)
+ }
+ is PageState.NeedsConsent -> Notice(name, NoticeKind.NEEDS_CONSENT)
+ PageState.Refused -> Notice(name, NoticeKind.REFUSED)
+ PageState.NotRegistered -> Notice(name, NoticeKind.NOT_REGISTERED)
+ PageState.NoSite -> Notice(name, NoticeKind.NO_SITE)
+ PageState.Unavailable -> Notice(name, NoticeKind.UNAVAILABLE)
+ }
+ }
+}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/view/AddressBarView.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/view/AddressBarView.kt
index 427fa25f..5196d79e 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/view/AddressBarView.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/browser/main/view/AddressBarView.kt
@@ -4,13 +4,17 @@ import android.content.Context
import android.util.AttributeSet
import android.view.Gravity
import android.widget.LinearLayout
+import androidx.core.view.updateLayoutParams
import io.novafoundation.nova.common.utils.WithContextExtensions
+import io.novafoundation.nova.common.utils.dp
import io.novafoundation.nova.common.utils.inflater
+import io.novafoundation.nova.common.utils.makeVisible
import io.novafoundation.nova.common.utils.setImageTintRes
import io.novafoundation.nova.common.utils.setTextColorRes
import io.novafoundation.nova.common.utils.setVisible
import io.novafoundation.nova.feature_dapp_impl.R
import io.novafoundation.nova.feature_dapp_impl.databinding.ViewAddressBarBinding
+import io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.kurd.KurdPageUi
class AddressBarView @JvmOverloads constructor(
context: Context,
@@ -37,7 +41,41 @@ class AddressBarView @JvmOverloads constructor(
binder.addressBarIcon.setVisible(shouldShow)
}
+ /**
+ * The badge of a `.kurd` page, or none. It replaces the padlock: a `.kurd` page is not reached
+ * over the network the padlock speaks of, and the badge says what was verified instead.
+ */
+ fun showKurdBadge(badge: KurdPageUi.Badge?, onClick: () -> Unit) {
+ val badgeView = binder.addressBarKurdBadge
+ badgeView.setVisible(badge != null)
+ binder.addressBarUrl.updateLayoutParams { marginEnd = (if (badge != null) 6 else 32).dp(context) }
+ if (badge == null) {
+ badgeView.setOnClickListener(null)
+ return
+ }
+
+ val (textRes, colorRes, iconRes) = when (badge) {
+ KurdPageUi.Badge.OFFICIAL -> Triple(R.string.dapp_kurd_badge_official, R.color.text_positive, R.drawable.shield_checkmark_outline)
+ KurdPageUi.Badge.REGISTERED -> Triple(R.string.dapp_kurd_badge_registered, R.color.text_secondary, R.drawable.ic_lock)
+ KurdPageUi.Badge.UNVERIFIED -> Triple(R.string.dapp_kurd_badge_unverified, R.color.text_warning, R.drawable.ic_warning_filled)
+ }
+ val iconTint = when (badge) {
+ KurdPageUi.Badge.OFFICIAL -> R.color.icon_positive
+ KurdPageUi.Badge.REGISTERED -> R.color.icon_secondary
+ KurdPageUi.Badge.UNVERIFIED -> R.color.icon_warning
+ }
+
+ badgeView.setText(textRes)
+ badgeView.setTextColorRes(colorRes)
+ binder.addressBarIcon.makeVisible()
+ binder.addressBarIcon.setImageResource(iconRes)
+ binder.addressBarIcon.setImageTintRes(iconTint)
+ binder.addressBarUrl.setTextColorRes(R.color.text_primary)
+ badgeView.setOnClickListener { onClick() }
+ }
+
fun showSecure(shouldShow: Boolean) {
+ binder.addressBarIcon.setImageResource(R.drawable.ic_lock)
binder.addressBarIcon.setVisible(shouldShow)
if (shouldShow) {
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/DAppSearchViewModel.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/DAppSearchViewModel.kt
index 9825ca49..03767eee 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/DAppSearchViewModel.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/DAppSearchViewModel.kt
@@ -13,20 +13,25 @@ import io.novafoundation.nova.common.utils.Event
import io.novafoundation.nova.common.utils.inBackground
import io.novafoundation.nova.common.utils.sendEvent
import io.novafoundation.nova.common.utils.withSafeLoading
-import io.novafoundation.nova.feature_dapp_impl.presentation.DAppRouter
import io.novafoundation.nova.feature_dapp_api.presentation.browser.main.DAppBrowserPayload
import io.novafoundation.nova.feature_dapp_impl.R
import io.novafoundation.nova.feature_dapp_impl.domain.DappInteractor
import io.novafoundation.nova.feature_dapp_impl.domain.search.DappSearchGroup
import io.novafoundation.nova.feature_dapp_impl.domain.search.DappSearchResult
import io.novafoundation.nova.feature_dapp_impl.domain.search.SearchDappInteractor
+import io.novafoundation.nova.feature_dapp_impl.presentation.DAppRouter
import io.novafoundation.nova.feature_dapp_impl.presentation.common.dappCategoryToUi
import io.novafoundation.nova.feature_dapp_impl.presentation.search.model.DappSearchModel
+import io.novafoundation.nova.runtime.names.KurdLookalikes
+import io.novafoundation.nova.runtime.names.KurdName
+import io.novafoundation.nova.runtime.names.KurdNameResolver
+import io.novafoundation.nova.runtime.names.KurdResolution
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.launch
+import kotlinx.coroutines.withTimeoutOrNull
@OptIn(ExperimentalCoroutinesApi::class)
class DAppSearchViewModel(
@@ -37,11 +42,14 @@ class DAppSearchViewModel(
private val payload: SearchPayload,
private val dAppSearchResponder: DAppSearchResponder,
private val actionAwaitableMixinFactory: ActionAwaitableMixin.Factory,
- private val appLinksProvider: AppLinksProvider
+ private val appLinksProvider: AppLinksProvider,
+ private val kurdNameResolver: KurdNameResolver,
) : BaseViewModel() {
val dAppNotInCatalogWarning = actionAwaitableMixinFactory.confirmingAction()
+ val kurdLookalikeWarning = actionAwaitableMixinFactory.create()
+
val query = MutableStateFlow(payload.initialUrl.orEmpty())
private val _selectQueryTextEvent = MutableLiveData>()
@@ -91,6 +99,7 @@ class DAppSearchViewModel(
val content = when (searchGroup) {
DappSearchGroup.DAPPS -> resourceManager.getString(R.string.dapp_dapps)
DappSearchGroup.SEARCH -> resourceManager.getString(R.string.common_search)
+ DappSearchGroup.KURD_NAME -> resourceManager.getString(R.string.dapp_search_kurd_name)
}
return TextHeader(content)
@@ -117,6 +126,14 @@ class DAppSearchViewModel(
searchResult = searchResult,
actionIcon = null
)
+
+ is DappSearchResult.KurdName -> DappSearchModel(
+ title = searchResult.name.name,
+ description = resourceManager.getString(R.string.dapp_search_kurd_name_subtitle),
+ iconRes = R.drawable.shield_checkmark_outline,
+ searchResult = searchResult,
+ actionIcon = null
+ )
}
}
@@ -126,6 +143,7 @@ class DAppSearchViewModel(
is DappSearchResult.Dapp -> searchResult.dapp.url
is DappSearchResult.Search -> searchResult.searchUrl
is DappSearchResult.Url -> searchResult.url
+ is DappSearchResult.KurdName -> urlAfterLookalikeCheck(searchResult.name)
}
if (!searchResult.isTrustedByNova) {
@@ -143,6 +161,25 @@ class DAppSearchViewModel(
}
}
+ /**
+ * The typed name's address, unless a proven official name it imitates exists and the reader
+ * chooses that one. Looked up only when the typed name has such a candidate, and for a few
+ * seconds at most: the opened page still shows by its badge whether it is official.
+ */
+ private suspend fun urlAfterLookalikeCheck(typed: KurdName): String {
+ val official = withTimeoutOrNull(LOOKALIKE_CHECK_MILLIS) {
+ KurdLookalikes.candidates(typed).firstOrNull { candidate ->
+ val resolution = kurdNameResolver.resolve(candidate)
+ resolution is KurdResolution.Resolved && resolution.verified && resolution.official
+ }
+ } ?: return DappSearchResult.KurdName(typed).url
+
+ return when (kurdLookalikeWarning.awaitAction(KurdLookalikeWarning(typed, official))) {
+ KurdLookalikeChoice.GO_OFFICIAL -> DappSearchResult.KurdName(official).url
+ KurdLookalikeChoice.OPEN_TYPED -> DappSearchResult.KurdName(typed).url
+ }
+ }
+
private fun shouldReportResult() = when (payload.request) {
SearchPayload.Request.GO_TO_URL -> true
@@ -157,3 +194,5 @@ class DAppSearchViewModel(
}
}
}
+
+private const val LOOKALIKE_CHECK_MILLIS = 8_000L
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/DappSearchFragment.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/DappSearchFragment.kt
index 79d6c3c2..c0e80c55 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/DappSearchFragment.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/DappSearchFragment.kt
@@ -108,6 +108,10 @@ class DappSearchFragment : BaseFragment
+ KurdLookalikeSheet(providedContext, event.payload, onChoice = event.onSuccess, onCancel = event.onCancel).show()
+ }
+
viewModel.dAppNotInCatalogWarning.awaitableActionLiveData.observeEvent { event ->
warningDialog(
context = providedContext,
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/KurdLookalikeSheet.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/KurdLookalikeSheet.kt
new file mode 100644
index 00000000..96ed62ba
--- /dev/null
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/KurdLookalikeSheet.kt
@@ -0,0 +1,44 @@
+package io.novafoundation.nova.feature_dapp_impl.presentation.search
+
+import android.content.Context
+import android.os.Bundle
+import android.view.LayoutInflater
+import io.novafoundation.nova.common.utils.WithContextExtensions
+import io.novafoundation.nova.common.view.bottomSheet.BaseBottomSheet
+import io.novafoundation.nova.feature_dapp_impl.R
+import io.novafoundation.nova.feature_dapp_impl.databinding.SheetKurdLookalikeBinding
+import io.novafoundation.nova.runtime.names.KurdName
+
+class KurdLookalikeWarning(val typed: KurdName, val official: KurdName)
+
+enum class KurdLookalikeChoice { GO_OFFICIAL, OPEN_TYPED }
+
+/** Before opening a typed name that a proven official name could be mistaken for. */
+class KurdLookalikeSheet(
+ context: Context,
+ private val warning: KurdLookalikeWarning,
+ private val onChoice: (KurdLookalikeChoice) -> Unit,
+ onCancel: () -> Unit,
+) : BaseBottomSheet(context, R.style.BottomSheetDialog, onCancel), WithContextExtensions by WithContextExtensions(context) {
+
+ override val binder: SheetKurdLookalikeBinding = SheetKurdLookalikeBinding.inflate(LayoutInflater.from(context))
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ binder.kurdLookalikeTyped.setTitle(R.string.dapp_kurd_lookalike_typed)
+ binder.kurdLookalikeTyped.showValue(warning.typed.name)
+ binder.kurdLookalikeOfficial.setTitle(R.string.dapp_kurd_lookalike_official)
+ binder.kurdLookalikeOfficial.showValue(warning.official.name, context.getString(R.string.dapp_kurd_badge_official))
+
+ binder.kurdLookalikeGoOfficial.text = context.getString(R.string.dapp_kurd_lookalike_go, warning.official.name)
+ binder.kurdLookalikeGoOfficial.setOnClickListener { choose(KurdLookalikeChoice.GO_OFFICIAL) }
+ binder.kurdLookalikeOpenAnyway.text = context.getString(R.string.dapp_kurd_lookalike_open_anyway, warning.typed.name)
+ binder.kurdLookalikeOpenAnyway.setOnClickListener { choose(KurdLookalikeChoice.OPEN_TYPED) }
+ }
+
+ private fun choose(choice: KurdLookalikeChoice) {
+ onChoice(choice)
+ dismiss()
+ }
+}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/SearchDappAdapter.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/SearchDappAdapter.kt
index 6add1b46..8c75472e 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/SearchDappAdapter.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/SearchDappAdapter.kt
@@ -8,9 +8,10 @@ import io.novafoundation.nova.common.list.PayloadGenerator
import io.novafoundation.nova.common.list.headers.TextHeader
import io.novafoundation.nova.common.list.resolvePayload
import io.novafoundation.nova.common.utils.inflater
-import io.novafoundation.nova.feature_dapp_impl.domain.search.DappSearchResult
import io.novafoundation.nova.feature_dapp_api.presentation.view.DAppView
+import io.novafoundation.nova.feature_dapp_impl.R
import io.novafoundation.nova.feature_dapp_impl.databinding.ItemDappSearchCategoryBinding
+import io.novafoundation.nova.feature_dapp_impl.domain.search.DappSearchResult
import io.novafoundation.nova.feature_dapp_impl.presentation.search.model.DappSearchModel
class SearchDappAdapter(
@@ -77,6 +78,7 @@ private object DiffCallback : BaseGroupedDiffCallback true
is DappSearchResult.Url -> true
+ is DappSearchResult.KurdName -> true
is DappSearchResult.Dapp -> false
}
}
@@ -100,7 +102,7 @@ private class SearchHolder(
}
fun bind(item: DappSearchModel) = with(dAppView) {
- setIconUrl(item.icon)
+ if (item.iconRes != null) setIconResource(item.iconRes, R.color.icon_positive) else setIconUrl(item.icon)
bindTitle(item)
setSubtitle(item.description)
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/di/DAppSearchModule.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/di/DAppSearchModule.kt
index 3e9ebe81..ac881c3c 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/di/DAppSearchModule.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/di/DAppSearchModule.kt
@@ -13,13 +13,14 @@ import io.novafoundation.nova.common.di.viewmodel.ViewModelModule
import io.novafoundation.nova.common.mixin.actionAwaitable.ActionAwaitableMixin
import io.novafoundation.nova.common.resources.ResourceManager
import io.novafoundation.nova.feature_dapp_api.data.repository.DAppMetadataRepository
-import io.novafoundation.nova.feature_dapp_impl.presentation.DAppRouter
import io.novafoundation.nova.feature_dapp_impl.data.repository.FavouritesDAppRepository
import io.novafoundation.nova.feature_dapp_impl.domain.DappInteractor
import io.novafoundation.nova.feature_dapp_impl.domain.search.SearchDappInteractor
+import io.novafoundation.nova.feature_dapp_impl.presentation.DAppRouter
import io.novafoundation.nova.feature_dapp_impl.presentation.search.DAppSearchCommunicator
import io.novafoundation.nova.feature_dapp_impl.presentation.search.DAppSearchViewModel
import io.novafoundation.nova.feature_dapp_impl.presentation.search.SearchPayload
+import io.novafoundation.nova.runtime.names.KurdNameResolver
@Module(includes = [ViewModelModule::class])
class DAppSearchModule {
@@ -47,7 +48,8 @@ class DAppSearchModule {
searchResponder: DAppSearchCommunicator,
payload: SearchPayload,
actionAwaitableMixinFactory: ActionAwaitableMixin.Factory,
- appLinksProvider: AppLinksProvider
+ appLinksProvider: AppLinksProvider,
+ kurdNameResolver: KurdNameResolver,
): ViewModel {
return DAppSearchViewModel(
router = router,
@@ -57,7 +59,8 @@ class DAppSearchModule {
payload = payload,
actionAwaitableMixinFactory = actionAwaitableMixinFactory,
appLinksProvider = appLinksProvider,
- dappInteractor = dappInteractor
+ dappInteractor = dappInteractor,
+ kurdNameResolver = kurdNameResolver,
)
}
}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/model/DappSearchModel.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/model/DappSearchModel.kt
index 3cf5ce09..fd25da2d 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/model/DappSearchModel.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/presentation/search/model/DappSearchModel.kt
@@ -8,5 +8,6 @@ class DappSearchModel(
val description: String? = null,
val icon: String? = null,
@DrawableRes val actionIcon: Int?,
+ @DrawableRes val iconRes: Int? = null,
val searchResult: DappSearchResult
)
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/utils/tabs/models/BrowserTabSession.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/utils/tabs/models/BrowserTabSession.kt
index 3212bbd5..fd4e32e2 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/utils/tabs/models/BrowserTabSession.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/utils/tabs/models/BrowserTabSession.kt
@@ -1,5 +1,6 @@
package io.novafoundation.nova.feature_dapp_impl.utils.tabs.models
+import io.novafoundation.nova.runtime.names.content.KurdSiteServer
import android.graphics.Bitmap
import android.webkit.WebResourceRequest
import android.webkit.WebView
@@ -22,7 +23,8 @@ import kotlinx.coroutines.withContext
class BrowserTabSessionFactory(
private val compoundWeb3Injector: CompoundWeb3Injector,
private val contextManager: ContextManager,
- private val integrityCheckJSBridgeFactory: IntegrityCheckJSBridgeFactory
+ private val integrityCheckJSBridgeFactory: IntegrityCheckJSBridgeFactory,
+ private val kurdSiteServer: KurdSiteServer,
) {
suspend fun create(tabId: String, startUrl: String, onPageChangedCallback: OnPageChangedCallback): BrowserTabSession {
@@ -37,7 +39,8 @@ class BrowserTabSessionFactory(
webView = webView,
integrityCheckJSBridge = integrityCheckProvider,
compoundWeb3Injector = compoundWeb3Injector,
- onPageChangedCallback = onPageChangedCallback
+ onPageChangedCallback = onPageChangedCallback,
+ kurdSiteServer = kurdSiteServer,
)
}
}
@@ -49,12 +52,14 @@ class BrowserTabSession(
val webView: WebView,
compoundWeb3Injector: CompoundWeb3Injector,
private val onPageChangedCallback: OnPageChangedCallback,
- private val integrityCheckJSBridge: IntegrityCheckJSBridge
+ private val integrityCheckJSBridge: IntegrityCheckJSBridge,
+ kurdSiteServer: KurdSiteServer,
) : PageCallback, CoroutineScope by CoroutineScope(Dispatchers.Main) {
val webViewClient: Web3WebViewClient = Web3WebViewClient(
webView = webView,
- pageCallback = this
+ pageCallback = this,
+ kurdSiteServer = kurdSiteServer,
)
var currentUrl: String = startUrl
@@ -63,8 +68,9 @@ class BrowserTabSession(
init {
webView.injectWeb3(webViewClient)
- webView.loadUrl(startUrl)
+ // Before the first load: the bridge is only exposed to documents loaded after it is added
compoundWeb3Injector.initialInject(webView)
+ webView.loadUrl(startUrl)
integrityCheckJSBridge.errorFlow
.onEach { sessionCallback?.onPageError(it) }
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/Web3Transport.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/Web3Transport.kt
index e28d99e1..22e0af58 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/Web3Transport.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/Web3Transport.kt
@@ -8,6 +8,9 @@ interface Web3Transport> {
interface Request {
+ /** The origin of the page that sent it, as the WebView reported it rather than the page. */
+ val origin: String
+
fun accept(response: RESPONSE)
fun reject(error: Throwable)
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/states/DefaultMetamaskState.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/states/DefaultMetamaskState.kt
index 616475da..43ce5014 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/states/DefaultMetamaskState.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/states/DefaultMetamaskState.kt
@@ -58,6 +58,11 @@ class DefaultMetamaskState(
private val knownChains = mapOf(MetamaskChain.ETHEREUM.chainId to MetamaskChain.ETHEREUM)
override suspend fun acceptRequest(request: MetamaskTransportRequest<*>, transition: StateMachineTransition) {
+ if (!isFromCurrentPage(request)) {
+ request.reject(MetamaskError.Rejected())
+ return
+ }
+
when (request) {
is MetamaskTransportRequest.RequestAccounts -> handleRequestAccounts(request, transition)
is MetamaskTransportRequest.AddEthereumChain -> handleAddEthereumChain(request, transition)
@@ -181,7 +186,7 @@ class DefaultMetamaskState(
metamaskRequest: MetamaskTransportRequest,
hostApiConfirmRequest: ExternalSignRequest.Evm
) {
- when (val response = hostApi.confirmTx(hostApiConfirmRequest)) {
+ when (val response = hostApi.confirmTx(hostApiConfirmRequest, metamaskRequest.origin)) {
is ConfirmTxResponse.Rejected -> metamaskRequest.reject(MetamaskError.Rejected())
is ConfirmTxResponse.Signed -> metamaskRequest.accept(response.signature)
is ConfirmTxResponse.Sent -> metamaskRequest.accept(response.txHash)
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskInjector.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskInjector.kt
index 86ffa6e7..321e9ae1 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskInjector.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskInjector.kt
@@ -46,7 +46,7 @@ class MetamaskInjector(
window.ethereum = new pezkuwi.Provider($providerConfigJson);
window.web3 = new pezkuwi.Web3(window.ethereum);
pezkuwi.postMessage = (jsonString) => {
- ${jsInterfaceFullName(JS_INTERFACE_NAME)}.onNewMessage(JSON.stringify(jsonString))
+ ${jsInterfaceFullName(JS_INTERFACE_NAME)}.postMessage(JSON.stringify(jsonString))
};
""".trimIndent()
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskTransport.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskTransport.kt
index 2f5c997d..a8a0fc84 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskTransport.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskTransport.kt
@@ -46,37 +46,37 @@ class MetamaskTransport(
scope: CoroutineScope,
) : WebViewWeb3Transport>(scope, webViewWeb3JavaScriptInterface) {
- override suspend fun messageToRequest(message: String): MetamaskTransportRequest<*>? = runCatching {
+ override suspend fun messageToRequest(message: String, origin: String): MetamaskTransportRequest<*>? = runCatching {
val request = gson.fromJson(message)
when (request.identifier) {
MetamaskTransportRequest.Identifier.REQUEST_ACCOUNTS.id -> {
- MetamaskTransportRequest.RequestAccounts(request.id, gson, responder)
+ MetamaskTransportRequest.RequestAccounts(request.id, origin, gson, responder)
}
MetamaskTransportRequest.Identifier.ADD_ETHEREUM_CHAIN.id -> {
val chain = gson.fromParsedHierarchy(request.payload)
- MetamaskTransportRequest.AddEthereumChain(request.id, gson, responder, chain)
+ MetamaskTransportRequest.AddEthereumChain(request.id, origin, gson, responder, chain)
}
MetamaskTransportRequest.Identifier.SWITCH_ETHEREUM_CHAIN.id -> {
val switchChainRequest = gson.fromParsedHierarchy(request.payload)
- MetamaskTransportRequest.SwitchEthereumChain(request.id, gson, responder, switchChainRequest.chainId)
+ MetamaskTransportRequest.SwitchEthereumChain(request.id, origin, gson, responder, switchChainRequest.chainId)
}
MetamaskTransportRequest.Identifier.SIGN_TRANSACTION.id -> {
val transaction = gson.fromParsedHierarchy(request.payload)
- MetamaskTransportRequest.SendTransaction(request.id, gson, responder, transaction)
+ MetamaskTransportRequest.SendTransaction(request.id, origin, gson, responder, transaction)
}
MetamaskTransportRequest.Identifier.SIGN_TYPED_MESSAGE.id -> {
val typedMessage = gson.fromParsedHierarchy(request.payload)
- MetamaskTransportRequest.SignTypedMessage(request.id, gson, responder, typedMessage)
+ MetamaskTransportRequest.SignTypedMessage(request.id, origin, gson, responder, typedMessage)
}
MetamaskTransportRequest.Identifier.PERSONAL_SIGN.id -> {
val personalSignMessage = gson.fromParsedHierarchy(request.payload)
- MetamaskTransportRequest.PersonalSign(request.id, gson, responder, personalSignMessage)
+ MetamaskTransportRequest.PersonalSign(request.id, origin, gson, responder, personalSignMessage)
}
else -> null
}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskTransportRequest.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskTransportRequest.kt
index ef1cf6e0..3a37859c 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskTransportRequest.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/metamask/transport/MetamaskTransportRequest.kt
@@ -12,6 +12,7 @@ import io.novafoundation.nova.feature_dapp_impl.web3.metamask.model.SignedMessag
sealed class MetamaskTransportRequest(
val id: String,
+ override val origin: String,
private val gson: Gson,
protected val responder: MetamaskResponder,
) : Web3Transport.Request {
@@ -43,42 +44,48 @@ sealed class MetamaskTransportRequest(
class RequestAccounts(
id: String,
+ origin: String,
gson: Gson,
responder: MetamaskResponder
- ) : MetamaskTransportRequest>(id, gson, responder)
+ ) : MetamaskTransportRequest>(id, origin, gson, responder)
class AddEthereumChain(
id: String,
+ origin: String,
gson: Gson,
responder: MetamaskResponder,
val chain: MetamaskChain,
- ) : MetamaskTransportRequest(id, gson, responder)
+ ) : MetamaskTransportRequest(id, origin, gson, responder)
class SwitchEthereumChain(
id: String,
+ origin: String,
gson: Gson,
responder: MetamaskResponder,
val chainId: String
- ) : MetamaskTransportRequest(id, gson, responder)
+ ) : MetamaskTransportRequest(id, origin, gson, responder)
class SendTransaction(
id: String,
+ origin: String,
gson: Gson,
responder: MetamaskResponder,
val transaction: MetamaskTransaction
- ) : MetamaskTransportRequest(id, gson, responder)
+ ) : MetamaskTransportRequest(id, origin, gson, responder)
class SignTypedMessage(
id: String,
+ origin: String,
gson: Gson,
responder: MetamaskResponder,
val message: MetamaskTypedMessage
- ) : MetamaskTransportRequest(id, gson, responder)
+ ) : MetamaskTransportRequest(id, origin, gson, responder)
class PersonalSign(
id: String,
+ origin: String,
gson: Gson,
responder: MetamaskResponder,
val message: MetamaskPersonalSignMessage
- ) : MetamaskTransportRequest(id, gson, responder)
+ ) : MetamaskTransportRequest(id, origin, gson, responder)
}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/polkadotJs/PolkadotJsTransport.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/polkadotJs/PolkadotJsTransport.kt
index 250e4b6d..59e4efd2 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/polkadotJs/PolkadotJsTransport.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/polkadotJs/PolkadotJsTransport.kt
@@ -7,6 +7,7 @@ import io.novafoundation.nova.common.utils.parseArbitraryObject
import io.novafoundation.nova.feature_dapp_impl.web3.Web3Responder
import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.model.mapRawPayloadToSignerPayloadJSON
import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.model.mapRawPayloadToSignerPayloadRaw
+import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.rpc.rpcCall
import io.novafoundation.nova.feature_dapp_impl.web3.webview.WebViewWeb3JavaScriptInterface
import io.novafoundation.nova.feature_dapp_impl.web3.webview.WebViewWeb3Transport
import kotlinx.coroutines.CoroutineScope
@@ -34,12 +35,13 @@ class PolkadotJsTransport(
scope: CoroutineScope,
) : WebViewWeb3Transport>(scope, webViewWeb3JavaScriptInterface) {
- override suspend fun messageToRequest(message: String): PolkadotJsTransportRequest<*>? {
+ override suspend fun messageToRequest(message: String, origin: String): PolkadotJsTransportRequest<*>? {
Log.d(LOG_TAG, message)
val parsedMessage = gson.parseArbitraryObject(message)!!
- val url = parsedMessage["url"] as? String ?: return null
+ // The page writes its own url into the message; the WebView's word for the origin is used instead
+ val url = origin
val requestId = parsedMessage["id"] as? String ?: return null
return when (parsedMessage["msgType"]) {
@@ -74,6 +76,24 @@ class PolkadotJsTransport(
PolkadotJsTransportRequest.Identifier.PROVIDE_METADATA.id ->
PolkadotJsTransportRequest.Single.ProvideMetadata(web3Responder, url, requestId)
+ PolkadotJsTransportRequest.Identifier.RPC_LIST_PROVIDERS.id ->
+ PolkadotJsTransportRequest.Rpc.ListProviders(web3Responder, url, requestId, gson)
+
+ PolkadotJsTransportRequest.Identifier.RPC_START_PROVIDER.id -> (parsedMessage["request"] as? String)?.let { key ->
+ PolkadotJsTransportRequest.Rpc.StartProvider(web3Responder, url, requestId, key, gson)
+ }
+
+ PolkadotJsTransportRequest.Identifier.RPC_SEND.id -> rpcCall(message)?.let { (method, params) ->
+ PolkadotJsTransportRequest.Rpc.Send(scope = this, web3Responder, url, requestId, method, params, gson)
+ }
+
+ PolkadotJsTransportRequest.Identifier.RPC_SUBSCRIBE.id -> rpcCall(message)?.let { (method, params) ->
+ PolkadotJsTransportRequest.Rpc.Subscribe(scope = this, web3Responder, url, requestId, method, params, gson)
+ }
+
+ PolkadotJsTransportRequest.Identifier.RPC_SUBSCRIBE_CONNECTED.id ->
+ PolkadotJsTransportRequest.Rpc.SubscribeConnected(scope = this, web3Responder, url, requestId)
+
else -> null
}
}
diff --git a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/polkadotJs/PolkadotJsTransportRequest.kt b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/polkadotJs/PolkadotJsTransportRequest.kt
index cd0635e7..da4fcbd6 100644
--- a/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/polkadotJs/PolkadotJsTransportRequest.kt
+++ b/feature-dapp-impl/src/main/java/io/novafoundation/nova/feature_dapp_impl/web3/polkadotJs/PolkadotJsTransportRequest.kt
@@ -7,9 +7,11 @@ import io.novafoundation.nova.feature_dapp_impl.web3.Web3Transport
import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.model.InjectedAccount
import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.model.InjectedMetadataKnown
import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.model.SignerPayload
+import io.novafoundation.nova.feature_dapp_impl.web3.polkadotJs.rpc.ProviderMeta
import io.novafoundation.nova.feature_external_sign_api.model.signPayload.polkadot.PolkadotSignerResult
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
@@ -21,6 +23,9 @@ sealed class PolkadotJsTransportRequest(
val requestId: String,
) : Web3Transport.Request {
+ /** [url] is the sender's origin as the WebView reported it; the page's own claim is not read. */
+ override val origin: String get() = url
+
override fun reject(error: Throwable) {
web3Responder.respondError(requestId, error)
}
@@ -33,6 +38,11 @@ sealed class PolkadotJsTransportRequest(
LIST_METADATA("pub(metadata.list)"),
PROVIDE_METADATA("pub(metadata.provide)"),
SIGN_BYTES("pub(bytes.sign)"),
+ RPC_LIST_PROVIDERS("pub(rpc.listProviders)"),
+ RPC_START_PROVIDER("pub(rpc.startProvider)"),
+ RPC_SEND("pub(rpc.send)"),
+ RPC_SUBSCRIBE("pub(rpc.subscribe)"),
+ RPC_SUBSCRIBE_CONNECTED("pub(rpc.subscribeConnected)"),
}
sealed class Single(
@@ -126,6 +136,95 @@ sealed class PolkadotJsTransportRequest(
}
}
+ /** The provider half of the extension API: the page's chain calls, answered over the wallet's connection. */
+ sealed class Rpc(
+ web3Responder: Web3Responder,
+ url: String,
+ identifier: Identifier,
+ requestId: String,
+ ) : PolkadotJsTransportRequest(web3Responder, identifier, url, requestId) {
+
+ class ListProviders(
+ web3Responder: Web3Responder,
+ url: String,
+ requestId: String,
+ private val gson: Gson,
+ ) : Rpc