2024-01-17

Crypto/UUID

Speaking of crypto.

I learned by a pure accident that browsers offer now generating popular UUID out of the box. There is a global component crypto that has a method randomUUID, which will generate a UUID. No more need for a library with a tonne of dependencies.

crypto.randomUUID();

One interesting thing is that this method is present on crypto *only* when the page is under HTTPS (and localhost). We noticed that when we switched from localhost to a domain from the hosts file, and the method disappeared. I like that because it enforces security: when using the native crypto, your app will not function under HTTP. It's a bit of poor man's enforcing but still.

It's also available in Node.