Page MenuHomePhabricator

[ecash-lib] Support custom WASM URL and module
ClosedPublic

Authored by tobias_ruck on Fri, Jan 31, 21:55.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Project
Commits
rABC92f16ad6b35e: [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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable