Announcing Heptapod: Generate UUIDv7 in Haskell

by Taylor Fausak on

I’m happy to announce Heptapod, a tiny Haskell library for generating version 7 UUIDs. If you’re not familiar with UUIDv7s, they are defined by RFC 9562. As a brief summary, they are sort of like a mix of UUIDv1s and UUIDv4s. They start with a timestamp and end with some randomness. Here’s a diagram of their layout:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           unix_ts_ms                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          unix_ts_ms           |  ver  |       rand_a          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|var|                        rand_b                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            rand_b                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Heptapod allows you to generate UUIDv7s. unix_ts_ms comes from getSystemTime. Both rand_a and rand_b both come from getEntropy, which is cryptographically secure.

The rand_a field can be a few different things: additional clock precision, a monotonic counter, or simply more randomness. Heptapod chooses the latter. If you’d like it to be something else, Heptapod also allows you to build your own UUIDv7 using provided values for unix_ts_ms, rand_a, and rand_b.

That’s it! Please check out Heptapod and consider using version 7 UUIDs!