fix: incorrect enc msg detection

This commit is contained in:
Adhiraj Singh
2021-12-19 00:33:33 +05:30
parent 89a159aac3
commit af0804048c

View File

@@ -30,7 +30,9 @@ export const decodeWAMessage = (
if(typeof data === 'string' || !possiblyEnc) { if(typeof data === 'string' || !possiblyEnc) {
json = JSON.parse(data.toString()) // parse the JSON json = JSON.parse(data.toString()) // parse the JSON
} else { } else {
try {
json = JSON.parse(data.toString())
} catch {
const { macKey, encKey } = auth || {} const { macKey, encKey } = auth || {}
if (!macKey || !encKey) { if (!macKey || !encKey) {
throw new Boom('recieved encrypted buffer when auth creds unavailable', { data: message, statusCode: DisconnectReason.badSession }) throw new Boom('recieved encrypted buffer when auth creds unavailable', { data: message, statusCode: DisconnectReason.badSession })
@@ -66,6 +68,7 @@ export const decodeWAMessage = (
} }
} }
} }
}
return [messageTag, json, tags] as const return [messageTag, json, tags] as const
} }