HomePhabricator

[ecash-lib] Support custom WASM URL and module

Description

[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:

  1. ionic start, make React project
  2. npm install --save @ecash/lib@1.5.0-rc0 (a published version of this diff)
  3. in App.tsx, add import * as ecashLib from '@ecash/lib' and ecashLib.initWasm(); in const App
  4. ionic serve
  5. -> "CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0"
  6. in App.tsx, add import wasmUrl from '@ecash/lib/dist/ffi/ecash_lib_wasm_bg_browser.wasm?url';
  7. Change to ecashLib.initWasm(wasmUrl)
  8. -> CompileError disappears

Reviewers: bytesofman, #bitcoin_abc

Reviewed By: bytesofman, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D17622

Details

Provenance
tobias_ruckAuthored on Fri, Jan 31, 21:49
tobias_ruckPushed on Fri, Jan 31, 22:22
Reviewer
Restricted Project
Differential Revision
D17622: [ecash-lib] Support custom WASM URL and module
Parents
rABC2ccbb46a96c1: [ecash-lib] Patch import in `mnemonic.ts`
Branches
Unknown
Tags
Unknown