From 154926ec3cf5d59edf20614ee59a117eee02aeb7 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Sun, 6 Nov 2022 20:06:50 +0530 Subject: [PATCH] chore: correctly throw app state key not found --- src/Utils/chat-utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index 5de42e1..d7e566c 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -9,7 +9,7 @@ import { toNumber } from './generics' import { LT_HASH_ANTI_TAMPERING } from './lt-hash' import { downloadContentFromMessage, } from './messages-media' -type FetchAppStateSyncKey = (keyId: string) => Promise | proto.Message.IAppStateSyncKeyData +type FetchAppStateSyncKey = (keyId: string) => Promise const mutationKeys = (keydata: Uint8Array) => { const expanded = hkdf(keydata, 160, { info: 'WhatsApp Mutation Keys' }) @@ -261,6 +261,10 @@ export const decodeSyncdPatch = async( if(validateMacs) { const base64Key = Buffer.from(msg.keyId!.id!).toString('base64') const mainKeyObj = await getAppStateSyncKey(base64Key) + if(!mainKeyObj) { + throw new Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } }) + } + const mainKey = mutationKeys(mainKeyObj.keyData!) const mutationmacs = msg.mutations!.map(mutation => mutation.record!.value!.blob!.slice(-32))