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

ENSIP-10 Reverse Resolution #4632

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

adraffy
Copy link

@adraffy adraffy commented Mar 3, 2024

I added EnsResolver.getName(). At a glance, it looks like a lot of EnsResolver could be simplified with the latest CCIP-Read stuff in v6.

I used that to re-implement AbstractResolver.lookupAddress(). I made this process more strict, as I don't think it's correct to return null for some of those cases. If that is too big of a change, possibly, we could add a separate function, which is strict, and the old function could just squelch those errors like the original implementation.

I unearthed an unused error type ValueMismatchError and used that for the mismatch case where the addresses don't match. Not sure if that fits your use-case. Additionally, maybe this function should get a second argument, which only does the one-sided request, as that it also useful in certain circumstances, although the new error would expose both addresses.


I'm not exactly sure how your testing stuff works. I added the start of a test but commented it. I ran build-dist and then tested it with a different project.

For testing, I configured a simple CCIP-Read reverse name on goerli that round-trips correctly and then called the new lookup function.

import {ethers} from 'ethers from fresh build-dist';
let p = new ethers.InfuraProvider(5);
let name = await p.lookupAddress("0xb404Af9A235Be881335d8898B5B487dc9Cd5ed9D");
// "raffyraffy.eth"

This corresponds to raffyraffy.eth which as the image shows, correctly round trips.

image

And the reverse record b404af9a235be881335d8898b5b487dc9cd5ed9d.addr.reverse is both wildcard and offchain.

image


For reference, this was my initial implementation using ethers v6.

import {ethers} from 'https://cdnjs.cloudflare.com/ajax/libs/ethers/6.11.0/ethers.js';
let provider = new ethers.InfuraProvider(5);
let name = 'b404af9a235be881335d8898b5b487dc9cd5ed9d.addr.reverse';
let node = ethers.namehash(name);
// get ensip-10 resolver
let {address: resolver} = await provider.getResolver(name);
// make ensip-10 contract stub
let contract = new ethers.Contract(resolver, [
	'function resolve(bytes,bytes) view returns (bytes)'
], provider);
// create call data
let abi = new ethers.Interface([
	'function name(bytes32) view returns (string)'
]);
// call resolve("name", name())
let request = abi.encodeFunctionData('name', [node]);
let response = await contract.resolve(
    ethers.dnsEncode(name, 255), 
    request, 
    {enableCcipRead: true}
);
let [primary] = abi.decodeFunctionResult('name', response);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant