Updated on 2026-08-14

This commit is contained in:
Tangem 2025-12-29 21:47:19 +05:00
parent 3ef88c33ee
commit 8d813113bd
7 changed files with 28 additions and 23 deletions

View file

@ -519,13 +519,14 @@ internal class DefaultTangemSdkManager(
}
override suspend fun tangemPayProduceInitialCredentials(
cardId: String,
preflightReadFilter: PreflightReadFilter,
): Either<Throwable, TangemPayInitialCredentials> {
return coroutineScope {
val result = runTaskAsyncReturnOnMain(
runnable = tangemPayChallengeTaskFactory.create(coroutineScope = this),
cardId = cardId,
cardId = null,
initialMessage = Message(resources.getStringSafe(R.string.initial_message_tap_header)),
preflightReadFilter = preflightReadFilter,
)
return@coroutineScope when (result) {
@ -536,14 +537,15 @@ internal class DefaultTangemSdkManager(
}
override suspend fun getWithdrawalSignature(
cardId: String,
hash: String,
preflightReadFilter: PreflightReadFilter,
): Either<Throwable, WithdrawalSignatureResult> {
return coroutineScope {
val result = runTaskAsyncReturnOnMain(
runnable = TangemPaySignWithdrawalHashTask(cardId = cardId, hash = hash.hexToBytes()),
cardId = cardId,
runnable = TangemPaySignWithdrawalHashTask(hash = hash.hexToBytes()),
cardId = null,
initialMessage = Message(resources.getStringSafe(R.string.initial_message_tap_header)),
preflightReadFilter = preflightReadFilter,
)
return@coroutineScope when (result) {

View file

@ -219,14 +219,14 @@ class MockTangemSdkManager(
}
override suspend fun tangemPayProduceInitialCredentials(
cardId: String,
preflightReadFilter: PreflightReadFilter,
): Either<Throwable, TangemPayInitialCredentials> {
error("Not implemented")
}
override suspend fun getWithdrawalSignature(
cardId: String,
hash: String,
preflightReadFilter: PreflightReadFilter,
): Either<Throwable, WithdrawalSignatureResult> {
error("Not implemented")
}

View file

@ -62,7 +62,6 @@ class TangemPayGenerateAddressAndSignChallengeTask @AssistedInject constructor(
val dataToSign = VisaDataToSignByCustomerWallet(hashToSign = challenge.challenge)
val approveResult = runVisaCustomerWalletApproveTask(
session = session,
cardId = card.cardId,
targetAddress = address,
dataToSign = dataToSign,
)
@ -103,14 +102,13 @@ class TangemPayGenerateAddressAndSignChallengeTask @AssistedInject constructor(
private suspend fun runVisaCustomerWalletApproveTask(
session: CardSession,
cardId: String,
targetAddress: String,
dataToSign: VisaDataToSignByCustomerWallet,
): CompletionResult<VisaSignedDataByCustomerWallet> {
val deferred = CompletableDeferred<CompletionResult<VisaSignedDataByCustomerWallet>>()
val task = VisaCustomerWalletApproveTask(
visaDataForApprove = VisaCustomerWalletApproveTask.Input(
cardId = cardId,
cardId = null,
targetAddress = targetAddress,
hashToSign = dataToSign.hashToSign,
sign = dataToSign::sign,

View file

@ -14,10 +14,7 @@ import com.tangem.domain.visa.error.VisaActivationError
import com.tangem.operations.derivation.DeriveWalletPublicKeyTask
import com.tangem.operations.sign.SignHashCommand
class TangemPaySignWithdrawalHashTask(
private val cardId: String,
private val hash: ByteArray,
) : CardSessionRunnable<String> {
class TangemPaySignWithdrawalHashTask(private val hash: ByteArray) : CardSessionRunnable<String> {
override fun run(session: CardSession, callback: CompletionCallback<String>) {
val card = session.environment.card ?: run {
@ -25,11 +22,6 @@ class TangemPaySignWithdrawalHashTask(
return
}
if (card.cardId != cardId) {
callback(CompletionResult.Failure(VisaActivationError.CardIdNotMatched.tangemError))
return
}
proceedSign(card, session, callback)
}

View file

@ -20,6 +20,7 @@ dependencies {
implementation(projects.core.error.ext)
implementation(projects.core.security)
implementation(projects.data.common)
implementation(projects.data.wallets)
/** Project - Domain */
implementation(projects.domain.visa)

View file

@ -1,6 +1,7 @@
package com.tangem.data.pay.datasource
import arrow.core.Either
import com.tangem.data.wallets.cold.UserWalletIdPreflightReadFilter
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.pay.WithdrawalSignatureResult
import com.tangem.domain.pay.datasource.TangemPayAuthDataSource
@ -17,7 +18,10 @@ internal class DefaultTangemPayAuthDataSource @Inject constructor(
userWallet: UserWallet,
): Either<Throwable, TangemPayInitialCredentials> {
return when (userWallet) {
is UserWallet.Cold -> tangemSdkManager.tangemPayProduceInitialCredentials(cardId = userWallet.cardId)
is UserWallet.Cold -> {
val preflightReadFilter = UserWalletIdPreflightReadFilter(userWallet.walletId)
tangemSdkManager.tangemPayProduceInitialCredentials(preflightReadFilter = preflightReadFilter)
}
is UserWallet.Hot -> tangemPayHotSdkManager.produceInitialCredentials(userWallet)
}
}
@ -27,7 +31,10 @@ internal class DefaultTangemPayAuthDataSource @Inject constructor(
hash: String,
): Either<Throwable, WithdrawalSignatureResult> {
return when (userWallet) {
is UserWallet.Cold -> tangemSdkManager.getWithdrawalSignature(cardId = userWallet.cardId, hash = hash)
is UserWallet.Cold -> {
val preflightReadFilter = UserWalletIdPreflightReadFilter(userWallet.walletId)
tangemSdkManager.getWithdrawalSignature(hash = hash, preflightReadFilter = preflightReadFilter)
}
is UserWallet.Hot -> tangemPayHotSdkManager.getWithdrawalSignature(hotWallet = userWallet, hash = hash)
}
}

View file

@ -161,8 +161,13 @@ interface TangemSdkManager {
visaDataForApprove: VisaDataForApprove,
): CompletionResult<VisaSignedDataByCustomerWallet>
suspend fun tangemPayProduceInitialCredentials(cardId: String): Either<Throwable, TangemPayInitialCredentials>
suspend fun tangemPayProduceInitialCredentials(
preflightReadFilter: PreflightReadFilter,
): Either<Throwable, TangemPayInitialCredentials>
suspend fun getWithdrawalSignature(cardId: String, hash: String): Either<Throwable, WithdrawalSignatureResult>
suspend fun getWithdrawalSignature(
hash: String,
preflightReadFilter: PreflightReadFilter,
): Either<Throwable, WithdrawalSignatureResult>
// endregion
}