Updated on 2026-08-14
This commit is contained in:
parent
53b68c596c
commit
7e7b8e8c94
4 changed files with 25 additions and 35 deletions
|
|
@ -77,7 +77,7 @@ dependencies {
|
|||
implementation 'com.google.android.play:core-ktx:1.8.1'
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
||||
|
||||
implementation 'com.tangem:blockchain:develop-12'
|
||||
implementation 'com.tangem:blockchain:develop-16'
|
||||
implementation 'com.tangem:core:develop-36'
|
||||
implementation 'com.tangem:sdk:develop-36'
|
||||
|
||||
|
|
@ -111,6 +111,17 @@ dependencies {
|
|||
// WalletConnect
|
||||
implementation 'com.github.salomonbrys.kotson:kotson:2.5.0'
|
||||
|
||||
// Network and Json
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.8.1'
|
||||
implementation 'com.squareup.retrofit2:converter-moshi:2.6.0'
|
||||
implementation 'com.squareup.moshi:moshi:1.9.2'
|
||||
implementation "com.squareup.moshi:moshi-kotlin:1.9.2"
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:4.2.2'
|
||||
//
|
||||
// //Crypto
|
||||
implementation "com.madgag.spongycastle:core:1.58.0.0"
|
||||
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation "com.google.truth:truth:1.0.1"
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue