feat: replace async crypto with sync Rust WASM for app state sync (#2315)

* feat: replace async crypto with sync Rust WASM for app state sync

* fix: remove unecessary buffer copying

* fix: update whatsapp-rust-bridge to version 0.5.2 and refactor async calls to sync. HKDF and MD5 in rust
This commit is contained in:
João Lucas
2026-02-05 11:06:47 -03:00
committed by GitHub
parent fa2a837a4a
commit b5c174111f
12 changed files with 97 additions and 181 deletions
+5 -5
View File
@@ -106,7 +106,7 @@ export async function getMediaKeys(
}
// expand using HKDF to 112 bytes, also pass in the relevant app info
const expandedMediaKey = await hkdf(buffer, 112, { info: hkdfInfoKey(mediaType) })
const expandedMediaKey = hkdf(buffer, 112, { info: hkdfInfoKey(mediaType) })
return {
iv: expandedMediaKey.slice(0, 16),
cipherKey: expandedMediaKey.slice(16, 48),
@@ -888,12 +888,12 @@ const getMediaRetryKey = (mediaKey: Buffer | Uint8Array) => {
/**
* Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
*/
export const encryptMediaRetryRequest = async (key: WAMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => {
export const encryptMediaRetryRequest = (key: WAMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => {
const recp: proto.IServerErrorReceipt = { stanzaId: key.id }
const recpBuffer = proto.ServerErrorReceipt.encode(recp).finish()
const iv = Crypto.randomBytes(12)
const retryKey = await getMediaRetryKey(mediaKey)
const retryKey = getMediaRetryKey(mediaKey)
const ciphertext = aesEncryptGCM(recpBuffer, retryKey, iv, Buffer.from(key.id!))
const req: BinaryNode = {
@@ -963,12 +963,12 @@ export const decodeMediaRetryNode = (node: BinaryNode) => {
return event
}
export const decryptMediaRetryData = async (
export const decryptMediaRetryData = (
{ ciphertext, iv }: { ciphertext: Uint8Array; iv: Uint8Array },
mediaKey: Uint8Array,
msgId: string
) => {
const retryKey = await getMediaRetryKey(mediaKey)
const retryKey = getMediaRetryKey(mediaKey)
const plaintext = aesDecryptGCM(ciphertext, retryKey, iv, Buffer.from(msgId))
return proto.MediaRetryNotification.decode(plaintext)
}