Updated on 2026-08-14

This commit is contained in:
Tangem 2025-02-05 19:08:37 +03:00
parent 439fb00fb2
commit 416e401d5b
18 changed files with 134 additions and 28 deletions

View file

@ -2,7 +2,7 @@ package com.tangem.tap
import com.tangem.TangemSdkLogger
import com.tangem.blockchainsdk.BlockchainSDKFactory
import com.tangem.blockchainsdk.signer.TransactionSignerFactory
import com.tangem.data.card.TransactionSignerFactory
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.common.routing.AppRouter
import com.tangem.core.analytics.filter.OneTimeEventFilter

View file

@ -8,7 +8,7 @@ import com.tangem.Log
import com.tangem.TangemSdkLogger
import com.tangem.blockchain.network.BlockchainSdkRetrofitBuilder
import com.tangem.blockchainsdk.BlockchainSDKFactory
import com.tangem.blockchainsdk.signer.TransactionSignerFactory
import com.tangem.data.card.TransactionSignerFactory
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.common.routing.AppRouter
import com.tangem.core.analytics.Analytics

View file

@ -3,18 +3,20 @@ package com.tangem.tap.common.libs.blockchainsdk
import com.tangem.Message
import com.tangem.TangemSdk
import com.tangem.blockchain.common.TransactionSigner
import com.tangem.blockchainsdk.signer.TransactionSignerFactory
import com.tangem.data.card.TransactionSignerFactory
import com.tangem.domain.card.models.TwinKey
import com.tangem.tap.common.redux.global.GlobalAction
import com.tangem.tap.domain.TangemSigner
import com.tangem.tap.store
internal class DefaultTransactionSignerFactory : TransactionSignerFactory {
override fun createTransactionSigner(cardId: String?, sdk: TangemSdk): TransactionSigner {
override fun createTransactionSigner(cardId: String?, sdk: TangemSdk, twinKey: TwinKey?): TransactionSigner {
return TangemSigner(
cardId = cardId,
tangemSdk = sdk,
initialMessage = Message(),
twinKey = twinKey,
) { signResponse ->
store.dispatch(action = GlobalAction.IsSignWithRing(signResponse.isRing))
}

View file

@ -1,6 +1,6 @@
package com.tangem.tap.di.libs.blockchainsdk
import com.tangem.blockchainsdk.signer.TransactionSignerFactory
import com.tangem.data.card.TransactionSignerFactory
import com.tangem.tap.common.libs.blockchainsdk.DefaultTransactionSignerFactory
import dagger.Module
import dagger.Provides

View file

@ -5,6 +5,7 @@ import com.tangem.TangemSdk
import com.tangem.blockchain.common.TransactionSigner
import com.tangem.blockchain.common.Wallet
import com.tangem.common.CompletionResult
import com.tangem.domain.card.models.TwinKey
import com.tangem.domain.models.scan.isRing
import com.tangem.tap.domain.tasks.SignHashesTask
import kotlinx.coroutines.suspendCancellableCoroutine
@ -14,6 +15,7 @@ class TangemSigner(
private val cardId: String?,
private val tangemSdk: TangemSdk,
private val initialMessage: Message,
private val twinKey: TwinKey?,
private val signerCallback: (TangemSignerResponse) -> Unit,
) : TransactionSigner {
@ -22,7 +24,7 @@ class TangemSigner(
publicKey: Wallet.PublicKey,
): CompletionResult<List<ByteArray>> {
return suspendCancellableCoroutine { continuation ->
val task = SignHashesTask(hashes, publicKey)
val task = SignHashesTask(hashes, publicKey, twinKey?.getPairKey(publicKey.seedKey))
tangemSdk.startSessionWithRunnable(
runnable = task,

View file

@ -5,6 +5,8 @@ import com.tangem.common.CompletionResult
import com.tangem.common.core.CardSession
import com.tangem.common.core.CardSessionRunnable
import com.tangem.common.core.CompletionCallback
import com.tangem.common.core.TangemSdkError
import com.tangem.crypto.hdWallet.DerivationPath
import com.tangem.operations.CommandResponse
import com.tangem.operations.sign.SignHashesCommand
@ -18,7 +20,9 @@ class TangemSignHashesResponse(
class SignHashesTask(
private val hashes: Collection<ByteArray>,
private val publicKey: Wallet.PublicKey,
private val pairWalletPublicKey: ByteArray?,
) : CardSessionRunnable<TangemSignHashesResponse> {
override fun run(session: CardSession, callback: CompletionCallback<TangemSignHashesResponse>) {
SignHashesCommand(hashes.toTypedArray(), publicKey.seedKey, publicKey.derivationPath).run(session) { response ->
when (response) {
@ -35,8 +39,42 @@ class SignHashesTask(
),
)
}
is CompletionResult.Failure ->
is CompletionResult.Failure -> {
when {
response.error is TangemSdkError.WalletNotFound && pairWalletPublicKey != null -> {
sign(session, pairWalletPublicKey, publicKey.derivationPath, callback)
}
else -> callback(CompletionResult.Failure(response.error))
}
}
}
}
}
private fun sign(
session: CardSession,
publicKey: ByteArray,
derivationPath: DerivationPath?,
callback: CompletionCallback<TangemSignHashesResponse>,
) {
SignHashesCommand(hashes.toTypedArray(), publicKey, derivationPath).run(session) { response ->
when (response) {
is CompletionResult.Success -> {
val card = session.environment.card
callback(
CompletionResult.Success(
TangemSignHashesResponse(
signatures = response.data.signatures,
totalSignedHashes = response.data.totalSignedHashes,
remainingSignatures = card?.wallet(publicKey)?.remainingSignatures,
batchId = card?.batchId,
),
),
)
}
is CompletionResult.Failure -> {
callback(CompletionResult.Failure(response.error))
}
}
}
}

View file

@ -218,6 +218,7 @@ class WalletConnectSdkHelper {
signer = store.inject(DaggerGraphState::transactionSignerFactory).createTransactionSigner(
cardId = cardId,
sdk = sdk,
twinKey = null, // use null here because twin doesn't support WC
),
)
return when (result) {

View file

@ -104,6 +104,7 @@ class CurrencyExchangeManager(
}
}
@Deprecated("Useless")
suspend fun buyErc20TestnetTokens(card: CardDTO, walletManager: EthereumWalletManager, destinationAddress: String) {
walletManager.safeUpdate(card.isDemoCard())
@ -123,6 +124,7 @@ suspend fun buyErc20TestnetTokens(card: CardDTO, walletManager: EthereumWalletMa
cardId = card.cardId.takeIf { isCardNotBackedUp },
tangemSdk = store.inject(DaggerGraphState::cardSdkConfigRepository).sdk,
initialMessage = Message(),
twinKey = null,
) { signResponse ->
store.dispatch(
GlobalAction.UpdateWalletSignedHashes(

View file

@ -1,7 +1,7 @@
package com.tangem.tap.proxy.redux
import com.tangem.blockchainsdk.BlockchainSDKFactory
import com.tangem.blockchainsdk.signer.TransactionSignerFactory
import com.tangem.data.card.TransactionSignerFactory
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.common.routing.AppRouter
import com.tangem.core.decompose.ui.UiMessageSender