-
Notifications
You must be signed in to change notification settings - Fork 107
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
Crypto API isn't detected on alternative platforms #72
Comments
Hoping this aligns with the original point of this issue, but I've noticed too that on some platforms like Mobile Safari on iOS 8-10.3, crypto is Along with using a generic global lookup, perhaps expand the crypto lookup to include the webkit reference? |
I also could not use |
@SokichiFujita Added an issue for that at #83. Should be fixed by my PR at #82. |
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. |
@DavidJFelix I've made a supported fork here, in case that's of interest: ulidx. There's also another fork designed specifically for cloudflare workers: ulid-workers. |
I run across this using Cloudflare Workers. It should be possible to use this library by instead checking for a
crypto
global instead of trying to detect `window. Documentation from Cloudflare here: https://developers.cloudflare.com/workers/reference/apis/web-crypto/.The text was updated successfully, but these errors were encountered: