fix: replace static whatsapp-rust-bridge imports with lazy dynamic loading

The whatsapp-rust-bridge package contains a top-level await on an inline
WASM binary, which propagates through the ESM graph and causes
ERR_REQUIRE_ASYNC_MODULE when CJS consumers try to require() this package.

Replace all static imports from whatsapp-rust-bridge with a lazy-loading
bridge module (wasm-bridge.ts) that uses import().then() instead of
top-level await, keeping the dependency out of the static ESM graph.

https://claude.ai/code/session_01XaA7GwNaB6azTHFYQ8WEpB
This commit is contained in:
Claude
2026-02-09 02:31:52 +00:00
parent ffd3c7735f
commit 38575fb2d8
5 changed files with 46 additions and 5 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ import {
type MessageLabelAssociation
} from '../Types/LabelAssociation'
import { type BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidNormalizedUser } from '../WABinary'
import { expandAppStateKeys } from 'whatsapp-rust-bridge'
import { expandAppStateKeys } from './wasm-bridge'
import { aesDecrypt, aesEncrypt, hmacSign } from './crypto'
import { toNumber } from './generics'
import type { ILogger } from './logger'
@@ -102,7 +102,7 @@ const makeLtHashGenerator = ({ indexValueMap, hash }: Pick<LTHashState, 'hash' |
}
},
finish: () => {
const result = LT_HASH_ANTI_TAMPERING.subtractThenAdd(new Uint8Array(hash), addBuffs, subBuffs)
const result = LT_HASH_ANTI_TAMPERING().subtractThenAdd(new Uint8Array(hash), addBuffs, subBuffs)
return {
hash: Buffer.from(result),