V2 Records

Get Record V2

Single records can be obtained using the getRecordV2function. The optional final argument to the function is an object with a key of deserialized with a boolean value to indicate if the response should be deserialized.

import { Record, getRecordV2 } from "@bonfida/spl-name-service";

const recordOptions = { deserialize: true };

const discordRecord = getRecordV2(connection, domain, Record.Discord, recordOptions);

Get multiple V2 Records

import { Record, getMultipleRecordsV2 } from "@bonfida/spl-name-service";

const recordsToFetch = [Record.Discord, Record.Twitter, Record.Telegram];

const recordOptions = { deserialize: true };

const domainRecords = getMultipleRecordsV2(
  connection,
  domain,
  recordsToFetch,
  recordOptions,
 );

Verify Staleness and Verify Right of Association

The introduction of Records V2 improves on-chain trust by introducing the verifyStaleness method to ensure records are not stale, and the verifyRightOfAssociation to ensure records are authentic. These functions are described in detail below.

Verify Staleness

You're able to verify the staleness of a record with Records V2. A record is stale when it was set up by a previous domain owner, and is no longer relevant to the current owner. The function returns a boolean indicating if the record is fresh or not.

import { verifyStaleness } from "@bonfida/spl-name-service";

const isFreshRecord = await verifyStaleness(connection, record, domain);

Verify Right of Association

You're also able to verify the authenticity of a record with Records V2 using the verifyRightOfAssociation function. The function returns a boolean indicating if the record is authentic or not. Unique to this function is the verifier parameter, which is the known public key of the on-chain/off-chain oracle used to verify authenticity of a record. This is currently supported for SOL, ETH, INJ, BNB, URL, and CNAME records with support for further records on the way.

import { verifyRightOfAssociation, GUARDIANS } from "@bonfida/spl-name-service";

const verifier = GUARDIANS.get(Record.URL); 

const ROA = await verifyRightOfAssociation(
  connection,
  record,
  domain,
  verifier.toBuffer()
);

ETH, SOL, BNB, and INJ records are unique because they are self signing. To verify the authenticity of these records, we must pass the content of the record itself as the verifier agrument to the verifyRightOfAssociation function.

const { retrievedRecord } = await getRecordV2(connection, domain, record); // Import getRecordV2 from the spl-name-service library

const ROA = await verifyRightOfAssociation(
  connection,
  record,
  domain,
  retrievedRecord.getContent()
);

Walkthrough

For a detailed walkthrough tutorial outlining the Records V2 upgrade, as well as examples on how to fetch stalesness and right of association, check out the video below.

Last updated