From 47540e961ed1530b3fa2b46847258fdaceacce5b Mon Sep 17 00:00:00 2001 From: w3nder Date: Tue, 22 Apr 2025 15:58:25 -0300 Subject: [PATCH 1/3] fix: readAdJid domainType jid = 0 and 128 lid = 1 and 129 --- src/WABinary/decode.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/WABinary/decode.ts b/src/WABinary/decode.ts index 23bb480..e138ade 100644 --- a/src/WABinary/decode.ts +++ b/src/WABinary/decode.ts @@ -3,6 +3,7 @@ import { inflate } from 'zlib' import * as constants from './constants' import { jidEncode } from './jid-utils' import type { BinaryNode, BinaryNodeCodingOptions } from './types' +import logger from '../Utils/logger' const inflatePromise = promisify(inflate) @@ -147,11 +148,26 @@ export const decodeDecompressedBinaryNode = ( } const readAdJid = () => { - const agent = readByte() + const rawDomainType = readByte() + const domainType = typeof rawDomainType === 'number' + ? rawDomainType + : Number(rawDomainType) + + const device = readByte() const user = readString(readByte()) - return jidEncode(user, agent === 0 ? 's.whatsapp.net' : 'lid', device) + if((domainType & 1) !== 0 || (domainType & 0x80) === 0) { + if(![0, 1].includes(domainType)) { + logger.warn('Possibly invalid domainType:', domainType, user, device) + } + } + + return jidEncode( + user, + domainType === 0 || domainType === 128 ? 's.whatsapp.net' : 'lid', + device + ) } const readString = (tag: number): string => { From 131aeadd45065512bd0b2d420673d605f209c373 Mon Sep 17 00:00:00 2001 From: w3nder Date: Tue, 22 Apr 2025 19:45:20 -0300 Subject: [PATCH 2/3] fix: lint --- src/WABinary/decode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WABinary/decode.ts b/src/WABinary/decode.ts index e138ade..d8da84e 100644 --- a/src/WABinary/decode.ts +++ b/src/WABinary/decode.ts @@ -1,9 +1,9 @@ import { promisify } from 'util' import { inflate } from 'zlib' +import logger from '../Utils/logger' import * as constants from './constants' import { jidEncode } from './jid-utils' import type { BinaryNode, BinaryNodeCodingOptions } from './types' -import logger from '../Utils/logger' const inflatePromise = promisify(inflate) From f4dc41eda10b01e638c85d434a9db4822467ee0d Mon Sep 17 00:00:00 2001 From: w3nder Date: Tue, 22 Apr 2025 21:30:39 -0300 Subject: [PATCH 3/3] fix: simplify domainType --- src/WABinary/decode.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/WABinary/decode.ts b/src/WABinary/decode.ts index d8da84e..53e8c86 100644 --- a/src/WABinary/decode.ts +++ b/src/WABinary/decode.ts @@ -149,10 +149,7 @@ export const decodeDecompressedBinaryNode = ( const readAdJid = () => { const rawDomainType = readByte() - const domainType = typeof rawDomainType === 'number' - ? rawDomainType - : Number(rawDomainType) - + const domainType = Number(rawDomainType) const device = readByte() const user = readString(readByte())