Skip to content
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 __tests__/identifiers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ describe("opaque identifiers", () => {
expect(newId()).toMatch(/^[0-9a-f]{32}$/);
});

it("uses 128-bit URL-safe share credentials", () => {
it("mints share credentials in the same 128-bit hex style as note ids", () => {
const tokens = Array.from({ length: 100 }, () => newShareToken());
expect(new Set(tokens)).toHaveLength(tokens.length);
for (const token of tokens) expect(token).toMatch(/^[A-Za-z0-9_-]{22}$/);
for (const token of tokens) expect(token).toMatch(/^[0-9a-f]{32}$/);
});
});
6 changes: 3 additions & 3 deletions lib/shareToken.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomBytes } from "crypto";

// Share links are bearer credentials. Use 128 bits so they remain unguessable
// even with many active links; existing shorter tokens continue to resolve.
// Share links are bearer credentials. 128 bits, rendered as 32 hex chars so
// /p/<token> reads like /note/<id>; existing base64url tokens still resolve.
export function newShareToken() {
return randomBytes(16).toString("base64url");
return randomBytes(16).toString("hex");
}
Loading