Skip to content

Add option to generate UUIDv7 compatible ULIDs #122

Description

@nakedible-p

Could you add an option to generate UUIDv7 compatible ULIDs as well. You already have the UUID encoding and decoding functions, which generate invalid UUIDs. To make sure the UUIDs are actually interoperable, it would be good to have UUIDv7 compatible ULID generation functions.

The only thing it needs is making sure in the random portion you set a few bits. Here's external example code, but it is of course easier when generating the ULID.

  const bytes = decode(ulid());
  bytes[6] = (bytes[6] & 0x0f) | 0x70;
  bytes[8] = (bytes[8] & 0x3f) | 0x80;
  return encode(bytes);

It will remove 6 bits of entropy, but the effect of that should be minor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions