Skip to content
This repository was archived by the owner on Mar 7, 2023. It is now read-only.

Commit 7a8d1c1

Browse files
authored
Change smart chain derivation path (trustwallet#1101)
1 parent a00c16b commit 7a8d1c1

File tree

13 files changed

+92
-17
lines changed

13 files changed

+92
-17
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CoinAddressDerivationTests {
3636
CALLISTO -> assertEquals("0x3E6FFC80745E6669135a76F4A7ce6BCF02436e04", address)
3737
DASH -> assertEquals("XqHiz8EXYbTAtBEYs4pWTHh7ipEDQcNQeT", address)
3838
DIGIBYTE -> assertEquals("dgb1qtjgmerfqwdffyf8ghcrkgy52cghsqptynmyswu", address)
39-
ETHEREUM -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address)
39+
ETHEREUM, SMARTCHAIN -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address)
4040
ETHEREUMCLASSIC -> assertEquals("0x078bA3228F3E6C08bEEac9A005de0b7e7089aD1c", address)
4141
GOCHAIN -> assertEquals("0x5940ce4A14210d4Ccd0ac206CE92F21828016aC2", address)
4242
GROESTLCOIN -> assertEquals("grs1qexwmshts5pdpeqglkl39zyl6693tmfwp0cue4j", address)
@@ -89,6 +89,6 @@ class CoinAddressDerivationTests {
8989
FILECOIN -> assertEquals("f1zzykebxldfcakj5wdb5n3n7priul522fnmjzori", address)
9090
ELROND -> assertEquals("erd1jfcy8aeru6vlx4fe6h3pc3vlpe2cnnur5zetxdhp879yagq7vqvs8na4f8", address)
9191
BANDCHAIN -> assertEquals("band1624hqgend0s3d94z68fyka2y5jak6vd7u0l50r", address)
92-
SMARTCHAIN -> assertEquals("0x49784f90176D8D9d4A3feCDE7C1373dAAb5b13b8", address)
92+
SMARTCHAINLEGACY -> assertEquals("0x49784f90176D8D9d4A3feCDE7C1373dAAb5b13b8", address)
9393
}
9494
}

coins.json

+26-1
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@
14681468
},
14691469
{
14701470
"id": "bsc",
1471-
"name": "Smart Chain",
1471+
"name": "Smart Chain Legacy",
14721472
"coinId": 10000714,
14731473
"slip44": 714,
14741474
"symbol": "BNB",
@@ -1490,5 +1490,30 @@
14901490
"clientPublic": "https://data-seed-prebsc-1-s1.binance.org:8545",
14911491
"clientDocs": "https://github.com/ethereum/wiki/wiki/JSON-RPC"
14921492
}
1493+
},
1494+
{
1495+
"id": "smartchain",
1496+
"name": "Smart Chain",
1497+
"coinId": 20000714,
1498+
"slip44": 714,
1499+
"symbol": "BNB",
1500+
"decimals": 18,
1501+
"blockchain": "Ethereum",
1502+
"derivationPath": "m/44'/60'/0'/0/0",
1503+
"curve": "secp256k1",
1504+
"publicKeyType": "secp256k1Extended",
1505+
"explorer": {
1506+
"url": "https://bscscan.com",
1507+
"txPath": "/tx/",
1508+
"accountPath": "/address/",
1509+
"sampleTx": "0xb9ae2e808fe8e57171f303ad8f6e3fd17d949b0bfc7b4db6e8e30a71cc517d7e",
1510+
"sampleAccount": "0x35552c16704d214347f29Fa77f77DA6d75d7C752"
1511+
},
1512+
"info": {
1513+
"url": "https://www.binance.org/en/smartChain",
1514+
"client": "https://github.com/binance-chain/bsc",
1515+
"clientPublic": "https://bsc-dataseed1.binance.org",
1516+
"clientDocs": "https://eth.wiki/json-rpc/API"
1517+
}
14931518
}
14941519
]

docs/coins.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ This list is generated from [./coins.json](../coins.json)
6464
| 19167 | Zelcash | ZEL | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zelcash/info/logo.png" width="32" /> | <https://zel.cash> |
6565
| 5718350 | Wanchain | WAN | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/wanchain/info/logo.png" width="32" /> | <https://wanchain.org> |
6666
| 5741564 | Waves | WAVES | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/waves/info/logo.png" width="32" /> | <https://wavesplatform.com> |
67-
| 10000714 | Smart Chain | BNB | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bsc/info/logo.png" width="32" /> | <https://www.binance.org/en/smartChain> |
67+
| 20000714 | Smart Chain | BNB | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bsc/info/logo.png" width="32" /> | <https://www.binance.org/en/smartChain> |

