Skip to content

feat(uniku): derive stable IDs with name-based uuid/v5 - #106

Merged
jkomyno merged 14 commits into
mainfrom
feat/uuid-v5
Nov 11, 2026
Merged

jkomyno merged 14 commits into
mainfrom
feat/uuid-v5

Conversation

@jkomyno

@jkomyno jkomyno commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

uniku can now derive a stable ID from an identifier you already hold: uniku/uuid/v5 returns the same RFC 9562 UUID v5 for the same name and namespace in every process and runtime, with no state to keep. The CLI exposes it as uniku uuid -v 5 --namespace <dns|url|oid|x500|uuid> --name <value>.

import { uuidv5 } from 'uniku/uuid/v5'

uuidv5('www.example.com', uuidv5.DNS) // '2ed6657d-e927-568b-95e1-2665a8aea6a2' (RFC 9562 A.4)

const sessionId = uuidv5.namespace(APP_NAMESPACE) // parse the namespace once
sessionId('tool-a:3f2c')

Fixes #105

Decisions on the issue's open questions

Question Decision
Sync or async Synchronous, like every other generator. SHA-1 is a small inlined implementation, so the entry point has no dependency and imports only the shared error, validation, and UUID codec chunks.
SHA-1 No UUID v8 / SHA-256 entry point. The docs say SHA-1 is fine for identity but not a security boundary.
String encoding UTF-8 without Unicode normalization, matching the uuid package. Lone surrogates hash as U+FFFD, where uuid throws instead. Both behaviors are pinned by tests, documented, and listed in STABILITY.md as fixed for 1.x.
Reversibility Documented as an identifier, not a secret.
Timestamp No timestamp(), as on uuid/v4.

TypeID. The issue's typeid.fromUuid('sess', uuidv5(...)) now works. The TypeID spec (v0.3.0) only requires generated TypeIDs to be UUID v7, and says implementations SHOULD encode and decode other versions. uniku rejected 8 of the spec's 9 valid test vectors with UUID_NOT_V7, including nil and max. Now:

  • fromUuid, fromBytes, toUuid, toBytes, prefix, suffix and isValid accept any 128-bit value, which matches typeid-js.
  • typeid() still generates UUID v7.
  • typeid.timestamp() is the only function that throws UUID_NOT_V7, for a TypeID that does not wrap a UUID v7.
  • fromUuid with a string that is not a UUID now throws ParseError (INVALID_LENGTH, INVALID_FORMAT or INVALID_CHAR, strategy typeid) instead of UUID_NOT_V7. This has its own minor changeset.

Errors. No new error codes. A malformed namespace string throws ParseError, namespace bytes that are not 16 long throw InvalidInputError (BYTES_INVALID_LENGTH), and a bad offset throws BufferError. Values outside the TypeScript signatures, such as null, still throw a native TypeError, as they do in every other generator.

CLI. -v 5 requires both --name and --namespace. Either flag with v4 or v7 is a usage error, and so is -n above 1, because every output would be the same ID. uniku inspect and uniku validate now report v5 IDs as UUID v5. Before, auto-detection classified them as Nanoid.

Changes outside the new module

  • Entry-point isolation check. publish-smoke now fails if any packed generator imports another generator's module, following both relative and bare uniku/* imports. The two existing generator-to-generator imports are allowed by name: typeid uses uuid/v7, and cuid/v2 uses cuid2. I checked it catches a planted uniku/uuid/v4 import in the built v5 file.
  • Benchmark baseline. mergeBenchmarkHistory now drops baseline entries measured on a different set of benchmarks, so the rolling window restarts. Without this, the new v5 benchmark rows would make the baseline job throw Benchmark matrix mismatch on the first push to main.
  • CLI npm install fix. npm i -g @uniku/cli crashed on startup, and so did CI's global-install check, until this PR. @effect/[email protected] accepts @effect/platform-node-shared@^4.0.0-beta.93, and npm now resolves that range to 4.1.3, which imports an effect module that the pinned 4.0.0-beta.93 does not have. The CLI now depends on @effect/[email protected] directly, so npm reuses that version. This was already broken before this PR and showed up because CI had not run since August.
  • CLI and TypeID. uniku validate and uniku inspect report the UUID version a TypeID wraps. They used to hard-code v7. Inspecting a non-v7 TypeID shows no timestamp and adds a note. Auto-detection still treats a prefixless TypeID as a ULID unless it wraps a UUID v7, because every lowercase ULID is also a valid prefixless TypeID.
  • No Node.js Buffer in the library. A Biome rule now rejects the Buffer global and buffer/node:buffer imports in packages/uniku/src. uuidv5.namespace() copies namespace bytes with new Uint8Array(...), because .slice() on a caller's Buffer returns a view of the same memory.
  • CLI release. @uniku/cli is out of the Changesets ignore list, which it joined in August for the library-only 0.6.0 release. A patch changeset ships uuid -v 5 and the npm install fix as @uniku/cli 0.7.1. The move to Effect 4.1.x and a CLI minor release is Release a @uniku/cli minor version on Effect 4.1.x #107.
  • Bundle table. I regenerated the table in performance.mdx. Several existing sizes were stale, for example typeid and errors.

