Skip to content

feat(wasm-mps): add --target web build for browser-safe WASM initialisation#267

Closed
bitgo-ai-agent-dev[bot] wants to merge 2 commits into
masterfrom
wci-250-wasm-mps-web-target
Closed

feat(wasm-mps): add --target web build for browser-safe WASM initialisation#267
bitgo-ai-agent-dev[bot] wants to merge 2 commits into
masterfrom
wci-250-wasm-mps-web-target

Conversation

@bitgo-ai-agent-dev
Copy link
Copy Markdown

Summary

  • Adds a dist/web/js/wasm Makefile target using wasm-pack --target web, generating a single flat ESM file with an explicit async init() default export
  • Adds dist/web/js/**/* to the files array in package.json so the web build is included in the npm publish
  • Adds "./web": "./dist/web/js/wasm/wasm_mps.js" subpath export so consumers can import via @bitgo/wasm-mps/web
  • Adds make dist/web/js/wasm to the build:wasm script

Motivation

The current --target bundler ESM build uses a two-file pattern where wasm_mps.js imports the .wasm file and calls __wbg_set_wasm. In webpack 5 asyncWebAssembly mode, await import('@bitgo/wasm-mps') can resolve before __wbg_set_wasm is called, leaving wasm as undefined and causing TypeError: wasm.ed25519_dkg_round0_process is not a function.

The --target web build solves this by generating an init() default export that fetches and instantiates the WASM binary synchronously before returning. Callers await init() once before using any exported function — guaranteed ready, no webpack timing dependency. This mirrors the pattern used by @silencelaboratories/dkls-wasm-ll-web.

Test plan

  • make dist/web/js/wasm runs without error and produces dist/web/js/wasm/wasm_mps.js (single-file ESM with export default __wbg_init)
  • npm run build:wasm completes and includes all four targets (js/wasm, dist/esm/js/wasm, dist/cjs/js/wasm, dist/web/js/wasm)
  • npm pack --dry-run shows dist/web/js/** files included
  • Importing @bitgo/wasm-mps/web in a browser bundle resolves to the web entry point
  • await init() followed by WASM function calls works without TypeError in webpack 5 asyncWebAssembly mode

Ticket: WCI-250

🤖 Generated with Claude Code

Add dist/web/js/wasm Makefile target using wasm-pack --target web,
which generates a single ESM file with an explicit async init()
default export. This avoids the webpack asyncWebAssembly race where
__wbg_set_wasm may not be called before exports are used.

Update package.json to include dist/web/js/**/* in published files,
expose the ./web subpath export pointing to the generated entry
point, and add make dist/web/js/wasm to the build:wasm script.

Ticket: WCI-250
@bitgo-ai-agent-dev bitgo-ai-agent-dev Bot requested a review from a team as a code owner April 28, 2026 09:37
@linear
Copy link
Copy Markdown

linear Bot commented Apr 28, 2026

@Marzooqa Marzooqa closed this Apr 28, 2026
@Marzooqa
Copy link
Copy Markdown
Contributor

The dev agent pushed another pr 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant