diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/TestCoinType.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/TestCoinType.kt index 6c518ea54e7..d565a1a08be 100644 --- a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/TestCoinType.kt +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/TestCoinType.kt @@ -52,9 +52,9 @@ class TestCoinType { fun testDerivationPath() { var res = CoinType.createFromValue(CoinType.BITCOIN.value()).derivationPath().toString() assertEquals(res, "m/84'/0'/0'/0/0") - res = CoinType.createFromValue(CoinType.BITCOIN.value()).derivationPathWithDerivation(Derivation.LEGACY).toString() + res = CoinType.createFromValue(CoinType.BITCOIN.value()).derivationPathWithDerivation(Derivation.BITCOINLEGACY).toString() assertEquals(res, "m/44'/0'/0'/0/0") - res = CoinType.createFromValue(CoinType.SOLANA.value()).derivationPathWithDerivation(Derivation.SOLANA).toString() + res = CoinType.createFromValue(CoinType.SOLANA.value()).derivationPathWithDerivation(Derivation.SOLANASOLANA).toString() assertEquals(res, "m/44'/501'/0'/0'") } @@ -62,7 +62,7 @@ class TestCoinType { fun testDeriveAddressFromPublicKeyAndDerivation() { val publicKey = PublicKey("0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798".toHexByteArray(), PublicKeyType.SECP256K1) - val address = CoinType.BITCOIN.deriveAddressFromPublicKeyAndDerivation(publicKey, Derivation.SEGWIT) + val address = CoinType.BITCOIN.deriveAddressFromPublicKeyAndDerivation(publicKey, Derivation.BITCOINSEGWIT) assertEquals(address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4") } } diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/utils/TestAnyAddress.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/utils/TestAnyAddress.kt index 40f9fe147c9..ae4b47b4bd0 100644 --- a/android/app/src/androidTest/java/com/trustwallet/core/app/utils/TestAnyAddress.kt +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/utils/TestAnyAddress.kt @@ -53,10 +53,10 @@ class TestAnyAddress { fun testCreateWithPublicKeyDerivation() { val coin = CoinType.BITCOIN val pubkey = PublicKey(any_address_test_pubkey.toHexByteArray(), PublicKeyType.SECP256K1) - val address1 = AnyAddress(pubkey, coin, Derivation.SEGWIT) + val address1 = AnyAddress(pubkey, coin, Derivation.BITCOINSEGWIT) assertEquals(address1.description(), any_address_test_address) - val address2 = AnyAddress(pubkey, coin, Derivation.LEGACY) + val address2 = AnyAddress(pubkey, coin, Derivation.BITCOINLEGACY) assertEquals(address2.description(), "1JvRfEQFv5q5qy9uTSAezH7kVQf4hqnHXx") } diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/utils/TestHDWallet.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/utils/TestHDWallet.kt index 6e6d2e995b9..e3ec6f29b12 100644 --- a/android/app/src/androidTest/java/com/trustwallet/core/app/utils/TestHDWallet.kt +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/utils/TestHDWallet.kt @@ -113,13 +113,13 @@ class TestHDWallet { val coin = CoinType.BITCOIN val wallet = HDWallet(words, password) - val key1 = wallet.getKeyDerivation(coin, Derivation.SEGWIT) + val key1 = wallet.getKeyDerivation(coin, Derivation.BITCOINSEGWIT) assertEquals(key1.data().toHex(), "0x1901b5994f075af71397f65bd68a9fff8d3025d65f5a2c731cf90f5e259d6aac") - val key2 = wallet.getKeyDerivation(coin, Derivation.LEGACY) + val key2 = wallet.getKeyDerivation(coin, Derivation.BITCOINLEGACY) assertEquals(key2.data().toHex(), "0x28071bf4e2b0340db41b807ed8a5514139e5d6427ff9d58dbd22b7ed187103a4") - val key3 = wallet.getKeyDerivation(coin, Derivation.TESTNET) + val key3 = wallet.getKeyDerivation(coin, Derivation.BITCOINTESTNET) assertEquals(key3.data().toHex(), "0xca5845e1b43e3adf577b7f110b60596479425695005a594c88f9901c3afe864f") } @@ -137,13 +137,13 @@ class TestHDWallet { val coin = CoinType.BITCOIN val wallet = HDWallet(words, password) - val address1 = wallet.getAddressDerivation(coin, Derivation.SEGWIT) + val address1 = wallet.getAddressDerivation(coin, Derivation.BITCOINSEGWIT) assertEquals(address1, "bc1qumwjg8danv2vm29lp5swdux4r60ezptzz7ce85") - val address2 = wallet.getAddressDerivation(coin, Derivation.LEGACY) + val address2 = wallet.getAddressDerivation(coin, Derivation.BITCOINLEGACY) assertEquals(address2, "1PeUvjuxyf31aJKX6kCXuaqxhmG78ZUdL1") - val address3 = wallet.getAddressDerivation(coin, Derivation.TESTNET) + val address3 = wallet.getAddressDerivation(coin, Derivation.BITCOINTESTNET) assertEquals(address3, "tb1qwgpxgwn33z3ke9s7q65l976pseh4edrzfmyvl0") } diff --git a/codegen/bin/coins b/codegen/bin/coins index 4c25b67fc50..a5ea5909e05 100755 --- a/codegen/bin/coins +++ b/codegen/bin/coins @@ -31,9 +31,9 @@ def self.derivation_name(deriv) deriv['name'].downcase end -def self.derivation_enum_name(deriv) +def self.derivation_enum_name(deriv, coin) return "TWDerivationDefault" if deriv['name'].nil? - "TWDerivation" + camel_case(deriv['name']) + "TWDerivation" + format_name(coin['name']) + camel_case(deriv['name']) end def self.coin_img(coin) @@ -53,7 +53,6 @@ coins = JSON.parse(json_string).sort_by { |x| x['coinId'] } # used in some cases for numbering enum values enum_count = 0 -derivations = {} erbs = [ {'template' => 'TWDerivation.h.erb', 'folder' => 'include/TrustWalletCore', 'file' => 'TWDerivation.h'}, diff --git a/codegen/lib/templates/CoinInfoData.cpp.erb b/codegen/lib/templates/CoinInfoData.cpp.erb index 6e0d29a074e..d2bbb5d6b71 100644 --- a/codegen/lib/templates/CoinInfoData.cpp.erb +++ b/codegen/lib/templates/CoinInfoData.cpp.erb @@ -51,7 +51,7 @@ const CoinInfo getCoinInfo(TWCoinType coin) { TWCurve<%= format_name(coin['curve']) %>, { <% coin['derivation'].each do |deriv| -%>{ - <%= derivation_enum_name(deriv) %>, + <%= derivation_enum_name(deriv, coin) %>, "<%= deriv['path'] %>", "<%= derivation_name(deriv) %>", TWHDVersion<% if deriv['xpub'].nil? -%>None<% else -%><%= format_name(deriv['xpub']) %><% end -%>, diff --git a/codegen/lib/templates/TWDerivation.h.erb b/codegen/lib/templates/TWDerivation.h.erb index 6ef63d074b3..e2c9a53a494 100644 --- a/codegen/lib/templates/TWDerivation.h.erb +++ b/codegen/lib/templates/TWDerivation.h.erb @@ -19,9 +19,8 @@ enum TWDerivation { <% enum_count += 1 -%> <% coins.each do |coin| -%> <% coin['derivation'].each_with_index do |deriv, index| -%> -<% if !deriv['name'].nil? and !derivations.has_key?(deriv['name']) -%> -<% derivations[deriv['name']] = true -%> - <%= derivation_enum_name(deriv) %> = <% enum_count += 1 -%><%= enum_count %>, +<% if index > 0 or !deriv['name'].nil? -%> + <%= derivation_enum_name(deriv, coin) %> = <% enum_count += 1 -%><%= enum_count %>, <% end -%> <% end -%> <% end -%> diff --git a/registry.json b/registry.json index 2829accbbc2..ab83bc849f1 100644 --- a/registry.json +++ b/registry.json @@ -56,7 +56,6 @@ "blockchain": "Bitcoin", "derivation": [ { - "name": "segwit", "path": "m/84'/2'/0'/0/0", "xpub": "zpub", "xprv": "zprv" @@ -160,16 +159,9 @@ "blockchain": "Bitcoin", "derivation": [ { - "name": "segwit", "path": "m/84'/14'/0'/0/0", "xpub": "zpub", "xprv": "zprv" - }, - { - "name": "legacy", - "path": "m/44'/14'/0'/0/0", - "xpub": "xpub", - "xprv": "xprv" } ], "curve": "secp256k1", @@ -233,7 +225,6 @@ "blockchain": "Bitcoin", "derivation": [ { - "name": "segwit", "path": "m/84'/20'/0'/0/0", "xpub": "zpub", "xprv": "zprv" @@ -267,16 +258,9 @@ "blockchain": "Bitcoin", "derivation": [ { - "name": "legacy", "path": "m/44'/22'/0'/0/0", "xpub": "xpub", "xprv": "xprv" - }, - { - "name": "segwit", - "path": "m/84'/22'/0'/0/0", - "xpub": "zpub", - "xprv": "zprv" } ], "curve": "secp256k1", @@ -340,16 +324,9 @@ "blockchain": "Bitcoin", "derivation": [ { - "name": "segwit", "path": "m/84'/57'/0'/0/0", "xpub": "zpub", "xprv": "zprv" - }, - { - "name": "legacy", - "path": "m/44'/57'/0'/0/0", - "xpub": "xpub", - "xprv": "xprv" } ], "curve": "secp256k1", @@ -1540,16 +1517,9 @@ "blockchain": "Bitcoin", "derivation": [ { - "name": "segwit", "path": "m/84'/156'/0'/0/0", "xpub": "zpub", "xprv": "zprv" - }, - { - "name": "legacy", - "path": "m/44'/156'/0'/0/0", - "xpub": "xpub", - "xprv": "xprv" } ], "curve": "secp256k1", @@ -2872,16 +2842,9 @@ "blockchain": "Bitcoin", "derivation": [ { - "name": "legacy", "path": "m/44'/2301'/0'/0/0", "xpub": "xpub", "xprv": "xprv" - }, - { - "name": "segwit", - "path": "m/84'/2301'/0'/0/0", - "xpub": "zpub", - "xprv": "zprv" } ], "curve": "secp256k1", diff --git a/rust/frameworks/tw_utxo/src/address/derivation.rs b/rust/frameworks/tw_utxo/src/address/derivation.rs index bd6cb3cfaf0..05ced642e02 100644 --- a/rust/frameworks/tw_utxo/src/address/derivation.rs +++ b/rust/frameworks/tw_utxo/src/address/derivation.rs @@ -3,7 +3,9 @@ // Copyright © 2017 Trust Wallet. use tw_coin_entry::coin_context::CoinContext; -use tw_coin_entry::derivation::Derivation; +use tw_coin_entry::derivation::{ChildIndex, Derivation}; + +pub const SEGWIT_DERIVATION_PATH_TYPE: ChildIndex = ChildIndex::Hardened(84); pub enum BitcoinDerivation { Legacy, @@ -15,27 +17,36 @@ impl BitcoinDerivation { /// https://github.com/trustwallet/wallet-core/blob/b65adc4c86e49eb905f659ade025185a62e87ca9/src/Bitcoin/Entry.cpp#L67 pub fn tw_derivation(coin: &dyn CoinContext, derivation: Derivation) -> BitcoinDerivation { match derivation { - Derivation::Default + // In case of a default derivation specified by the function caller, + // we should check the default derivation in the `coin`'s context. // Please note that testnet derivation is no longer supported. Instead, use address prefix. - | Derivation::Testnet => { - let Some(default_derivation) = coin.derivations().first() else { - return BitcoinDerivation::Segwit; - }; - if default_derivation.name == Derivation::Segwit { - return BitcoinDerivation::Segwit; - } + Derivation::Default | Derivation::Testnet => (), + Derivation::Segwit => return BitcoinDerivation::Segwit, + Derivation::Legacy => return BitcoinDerivation::Legacy, + } + + let Some(default_derivation) = coin.derivations().first() else { + return BitcoinDerivation::Legacy; + }; + let derivation_path_type = default_derivation.path.path().first().copied(); + + match default_derivation.name { + Derivation::Segwit => BitcoinDerivation::Segwit, + Derivation::Default if derivation_path_type == Some(SEGWIT_DERIVATION_PATH_TYPE) => { + BitcoinDerivation::Segwit + }, + Derivation::Default | Derivation::Legacy | Derivation::Testnet => { BitcoinDerivation::Legacy }, - Derivation::Segwit => BitcoinDerivation::Segwit, - Derivation::Legacy => BitcoinDerivation::Legacy, } } /// TrustWallet behaviour inherited from: /// https://github.com/trustwallet/wallet-core/blob/b65adc4c86e49eb905f659ade025185a62e87ca9/src/Bitcoin/Entry.cpp#L14 pub fn tw_supports_segwit(coin: &dyn CoinContext) -> bool { - coin.derivations() - .iter() - .any(|der| der.name == Derivation::Segwit) + coin.derivations().iter().any(|der| { + der.name == Derivation::Segwit + || der.path.path().first().copied() == Some(SEGWIT_DERIVATION_PATH_TYPE) + }) } } diff --git a/src/Bitcoin/Entry.cpp b/src/Bitcoin/Entry.cpp index d76aa288122..504ea50f796 100644 --- a/src/Bitcoin/Entry.cpp +++ b/src/Bitcoin/Entry.cpp @@ -79,13 +79,14 @@ std::string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, TW case TWCoinTypeSyscoin: case TWCoinTypeStratis: switch (derivation) { - case TWDerivationLegacy: + case TWDerivationBitcoinLegacy: + case TWDerivationLitecoinLegacy: return Address(publicKey, p2pkh).string(); - case TWDerivationTestnet: + case TWDerivationBitcoinTestnet: return SegwitAddress::createTestnetFromPublicKey(publicKey).string(); - case TWDerivationSegwit: + case TWDerivationBitcoinSegwit: case TWDerivationDefault: default: return SegwitAddress(publicKey, hrp).string(); diff --git a/src/BitcoinDiamond/Entry.cpp b/src/BitcoinDiamond/Entry.cpp index cbf9eddf441..b75a9ea6d1b 100644 --- a/src/BitcoinDiamond/Entry.cpp +++ b/src/BitcoinDiamond/Entry.cpp @@ -29,7 +29,7 @@ string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, TWDeriv const char* hrp = getFromPrefixHrpOrDefault(addressPrefix, coin); switch (derivation) { - case TWDerivationLegacy: + case TWDerivationBitcoinLegacy: case TWDerivationDefault: return Bitcoin::Address(publicKey, p2pkh).string(); default: diff --git a/src/Groestlcoin/Entry.cpp b/src/Groestlcoin/Entry.cpp index 2a5922155a8..89254b29e9a 100644 --- a/src/Groestlcoin/Entry.cpp +++ b/src/Groestlcoin/Entry.cpp @@ -22,7 +22,7 @@ std::string Entry::deriveAddress([[maybe_unused]] TWCoinType coin, const PublicK auto p2pkh = getFromPrefixPkhOrDefault(addressPrefix, coin); switch (derivation) { - case TWDerivationLegacy: + case TWDerivationBitcoinLegacy: return Address(publicKey, p2pkh).string(); default: return TW::Bitcoin::SegwitAddress(publicKey, hrp).string(); diff --git a/src/Verge/Entry.cpp b/src/Verge/Entry.cpp index 6b22d76a853..fea63ca93f8 100644 --- a/src/Verge/Entry.cpp +++ b/src/Verge/Entry.cpp @@ -27,7 +27,7 @@ string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, TWDeriv const char* hrp = getFromPrefixHrpOrDefault(addressPrefix, coin); switch (derivation) { - case TWDerivationLegacy: + case TWDerivationBitcoinLegacy: case TWDerivationDefault: return Bitcoin::Address(publicKey, p2pkh).string(); default: diff --git a/swift/Tests/AnyAddressTests.swift b/swift/Tests/AnyAddressTests.swift index 1ecdde2c8f3..85893b6ba17 100644 --- a/swift/Tests/AnyAddressTests.swift +++ b/swift/Tests/AnyAddressTests.swift @@ -35,10 +35,10 @@ class AnyAddressTests: XCTestCase { func testCreateWithPublicKeyDerivation() { let coin = CoinType.bitcoin let pubkey = PublicKey(data: Data(hexString: any_address_test_pubkey)!, type: .secp256k1)! - let address1 = AnyAddress(publicKey: pubkey, coin: coin, derivation: .segwit) + let address1 = AnyAddress(publicKey: pubkey, coin: coin, derivation: .bitcoinSegwit) XCTAssertEqual(address1.description, any_address_test_address) - let address2 = AnyAddress(publicKey: pubkey, coin: coin, derivation: .legacy) + let address2 = AnyAddress(publicKey: pubkey, coin: coin, derivation: .bitcoinLegacy) XCTAssertEqual(address2.description, "1JvRfEQFv5q5qy9uTSAezH7kVQf4hqnHXx") } diff --git a/swift/Tests/CoinTypeTests.swift b/swift/Tests/CoinTypeTests.swift index 575e08fc0a2..63b4f8e9b6a 100644 --- a/swift/Tests/CoinTypeTests.swift +++ b/swift/Tests/CoinTypeTests.swift @@ -31,15 +31,15 @@ class CoinTypeTests: XCTestCase { func testCoinDerivation() { XCTAssertEqual(CoinType.bitcoin.derivationPath(), "m/84'/0'/0'/0/0") - XCTAssertEqual(CoinType.bitcoin.derivationPathWithDerivation(derivation: Derivation.legacy), "m/44'/0'/0'/0/0") - XCTAssertEqual(CoinType.solana.derivationPathWithDerivation(derivation: Derivation.solana), "m/44'/501'/0'/0'") + XCTAssertEqual(CoinType.bitcoin.derivationPathWithDerivation(derivation: Derivation.bitcoinLegacy), "m/44'/0'/0'/0/0") + XCTAssertEqual(CoinType.solana.derivationPathWithDerivation(derivation: Derivation.solanaSolana), "m/44'/501'/0'/0'") } - + func testDeriveAddressFromPublicKeyAndDerivation() { let pkData = Data(hexString: "0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798")! let publicKey = PublicKey(data: pkData, type: .secp256k1)! - - let address = CoinType.bitcoin.deriveAddressFromPublicKeyAndDerivation(publicKey: publicKey, derivation: Derivation.segwit) + + let address = CoinType.bitcoin.deriveAddressFromPublicKeyAndDerivation(publicKey: publicKey, derivation: Derivation.bitcoinSegwit) XCTAssertEqual(address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4") } } diff --git a/swift/Tests/HDWalletTests.swift b/swift/Tests/HDWalletTests.swift index 911638706b1..789dad6a6c4 100644 --- a/swift/Tests/HDWalletTests.swift +++ b/swift/Tests/HDWalletTests.swift @@ -92,13 +92,13 @@ class HDWalletTests: XCTestCase { let coin = CoinType.bitcoin let wallet = HDWallet.test - let key1 = wallet.getKeyDerivation(coin: coin, derivation: .segwit) + let key1 = wallet.getKeyDerivation(coin: coin, derivation: .bitcoinSegwit) XCTAssertEqual(key1.data.hexString, "1901b5994f075af71397f65bd68a9fff8d3025d65f5a2c731cf90f5e259d6aac") - let key2 = wallet.getKeyDerivation(coin: coin, derivation: .legacy) + let key2 = wallet.getKeyDerivation(coin: coin, derivation: .bitcoinLegacy) XCTAssertEqual(key2.data.hexString, "28071bf4e2b0340db41b807ed8a5514139e5d6427ff9d58dbd22b7ed187103a4") - let key3 = wallet.getKeyDerivation(coin: coin, derivation: .testnet) + let key3 = wallet.getKeyDerivation(coin: coin, derivation: .bitcoinTestnet) XCTAssertEqual(key3.data.hexString, "ca5845e1b43e3adf577b7f110b60596479425695005a594c88f9901c3afe864f") } @@ -114,13 +114,13 @@ class HDWalletTests: XCTestCase { let coin = CoinType.bitcoin let wallet = HDWallet.test - let address1 = wallet.getAddressDerivation(coin: coin, derivation: .segwit) + let address1 = wallet.getAddressDerivation(coin: coin, derivation: .bitcoinSegwit) XCTAssertEqual(address1, "bc1qumwjg8danv2vm29lp5swdux4r60ezptzz7ce85") - let address2 = wallet.getAddressDerivation(coin: coin, derivation: .legacy) + let address2 = wallet.getAddressDerivation(coin: coin, derivation: .bitcoinLegacy) XCTAssertEqual(address2, "1PeUvjuxyf31aJKX6kCXuaqxhmG78ZUdL1") - let address3 = wallet.getAddressDerivation(coin: coin, derivation: .testnet) + let address3 = wallet.getAddressDerivation(coin: coin, derivation: .bitcoinTestnet) XCTAssertEqual(address3, "tb1qwgpxgwn33z3ke9s7q65l976pseh4edrzfmyvl0") } diff --git a/swift/Tests/Keystore/KeyStoreTests.swift b/swift/Tests/Keystore/KeyStoreTests.swift index 31a813e2938..3017d10c304 100755 --- a/swift/Tests/Keystore/KeyStoreTests.swift +++ b/swift/Tests/Keystore/KeyStoreTests.swift @@ -434,7 +434,7 @@ class KeyStoreTests: XCTestCase { XCTAssertEqual(btc1.address, "bc1qturc268v0f2srjh4r2zu4t6zk4gdutqd5a6zny") XCTAssertEqual(btc1.extendedPublicKey, "zpub6qbsWdbcKW9sC6shTKK4VEhfWvDCoWpfLnnVfYKHLHt31wKYUwH3aFDz4WLjZvjHZ5W4qVEyk37cRwzTbfrrT1Gnu8SgXawASnkdQ994atn") - let btc2 = try wallet.getAccount(password: password, coin: .bitcoin, derivation: .legacy) + let btc2 = try wallet.getAccount(password: password, coin: .bitcoin, derivation: .bitcoinLegacy) XCTAssertEqual(btc2.address, "1NyRyFewhZcWMa9XCj3bBxSXPXyoSg8dKz") XCTAssertEqual(btc2.extendedPublicKey, "xpub6CR52eaUuVb4kXAVyHC2i5ZuqJ37oWNPZFtjXaazFPXZD45DwWBYEBLdrF7fmCR9pgBuCA9Q57zZfyJjDUBDNtWkhWuGHNYKLgDHpqrHsxV") @@ -442,7 +442,7 @@ class KeyStoreTests: XCTestCase { XCTAssertEqual(solana1.address, "HiipoCKL8hX2RVmJTz3vaLy34hS2zLhWWMkUWtw85TmZ") XCTAssertEqual(solana1.derivationPath, "m/44'/501'/0'") - let solana2 = try wallet.getAccount(password: password, coin: .solana, derivation: .solana) + let solana2 = try wallet.getAccount(password: password, coin: .solana, derivation: .solanaSolana) XCTAssertEqual(solana2.address, "CgWJeEWkiYqosy1ba7a3wn9HAQuHyK48xs3LM4SSDc1C") XCTAssertEqual(solana2.derivationPath, "m/44'/501'/0'/0'") } diff --git a/tests/chains/Bitcoin/SegwitAddressTests.cpp b/tests/chains/Bitcoin/SegwitAddressTests.cpp index d36d95fb2ef..62c7fe7fde5 100644 --- a/tests/chains/Bitcoin/SegwitAddressTests.cpp +++ b/tests/chains/Bitcoin/SegwitAddressTests.cpp @@ -243,9 +243,9 @@ TEST(SegwitAddress, SegwitDerivationHDWallet) { // addresses with different derivations EXPECT_EQ(wallet.deriveAddress(coin), "bc1qpsp72plnsqe6e2dvtsetxtww2cz36ztmfxghpd"); EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationDefault), "bc1qpsp72plnsqe6e2dvtsetxtww2cz36ztmfxghpd"); - EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationSegwit), "bc1qpsp72plnsqe6e2dvtsetxtww2cz36ztmfxghpd"); - EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationLegacy), "1GVb4mfQrvymPLz7zeZ3LnQ8sFv3NedZXe"); - EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationTestnet), "tb1qq8p994ak933c39d2jaj8n4sg598tnkhnyk5sg5"); + EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationBitcoinSegwit), "bc1qpsp72plnsqe6e2dvtsetxtww2cz36ztmfxghpd"); + EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationBitcoinLegacy), "1GVb4mfQrvymPLz7zeZ3LnQ8sFv3NedZXe"); + EXPECT_EQ(wallet.deriveAddress(coin, TWDerivationBitcoinTestnet), "tb1qq8p994ak933c39d2jaj8n4sg598tnkhnyk5sg5"); } } // namespace TW::Bitcoin::tests diff --git a/tests/chains/BitcoinDiamond/AddressTests.cpp b/tests/chains/BitcoinDiamond/AddressTests.cpp index 1bf4d91546c..a99b7ce46ea 100644 --- a/tests/chains/BitcoinDiamond/AddressTests.cpp +++ b/tests/chains/BitcoinDiamond/AddressTests.cpp @@ -31,7 +31,7 @@ TEST(BitcoinDiamondAddress, FromPublicKey) { auto addr = wallet.deriveAddress(TWCoinTypeBitcoinDiamond); EXPECT_EQ(addr, "1KaRW9xPPtCTZ9FdaTHduCPck4YvSeEWNn"); - addr = wallet.deriveAddress(TWCoinTypeBitcoinDiamond, TWDerivationSegwit); + addr = wallet.deriveAddress(TWCoinTypeBitcoinDiamond, TWDerivationBitcoinSegwit); EXPECT_EQ(addr, "bcd1q7jh5qukuy9fc2pjm89xnyvx5dtfyvru9evw30x"); } @@ -45,7 +45,7 @@ TEST(BitcoinDiamondAddress, FromString) { TEST(BitcoinDiamondAddress, AddressData) { const auto publicKey = PublicKey(parse_hex("02485a209514cc896f8ed736e205bc4c35bd5299ef3f9e84054475336b964c02a3"), TWPublicKeyTypeSECP256k1); - auto address = TW::deriveAddress(TWCoinTypeBitcoinDiamond, publicKey, TWDerivationSegwit); + auto address = TW::deriveAddress(TWCoinTypeBitcoinDiamond, publicKey, TWDerivationBitcoinSegwit); auto data = TW::addressToData(TWCoinTypeBitcoinDiamond, "1G15VvshDxwFTnahZZECJfFwEkq9fP79o8"); ASSERT_EQ(hex(data), "a48da46386ce52cccad178de900c71f06130c310"); diff --git a/tests/chains/BitcoinDiamond/SignerTests.cpp b/tests/chains/BitcoinDiamond/SignerTests.cpp index 2f88e8f66c1..2b0a239d726 100644 --- a/tests/chains/BitcoinDiamond/SignerTests.cpp +++ b/tests/chains/BitcoinDiamond/SignerTests.cpp @@ -104,7 +104,7 @@ TEST(BitcoinDiamondSigner, SignSegwit) { auto utxoKey0 = PrivateKey(parse_hex("d2b9f2846d3adcead910ee0124a3ba7ae29e8a4729787d27f9bea1f532928eee")); auto utxoAddr0 = - TW::deriveAddress(TWCoinTypeBitcoinDiamond, utxoKey0, TWDerivationSegwit); + TW::deriveAddress(TWCoinTypeBitcoinDiamond, utxoKey0, TWDerivationBitcoinSegwit); ASSERT_EQ(utxoAddr0, "bcd1q5jx6gcuxeefvejk30r0fqrr37psnpscslrrd0y"); auto script0 = Bitcoin::Script::lockScriptForAddress(utxoAddr0, TWCoinTypeBitcoinDiamond); ASSERT_EQ(hex(script0.bytes), "0014a48da46386ce52cccad178de900c71f06130c310"); @@ -162,7 +162,7 @@ TEST(BitcoinDiamondSigner, SignAnyoneCanPay) { auto utxoKey0 = PrivateKey(parse_hex("d2b9f2846d3adcead910ee0124a3ba7ae29e8a4729787d27f9bea1f532928eee")); auto utxoAddr0 = - TW::deriveAddress(TWCoinTypeBitcoinDiamond, utxoKey0, TWDerivationSegwit); + TW::deriveAddress(TWCoinTypeBitcoinDiamond, utxoKey0, TWDerivationBitcoinSegwit); ASSERT_EQ(utxoAddr0, "bcd1q5jx6gcuxeefvejk30r0fqrr37psnpscslrrd0y"); auto script0 = Bitcoin::Script::lockScriptForAddress(utxoAddr0, TWCoinTypeBitcoinDiamond); ASSERT_EQ(hex(script0.bytes), "0014a48da46386ce52cccad178de900c71f06130c310"); diff --git a/tests/chains/Groestlcoin/AddressTests.cpp b/tests/chains/Groestlcoin/AddressTests.cpp index 7382a02ad85..8fcce675012 100644 --- a/tests/chains/Groestlcoin/AddressTests.cpp +++ b/tests/chains/Groestlcoin/AddressTests.cpp @@ -54,19 +54,19 @@ TEST(GroestlcoinAddress, Derive) { auto address = TW::deriveAddress(TWCoinTypeGroestlcoin, wallet.getKey(TWCoinTypeGroestlcoin, path)); ASSERT_EQ(address, "grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne"); - address = TW::deriveAddress(TWCoinTypeGroestlcoin, wallet.getKey(TWCoinTypeGroestlcoin, path), TWDerivationLegacy); + address = TW::deriveAddress(TWCoinTypeGroestlcoin, wallet.getKey(TWCoinTypeGroestlcoin, path), TWDerivationBitcoinLegacy); ASSERT_EQ(address, "FfsAQrzfdECwEsApubn2rvxgamU8CcqsLT"); } TEST(GroestlcoinAddress, AddressData) { const auto publicKey = PublicKey(parse_hex("03b85cc59b67c35851eb5060cfc3a759a482254553c5857075c9e247d74d412c91"), TWPublicKeyTypeSECP256k1); - auto address = TW::deriveAddress(TWCoinTypeGroestlcoin, publicKey, TWDerivationLegacy); + auto address = TW::deriveAddress(TWCoinTypeGroestlcoin, publicKey, TWDerivationBitcoinLegacy); ASSERT_EQ(address, "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM"); auto addressData = TW::addressToData(TWCoinTypeGroestlcoin, address); ASSERT_EQ(hex(addressData), "98af0aaca388a7e1024f505c033626d908e3b54a"); - address = TW::deriveAddress(TWCoinTypeGroestlcoin, publicKey, TWDerivationSegwit); + address = TW::deriveAddress(TWCoinTypeGroestlcoin, publicKey, TWDerivationBitcoinSegwit); EXPECT_EQ(address, "grs1qnzhs4t9r3zn7zqj02pwqxd3xmyyw8d22q55nf8"); addressData = TW::addressToData(TWCoinTypeGroestlcoin, address); diff --git a/tests/chains/Litecoin/LitecoinAddressTests.cpp b/tests/chains/Litecoin/LitecoinAddressTests.cpp index f31b070741a..19bee636bb4 100644 --- a/tests/chains/Litecoin/LitecoinAddressTests.cpp +++ b/tests/chains/Litecoin/LitecoinAddressTests.cpp @@ -20,7 +20,7 @@ namespace TW::Bitcoin::tests { TEST(LitecoinAddress, deriveAddress_legacy) { const auto pubKey = PublicKey(parse_hex("03b49081a4d7ad24b20e209bc6fe10491aadb5607777baf0509a036cce96025db0"), TWPublicKeyTypeSECP256k1); - auto addrStr = deriveAddress(TWCoinTypeLitecoin, pubKey, TWDerivationLegacy); + auto addrStr = deriveAddress(TWCoinTypeLitecoin, pubKey, TWDerivationLitecoinLegacy); EXPECT_EQ(addrStr, "LW6HjAU6GL9fK2LZWUA6VZCzomTdrpx3nr"); const auto address = Address(pubKey, TWCoinTypeP2pkhPrefix(TWCoinTypeLitecoin)); @@ -29,7 +29,7 @@ TEST(LitecoinAddress, deriveAddress_legacy) { TEST(LitecoinAddress, deriveAddress_segwit) { const auto pubKey = PublicKey(parse_hex("030fc2fdd1a0b5d43b31227a4b1cd57e7d35a6edc93fb12f9315e67762abeb8be0"), TWPublicKeyTypeSECP256k1); - auto addrStr = deriveAddress(TWCoinTypeLitecoin, pubKey, TWDerivationSegwit); + auto addrStr = deriveAddress(TWCoinTypeLitecoin, pubKey, TWDerivationBitcoinSegwit); EXPECT_EQ(addrStr, "ltc1q3m3ujh350qrqdl33pv7pjw0d0m9qnm6qjcjpga"); const auto address = SegwitAddress(pubKey, stringForHRP(TWCoinTypeHRP(TWCoinTypeLitecoin))); diff --git a/tests/chains/Nebl/AddressTests.cpp b/tests/chains/Nebl/AddressTests.cpp index 231e80f8e19..932f9dfd9b4 100644 --- a/tests/chains/Nebl/AddressTests.cpp +++ b/tests/chains/Nebl/AddressTests.cpp @@ -36,7 +36,7 @@ TEST(NeblAddress, FromPublicKey) { auto address = Address(publicKey, TWCoinTypeP2pkhPrefix(TWCoinTypeNebl)); ASSERT_EQ(address.string(), "NboLGGKWtK5eXzaah5GVpXju9jCcoMi4cc"); - auto addr = TW::deriveAddress(TWCoinTypeNebl, publicKey, TWDerivationLegacy); + auto addr = TW::deriveAddress(TWCoinTypeNebl, publicKey, TWDerivationBitcoinLegacy); ASSERT_EQ(addr, "NboLGGKWtK5eXzaah5GVpXju9jCcoMi4cc"); } diff --git a/tests/chains/Verge/AddressTests.cpp b/tests/chains/Verge/AddressTests.cpp index 46435000397..5185d3bd005 100644 --- a/tests/chains/Verge/AddressTests.cpp +++ b/tests/chains/Verge/AddressTests.cpp @@ -31,7 +31,7 @@ TEST(VergeAddress, FromPrivateKey) { auto address = Address(publicKey, TWCoinTypeP2pkhPrefix(TWCoinTypeVerge)); ASSERT_EQ(address.string(), "DRyNFvJaybnF22UfMS6NR1Qav3mqxPj86E"); - auto addr = TW::deriveAddress(TWCoinTypeVerge, publicKey, TWDerivationSegwit); + auto addr = TW::deriveAddress(TWCoinTypeVerge, publicKey, TWDerivationBitcoinSegwit); ASSERT_EQ(addr, "vg1qujpe553lzgyg95g7k0w6zwscuy0ae022h4q4zg"); } @@ -40,7 +40,7 @@ TEST(VergeAddress, FromPublicKey) { auto address = Address(publicKey, TWCoinTypeP2pkhPrefix(TWCoinTypeVerge)); ASSERT_EQ(address.string(), "D8rBdwBfz5wvLhmHvRkXnNzeeihQgxkLmL"); - auto addr = TW::deriveAddress(TWCoinTypeVerge, publicKey, TWDerivationLegacy); + auto addr = TW::deriveAddress(TWCoinTypeVerge, publicKey, TWDerivationBitcoinLegacy); ASSERT_EQ(addr, "D8rBdwBfz5wvLhmHvRkXnNzeeihQgxkLmL"); } diff --git a/tests/common/AnyAddressTests.cpp b/tests/common/AnyAddressTests.cpp index f1fc893ca66..fc765c6f548 100644 --- a/tests/common/AnyAddressTests.cpp +++ b/tests/common/AnyAddressTests.cpp @@ -32,7 +32,7 @@ TEST(AnyAddress, createFromPubKeyDerivation) { EXPECT_EQ(addr->address, ANY_ADDRESS_TEST_ADDRESS); } { - std::unique_ptr addr(AnyAddress::createAddress(publicKey, TWCoinTypeBitcoin, TWDerivationLegacy, std::monostate())); + std::unique_ptr addr(AnyAddress::createAddress(publicKey, TWCoinTypeBitcoin, TWDerivationBitcoinLegacy, std::monostate())); EXPECT_EQ(addr->address, "1JvRfEQFv5q5qy9uTSAezH7kVQf4hqnHXx"); } } diff --git a/tests/common/Keystore/DerivationPathTests.cpp b/tests/common/Keystore/DerivationPathTests.cpp index 9a899575b3b..178c9072f54 100644 --- a/tests/common/Keystore/DerivationPathTests.cpp +++ b/tests/common/Keystore/DerivationPathTests.cpp @@ -78,18 +78,18 @@ TEST(Derivation, derivationPath) { TEST(Derivation, alternativeDerivation) { EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin).string(), "m/84'/0'/0'/0/0"); EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin, TWDerivationDefault).string(), "m/84'/0'/0'/0/0"); - EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin, TWDerivationSegwit).string(), "m/84'/0'/0'/0/0"); - EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeBitcoin, TWDerivationSegwit)), "segwit"); - EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin, TWDerivationLegacy).string(), "m/44'/0'/0'/0/0"); - EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeBitcoin, TWDerivationLegacy)), "legacy"); + EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin, TWDerivationBitcoinSegwit).string(), "m/84'/0'/0'/0/0"); + EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeBitcoin, TWDerivationBitcoinSegwit)), "segwit"); + EXPECT_EQ(TW::derivationPath(TWCoinTypeBitcoin, TWDerivationBitcoinLegacy).string(), "m/44'/0'/0'/0/0"); + EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeBitcoin, TWDerivationBitcoinLegacy)), "legacy"); EXPECT_EQ(TW::derivationPath(TWCoinTypeLitecoin, TWDerivationDefault).string(), "m/84'/2'/0'/0/0"); - EXPECT_EQ(TW::derivationPath(TWCoinTypeLitecoin, TWDerivationLegacy).string(), "m/44'/2'/0'/0/0"); + EXPECT_EQ(TW::derivationPath(TWCoinTypeLitecoin, TWDerivationLitecoinLegacy).string(), "m/44'/2'/0'/0/0"); EXPECT_EQ(TW::derivationPath(TWCoinTypeSolana).string(), "m/44'/501'/0'"); EXPECT_EQ(TW::derivationPath(TWCoinTypeSolana, TWDerivationDefault).string(), "m/44'/501'/0'"); - EXPECT_EQ(TW::derivationPath(TWCoinTypeSolana, TWDerivationSolana).string(), "m/44'/501'/0'/0'"); - EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeSolana, TWDerivationSolana)), "solana"); + EXPECT_EQ(TW::derivationPath(TWCoinTypeSolana, TWDerivationSolanaSolana).string(), "m/44'/501'/0'/0'"); + EXPECT_EQ(std::string(TW::derivationName(TWCoinTypeSolana, TWDerivationSolanaSolana)), "solana"); } } // namespace TW diff --git a/tests/common/Keystore/StoredKeyTests.cpp b/tests/common/Keystore/StoredKeyTests.cpp index 4c14244788b..ba189cfe5a1 100644 --- a/tests/common/Keystore/StoredKeyTests.cpp +++ b/tests/common/Keystore/StoredKeyTests.cpp @@ -243,7 +243,7 @@ TEST(StoredKey, AddRemoveAccountDerivation) { EXPECT_EQ(key.accounts.size(), 1ul); } { - key.addAccount("1NyRyFewhZcWMa9XCj3bBxSXPXyoSg8dKz", coinTypeBc, TWDerivationLegacy, derivationPath, "", "xpub6CR52eaUuVb4kXAVyHC2i5ZuqJ37oWNPZFtjXaazFPXZD45DwWBYEBLdrF7fmCR9pgBuCA9Q57zZfyJjDUBDNtWkhWuGHNYKLgDHpqrHsxV"); + key.addAccount("1NyRyFewhZcWMa9XCj3bBxSXPXyoSg8dKz", coinTypeBc, TWDerivationBitcoinLegacy, derivationPath, "", "xpub6CR52eaUuVb4kXAVyHC2i5ZuqJ37oWNPZFtjXaazFPXZD45DwWBYEBLdrF7fmCR9pgBuCA9Q57zZfyJjDUBDNtWkhWuGHNYKLgDHpqrHsxV"); EXPECT_EQ(key.accounts.size(), 2ul); } @@ -251,9 +251,9 @@ TEST(StoredKey, AddRemoveAccountDerivation) { EXPECT_EQ(key.accounts.size(), 1ul); key.removeAccount(coinTypeBc, TWDerivationDefault); // try 2nd time EXPECT_EQ(key.accounts.size(), 1ul); - key.removeAccount(coinTypeBc, TWDerivationLegacy); + key.removeAccount(coinTypeBc, TWDerivationBitcoinLegacy); EXPECT_EQ(key.accounts.size(), 0ul); - key.removeAccount(coinTypeBc, TWDerivationLegacy); // try 2nd time + key.removeAccount(coinTypeBc, TWDerivationBitcoinLegacy); // try 2nd time EXPECT_EQ(key.accounts.size(), 0ul); } @@ -627,7 +627,7 @@ TEST(StoredKey, CreateMultiAccounts) { // Multiple accounts for the same coin { // Create alternative P2PK Bitcoin account (different address format) const auto coin = TWCoinTypeBitcoin; - const auto btc2 = key.account(coin, TWDerivationLegacy, wallet); + const auto btc2 = key.account(coin, TWDerivationBitcoinLegacy, wallet); EXPECT_EQ(btc2.address, expectedBtc2); EXPECT_EQ(btc2.derivationPath.string(), "m/44'/0'/0'/0/0"); @@ -635,7 +635,7 @@ TEST(StoredKey, CreateMultiAccounts) { // Multiple accounts for the same coin EXPECT_EQ(key.accounts.size(), ++expectedAccounts); EXPECT_EQ(key.accounts[expectedAccounts - 1].address, expectedBtc2); EXPECT_EQ(key.account(coin)->address, expectedBtc1); - EXPECT_EQ(key.account(coin, TWDerivationLegacy, wallet).address, expectedBtc2); + EXPECT_EQ(key.account(coin, TWDerivationBitcoinLegacy, wallet).address, expectedBtc2); EXPECT_EQ(key.getAccounts(coin).size(), 2ul); EXPECT_EQ(key.getAccounts(coin)[0].address, expectedBtc1); EXPECT_EQ(key.getAccounts(coin)[1].address, expectedBtc2); @@ -643,7 +643,7 @@ TEST(StoredKey, CreateMultiAccounts) { // Multiple accounts for the same coin { // Create alternative Solana account with non-default derivation path (different derivation path and address) const auto coin = TWCoinTypeSolana; - const auto sol2 = key.account(coin, TWDerivationSolana, wallet); + const auto sol2 = key.account(coin, TWDerivationSolanaSolana, wallet); const auto expectedSol2 = "CgWJeEWkiYqosy1ba7a3wn9HAQuHyK48xs3LM4SSDc1C"; EXPECT_EQ(sol2.address, expectedSol2); @@ -652,7 +652,7 @@ TEST(StoredKey, CreateMultiAccounts) { // Multiple accounts for the same coin EXPECT_EQ(key.accounts[expectedAccounts - 1].address, expectedSol2); // Now we have 2 Solana addresses, 1st is returned here EXPECT_EQ(key.account(coin)->address, expectedSol1); - EXPECT_EQ(key.account(coin, TWDerivationSolana, wallet).address, expectedSol2); + EXPECT_EQ(key.account(coin, TWDerivationSolanaSolana, wallet).address, expectedSol2); EXPECT_EQ(key.getAccounts(coin).size(), 2ul); EXPECT_EQ(key.getAccounts(coin)[0].address, expectedSol1); EXPECT_EQ(key.getAccounts(coin)[1].address, expectedSol2); @@ -697,13 +697,13 @@ TEST(StoredKey, CreateWithMnemonicAlternativeDerivation) { ASSERT_EQ(key.accounts.size(), 1ul); // alternative derivation, different keys - EXPECT_EQ(hex(key.privateKey(coin, TWDerivationSolana, gPassword).bytes), "d49a5fa7f77593534c7afd2ba8dc8e9d8b007bc6ec65fe8df25ffe6fafc57151"); + EXPECT_EQ(hex(key.privateKey(coin, TWDerivationSolanaSolana, gPassword).bytes), "d49a5fa7f77593534c7afd2ba8dc8e9d8b007bc6ec65fe8df25ffe6fafc57151"); ASSERT_EQ(key.accounts.size(), 2ul); EXPECT_EQ(key.accounts[1].coin, coin); EXPECT_EQ(key.accounts[1].address, "CgWJeEWkiYqosy1ba7a3wn9HAQuHyK48xs3LM4SSDc1C"); EXPECT_EQ(key.accounts[1].publicKey, "ad8f57924dce62f9040f93b4f6ce3c3d39afde7e29bcb4013dad59db7913c4c7"); - EXPECT_EQ(hex(key.privateKey(coin, TWDerivationSolana, gPassword).bytes), "d49a5fa7f77593534c7afd2ba8dc8e9d8b007bc6ec65fe8df25ffe6fafc57151"); + EXPECT_EQ(hex(key.privateKey(coin, TWDerivationSolanaSolana, gPassword).bytes), "d49a5fa7f77593534c7afd2ba8dc8e9d8b007bc6ec65fe8df25ffe6fafc57151"); } } // namespace TW::Keystore diff --git a/tests/interface/TWAnyAddressTests.cpp b/tests/interface/TWAnyAddressTests.cpp index 8459c310095..1068efe40fb 100644 --- a/tests/interface/TWAnyAddressTests.cpp +++ b/tests/interface/TWAnyAddressTests.cpp @@ -191,11 +191,11 @@ TEST(TWAnyAddress, createFromPubKeyDerivation) { assertStringsEqual(WRAPS(TWAnyAddressDescription(addr.get())), "bc1qcj2vfjec3c3luf9fx9vddnglhh9gawmncmgxhz"); } { - const auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKeyDerivation(pubkey_obj.get(), TWCoinTypeBitcoin, TWDerivationLegacy)); + const auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKeyDerivation(pubkey_obj.get(), TWCoinTypeBitcoin, TWDerivationBitcoinLegacy)); assertStringsEqual(WRAPS(TWAnyAddressDescription(addr.get())), "1JvRfEQFv5q5qy9uTSAezH7kVQf4hqnHXx"); } { - const auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKeyDerivation(pubkey_obj.get(), TWCoinTypeBitcoin, TWDerivationTestnet)); + const auto addr = WRAP(TWAnyAddress, TWAnyAddressCreateWithPublicKeyDerivation(pubkey_obj.get(), TWCoinTypeBitcoin, TWDerivationBitcoinTestnet)); assertStringsEqual(WRAPS(TWAnyAddressDescription(addr.get())), "tb1qcj2vfjec3c3luf9fx9vddnglhh9gawmnjan4v3"); } } diff --git a/tests/interface/TWCoinTypeTests.cpp b/tests/interface/TWCoinTypeTests.cpp index d162b654cfb..b7547ae34a9 100644 --- a/tests/interface/TWCoinTypeTests.cpp +++ b/tests/interface/TWCoinTypeTests.cpp @@ -150,7 +150,7 @@ TEST(TWCoinType, DeriveAddress) { auto pkData = DATA("0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"); auto publicKey = WRAP(TWPublicKey, TWPublicKeyCreateWithData(pkData.get(), TWPublicKeyTypeSECP256k1)); - auto address = WRAPS(TWCoinTypeDeriveAddressFromPublicKeyAndDerivation(TWCoinTypeBitcoin, publicKey.get(), TWDerivationSegwit)); + auto address = WRAPS(TWCoinTypeDeriveAddressFromPublicKeyAndDerivation(TWCoinTypeBitcoin, publicKey.get(), TWDerivationBitcoinSegwit)); assertStringsEqual(address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"); } @@ -162,14 +162,14 @@ TEST(TWCoinType, TWCoinTypeDerivationPath) { } TEST(TWCoinType, TWCoinTypeDerivationPathWithDerivation) { - auto res = TWCoinTypeDerivationPathWithDerivation(TWCoinTypeBitcoin, TWDerivationLegacy); + auto res = TWCoinTypeDerivationPathWithDerivation(TWCoinTypeBitcoin, TWDerivationBitcoinLegacy); auto result = *reinterpret_cast(res); ASSERT_EQ(result, "m/44'/0'/0'/0/0"); TWStringDelete(res); } TEST(TWCoinType, TWCoinTypeDerivationPathWithDerivationSolana) { - auto res = TWCoinTypeDerivationPathWithDerivation(TWCoinTypeSolana, TWDerivationSolana); + auto res = TWCoinTypeDerivationPathWithDerivation(TWCoinTypeSolana, TWDerivationSolanaSolana); auto result = *reinterpret_cast(res); ASSERT_EQ(result, "m/44'/501'/0'/0'"); TWStringDelete(res); diff --git a/tests/interface/TWHDWalletTests.cpp b/tests/interface/TWHDWalletTests.cpp index 0cdfbd990a8..91d183be300 100644 --- a/tests/interface/TWHDWalletTests.cpp +++ b/tests/interface/TWHDWalletTests.cpp @@ -143,14 +143,14 @@ TEST(HDWallet, DeriveBitcoinExtended) { TEST(HDWallet, GetKeyDerivation) { auto wallet = WRAP(TWHDWallet, TWHDWalletCreateWithMnemonic(gWords.get(), gPassphrase.get())); { - auto key = WRAP(TWPrivateKey, TWHDWalletGetKeyDerivation(wallet.get(), TWCoinTypeBitcoin, TWDerivationSegwit)); + auto key = WRAP(TWPrivateKey, TWHDWalletGetKeyDerivation(wallet.get(), TWCoinTypeBitcoin, TWDerivationBitcoinSegwit)); assertHexEqual(WRAPD(TWPrivateKeyData(key.get())), "1901b5994f075af71397f65bd68a9fff8d3025d65f5a2c731cf90f5e259d6aac"); auto publicKey = WRAP(TWPublicKey, TWPrivateKeyGetPublicKeySecp256k1(key.get(), true)); auto publicKeyData = WRAPD(TWPublicKeyData(publicKey.get())); assertHexEqual(publicKeyData, "037ea5dff03f677502c4a1d73c5ac897200e56b155e876774c8fba0cc22f80b941"); } { - auto key = WRAP(TWPrivateKey, TWHDWalletGetKeyDerivation(wallet.get(), TWCoinTypeBitcoin, TWDerivationLegacy)); + auto key = WRAP(TWPrivateKey, TWHDWalletGetKeyDerivation(wallet.get(), TWCoinTypeBitcoin, TWDerivationBitcoinLegacy)); assertHexEqual(WRAPD(TWPrivateKeyData(key.get())), "28071bf4e2b0340db41b807ed8a5514139e5d6427ff9d58dbd22b7ed187103a4"); auto publicKey = WRAP(TWPublicKey, TWPrivateKeyGetPublicKeySecp256k1(key.get(), true)); auto publicKeyData = WRAPD(TWPublicKeyData(publicKey.get())); @@ -167,11 +167,11 @@ TEST(HDWallet, DeriveAddressBitcoin) { TEST(HDWallet, DeriveAddressBitcoinDerivation) { auto wallet = WRAP(TWHDWallet, TWHDWalletCreateWithMnemonic(gWords.get(), gPassphrase.get())); { - auto address = WRAP(TWString, TWHDWalletGetAddressDerivation(wallet.get(), TWCoinTypeBitcoin, TWDerivationSegwit)); + auto address = WRAP(TWString, TWHDWalletGetAddressDerivation(wallet.get(), TWCoinTypeBitcoin, TWDerivationBitcoinSegwit)); assertStringsEqual(address, "bc1qumwjg8danv2vm29lp5swdux4r60ezptzz7ce85"); } { - auto address = WRAP(TWString, TWHDWalletGetAddressDerivation(wallet.get(), TWCoinTypeBitcoin, TWDerivationLegacy)); + auto address = WRAP(TWString, TWHDWalletGetAddressDerivation(wallet.get(), TWCoinTypeBitcoin, TWDerivationBitcoinLegacy)); assertStringsEqual(address, "1PeUvjuxyf31aJKX6kCXuaqxhmG78ZUdL1"); } } @@ -364,14 +364,14 @@ TEST(HDWallet, ExtendedKeysCustomAccount) { auto words = STRING("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"); auto wallet = WRAP(TWHDWallet, TWHDWalletCreateWithMnemonic(words.get(), STRING("").get())); - auto zprv0 = WRAPS(TWHDWalletGetExtendedPrivateKeyAccount(wallet.get(), TWPurposeBIP84, TWCoinTypeBitcoin, TWDerivationSegwit, TWHDVersionZPRV, 0)); + auto zprv0 = WRAPS(TWHDWalletGetExtendedPrivateKeyAccount(wallet.get(), TWPurposeBIP84, TWCoinTypeBitcoin, TWDerivationBitcoinSegwit, TWHDVersionZPRV, 0)); assertStringsEqual(zprv0, "zprvAdG4iTXWBoARxkkzNpNh8r6Qag3irQB8PzEMkAFeTRXxHpbF9z4QgEvBRmfvqWvGp42t42nvgGpNgYSJA9iefm1yYNZKEm7z6qUWCroSQnE"); - auto zprv1 = WRAPS(TWHDWalletGetExtendedPrivateKeyAccount(wallet.get(), TWPurposeBIP84, TWCoinTypeBitcoin, TWDerivationSegwit, TWHDVersionZPRV, 1)); + auto zprv1 = WRAPS(TWHDWalletGetExtendedPrivateKeyAccount(wallet.get(), TWPurposeBIP84, TWCoinTypeBitcoin, TWDerivationBitcoinSegwit, TWHDVersionZPRV, 1)); assertStringsEqual(zprv1, "zprvAdG4iTXWBoAS2cCGuaGevCvH54GCunrvLJb2hoWCSuE3D9LS42XVg3c6sPm64w6VMq3w18vJf8nF3cBA2kUMkyWHsq6enWVXivzw42UrVHG"); - auto zpub0 = WRAPS(TWHDWalletGetExtendedPublicKeyAccount(wallet.get(), TWPurposeBIP84, TWCoinTypeBitcoin, TWDerivationSegwit, TWHDVersionZPUB, 0)); + auto zpub0 = WRAPS(TWHDWalletGetExtendedPublicKeyAccount(wallet.get(), TWPurposeBIP84, TWCoinTypeBitcoin, TWDerivationBitcoinSegwit, TWHDVersionZPUB, 0)); assertStringsEqual(zpub0, "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"); - auto zpub1 = WRAPS(TWHDWalletGetExtendedPublicKeyAccount(wallet.get(), TWPurposeBIP84, TWCoinTypeBitcoin, TWDerivationSegwit, TWHDVersionZPUB, 1)); + auto zpub1 = WRAPS(TWHDWalletGetExtendedPublicKeyAccount(wallet.get(), TWPurposeBIP84, TWCoinTypeBitcoin, TWDerivationBitcoinSegwit, TWHDVersionZPUB, 1)); assertStringsEqual(zpub1, "zpub6rFR7y4Q2AijF6Gk1bofHLs1d66hKFamhXWdWBup1Em25wfabZqkDqvaieV63fDQFaYmaatCG7jVNUpUiM2hAMo6SAVHcrUpSnHDpNzucB7"); } diff --git a/tests/interface/TWStoredKeyTests.cpp b/tests/interface/TWStoredKeyTests.cpp index 0adef9837c4..ac9bd0cc366 100644 --- a/tests/interface/TWStoredKeyTests.cpp +++ b/tests/interface/TWStoredKeyTests.cpp @@ -199,7 +199,7 @@ TEST(TWStoredKey, addressAddDerivation) { const auto accountAddress1 = WRAPS(TWAccountAddress(accountCoin1.get())); EXPECT_EQ(string(TWStringUTF8Bytes(accountAddress1.get())), "bc1qturc268v0f2srjh4r2zu4t6zk4gdutqd5a6zny"); - const auto accountCoin2 = WRAP(TWAccount, TWStoredKeyAccountForCoinDerivation(key.get(), coin, TWDerivationLegacy, wallet.get())); + const auto accountCoin2 = WRAP(TWAccount, TWStoredKeyAccountForCoinDerivation(key.get(), coin, TWDerivationBitcoinLegacy, wallet.get())); const auto accountAddress2 = WRAPS(TWAccountAddress(accountCoin2.get())); EXPECT_EQ(string(TWStringUTF8Bytes(accountAddress2.get())), "1NyRyFewhZcWMa9XCj3bBxSXPXyoSg8dKz"); diff --git a/wasm/tests/CoinType.test.ts b/wasm/tests/CoinType.test.ts index efaa02d6ba9..75a0bed0408 100644 --- a/wasm/tests/CoinType.test.ts +++ b/wasm/tests/CoinType.test.ts @@ -26,7 +26,7 @@ describe("CoinType", () => { assert.equal(CoinTypeExt.curve(CoinType.solana), Curve.ed25519); assert.isTrue(CoinTypeExt.validate(CoinType.solana, "Bxp8yhH9zNwxyE4UqxP7a7hgJ5xTZfxNNft7YJJ2VRjT")) assert.equal(CoinTypeExt.derivationPath(CoinType.solana), "m/44'/501'/0'"); - assert.equal(CoinTypeExt.derivationPathWithDerivation(CoinType.solana, Derivation.solana), "m/44'/501'/0'/0'"); + assert.equal(CoinTypeExt.derivationPathWithDerivation(CoinType.solana, Derivation.solanaSolana), "m/44'/501'/0'/0'"); }); it("test deriveAddress", () => { @@ -52,7 +52,7 @@ describe("CoinType", () => { const data = HexCoding.decode("0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"); const key = PublicKey.createWithData(data, PublicKeyType.secp256k1); - const addr = CoinTypeExt.deriveAddressFromPublicKeyAndDerivation(CoinType.bitcoin, key, Derivation.segwit); + const addr = CoinTypeExt.deriveAddressFromPublicKeyAndDerivation(CoinType.bitcoin, key, Derivation.bitcoinSegwit); assert.equal(addr, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"); }); });