Skip to content

Commit

Permalink
Merge pull request #866 from tangem/feature/AND-9490_migrate_TON_signer
Browse files Browse the repository at this point in the history
AND-9490 Moved TON tx signing to WalletCore
  • Loading branch information
Yoggam1 authored Dec 28, 2024
2 parents 33844ee + b180424 commit f6681fa
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 344 deletions.
4 changes: 2 additions & 2 deletions blockchain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ dependencies {

implementation files('libs/hedera-sdk-java-2.29.0.jar')
implementation "com.tangem:blstlib:master-6@aar"
implementation "com.tangem:wallet-core:4.0.46-tangem1@aar"
implementation("com.tangem:wallet-core-proto:4.0.46-tangem1") {
implementation "com.tangem:wallet-core:4.1.20-tangem3@aar"
implementation("com.tangem:wallet-core-proto:4.1.20-tangem3") {
exclude group: 'com.google.protobuf', module: 'protobuf-javalite'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.tangem.blockchain.blockchains.algorand

import com.google.common.truth.Truth
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.address.TrustWalletAddressService
import com.tangem.blockchain.common.address.WalletCoreAddressService
import com.tangem.common.card.EllipticCurve
import com.tangem.common.extensions.hexToBytes
import org.junit.Test

class AlgorandAddressTest {

private val addressService = TrustWalletAddressService(Blockchain.Algorand)
private val addressService = WalletCoreAddressService(Blockchain.Algorand)

init {
System.loadLibrary("TrustWalletCore")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.tangem.blockchain.blockchains.aptos

import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.address.TrustWalletAddressService
import com.tangem.blockchain.common.address.WalletCoreAddressService
import com.tangem.common.card.EllipticCurve
import com.tangem.common.extensions.hexToBytes
import junit.framework.TestCase.assertEquals
import org.junit.Test

internal class AptosAddressTest {

private val addressService = TrustWalletAddressService(Blockchain.Aptos)
private val addressService = WalletCoreAddressService(Blockchain.Aptos)

init {
System.loadLibrary("TrustWalletCore")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.tangem.blockchain.blockchains.cosmos

import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.address.TrustWalletAddressService
import com.tangem.blockchain.common.address.WalletCoreAddressService
import com.tangem.common.extensions.hexToBytes
import junit.framework.TestCase.assertEquals
import org.junit.Test

class CosmosAddressTest {

private val addressService = TrustWalletAddressService(Blockchain.Cosmos)
private val addressService = WalletCoreAddressService(Blockchain.Cosmos)

init {
System.loadLibrary("TrustWalletCore")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tangem.blockchain.blockchains.filecoin

import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.address.TrustWalletAddressService
import com.tangem.blockchain.common.address.WalletCoreAddressService
import com.tangem.common.card.EllipticCurve
import com.tangem.common.extensions.hexToBytes
import com.tangem.common.extensions.toDecompressedPublicKey
Expand All @@ -10,7 +10,7 @@ import org.junit.Test

internal class FilecoinAddressTest {

private val addressService = TrustWalletAddressService(Blockchain.Filecoin)
private val addressService = WalletCoreAddressService(Blockchain.Filecoin)

init {
System.loadLibrary("TrustWalletCore")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.tangem.blockchain.blockchains.icp

import com.google.common.truth.Truth
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.address.TrustWalletAddressService
import com.tangem.blockchain.common.address.WalletCoreAddressService
import com.tangem.common.extensions.hexToBytes
import com.tangem.common.extensions.toHexString
import org.junit.Test
Expand All @@ -15,7 +15,7 @@ class InternetComputerAddressTest {
System.loadLibrary("TrustWalletCore")
}

private val addressService = TrustWalletAddressService(Blockchain.InternetComputer)
private val addressService = WalletCoreAddressService(Blockchain.InternetComputer)
private val coinType = CoinType.INTERNETCOMPUTER

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,30 @@ package com.tangem.blockchain.blockchains.ton

import com.google.common.truth.Truth
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.address.TrustWalletAddressService
import com.tangem.blockchain.common.address.WalletCoreAddressService
import com.tangem.common.extensions.hexToBytes
import org.junit.Test
import wallet.core.jni.TheOpenNetworkAddress

internal class TonAddressTest {

init {
System.loadLibrary("TrustWalletCore")
}

private val blockchain = Blockchain.TON
private val publicKey = "993E12F27E3EA3BC0FDDA4DD09664C52FEDDC0A1191675089B7B59BACE4C1AE1".hexToBytes()
private val tonAddressService = TonAddressService(blockchain)
private val legacyAddressService = TrustWalletAddressService(blockchain)

@Test
fun checkEqualityWithLegacyAddressService() {
val legacyAddress = TheOpenNetworkAddress(legacyAddressService.makeAddress(walletPublicKey = publicKey))
val newAddress = tonAddressService.makeTheOpenNetworkAddress(walletPublicKey = publicKey)
Truth.assertThat(TheOpenNetworkAddress.equals(legacyAddress, newAddress)).isTrue()
}
private val tonAddressService = WalletCoreAddressService(Blockchain.TON)

@Test
fun checkGeneratingBounceableAddress() {
val bounceAbleAddress = tonAddressService.makeTheOpenNetworkAddress(walletPublicKey = publicKey)
val bounceAbleAddress = tonAddressService.makeAddress(walletPublicKey = publicKey)
val expectedAddress = "EQC1dizHG_5rmYUJ7KkysiSZA-cQVJxxNVQqf73cvMV7obwG"
Truth.assertThat(
bounceAbleAddress.stringRepresentation(/*userFriendly*/ true, /*bounceable*/ true, /*testOnly*/ false),
).isEqualTo(expectedAddress)
Truth.assertThat(bounceAbleAddress).isNotEqualTo(expectedAddress)
}

@Test
fun checkGeneratingNonBounceableAddress() {
val bounceAbleAddress = tonAddressService.makeTheOpenNetworkAddress(walletPublicKey = publicKey)
val bounceAbleAddress = tonAddressService.makeAddress(walletPublicKey = publicKey)
val expectedAddress = "UQC1dizHG_5rmYUJ7KkysiSZA-cQVJxxNVQqf73cvMV7oeHD"
Truth.assertThat(
bounceAbleAddress.stringRepresentation(/*userFriendly*/ true, /*bounceable*/ false, /*testOnly*/ false),
).isEqualTo(expectedAddress)
}

@Test
fun checkRawForm() {
val bounceAbleAddress = tonAddressService.makeTheOpenNetworkAddress(walletPublicKey = publicKey)
val expectedAddress = "0:b5762cc71bfe6b998509eca932b2249903e710549c7135542a7fbddcbcc57ba1"
Truth.assertThat(
bounceAbleAddress.stringRepresentation(/*userFriendly*/ false, /*bounceable*/ false, /*testOnly*/ false),
).isEqualTo(expectedAddress)
}

@Test
fun addressServiceGeneratingCorrectAddress() {
val theOpenNetworkAddress = tonAddressService.makeTheOpenNetworkAddress(walletPublicKey = publicKey)
val generatedAddress = tonAddressService.makeAddress(walletPublicKey = publicKey)
Truth.assertThat(generatedAddress)
.isEqualTo(
theOpenNetworkAddress.stringRepresentation(
/*userFriendly*/ true,
/*bounceable*/ false,
/*testOnly*/ false,
),
)
Truth.assertThat(bounceAbleAddress).isEqualTo(expectedAddress)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package com.tangem.blockchain.blockchains.aptos

import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.HEX_PREFIX
import com.tangem.blockchain.common.address.TrustWalletAddressService
import com.tangem.blockchain.common.address.WalletCoreAddressService
import com.tangem.common.card.EllipticCurve

/**
* Address service implementation for [Blockchain.Aptos] based on [TrustWalletAddressService]
* Address service implementation for [Blockchain.Aptos] based on [WalletCoreAddressService]
*
* @property isTestnet flag that indicates if current network is testnet
*
* @author Andrew Khokhlov on 26/03/2024
*/
internal class AptosAddressService(private val isTestnet: Boolean) : TrustWalletAddressService(
internal class AptosAddressService(private val isTestnet: Boolean) : WalletCoreAddressService(
blockchain = if (isTestnet) Blockchain.AptosTestnet else Blockchain.Aptos,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.address.Address
import com.tangem.blockchain.common.address.AddressService
import com.tangem.blockchain.common.address.ContractAddressValidator
import com.tangem.blockchain.common.address.TrustWalletAddressService
import com.tangem.blockchain.common.address.WalletCoreAddressService
import com.tangem.common.card.EllipticCurve

internal class CardanoAddressServiceFacade : AddressService(), ContractAddressValidator {

private val legacyService = CardanoAddressService(Blockchain.Cardano)
private val trustWalletService = TrustWalletAddressService(Blockchain.Cardano)
private val trustWalletService = WalletCoreAddressService(Blockchain.Cardano)

override fun makeAddress(walletPublicKey: ByteArray, curve: EllipticCurve?): String {
return if (CardanoUtils.isExtendedPublicKey(walletPublicKey)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.tangem.blockchain.blockchains.cardano

import com.google.protobuf.ByteString
import com.tangem.Log
import com.tangem.blockchain.blockchains.cardano.network.common.models.CardanoUnspentOutput
import com.tangem.blockchain.blockchains.cardano.utils.matchesCardanoAsset
import com.tangem.blockchain.blockchains.cardano.walletcore.CardanoTWTxBuilder
import com.tangem.blockchain.common.*
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.extensions.hexToBigDecimal
import com.tangem.blockchain.extensions.isValidUtf8
import com.tangem.blockchain.extensions.trustWalletCoinType
import com.tangem.common.extensions.hexToBytes
import com.tangem.common.extensions.toHexString
import wallet.core.java.AnySigner
import wallet.core.jni.CoinType
Expand All @@ -33,20 +30,7 @@ internal class CardanoTransactionBuilder(
private var twTxBuilder: CardanoTWTxBuilder by Delegates.notNull()

fun update(outputs: List<CardanoUnspentOutput>) {
twTxBuilder = CardanoTWTxBuilder(
wallet = wallet,
outputs = outputs.filter { output ->
val containsIncorrectAssetNameHex = output.assets.any { asset ->
asset.assetNameHex.hexToBytes().isValidUtf8().not()
}

if (containsIncorrectAssetNameHex) {
Log.debug { "CardanoTransactionBuilder will exclude output: $output" }
}

!containsIncorrectAssetNameHex
},
)
twTxBuilder = CardanoTWTxBuilder(wallet = wallet, outputs = outputs)
}

override fun validate(transactionData: TransactionData): Result<Unit> {
Expand Down

This file was deleted.

Loading

0 comments on commit f6681fa

Please sign in to comment.