Skip to content

Commit d02dbb8

Browse files
committed
fix: records v2 methods for subdomains
Additional fixes for subdomains and record v2 instructions: - updateRecordV2Instruction - deleteRecordV2 - validateRecordV2Content - writRoaRecordV2 - ethValidateRecordV2Content
1 parent 9a595cb commit d02dbb8

4 files changed

Lines changed: 71 additions & 8 deletions

File tree

js/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bonfida/spl-name-service",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"license": "MIT",
55
"files": [
66
"dist"

js/src/bindings.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,15 @@ export const updateRecordV2Instruction = (
626626
owner: PublicKey,
627627
payer: PublicKey,
628628
) => {
629-
const { pubkey, parent } = getDomainKeySync(
629+
let { pubkey, parent, isSub } = getDomainKeySync(
630630
`${record}.${domain}`,
631631
RecordVersion.V2,
632632
);
633+
634+
if (isSub) {
635+
parent = getDomainKeySync(domain).pubkey;
636+
}
637+
633638
if (!parent) {
634639
throw new Error("Invalid parent");
635640
}
@@ -662,11 +667,15 @@ export const deleteRecordV2 = (
662667
owner: PublicKey,
663668
payer: PublicKey,
664669
) => {
665-
const { pubkey, parent } = getDomainKeySync(
670+
let { pubkey, parent, isSub } = getDomainKeySync(
666671
`${record}.${domain}`,
667672
RecordVersion.V2,
668673
);
669674

675+
if (isSub) {
676+
parent = getDomainKeySync(domain).pubkey;
677+
}
678+
670679
if (!parent) {
671680
throw new Error("Invalid parent");
672681
}
@@ -690,11 +699,15 @@ export const validateRecordV2Content = (
690699
payer: PublicKey,
691700
verifier: PublicKey,
692701
) => {
693-
const { pubkey, parent } = getDomainKeySync(
702+
let { pubkey, parent, isSub } = getDomainKeySync(
694703
`${record}.${domain}`,
695704
RecordVersion.V2,
696705
);
697706

707+
if (isSub) {
708+
parent = getDomainKeySync(domain).pubkey;
709+
}
710+
698711
if (!parent) {
699712
throw new Error("Invalid parent");
700713
}
@@ -719,11 +732,15 @@ export const writRoaRecordV2 = (
719732
payer: PublicKey,
720733
roaId: PublicKey,
721734
) => {
722-
const { pubkey, parent } = getDomainKeySync(
735+
let { pubkey, parent, isSub } = getDomainKeySync(
723736
`${record}.${domain}`,
724737
RecordVersion.V2,
725738
);
726739

740+
if (isSub) {
741+
parent = getDomainKeySync(domain).pubkey;
742+
}
743+
727744
if (!parent) {
728745
throw new Error("Invalid parent");
729746
}
@@ -747,11 +764,15 @@ export const ethValidateRecordV2Content = (
747764
signature: Buffer,
748765
expectedPubkey: Buffer,
749766
) => {
750-
const { pubkey, parent } = getDomainKeySync(
767+
let { pubkey, parent, isSub } = getDomainKeySync(
751768
`${record}.${domain}`,
752769
RecordVersion.V2,
753770
);
754771

772+
if (isSub) {
773+
parent = getDomainKeySync(domain).pubkey;
774+
}
775+
755776
if (!parent) {
756777
throw new Error("Invalid parent");
757778
}

js/tests/records-v2.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,45 @@ test("Create record for sub", async () => {
221221
const { value } = await connection.simulateTransaction(tx);
222222
expect(value.err).toBe(null);
223223
});
224+
225+
test("Create record for sub & update & verify staleness & delete", async () => {
226+
const domain = "sub-0.wallet-guide-9";
227+
const owner = new PublicKey("Fxuoy3gFjfJALhwkRcuKjRdechcgffUApeYAfMWck6w8");
228+
const tx = new Transaction();
229+
const ix_create = createRecordV2Instruction(
230+
domain,
231+
Record.Github,
232+
"bonfida",
233+
owner,
234+
owner,
235+
);
236+
tx.add(ix_create);
237+
238+
const ix_update = updateRecordV2Instruction(
239+
domain,
240+
Record.Github,
241+
"somethingelse",
242+
owner,
243+
owner,
244+
);
245+
tx.add(ix_update);
246+
247+
const ix_verify = validateRecordV2Content(
248+
true,
249+
domain,
250+
Record.Github,
251+
owner,
252+
owner,
253+
owner,
254+
);
255+
tx.add(ix_verify);
256+
257+
const ix_delete = deleteRecordV2(domain, Record.Github, owner, owner);
258+
tx.add(ix_delete);
259+
260+
tx.feePayer = owner;
261+
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
262+
263+
const { value } = await connection.simulateTransaction(tx);
264+
expect(value.err).toBe(null);
265+
});

0 commit comments

Comments
 (0)