Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/deserialize reverse null byte #91

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "3.0.4",
"version": "3.0.5",
"license": "MIT",
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion js/src/favorite-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const getMultipleFavoriteDomains = async (
const nativeOwner = new PublicKey(domainInfo?.data.slice(32, 64));

if (nativeOwner.equals(wallets[i])) {
result.push(deserializeReverse(rev?.data.slice(96)) + parentRev);
result.push(deserializeReverse(rev?.data.slice(96), true) + parentRev);
continue;
}
// Either tokenized or stale
Expand Down
13 changes: 10 additions & 3 deletions js/src/utils/deserializeReverse.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { Buffer } from "buffer";

export function deserializeReverse(data: Buffer): string;
export function deserializeReverse(data: undefined): undefined;
export function deserializeReverse(
data: Buffer,
trimFirstNullByte?: boolean,
): string;
export function deserializeReverse(
data: undefined,
trimFirstNullByte?: boolean,
): undefined;

export function deserializeReverse(
data: Buffer | undefined,
trimFirstNullByte = false,
): string | undefined {
if (!data) return undefined;
const nameLength = data.slice(0, 4).readUInt32LE(0);
return data
.slice(4, 4 + nameLength)
.toString()
.replace(/\0/g, "");
.replace(/^\0/, trimFirstNullByte ? "" : "\0");
}
4 changes: 2 additions & 2 deletions js/src/utils/findSubdomains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const findSubdomains = async (
const map = new Map<string, string | undefined>(
reverses.map((e) => [
e.pubkey.toBase58(),
deserializeReverse(e.account.data.slice(96)),
deserializeReverse(e.account.data.slice(96), true),
]),
);

Expand All @@ -59,7 +59,7 @@ export const findSubdomains = async (
const revKey = getReverseKeyFromDomainKey(e.pubkey, parentKey).toBase58();
const rev = map.get(revKey);
if (!!rev) {
result.push(rev.replace("\0", ""));
result.push(rev);
}
});

Expand Down
2 changes: 1 addition & 1 deletion js/src/utils/reverseLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export async function reverseLookup(
throw new NoAccountDataError("The registry data is empty");
}

return deserializeReverse(registry.data);
return deserializeReverse(registry.data, !!parent);
}
1 change: 1 addition & 0 deletions js/tests/registration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getReverseKeySync } from "../src/utils/getReverseKeySync";
import { Metaplex } from "@metaplex-foundation/js";

jest.setTimeout(20_000);
jest.retryTimes(3);
const FIDA_MINT = new PublicKey("EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp");
const PYTH_MINT = new PublicKey("HZ1JovNiVvGrGNiiYvEozEVgZ58xaU3RKwX8eACQBCt3");

Expand Down
8 changes: 4 additions & 4 deletions js/tests/twitter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ test("Resolution & derivation", async () => {
const expected = {
handle: "plenthor",
registry: "HrguVp54KnhQcRPaEBULTRhC2PWcyGTQBfwBNVX9SW2i",
reverse: "RyRmCEVW4wq8xaRGh3sPvp2HDDzb3BgGGMavnXZrbWG",
reverse: "C2MB7RDr4wdwSHAPZ8f5qmScYSUHdPKTL6t5meYdcjjW",
};
const owner = new PublicKey("FSMFjujJ1Xi2CN424e4wfFsSMNcdYDGktsuxunazsnjd");
const owner = new PublicKey("JB27XSKgYFBsuxee5yAS2yi1NKSU6WV5GZrKdrzeTHYC");

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -74,7 +74,7 @@ test("Create instruction", async () => {

const handle = randomBytes(10).toString("hex");
const user = Keypair.generate().publicKey;
const payer = new PublicKey("FSMFjujJ1Xi2CN424e4wfFsSMNcdYDGktsuxunazsnjd");
const payer = new PublicKey("JB27XSKgYFBsuxee5yAS2yi1NKSU6WV5GZrKdrzeTHYC");

const ix = await createVerifiedTwitterRegistry(
connection,
Expand All @@ -98,7 +98,7 @@ test("Create & delete instruction", async () => {

const handle = randomBytes(10).toString("hex");
const user = Keypair.generate().publicKey;
const payer = new PublicKey("FSMFjujJ1Xi2CN424e4wfFsSMNcdYDGktsuxunazsnjd");
const payer = new PublicKey("JB27XSKgYFBsuxee5yAS2yi1NKSU6WV5GZrKdrzeTHYC");

tx.add(
...(await createVerifiedTwitterRegistry(
Expand Down
Loading