Skip to content

Commit 7409aa9

Browse files
Merge branch 'master' into dev
2 parents 77538af + 9dae7e1 commit 7409aa9

File tree

88 files changed

+3753
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3753
-84
lines changed

android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,6 @@ class CoinAddressDerivationTests {
154154
TIA -> assertEquals("celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7", address)
155155
NATIVEZETACHAIN -> assertEquals("zeta13u6g7vqgw074mgmf2ze2cadzvkz9snlwywj304", address)
156156
DYDX -> assertEquals("dydx142j9u5eaduzd7faumygud6ruhdwme98qeayaky", address)
157+
PACTUS -> assertEquals("pc1r7ys2g5a4xc2qtm0t4q987m4mvs57w5g0v4pvzg", address)
157158
}
158159
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// Copyright © 2017 Trust Wallet.
4+
5+
package com.trustwallet.core.app.blockchains.pactus
6+
7+
import com.trustwallet.core.app.utils.toHex
8+
import com.trustwallet.core.app.utils.toHexByteArray
9+
import org.junit.Assert.assertEquals
10+
import org.junit.Test
11+
import wallet.core.jni.*
12+
13+
class TestPactusAddress {
14+
15+
init {
16+
System.loadLibrary("TrustWalletCore")
17+
}
18+
19+
@Test
20+
fun testAddress() {
21+
val key = PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6".toHexByteArray())
22+
val pubkey = key.publicKeyEd25519
23+
val address = AnyAddress(pubkey, CoinType.PACTUS)
24+
val expected = AnyAddress("pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr", CoinType.PACTUS)
25+
26+
assertEquals(pubkey.data().toHex(), "0x95794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa")
27+
assertEquals(address.description(), expected.description())
28+
}
29+
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// Copyright © 2017 Trust Wallet.
4+
5+
package com.trustwallet.core.app.blockchains.pactus
6+
7+
import com.google.protobuf.ByteString
8+
import com.trustwallet.core.app.utils.toHexByteArray
9+
import org.junit.Assert.assertEquals
10+
import org.junit.Test
11+
import wallet.core.jni.PrivateKey
12+
import wallet.core.java.AnySigner
13+
import wallet.core.jni.CoinType
14+
import wallet.core.jni.CoinType.PACTUS
15+
import wallet.core.jni.proto.Pactus
16+
import wallet.core.jni.proto.Pactus.SigningOutput
17+
import com.trustwallet.core.app.utils.Numeric
18+
import org.junit.Assert.assertArrayEquals
19+
20+
class TestPactusSigner {
21+
22+
init {
23+
System.loadLibrary("TrustWalletCore")
24+
}
25+
26+
@Test
27+
fun testPactusTransferSigning() {
28+
// Successfully broadcasted transaction:
29+
// https://pacviewer.com/transaction/1b6b7226f7935a15f05371d1a1fefead585a89704ce464b7cc1d453d299d235f
30+
//
31+
val signingInput = Pactus.SigningInput.newBuilder()
32+
signingInput.apply {
33+
privateKey = ByteString.copyFrom(
34+
PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6"
35+
.toHexByteArray()).data()
36+
)
37+
transaction = Pactus.TransactionMessage.newBuilder().apply {
38+
lockTime = 2335524
39+
fee = 10000000
40+
memo = "wallet-core"
41+
transfer = Pactus.TransferPayload.newBuilder().apply {
42+
sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr"
43+
receiver = "pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra"
44+
amount = 200000000
45+
}.build()
46+
}.build()
47+
}
48+
49+
val output = AnySigner.sign(signingInput.build(), PACTUS, SigningOutput.parser())
50+
51+
assertEquals(
52+
"0x1b6b7226f7935a15f05371d1a1fefead585a89704ce464b7cc1d453d299d235f",
53+
Numeric.toHexString(output.transactionId.toByteArray())
54+
)
55+
56+
assertEquals(
57+
"0x4ed8fee3d8992e82660dd05bbe8608fc56ceabffdeeee61e3213b9b49d33a0fc8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736693eda8506",
58+
Numeric.toHexString(output.signature.toByteArray())
59+
)
60+
61+
assertEquals(
62+
"0x000124a3230080ade2040b77616c6c65742d636f726501037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df218084af5f4ed8fee3d8992e82660dd05bbe8608fc56ceabffdeeee61e3213b9b49d33a0fc8dea6d79ee7ec60f66433f189ed9b3c50b2ad6fa004e26790ee736693eda850695794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa",
63+
Numeric.toHexString(output.signedTransactionData.toByteArray())
64+
)
65+
}
66+
67+
@Test
68+
fun testPactusBondWithPublicKeySigning() {
69+
// Successfully broadcasted transaction:
70+
// https://pacviewer.com/transaction/d194b445642a04ec78ced4448696e50b733f2f0b517a23871882c0eefaf1c28f
71+
//
72+
val signingInput = Pactus.SigningInput.newBuilder()
73+
signingInput.apply {
74+
privateKey = ByteString.copyFrom(
75+
PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6"
76+
.toHexByteArray()).data()
77+
)
78+
transaction = Pactus.TransactionMessage.newBuilder().apply {
79+
lockTime = 2339009
80+
fee = 10000000
81+
memo = "wallet-core"
82+
bond = Pactus.BondPayload.newBuilder().apply {
83+
sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr"
84+
receiver = "pc1p9y5gmu9l002tt60wak9extgvwm69rq3a9ackrl"
85+
stake = 1000000000
86+
publicKey = "public1pnz75msstqdrq5eguvcwanug0zauhqjw2cc4flmez3qethnp68y64ehc4k69amapj7x4na2uda0snqz4yxujgx3jsse4f64fgy7jkh0xauvhrc5ts09vfk48g85t0js66hvajm6xruemsvlxqv3xvkyur8v9v0mtn"
87+
}.build()
88+
}.build()
89+
}
90+
91+
val output = AnySigner.sign(signingInput.build(), PACTUS, SigningOutput.parser())
92+
93+
assertEquals(
94+
"0xd194b445642a04ec78ced4448696e50b733f2f0b517a23871882c0eefaf1c28f",
95+
Numeric.toHexString(output.transactionId.toByteArray())
96+
)
97+
98+
assertEquals(
99+
"0x0d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda55b4338328adac79d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff65e39ce7006300",
100+
Numeric.toHexString(output.signature.toByteArray())
101+
)
102+
103+
assertEquals(
104+
"0x0001c1b0230080ade2040b77616c6c65742d636f726502037098338e0b6808119dfd4457ab806b9c2059b89b0129288df0bf7bd4b5e9eeed8b932d0c76f451823d6098bd4dc20b03460a651c661dd9f10f17797049cac62a9fef228832bbcc3a39355cdf15b68bddf432f1ab3eab8debe1300aa43724834650866a9d552827a56bbcdde32e3c517079589b54e83d16f9435abb3b2de8c3e677067cc0644ccb13833b8094ebdc030d7bc6d94927534b89e2f53bcfc9fc849e0e2982438955eda55b4338328adac79d4ee3216d143f0e1629764ab650734f8ba188e716d71f9eff65e39ce700630095794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa",
105+
Numeric.toHexString(output.signedTransactionData.toByteArray())
106+
)
107+
}
108+
109+
@Test
110+
fun testPactusBondWithoutPublicKeySigning() {
111+
// Successfully broadcasted transaction:
112+
// https://pacviewer.com/transaction/f83f583a5c40adf93a90ea536a7e4b467d30ca4f308d5da52624d80c42adec80
113+
//
114+
val signingInput = Pactus.SigningInput.newBuilder()
115+
signingInput.apply {
116+
privateKey = ByteString.copyFrom(
117+
PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6"
118+
.toHexByteArray()).data()
119+
)
120+
transaction = Pactus.TransactionMessage.newBuilder().apply {
121+
lockTime = 2335580
122+
fee = 10000000
123+
memo = "wallet-core"
124+
bond = Pactus.BondPayload.newBuilder().apply {
125+
sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr"
126+
receiver = "pc1p6taz5l2kq5ppnxv4agnqj48svnvsy797xpe6wd"
127+
stake = 1000000000
128+
}.build()
129+
}.build()
130+
}
131+
132+
val output = AnySigner.sign(signingInput.build(), PACTUS, SigningOutput.parser())
133+
134+
assertEquals(
135+
"0xf83f583a5c40adf93a90ea536a7e4b467d30ca4f308d5da52624d80c42adec80",
136+
Numeric.toHexString(output.transactionId.toByteArray())
137+
)
138+
139+
assertEquals(
140+
"0x9e6279fb64067c7d7316ac74630bbb8589df268aa4548f1c7d85c087a8748ff0715b9149afbd94c5d8ee6b37c787ec63e963cbb38be513ebc436aa58f9a8f00d",
141+
Numeric.toHexString(output.signature.toByteArray())
142+
)
143+
144+
assertEquals(
145+
"0x00015ca3230080ade2040b77616c6c65742d636f726502037098338e0b6808119dfd4457ab806b9c2059b89b01d2fa2a7d560502199995ea260954f064d90278be008094ebdc039e6279fb64067c7d7316ac74630bbb8589df268aa4548f1c7d85c087a8748ff0715b9149afbd94c5d8ee6b37c787ec63e963cbb38be513ebc436aa58f9a8f00d95794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa",
146+
Numeric.toHexString(output.signedTransactionData.toByteArray())
147+
)
148+
}
149+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.trustwallet.core.app.utils
2+
3+
import org.junit.Assert.*
4+
import org.junit.Test
5+
import wallet.core.jni.Bech32
6+
7+
class TestBech32 {
8+
init {
9+
System.loadLibrary("TrustWalletCore");
10+
}
11+
12+
@Test
13+
fun testEncode() {
14+
val data = Numeric.hexStringToByteArray("00443214c74254b635cf84653a56d7c675be77df")
15+
assertEquals(Bech32.encode("abcdef", data), "abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw")
16+
}
17+
18+
@Test
19+
fun testDecode() {
20+
val decoded = Bech32.decode("abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw")
21+
assertEquals(Numeric.toHexString(decoded), "0x00443214c74254b635cf84653a56d7c675be77df")
22+
}
23+
24+
@Test
25+
fun testDecodeWrongChecksumVariant() {
26+
// This is a Bech32m variant, not Bech32 variant. So it should fail using Bech32 decoder.
27+
val decoded = Bech32.decode("abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx")
28+
assertNull(decoded)
29+
}
30+
31+
@Test
32+
fun testEncodeM() {
33+
val data = Numeric.hexStringToByteArray("ffbbcdeb38bdab49ca307b9ac5a928398a418820")
34+
assertEquals(Bech32.encodeM("abcdef", data), "abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx")
35+
}
36+
37+
@Test
38+
fun testDecodeM() {
39+
val decoded = Bech32.decodeM("abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx")
40+
assertEquals(Numeric.toHexString(decoded), "0xffbbcdeb38bdab49ca307b9ac5a928398a418820")
41+
}
42+
43+
@Test
44+
fun testDecodeMWrongChecksumVariant() {
45+
// This is a Bech32 variant, not Bech32m variant. So it should fail using Bech32M decoder.
46+
val decoded = Bech32.decodeM("abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw")
47+
assertNull(decoded)
48+
}
49+
}

