From 7bf182c4a62a39706baffbda9453e085ac215b34 Mon Sep 17 00:00:00 2001 From: Valentun Date: Mon, 25 Nov 2024 12:10:46 +0300 Subject: [PATCH 1/3] Fix - handle evm addresses in polkadot namespace signing --- .../PolkadotExternalSignInteractor.kt | 24 +++++++++++++++---- .../nova/runtime/ext/ChainExt.kt | 10 ++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/feature-external-sign-impl/src/main/java/io/novafoundation/nova/feature_external_sign_impl/domain/sign/polkadot/PolkadotExternalSignInteractor.kt b/feature-external-sign-impl/src/main/java/io/novafoundation/nova/feature_external_sign_impl/domain/sign/polkadot/PolkadotExternalSignInteractor.kt index bd36f264a4..d9b2aab568 100644 --- a/feature-external-sign-impl/src/main/java/io/novafoundation/nova/feature_external_sign_impl/domain/sign/polkadot/PolkadotExternalSignInteractor.kt +++ b/feature-external-sign-impl/src/main/java/io/novafoundation/nova/feature_external_sign_impl/domain/sign/polkadot/PolkadotExternalSignInteractor.kt @@ -3,7 +3,6 @@ package io.novafoundation.nova.feature_external_sign_impl.domain.sign.polkadot import com.google.gson.Gson import io.novafoundation.nova.common.address.AddressIconGenerator import io.novafoundation.nova.common.address.AddressModel -import io.novafoundation.nova.common.address.createAddressModel import io.novafoundation.nova.common.utils.asHexString import io.novafoundation.nova.common.utils.bigIntegerFromHex import io.novafoundation.nova.common.utils.intFromHex @@ -27,6 +26,7 @@ import io.novafoundation.nova.feature_external_sign_impl.domain.sign.ExternalSig import io.novafoundation.nova.feature_wallet_api.domain.interfaces.TokenRepository import io.novafoundation.nova.feature_wallet_api.domain.model.Token import io.novafoundation.nova.runtime.ext.accountIdOf +import io.novafoundation.nova.runtime.ext.anyAddressToAccountId import io.novafoundation.nova.runtime.ext.utilityAsset import io.novafoundation.nova.runtime.extrinsic.CustomSignedExtensions import io.novafoundation.nova.runtime.extrinsic.metadata.MetadataShortenerService @@ -38,6 +38,7 @@ import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import io.novafoundation.nova.runtime.multiNetwork.getChainOrNull import io.novafoundation.nova.runtime.multiNetwork.getRuntime import io.novasama.substrate_sdk_android.extensions.fromHex +import io.novasama.substrate_sdk_android.runtime.AccountId import io.novasama.substrate_sdk_android.runtime.RuntimeSnapshot import io.novasama.substrate_sdk_android.runtime.definitions.types.fromHex import io.novasama.substrate_sdk_android.runtime.definitions.types.generics.EraType @@ -104,12 +105,13 @@ class PolkadotExternalSignInteractor( override val validationSystem: ConfirmDAppOperationValidationSystem = EmptyValidationSystem() override suspend fun createAccountAddressModel(): AddressModel { - return addressIconGenerator.createAddressModel( - accountAddress = signPayload.address, + val icon = addressIconGenerator.createAddressIcon( + accountId = signPayload.accountId(), sizeInDp = AddressIconGenerator.SIZE_MEDIUM, - accountName = null, - background = AddressIconGenerator.BACKGROUND_TRANSPARENT + backgroundColorRes = AddressIconGenerator.BACKGROUND_TRANSPARENT ) + + return AddressModel(signPayload.address, icon, name = null) } override suspend fun chainUi(): Result { @@ -293,6 +295,18 @@ class PolkadotExternalSignInteractor( } } + private suspend fun PolkadotSignPayload.accountId(): AccountId { + return when (this) { + is PolkadotSignPayload.Json -> { + val chain = chainOrNull() + + chain?.accountIdOf(address) ?: address.anyAddressToAccountId() + } + + is PolkadotSignPayload.Raw -> address.anyAddressToAccountId() + } + } + private class ActualMetadataHash(val modifiedOriginal: Boolean, val checkMetadataHash: CheckMetadataHash) { constructor(modifiedOriginal: Boolean, hash: ByteArray?) : this(modifiedOriginal, CheckMetadataHash(hash)) diff --git a/runtime/src/main/java/io/novafoundation/nova/runtime/ext/ChainExt.kt b/runtime/src/main/java/io/novafoundation/nova/runtime/ext/ChainExt.kt index f796f0351e..3dd12d551b 100644 --- a/runtime/src/main/java/io/novafoundation/nova/runtime/ext/ChainExt.kt +++ b/runtime/src/main/java/io/novafoundation/nova/runtime/ext/ChainExt.kt @@ -263,6 +263,16 @@ fun Chain.accountIdOf(address: String): ByteArray { } } +fun String.anyAddressToAccountId(): ByteArray { + return runCatching { + // Substrate + toAccountId() + }.recoverCatching { + // Evm + asEthereumAddress().toAccountId().value + }.getOrThrow() +} + fun Chain.accountIdOrNull(address: String): ByteArray? { return runCatching { accountIdOf(address) }.getOrNull() } From c5142a0b11379954fae30d29ccabcddefb8c726a Mon Sep 17 00:00:00 2001 From: Valentun Date: Mon, 25 Nov 2024 14:20:16 +0300 Subject: [PATCH 2/3] Code style --- .../main/java/io/novafoundation/nova/runtime/ext/ChainExt.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/main/java/io/novafoundation/nova/runtime/ext/ChainExt.kt b/runtime/src/main/java/io/novafoundation/nova/runtime/ext/ChainExt.kt index 3dd12d551b..80114ca33d 100644 --- a/runtime/src/main/java/io/novafoundation/nova/runtime/ext/ChainExt.kt +++ b/runtime/src/main/java/io/novafoundation/nova/runtime/ext/ChainExt.kt @@ -264,7 +264,7 @@ fun Chain.accountIdOf(address: String): ByteArray { } fun String.anyAddressToAccountId(): ByteArray { - return runCatching { + return runCatching { // Substrate toAccountId() }.recoverCatching { From 2878113eff960d5fb1317972a3b072e23b756b35 Mon Sep 17 00:00:00 2001 From: Valentun Date: Tue, 26 Nov 2024 11:02:41 +0300 Subject: [PATCH 3/3] Bump versions --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index acffd89dc6..4716250319 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ buildscript { ext { // App version - versionName = '9.0.2' - versionCode = 161 + versionName = '9.0.3' + versionCode = 162 applicationId = "io.novafoundation.nova" releaseApplicationSuffix = "market"