Skip to content

node:crypto: implement crypto.randomUUIDv7 (#2550) - #3255

Merged
proggeramlug merged 3 commits into
mainfrom
fix/2550-randomuuidv7-impl
May 30, 2026
Merged

proggeramlug merged 3 commits into
mainfrom
fix/2550-randomuuidv7-impl

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Summary

Implements crypto.randomUUIDv7([options]) (Node v26.1.0 / RFC 9562 version 7 UUIDs) — closes #2550. Perry already had randomUUID (v4); this mirrors that path end to end so all call shapes work.

const crypto = require("node:crypto");
const id = crypto.randomUUIDv7();
typeof id;   // "string"
id.length;   // 36
id[14];      // "7"  (version nibble)

What changed

  • runtime (perry-stdlib/src/crypto/random.rs): js_crypto_random_uuidv7 via the uuid crate's now_v7() (the v7 feature was already enabled), plus the "randomUUIDv7" arm in the crypto method dispatcher.
  • HIR: new Expr::CryptoRandomUUIDv7 variant + randomUUIDv7 → variant lowering in the shared crypto passthrough (covers both import { randomUUIDv7 } and crypto.randomUUIDv7() forms). All walker/monomorph/analysis/stable-hash match sites updated.
  • codegen: misc_methods + calls.rs dotted-form arms calling js_crypto_random_uuidv7, runtime decl, and the native_module callable-value list so const { randomUUIDv7 } = crypto yields a callable.
  • api manifest entry (drives the regenerated .d.ts / reference docs) + js/wasm emit parity + android stub for cross-target builds.

The optional options object (Node's { disableEntropyCache }) is accepted for shape parity but does not affect output.

Testing

  • Rust unit tests (random_uuidv7_has_version_and_variant_bits, random_uuidv7_is_fresh_each_call) assert the canonical 36-char dashed form, version nibble 7, variant nibble in {8,9,a,b}, non-zero timestamp prefix, and per-call freshness. Both pass.
  • Manual smoke (compiled): dotted, named-import, and destructure-from-namespace (const { randomUUIDv7 } = crypto) forms all return valid v7 UUIDs. (Local Node v25.8.0 predates the API, so byte-diff parity is N/A here; structural checks used instead.)
  • cargo fmt --all --check clean; API docs regenerated (no drift).

Ralph Küpper and others added 3 commits May 30, 2026 11:19
Add RFC 9562 version 7 UUID generation via crypto.randomUUIDv7([options]),
mirroring the existing randomUUID (v4) lowering end to end:

- runtime: js_crypto_random_uuidv7 (uuid crate now_v7) + crypto dispatch arm
- HIR: Expr::CryptoRandomUUIDv7 variant + crypto passthrough lowering
- codegen: misc_methods + calls.rs dotted-form arms + runtime decl
- native_module callable-value list so const { randomUUIDv7 } = crypto works
- api manifest entry (drives .d.ts) + js/wasm emit parity + android stub

Options object accepted for shape parity (does not affect output).
Unit tests assert version/variant nibbles, 36-char form, and freshness.
# Conflicts:
#	crates/perry-codegen/src/runtime_decls/strings.rs
#	crates/perry-hir/src/lower/expr_call/crypto.rs
#	crates/perry-stdlib/src/crypto/random.rs
# Conflicts:
#	docs/api/perry.d.ts
#	docs/src/api/reference.md
@proggeramlug
proggeramlug merged commit d1bbdf5 into main May 30, 2026
11 checks passed
@proggeramlug
proggeramlug deleted the fix/2550-randomuuidv7-impl branch May 30, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node:crypto: implement randomUUIDv7

1 participant