codegen-v2/manifest/TWBech32.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: TWBech32
2+
structs:
3+
- name: TWBech32
4+
is_public: true
5+
is_class: false
6+
functions:
7+
- name: TWBech32Encode
8+
is_public: true
9+
is_static: true
10+
params:
11+
- name: hrp
12+
type:
13+
variant: string
14+
is_constant: true
15+
is_nullable: false
16+
is_pointer: true
17+
- name: data
18+
type:
19+
variant: data
20+
is_constant: true
21+
is_nullable: false
22+
is_pointer: true
23+
return_type:
24+
variant: string
25+
is_constant: true
26+
is_nullable: false
27+
is_pointer: true
28+
- name: TWBech32Decode
29+
is_public: true
30+
is_static: true
31+
params:
32+
- name: string
33+
type:
34+
variant: string
35+
is_constant: true
36+
is_nullable: false
37+
is_pointer: true
38+
return_type:
39+
variant: data
40+
is_constant: true
41+
is_nullable: true
42+
is_pointer: true
43+
- name: TWBech32EncodeM
44+
is_public: true
45+
is_static: true
46+
params:
47+
- name: hrp
48+
type:
49+
variant: string
50+
is_constant: true
51+
is_nullable: false
52+
is_pointer: true
53+
- name: data
54+
type:
55+
variant: data
56+
is_constant: true
57+
is_nullable: false
58+
is_pointer: true
59+
return_type:
60+
variant: string
61+
is_constant: true
62+
is_nullable: false
63+
is_pointer: true
64+
- name: TWBech32DecodeM
65+
is_public: true
66+
is_static: true
67+
params:
68+
- name: string
69+
type:
70+
variant: string
71+
is_constant: true
72+
is_nullable: false
73+
is_pointer: true
74+
return_type:
75+
variant: data
76+
is_constant: true
77+
is_nullable: true
78+
is_pointer: true

