Updated on 2026-08-14

This commit is contained in:
Tangem 2021-06-15 12:43:40 +03:00
commit 5ee23774f8
4 changed files with 25 additions and 35 deletions

View file

@ -1,8 +1,8 @@
package com.tangem.tap.domain
import android.net.Uri
import android.util.Base64
import com.tangem.tap.common.redux.global.CryptoCurrencyName
import org.spongycastle.util.encoders.Base64
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
@ -37,7 +37,8 @@ class TopUpHelper {
val sha256Hmac = Mac.getInstance("HmacSHA256")
val secretKey = SecretKeySpec(key.toByteArray(), "HmacSHA256")
sha256Hmac.init(secretKey)
return Base64.toBase64String(sha256Hmac.doFinal(data.toByteArray()))
val sha256encoded = sha256Hmac.doFinal(data.toByteArray())
return Base64.encodeToString(sha256encoded, Base64.NO_WRAP)
}
}
}

View file

@ -3,16 +3,13 @@ package com.tangem.tap.domain.extensions
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.Token
import com.tangem.commands.common.card.EllipticCurve
import org.stellar.sdk.requests.ErrorResponse
import java.math.BigDecimal
fun Blockchain.isNoAccountError(exception: Throwable): Boolean {
return when (this) {
Blockchain.Stellar -> {
(exception is ErrorResponse) && (exception.code == 404)
}
Blockchain.XRP -> exception.message?.contains("Account not found") == true
Blockchain.Stellar, Blockchain.XRP ->
exception.message?.contains("Account not found") == true
else -> false
}
}

View file

@ -1,18 +1,15 @@
package com.tangem.tap.domain.walletconnect
import com.google.common.base.CharMatcher
import com.tangem.Message
import com.tangem.blockchain.blockchains.ethereum.EthereumGasLoader
import com.tangem.blockchain.blockchains.ethereum.EthereumHelper
import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionExtras
import com.tangem.blockchain.blockchains.ethereum.EthereumUtils
import com.tangem.blockchain.blockchains.ethereum.EthereumUtils.Companion.toKeccak
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.TransactionData
import com.tangem.blockchain.common.TransactionSender
import com.tangem.blockchain.extensions.Result
import com.tangem.blockchain.extensions.Signer
import com.tangem.blockchain.extensions.SimpleResult
import com.tangem.blockchain.extensions.hexToBigDecimal
import com.tangem.blockchain.extensions.*
import com.tangem.commands.SignCommand
import com.tangem.commands.wallet.WalletIndex
import com.tangem.common.CompletionResult
@ -26,14 +23,8 @@ import com.tangem.tap.tangemSdk
import com.tangem.tap.tangemSdkManager
import com.trustwallet.walletconnect.models.ethereum.WCEthereumSignMessage
import com.trustwallet.walletconnect.models.ethereum.WCEthereumTransaction
import org.kethereum.crypto.api.ec.ECDSASignature
import org.kethereum.crypto.determineRecId
import org.kethereum.crypto.impl.ec.canonicalise
import org.kethereum.keccakshortcut.keccak
import org.kethereum.model.PublicKey
import timber.log.Timber
import java.math.BigDecimal
import java.math.BigInteger
class WalletConnectSdkHelper {
@ -144,7 +135,7 @@ class WalletConnectSdkHelper {
}
private suspend fun signTransaction(data: WcTransactionData): String? {
val dataToSign = EthereumHelper.buildTransactionToSign(
val dataToSign = EthereumUtils.buildTransactionToSign(
transactionData = data.transaction,
nonce = null,
blockchain = data.walletManager.wallet.blockchain,
@ -176,7 +167,7 @@ class WalletConnectSdkHelper {
val messageString = message.data.hexToAscii() ?: message.data
val prefixData = (ETH_MESSAGE_PREFIX + messageData.size.toString()).toByteArray()
val hashToSign = (prefixData + messageData).keccak()
val hashToSign = (prefixData + messageData).toKeccak()
val dialogData = PersonalSignDialogData(
@ -203,8 +194,6 @@ class WalletConnectSdkHelper {
.joinToString("")
}
private fun Char.isAscii(): Boolean = CharMatcher.ascii().matches(this)
suspend fun signPersonalMessage(hashToSign: ByteArray, wallet: WalletForSession): String? {
val publicKey = wallet.walletPublicKey.hexToBytes()
val command = SignCommand(
@ -214,17 +203,9 @@ class WalletConnectSdkHelper {
is CompletionResult.Success -> {
val hash = result.data.signatures.first()
val r = BigInteger(1, hash.copyOfRange(0, 32))
val s = BigInteger(1, hash.copyOfRange(32, 64))
val ecdsaSignature = ECDSASignature(r, s).canonicalise()
val recId = ecdsaSignature.determineRecId(hashToSign,
PublicKey(publicKey.sliceArray(1..64)))
val v = (recId + 27).toBigInteger()
return HEX_PREFIX + ecdsaSignature.r.toString(16) + ecdsaSignature.s.toString(16) +
v.toString(16)
return EthereumUtils.prepareSignedMessageData(
hash, hashToSign, publicKey
)
}
is CompletionResult.Failure -> {
Timber.e(result.error.customMessage)