Skip to content
Open
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
2 changes: 1 addition & 1 deletion dist/invite/signed-invite.d.ts.map

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

6 changes: 5 additions & 1 deletion dist/invite/signed-invite.js

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

2 changes: 1 addition & 1 deletion dist/invite/signed-invite.js.map

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

7 changes: 6 additions & 1 deletion src/invite/signed-invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export function parseInviteSlug(slugOrUrl: string): ParsedInvite {
const bytes = decodeFromSlug(slug);
const signedInvite = decodeSignedInvite(bytes);
const payload = decodeInvitePayload(signedInvite.payload);
const creatorInboxId = bytesToHex(payload.creatorInboxId);

if (!creatorInboxId || !payload.tag || payload.conversationToken.length === 0) {
throw new Error("Invalid invite payload");
}

const now = BigInt(Math.floor(Date.now() / 1000));
const isExpired = payload.expiresAtUnix !== undefined && payload.expiresAtUnix < now;
Expand All @@ -100,7 +105,7 @@ export function parseInviteSlug(slugOrUrl: string): ParsedInvite {
return {
signedInvite,
payload,
creatorInboxId: bytesToHex(payload.creatorInboxId),
creatorInboxId,
isExpired,
isConversationExpired,
};
Expand Down
5 changes: 5 additions & 0 deletions tests/invite/signed-invite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ describe("signedInvite", () => {
const parsed = parseInviteSlug(url);
expect(parsed.payload.tag).toBe(testTag);
});

it("should reject invite-like strings that decode to an empty payload", () => {
expect(() => parseInviteSlug("8118")).toThrow("Invalid invite payload");
expect(() => parseInviteSlug("6018")).toThrow("Invalid invite payload");
});
});

describe("verifyInvite", () => {
Expand Down