docs/registry.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ This list is generated from [./registry.json](../registry.json)
9999
| 14001 | WAX | WAXP | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/wax/info/logo.png" width="32" /> | <http://wax.io> |
100100
| 18000 | Meter | MTR | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/meter/info/logo.png" width="32" /> | <https://meter.io/> |
101101
| 19167 | Flux | FLUX | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zelcash/info/logo.png" width="32" /> | <https://runonflux.io> |
102+
| 21888 | Pactus | PAC | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/pactus/info/logo.png" width="32" /> | <https://pactus.org> |
102103
| 52752 | Celo | CELO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/celo/info/logo.png" width="32" /> | <https://celo.org> |
103104
| 59144 | Linea | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/linea/info/logo.png" width="32" /> | <https://linea.build> |
104105
| 81457 | Blast | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/blast/info/logo.png" width="32" /> | <https://blast.io> |

include/TrustWalletCore/TWBase58.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ TWString *_Nonnull TWBase58EncodeNoCheck(TWData *_Nonnull data);
3131
/// Decodes a Base58 string, checking the checksum. Returns null if the string is not a valid Base58 string.
3232
///
3333
/// \param string The Base58 string to decode.
34-
/// \return the decoded data, empty if the string is not a valid Base58 string with checksum.
34+
/// \return the decoded data, null if the string is not a valid Base58 string with checksum.
3535
TW_EXPORT_STATIC_METHOD
3636
TWData *_Nullable TWBase58Decode(TWString *_Nonnull string);
3737

