Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ENS lookup methods #136

Merged
merged 11 commits into from
Jan 10, 2022
Merged

feat: Add ENS lookup methods #136

merged 11 commits into from
Jan 10, 2022

Conversation

usame-algan
Copy link
Member

What it solves

Resolves #3231

How this PR fixes it

Adds two new methods to the Web3Adapter for ens lookup and reverse lookup

@usame-algan usame-algan changed the title feat: Add ens lookup functions feat: Add ENS lookup methods Jan 5, 2022
@github-actions
Copy link

github-actions bot commented Jan 5, 2022

CLA Assistant Lite All Contributors have signed the CLA.

@usame-algan
Copy link
Member Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Member

@germartinez germartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪 Cool feature!

@@ -24,7 +26,7 @@ export interface Web3AdapterConfig {
}

class Web3Adapter implements EthAdapter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding some context:
EthAdapter is an interface implemented by Web3Adapter and EthersAdapter classes where all the methods are defined in the interface and implemented using Web3 and ethers.js libraries in the 2 classes respectively. This way it doesn't matter if a Dapp uses ethers.js or web3, they will still be able to access the same functionality.

It would be cool if the 2 new methods are included in EthAdapter and EthersAdapter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@@ -1,3 +1,5 @@
import Web3 from 'web3'
import { ethers } from 'ethers'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ethers.js import should not be present in Web3Adapter


async ensReverseLookup(address: string): Promise<string> {
const lookup = address.toLowerCase().substr(2) + '.addr.reverse'
const node = ethers.utils.namehash(lookup)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ethers.js library should not be used in Web3Adapter class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately web3 doesn't provide a namehash implementation yet. We could instead include a new package eth-ens-namehash and use it in both places. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@usame-algan, have you checked to see if we use one in the Safe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is the first place where we need the namehash for the reverse lookup. Ethers can do the reverse lookup without the namehash so this only affects web3 atm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@germartinez isn't ethers.js bundled with the Core SDK in any case? Or is there tree-shaking in place?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eth-ens-namehash is very big too. I think it's better if use ethers temporarily. Web3 will include this function in one of the upcoming versions as per their GitHub.

Copy link
Member

@germartinez germartinez Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not import eth-ens-namehash or ethers.js, but @ethersproject/hash sub-module instead (https://www.npmjs.com/package/@ethersproject/hash?activeTab=readme)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Idea! I removed the eth-ens-namehash and used the sub-module instead.

@lukasschor
Copy link
Member

Nice! 😎

Copy link
Member

@iamacook iamacook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far! Just a couple type adjustments.

packages/safe-core-sdk/src/ethereumLibs/Web3Adapter.ts Outdated Show resolved Hide resolved
packages/safe-core-sdk/tests/ens.test.ts Outdated Show resolved Hide resolved
@usame-algan usame-algan changed the base branch from main to development January 10, 2022 12:23
Copy link
Member

@iamacook iamacook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@germartinez germartinez merged commit 63ece7e into development Jan 10, 2022
@germartinez germartinez deleted the reverse-ens-lookup branch January 10, 2022 16:25
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reverse ENS lookup
5 participants