22//
33// Copyright © 2017 Trust Wallet.
44
5- #include " Ethereum/EIP2645.h"
65#include " HexCoding.h"
76#include " ImmutableX/Constants.h"
87#include " ImmutableX/StarkKey.h"
98#include < gtest/gtest.h>
9+ #include < TrustWalletCore/TWEthereum.h>
10+ #include " TestUtilities.h"
1011
1112namespace TW ::ImmutableX::tests {
1213
1314TEST (ImmutableX, PathFromAddress) {
1415 // https://github.com/immutable/imx-core-sdk-swift/blob/main/Tests/ImmutableXCoreTests/Crypto/Stark/StarkKeyTests.swift#L30
15- auto res = Ethereum::accountPathFromAddress ( " 0xa76e3eeb2f7143165618ab8feaabcd395b6fac7f" , internal::gLayer , internal::gApplication , internal::gIndex );
16- ASSERT_EQ (res, " m/2645'/579218131'/211006541'/1534045311'/1431804530'/1" );
16+ const auto & res = WRAPS ( TWEthereumEip2645GetPath ( STRING ( " 0xa76e3eeb2f7143165618ab8feaabcd395b6fac7f" ). get (), STRING ( internal::gLayer ). get (), STRING ( internal::gApplication ). get (), STRING ( internal::gIndex ). get ()) );
17+ assertStringsEqual (res, " m/2645'/579218131'/211006541'/1534045311'/1431804530'/1" );
1718}
1819
1920TEST (ImmutableX, ExtraGrinding) {
2021 using namespace internal ;
2122 std::string signature = " 0x6d1550458c7a9a1257d73adbcf0fabc12f4497e970d9fa62dd88bf7d9e12719148c96225c1402d8707fd061b1aae2222bdf13571dfc82b3aa9974039f247f2b81b" ;
2223 std::string address = " 0xa4864d977b944315389d1765ffa7e66F74ee8cd7" ;
2324 auto data = parse_hex (signature);
24- auto path = DerivationPath (Ethereum::accountPathFromAddress (address, gLayer , gApplication , gIndex ));
25+ const auto & res = WRAPS (TWEthereumEip2645GetPath (STRING (address.c_str ()).get (), STRING (internal::gLayer ).get (), STRING (internal::gApplication ).get (), STRING (internal::gIndex ).get ()));
26+ auto path = DerivationPath (TWStringUTF8Bytes (res.get ()));
2527 auto privKey = ImmutableX::getPrivateKeyFromRawSignature (parse_hex (signature), path);
2628 auto pubKey = privKey.getPublicKey (TWPublicKeyTypeStarkex);
2729 ASSERT_EQ (hexEncoded (pubKey.bytes ), " 0x035919acd61e97b3ecdc75ff8beed8d1803f7ea3cad2937926ae59cc3f8070d4" );
@@ -46,7 +48,8 @@ TEST(ImmutableX, GetPrivateKeyFromSignature) {
4648 using namespace internal ;
4749 std::string address = " 0xa76e3eeb2f7143165618ab8feaabcd395b6fac7f" ;
4850 std::string signature = " 0x5a263fad6f17f23e7c7ea833d058f3656d3fe464baf13f6f5ccba9a2466ba2ce4c4a250231bcac7beb165aec4c9b049b4ba40ad8dd287dc79b92b1ffcf20cdcf1b" ;
49- auto path = DerivationPath (Ethereum::accountPathFromAddress (address, gLayer , gApplication , gIndex ));
51+ const auto & res = WRAPS (TWEthereumEip2645GetPath (STRING (address.c_str ()).get (), STRING (internal::gLayer ).get (), STRING (internal::gApplication ).get (), STRING (internal::gIndex ).get ()));
52+ auto path = DerivationPath (TWStringUTF8Bytes (res.get ()));
5053 auto privKey = ImmutableX::getPrivateKeyFromRawSignature (parse_hex (signature), path);
5154 ASSERT_EQ (hex (privKey.bytes ), " 058ab7989d625b1a690400dcbe6e070627adedceff7bd196e58d4791026a8afe" );
5255 ASSERT_TRUE (PrivateKey::isValid (privKey.bytes ));
0 commit comments