Skip to content

Commit

Permalink
fix: records v2 methods for subdomains
Browse files Browse the repository at this point in the history
Additional fixes for subdomains and record v2 instructions:
- updateRecordV2Instruction
- deleteRecordV2
- validateRecordV2Content
- writRoaRecordV2
- ethValidateRecordV2Content
  • Loading branch information
dr497 committed Dec 6, 2023
1 parent 9a595cb commit d02dbb8
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
4 changes: 2 additions & 2 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bonfida/spl-name-service",
"version": "2.0.2",
"version": "2.0.3",
"license": "MIT",
"files": [
"dist"
Expand Down
31 changes: 26 additions & 5 deletions js/src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,15 @@ export const updateRecordV2Instruction = (
owner: PublicKey,
payer: PublicKey,
) => {
const { pubkey, parent } = getDomainKeySync(
let { pubkey, parent, isSub } = getDomainKeySync(
`${record}.${domain}`,
RecordVersion.V2,
);

if (isSub) {
parent = getDomainKeySync(domain).pubkey;
}

if (!parent) {
throw new Error("Invalid parent");
}
Expand Down Expand Up @@ -662,11 +667,15 @@ export const deleteRecordV2 = (
owner: PublicKey,
payer: PublicKey,
) => {
const { pubkey, parent } = getDomainKeySync(
let { pubkey, parent, isSub } = getDomainKeySync(
`${record}.${domain}`,
RecordVersion.V2,
);

if (isSub) {
parent = getDomainKeySync(domain).pubkey;
}

if (!parent) {
throw new Error("Invalid parent");
}
Expand All @@ -690,11 +699,15 @@ export const validateRecordV2Content = (
payer: PublicKey,
verifier: PublicKey,
) => {
const { pubkey, parent } = getDomainKeySync(
let { pubkey, parent, isSub } = getDomainKeySync(
`${record}.${domain}`,
RecordVersion.V2,
);

if (isSub) {
parent = getDomainKeySync(domain).pubkey;
}

if (!parent) {
throw new Error("Invalid parent");
}
Expand All @@ -719,11 +732,15 @@ export const writRoaRecordV2 = (
payer: PublicKey,
roaId: PublicKey,
) => {
const { pubkey, parent } = getDomainKeySync(
let { pubkey, parent, isSub } = getDomainKeySync(
`${record}.${domain}`,
RecordVersion.V2,
);

if (isSub) {
parent = getDomainKeySync(domain).pubkey;
}

if (!parent) {
throw new Error("Invalid parent");
}
Expand All @@ -747,11 +764,15 @@ export const ethValidateRecordV2Content = (
signature: Buffer,
expectedPubkey: Buffer,
) => {
const { pubkey, parent } = getDomainKeySync(
let { pubkey, parent, isSub } = getDomainKeySync(
`${record}.${domain}`,
RecordVersion.V2,
);

if (isSub) {
parent = getDomainKeySync(domain).pubkey;
}

if (!parent) {
throw new Error("Invalid parent");
}
Expand Down
42 changes: 42 additions & 0 deletions js/tests/records-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,45 @@ test("Create record for sub", async () => {
const { value } = await connection.simulateTransaction(tx);
expect(value.err).toBe(null);
});

test("Create record for sub & update & verify staleness & delete", async () => {
const domain = "sub-0.wallet-guide-9";
const owner = new PublicKey("Fxuoy3gFjfJALhwkRcuKjRdechcgffUApeYAfMWck6w8");
const tx = new Transaction();
const ix_create = createRecordV2Instruction(
domain,
Record.Github,
"bonfida",
owner,
owner,
);
tx.add(ix_create);

const ix_update = updateRecordV2Instruction(
domain,
Record.Github,
"somethingelse",
owner,
owner,
);
tx.add(ix_update);

const ix_verify = validateRecordV2Content(
true,
domain,
Record.Github,
owner,
owner,
owner,
);
tx.add(ix_verify);

const ix_delete = deleteRecordV2(domain, Record.Github, owner, owner);
tx.add(ix_delete);

tx.feePayer = owner;
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;

const { value } = await connection.simulateTransaction(tx);
expect(value.err).toBe(null);
});

0 comments on commit d02dbb8

Please sign in to comment.