Performance

Local runs on Node 25, uniku against the uuid package's v5. These are directional numbers. The CI benchmark comment on this PR shows 3.1x, 2x, and 1.8x for the same three rows.

Benchmark uniku uuid Ratio
Generate, 'www.example.com' 1.11M ops/s 582K ops/s 1.9x
Generate, 256-character name 444K ops/s 332K ops/s 1.3x
Validate 9.59M ops/s 5.46M ops/s 1.8x

uuidv5.namespace() runs at about 2.36M ops/s, against 1.13M for the two-argument call, because the two-argument call parses the namespace string each time. The library does not cache it, as the issue asks. The built uuid/v5 entry is about 1.8 KB. The UUID parser now takes the error strategy as a parameter, which adds 9 bytes gzipped to the UUID entries and moves uuid/v7 from ~1.6 KB to ~1.7 KB in the table. TypeID shrinks by 28 bytes.

Verification

  • 30 v5 unit tests, including:
    • the RFC 9562 A.4 vector
    • a node:crypto SHA-1 check for every name length from 0 to 200 bytes, which crosses each padding boundary, plus names of 10,000 and 70,000 bytes
    • UTF-8 input, NFC against NFD, and lone surrogates
    • buffer offsets, and name or namespace bytes used as the output buffer
    • namespace() keeping its own copy of the namespace bytes
  • Integration tests compare against uuid@14 v5 with random Unicode and byte names and random namespaces.
  • TypeID now passes all of the spec's valid.yml and invalid.yml vectors, and an integration test checks UUID v4, v5 and v7 conversions against typeid-js.
  • 27 new CLI tests.
  • Runtime smoke passes on Node, Bun, Deno, and Chromium. The Cloudflare Workers e2e suite passes 63/63, and the runtime checks assert the exact v5 vectors.
  • pnpm test (547 uniku tests, 256 CLI tests), pnpm typecheck, pnpm lint:ci, the docs typecheck and build, publish smoke, attw, and publint all pass.

Not included, as the issue's out-of-scope list says: a cache, HMAC-keyed derivation, and a SHA-256 variant. The meta tags in apps/docs/src/routes/__root.tsx still say "ten" strategies. That file had unrelated uncommitted edits, so I left it out of this PR.

