-
Notifications
You must be signed in to change notification settings - Fork 300
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
π Bug Report β Runtime APIs - nodejs compat - crypto - getRandomBytes()
#2716
Comments
To be more concrete. Using import { getBuiltinModule } from "node:process";
export default {
async fetch(
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> {
const results: string[] = [];
const nodeCrypto = getBuiltinModule("crypto");
const webcrypto = nodeCrypto.webcrypto;
const getRandomValues = webcrypto.getRandomValues;
results.push(crypto.getRandomValues(new Uint8Array(6)).toString()); // global
results.push(webcrypto.getRandomValues(new Uint8Array(6)).toString()); // webcrypto
results.push(nodeCrypto.getRandomValues(new Uint8Array(6)).toString()); // namespace import
results.push(getRandomValues(new Uint8Array(6)).toString()); // free standing
return Response.json(results);
},
}; Results in exceptions on these lines: nodeCrypto.getRandomValues(new Uint8Array(6)).toString(); // namespace import
getRandomValues(new Uint8Array(6)).toString(); // free standing I could accept that the bare |
petebacondarwin
changed the title
π Bug Report β Runtime APIs - nodejs compat - crypto - getRuntimeBytes
π Bug Report β Runtime APIs - nodejs compat - crypto - Sep 17, 2024
getRandomBytes()
Also given that this is for Node.js compatibility, I tested it on vanilla Node.js (18):
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
getRandomBytes()
function will fail when called if it is not bound to thewebcrypto
object.See cloudflare/workers-sdk#6721 for a test case.
Currently the calls fail with:
TypeError: Illegal invocation: function called with incorrect
thisreference.
.This has been fixed in unenv via unjs/unenv#309 but I think that the
getRandomBytes()
function should not require any particularthis
to work.The text was updated successfully, but these errors were encountered: