diff --git a/src/Defaults/index.ts b/src/Defaults/index.ts index 7e75838d..11885d93 100644 --- a/src/Defaults/index.ts +++ b/src/Defaults/index.ts @@ -31,9 +31,26 @@ export const STATUS_EXPIRY_SECONDS = 24 * 60 * 60 export const PLACEHOLDER_MAX_AGE_SECONDS = 7 * 24 * 60 * 60 export const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0' -export const DICT_VERSION = 3 + +/** + * Protocol mode: 'web' (default) or 'native' (experimental) + * - web: WA\x06\x03 — standard WhatsApp Web protocol + * - native: WAM\x05 — native Android protocol (may enable view-once media on companions) + * + * Set via BAILEYS_PROTOCOL env var: + * BAILEYS_PROTOCOL=native + */ +const PROTOCOL_MODE = process.env.BAILEYS_PROTOCOL?.trim().toLowerCase() === 'native' ? 'native' : 'web' + +export const DICT_VERSION = PROTOCOL_MODE === 'native' ? 5 : 3 export const KEY_BUNDLE_TYPE = Buffer.from([5]) -export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]) // last is "DICT_VERSION" + +// WA\x06\x03 = web protocol, WAM\x05 = native Android protocol +export const NOISE_WA_HEADER = PROTOCOL_MODE === 'native' + ? Buffer.from([87, 65, 77, DICT_VERSION]) // WAM\x05 + : Buffer.from([87, 65, 6, DICT_VERSION]) // WA\x06\x03 + +export { PROTOCOL_MODE } /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */ export const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g diff --git a/src/Utils/validate-connection.ts b/src/Utils/validate-connection.ts index ba130da3..a5ed8f1b 100644 --- a/src/Utils/validate-connection.ts +++ b/src/Utils/validate-connection.ts @@ -3,6 +3,7 @@ import { createHash } from 'crypto' import { proto } from '../../WAProto/index.js' import { KEY_BUNDLE_TYPE, + PROTOCOL_MODE, WA_ADV_ACCOUNT_SIG_PREFIX, WA_ADV_DEVICE_SIG_PREFIX, WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX @@ -58,7 +59,10 @@ const getClientPayload = (config: SocketConfig) => { userAgent: getUserAgent(config) } - payload.webInfo = getWebInfo(config) + // Native protocol (WAM\x05) does not use WebInfo — only web protocol does + if (PROTOCOL_MODE !== 'native') { + payload.webInfo = getWebInfo(config) + } return payload }