[ecash-lib] Support custom WASM URL and module
Summary:
Some bundlers don't support WebAssembly yet.
For example, Vite doesn't include the wasm file at all and returns a 404 HTML file instead, which returns in CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0. This is because Vite's HTML files start with <!DOCTYPE html>, and 3c 21 44 4f is <!DO.
The fix is to allow users to specify a custom URL/module in initWasm, and they can then let the bundler handle it via import ecashLibWasmUrl from 'ecash-lib/dist/ffi/ecash_lib_wasm_bg_browser.wasm?url'.
wasm-bindgen doesn't provide the same for NodeJS, so we add a dummy param for typechecking.
Test Plan:
- ionic start, make React project
- npm install --save @ecash/lib@1.5.0-rc0 (a published version of this diff)
- in App.tsx, add import * as ecashLib from '@ecash/lib' and ecashLib.initWasm(); in const App
- ionic serve
- -> "CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0"
- in App.tsx, add import wasmUrl from '@ecash/lib/dist/ffi/ecash_lib_wasm_bg_browser.wasm?url';
- Change to ecashLib.initWasm(wasmUrl)
- -> CompileError disappears
Reviewers: bytesofman, #bitcoin_abc
Reviewed By: bytesofman, #bitcoin_abc
Differential Revision: https://reviews.bitcoinabc.org/D17622