Skip to content

Commit

Permalink
[DT-902] fix: Added final validation for Ens.reverseOf()
Browse files Browse the repository at this point in the history
  • Loading branch information
DChan0319 committed Sep 26, 2023
1 parent faa6b80 commit 2dcdb11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default class Ens extends NamingService {
// Current implementation uses reverseRegistrarContract to fetch the correct node hash.
// @see: https://eips.ethereum.org/EIPS/eip-181
async reverseOf(address: string): Promise<string | null> {
const originalAddress = address;
if (address.startsWith('0x')) {
address = address.substr(2);
}
Expand Down Expand Up @@ -225,7 +226,16 @@ export default class Ens extends NamingService {
this.proxyServiceApiKey,
);

return await this.resolverCallToName(resolverContract, nodeHash);
const domainName = await this.resolverCallToName(
resolverContract,
nodeHash,
);
const fetchedAddress = await this.addr(domainName, BlockchainType.ETH);
if (fetchedAddress?.toLowerCase() !== originalAddress.toLowerCase()) {
return null;
}

return domainName;
}

async getTokenUri(domain: string): Promise<string> {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/Ens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {NullAddress} from '../types';
import {
expectResolutionErrorCode,
expectSpyToBeCalled,
mockAsyncMethod,
mockAsyncMethods,
getProtocolLinkFromEnv,
ProviderProtocol,
Expand Down Expand Up @@ -69,6 +68,7 @@ describe('ENS', () => {
reverseRegistrarCallToNode:
'0x4da70a332a7a98a58486f551a455b1398ce309d9bd3a4f0800da4eec299829a4',
callMethod: '0xDa1756Bb923Af5d1a05E277CB1E54f1D0A127890',
addr: '0xb0E7a465D255aE83eb7F8a50504F3867B945164C',
resolverCallToName: 'adrian.argent.xyz',
});
const result = await ens?.reverseOf(
Expand Down

0 comments on commit 2dcdb11

Please sign in to comment.