paritytech / libsecp256k1

Pure Rust Implementation of secp256k1.
Apache License 2.0
175 stars 84 forks source link

Wasm - Cannot find module env #72

Closed fredfortier closed 3 years ago

fredfortier commented 3 years ago

This crate is triggering the behavior documented here: https://github.com/rust-bitcoin/rust-secp256k1/pull/254, here: https://github.com/rustwasm/wasm-bindgen/issues/2160 and here: https://github.com/rustwasm/wasm-pack/issues/743

Please let me know if you think the root cause is similar and can patch quickly.

fredfortier commented 3 years ago

I tried manually replacing require('env') with require('crypto'), which I assume is what it wants.

let imports = {};
imports['__wbindgen_placeholder__'] = module.exports;
imports['env'] = require('crypto');

It does not work, but it might offer an additional clue:

$ node ./build/index.js
/src/rust-packages/ddx-wasm/examples/node_modules/ddx-wasm/ddx_wasm.js:173
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
                     ^

LinkError: WebAssembly.Instance(): Import #1 module="env" function="GFp_aes_nohw_encrypt" error: function import requires a callable
MatthewHerbst commented 2 years ago

@fredfortier did you end up solving this issue? I'm running into something very similar but can't seem to figure out why it's including the env import. Thanks