Skip to content

Commit

Permalink
js: don't use resolve to validate staleness
Browse files Browse the repository at this point in the history
  • Loading branch information
dr497 committed Feb 22, 2024
1 parent d747124 commit 6c70827
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion js/src/favorite-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
AccountLayout,
getAssociatedTokenAddressSync,
} from "@solana/spl-token";
import { NameRegistryState } from "./state";

export const NAME_OFFERS_ID = new PublicKey(
"85iDfUvr3HJyLM2zcq5BXSiDvUWfw6cSE1FfNBo8Ap29",
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions js/src/record_v2/utils.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
);
};

0 comments on commit 6c70827

Please sign in to comment.