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

libsodium-wrapper reports "No secure random number generator found" #1418

Closed
caoster opened this issue Nov 18, 2023 · 2 comments
Closed

libsodium-wrapper reports "No secure random number generator found" #1418

caoster opened this issue Nov 18, 2023 · 2 comments

Comments

@caoster
Copy link

caoster commented Nov 18, 2023

Here is a minimal working example:

// src/index.js
import 'node:crypto';
import _sodium from 'libsodium-wrappers';

globalThis.window = undefined;
globalThis.importScripts = undefined;

export default {
	async fetch(request) {
		globalThis.window = undefined;
		globalThis.importScripts = undefined;

		await _sodium.ready;
		return new Response('Hello');
	}
};
# wrangler.toml
name = "test"
main = "src/index.js"
compatibility_date = "2023-10-25"
compatibility_flags = [ "nodejs_compat" ]
env = { }

According to the issue at miniflare, it should work with wrangler dev. However, it keeps reporting Both wasm and asm failed to loadNo secure random number generator found at (.../node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.js:1:16026) no matter how I modify the version of wrangler (with "compatibility_date" in .toml) and libsodium.

This code works neither on my computer nor with Cloudflare workers.


System information

Apple M2 chip
macOS Sonoma 14.1.1 (23B81)
npm: '10.2.0'
node: '21.1.0'
wrangler 3.15.0 
@mschwarzl
Copy link

Hi,

I stumbled over the same issue quite recently.

I created a PR for libsodium adding support for crypto API:
jedisct1/libsodium#1401

Minimal example that works with the patch:

export default {
  async fetch(request,env,context) {    
    const _sodium = await import("libsodium-wrappers");
    await _sodium.ready;
    let binkey = _sodium.from_base64(env.PUBKEY, _sodium.base64_variants.ORIGINAL)
    console.log(binkey);
    return new Response('Hello');
  }
};

@caoster
Copy link
Author

caoster commented Aug 21, 2024

They've merged the PR, it seems working :D

@caoster caoster closed this as completed Aug 21, 2024
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

No branches or pull requests

2 participants