import { afterUpdateGlobalBufferAndViews } from "./memory";
import { replaceEmscriptenPThreadLibrary } from "./pthreads/shared/emscripten-replacements";
import { DotnetModuleConfigImports, EarlyReplacements } from "./types";
+import { TypedArray } from "./types/emscripten";
let node_fs: any | undefined = undefined;
let node_url: any | undefined = undefined;
const { performance } = INTERNAL.require("perf_hooks");
globalThis.performance = performance;
}
+
+ if (!globalThis.crypto) {
+ globalThis.crypto = <any>{};
+ }
+ if (!globalThis.crypto.getRandomValues) {
+ const nodeCrypto = INTERNAL.require("node:crypto");
+ if (nodeCrypto.webcrypto) {
+ globalThis.crypto = nodeCrypto.webcrypto;
+ } else if (nodeCrypto.randomBytes) {
+ globalThis.crypto.getRandomValues = (buffer: TypedArray) => {
+ if (buffer) {
+ buffer.set(nodeCrypto.randomBytes(buffer.length));
+ }
+ };
+ }
+ }
}
}
throw new Error(`NodeJS at '${process.execPath}' has too low version '${process.versions.node}'`);
}
-if (typeof globalThis.crypto === 'undefined') {
+if (!is_node && !is_browser && typeof globalThis.crypto === 'undefined') {
// **NOTE** this is a simple insecure polyfill for testing purposes only
// /dev/random doesn't work on js shells, so define our own
// See library_fs.js:createDefaultDevices ()