include/TrustWalletCore/TWCoinType.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ enum TWCoinType {
8282
TWCoinTypeFilecoin = 461,
8383
TWCoinTypeElrond = 508,
8484
TWCoinTypeBandChain = 494,
85-
TWCoinTypeSmartChain = 10000714,
85+
TWCoinTypeSmartChainLegacy = 10000714,
86+
TWCoinTypeSmartChain = 20000714,
8687
};
8788

8889
/// Returns the blockchain for a coin type.

src/Ethereum/Entry.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Entry: public CoinEntry {
2323
TWCoinTypePOANetwork,
2424
TWCoinTypeThunderToken,
2525
TWCoinTypeTomoChain,
26+
TWCoinTypeSmartChainLegacy,
2627
TWCoinTypeSmartChain,
2728
};
2829
}

src/interface/TWAnyAddress.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ TWData* _Nonnull TWAnyAddressData(struct TWAnyAddress* _Nonnull address) {
144144
case TWCoinTypeTheta:
145145
case TWCoinTypeWanchain:
146146
case TWCoinTypeAion:
147+
case TWCoinTypeSmartChainLegacy:
147148
case TWCoinTypeSmartChain:
148149
data = parse_hex(string);
149150
break;

swift/Tests/CoinAddressDerivationTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CoinAddressDerivationTests: XCTestCase {
4949
case .digiByte:
5050
let expectedResult = "dgb1qtjgmerfqwdffyf8ghcrkgy52cghsqptynmyswu"
5151
assertCoinDerivation(coin, expectedResult, derivedAddress, address)
52-
case .ethereum:
52+
case .ethereum, .smartChain:
5353
let expectedResult = "0x8f348F300873Fd5DA36950B2aC75a26584584feE"
5454
assertCoinDerivation(coin, expectedResult, derivedAddress, address)
5555
case .ethereumClassic:
@@ -199,7 +199,7 @@ class CoinAddressDerivationTests: XCTestCase {
199199
case .elrond:
200200
let expectedResult = "erd1jfcy8aeru6vlx4fe6h3pc3vlpe2cnnur5zetxdhp879yagq7vqvs8na4f8"
201201
assertCoinDerivation(coin, expectedResult, derivedAddress, address)
202-
case .smartChain:
202+
case .smartChainLegacy:
203203
let expectedResult = "0x49784f90176D8D9d4A3feCDE7C1373dAAb5b13b8"
204204
assertCoinDerivation(coin, expectedResult, derivedAddress, address)
205205
@unknown default:

swift/Tests/Keystore/KeyStoreTests.swift

+15-4
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ class KeyStoreTests: XCTestCase {
229229
"address": "0x5dEc7A9299360aEb44c83B8F730F2BF5Dd1688bC",
230230
"coin": 10000714,
231231
"derivationPath": "m/44'/714'/0'/0/0"
232+
}, {
233+
"address": "0x33F44330cc4253cCd4ce4224186DB9baCe2190ea",
234+
"coin": 20000714,
235+
"derivationPath": "m/44'/60'/0'/0/0"
232236
}],
233237
"crypto": {
234238
"cipher": "aes-128-ctr",
@@ -255,12 +259,19 @@ class KeyStoreTests: XCTestCase {
255259

256260
let password = "e28ddf66cec05c1fc09939a00628b230459202b2493fccac288038ef37815723"
257261
let keyStore = try KeyStore(keyDirectory: keyDirectory)
258-
_ = try keyStore.addAccounts(wallet: keyStore.bnbWallet, coins: [.smartChain], password: password)
262+
_ = try keyStore.addAccounts(wallet: keyStore.bnbWallet, coins: [.smartChainLegacy, .smartChain], password: password)
263+
264+
XCTAssertEqual(keyStore.bnbWallet.accounts.count, 5)
265+
266+
let accountLegacy = keyStore.bnbWallet.accounts[3]
267+
268+
XCTAssertEqual(accountLegacy.coin, CoinType.smartChainLegacy)
269+
XCTAssertEqual(accountLegacy.address, "0x5dEc7A9299360aEb44c83B8F730F2BF5Dd1688bC")
270+
271+
let account = keyStore.bnbWallet.accounts[4]
259272

260-
let account = keyStore.bnbWallet.accounts[3]
261-
XCTAssertEqual(keyStore.bnbWallet.accounts.count, 4)
262273
XCTAssertEqual(account.coin, CoinType.smartChain)
263-
XCTAssertEqual(account.address, "0x5dEc7A9299360aEb44c83B8F730F2BF5Dd1688bC")
274+
XCTAssertEqual(account.address, "0x33F44330cc4253cCd4ce4224186DB9baCe2190ea")
264275

265276
let saved = try String(contentsOf: keyStore.bnbWallet.keyURL)
266277
XCTAssertJSONEqual(saved, expected)

tests/BinanceSmartChain/TWCoinTypeTests.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,19 @@ TEST(TWBinanceSmartChainCoinType, TWCoinType) {
2626
ASSERT_EQ(TWBlockchainEthereum, TWCoinTypeBlockchain(TWCoinTypeSmartChain));
2727
ASSERT_EQ(0x0, TWCoinTypeP2shPrefix(TWCoinTypeSmartChain));
2828
ASSERT_EQ(0x0, TWCoinTypeStaticPrefix(TWCoinTypeSmartChain));
29+
ASSERT_EQ(20000714, TWCoinTypeSmartChain);
2930
assertStringsEqual(symbol, "BNB");
3031
assertStringsEqual(txUrl, "https://bscscan.com/tx/0xb9ae2e808fe8e57171f303ad8f6e3fd17d949b0bfc7b4db6e8e30a71cc517d7e");
3132
assertStringsEqual(accUrl, "https://bscscan.com/address/0x35552c16704d214347f29Fa77f77DA6d75d7C752");
32-
assertStringsEqual(id, "bsc");
33+
assertStringsEqual(id, "smartchain");
3334
assertStringsEqual(name, "Smart Chain");
3435
}
36+
37+
TEST(TWBinanceSmartChainLegacyCoinType, TWCoinType) {
38+
auto id = WRAPS(TWCoinTypeConfigurationGetID(TWCoinTypeSmartChainLegacy));
39+
auto name = WRAPS(TWCoinTypeConfigurationGetName(TWCoinTypeSmartChainLegacy));
40+
41+
ASSERT_EQ(10000714, TWCoinTypeSmartChainLegacy);
42+
assertStringsEqual(id, "bsc");
43+
assertStringsEqual(name, "Smart Chain Legacy");
44+
}

tests/Keystore/StoredKeyTests.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const auto mnemonic = "team engine square letter hero song dizzy scrub tornado f
2626
const TWCoinType coinTypeBc = TWCoinTypeBitcoin;
2727
const TWCoinType coinTypeBnb = TWCoinTypeBinance;
2828
const TWCoinType coinTypeBsc = TWCoinTypeSmartChain;
29+
const TWCoinType coinTypeEth = TWCoinTypeEthereum;
30+
const TWCoinType coinTypeBscLegacy = TWCoinTypeSmartChainLegacy;
2931

3032
TEST(StoredKey, CreateWithMnemonic) {
3133
auto key = StoredKey::createWithMnemonic("name", password, mnemonic);
@@ -142,19 +144,27 @@ TEST(StoredKey, AddRemoveAccount) {
142144

143145
{
144146
const auto derivationPath = DerivationPath("m/84'/0'/0'/0/0");
145-
key.addAccount("bc1q375sq4kl2nv0mlmup3vm8znn4eqwu7mt6hkwhr", coinTypeBc, derivationPath, "zpub6qbsWdbcKW9sC6shTKK4VEhfWvDCoWpfLnnVfYKHLHt31wKYUwH3aFDz4WLjZvjHZ5W4qVEyk37cRwzTbfrrT1Gnu8SgXawASnkdQ994atn");
147+
key.addAccount("bc1qaucw06s3agez8tyyk4zj9kt0q2934e3mcewdpf", coinTypeBc, derivationPath, "zpub6rxtad3SPT1C5GUDjPiKQ5oJN5DBeMbdUR7LrdYt12VbU7TBSpGUkdLvfVYGuj1N5edkDoZ3bu1fdN1HprQYfCBdsSH5CaAAygHGsanwtTe");
146148
EXPECT_EQ(key.accounts.size(), 1);
147149
}
148150
{
149151
const auto derivationPath = DerivationPath("m/714'/0'/0'/0/0");
150-
key.addAccount("bnb1devga6q804tx9fqrnx0vtu5r36kxgp9tmk4xkm", coinTypeBnb, derivationPath, "");
151-
key.addAccount("0xf3d468DBb386aaD46E92FF222adDdf872C8CC064", coinTypeBsc, derivationPath, "");
152+
key.addAccount("bnb1utrnnjym7ustgw7pgyvtmnxay4qmt3ahh276nu", coinTypeBnb, derivationPath, "");
153+
key.addAccount("0x23b02dC8f67eD6cF8DCa47935791954286ffe7c9", coinTypeBsc, derivationPath, "");
152154
EXPECT_EQ(key.accounts.size(), 3);
153155
}
156+
{
157+
const auto derivationPath = DerivationPath("m/60'/0'/0'/0/0");
158+
key.addAccount("0xC0d97f61A84A0708225F15d54978D628Fe2C5E62", coinTypeEth, derivationPath, "");
159+
key.addAccount("0xC0d97f61A84A0708225F15d54978D628Fe2C5E62", coinTypeBscLegacy, derivationPath, "");
160+
EXPECT_EQ(key.accounts.size(), 5);
161+
}
154162

155163
key.removeAccount(coinTypeBc);
156164
key.removeAccount(coinTypeBnb);
157165
key.removeAccount(coinTypeBsc);
166+
key.removeAccount(coinTypeEth);
167+
key.removeAccount(coinTypeBscLegacy);
158168
EXPECT_EQ(key.accounts.size(), 0);
159169
}
160170

tests/interface/TWHDWalletTests.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,18 @@ TEST(HDWallet, DeriveAddressBitcoin) {
140140
TEST(HDWallet, DeriveEthereum) {
141141
auto wallet = WRAP(TWHDWallet, TWHDWalletCreateWithMnemonic(words.get(), passphrase.get()));
142142
auto key = WRAP(TWPrivateKey, TWHDWalletGetKeyForCoin(wallet.get(), TWCoinTypeEthereum));
143+
auto key2 = WRAP(TWPrivateKey, TWHDWalletGetKeyForCoin(wallet.get(), TWCoinTypeSmartChain));
144+
143145
auto publicKey = TWPrivateKeyGetPublicKeySecp256k1(key.get(), false);
146+
auto publicKey2 = TWPrivateKeyGetPublicKeySecp256k1(key2.get(), false);
144147
auto publicKeyData = WRAPD(TWPublicKeyData(publicKey));
145148

146149
auto address = WRAPS(TWCoinTypeDeriveAddressFromPublicKey(TWCoinTypeEthereum, publicKey));
150+
auto address2 = WRAPS(TWCoinTypeDeriveAddressFromPublicKey(TWCoinTypeSmartChain, publicKey2));
147151

148152
assertHexEqual(publicKeyData, "0414acbe5a06c68210fcbb77763f9612e45a526990aeb69d692d705f276f558a5ae68268e9389bb099ed5ac84d8d6861110f63644f6e5b447e3f86b4bab5dee011");
149153
assertStringsEqual(address, "0x27Ef5cDBe01777D62438AfFeb695e33fC2335979");
154+
assertStringsEqual(address2, "0x27Ef5cDBe01777D62438AfFeb695e33fC2335979");
150155
}
151156

152157
TEST(HDWallet, DeriveAddressEthereum) {
@@ -258,7 +263,7 @@ TEST(HDWallet, DeriveElrond) {
258263
TEST(HDWallet, DeriveBinance) {
259264
auto wallet = WRAP(TWHDWallet, TWHDWalletCreateWithMnemonic(words.get(), passphrase.get()));
260265
auto key = WRAP(TWPrivateKey, TWHDWalletGetKeyForCoin(wallet.get(), TWCoinTypeBinance));
261-
auto key2 = WRAP(TWPrivateKey, TWHDWalletGetKeyForCoin(wallet.get(), TWCoinTypeSmartChain));
266+
auto key2 = WRAP(TWPrivateKey, TWHDWalletGetKeyForCoin(wallet.get(), TWCoinTypeSmartChainLegacy));
262267
auto keyData = WRAPD(TWPrivateKeyData(key.get()));
263268
auto keyData2 = WRAPD(TWPrivateKeyData(key2.get()));
264269

typescript/tests/index.test.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,24 @@ describe('Wallet Core types tests', () => {
2626
const coin = CoinType.bsc;
2727
expect(coin).to.equal(10000714)
2828
expect(CoinType.id(coin)).to.equal('bsc')
29-
expect(CoinType.name(coin)).to.equal('Smart Chain')
29+
expect(CoinType.name(coin)).to.equal('Smart Chain Legacy')
3030
expect(CoinType.slip44(coin)).to.equal(714)
3131
expect(CoinType.symbol(coin)).to.equal('BNB')
3232
expect(CoinType.decimals(coin)).to.equal(18)
3333
expect(CoinType.derivationPath(coin)).to.equal(`m/44'/714'/0'/0/0`)
3434
})
3535

36+
it('test CoinType.smartchain', () => {
37+
const coin = CoinType.smartchain;
38+
expect(coin).to.equal(20000714)
39+
expect(CoinType.id(coin)).to.equal('smartchain')
40+
expect(CoinType.name(coin)).to.equal('Smart Chain')
41+
expect(CoinType.slip44(coin)).to.equal(714)
42+
expect(CoinType.symbol(coin)).to.equal('BNB')
43+
expect(CoinType.decimals(coin)).to.equal(18)
44+
expect(CoinType.derivationPath(coin)).to.equal(`m/44'/60'/0'/0/0`)
45+
})
46+
3647
it('test Ethereum encoding SigningInput', () => {
3748
const input = TW.Ethereum.Proto.SigningInput.create({
3849
toAddress: '0x3535353535353535353535353535353535353535',

0 commit comments

Comments
 (0)