Skip to content

fix!: expect crypto to be global everywhere (requires node@20+) - #935

Merged
broofa merged 4 commits into
mainfrom
unify_rng
Apr 19, 2026
Merged

broofa merged 4 commits into
mainfrom
unify_rng

Conversation

@broofa

@broofa broofa commented Apr 6, 2026 •

Copy link
Copy Markdown
Member

Now that crypto is globally defined everywhere (all browser environments and node@20+), we can clean up the feature detection logic we had around it.

  • Remove typeof crypto feature-detection
  • Remove rng-browser.ts
  • Remove native*.ts

Closes #891

@broofa
broofa marked this pull request as ready for review April 6, 2026 16:47
@broofa broofa changed the title fix!: expect crypto to be global everywhere fix!: expect crypto to be global everywhere (requires node@20+) Apr 6, 2026
@broofa
broofa merged commit f2c235f into main Apr 19, 2026
13 checks passed
@broofa
broofa deleted the unify_rng branch April 19, 2026 13:01
@realityking

Copy link
Copy Markdown

Very cool. Thank you!

@jimmycallin

Copy link
Copy Markdown

hi! will this update break usage of uuid in non-secure browser contexts? we are relying on uuid over crypto due to crypto.randomUUID not being available in non-https environments.

@realityking

Copy link
Copy Markdown

I haven’t tested it myself but if I’m reading the code right it’ll fallback to crypto.randomValues() if crypto.randomUUID() is not present.

@jimmycallin

Copy link
Copy Markdown

I haven’t tested it myself but if I’m reading the code right it’ll fallback to crypto.randomValues() if crypto.randomUUID() is not present.

i just tested this myself, and in contrast to my assumptions crypto.randomUUID is simply not available in insecure contexts. i assumed it would throw an error. so this should be fine. thank you!

@broofa

broofa commented May 4, 2026

Copy link
Copy Markdown
Member Author

if I’m reading the code right it’ll fallback to crypto.[getR]andomValues()

This is correct. FWIW, we test all of the examples/browser-* samples in non-secure contexts as part of our CI checks. E.g...

CleanShot 2026-05-04 at 05 57 00@2x

zeekay pushed a commit to hanzoai/uuid that referenced this pull request Sep 9, 2026
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.

[after node@18 is dropped] Combine rng.ts + rng-browser.ts

3 participants