From 6c70827f745069184f13ab62df44ee8e636db07b Mon Sep 17 00:00:00 2001 From: DR497 <47689875+dr497@users.noreply.github.com> Date: Thu, 22 Feb 2024 16:29:50 +0800 Subject: [PATCH] js: don't use `resolve` to validate staleness --- js/src/favorite-domain.ts | 7 ++++++- js/src/record_v2/utils.ts | 11 ++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/js/src/favorite-domain.ts b/js/src/favorite-domain.ts index 4debe601..eea2ca11 100644 --- a/js/src/favorite-domain.ts +++ b/js/src/favorite-domain.ts @@ -13,6 +13,7 @@ import { AccountLayout, getAssociatedTokenAddressSync, } from "@solana/spl-token"; +import { NameRegistryState } from "./state"; export const NAME_OFFERS_ID = new PublicKey( "85iDfUvr3HJyLM2zcq5BXSiDvUWfw6cSE1FfNBo8Ap29", @@ -101,7 +102,11 @@ export const getFavoriteDomain = async ( const favorite = await FavouriteDomain.retrieve(connection, favKey); const reverse = await reverseLookup(connection, favorite.nameAccount); - const domainOwner = await resolve(connection, reverse); + const { registry, nftOwner } = await NameRegistryState.retrieve( + connection, + favorite.nameAccount, + ); + const domainOwner = nftOwner || registry.owner; return { domain: favorite.nameAccount, diff --git a/js/src/record_v2/utils.ts b/js/src/record_v2/utils.ts index eb9bcaad..a0f51dac 100644 --- a/js/src/record_v2/utils.ts +++ b/js/src/record_v2/utils.ts @@ -1,8 +1,9 @@ import { Connection, PublicKey } from "@solana/web3.js"; import { Record } from "../types/record"; -import { resolve } from "../resolve"; import { getRecordV2Key } from "."; import { Record as SnsRecord, Validation } from "@bonfida/sns-records"; +import { NameRegistryState } from "../state"; +import { getDomainKeySync } from "../utils"; /** * This function verifies the staleness of a record. @@ -17,13 +18,17 @@ export const verifyStaleness = async ( domain: string, ) => { const recordKey = getRecordV2Key(domain, record); - const owner = await resolve(connection, domain); + const { registry, nftOwner } = await NameRegistryState.retrieve( + connection, + getDomainKeySync(domain).pubkey, + ); + const owner = nftOwner || registry.owner; const recordObj = await SnsRecord.retrieve(connection, recordKey); const stalenessId = recordObj.getStalenessId(); return ( - owner.equals(new PublicKey(stalenessId)) && + owner?.equals(new PublicKey(stalenessId)) && recordObj.header.stalenessValidation === Validation.Solana ); };