From 72957fe3ddf6bccfba17761af5fccbd4ac841089 Mon Sep 17 00:00:00 2001 From: brave-builds Date: Thu, 14 Oct 2021 15:38:19 +0000 Subject: [PATCH] Uplift of #10447 (squashed) to beta --- browser/decentralized_dns/test/BUILD.gn | 1 + ...centralized_dns_network_delegate_helper.cc | 64 ++--- ...ecentralized_dns_network_delegate_helper.h | 7 +- ...ed_dns_network_delegate_helper_unittest.cc | 188 ++++---------- .../browser/brave_wallet_constants.h | 3 + .../browser/brave_wallet_utils.cc | 30 +++ .../brave_wallet/browser/brave_wallet_utils.h | 4 + .../brave_wallet/browser/eth_data_builder.cc | 31 ++- .../brave_wallet/browser/eth_data_builder.h | 10 +- .../browser/eth_data_builder_unittest.cc | 43 ++++ .../browser/eth_json_rpc_controller.cc | 233 ++++++++++++++--- .../browser/eth_json_rpc_controller.h | 65 ++++- .../eth_json_rpc_controller_unittest.cc | 239 ++++++++++++++---- .../browser/eth_response_parser.cc | 57 +++++ .../browser/eth_response_parser.h | 13 +- .../browser/eth_response_parser_unittest.cc | 121 +++++++++ components/brave_wallet/browser/test/BUILD.gn | 1 + .../brave_wallet/common/brave_wallet.mojom | 4 +- components/brave_wallet_ui/constants/types.ts | 7 + components/decentralized_dns/constants.h | 6 - 20 files changed, 811 insertions(+), 316 deletions(-) diff --git a/browser/decentralized_dns/test/BUILD.gn b/browser/decentralized_dns/test/BUILD.gn index 407173be7124..4ed79c858431 100644 --- a/browser/decentralized_dns/test/BUILD.gn +++ b/browser/decentralized_dns/test/BUILD.gn @@ -44,6 +44,7 @@ source_set("unit_tests") { "//base", "//base/test:test_support", "//brave/browser/net", + "//brave/components/brave_wallet/browser", "//brave/components/decentralized_dns", "//brave/components/tor/buildflags", "//chrome/test:test_support", diff --git a/browser/net/decentralized_dns_network_delegate_helper.cc b/browser/net/decentralized_dns_network_delegate_helper.cc index ce2506ba5354..6fe4445ee19e 100644 --- a/browser/net/decentralized_dns_network_delegate_helper.cc +++ b/browser/net/decentralized_dns_network_delegate_helper.cc @@ -9,8 +9,6 @@ #include #include "brave/browser/brave_wallet/rpc_controller_factory.h" -#include "brave/components/brave_wallet/browser/brave_wallet_utils.h" -#include "brave/components/brave_wallet/browser/eth_data_builder.h" #include "brave/components/brave_wallet/browser/eth_json_rpc_controller.h" #include "brave/components/brave_wallet/common/brave_wallet.mojom.h" #include "brave/components/decentralized_dns/constants.h" @@ -38,12 +36,9 @@ int OnBeforeURLRequest_DecentralizedDnsPreRedirectWork( return net::OK; } - auto pending = - brave_wallet::RpcControllerFactory::GetForContext(ctx->browser_context); - - mojo::Remote rpc_controller; - rpc_controller.Bind(std::move(pending)); - + auto* rpc_controller = + brave_wallet::RpcControllerFactory::GetControllerForContext( + ctx->browser_context); if (!rpc_controller) return net::OK; @@ -52,14 +47,9 @@ int OnBeforeURLRequest_DecentralizedDnsPreRedirectWork( g_browser_process->local_state())) { auto keys = std::vector(std::begin(kRecordKeys), std::end(kRecordKeys)); - std::string data; - if (!brave_wallet::unstoppable_domains::GetMany( - keys, ctx->request_url.host(), &data)) - return net::OK; - rpc_controller->UnstoppableDomainsProxyReaderGetMany( - kProxyReaderContractAddress, ctx->request_url.host(), keys, - base::BindOnce(&OnBeforeURLRequest_DecentralizedDnsRedirectWork, + brave_wallet::mojom::kMainnetChainId, ctx->request_url.host(), keys, + base::BindOnce(&OnBeforeURLRequest_UnstoppableDomainsRedirectWork, next_callback, ctx)); return net::ERR_IO_PENDING; @@ -67,12 +57,8 @@ int OnBeforeURLRequest_DecentralizedDnsPreRedirectWork( if (IsENSTLD(ctx->request_url) && IsENSResolveMethodEthereum(g_browser_process->local_state())) { - std::string data; - if (!brave_wallet::ens::GetResolverAddress(ctx->request_url.host(), &data)) - return net::OK; - - rpc_controller->EnsProxyReaderGetResolverAddress( - kEnsRegistryContractAddress, ctx->request_url.host(), + rpc_controller->EnsResolverGetContentHash( + brave_wallet::mojom::kMainnetChainId, ctx->request_url.host(), base::BindOnce(&OnBeforeURLRequest_EnsRedirectWork, next_callback, ctx)); @@ -86,22 +72,14 @@ void OnBeforeURLRequest_EnsRedirectWork( const brave::ResponseCallback& next_callback, std::shared_ptr ctx, bool success, - const std::string& result) { + const std::string& content_hash) { if (!success) { if (!next_callback.is_null()) next_callback.Run(); return; } - size_t offset = 2 /* len of "0x" */ + 64 /* len of offset to array */; - std::string contenthash; - if (offset > result.size() || - !brave_wallet::DecodeString(offset, result, &contenthash)) { - if (!next_callback.is_null()) - next_callback.Run(); - return; - } - GURL ipfs_uri = ipfs::ContentHashToCIDv1URL(contenthash); + GURL ipfs_uri = ipfs::ContentHashToCIDv1URL(content_hash); if (ipfs_uri.is_valid()) { ctx->new_url_spec = ipfs_uri.spec(); } @@ -110,21 +88,13 @@ void OnBeforeURLRequest_EnsRedirectWork( next_callback.Run(); } -void OnBeforeURLRequest_DecentralizedDnsRedirectWork( +void OnBeforeURLRequest_UnstoppableDomainsRedirectWork( const brave::ResponseCallback& next_callback, std::shared_ptr ctx, bool success, - const std::string& result) { - if (!success) { - if (!next_callback.is_null()) - next_callback.Run(); - return; - } - - std::vector output; - size_t offset = 2 /* len of "0x" */ + 64 /* len of offset to array */; - if (offset > result.size() || - !brave_wallet::DecodeStringArray(result.substr(offset), &output)) { + const std::vector& values) { + if (!success || + values.size() != static_cast(RecordKeys::MAX_RECORD_KEY) + 1) { if (!next_callback.is_null()) next_callback.Run(); return; @@ -137,14 +107,14 @@ void OnBeforeURLRequest_DecentralizedDnsRedirectWork( // // TODO(jocelyn): Do not fallback to the set redirect URL if dns.A or // dns.AAAA is not empty once we support the classical DNS records case. - std::string ipfs_uri = GetValue(output, RecordKeys::DWEB_IPFS_HASH); + std::string ipfs_uri = GetValue(values, RecordKeys::DWEB_IPFS_HASH); if (ipfs_uri.empty()) { // Try legacy value. - ipfs_uri = GetValue(output, RecordKeys::IPFS_HTML_VALUE); + ipfs_uri = GetValue(values, RecordKeys::IPFS_HTML_VALUE); } - std::string fallback_url = GetValue(output, RecordKeys::BROWSER_REDIRECT_URL); + std::string fallback_url = GetValue(values, RecordKeys::BROWSER_REDIRECT_URL); if (fallback_url.empty()) { // Try legacy value. - fallback_url = GetValue(output, RecordKeys::IPFS_REDIRECT_DOMAIN_VALUE); + fallback_url = GetValue(values, RecordKeys::IPFS_REDIRECT_DOMAIN_VALUE); } if (!ipfs_uri.empty()) { diff --git a/browser/net/decentralized_dns_network_delegate_helper.h b/browser/net/decentralized_dns_network_delegate_helper.h index bc2c78feba93..bb801f3f01f4 100644 --- a/browser/net/decentralized_dns_network_delegate_helper.h +++ b/browser/net/decentralized_dns_network_delegate_helper.h @@ -8,6 +8,7 @@ #include #include +#include #include "brave/browser/net/url_context.h" #include "net/base/completion_once_callback.h" @@ -20,17 +21,17 @@ int OnBeforeURLRequest_DecentralizedDnsPreRedirectWork( const brave::ResponseCallback& next_callback, std::shared_ptr ctx); -void OnBeforeURLRequest_DecentralizedDnsRedirectWork( +void OnBeforeURLRequest_UnstoppableDomainsRedirectWork( const brave::ResponseCallback& next_callback, std::shared_ptr ctx, bool success, - const std::string& result); + const std::vector& values); void OnBeforeURLRequest_EnsRedirectWork( const brave::ResponseCallback& next_callback, std::shared_ptr ctx, bool success, - const std::string& ipfs_uri); + const std::string& content_hash); } // namespace decentralized_dns diff --git a/browser/net/decentralized_dns_network_delegate_helper_unittest.cc b/browser/net/decentralized_dns_network_delegate_helper_unittest.cc index ca7de9b391cb..7600dfb6d5ea 100644 --- a/browser/net/decentralized_dns_network_delegate_helper_unittest.cc +++ b/browser/net/decentralized_dns_network_delegate_helper_unittest.cc @@ -9,6 +9,7 @@ #include "base/test/scoped_feature_list.h" #include "brave/browser/net/url_context.h" +#include "brave/components/brave_wallet/browser/brave_wallet_utils.h" #include "brave/components/decentralized_dns/constants.h" #include "brave/components/decentralized_dns/features.h" #include "brave/components/decentralized_dns/pref_names.h" @@ -111,164 +112,56 @@ TEST_F(DecentralizedDnsNetworkDelegateHelperTest, } TEST_F(DecentralizedDnsNetworkDelegateHelperTest, - DecentralizedDnsRedirectWork) { + UnstoppableDomainsRedirectWork) { GURL url("http://brave.crypto"); auto brave_request_info = std::make_shared(url); // No redirect for failed requests. - OnBeforeURLRequest_DecentralizedDnsRedirectWork( - ResponseCallback(), brave_request_info, false, ""); + OnBeforeURLRequest_UnstoppableDomainsRedirectWork(ResponseCallback(), + brave_request_info, false, + std::vector()); EXPECT_TRUE(brave_request_info->new_url_spec.empty()); - OnBeforeURLRequest_DecentralizedDnsRedirectWork(ResponseCallback(), - brave_request_info, true, ""); + OnBeforeURLRequest_UnstoppableDomainsRedirectWork( + ResponseCallback(), brave_request_info, true, std::vector()); EXPECT_TRUE(brave_request_info->new_url_spec.empty()); // Has both IPFS URI & fallback URL. - std::string result = - // offset for array - "0x0000000000000000000000000000000000000000000000000000000000000020" - // count for array - "0000000000000000000000000000000000000000000000000000000000000006" - // offsets for array elements - "00000000000000000000000000000000000000000000000000000000000000c0" - "0000000000000000000000000000000000000000000000000000000000000120" - "0000000000000000000000000000000000000000000000000000000000000180" - "00000000000000000000000000000000000000000000000000000000000001a0" - "00000000000000000000000000000000000000000000000000000000000001c0" - "0000000000000000000000000000000000000000000000000000000000000200" - // count for "QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka" - "000000000000000000000000000000000000000000000000000000000000002e" - // encoding for "QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka" - "516d5772644e4a574d62765278787a4c686f6a564b614244737753344b4e564d" - "374c766a734e3751624472766b61000000000000000000000000000000000000" - // count for "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" - "000000000000000000000000000000000000000000000000000000000000002e" - // encoding for "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" - "516d6257717842454b433350387471734b633938786d574e7a727a4474524c4d" - "694d504c387742755447734d6e52000000000000000000000000000000000000" - // count for empty dns.A - "0000000000000000000000000000000000000000000000000000000000000000" - // count for empty dns.AAAA - "0000000000000000000000000000000000000000000000000000000000000000" - // count for "https://fallback1.test.com" - "000000000000000000000000000000000000000000000000000000000000001a" - // encoding for "https://fallback1.test.com" - "68747470733a2f2f66616c6c6261636b312e746573742e636f6d000000000000" - // count for "https://fallback2.test.com" - "000000000000000000000000000000000000000000000000000000000000001a" - // encoding for "https://fallback2.test.com" - "68747470733a2f2f66616c6c6261636b322e746573742e636f6d000000000000"; - - OnBeforeURLRequest_DecentralizedDnsRedirectWork( + std::vector result = { + "QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka", // dweb.ipfs.hash + "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR", // ipfs.html.value + "", // dns.A + "", // dns.AAAA + "https://fallback1.test.com", // browser.redirect_url + "https://fallback2.test.com", // ipfs.redirect_domain.value + }; + OnBeforeURLRequest_UnstoppableDomainsRedirectWork( ResponseCallback(), brave_request_info, true, result); EXPECT_EQ("ipfs://QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka", brave_request_info->new_url_spec); // Has legacy IPFS URI & fallback URL - result = - // offset for array - "0x0000000000000000000000000000000000000000000000000000000000000020" - // count for array - "0000000000000000000000000000000000000000000000000000000000000006" - // offsets for array elements - "00000000000000000000000000000000000000000000000000000000000000c0" - "00000000000000000000000000000000000000000000000000000000000000e0" - "0000000000000000000000000000000000000000000000000000000000000140" - "0000000000000000000000000000000000000000000000000000000000000160" - "0000000000000000000000000000000000000000000000000000000000000180" - "00000000000000000000000000000000000000000000000000000000000001c0" - // count for empty dweb.ipfs.hash - "0000000000000000000000000000000000000000000000000000000000000000" - // count for "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" - "000000000000000000000000000000000000000000000000000000000000002e" - // encoding for "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" - "516d6257717842454b433350387471734b633938786d574e7a727a4474524c4d" - "694d504c387742755447734d6e52000000000000000000000000000000000000" - // count for empty dns.A - "0000000000000000000000000000000000000000000000000000000000000000" - // count for empty dns.AAAA - "0000000000000000000000000000000000000000000000000000000000000000" - // count for "https://fallback1.test.com" - "000000000000000000000000000000000000000000000000000000000000001a" - // encoding for "https://fallback1.test.com" - "68747470733a2f2f66616c6c6261636b312e746573742e636f6d000000000000" - // count for "https://fallback2.test.com" - "000000000000000000000000000000000000000000000000000000000000001a" - // encoding for "https://fallback2.test.com" - "68747470733a2f2f66616c6c6261636b322e746573742e636f6d000000000000"; - OnBeforeURLRequest_DecentralizedDnsRedirectWork( + result[static_cast(RecordKeys::DWEB_IPFS_HASH)] = ""; + OnBeforeURLRequest_UnstoppableDomainsRedirectWork( ResponseCallback(), brave_request_info, true, result); EXPECT_EQ("ipfs://QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR", brave_request_info->new_url_spec); // Has both fallback URL - result = - // offset for array - "0x0000000000000000000000000000000000000000000000000000000000000020" - // count for array - "0000000000000000000000000000000000000000000000000000000000000006" - // offsets for array elements - "00000000000000000000000000000000000000000000000000000000000000c0" - "00000000000000000000000000000000000000000000000000000000000000e0" - "0000000000000000000000000000000000000000000000000000000000000100" - "0000000000000000000000000000000000000000000000000000000000000120" - "0000000000000000000000000000000000000000000000000000000000000140" - "0000000000000000000000000000000000000000000000000000000000000180" - // count for empty dweb.ipfs.hash - "0000000000000000000000000000000000000000000000000000000000000000" - // count for empty ipfs.html.value - "0000000000000000000000000000000000000000000000000000000000000000" - // count for empty dns.A - "0000000000000000000000000000000000000000000000000000000000000000" - // count for empty dns.AAAA - "0000000000000000000000000000000000000000000000000000000000000000" - // count for "https://fallback1.test.com" - "000000000000000000000000000000000000000000000000000000000000001a" - // encoding for "https://fallback1.test.com" - "68747470733a2f2f66616c6c6261636b312e746573742e636f6d000000000000" - // count for "https://fallback2.test.com" - "000000000000000000000000000000000000000000000000000000000000001a" - // encoding for "https://fallback2.test.com" - "68747470733a2f2f66616c6c6261636b322e746573742e636f6d000000000000"; - OnBeforeURLRequest_DecentralizedDnsRedirectWork( + result[static_cast(RecordKeys::IPFS_HTML_VALUE)] = ""; + OnBeforeURLRequest_UnstoppableDomainsRedirectWork( ResponseCallback(), brave_request_info, true, result); EXPECT_EQ("https://fallback1.test.com/", brave_request_info->new_url_spec); // Has legacy URL - result = - // offset for array - "0x0000000000000000000000000000000000000000000000000000000000000020" - // count for array - "0000000000000000000000000000000000000000000000000000000000000006" - // offsets for array elements - "00000000000000000000000000000000000000000000000000000000000000c0" - "00000000000000000000000000000000000000000000000000000000000000e0" - "0000000000000000000000000000000000000000000000000000000000000100" - "0000000000000000000000000000000000000000000000000000000000000120" - "0000000000000000000000000000000000000000000000000000000000000140" - "0000000000000000000000000000000000000000000000000000000000000160" - // count for empty dweb.ipfs.hash - "0000000000000000000000000000000000000000000000000000000000000000" - // count for empty ipfs.html.value - "0000000000000000000000000000000000000000000000000000000000000000" - // count for empty dns.A - "0000000000000000000000000000000000000000000000000000000000000000" - // count for empty dns.AAAA - "0000000000000000000000000000000000000000000000000000000000000000" - // count for empty browser.redirect_url - "0000000000000000000000000000000000000000000000000000000000000000" - // count for "https://fallback2.test.com" - "000000000000000000000000000000000000000000000000000000000000001a" - // encoding for "https://fallback2.test.com" - "68747470733a2f2f66616c6c6261636b322e746573742e636f6d000000000000"; - OnBeforeURLRequest_DecentralizedDnsRedirectWork( + result[static_cast(RecordKeys::BROWSER_REDIRECT_URL)] = ""; + OnBeforeURLRequest_UnstoppableDomainsRedirectWork( ResponseCallback(), brave_request_info, true, result); EXPECT_EQ("https://fallback2.test.com/", brave_request_info->new_url_spec); } TEST_F(DecentralizedDnsNetworkDelegateHelperTest, EnsRedirectWork) { - GURL url("http://brave.eth"); + GURL url("http://brantly.eth"); auto brave_request_info = std::make_shared(url); // No redirect for failed requests. @@ -279,27 +172,36 @@ TEST_F(DecentralizedDnsNetworkDelegateHelperTest, EnsRedirectWork) { OnBeforeURLRequest_EnsRedirectWork(ResponseCallback(), brave_request_info, true, ""); EXPECT_TRUE(brave_request_info->new_url_spec.empty()); - std::string hash = - "0x0000000000000000000000000000000000000000000000000000000000000020" - "0000000000000000000000000000000000000000000000000000000000000026e7" - "0101701220f073be187e8e06039796c432a5bdd6da3f403c2f93fa5d9dbdc5547c" - "7fe0e3bc0000000000000000000000000000000000000000000000000000"; + // No redirect for invalid content hash. + std::string content_hash_encoded_string = + "0x0000000000000000000000000000000000000000000000000000000000000020000000" + "000000000000000000000000000000000000000000000000000000002655010170122023" + "e0160eec32d7875c19c5ac7c03bc1f306dc260080d621454bc5f631e7310a70000000000" + "000000000000000000000000000000000000000000"; + + std::string content_hash; + EXPECT_TRUE(brave_wallet::DecodeString(66, content_hash_encoded_string, + &content_hash)); OnBeforeURLRequest_EnsRedirectWork(ResponseCallback(), brave_request_info, - true, hash); + true, content_hash); EXPECT_TRUE(brave_request_info->new_url_spec.empty()); - hash = - "0x0000000000000000000000000000000000000000000000000000000000000020" - "0000000000000000000000000000000000000000000000000000000000000026e5" - "0101701220f073be187e8e06039796c432a5bdd6da3f403c2f93fa5d9dbdc5547c" - "7fe0e3bc0000000000000000000000000000000000000000000000000000"; + // Redirect for valid content hash. + content_hash_encoded_string = + "0x0000000000000000000000000000000000000000000000000000000000000020000000" + "0000000000000000000000000000000000000000000000000000000026e3010170122023" + "e0160eec32d7875c19c5ac7c03bc1f306dc260080d621454bc5f631e7310a70000000000" + "000000000000000000000000000000000000000000"; + content_hash = ""; + EXPECT_TRUE(brave_wallet::DecodeString(66, content_hash_encoded_string, + &content_hash)); OnBeforeURLRequest_EnsRedirectWork(ResponseCallback(), brave_request_info, - true, hash); + true, content_hash); EXPECT_EQ( brave_request_info->new_url_spec, - "ipns://bafybeihqoo7bq7uoaybzpfwegks33vw2h5adyl4t7joz3pofkr6h7yhdxq"); + "ipfs://bafybeibd4ala53bs26dvygofvr6ahpa7gbw4eyaibvrbivf4l5rr44yqu4"); } } // namespace decentralized_dns diff --git a/components/brave_wallet/browser/brave_wallet_constants.h b/components/brave_wallet/browser/brave_wallet_constants.h index ef3479deeadb..58af5f52bcd1 100644 --- a/components/brave_wallet/browser/brave_wallet_constants.h +++ b/components/brave_wallet/browser/brave_wallet_constants.h @@ -434,6 +434,9 @@ const char kSwapBaseAPIURL[] = "https://api.0x.org/"; const char kBuyTokenPercentageFee[] = "0.00875"; const char kFeeRecipient[] = "0xbd9420A98a7Bd6B89765e5715e169481602D9c3d"; +// Unstoppable domains record key for ethereum address. +constexpr char kCryptoEthAddressKey[] = "crypto.ETH.address"; + } // namespace brave_wallet #endif // BRAVE_COMPONENTS_BRAVE_WALLET_BROWSER_BRAVE_WALLET_CONSTANTS_H_ diff --git a/components/brave_wallet/browser/brave_wallet_utils.cc b/components/brave_wallet/browser/brave_wallet_utils.cc index 7c0724bc8804..8511f1927b33 100644 --- a/components/brave_wallet/browser/brave_wallet_utils.cc +++ b/components/brave_wallet/browser/brave_wallet_utils.cc @@ -141,6 +141,23 @@ const base::flat_map kInfuraSubdomains = { {brave_wallet::mojom::kGoerliChainId, "goerli"}, {brave_wallet::mojom::kKovanChainId, "kovan"}}; +const base::flat_map + kUnstoppableDomainsProxyReaderContractAddressMap = { + {brave_wallet::mojom::kMainnetChainId, + "0xa6E7cEf2EDDEA66352Fd68E5915b60BDbb7309f5"}, + {brave_wallet::mojom::kRinkebyChainId, + "0x3A2e74CF832cbA3d77E72708d55370119E4323a6"}}; + +const base::flat_map kEnsRegistryContractAddressMap = + {{brave_wallet::mojom::kMainnetChainId, + "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"}, + {brave_wallet::mojom::kRopstenChainId, + "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"}, + {brave_wallet::mojom::kRinkebyChainId, + "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"}, + {brave_wallet::mojom::kGoerliChainId, + "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"}}; + std::string GetInfuraURLForKnownChainId(const std::string& chain_id) { auto subdomain = brave_wallet::GetInfuraSubdomainForKnownChainId(chain_id); if (subdomain.empty()) @@ -782,4 +799,17 @@ void SetDefaultWallet(PrefService* prefs, mojom::DefaultWallet default_wallet) { prefs->SetInteger(kBraveWalletWeb3Provider, static_cast(default_wallet)); } +std::string GetUnstoppableDomainsProxyReaderContractAddress( + const std::string& chain_id) { + if (kUnstoppableDomainsProxyReaderContractAddressMap.contains(chain_id)) + return kUnstoppableDomainsProxyReaderContractAddressMap.at(chain_id); + return ""; +} + +std::string GetEnsRegistryContractAddress(const std::string& chain_id) { + if (kEnsRegistryContractAddressMap.contains(chain_id)) + return kEnsRegistryContractAddressMap.at(chain_id); + return ""; +} + } // namespace brave_wallet diff --git a/components/brave_wallet/browser/brave_wallet_utils.h b/components/brave_wallet/browser/brave_wallet_utils.h index c7d3cc31eb85..74f7e15cbbff 100644 --- a/components/brave_wallet/browser/brave_wallet_utils.h +++ b/components/brave_wallet/browser/brave_wallet_utils.h @@ -115,6 +115,10 @@ mojom::DefaultWallet GetDefaultWallet(PrefService* prefs); std::vector GetAllKnownNetworkIds(); std::string GetKnownNetworkId(const std::string& chain_id); +std::string GetUnstoppableDomainsProxyReaderContractAddress( + const std::string& chain_id); +std::string GetEnsRegistryContractAddress(const std::string& chain_id); + } // namespace brave_wallet #endif // BRAVE_COMPONENTS_BRAVE_WALLET_BROWSER_BRAVE_WALLET_UTILS_H_ diff --git a/components/brave_wallet/browser/eth_data_builder.cc b/components/brave_wallet/browser/eth_data_builder.cc index 2951cd3b7de6..643c65ecac1e 100644 --- a/components/brave_wallet/browser/eth_data_builder.cc +++ b/components/brave_wallet/browser/eth_data_builder.cc @@ -107,24 +107,51 @@ bool GetMany(const std::vector& keys, return true; } +bool Get(const std::string& key, const std::string& domain, std::string* data) { + const std::string function_hash = GetFunctionHash("get(string,uint256)"); + + std::string offset_for_key; + if (!PadHexEncodedParameter(Uint256ValueToHex(64), &offset_for_key)) { + return false; + } + + std::string tokenID = Namehash(domain); + + std::string encoded_key; + if (!EncodeString(key, &encoded_key)) { + return false; + } + + std::vector hex_strings = {function_hash, offset_for_key, + tokenID, encoded_key}; + return ConcatHexStrings(hex_strings, data); +} + } // namespace unstoppable_domains namespace ens { -bool GetResolverAddress(const std::string& domain, std::string* data) { +bool Resolver(const std::string& domain, std::string* data) { const std::string function_hash = GetFunctionHash("resolver(bytes32)"); std::string tokenID = Namehash(domain); std::vector hex_strings = {function_hash, tokenID}; return ConcatHexStrings(hex_strings, data); } -bool GetContentHashAddress(const std::string& domain, std::string* data) { +bool ContentHash(const std::string& domain, std::string* data) { const std::string function_hash = GetFunctionHash("contenthash(bytes32)"); std::string tokenID = Namehash(domain); std::vector hex_strings = {function_hash, tokenID}; return ConcatHexStrings(hex_strings, data); } +bool Addr(const std::string& domain, std::string* data) { + const std::string function_hash = GetFunctionHash("addr(bytes32)"); + std::string tokenID = Namehash(domain); + std::vector hex_strings = {function_hash, tokenID}; + return ConcatHexStrings(hex_strings, data); +} + } // namespace ens } // namespace brave_wallet diff --git a/components/brave_wallet/browser/eth_data_builder.h b/components/brave_wallet/browser/eth_data_builder.h index 9513e939e28e..411aa7df2161 100644 --- a/components/brave_wallet/browser/eth_data_builder.h +++ b/components/brave_wallet/browser/eth_data_builder.h @@ -38,12 +38,18 @@ bool GetMany(const std::vector& keys, const std::string& domain, std::string* data); +// Get the value of the key for the target domain. +bool Get(const std::string& key, const std::string& domain, std::string* data); + } // namespace unstoppable_domains namespace ens { -bool GetResolverAddress(const std::string& domain, std::string* data); -bool GetContentHashAddress(const std::string& domain, std::string* data); +bool Resolver(const std::string& domain, std::string* data); +bool ContentHash(const std::string& domain, std::string* data); + +// Get Ethereum address from an ENS name. +bool Addr(const std::string& domain, std::string* data); } // namespace ens diff --git a/components/brave_wallet/browser/eth_data_builder_unittest.cc b/components/brave_wallet/browser/eth_data_builder_unittest.cc index 34f6dd842248..9496b388f0f0 100644 --- a/components/brave_wallet/browser/eth_data_builder_unittest.cc +++ b/components/brave_wallet/browser/eth_data_builder_unittest.cc @@ -106,6 +106,49 @@ TEST(EthCallDataBuilderTest, GetMany) { "697066732e72656469726563745f646f6d61696e2e76616c7565000000000000"); } +TEST(EthCallDataBuilderTest, Get) { + std::string data; + EXPECT_TRUE(Get("crypto.ETH.address", "brave.crypto", &data)); + EXPECT_EQ(data, + "0x1be5e7ed" + "0000000000000000000000000000000000000000000000000000000000000040" + // Name hash of brave.crypto. + "77252571a99feee8f5e6b2f0c8b705407d395adc00b3c8ebcc7c19b2ea850013" + // Count of "crypto.ETH.address" + "0000000000000000000000000000000000000000000000000000000000000012" + // Encoding of "crypto.ETH.address" + "63727970746f2e4554482e616464726573730000000000000000000000000000"); +} + } // namespace unstoppable_domains +namespace ens { + +TEST(EthCallDataBuilderTest, Resolver) { + std::string data; + EXPECT_TRUE(Resolver("brantly.eth", &data)); + EXPECT_EQ(data, + "0x0178b8bf" + // Name hash of brantly.eth. + "43fcd34d8589090581e1d2bdcf5dc17feb05b2006401fb1c3fdded335a465b51"); +} + +TEST(EthCallDataBuilderTest, ContentHash) { + std::string data; + EXPECT_TRUE(ContentHash("brantly.eth", &data)); + EXPECT_EQ(data, + "0xbc1c58d1" + "43fcd34d8589090581e1d2bdcf5dc17feb05b2006401fb1c3fdded335a465b51"); +} + +TEST(EthCallDataBuilderTest, Addr) { + std::string data; + EXPECT_TRUE(Addr("brantly.eth", &data)); + EXPECT_EQ(data, + "0x3b3b57de" + "43fcd34d8589090581e1d2bdcf5dc17feb05b2006401fb1c3fdded335a465b51"); +} + +} // namespace ens + } // namespace brave_wallet diff --git a/components/brave_wallet/browser/eth_json_rpc_controller.cc b/components/brave_wallet/browser/eth_json_rpc_controller.cc index 37ec6d9f038e..7a9ef9faed14 100644 --- a/components/brave_wallet/browser/eth_json_rpc_controller.cc +++ b/components/brave_wallet/browser/eth_json_rpc_controller.cc @@ -82,6 +82,16 @@ void EthJsonRpcController::AddObserver( void EthJsonRpcController::Request(const std::string& json_payload, bool auto_retry_on_network_change, RequestCallback callback) { + RequestInternal(json_payload, auto_retry_on_network_change, network_url_, + std::move(callback)); +} + +void EthJsonRpcController::RequestInternal(const std::string& json_payload, + bool auto_retry_on_network_change, + const GURL& network_url, + RequestCallback callback) { + DCHECK(network_url.is_valid()); + base::flat_map request_headers; std::string id, method, params; if (GetEthJsonRequestInfo(json_payload, nullptr, &method, ¶ms)) { @@ -102,7 +112,7 @@ void EthJsonRpcController::Request(const std::string& json_payload, } request_headers["x-brave-key"] = brave_key; - api_request_helper_.Request("POST", network_url_, json_payload, + api_request_helper_.Request("POST", network_url, json_payload, "application/json", auto_retry_on_network_change, std::move(callback), request_headers); } @@ -472,25 +482,37 @@ void EthJsonRpcController::OnGetERC20TokenAllowance( std::move(callback).Run(true, result); } -void EthJsonRpcController::EnsProxyReaderGetResolverAddress( - const std::string& contract_address, +void EthJsonRpcController::EnsRegistryGetResolver( + const std::string& chain_id, const std::string& domain, - UnstoppableDomainsProxyReaderGetManyCallback callback) { + StringResultCallback callback) { + const std::string contract_address = GetEnsRegistryContractAddress(chain_id); + if (contract_address.empty()) { + std::move(callback).Run(false, ""); + return; + } + std::string data; - if (!ens::GetResolverAddress(domain, &data)) { + if (!ens::Resolver(domain, &data)) { std::move(callback).Run(false, ""); + return; } - auto internal_callback = base::BindOnce( - &EthJsonRpcController::OnEnsProxyReaderGetResolverAddress, - weak_ptr_factory_.GetWeakPtr(), std::move(callback), domain); - Request(eth_call("", contract_address, "", "", "", data, "latest"), true, - std::move(internal_callback)); + GURL network_url = GetNetworkURL(prefs_, chain_id); + if (!network_url.is_valid()) { + std::move(callback).Run(false, ""); + return; + } + + auto internal_callback = + base::BindOnce(&EthJsonRpcController::OnEnsRegistryGetResolver, + weak_ptr_factory_.GetWeakPtr(), std::move(callback)); + RequestInternal(eth_call("", contract_address, "", "", "", data, "latest"), + true, network_url, std::move(internal_callback)); } -void EthJsonRpcController::OnEnsProxyReaderGetResolverAddress( - UnstoppableDomainsProxyReaderGetManyCallback callback, - const std::string& domain, +void EthJsonRpcController::OnEnsRegistryGetResolver( + StringResultCallback callback, int status, const std::string& body, const base::flat_map& headers) { @@ -499,39 +521,110 @@ void EthJsonRpcController::OnEnsProxyReaderGetResolverAddress( std::move(callback).Run(false, ""); return; } - std::string result; - if (!ParseEthCall(body, &result) || result.empty()) { + + std::string resolver_address; + if (!ParseEnsAddress(body, &resolver_address) || resolver_address.empty()) { std::move(callback).Run(false, ""); return; } - size_t offset = 2 /* len of "0x" */ + 24 /* len of offset to array */; - if (offset >= result.size()) { + + std::move(callback).Run(true, resolver_address); +} + +void EthJsonRpcController::EnsResolverGetContentHash( + const std::string& chain_id, + const std::string& domain, + StringResultCallback callback) { + auto internal_callback = base::BindOnce( + &EthJsonRpcController::ContinueEnsResolverGetContentHash, + weak_ptr_factory_.GetWeakPtr(), chain_id, domain, std::move(callback)); + EnsRegistryGetResolver(chain_id, domain, std::move(internal_callback)); +} + +void EthJsonRpcController::ContinueEnsResolverGetContentHash( + const std::string& chain_id, + const std::string& domain, + StringResultCallback callback, + bool success, + const std::string& resolver_address) { + if (!success || resolver_address.empty()) { + std::move(callback).Run(false, ""); + return; + } + + std::string data; + if (!ens::ContentHash(domain, &data)) { + std::move(callback).Run(false, ""); + return; + } + + GURL network_url = GetNetworkURL(prefs_, chain_id); + if (!network_url.is_valid()) { std::move(callback).Run(false, ""); return; } - std::string contenthash = "0x" + result.substr(offset); - EnsProxyReaderResolveAddress(contenthash, domain, std::move(callback)); + + auto internal_callback = + base::BindOnce(&EthJsonRpcController::OnEnsResolverGetContentHash, + weak_ptr_factory_.GetWeakPtr(), std::move(callback)); + RequestInternal(eth_call("", resolver_address, "", "", "", data, "latest"), + true, network_url, std::move(internal_callback)); } -bool EthJsonRpcController::EnsProxyReaderResolveAddress( - const std::string& contract_address, +void EthJsonRpcController::OnEnsResolverGetContentHash( + StringResultCallback callback, + int status, + const std::string& body, + const base::flat_map& headers) { + DCHECK(callback); + if (status < 200 || status > 299) { + std::move(callback).Run(false, ""); + return; + } + + std::string content_hash; + if (!ParseEnsResolverContentHash(body, &content_hash) || + content_hash.empty()) { + std::move(callback).Run(false, ""); + return; + } + + std::move(callback).Run(true, content_hash); +} + +void EthJsonRpcController::EnsGetEthAddr(const std::string& domain, + EnsGetEthAddrCallback callback) { + auto internal_callback = base::BindOnce( + &EthJsonRpcController::ContinueEnsGetEthAddr, + weak_ptr_factory_.GetWeakPtr(), domain, std::move(callback)); + EnsRegistryGetResolver(chain_id_, domain, std::move(internal_callback)); +} + +void EthJsonRpcController::ContinueEnsGetEthAddr( const std::string& domain, - UnstoppableDomainsProxyReaderGetManyCallback callback) { + StringResultCallback callback, + bool success, + const std::string& resolver_address) { + if (!success || resolver_address.empty()) { + std::move(callback).Run(false, ""); + return; + } + std::string data; - if (!ens::GetContentHashAddress(domain, &data)) { - return false; + if (!ens::Addr(domain, &data)) { + std::move(callback).Run(false, ""); + return; } auto internal_callback = - base::BindOnce(&EthJsonRpcController::OnEnsProxyReaderResolveAddress, - base::Unretained(this), std::move(callback)); - Request(eth_call("", contract_address, "", "", "", data, "latest"), true, + base::BindOnce(&EthJsonRpcController::OnEnsGetEthAddr, + weak_ptr_factory_.GetWeakPtr(), std::move(callback)); + Request(eth_call("", resolver_address, "", "", "", data, "latest"), true, std::move(internal_callback)); - return true; } -void EthJsonRpcController::OnEnsProxyReaderResolveAddress( - UnstoppableDomainsProxyReaderGetManyCallback callback, +void EthJsonRpcController::OnEnsGetEthAddr( + StringResultCallback callback, int status, const std::string& body, const base::flat_map& headers) { @@ -540,29 +633,45 @@ void EthJsonRpcController::OnEnsProxyReaderResolveAddress( std::move(callback).Run(false, ""); return; } - std::string result; - if (!ParseEthCall(body, &result)) { + + std::string address; + if (!ParseEnsAddress(body, &address) || address.empty()) { std::move(callback).Run(false, ""); return; } - std::move(callback).Run(true, result); + + std::move(callback).Run(true, address); } void EthJsonRpcController::UnstoppableDomainsProxyReaderGetMany( - const std::string& contract_address, + const std::string& chain_id, const std::string& domain, const std::vector& keys, UnstoppableDomainsProxyReaderGetManyCallback callback) { + const std::string contract_address = + GetUnstoppableDomainsProxyReaderContractAddress(chain_id); + if (contract_address.empty()) { + std::move(callback).Run(false, std::vector()); + return; + } + std::string data; if (!unstoppable_domains::GetMany(keys, domain, &data)) { - std::move(callback).Run(false, ""); + std::move(callback).Run(false, std::vector()); + return; + } + + GURL network_url = GetNetworkURL(prefs_, chain_id); + if (!network_url.is_valid()) { + std::move(callback).Run(false, std::vector()); + return; } auto internal_callback = base::BindOnce( &EthJsonRpcController::OnUnstoppableDomainsProxyReaderGetMany, weak_ptr_factory_.GetWeakPtr(), std::move(callback)); - Request(eth_call("", contract_address, "", "", "", data, "latest"), true, - std::move(internal_callback)); + RequestInternal(eth_call("", contract_address, "", "", "", data, "latest"), + true, network_url, std::move(internal_callback)); } void EthJsonRpcController::OnUnstoppableDomainsProxyReaderGetMany( @@ -570,16 +679,60 @@ void EthJsonRpcController::OnUnstoppableDomainsProxyReaderGetMany( const int status, const std::string& body, const base::flat_map& headers) { + if (status < 200 || status > 299) { + std::move(callback).Run(false, std::vector()); + return; + } + + std::vector values; + if (!ParseUnstoppableDomainsProxyReaderGetMany(body, &values)) { + std::move(callback).Run(false, std::vector()); + return; + } + + std::move(callback).Run(true, values); +} + +void EthJsonRpcController::UnstoppableDomainsGetEthAddr( + const std::string& domain, + UnstoppableDomainsGetEthAddrCallback callback) { + const std::string contract_address = + GetUnstoppableDomainsProxyReaderContractAddress(chain_id_); + if (contract_address.empty()) { + std::move(callback).Run(false, ""); + return; + } + + std::string data; + if (!unstoppable_domains::Get(kCryptoEthAddressKey, domain, &data)) { + std::move(callback).Run(false, ""); + return; + } + + auto internal_callback = + base::BindOnce(&EthJsonRpcController::OnUnstoppableDomainsGetEthAddr, + weak_ptr_factory_.GetWeakPtr(), std::move(callback)); + Request(eth_call("", contract_address, "", "", "", data, "latest"), true, + std::move(internal_callback)); +} + +void EthJsonRpcController::OnUnstoppableDomainsGetEthAddr( + UnstoppableDomainsGetEthAddrCallback callback, + const int status, + const std::string& body, + const base::flat_map& headers) { if (status < 200 || status > 299) { std::move(callback).Run(false, ""); return; } - std::string result; - if (!ParseEthCall(body, &result)) { + + std::string address; + if (!ParseUnstoppableDomainsProxyReaderGet(body, &address)) { std::move(callback).Run(false, ""); return; } - std::move(callback).Run(true, result); + + std::move(callback).Run(true, address); } GURL EthJsonRpcController::GetBlockTrackerUrlFromNetwork(std::string chain_id) { diff --git a/components/brave_wallet/browser/eth_json_rpc_controller.h b/components/brave_wallet/browser/eth_json_rpc_controller.h index 9666e5f9b5bc..9e603dbe3909 100644 --- a/components/brave_wallet/browser/eth_json_rpc_controller.h +++ b/components/brave_wallet/browser/eth_json_rpc_controller.h @@ -55,6 +55,9 @@ class EthJsonRpcController : public KeyedService, mojo::PendingRemote MakeRemote(); void Bind(mojo::PendingReceiver receiver); + using StringResultCallback = + base::OnceCallback; + using GetBlockNumberCallback = base::OnceCallback; void GetBlockNumber(GetBlockNumberCallback callback); @@ -62,6 +65,7 @@ class EthJsonRpcController : public KeyedService, void Request(const std::string& json_payload, bool auto_retry_on_network_change, RequestCallback callback) override; + void GetBalance(const std::string& address, GetBalanceCallback callback) override; @@ -88,22 +92,25 @@ class EthJsonRpcController : public KeyedService, const std::string& spender_address, GetERC20TokenAllowanceCallback callback) override; + using UnstoppableDomainsProxyReaderGetManyCallback = + base::OnceCallback& values)>; // Call getMany function of ProxyReader contract from Unstoppable Domains. void UnstoppableDomainsProxyReaderGetMany( - const std::string& contract_address, + const std::string& chain_id, const std::string& domain, const std::vector& keys, - UnstoppableDomainsProxyReaderGetManyCallback callback) override; + UnstoppableDomainsProxyReaderGetManyCallback callback); - void EnsProxyReaderGetResolverAddress( - const std::string& contract_address, + void UnstoppableDomainsGetEthAddr( const std::string& domain, - UnstoppableDomainsProxyReaderGetManyCallback callback) override; + UnstoppableDomainsGetEthAddrCallback callback) override; - bool EnsProxyReaderResolveAddress( - const std::string& contract_address, - const std::string& domain, - UnstoppableDomainsProxyReaderGetManyCallback callback); + void EnsResolverGetContentHash(const std::string& chain_id, + const std::string& domain, + StringResultCallback callback); + void EnsGetEthAddr(const std::string& domain, + EnsGetEthAddrCallback callback) override; void SetNetwork(const std::string& chain_id) override; void AddEthereumChain(mojom::EthereumChainPtr chain, @@ -196,19 +203,44 @@ class EthJsonRpcController : public KeyedService, const std::string& body, const base::flat_map& headers); - void OnEnsProxyReaderGetResolverAddress( - UnstoppableDomainsProxyReaderGetManyCallback callback, - const std::string& domain, + void OnUnstoppableDomainsGetEthAddr( + UnstoppableDomainsGetEthAddrCallback callback, + const int status, + const std::string& body, + const base::flat_map& headers); + + void EnsRegistryGetResolver(const std::string& chain_id, + const std::string& domain, + StringResultCallback callback); + + void OnEnsRegistryGetResolver( + StringResultCallback callback, int status, const std::string& body, const base::flat_map& headers); - void OnEnsProxyReaderResolveAddress( - UnstoppableDomainsProxyReaderGetManyCallback callback, + void ContinueEnsResolverGetContentHash(const std::string& chain_id, + const std::string& domain, + StringResultCallback callback, + bool success, + const std::string& resolver_address); + + void OnEnsResolverGetContentHash( + StringResultCallback callback, int status, const std::string& body, const base::flat_map& headers); + void ContinueEnsGetEthAddr(const std::string& domain, + StringResultCallback callback, + bool success, + const std::string& resolver_address); + + void OnEnsGetEthAddr(StringResultCallback callback, + int status, + const std::string& body, + const base::flat_map& headers); + void OnGetEstimateGas( GetEstimateGasCallback callback, int status, @@ -230,6 +262,11 @@ class EthJsonRpcController : public KeyedService, bool success, bool is_eip1559); + void RequestInternal(const std::string& json_payload, + bool auto_retry_on_network_change, + const GURL& network_url, + RequestCallback callback); + api_request_helper::APIRequestHelper api_request_helper_; GURL network_url_; std::string chain_id_; diff --git a/components/brave_wallet/browser/eth_json_rpc_controller_unittest.cc b/components/brave_wallet/browser/eth_json_rpc_controller_unittest.cc index 8dd5bf87319b..024d5f4edacb 100644 --- a/components/brave_wallet/browser/eth_json_rpc_controller_unittest.cc +++ b/components/brave_wallet/browser/eth_json_rpc_controller_unittest.cc @@ -19,6 +19,7 @@ #include "brave/components/brave_wallet/browser/pref_names.h" #include "brave/components/brave_wallet/common/brave_wallet.mojom.h" #include "brave/components/brave_wallet/common/value_conversion_utils.h" +#include "brave/components/ipfs/ipfs_utils.h" #include "components/prefs/scoped_user_pref_update.h" #include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/user_prefs/user_prefs.h" @@ -79,6 +80,16 @@ void OnBoolResponse(bool* callback_called, EXPECT_EQ(expected_success, success); } +void OnStringsResponse(bool* callback_called, + bool expected_success, + const std::vector& expected_response, + bool success, + const std::vector& response) { + *callback_called = true; + EXPECT_EQ(expected_response, response); + EXPECT_EQ(expected_success, success); +} + class TestEthJsonRpcControllerObserver : public brave_wallet::mojom::EthJsonRpcControllerObserver { public: @@ -203,14 +214,56 @@ class EthJsonRpcControllerUnitTest : public testing::Test { return false; } - void SetRegistrarResponse() { - auto localhost_url_spec = - brave_wallet::GetNetworkURL(prefs(), mojom::kLocalhostChainId).spec(); + void SetUDENSInterceptor(const std::string& chain_id) { + GURL network_url = brave_wallet::GetNetworkURL(prefs(), chain_id); + ASSERT_TRUE(network_url.is_valid()); - url_loader_factory_.AddResponse( - localhost_url_spec, - "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x00000" - "0000000000000000000226159d592e2b063810a10ebf6dcbada94ed68b8\"}"); + url_loader_factory_.SetInterceptor(base::BindLambdaForTesting( + [&, network_url](const network::ResourceRequest& request) { + base::StringPiece request_string(request.request_body->elements() + ->at(0) + .As() + .AsStringPiece()); + url_loader_factory_.ClearResponses(); + if (request_string.find(GetFunctionHash("resolver(bytes32)")) != + std::string::npos) { + url_loader_factory_.AddResponse( + network_url.spec(), + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + "\"0x0000000000000000000000004976fb03c32e5b8cfe2b6ccb31c09ba78e" + "baba41\"}"); + } else if (request_string.find(GetFunctionHash( + "contenthash(bytes32)")) != std::string::npos) { + url_loader_factory_.AddResponse( + network_url.spec(), + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + "\"0x0000000000000000000000000000000000000000000000000000000000" + "00002000000000000000000000000000000000000000000000000000000000" + "00000026e3010170122023e0160eec32d7875c19c5ac7c03bc1f306dc26008" + "0d621454bc5f631e7310a70000000000000000000000000000000000000000" + "000000000000\"}"); + } else if (request_string.find(GetFunctionHash("addr(bytes32)")) != + std::string::npos) { + url_loader_factory_.AddResponse( + network_url.spec(), + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + "\"0x000000000000000000000000983110309620d911731ac0932219af0609" + "1b6744\"}"); + } else if (request_string.find(GetFunctionHash( + "get(string,uint256)")) != std::string::npos) { + url_loader_factory_.AddResponse( + network_url.spec(), + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + "\"0x0000000000000000000000000000000000000000000000000000000000" + "00002000000000000000000000000000000000000000000000000000000000" + "0000002a307838616144343433323141383662313730383739643741323434" + "63316538643336306339394464413800000000000000000000000000000000" + "000000000000\"}"); + } else { + url_loader_factory_.AddResponse(request.url.spec(), "", + net::HTTP_REQUEST_TIMEOUT); + } + })); } void SetInterceptor(const std::string& expected_method, @@ -378,25 +431,60 @@ TEST_F(EthJsonRpcControllerUnitTest, GetAllNetworks) { base::RunLoop().RunUntilIdle(); } -TEST_F(EthJsonRpcControllerUnitTest, ResolveENSDomain) { - rpc_controller_->SetNetwork(brave_wallet::mojom::kLocalhostChainId); - SetRegistrarResponse(); - base::RunLoop run; - rpc_controller_->EnsProxyReaderGetResolverAddress( - "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", "blocktimer.dappstar.eth", - base::BindOnce( - [](base::OnceClosure done, bool status, const std::string& result) { - ASSERT_TRUE(status); - EXPECT_EQ(result, - "0x000000000000000000000000000000000000000000000000000000" - "00000000200000000000000000000000000000000000000000000000" - "000000000000000026e3010170122008ab7bf21b73828364305ef6b7" - "c676c1f5a73e18ab4f93beec7e21e0bc84010e000000000000000000" - "0000000000000000000000000000000000"); - std::move(done).Run(); - }, - run.QuitClosure())); - run.Run(); +TEST_F(EthJsonRpcControllerUnitTest, EnsResolverGetContentHash) { + // Non-support chain should fail. + SetUDENSInterceptor(mojom::kLocalhostChainId); + + bool callback_called = false; + rpc_controller_->EnsResolverGetContentHash( + mojom::kLocalhostChainId, "brantly.eth", + base::BindOnce(&OnStringResponse, &callback_called, false, "")); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(callback_called); + + callback_called = false; + SetUDENSInterceptor(mojom::kMainnetChainId); + rpc_controller_->EnsResolverGetContentHash( + mojom::kMainnetChainId, "brantly.eth", + base::BindLambdaForTesting([&](bool status, const std::string& result) { + callback_called = true; + EXPECT_TRUE(status); + EXPECT_EQ( + ipfs::ContentHashToCIDv1URL(result).spec(), + "ipfs://" + "bafybeibd4ala53bs26dvygofvr6ahpa7gbw4eyaibvrbivf4l5rr44yqu4"); + })); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(callback_called); + + callback_called = false; + SetErrorInterceptor(); + rpc_controller_->EnsResolverGetContentHash( + mojom::kMainnetChainId, "brantly.eth", + base::BindOnce(&OnStringResponse, &callback_called, false, "")); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(callback_called); +} + +TEST_F(EthJsonRpcControllerUnitTest, EnsGetEthAddr) { + // Non-support chain (localhost) should fail. + SetUDENSInterceptor(rpc_controller_->GetChainId()); + bool callback_called = false; + rpc_controller_->EnsGetEthAddr( + "brantly.eth", + base::BindOnce(&OnStringResponse, &callback_called, false, "")); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(callback_called); + + callback_called = false; + rpc_controller_->SetNetwork(mojom::kMainnetChainId); + SetUDENSInterceptor(mojom::kMainnetChainId); + rpc_controller_->EnsGetEthAddr( + "brantly.eth", + base::BindOnce(&OnStringResponse, &callback_called, true, + "0x983110309620d911731ac0932219af06091b6744")); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(callback_called); } TEST_F(EthJsonRpcControllerUnitTest, ResetCustomChains) { @@ -687,57 +775,96 @@ TEST_F(EthJsonRpcControllerUnitTest, UnstoppableDomainsProxyReaderGetMany) { SetInterceptor( "eth_call", "", "{\"jsonrpc\":\"2.0\",\"id\": \"0\",\"result\": " - "\"0x00000000000000000000000000000000000000000000000000000000000000200000" - "000000000000000000000000000000000000000000000000000000000004000000000000" - "000000000000000000000000000000000000000000000000008000000000000000000000" - "000000000000000000000000000000000000000000a00000000000000000000000000000" - "000000000000000000000000000000000100000000000000000000000000000000000000" - "000000000000000000000000012000000000000000000000000000000000000000000000" - "000000000000000000000000000000000000000000000000000000000000000000000000" - "00000000002e516d5772644e4a574d62765278787a4c686f6a564b614244737753344b4e" - "564d374c766a734e3751624472766b610000000000000000000000000000000000000000" - "000000000000000000000000000000000000000000000000000000000000000000000000" - "0000000000000000000000000000000000000000000000000000\"}"); + // offset for array + "\"0x0000000000000000000000000000000000000000000000000000000000000020" + // count for array + "0000000000000000000000000000000000000000000000000000000000000006" + // offsets for array elements + "00000000000000000000000000000000000000000000000000000000000000c0" + "0000000000000000000000000000000000000000000000000000000000000120" + "0000000000000000000000000000000000000000000000000000000000000180" + "00000000000000000000000000000000000000000000000000000000000001a0" + "00000000000000000000000000000000000000000000000000000000000001c0" + "0000000000000000000000000000000000000000000000000000000000000200" + // count for "QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka" + "000000000000000000000000000000000000000000000000000000000000002e" + // encoding for "QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka" + "516d5772644e4a574d62765278787a4c686f6a564b614244737753344b4e564d" + "374c766a734e3751624472766b61000000000000000000000000000000000000" + // count for "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" + "000000000000000000000000000000000000000000000000000000000000002e" + // encoding for "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" + "516d6257717842454b433350387471734b633938786d574e7a727a4474524c4d" + "694d504c387742755447734d6e52000000000000000000000000000000000000" + // count for empty dns.A + "0000000000000000000000000000000000000000000000000000000000000000" + // count for empty dns.AAAA + "0000000000000000000000000000000000000000000000000000000000000000" + // count for "https://fallback1.test.com" + "000000000000000000000000000000000000000000000000000000000000001a" + // encoding for "https://fallback1.test.com" + "68747470733a2f2f66616c6c6261636b312e746573742e636f6d000000000000" + // count for "https://fallback2.test.com" + "000000000000000000000000000000000000000000000000000000000000001a" + // encoding for "https://fallback2.test.com" + "68747470733a2f2f66616c6c6261636b322e746573742e636f6d000000000000\"}"); + + std::vector expected_values = { + "QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka", + "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR", + "", + "", + "https://fallback1.test.com", + "https://fallback2.test.com"}; rpc_controller_->UnstoppableDomainsProxyReaderGetMany( - "0xa6E7cEf2EDDEA66352Fd68E5915b60BDbb7309f5" /* contract_address */, - "brave.crypto" /* domain */, + mojom::kMainnetChainId, "brave.crypto" /* domain */, {"dweb.ipfs.hash", "ipfs.html.value", "browser.redirect_url", "ipfs.redirect_domain.value"} /* keys */, - base::BindOnce( - &OnStringResponse, &callback_called, true, - "0x0000000000000000000000000000000000000000000000000000000000000020" - "0000000000000000000000000000000000000000000000000000000000000004" - "0000000000000000000000000000000000000000000000000000000000000080" - "00000000000000000000000000000000000000000000000000000000000000a0" - "0000000000000000000000000000000000000000000000000000000000000100" - "0000000000000000000000000000000000000000000000000000000000000120" - "0000000000000000000000000000000000000000000000000000000000000000" - "000000000000000000000000000000000000000000000000000000000000002e" - "516d5772644e4a574d62765278787a4c686f6a564b614244737753344b4e564d" - "374c766a734e3751624472766b61000000000000000000000000000000000000" - "0000000000000000000000000000000000000000000000000000000000000000" - "0000000000000000000000000000000000000000000000000000000000000000")); + base::BindOnce(&OnStringsResponse, &callback_called, true, + expected_values)); base::RunLoop().RunUntilIdle(); EXPECT_TRUE(callback_called); callback_called = false; SetErrorInterceptor(); rpc_controller_->UnstoppableDomainsProxyReaderGetMany( - "0xa6E7cEf2EDDEA66352Fd68E5915b60BDbb7309f5" /* contract_address */, - "brave.crypto" /* domain */, + mojom::kMainnetChainId, "brave.crypto" /* domain */, {"dweb.ipfs.hash", "ipfs.html.value", "browser.redirect_url", "ipfs.redirect_domain.value"} /* keys */, - base::BindOnce(&OnStringResponse, &callback_called, false, "")); + base::BindOnce(&OnStringsResponse, &callback_called, false, + std::vector())); base::RunLoop().RunUntilIdle(); EXPECT_TRUE(callback_called); callback_called = false; rpc_controller_->UnstoppableDomainsProxyReaderGetMany( "", "", std::vector(), + base::BindOnce(&OnStringsResponse, &callback_called, false, + std::vector())); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(callback_called); +} + +TEST_F(EthJsonRpcControllerUnitTest, UnstoppableDomainsGetEthAddr) { + // Non-support chain (localhost) should fail. + SetUDENSInterceptor(rpc_controller_->GetChainId()); + bool callback_called = false; + rpc_controller_->UnstoppableDomainsGetEthAddr( + "brad.crypto", base::BindOnce(&OnStringResponse, &callback_called, false, "")); base::RunLoop().RunUntilIdle(); EXPECT_TRUE(callback_called); + + callback_called = false; + rpc_controller_->SetNetwork(mojom::kMainnetChainId); + SetUDENSInterceptor(mojom::kMainnetChainId); + rpc_controller_->UnstoppableDomainsGetEthAddr( + "brad.crypto", + base::BindOnce(&OnStringResponse, &callback_called, true, + "0x8aaD44321A86b170879d7A244c1e8d360c99DdA8")); + base::RunLoop().RunUntilIdle(); + EXPECT_TRUE(callback_called); } TEST_F(EthJsonRpcControllerUnitTest, GetIsEip1559) { diff --git a/components/brave_wallet/browser/eth_response_parser.cc b/components/brave_wallet/browser/eth_response_parser.cc index d16e10328443..6fbc62d63ee1 100644 --- a/components/brave_wallet/browser/eth_response_parser.cc +++ b/components/brave_wallet/browser/eth_response_parser.cc @@ -168,4 +168,61 @@ bool ParseEthGasPrice(const std::string& json, std::string* result) { return ParseSingleStringResult(json, result); } +bool ParseEnsAddress(const std::string& json, std::string* address) { + DCHECK(address); + + std::string result; + if (!ParseSingleStringResult(json, &result)) + return false; + + // Expected result: 0x prefix + 24 leading 0s + 40 characters for address. + if (result.size() != 66) { + return false; + } + + size_t offset = 2 /* len of "0x" */ + 24 /* len of leading zeros */; + *address = "0x" + result.substr(offset); + return true; +} + +bool ParseEnsResolverContentHash(const std::string& json, + std::string* content_hash) { + DCHECK(content_hash); + + std::string result; + if (!ParseSingleStringResult(json, &result)) + return false; + + size_t offset = 2 /* len of "0x" */ + 64 /* len of offset to array */; + return brave_wallet::DecodeString(offset, result, content_hash); +} + +bool ParseUnstoppableDomainsProxyReaderGetMany( + const std::string& json, + std::vector* values) { + DCHECK(values); + + std::string result; + if (!ParseSingleStringResult(json, &result)) + return false; + + size_t offset = 2 /* len of "0x" */ + 64 /* len of offset to array */; + if (offset > result.size()) + return false; + + return brave_wallet::DecodeStringArray(result.substr(offset), values); +} + +bool ParseUnstoppableDomainsProxyReaderGet(const std::string& json, + std::string* value) { + DCHECK(value); + + std::string result; + if (!ParseSingleStringResult(json, &result)) + return false; + + size_t offset = 2 /* len of "0x" */ + 64 /* len of offset to array */; + return brave_wallet::DecodeString(offset, result, value); +} + } // namespace brave_wallet diff --git a/components/brave_wallet/browser/eth_response_parser.h b/components/brave_wallet/browser/eth_response_parser.h index d718cc61d33d..4b743b5cf165 100644 --- a/components/brave_wallet/browser/eth_response_parser.h +++ b/components/brave_wallet/browser/eth_response_parser.h @@ -7,8 +7,9 @@ #define BRAVE_COMPONENTS_BRAVE_WALLET_BROWSER_ETH_RESPONSE_PARSER_H_ #include -#include "base/values.h" +#include +#include "base/values.h" #include "brave/components/brave_wallet/browser/brave_wallet_types.h" namespace brave_wallet { @@ -25,6 +26,16 @@ bool ParseEthCall(const std::string& json, std::string* result); bool ParseEthEstimateGas(const std::string& json, std::string* result); bool ParseEthGasPrice(const std::string& json, std::string* result); +bool ParseEnsAddress(const std::string& json, std::string* resolver_address); +bool ParseEnsResolverContentHash(const std::string& json, + std::string* content_hash); +bool ParseUnstoppableDomainsProxyReaderGetMany( + const std::string& json, + std::vector* values); + +bool ParseUnstoppableDomainsProxyReaderGet(const std::string& json, + std::string* value); + } // namespace brave_wallet #endif // BRAVE_COMPONENTS_BRAVE_WALLET_BROWSER_ETH_RESPONSE_PARSER_H_ diff --git a/components/brave_wallet/browser/eth_response_parser_unittest.cc b/components/brave_wallet/browser/eth_response_parser_unittest.cc index cd9adf63d545..6cb5bac6c857 100644 --- a/components/brave_wallet/browser/eth_response_parser_unittest.cc +++ b/components/brave_wallet/browser/eth_response_parser_unittest.cc @@ -8,6 +8,7 @@ #include #include "brave/components/brave_wallet/browser/eth_response_parser.h" +#include "brave/components/ipfs/ipfs_utils.h" #include "testing/gtest/include/gtest/gtest.h" namespace brave_wallet { @@ -137,4 +138,124 @@ TEST(EthResponseParserUnitTest, ParseEthGetTransactionReceiptNullContractAddr) { EXPECT_TRUE(receipt.status); } +TEST(EthResponseParserUnitTest, ParseEnsAddress) { + std::string json = + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + "\"0x0000000000000000000000004976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41\"}"; + std::string addr; + EXPECT_TRUE(ParseEnsAddress(json, &addr)); + EXPECT_EQ(addr, "0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41"); + + // Non-expected address size. + addr = ""; + json = + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + "\"0x0000000000000000000000004976fb03c32e5b8cfe2b6ccb31c09ba78eba\"}"; + EXPECT_FALSE(ParseEnsAddress(json, &addr)); + EXPECT_TRUE(addr.empty()); +} + +TEST(EthResponseParserUnitTest, ParseEnsResolverContentHash) { + std::string json = + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + "\"0x00000000000000000000000000000000000000000000000000000000000000200000" + "00" + "0000000000000000000000000000000000000000000000000000000026e3010170122023" + "e0160eec32d7875c19c5ac7c03bc1f306dc260080d621454bc5f631e7310a70000000000" + "000000000000000000000000000000000000000000\"}"; + std::string content_hash; + EXPECT_TRUE(ParseEnsResolverContentHash(json, &content_hash)); + EXPECT_EQ( + ipfs::ContentHashToCIDv1URL(content_hash).spec(), + "ipfs://bafybeibd4ala53bs26dvygofvr6ahpa7gbw4eyaibvrbivf4l5rr44yqu4"); + + content_hash = ""; + json = + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + "\"0x000000000000000000000000000000000000000000000000000000000000002000"; + + EXPECT_FALSE(ParseEnsResolverContentHash(json, &content_hash)); + EXPECT_TRUE(content_hash.empty()); +} + +TEST(EthResponseParserUnitTest, ParseUnstoppableDomainsProxyReaderGetMany) { + std::string json = + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + // offset for array + "\"0x0000000000000000000000000000000000000000000000000000000000000020" + // count for array + "0000000000000000000000000000000000000000000000000000000000000006" + // offsets for array elements + "00000000000000000000000000000000000000000000000000000000000000c0" + "0000000000000000000000000000000000000000000000000000000000000120" + "0000000000000000000000000000000000000000000000000000000000000180" + "00000000000000000000000000000000000000000000000000000000000001a0" + "00000000000000000000000000000000000000000000000000000000000001c0" + "0000000000000000000000000000000000000000000000000000000000000200" + // count for "QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka" + "000000000000000000000000000000000000000000000000000000000000002e" + // encoding for "QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka" + "516d5772644e4a574d62765278787a4c686f6a564b614244737753344b4e564d" + "374c766a734e3751624472766b61000000000000000000000000000000000000" + // count for "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" + "000000000000000000000000000000000000000000000000000000000000002e" + // encoding for "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR" + "516d6257717842454b433350387471734b633938786d574e7a727a4474524c4d" + "694d504c387742755447734d6e52000000000000000000000000000000000000" + // count for empty dns.A + "0000000000000000000000000000000000000000000000000000000000000000" + // count for empty dns.AAAA + "0000000000000000000000000000000000000000000000000000000000000000" + // count for "https://fallback1.test.com" + "000000000000000000000000000000000000000000000000000000000000001a" + // encoding for "https://fallback1.test.com" + "68747470733a2f2f66616c6c6261636b312e746573742e636f6d000000000000" + // count for "https://fallback2.test.com" + "000000000000000000000000000000000000000000000000000000000000001a" + // encoding for "https://fallback2.test.com" + "68747470733a2f2f66616c6c6261636b322e746573742e636f6d000000000000\"}"; + + std::vector expected_values = { + "QmWrdNJWMbvRxxzLhojVKaBDswS4KNVM7LvjsN7QbDrvka", // dweb.ipfs.hash + "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR", // ipfs.html.value + "", // dns.A + "", // dns.AAAA + "https://fallback1.test.com", // browser.redirect_url + "https://fallback2.test.com", // ipfs.redirect_domain.value + }; + + std::vector values; + EXPECT_TRUE(ParseUnstoppableDomainsProxyReaderGetMany(json, &values)); + EXPECT_EQ(values, expected_values); + + values.clear(); + json = + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + "\"0x000000000000000000000000000000000000000000000000000000000000002000"; + EXPECT_FALSE(ParseUnstoppableDomainsProxyReaderGetMany(json, &values)); + EXPECT_TRUE(values.empty()); +} + +TEST(EthResponseParserUnitTest, ParseUnstoppableDomainsProxyReaderGet) { + std::string json = + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + // offset to string + "\"0x0000000000000000000000000000000000000000000000000000000000000020" + // string len + "000000000000000000000000000000000000000000000000000000000000002a" + // Encoded string of 0x8aaD44321A86b170879d7A244c1e8d360c99DdA8 + "3078386161443434333231413836623137303837396437413234346331653864" + "3336306339394464413800000000000000000000000000000000000000000000\"}"; + std::string value; + EXPECT_TRUE(ParseUnstoppableDomainsProxyReaderGet(json, &value)); + EXPECT_EQ(value, "0x8aaD44321A86b170879d7A244c1e8d360c99DdA8"); + + value = ""; + json = + "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":" + "\"0x000000000000000000000000000000000000000000000000000000000000002000"; + EXPECT_FALSE(ParseUnstoppableDomainsProxyReaderGet(json, &value)); + EXPECT_TRUE(value.empty()); +} + } // namespace brave_wallet diff --git a/components/brave_wallet/browser/test/BUILD.gn b/components/brave_wallet/browser/test/BUILD.gn index ad27df6b6038..069a3524cd34 100644 --- a/components/brave_wallet/browser/test/BUILD.gn +++ b/components/brave_wallet/browser/test/BUILD.gn @@ -44,6 +44,7 @@ source_set("brave_wallet_unit_tests") { "//brave/components/brave_wallet/browser:ethereum_permission_utils", "//brave/components/brave_wallet/common", "//brave/components/brave_wallet/common:mojom", + "//brave/components/ipfs", "//components/prefs", "//components/prefs:test_support", "//components/sync_preferences:test_support", diff --git a/components/brave_wallet/common/brave_wallet.mojom b/components/brave_wallet/common/brave_wallet.mojom index 2c4f61c04df8..041ef32eaaac 100644 --- a/components/brave_wallet/common/brave_wallet.mojom +++ b/components/brave_wallet/common/brave_wallet.mojom @@ -328,8 +328,8 @@ interface EthJsonRpcController { string address) => (bool success, string balance); GetERC20TokenAllowance(string contract, string owner_address, string spender_address) => (bool success, string allowance); - UnstoppableDomainsProxyReaderGetMany(string contract_address, string domain, array keys) => (bool status, string result); - EnsProxyReaderGetResolverAddress(string contract_address, string domain) => (bool status, string result); + EnsGetEthAddr(string domain) => (bool success, string address); + UnstoppableDomainsGetEthAddr(string domain) => (bool success, string address); Request(string json_payload, bool auto_retry_on_network_change) => (int32 http_code, string response, map headers); AddObserver(pending_remote observer); SetCustomNetworkForTesting(string chain_id, url.mojom.Url provider_url); diff --git a/components/brave_wallet_ui/constants/types.ts b/components/brave_wallet_ui/constants/types.ts index c39183af02f3..6c67bccaf583 100644 --- a/components/brave_wallet_ui/constants/types.ts +++ b/components/brave_wallet_ui/constants/types.ts @@ -589,6 +589,11 @@ export interface SetSelectedAccountReturnInfo { success: boolean } +export interface GetEthAddrReturnInfo { + success: boolean + address: string +} + export interface EthTxController { addUnapprovedTransaction: (txData: TxData, from: string) => Promise addUnapproved1559Transaction: (txData: TxData1559, from: string) => (AddUnapproved1559TransactionReturnInfo) @@ -614,6 +619,8 @@ export interface EthJsonRpcController { getBalance: (address: string) => Promise getERC20TokenBalance: (contract: string, address: string) => Promise getERC20TokenAllowance: (contract: string, ownerAddress: string, spenderAddress: string) => Promise + ensGetEthAddr: (domain: string) => Promise + unstoppableDomainsGetEthAddr: (domain: string) => Promise } export interface SwapController { diff --git a/components/decentralized_dns/constants.h b/components/decentralized_dns/constants.h index c1b9fc24db24..c951e4e2d61a 100644 --- a/components/decentralized_dns/constants.h +++ b/components/decentralized_dns/constants.h @@ -43,12 +43,6 @@ static_assert(static_cast(RecordKeys::MAX_RECORD_KEY) + 1u == sizeof(kRecordKeys) / sizeof(kRecordKeys[0]), "Size should match between RecordKeys and kRecordKeys."); -constexpr char kProxyReaderContractAddress[] = - "0xa6E7cEf2EDDEA66352Fd68E5915b60BDbb7309f5"; - -constexpr char kEnsRegistryContractAddress[] = - "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"; - } // namespace decentralized_dns #endif // BRAVE_COMPONENTS_DECENTRALIZED_DNS_CONSTANTS_H_