Generate globally unique nonces (number-only-used-once) in distributed Elixir. These nonces are be used to form the basis of an upcoming GUID generation package unique ID package Once, or in crypto operations that require nonces.
The nonces come in multiple types:
- counter nonces that are unique but predictable and can be generated incredibly quickly
- sortable nonces (Snowflake IDs) that have an accurate creation timestamp in their first bits
- encrypted nonces that are unique but unpredictable
The nonces are guaranteed to be unique if:
- machine IDs are unique for each node
- individual machines maintain a somewhat accurate clock (specifically, the UTC clock has to have progressed between node restarts)
To aid with the unique machine IDs, NoNoncense.MachineId
and its subsidiary conflict-detecting genserver NoNoncense.MachineId.ConflictGuard
can be used. ConflictGuard requires connected nodes to function, but is an optional extra and the entire thing can also work without it.
It’s possible to use the nonces for cryptographic purposes like cipher IVs and generating Poly1305 one-time-keys. For usecases where a nonce is required that is not just unique but unpredictable, there is a uniqueness-preserving encrypted-nonce option. However, caveats apply, you should read the NoNoncense module docs and make up your own mind.
Last but not least, performance is great thanks to the use of Erlang primitives :persistent_term
and :atomics
. Plaintext nonces can be generated at rates of tens of millions of nonces per second
Package: no_noncense | Hex
Docs: NoNoncense v0.0.3 — Documentation