asobi_id (asobi v0.75.1)

View Source

UUIDv7 generation for Asobi entities.

Generates UUIDv7 (RFC 9562) identifiers via jhn_uuid. UUIDv7 embeds a millisecond timestamp in the high 48 bits, giving time-ordered IDs that improve PostgreSQL B-tree index locality, reduce WAL writes, and enable native time-range queries on primary keys.

Privacy note (F-31): the embedded timestamp leaks the creation time of any id we expose. Match ids, world ids, ticket ids and similar ephemeral resources are an accepted trade-off, but player.id — which uses the same generator and persists for life — also reveals account-creation time. Treat the trade-off as acceptable for this codebase; if a future requirement needs unguessable, non-correlatable ids (e.g. for tokens, invite codes, etc.) generate them via crypto:strong_rand_bytes/1 rather than this function.

Summary

Functions

Generate a UUIDv7 as a lowercase hyphenated binary string.

Generate a random lowercase-hex binary carrying ByteLen bytes of real entropy (2xByteLen hex characters). For handles that need to be non-colliding across concurrent generation - e.g. a generated username suffix - where a generate/0 prefix is the wrong tool: its first characters are pure millisecond timestamp (see the moduledoc above), so two calls in the same millisecond produce the identical prefix.

Functions

generate()

-spec generate() -> binary().

Generate a UUIDv7 as a lowercase hyphenated binary string.

rand_suffix(ByteLen)

-spec rand_suffix(pos_integer()) -> binary().

Generate a random lowercase-hex binary carrying ByteLen bytes of real entropy (2xByteLen hex characters). For handles that need to be non-colliding across concurrent generation - e.g. a generated username suffix - where a generate/0 prefix is the wrong tool: its first characters are pure millisecond timestamp (see the moduledoc above), so two calls in the same millisecond produce the identical prefix.