From 1b5b9e8ab690f96ae0bb5ce22d9d77f59c3a5520 Mon Sep 17 00:00:00 2001 From: Frank Barrett Date: Thu, 9 Jul 2026 20:36:11 -0700 Subject: [PATCH] feat: mint share tokens in the same hex style as note ids Share links now read like note links (/p/<32-hex> vs /note/<32-hex>) instead of standing out as 22-char base64url. Entropy is unchanged at 128 bits, and existing tokens keep resolving since lookups are exact string matches. Co-Authored-By: Claude Fable 5 --- __tests__/identifiers.test.ts | 4 ++-- lib/shareToken.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/identifiers.test.ts b/__tests__/identifiers.test.ts index 1241cfb..b0b58bd 100644 --- a/__tests__/identifiers.test.ts +++ b/__tests__/identifiers.test.ts @@ -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}$/); }); }); diff --git a/lib/shareToken.ts b/lib/shareToken.ts index 1f3a558..2486986 100644 --- a/lib/shareToken.ts +++ b/lib/shareToken.ts @@ -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/ reads like /note/; existing base64url tokens still resolve. export function newShareToken() { - return randomBytes(16).toString("base64url"); + return randomBytes(16).toString("hex"); }