Updated on 2026-08-14

This commit is contained in:
Tangem 2025-08-19 13:25:47 +03:00
parent 7cfd21d898
commit 1c192d52b2
6 changed files with 57 additions and 14 deletions

View file

@ -7,10 +7,10 @@ import com.tangem.blockchainsdk.BlockchainSDKFactory
import com.tangem.crypto.hdWallet.DerivationPath
import com.tangem.data.walletmanager.extensions.makePublicKey
import com.tangem.data.walletmanager.extensions.makeWalletManagerForApp
import com.tangem.domain.card.configs.Wallet2CardConfig
import com.tangem.domain.wallets.derivations.DerivationStyleProvider
import com.tangem.domain.models.scan.ScanResponse
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.wallets.config.curvesConfig
import com.tangem.domain.wallets.derivations.derivationStyleProvider
import timber.log.Timber
@ -42,7 +42,7 @@ internal class WalletManagerFactory(
blockchain: Blockchain,
derivationPath: DerivationPath?,
): WalletManager? {
val curve = Wallet2CardConfig.primaryCurve(blockchain)
val curve = hotWallet.curvesConfig.primaryCurve(blockchain)
val selectedWallet = hotWallet.wallets.orEmpty().firstOrNull { it.curve == curve }
?: return null
return try {

View file

@ -7,12 +7,11 @@ import com.tangem.common.card.EllipticCurve
import com.tangem.common.extensions.ByteArrayKey
import com.tangem.common.extensions.toMapKey
import com.tangem.crypto.hdWallet.DerivationPath
import com.tangem.domain.card.configs.CardConfig
import com.tangem.domain.card.configs.Wallet2CardConfig
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.scan.KeyWalletPublicKey
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.wallets.config.curvesConfig
import com.tangem.domain.wallets.derivations.derivationStyleProvider
import com.tangem.operations.derivation.ExtendedPublicKeysMap
import kotlin.collections.forEach
@ -51,13 +50,9 @@ internal class MissedDerivationsFinder(private val userWallet: UserWallet) {
}
private fun List<Network>.mapToNewDerivations(): List<DerivationData> {
val config = when (userWallet) {
is UserWallet.Cold -> CardConfig.createConfig(userWallet.scanResponse.card)
is UserWallet.Hot -> Wallet2CardConfig // TODO [REDACTED_TASK_KEY] [Hot Wallet] Derivation config for hot wallet
}
return mapNotNull { network ->
val blockchain = network.toBlockchain()
val curve = config.primaryCurve(blockchain) ?: return@mapNotNull null
val curve = userWallet.curvesConfig.primaryCurve(blockchain) ?: return@mapNotNull null
val walletPublicKey = when (userWallet) {
is UserWallet.Cold -> {

View file

@ -0,0 +1,18 @@
package com.tangem.domain.wallets.config
import com.tangem.blockchain.common.Blockchain
import com.tangem.common.card.EllipticCurve
import com.tangem.domain.card.configs.CardConfig
import com.tangem.domain.models.scan.CardDTO
class ColdCurvesConfig(cardDTO: CardDTO) : CurvesConfig {
val cardConfig = CardConfig.createConfig(cardDTO)
override val mandatoryCurves: List<EllipticCurve>
get() = cardConfig.mandatoryCurves
override fun primaryCurve(blockchain: Blockchain): EllipticCurve? {
return cardConfig.primaryCurve(blockchain)
}
}

View file

@ -0,0 +1,18 @@
package com.tangem.domain.wallets.config
import com.tangem.blockchain.common.Blockchain
import com.tangem.common.card.EllipticCurve
import com.tangem.domain.models.wallet.UserWallet
interface CurvesConfig {
val mandatoryCurves: List<EllipticCurve>
fun primaryCurve(blockchain: Blockchain): EllipticCurve?
}
val UserWallet.curvesConfig: CurvesConfig
get() = when (this) {
is UserWallet.Cold -> ColdCurvesConfig(this.scanResponse.card)
is UserWallet.Hot -> HotCurvesConfig
}

View file

@ -0,0 +1,15 @@
package com.tangem.domain.wallets.config
import com.tangem.blockchain.common.Blockchain
import com.tangem.common.card.EllipticCurve
import com.tangem.domain.card.configs.Wallet2CardConfig
data object HotCurvesConfig : CurvesConfig {
override val mandatoryCurves: List<EllipticCurve>
get() = Wallet2CardConfig.mandatoryCurves
override fun primaryCurve(blockchain: Blockchain): EllipticCurve? {
return Wallet2CardConfig.primaryCurve(blockchain)
}
}

View file

@ -4,17 +4,14 @@ import com.tangem.blockchain.blockchains.cardano.CardanoUtils
import com.tangem.blockchain.common.Blockchain
import com.tangem.crypto.hdWallet.DerivationPath
import com.tangem.domain.card.common.util.hasDerivation
import com.tangem.domain.card.configs.Wallet2CardConfig
import com.tangem.domain.models.wallet.UserWallet
import kotlin.collections.first
import kotlin.collections.orEmpty
import com.tangem.domain.wallets.config.curvesConfig
fun UserWallet.hasDerivation(blockchain: Blockchain, derivationPath: String): Boolean {
return when (this) {
is UserWallet.Cold -> scanResponse.hasDerivation(blockchain, derivationPath)
is UserWallet.Hot -> {
// TODO [REDACTED_TASK_KEY] [Hot Wallet] Derivation config for hot wallet
val primaryCurve = Wallet2CardConfig.primaryCurve(blockchain)
val primaryCurve = curvesConfig.primaryCurve(blockchain)
val list = if (blockchain == Blockchain.Cardano) {
listOf(
CardanoUtils.extendedDerivationPath(DerivationPath(derivationPath)),