Skip to content

Commit

Permalink
fix: circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dr497 committed Jan 8, 2024
1 parent cd47d1b commit 98f7a63
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
1 change: 1 addition & 0 deletions js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export * from "./deprecated/utils";
export * from "./error";
export * from "./custom-bg";
export * from "./record_v2";
export * from "./record_v2/utils";
export * from "./devnet";
31 changes: 3 additions & 28 deletions js/src/record_v2.ts → js/src/record_v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { Record } from "./types/record";
import { ErrorType, SNSError } from "./error";
import { Record } from "../types/record";
import { ErrorType, SNSError } from "../error";
import { Connection, PublicKey } from "@solana/web3.js";
import { encode as encodePunycode, decode as decodePunnycode } from "punycode";
import {
check,
getDomainKeySync,
getHashedNameSync,
getNameAccountKeySync,
} from "./utils";
} from "../utils";
import { decode, encode } from "bech32-buffer";
import ipaddr from "ipaddr.js";
import {
CENTRAL_STATE_SNS_RECORDS,
Record as SnsRecord,
Validation,
} from "@bonfida/sns-records";
import { resolve } from "./resolve";

/**
* A map that associates each record type with a public key, known as guardians.
Expand All @@ -33,30 +32,6 @@ export const ETH_ROA_RECORDS = new Set<Record>([
Record.BSC,
]);

/**
* This function verifies the staleness of a record.
* @param {Connection} connection - The Solana RPC connection object
* @param {Record} record - The record to be verified.
* @param {string} domain - The domain associated with the record.
* @returns {Promise<boolean>} - Returns a promise that resolves to a boolean indicating whether the record is stale.
*/
export const verifyStaleness = async (
connection: Connection,
record: Record,
domain: string,
) => {
const recordKey = getRecordV2Key(domain, record);
const owner = await resolve(connection, domain);
const recordObj = await SnsRecord.retrieve(connection, recordKey);

const stalenessId = recordObj.getStalenessId();

return (
owner.equals(new PublicKey(stalenessId)) &&
recordObj.header.stalenessValidation === Validation.Solana
);
};

/**
*
* This function verifies the right of association of a record.
Expand Down
29 changes: 29 additions & 0 deletions js/src/record_v2/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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";

/**
* This function verifies the staleness of a record.
* @param {Connection} connection - The Solana RPC connection object
* @param {Record} record - The record to be verified.
* @param {string} domain - The domain associated with the record.
* @returns {Promise<boolean>} - Returns a promise that resolves to a boolean indicating whether the record is stale.
*/
export const verifyStaleness = async (
connection: Connection,
record: Record,
domain: string,
) => {
const recordKey = getRecordV2Key(domain, record);
const owner = await resolve(connection, domain);
const recordObj = await SnsRecord.retrieve(connection, recordKey);

const stalenessId = recordObj.getStalenessId();

return (
owner.equals(new PublicKey(stalenessId)) &&
recordObj.header.stalenessValidation === Validation.Solana
);
};
8 changes: 7 additions & 1 deletion js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
},
"resolveJsonModule": true
},
"include": ["src/*", "src/.ts", "src/deprecated/.ts", "src/nft/index.ts"],
"include": [
"src/*",
"src/.ts",
"src/deprecated/.ts",
"src/nft/index.ts",
"src/record_v2/index.ts"
],
"exclude": ["src/**/*.test.ts", "**/node_modules", "dist"]
}

0 comments on commit 98f7a63

Please sign in to comment.