-
Notifications
You must be signed in to change notification settings - Fork 147
Description
I know sodium.ready
needs to be called before using the library, but doing so at import time is difficult in libraries (where the await should be delegated to the application) or where lacking top-level await support.
At the same time, a common import pattern, even recommended by the Node error message in the details below (which might be fixable as a separate issue), is
import sodium from 'libsodium-wrappers-sumo'
const { crypto_hash_sha256, from_hex, to_hex } = sodium
file:///Users/filippo/src/filippo.io/age.ts/dist/hkdf.js:2
import { from_string } from "libsodium-wrappers-sumo";
^^^^^^^^^^^
SyntaxError: Named export 'from_string' not found. The requested module 'libsodium-wrappers-sumo' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'libsodium-wrappers-sumo';
const { from_string } = pkg;
When using that pattern, crypto_hash_sha256
is referenced before ready, which leads to intermittent errors.
https://github.com/FiloSottile/age.ts/actions/runs/6743827419/job/18332547466
Would it be possible to make it so calling functions before ready fails, but not simply referencing them?
(Also, if the failure was a clearer error, it would help. Debugging mysterious errors about _malloc to incorrect use of ready is pretty hard.)