3838
/// Decodes a Base58 string, w/o checking the checksum. Returns null if the string is not a valid Base58 string.
3939
///
4040
/// \param string The Base58 string to decode.
41-
/// \return the decoded data, empty if the string is not a valid Base58 string without checksum.
41+
/// \return the decoded data, null if the string is not a valid Base58 string without checksum.
4242
TW_EXPORT_STATIC_METHOD
4343
TWData *_Nullable TWBase58DecodeNoCheck(TWString *_Nonnull string);
4444

include/TrustWalletCore/TWBech32.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// Copyright © 2017 Trust Wallet.
4+
5+
#pragma once
6+
7+
#include "TWBase.h"
8+
#include "TWData.h"
9+
#include "TWString.h"
10+
11+
TW_EXTERN_C_BEGIN
12+
13+
/// Bech32 encode / decode functions
14+
TW_EXPORT_STRUCT
15+
struct TWBech32;
16+
17+
/// Encodes data as a Bech32 string.
18+
///
19+
/// \param hrp The human-readable part.
20+
/// \param data The data part.
21+
/// \return the encoded Bech32 string.
22+
TW_EXPORT_STATIC_METHOD
23+
TWString *_Nonnull TWBech32Encode(TWString* _Nonnull hrp, TWData *_Nonnull data);
24+
25+
/// Decodes a Bech32 string. Returns null if the string is not a valid Bech32 string.
26+
///
27+
/// \param string The Bech32 string to decode.
28+
/// \return the decoded data, null if the string is not a valid Bech32 string. Note that the human-readable part is not returned.
29+
TW_EXPORT_STATIC_METHOD
30+
TWData *_Nullable TWBech32Decode(TWString *_Nonnull string);
31+
32+
/// Encodes data as a Bech32m string.
33+
///
34+
/// \param hrp The human-readable part.
35+
/// \param data The data part.
36+
/// \return the encoded Bech32m string.
37+
TW_EXPORT_STATIC_METHOD
38+
TWString *_Nonnull TWBech32EncodeM(TWString* _Nonnull hrp, TWData *_Nonnull data);
39+
40+
/// Decodes a Bech32m string. Returns null if the string is not a valid Bech32m string.
41+
///
42+
/// \param string The Bech32m string to decode.
43+
/// \return the decoded data, null if the string is not a valid Bech32m string. Note that the human-readable part is not returned.
44+
TW_EXPORT_STATIC_METHOD
45+
TWData *_Nullable TWBech32DecodeM(TWString *_Nonnull string);
46+
47+
TW_EXTERN_C_END

include/TrustWalletCore/TWBlockchain.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ enum TWBlockchain {
6666
TWBlockchainNativeEvmos = 53, // Cosmos
6767
TWBlockchainNativeInjective = 54, // Cosmos
6868
TWBlockchainBitcoinCash = 55,
69+
TWBlockchainPactus = 56,
6970
};
7071

7172
TW_EXTERN_C_END

0 commit comments

Comments
 (0)