Skip to content

Commit cde1353

Browse files
committed
fix(sdk-lib-mpc): use @bitgo/wasm-mps/web in browser for EdDSA DKG
In browsers (webpack), importing @bitgo/wasm-mps resolves to the --target bundler ESM build which has a race condition between webpack's async WASM instantiation and __wbg_set_wasm being called. This causes wasm.ed25519_dkg_round0_process to be undefined when initDkg() runs. Mirror the ECDSA pattern in ecdsa-dkls/dkg.ts: detect browser via `typeof window !== 'undefined'` (excluding Electron via window.process checks), then use @bitgo/wasm-mps/web which exposes an explicit init() function — guaranteed ready after await. Adds a local .d.ts shim for @bitgo/wasm-mps/web until WCI-250 publishes the ./web subpath export with its own types. Ticket: WCI-251
1 parent f3cc4eb commit cde1353

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

modules/sdk-lib-mpc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
]
3737
},
3838
"dependencies": {
39-
"@bitgo/wasm-mps": "1.7.0",
39+
"@bitgo/wasm-mps": "1.8.0",
4040
"@noble/curves": "1.8.1",
4141
"@silencelaboratories/dkls-wasm-ll-node": "1.2.0-pre.4",
4242
"@silencelaboratories/dkls-wasm-ll-web": "1.2.0-pre.4",

modules/sdk-lib-mpc/src/tss/eddsa-mps/dkg.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { encode } from 'cbor-x';
33
import crypto from 'crypto';
44
import { DeserializedMessage, DeserializedMessages, DkgState, EddsaReducedKeyShare } from './types';
55

6-
type WasmMps = typeof import('@bitgo/wasm-mps');
6+
type NodeWasmer = typeof import('@bitgo/wasm-mps');
7+
type WebWasmer = typeof import('@bitgo/wasm-mps/web');
8+
type WasmMps = NodeWasmer | WebWasmer;
79

810
/**
911
* EdDSA Distributed Key Generation (DKG) implementation using @bitgo/wasm-mps.
@@ -53,7 +55,21 @@ export class DKG {
5355

5456
private async loadWasmMps(): Promise<void> {
5557
if (!this.wasmMps) {
56-
this.wasmMps = await import('@bitgo/wasm-mps');
58+
if (
59+
typeof window !== 'undefined' &&
60+
/* checks for electron processes */
61+
!window.process &&
62+
!window.process?.['type']
63+
) {
64+
// Browser: web build has explicit init() — guaranteed ready after await
65+
// eslint-disable-next-line import/no-internal-modules -- @bitgo/wasm-mps exposes environment-specific subpath exports.
66+
const webWasm = await import('@bitgo/wasm-mps/web');
67+
await webWasm.default();
68+
this.wasmMps = webWasm;
69+
} else {
70+
// Node.js: dynamic import() rewritten to require() by tsc → CJS build → readFileSync
71+
this.wasmMps = await import('@bitgo/wasm-mps');
72+
}
5773
}
5874
}
5975

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,10 +1015,10 @@
10151015
resolved "https://registry.npmjs.org/@bitgo/wasm-dot/-/wasm-dot-1.7.0.tgz"
10161016
integrity sha512-KoXavJvyDHlEN+sWcigbgxYJtdFaU7gS0EkYQbNH4npVjNlzo6rL6gwjyWbyOy7oEs65DhpJ9vY5kRbE/bKiTQ==
10171017

1018-
"@bitgo/wasm-mps@1.7.0":
1019-
version "1.7.0"
1020-
resolved "https://registry.npmjs.org/@bitgo/wasm-mps/-/wasm-mps-1.7.0.tgz#e7ebca1afd2df757e69c5cdac702d6a06156867c"
1021-
integrity sha512-SNO7as4UvnE2ptDXp1oUXjABA8Y3/71lgVpAQyAGSfSaURjz4rG19+JZR54GBRIaA6hvUPr029b4gFyqoZPcgg==
1018+
"@bitgo/wasm-mps@1.8.0":
1019+
version "1.8.0"
1020+
resolved "https://registry.npmjs.org/@bitgo/wasm-mps/-/wasm-mps-1.8.0.tgz#2b299c90bd1a84616985479037375276103774a6"
1021+
integrity sha512-4P8bqv8kMeQfjuJiyWnYppMK2hLDM2SbDuSFZKdhAbr7qneIquC4LJUIBc1nluQmZNYN9xJi14bR6vBxL6knNQ==
10221022

10231023
"@bitgo/wasm-solana@^2.6.0":
10241024
version "2.6.0"

0 commit comments

Comments
 (0)