stateless-me/uuidv47 logo

stateless-me/uuidv47

Free

⚡ UUIDv47 = v4 privacy + v7 performance

FreeFree tier
Type
Open Source

About stateless-me/uuidv47

UUIDv47 is a header-only C library (C89) that provides a deterministic, invertible mapping between UUIDv7 (time-ordered) and UUIDv4-looking façades. It XOR-masks only the timestamp field of a UUIDv7 with a keyed SipHash‑2‑4 stream derived from the UUID's own random bits, preserving the random bits unchanged. This allows storing sortable UUIDv7 in databases for better index locality and pagination while emitting a UUIDv4-compliant façade at the API boundary to avoid revealing internal timing patterns. The library is RFC-compatible (version/variant bits), includes a full test suite, and offers an optional PostgreSQL extension with custom UUID type, operators, and opclasses. It is designed for key-recovery resistance via SipHash‑2‑4 with a 128-bit key.

Key Features

Header-only C (C89) with zero dependencies
Deterministic, invertible mapping (exact round-trip)
RFC-compatible version/variant bits (v7 in DB, v4 on the wire)
Key-recovery resistant (SipHash‑2‑4, 128-bit key)
Full tests provided
Optional PostgreSQL extension (UUID type + operators/opclasses)
Time-ordered UUIDv7 for better index locality and pagination
Externally neutral façade hides timing patterns
Uses PRF (SipHash‑2‑4) for secret safety

Pros & Cons

Pros
  • Improves database indexing and pagination due to UUIDv7 time-ordering
  • Maintains UUIDv4 look externally to avoid revealing internal timing
  • Deterministic and reversible transformation
  • Strong security with SipHash‑2‑4 keyed hashing
  • Lightweight header-only C library with no dependencies
  • Includes comprehensive tests and optional PostgreSQL extension
Cons
  • Only works with UUIDv7 as input; requires existing v7 UUIDs
  • Requires secret key management for the SipHash key
  • Additional computational overhead for masking/unmasking
  • Relies on SipHash, which is a PRF and not suitable for cryptographic-grade security if slower hashes are needed
  • Limited to C/C++ projects unless ports are used

Best For

Storing time-ordered UUIDs in databases for better index performanceExposing UUIDs in APIs without revealing timestamp informationConverting existing UUIDv4 systems to use sortable UUIDv7 internally while maintaining v4 façade for backward compatibilityPrivacy-preserving UUID generation where external observers cannot deduce creation time