Skip to content

Commit

Permalink
[Breaking] Add AnyAddress (#817)
Browse files Browse the repository at this point in the history
* Add AnyAddress

* Fix android tests

* Remove TWZilliqaAddress and TWBitcoinCashAddress

* Fix iOS build

* worry free C interface for Signer

* remove trailing space

* expose coin property, normalized eth/bch address
  • Loading branch information
hewigovens committed Jan 19, 2020
1 parent 52b74ff commit e1e9c0c
Show file tree
Hide file tree
Showing 190 changed files with 811 additions and 3,869 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package com.trustwallet.core.app.blockchains.aeternity
import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.AeternityAddress
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.*

class TestAeternityAddress {

Expand All @@ -16,15 +14,15 @@ class TestAeternityAddress {
@Test
fun testAddressFromPublicKey() {
val key = PublicKey("ee93a4f66f8d16b819bb9beb9ffccdfcdc1412e87fee6a324c2a99a1e0e67148".toHexByteArray(), PublicKeyType.ED25519)
val address = AeternityAddress(key)
val address = AnyAddress(key, CoinType.AETERNITY)

assertEquals(address.description(), "ak_2p5878zbFhxnrm7meL7TmqwtvBaqcBddyp5eGzZbovZ5FeVfcw")
}

@Test
fun testAddressFromString() {
val addressString = "ak_2p5878zbFhxnrm7meL7TmqwtvBaqcBddyp5eGzZbovZ5FeVfcw"
val address = AeternityAddress(addressString)
val address = AnyAddress(addressString, CoinType.AETERNITY)
assertEquals(address.description(), addressString)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import com.trustwallet.core.app.utils.toHex
import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.AlgorandAddress
import wallet.core.jni.PrivateKey
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.*

class TestAlgorandAddress {

Expand All @@ -19,8 +16,8 @@ class TestAlgorandAddress {
fun testAddress() {
val key = PrivateKey("a6c4394041e64fe93d889386d7922af1b9a87f12e433762759608e61434d6cf7".toHexByteArray())
val pubkey = key.publicKeyEd25519
val address = AlgorandAddress(pubkey)
val expected = AlgorandAddress("ADIYK65L3XR5ODNNCUIQVEET455L56MRKJHRBX5GU4TZI2752QIWK4UL5A")
val address = AnyAddress(pubkey, CoinType.ALGORAND)
val expected = AnyAddress("ADIYK65L3XR5ODNNCUIQVEET455L56MRKJHRBX5GU4TZI2752QIWK4UL5A", CoinType.ALGORAND)

assertEquals(pubkey.data().toHex(), "0x00d1857babdde3d70dad15110a9093e77abef991524f10dfa6a727946bfdd411")
assertEquals(address.description(), expected.description())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import com.google.protobuf.ByteString
import com.trustwallet.core.app.utils.toHexBytes
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.BinanceSigner
import wallet.core.jni.HRP
import wallet.core.jni.PrivateKey
import wallet.core.jni.CosmosAddress
import wallet.core.jni.proto.Binance
import wallet.core.jni.*
import com.trustwallet.core.app.utils.toHex

class TestBinanceTransactionSigning {
Expand All @@ -34,11 +31,11 @@ class TestBinanceTransactionSigning {
token.amount = 1

val input = Binance.SendOrder.Input.newBuilder()
input.address = ByteString.copyFrom(CosmosAddress(HRP.BINANCE, publicKey).keyHash())
input.address = ByteString.copyFrom(AnyAddress(publicKey, CoinType.BINANCE).data())
input.addAllCoins(listOf(token.build()))

val output = Binance.SendOrder.Output.newBuilder()
output.address = ByteString.copyFrom(CosmosAddress("bnb1hlly02l6ahjsgxw9wlcswnlwdhg4xhx38yxpd5").keyHash())
output.address = ByteString.copyFrom(AnyAddress("bnb1hlly02l6ahjsgxw9wlcswnlwdhg4xhx38yxpd5", CoinType.BINANCE).data())
output.addAllCoins(listOf(token.build()))

val sendOrder = Binance.SendOrder.newBuilder()
Expand All @@ -51,4 +48,4 @@ class TestBinanceTransactionSigning {
val signBytes = sign.encoded.toByteArray()
assertEquals(signBytes.toHex(), "0xb801f0625dee0a462a2c87fa0a1f0a1440c2979694bbc961023d1d27be6fc4d21a9febe612070a03424e421001121f0a14bffe47abfaede50419c577f1074fee6dd1535cd112070a03424e421001126a0a26eb5ae98721026a35920088d98c3888ca68c53dfc93f4564602606cbb87f0fe5ee533db38e50212401b1181faec30b60a2ddaa2804c253cf264c69180ec31814929b5de62088c0c5a45e8a816d1208fc5366bb8b041781a6771248550d04094c3d7a504f9e8310679")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import com.trustwallet.core.app.utils.toHex
import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.CardanoAddress
import wallet.core.jni.PrivateKey
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.*

class TestCardanoAddress {

Expand All @@ -25,8 +22,8 @@ class TestCardanoAddress {
fun testAddress() {
val key = PrivateKey("b0884d248cb301edd1b34cf626ba6d880bb3ae8fd91b4696446999dc4f0b5744309941d56938e943980d11643c535e046653ca6f498c014b88f2ad9fd6e71effbf36a8fa9f5e11eb7a852c41e185e3969d518e66e6893c81d3fc7227009952d4".toHexByteArray())
val pubkey = key.publicKeyEd25519Extended
val address = CardanoAddress(pubkey)
val expected = CardanoAddress("Ae2tdPwUPEZ6RUCnjGHFqi59k5WZLiv3HoCCNGCW8SYc5H9srdTzn1bec4W")
val address = AnyAddress(pubkey, CoinType.CARDANO)
val expected = AnyAddress("Ae2tdPwUPEZ6RUCnjGHFqi59k5WZLiv3HoCCNGCW8SYc5H9srdTzn1bec4W", CoinType.CARDANO)

assertEquals(pubkey.data().toHex(), "0x57fd54be7b38bb8952782c2f59aa276928a4dcbb66c8c62ce44f9d623ecd5a03bf36a8fa9f5e11eb7a852c41e185e3969d518e66e6893c81d3fc7227009952d4")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import com.google.protobuf.ByteString
import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.CosmosAddress
import wallet.core.jni.CosmosSigner
import wallet.core.jni.HRP
import wallet.core.jni.PrivateKey
import wallet.core.jni.*
import wallet.core.jni.proto.Cosmos

class TestCosmosTransactions {
Expand All @@ -22,7 +19,7 @@ class TestCosmosTransactions {
val key =
PrivateKey("80e81ea269e66a0a05b11236df7919fb7fbeedba87452d667489d7403a02f005".toHexByteArray())
val publicKey = key.getPublicKeySecp256k1(true)
val from = CosmosAddress(HRP.COSMOS, publicKey).description()
val from = AnyAddress(publicKey, CoinType.COSMOS).description()

val txAmount = Cosmos.Amount.newBuilder().apply {
amount = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ package com.trustwallet.core.app.blockchains.harmony

import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.Base58
import wallet.core.jni.PrivateKey
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.HarmonyAddress
import wallet.core.jni.*

class TestHarmonyAddress {

Expand All @@ -20,7 +16,7 @@ class TestHarmonyAddress {
fun testAddressFromPrivateKey() {
val key = PrivateKey(Base58.decodeNoCheck("GGzxJ4QmKCXH2juK89RVAmvFAfdUfUARCvxEsBM356vX"))
val pubkey = key.getPublicKeySecp256k1(false)
val address = HarmonyAddress(pubkey)
val address = AnyAddress(pubkey, CoinType.HARMONY)
assertEquals(address.description(), targetAddress)
}

Expand All @@ -30,13 +26,13 @@ class TestHarmonyAddress {
Base58.decodeNoCheck("RKjfnr3wMojEruvXZuvNDmL7UfLUiyU3vsBGoZ4k2qY8YzoEJDHLmXDWid9K6YDuGJ2u1fZ8E8JXDjk3KUuDXtwz"),
PublicKeyType.SECP256K1EXTENDED
)
val address = HarmonyAddress(pubkey)
val address = AnyAddress(pubkey, CoinType.HARMONY)
assertEquals(address.description(), targetAddress)
}

@Test
fun testAddressFromString() {
val address = HarmonyAddress(targetAddress)
val address = AnyAddress(targetAddress, CoinType.HARMONY)
assertEquals(address.description(), targetAddress)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import com.trustwallet.core.app.utils.toHex
import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.KusamaAddress
import wallet.core.jni.PrivateKey
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.*

class TestKusamaAddress {

Expand All @@ -26,8 +23,8 @@ class TestKusamaAddress {

val key = PrivateKey("0x85fca134b3fe3fd523d8b528608d803890e26c93c86dc3d97b8d59c7b3540c97".toHexByteArray())
val pubkey = key.publicKeyEd25519
val address = KusamaAddress(pubkey)
val expected = KusamaAddress("HewiDTQv92L2bVtkziZC8ASxrFUxr6ajQ62RXAnwQ8FDVmg")
val address = AnyAddress(pubkey, CoinType.KUSAMA)
val expected = AnyAddress("HewiDTQv92L2bVtkziZC8ASxrFUxr6ajQ62RXAnwQ8FDVmg", CoinType.KUSAMA)

assertEquals(pubkey.data().toHex(), "0xe0b3fcccfe0283cc0f8c105c68b5690aab8c5c1692a868e55eaca836c8779085")
assertEquals(address.description(), expected.description())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.NanoAddress
import wallet.core.jni.AnyAddress
import wallet.core.jni.CoinType

class TestNanoAddress {

Expand All @@ -16,7 +17,7 @@ class TestNanoAddress {
@Test
fun testAddressFromPublicKey() {
val pubkey = PublicKey(("5114aad86a390897d2a91b33b931b3a59a7df9e63eb3694f9430122f5622ae50").toHexByteArray(), PublicKeyType.ED25519BLAKE2B)
val address = NanoAddress(pubkey)
val address = AnyAddress(pubkey, CoinType.NANO)

assertEquals(address.description(), "nano_1nanode8ngaakzbck8smq6ru9bethqwyehomf79sae1k7xd47dkidjqzffeg")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.trustwallet.core.app.blockchains.solana

import com.google.protobuf.ByteString
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.Base58
import wallet.core.jni.PrivateKey
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.NEARAddress
import wallet.core.jni.*

class TestNEARAddress {

Expand All @@ -22,15 +17,15 @@ class TestNEARAddress {
val privateKeyBytes = Base58.decodeNoCheck("3hoMW1HvnRLSFCLZnvPzWeoGwtdHzke34B2cTHM8rhcbG3TbuLKtShTv3DvyejnXKXKBiV7YPkLeqUHN1ghnqpFv").sliceArray(0..31)
val key = PrivateKey(privateKeyBytes)
val pubkey = key.getPublicKeyEd25519()
val address = NEARAddress(pubkey)
val address = AnyAddress(pubkey, CoinType.NEAR)

assertEquals(address.description(), expectedAddressString)
}

@Test
fun testAddressFromString() {
val addressString = expectedAddressString
val address = NEARAddress(addressString)
val address = AnyAddress(addressString, CoinType.NEAR)
assertEquals(address.description(), addressString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package com.trustwallet.core.app.blockchains.nebulas
import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.PrivateKey
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.NebulasAddress
import wallet.core.jni.*

class TestNebulasAddress {

Expand All @@ -19,18 +16,18 @@ class TestNebulasAddress {
var addrStr = "n1V5bB2tbaM3FUiL4eRwpBLgEredS5C2wLY"
var addrStr2 = "n1zUNqeBPvsyrw5zxp9mKcDdLTjuaEL7s39"

val address = NebulasAddress(addrStr)
val address = AnyAddress(addrStr, CoinType.NEBULAS)
assertEquals(address.description(), addrStr)

val addressOfATP = NebulasAddress(addrStr2)
val addressOfATP = AnyAddress(addrStr2, CoinType.NEBULAS)
assertEquals(addressOfATP.description(), addrStr2)
}

@Test
fun testAddressFromPublicKey() {
var priKey = PrivateKey(("d2fd0ec9f6268fc8d1f563e3e976436936708bdf0dc60c66f35890f5967a8d2b").toHexByteArray())
val pubkey = priKey.getPublicKeySecp256k1(false)
val address = NebulasAddress(pubkey)
val address = AnyAddress(pubkey, CoinType.NEBULAS)

assertEquals(address.description(), "n1V5bB2tbaM3FUiL4eRwpBLgEredS5C2wLY")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.trustwallet.core.app.blockchains.nuls

import com.trustwallet.core.app.utils.toHex
import com.trustwallet.core.app.utils.toHexByteArray
import com.trustwallet.core.app.utils.Numeric
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.NULSAddress
import wallet.core.jni.PrivateKey
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.*

class TestNULSAddress {

Expand All @@ -20,8 +15,8 @@ class TestNULSAddress {
fun testAddress() {
val priKey = PrivateKey(Numeric.hexStringToByteArray("a1269039e4ffdf43687852d7247a295f0b5bc55e6dda031cffaa3295ca0a9d7a"))
val pubkey = priKey.getPublicKeySecp256k1(true)
val address = NULSAddress(pubkey)
val expected = NULSAddress("NULSd6HghWa4CN5qdxqMwYVikQxRZyj57Jn4L")
val address = AnyAddress(pubkey, CoinType.NULS)
val expected = AnyAddress("NULSd6HghWa4CN5qdxqMwYVikQxRZyj57Jn4L", CoinType.NULS)

assertEquals(address.description(), expected.description())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import com.trustwallet.core.app.utils.toHex
import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.PolkadotAddress
import wallet.core.jni.PrivateKey
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.*

class TestPolkadotAddress {

Expand All @@ -26,8 +23,8 @@ class TestPolkadotAddress {

val key = PrivateKey("0xd65ed4c1a742699b2e20c0c1f1fe780878b1b9f7d387f934fe0a7dc36f1f9008".toHexByteArray())
val pubkey = key.publicKeyEd25519
val address = PolkadotAddress(pubkey)
val expected = PolkadotAddress("12twBQPiG5yVSf3jQSBkTAKBKqCShQ5fm33KQhH3Hf6VDoKW")
val address = AnyAddress(pubkey, CoinType.POLKADOT)
val expected = AnyAddress("12twBQPiG5yVSf3jQSBkTAKBKqCShQ5fm33KQhH3Hf6VDoKW", CoinType.POLKADOT)

assertEquals(pubkey.data().toHex(), "0x53d82211c4aadb8c67e1930caef2058a93bc29d7af86bf587fba4aa3b1515037")
assertEquals(address.description(), expected.description())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ package com.trustwallet.core.app.blockchains.solana

import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.Base58
import wallet.core.jni.PrivateKey
import wallet.core.jni.PublicKey
import wallet.core.jni.PublicKeyType
import wallet.core.jni.SolanaAddress
import wallet.core.jni.*

class TestSolanaAddress {

Expand All @@ -19,24 +15,24 @@ class TestSolanaAddress {
@Test
fun testAddressFromPrivateKey() {
val key = PrivateKey(Base58.decodeNoCheck("A7psj2GW7ZMdY4E5hJq14KMeYg7HFjULSsWSrTXZLvYr"))
val pubkey = key.getPublicKeyEd25519()
val address = SolanaAddress(pubkey)
val pubkey = key.publicKeyEd25519
val address = AnyAddress(pubkey, CoinType.SOLANA)

assertEquals(address.description(), expectedAddressString)
}

@Test
fun testAddressFromPublicKey() {
val pubkey = PublicKey(Base58.decodeNoCheck(expectedAddressString), PublicKeyType.ED25519)
val address = SolanaAddress(pubkey)
val address = AnyAddress(pubkey, CoinType.SOLANA)

assertEquals(address.description(), expectedAddressString)
}

@Test
fun testAddressFromString() {
val addressString = expectedAddressString
val address = SolanaAddress(addressString)
val address = AnyAddress(addressString, CoinType.SOLANA)
assertEquals(address.description(), addressString)
}
}
Loading

0 comments on commit e1e9c0c

Please sign in to comment.