Skip to content

Commit ad49560

Browse files
authored
ENS: add coinType param to reverse resolver (#8735)
1 parent 83198b2 commit ad49560

3 files changed

Lines changed: 39 additions & 23 deletions

File tree

.changeset/every-donuts-stop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
ENS: add coinType param to reverse resolver

packages/thirdweb/src/extensions/ens/__generated__/UniversalResolver/read/reverse.ts

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/thirdweb/src/extensions/ens/resolve-name.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { ethereum } from "../../chains/chain-definitions/ethereum.js";
33
import type { Chain } from "../../chains/types.js";
44
import type { ThirdwebClient } from "../../client/client.js";
55
import { getContract } from "../../contract/contract.js";
6-
import { toHex } from "../../utils/encoding/hex.js";
7-
import { packetToBytes } from "../../utils/ens/packetToBytes.js";
86
import { withCache } from "../../utils/promise/withCache.js";
97
import { reverse } from "./__generated__/UniversalResolver/read/reverse.js";
108
import { UNIVERSAL_RESOLVER_ADDRESS } from "./constants.js";
@@ -33,7 +31,9 @@ export type ResolveNameOptions = {
3331
* @extension ENS
3432
* @returns A promise that resolves to the Ethereum address.
3533
*/
36-
export async function resolveName(options: ResolveNameOptions) {
34+
export async function resolveName(
35+
options: ResolveNameOptions,
36+
): Promise<string | null> {
3737
const { client, address, resolverAddress, resolverChain } = options;
3838

3939
return withCache(
@@ -44,25 +44,28 @@ export async function resolveName(options: ResolveNameOptions) {
4444
client,
4545
});
4646

47-
const reverseName = toHex(
48-
packetToBytes(`${address.toLowerCase().substring(2)}.addr.reverse`),
49-
);
50-
51-
const [name, resolvedAddress] = await reverse({
47+
const [name] = await reverse({
5248
contract,
53-
reverseName,
49+
reverseName: address as `0x${string}`,
50+
coinType: 60n,
5451
}).catch((e) => {
55-
if ("data" in e && e.data === "0x7199966d") {
56-
return [null, address] as const;
52+
// Re-throw verification errors so callers can detect data integrity issues
53+
if (
54+
typeof e === "object" &&
55+
e !== null &&
56+
"data" in e &&
57+
typeof e.data === "string"
58+
) {
59+
// ReverseAddressMismatch(string,bytes) = 0xef9c03ce
60+
if (e.data.startsWith("0xef9c03ce")) {
61+
throw e;
62+
}
5763
}
58-
throw e;
64+
// Swallow expected "no resolver" / "no name" errors
65+
return [null] as const;
5966
});
6067

61-
if (address.toLowerCase() !== resolvedAddress.toLowerCase()) {
62-
return null;
63-
}
64-
65-
return name;
68+
return name || null;
6669
},
6770
{
6871
cacheKey: `ens:name:${resolverChain?.id || 1}:${address}`,

0 commit comments

Comments
 (0)