Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web worker support #82

Closed
wants to merge 4 commits into from
Closed

Web worker support #82

wants to merge 4 commits into from

Conversation

perry-mitchell
Copy link

@perry-mitchell perry-mitchell commented Mar 26, 2021

This PR adds support for detecting crypto within a Web Worker, where window is not defined but self (and therefore self.crypto) is.

Fixes #83

@codecov-io
Copy link

codecov-io commented Mar 26, 2021

Codecov Report

Merging #82 (63d6d45) into master (a583120) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #82   +/-   ##
=======================================
  Coverage   93.08%   93.08%           
=======================================
  Files           2        2           
  Lines         246      246           
  Branches       31       31           
=======================================
  Hits          229      229           
  Misses         17       17           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a583120...63d6d45. Read the comment docs.

Ignore the webworker lookup as the types aren't available outside the `WebWorker` type interface. Including it alongside `DOM` causes TS build failures.
@lucaslago
Copy link

Hi, any reason this hasn't been merged?

@DavidJFelix
Copy link

Hey, if anyone else finds this issue like I did and is using cloudflare workers, here's what worked for me:

import {monotonicFactory} from 'ulid'
// or import {factory} from 'ulid'

const prng = () => {
  const buffer = new Uint8Array(1)
  crypto.getRandomValues(buffer)
  return buffer[0] / 0xff
}
export const ulid = monotonicFactory(prng) // or factory(prng)

This will bypass the code that checks for browser crypto and allow you to set your own. The PRNG function is the same as used internally with a different global reference.

I think this package may be abandoned, I'm working on potentially forking it.

This pull request was closed.
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.

Not available in web workers
4 participants