tiny-secp256k1
tiny-secp256k1 copied to clipboard
`WebAssembly.Compile` is disallowed on the main thread, if the buffer size is larger than 4KB.
Currently the WebAssembly
part is loaded synchronously:
const mod = new WebAssembly.Module(binary);
const instance = new WebAssembly.Instance(mod, imports);
This results in the following error:
WebAssembly.Compile
is disallowed on the main thread, if the buffer size is larger than 4KB. Use WebAssembly.compile
, or compile on a worker thread.
However the async
version of the methods cannot be run on the top-level file AFAIK.
Any ideas how to fix this?
Can you provide detailed repro steps?
I think this is a browser error... but that file is not used in browsers.
wasm_loader.browser.ts
is for browsers.
Either:
- It's an error in whatever bundler you used.
- Maybe there's some weird edge case in NodeJS... in which case I need better repro steps.
- It's an error in whatever bundler you used.
It is an Electron app that uses the lib, it might be the bundler. I will have a more in detail look. Thank you for the hint.
Facing the same issue.
I ended up creating a fork and updating the browser loader. src_ts /wasm_loader.browser.ts
// Suppress TS2792: Cannot find module './secp256k1.wasm'.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import wasm from "./secp256k1.wasm";
import * as rand from "./rand.js";
import * as validate_error from "./validate_error.js";
const imports = {
"./rand.js": rand,
"./validate_error.js": validate_error,
};
const mod = await WebAssembly.compile(Buffer.from(wasm.split(',')[1], 'base64'));
const instance = await WebAssembly.instantiate(mod, imports);
export default instance.exports;
hey @motorina0 , I know it's been long time since this issue was opened , just checking if you was able to solve this error