feat: replace async crypto with sync Rust WASM (port of Baileys b5c1741)

Surgically applies the changes from WhiskeySockets/Baileys commit b5c1741
("feat: replace async crypto with sync Rust WASM" by jlucaso1) while
preserving all custom modifications (interactive messages, carousels,
albums, sticker packs, native flow buttons, Prometheus metrics, etc).

Changes:
- Replace async hkdf/md5 (Web Crypto API) with sync re-exports from whatsapp-rust-bridge@0.5.2
- Replace LTHash class with LTHashAntiTampering from WASM
- Replace mutationKeys() with expandAppStateKeys() from WASM
- Remove ~25 unnecessary await keywords across crypto call chain
- Update Buffer→Uint8Array types for MediaDecryptionKeyInfo and internal crypto functions
- Make noise handshake, media retry encrypt/decrypt, and reporting token generation synchronous

Performance impact:
- Eliminates Promise overhead on every HKDF/LTHash operation
- Significant improvement during app state sync (hundreds of mutations per reconnection)
- Sync crypto reduces event loop pressure under high session load

Custom code preserved (zero conflicts):
- messages-send.ts: All interactive message, carousel, album, sticker pack logic intact
- Types/Message.ts: All custom types (NativeFlowButton, Carousel, Album, etc.) intact
- All Prometheus metrics, circuit breakers, session TTL logic intact

https://claude.ai/code/session_01Ffc5YrPuqv8N9SwEuSM8mr
This commit is contained in:
Claude
2026-02-08 20:49:18 +00:00
parent 395f3aace5
commit 2c18b734ee
13 changed files with 76 additions and 169 deletions
+2 -2
View File
@@ -1619,7 +1619,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
const content = assertMediaContent(message.message)
const mediaKey = content.mediaKey!
const meId = authState.creds.me!.id
const node = await encryptMediaRetryRequest(message.key, mediaKey, meId)
const node = encryptMediaRetryRequest(message.key, mediaKey, meId)
let error: Error | undefined = undefined
await Promise.all([
@@ -1631,7 +1631,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
error = result.error
} else {
try {
const media = await decryptMediaRetryData(result.media!, mediaKey, result.key.id!)
const media = decryptMediaRetryData(result.media!, mediaKey, result.key.id!)
if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
const resultStr = proto.MediaRetryNotification.ResultType[media.result!]
throw new Boom(`Media re-upload failed by device (${resultStr})`, {