@@ -3,8 +3,6 @@ import { ethereum } from "../../chains/chain-definitions/ethereum.js";
33import type { Chain } from "../../chains/types.js" ;
44import type { ThirdwebClient } from "../../client/client.js" ;
55import { getContract } from "../../contract/contract.js" ;
6- import { toHex } from "../../utils/encoding/hex.js" ;
7- import { packetToBytes } from "../../utils/ens/packetToBytes.js" ;
86import { withCache } from "../../utils/promise/withCache.js" ;
97import { reverse } from "./__generated__/UniversalResolver/read/reverse.js" ;
108import { 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