Skip to content

Commit

Permalink
Fix: Add fallback value when Solana v2 record unverified
Browse files Browse the repository at this point in the history
  • Loading branch information
akashrdev committed Feb 5, 2025
1 parent 61bb365 commit 6df472a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
53 changes: 29 additions & 24 deletions js/src/resolve/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,40 @@ export const resolve = async (

// Check SOL record V2
recordV2: if (solRecordV2Info?.data) {
const recordV2 = RecordV2.deserialize(solRecordV2Info.data);
const stalenessId = recordV2.getStalenessId();
const roaId = recordV2.getRoAId();
const content = recordV2.getContent();
try {
const recordV2 = RecordV2.deserialize(solRecordV2Info.data);
const stalenessId = recordV2.getStalenessId();
const roaId = recordV2.getRoAId();
const content = recordV2.getContent();

if (content.length !== 32) {
throw new RecordMalformed(`Record is malformed`);
}

if (content.length !== 32) {
throw new RecordMalformed(`Record is malformed`);
}
if (
recordV2.header.rightOfAssociationValidation !== Validation.Solana ||
recordV2.header.stalenessValidation !== Validation.Solana
) {
throw new WrongValidation();
}

if (
recordV2.header.rightOfAssociationValidation !== Validation.Solana ||
recordV2.header.stalenessValidation !== Validation.Solana
) {
throw new WrongValidation();
}
if (!stalenessId.equals(registry.owner.toBuffer())) {
break recordV2;
}

if (!stalenessId.equals(registry.owner.toBuffer())) {
break recordV2;
}
if (roaId.equals(content)) {
return new PublicKey(content);
}

if (roaId.equals(content)) {
return new PublicKey(content);
throw new InvalidRoAError(
`The RoA ID shoudl be ${new PublicKey(
content,
).toBase58()} but is ${new PublicKey(roaId).toBase58()} `,
);
} catch (error) {
console.error("Error in V2 record", error);
return registry.owner;
}

throw new InvalidRoAError(
`The RoA ID shoudl be ${new PublicKey(
content,
).toBase58()} but is ${new PublicKey(roaId).toBase58()} `,
);
}

// Check SOL record V1
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

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

0 comments on commit 6df472a

Please sign in to comment.