Derive a stable RFC 9562 UUID v5 from a name and namespace with a
synchronous, dependency-free SHA-1. Adds uuidv5.namespace() to parse a
namespace once, plus the DNS, URL, OID, and X500 namespace constants.
Add --name and --namespace (dns, url, oid, x500, or a UUID) for name-based
UUIDs, and recognize v5 IDs in inspect and validate.
Check the RFC 9562 vector on Node, Bun, Deno, browsers, and Cloudflare
Workers, add v5 generation and validation benchmarks against npm uuid,
assert in publish-smoke that each entry point imports no other generator,
and restart the rolling benchmark baseline when the benchmark set changes.
Add the UUID v5 reference page and cover derived IDs in the choosing
guide, uuid migration guide, stability contract, and entry point lists.
Document that lone surrogates hash as U+FFFD, cover name and namespace
bytes aliasing the output buffer, and make the publish-smoke isolation
check follow bare uniku/* self-imports too.
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Preview removed because the pull request was closed.

@effect/[email protected] depends on platform-node-shared
^4.0.0-beta.93, which npm now resolves to 4.1.3. That version imports
effect modules missing from [email protected], so a global npm install
of @uniku/cli crashed on startup. A direct exact dependency makes npm
dedupe the transitive to the pinned beta.
@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/@uniku/cli@106
pnpm add https://pkg.pr.new/uniku@106

commit: 343f72d

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results

Generation

ID uniku npm/regex Comparison
ULID 6.4M ops/s 36K ops/s 176.8x faster ⚠️ ±14.3%
UUID v7 4.7M ops/s 613.9K ops/s 7.7x faster
CUID2 57.2K ops/s 8.5K ops/s 6.8x faster ⚠️ ±3.8%
TypeID 2.7M ops/s 720.6K ops/s 3.8x faster
UUID v5 1.5M ops/s 468.1K ops/s 3.2x faster ⚠️ ±8.1%
TSID 7.8M ops/s 3.5M ops/s 2.3x faster
UUID v5 (256-char name) 500.3K ops/s 244.2K ops/s 2x faster ⚠️ ±12.6%
NanoID 13.5M ops/s 7.2M ops/s 1.9x faster
KSUID 490.3K ops/s 286.2K ops/s 1.7x faster ⚠️ ±3.6%
NanoID (10) 16.4M ops/s 10.5M ops/s 1.6x faster ⚠️ ±17.2%
XID 9.4M ops/s 7.5M ops/s 1.3x faster
ObjectID 6.5M ops/s 5.2M ops/s 1.3x faster
UUID v4 15.5M ops/s 12.5M ops/s 1.2x faster

Validation

ID uniku npm/regex Comparison
KSUID 13.1M ops/s 906.9K ops/s 14.4x faster ⚠️ ±3.4%
TypeID 6.1M ops/s 1.4M ops/s 4.4x faster
TSID 5.8M ops/s 2M ops/s 2.9x faster ⚠️ ±8.2%
XID 14.2M ops/s 5.9M ops/s 2.4x faster
UUID v7 13.2M ops/s 7.1M ops/s 1.8x faster
UUID v4 12.8M ops/s 7.3M ops/s 1.8x faster
UUID v5 12.6M ops/s 7.3M ops/s 1.7x faster
CUID2 17.6M ops/s 18.3M ops/s ~parity
ObjectID 14.1M ops/s 14.8M ops/s ~parity
ULID 12.9M ops/s 14.3M ops/s regex 1.1x faster
NanoID 17M ops/s 19.4M ops/s regex 1.1x faster

Cold Start (Node)

Generator Process to exit (median / p95) Import + first ID (median / p95)
uuid/v4 24.3 ms / 27.6 ms 4.1 ms / 4.3 ms
uuid/v5 22.2 ms / 24.2 ms 2.9 ms / 3.0 ms
uuid/v7 24.4 ms / 28.0 ms 4.4 ms / 4.5 ms
ulid 24.9 ms / 29.0 ms 4.3 ms / 4.5 ms
typeid 25.4 ms / 28.5 ms 4.9 ms / 5.2 ms
cuid2 31.7 ms / 60.7 ms 11.1 ms / 11.8 ms
cuid/v2 31.1 ms / 42.8 ms 11.2 ms / 15.2 ms
nanoid 25.0 ms / 35.0 ms 3.9 ms / 5.3 ms
ksuid 25.8 ms / 28.2 ms 4.8 ms / 5.5 ms
objectid 25.3 ms / 27.4 ms 4.8 ms / 5.2 ms
tsid 25.9 ms / 27.9 ms 4.5 ms / 4.6 ms
xid 27.6 ms / 29.8 ms 5.1 ms / 5.5 ms

Comparison vs Main

Benchmark Baseline Current Change
tests/bench/compat.bench.ts > Validation > KSUID > uniku 6.5M ops/s 13.1M ops/s 🟢 +101.0% (+/-12.6% RME)
tests/bench/compat.bench.ts > Validation > ObjectID > uniku 7.3M ops/s 14.1M ops/s 🟢 +94.0% (+/-10.8% RME)
tests/bench/compat.bench.ts > Validation > XID > uniku 7.4M ops/s 14.2M ops/s 🟢 +92.0% (+/-14.7% RME)
tests/bench/compat.bench.ts > Validation > UUID v7 > uniku 6.9M ops/s 13.2M ops/s 🟢 +91.3% (+/-9.5% RME)
tests/bench/compat.bench.ts > Validation > UUID v4 > uniku 6.7M ops/s 12.8M ops/s 🟢 +90.7% (+/-14.1% RME)
tests/bench/compat.bench.ts > Generation > UUID v4 > uniku 8.2M ops/s 15.5M ops/s 🟢 +89.0% (+/-6.5% RME)
tests/bench/compat.bench.ts > Generation > ULID > uniku 3.4M ops/s 6.4M ops/s 🟢 +88.7% (+/-20.0% RME)
tests/bench/compat.bench.ts > Validation > CUID2 > uniku 9.4M ops/s 17.6M ops/s 🟢 +86.6% (+/-12.4% RME)
tests/bench/compat.bench.ts > Validation > TypeID > uniku 3.3M ops/s 6.1M ops/s 🟢 +83.3% (+/-29.1% RME)
tests/bench/compat.bench.ts > Generation > NanoID (10) > uniku 9.2M ops/s 16.4M ops/s 🟢 +78.3% (+/-8.4% RME)
tests/bench/compat.bench.ts > Validation > NanoID > uniku 9.6M ops/s 17M ops/s 🟢 +77.9% (+/-16.3% RME)
tests/bench/compat.bench.ts > Generation > TypeID > uniku 1.5M ops/s 2.7M ops/s 🟢 +77.2% (+/-10.6% RME)
tests/bench/compat.bench.ts > Validation > ULID > uniku 7.3M ops/s 12.9M ops/s 🟢 +77.1% (+/-10.9% RME)
tests/bench/compat.bench.ts > Generation > ObjectID > uniku 3.7M ops/s 6.5M ops/s 🟢 +77.0% (+/-6.6% RME)
tests/bench/compat.bench.ts > Generation > NanoID > uniku 7.7M ops/s 13.5M ops/s 🟢 +75.4% (+/-13.9% RME)
tests/bench/compat.bench.ts > Generation > UUID v7 > uniku 2.7M ops/s 4.7M ops/s 🟢 +74.7% (+/-8.4% RME)
tests/bench/compat.bench.ts > Generation > TSID > uniku 4.6M ops/s 7.8M ops/s 🟢 +69.7% (+/-5.5% RME)
tests/bench/compat.bench.ts > Validation > TSID > uniku 3.4M ops/s 5.8M ops/s 🟢 +69.3% (+/-17.7% RME)
tests/bench/compat.bench.ts > Generation > CUID2 > uniku 34.2K ops/s 57.2K ops/s 🟢 +67.3% (+/-10.6% RME)
tests/bench/compat.bench.ts > Generation > KSUID > uniku 294.7K ops/s 490.3K ops/s 🟢 +66.4% (+/-13.9% RME)
tests/bench/compat.bench.ts > Generation > XID > uniku 5.7M ops/s 9.4M ops/s 🟢 +65.0% (+/-14.1% RME)
tests/bench/compat.bench.ts > Validation > UUID v4 > npm 3.8M ops/s 7.3M ops/s ℹ️ +90.8% (+/-11.2% RME) (ref)
tests/bench/compat.bench.ts > Validation > XID > npm 3.1M ops/s 5.9M ops/s ℹ️ +90.4% (+/-9.7% RME) (ref)
tests/bench/compat.bench.ts > Validation > TSID > npm 1M ops/s 2M ops/s ℹ️ +88.9% (+/-22.0% RME) (ref)
tests/bench/compat.bench.ts > Validation > UUID v7 > npm 3.8M ops/s 7.1M ops/s ℹ️ +88.7% (+/-13.6% RME) (ref)
tests/bench/compat.bench.ts > Generation > UUID v4 > npm 6.7M ops/s 12.5M ops/s ℹ️ +87.0% (+/-5.0% RME) (ref)
tests/bench/compat.bench.ts > Generation > XID > npm 4.2M ops/s 7.5M ops/s ℹ️ +79.4% (+/-13.7% RME) (ref)
tests/bench/compat.bench.ts > Generation > NanoID > npm 4M ops/s 7.2M ops/s ℹ️ +77.9% (+/-4.8% RME) (ref)
tests/bench/compat.bench.ts > Validation > ULID > regex 8.1M ops/s 14.3M ops/s ℹ️ +76.5% (+/-9.1% RME) (ref)
tests/bench/compat.bench.ts > Validation > KSUID > npm 515.4K ops/s 906.9K ops/s ℹ️ +75.9% (+/-28.3% RME) (ref)
tests/bench/compat.bench.ts > Validation > NanoID > regex 11.1M ops/s 19.4M ops/s ℹ️ +73.9% (+/-17.1% RME) (ref)
tests/bench/compat.bench.ts > Validation > CUID2 > npm 10.7M ops/s 18.3M ops/s ℹ️ +70.3% (+/-18.0% RME) (ref)
tests/bench/compat.bench.ts > Generation > ObjectID > npm 3.1M ops/s 5.2M ops/s ℹ️ +65.0% (+/-11.9% RME) (ref)
tests/bench/compat.bench.ts > Generation > TSID > npm 2.1M ops/s 3.5M ops/s ℹ️ +64.9% (+/-14.4% RME) (ref)
tests/bench/compat.bench.ts > Validation > ObjectID > npm 9M ops/s 14.8M ops/s ℹ️ +64.6% (+/-14.8% RME) (ref)
tests/bench/compat.bench.ts > Generation > NanoID (10) > npm 6.5M ops/s 10.5M ops/s ℹ️ +63.1% (+/-23.4% RME) (ref)
tests/bench/compat.bench.ts > Generation > UUID v7 > npm 382.7K ops/s 613.9K ops/s ℹ️ +60.4% (+/-19.4% RME) (ref)
tests/bench/compat.bench.ts > Generation > KSUID > npm 179.2K ops/s 286.2K ops/s ℹ️ +59.7% (+/-14.7% RME) (ref)
tests/bench/compat.bench.ts > Generation > CUID2 > npm 5.4K ops/s 8.5K ops/s ℹ️ +57.1% (+/-14.3% RME) (ref)
tests/bench/compat.bench.ts > Generation > TypeID > npm 478.7K ops/s 720.6K ops/s ℹ️ +50.5% (+/-11.5% RME) (ref)
tests/bench/compat.bench.ts > Generation > ULID > npm 25.5K ops/s 36K ops/s ℹ️ +41.3% (+/-29.8% RME) (ref)
tests/bench/compat.bench.ts > Validation > TypeID > npm 1.2M ops/s 1.4M ops/s ℹ️ +17.9% (+/-17.4% RME) (ref)
tests/bench/compat.bench.ts > Generation > UUID v5 > uniku N/A ops/s 1.5M ops/s 🆕 new
tests/bench/compat.bench.ts > Generation > UUID v5 > npm N/A ops/s 468.1K ops/s 🆕 new
tests/bench/compat.bench.ts > Generation > UUID v5 (256-char name) > uniku N/A ops/s 500.3K ops/s 🆕 new
tests/bench/compat.bench.ts > Generation > UUID v5 (256-char name) > npm N/A ops/s 244.2K ops/s 🆕 new
tests/bench/compat.bench.ts > Validation > UUID v5 > uniku N/A ops/s 12.6M ops/s 🆕 new
tests/bench/compat.bench.ts > Validation > UUID v5 > npm N/A ops/s 7.3M ops/s 🆕 new

Bundle Impact

Import Minified + gzipped
uniku/uuid/v4 ~1.2 KB
uniku/uuid/v5 ~1.8 KB
uniku/uuid/v7 ~1.7 KB
uniku/ulid ~1.9 KB
uniku/typeid ~2.9 KB
uniku/cuid2 ~1.0 KB*
uniku/cuid/v2 ~1.0 KB*
uniku/nanoid ~1.2 KB
uniku/ksuid ~1.5 KB
uniku/objectid ~1.6 KB
uniku/tsid ~1.6 KB
uniku/xid ~2.1 KB
uniku/errors ~445 B
uniku/generators ~101 B

*Excludes external dependencies (e.g., @noble/hashes)

Generated by workflow run 42925049527

@jkomyno jkomyno left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues to fix before merging and cutting the minor release. A bound UUID v5 namespace can change after construction when supplied as a Node.js Buffer. The Changesets plan also leaves the CLI at its current version, so the documented UUID v5 command and npm startup fix would stay out of the published CLI.

Comment thread packages/uniku/src/uuid/v5.ts Resolved
Comment thread .changeset/derived-uuid-v5.md Resolved
@jkomyno
jkomyno merged commit eb6550d into main Nov 11, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deterministic IDs: derive a stable ID from an existing identifier (uuid/v5)

1 participant