Updated on 2026-08-14

This commit is contained in:
Tangem 2025-02-13 19:01:17 +03:00
parent 6f973aed83
commit 9812f9f253
15 changed files with 184 additions and 67 deletions

View file

@ -2,7 +2,6 @@ package com.tangem.domain.common.visa
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.derivation.DerivationStyle
import com.tangem.common.card.EllipticCurve
import com.tangem.common.card.FirmwareVersion
import com.tangem.domain.models.scan.CardDTO
@ -10,8 +9,6 @@ private const val VISA_BATCH_START = "AE"
object VisaUtilities {
val mandatoryCurve = EllipticCurve.Secp256k1
const val tokenId = "tether"
val visaBlockchain = Blockchain.Polygon

View file

@ -5,6 +5,7 @@ import arrow.core.raise.catch
import arrow.core.raise.either
import com.tangem.blockchain.common.address.Address
import com.tangem.blockchain.common.address.AddressType
import com.tangem.common.card.EllipticCurve
import com.tangem.crypto.hdWallet.bip32.ExtendedPublicKey
import com.tangem.domain.models.scan.CardDTO
@ -19,7 +20,7 @@ object VisaWalletPublicKeyUtility {
}
fun findKeyWithoutDerivation(targetAddress: String, card: CardDTO): Either<Error, ByteArray> = either {
val wallet = findWalletOnVisaCurve(card).bind()
val wallet = findWalletOnSecp256k1(card).bind()
validatePublicKey(
targetAddress = targetAddress,
@ -29,13 +30,13 @@ object VisaWalletPublicKeyUtility {
wallet.publicKey
}
fun generateAddressOnVisaCurve(walletPublicKey: ByteArray): Either<Error, Address> = either {
fun generateAddressOnSecp256k1(walletPublicKey: ByteArray): Either<Error, Address> = either {
val addresses = catch(
block = {
VisaUtilities.visaBlockchain.makeAddresses(
walletPublicKey = walletPublicKey,
pairPublicKey = null,
curve = VisaUtilities.mandatoryCurve,
curve = EllipticCurve.Secp256k1,
)
},
catch = { raise(Error.FailedToCreateAddress) },
@ -44,12 +45,12 @@ object VisaWalletPublicKeyUtility {
addresses.firstOrNull { it.type == AddressType.Default } ?: raise(Error.FailedToCreateAddress)
}
private fun findWalletOnVisaCurve(card: CardDTO): Either<Error, CardDTO.Wallet> = either {
card.wallets.firstOrNull { it.curve == VisaUtilities.mandatoryCurve } ?: raise(Error.MissingWalletOnTargetCurve)
private fun findWalletOnSecp256k1(card: CardDTO): Either<Error, CardDTO.Wallet> = either {
card.wallets.firstOrNull { it.curve == EllipticCurve.Secp256k1 } ?: raise(Error.MissingWalletOnTargetCurve)
}
private fun validatePublicKey(targetAddress: String, publicKey: ByteArray): Either<Error, Unit> = either {
val address = generateAddressOnVisaCurve(publicKey).bind()
val address = generateAddressOnSecp256k1(publicKey).bind()
if (address.value != targetAddress) {
raise(Error.AddressNotMatched)