@xbibzlibrary/whatsbibz 1.4.0 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.cn.md +5 -5
  3. package/README.id.md +5 -5
  4. package/README.md +5 -5
  5. package/SECURITY.md +6 -6
  6. package/WAProto/WAProto.proto +1 -0
  7. package/WAProto/index.d.ts +1 -0
  8. package/WAProto/index.js +1 -0
  9. package/lib/BibzWhats/banner.d.ts +1 -0
  10. package/lib/BibzWhats/banner.js +1 -0
  11. package/lib/BibzWhats/client.d.ts +1 -0
  12. package/lib/BibzWhats/client.js +1 -0
  13. package/lib/BibzWhats/device-identity.d.ts +1 -0
  14. package/lib/BibzWhats/device-identity.js +1 -0
  15. package/lib/BibzWhats/extract.d.ts +1 -0
  16. package/lib/BibzWhats/extract.js +1 -0
  17. package/lib/BibzWhats/index.d.ts +1 -0
  18. package/lib/BibzWhats/index.js +1 -0
  19. package/lib/BibzWhats/jid.d.ts +1 -0
  20. package/lib/BibzWhats/jid.js +1 -0
  21. package/lib/BibzWhats/pairing.d.ts +1 -0
  22. package/lib/BibzWhats/pairing.js +1 -0
  23. package/lib/BibzWhats/send.d.ts +1 -0
  24. package/lib/BibzWhats/send.js +1 -0
  25. package/lib/BibzWhats/version.js +5 -4
  26. package/lib/Defaults/index.d.ts +3 -0
  27. package/lib/Defaults/index.js +4 -6
  28. package/lib/Modded/message_builder.d.ts +1 -0
  29. package/lib/Modded/message_builder.js +13 -36
  30. package/lib/Signal/Group/ciphertext-message.d.ts +1 -0
  31. package/lib/Signal/Group/ciphertext-message.js +1 -0
  32. package/lib/Signal/Group/group-session-builder.d.ts +1 -0
  33. package/lib/Signal/Group/group-session-builder.js +1 -0
  34. package/lib/Signal/Group/group_cipher.d.ts +1 -0
  35. package/lib/Signal/Group/group_cipher.js +1 -0
  36. package/lib/Signal/Group/index.d.ts +1 -0
  37. package/lib/Signal/Group/index.js +1 -0
  38. package/lib/Signal/Group/keyhelper.d.ts +1 -0
  39. package/lib/Signal/Group/keyhelper.js +1 -0
  40. package/lib/Signal/Group/sender-chain-key.d.ts +1 -0
  41. package/lib/Signal/Group/sender-chain-key.js +1 -0
  42. package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -0
  43. package/lib/Signal/Group/sender-key-distribution-message.js +1 -0
  44. package/lib/Signal/Group/sender-key-message.d.ts +1 -0
  45. package/lib/Signal/Group/sender-key-message.js +1 -0
  46. package/lib/Signal/Group/sender-key-name.d.ts +1 -0
  47. package/lib/Signal/Group/sender-key-name.js +1 -0
  48. package/lib/Signal/Group/sender-key-record.d.ts +1 -0
  49. package/lib/Signal/Group/sender-key-record.js +1 -0
  50. package/lib/Signal/Group/sender-key-state.d.ts +1 -0
  51. package/lib/Signal/Group/sender-key-state.js +1 -0
  52. package/lib/Signal/Group/sender-message-key.d.ts +1 -0
  53. package/lib/Signal/Group/sender-message-key.js +1 -0
  54. package/lib/Signal/libsignal.d.ts +1 -0
  55. package/lib/Signal/libsignal.js +1 -0
  56. package/lib/Signal/lid-mapping.d.ts +1 -0
  57. package/lib/Signal/lid-mapping.js +1 -0
  58. package/lib/Socket/Client/index.d.ts +1 -0
  59. package/lib/Socket/Client/index.js +1 -0
  60. package/lib/Socket/Client/types.d.ts +1 -0
  61. package/lib/Socket/Client/types.js +1 -0
  62. package/lib/Socket/Client/websocket.d.ts +1 -0
  63. package/lib/Socket/Client/websocket.js +1 -0
  64. package/lib/Socket/business.d.ts +1 -2
  65. package/lib/Socket/business.js +1 -0
  66. package/lib/Socket/chats.d.ts +1 -0
  67. package/lib/Socket/chats.js +1 -0
  68. package/lib/Socket/communities.d.ts +1 -2
  69. package/lib/Socket/communities.js +12 -2
  70. package/lib/Socket/engine.d.ts +1 -0
  71. package/lib/Socket/engine.js +1 -0
  72. package/lib/Socket/groups.d.ts +1 -0
  73. package/lib/Socket/groups.js +1 -0
  74. package/lib/Socket/index.d.ts +1 -2
  75. package/lib/Socket/index.js +12 -11
  76. package/lib/Socket/messages-recv.d.ts +1 -2
  77. package/lib/Socket/messages-recv.js +13 -4
  78. package/lib/Socket/messages-send.d.ts +7 -2
  79. package/lib/Socket/messages-send.js +59 -23
  80. package/lib/Socket/mex.d.ts +1 -0
  81. package/lib/Socket/mex.js +1 -0
  82. package/lib/Socket/newsletter.d.ts +1 -1
  83. package/lib/Socket/newsletter.js +255 -432
  84. package/lib/Socket/socket.d.ts +1 -0
  85. package/lib/Socket/socket.js +20 -1
  86. package/lib/Types/Auth.d.ts +2 -0
  87. package/lib/Types/Auth.js +1 -0
  88. package/lib/Types/Bussines.d.ts +1 -0
  89. package/lib/Types/Bussines.js +1 -0
  90. package/lib/Types/Call.d.ts +1 -0
  91. package/lib/Types/Call.js +1 -0
  92. package/lib/Types/Chat.d.ts +1 -0
  93. package/lib/Types/Chat.js +1 -0
  94. package/lib/Types/Contact.d.ts +1 -0
  95. package/lib/Types/Contact.js +1 -0
  96. package/lib/Types/Events.d.ts +1 -0
  97. package/lib/Types/Events.js +1 -0
  98. package/lib/Types/GroupMetadata.d.ts +1 -0
  99. package/lib/Types/GroupMetadata.js +1 -0
  100. package/lib/Types/Label.d.ts +1 -0
  101. package/lib/Types/Label.js +1 -0
  102. package/lib/Types/LabelAssociation.d.ts +1 -0
  103. package/lib/Types/LabelAssociation.js +1 -0
  104. package/lib/Types/Message.d.ts +1 -0
  105. package/lib/Types/Message.js +1 -0
  106. package/lib/Types/Newsletter.d.ts +1 -0
  107. package/lib/Types/Newsletter.js +1 -0
  108. package/lib/Types/Product.d.ts +1 -0
  109. package/lib/Types/Product.js +1 -0
  110. package/lib/Types/Signal.d.ts +1 -0
  111. package/lib/Types/Signal.js +1 -0
  112. package/lib/Types/Socket.d.ts +1 -6
  113. package/lib/Types/Socket.js +1 -0
  114. package/lib/Types/State.d.ts +1 -0
  115. package/lib/Types/State.js +1 -0
  116. package/lib/Types/USync.d.ts +1 -0
  117. package/lib/Types/USync.js +1 -0
  118. package/lib/Types/index.d.ts +1 -0
  119. package/lib/Types/index.js +1 -0
  120. package/lib/Utils/auth-utils.d.ts +1 -0
  121. package/lib/Utils/auth-utils.js +4 -0
  122. package/lib/Utils/browser-utils.d.ts +1 -0
  123. package/lib/Utils/browser-utils.js +3 -2
  124. package/lib/Utils/business.d.ts +1 -0
  125. package/lib/Utils/business.js +1 -0
  126. package/lib/Utils/chat-utils.d.ts +1 -0
  127. package/lib/Utils/chat-utils.js +1 -0
  128. package/lib/Utils/companion-reg-client-utils.d.ts +1 -0
  129. package/lib/Utils/companion-reg-client-utils.js +1 -0
  130. package/lib/Utils/crypto.d.ts +1 -0
  131. package/lib/Utils/crypto.js +1 -0
  132. package/lib/Utils/decode-wa-message.d.ts +1 -0
  133. package/lib/Utils/decode-wa-message.js +1 -0
  134. package/lib/Utils/event-buffer.d.ts +1 -0
  135. package/lib/Utils/event-buffer.js +9 -0
  136. package/lib/Utils/generics.d.ts +1 -0
  137. package/lib/Utils/generics.js +5 -3
  138. package/lib/Utils/history.d.ts +1 -0
  139. package/lib/Utils/history.js +1 -0
  140. package/lib/Utils/identity-change-handler.d.ts +1 -0
  141. package/lib/Utils/identity-change-handler.js +1 -0
  142. package/lib/Utils/index.d.ts +2 -0
  143. package/lib/Utils/index.js +2 -0
  144. package/lib/Utils/link-preview.d.ts +1 -0
  145. package/lib/Utils/link-preview.js +18 -13
  146. package/lib/Utils/logger.d.ts +1 -0
  147. package/lib/Utils/logger.js +1 -0
  148. package/lib/Utils/lt-hash.d.ts +1 -0
  149. package/lib/Utils/lt-hash.js +1 -0
  150. package/lib/Utils/make-mutex.d.ts +1 -0
  151. package/lib/Utils/make-mutex.js +1 -0
  152. package/lib/Utils/message-retry-manager.d.ts +1 -0
  153. package/lib/Utils/message-retry-manager.js +1 -0
  154. package/lib/Utils/messages-media.d.ts +1 -0
  155. package/lib/Utils/messages-media.js +31 -94
  156. package/lib/Utils/messages.d.ts +5 -0
  157. package/lib/Utils/messages.js +50 -5
  158. package/lib/Utils/node-security-2026-10.d.ts +18 -0
  159. package/lib/Utils/node-security-2026-10.js +236 -0
  160. package/lib/Utils/noise-handler.d.ts +1 -0
  161. package/lib/Utils/noise-handler.js +1 -0
  162. package/lib/Utils/offline-node-processor.d.ts +2 -0
  163. package/lib/Utils/offline-node-processor.js +6 -0
  164. package/lib/Utils/platform-identity.d.ts +1 -0
  165. package/lib/Utils/platform-identity.js +1 -0
  166. package/lib/Utils/pre-key-manager.d.ts +1 -0
  167. package/lib/Utils/pre-key-manager.js +1 -0
  168. package/lib/Utils/process-message.d.ts +1 -0
  169. package/lib/Utils/process-message.js +1 -0
  170. package/lib/Utils/reporting-utils.d.ts +1 -0
  171. package/lib/Utils/reporting-utils.js +1 -0
  172. package/lib/Utils/rich-messages.d.ts +1 -0
  173. package/lib/Utils/rich-messages.js +1 -0
  174. package/lib/Utils/signal.d.ts +1 -0
  175. package/lib/Utils/signal.js +1 -0
  176. package/lib/Utils/stanza-ack.d.ts +1 -0
  177. package/lib/Utils/stanza-ack.js +1 -0
  178. package/lib/Utils/sticker-pack.d.ts +1 -0
  179. package/lib/Utils/sticker-pack.js +1 -0
  180. package/lib/Utils/sync-action-utils.d.ts +1 -0
  181. package/lib/Utils/sync-action-utils.js +1 -0
  182. package/lib/Utils/tc-token-utils.d.ts +1 -0
  183. package/lib/Utils/tc-token-utils.js +1 -0
  184. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
  185. package/lib/Utils/use-multi-file-auth-state.js +1 -0
  186. package/lib/Utils/validate-connection.d.ts +1 -0
  187. package/lib/Utils/validate-connection.js +1 -0
  188. package/lib/VoIP/audio-feeder.d.ts +1 -0
  189. package/lib/VoIP/audio-feeder.js +1 -0
  190. package/lib/VoIP/index.d.ts +1 -0
  191. package/lib/VoIP/index.js +1 -0
  192. package/lib/VoIP/relay-transport.d.ts +1 -0
  193. package/lib/VoIP/relay-transport.js +1 -0
  194. package/lib/VoIP/signaling.js +1 -0
  195. package/lib/VoIP/types.d.ts +1 -0
  196. package/lib/VoIP/types.js +1 -0
  197. package/lib/VoIP/wasm-engine.d.ts +1 -0
  198. package/lib/VoIP/wasm-engine.js +1 -0
  199. package/lib/VoIP/worker-bootstrap.js +2 -1
  200. package/lib/WABinary/constants.d.ts +1 -0
  201. package/lib/WABinary/constants.js +1 -0
  202. package/lib/WABinary/decode.d.ts +1 -0
  203. package/lib/WABinary/decode.js +1 -0
  204. package/lib/WABinary/encode.d.ts +1 -0
  205. package/lib/WABinary/encode.js +1 -0
  206. package/lib/WABinary/generic-utils.d.ts +1 -0
  207. package/lib/WABinary/generic-utils.js +1 -0
  208. package/lib/WABinary/index.d.ts +1 -0
  209. package/lib/WABinary/index.js +1 -0
  210. package/lib/WABinary/jid-utils.d.ts +1 -0
  211. package/lib/WABinary/jid-utils.js +1 -0
  212. package/lib/WABinary/types.d.ts +1 -0
  213. package/lib/WABinary/types.js +1 -0
  214. package/lib/WAM/BinaryInfo.d.ts +1 -0
  215. package/lib/WAM/BinaryInfo.js +1 -0
  216. package/lib/WAM/constants.d.ts +1 -0
  217. package/lib/WAM/constants.js +1 -0
  218. package/lib/WAM/encode.d.ts +1 -0
  219. package/lib/WAM/encode.js +1 -0
  220. package/lib/WAM/index.d.ts +1 -0
  221. package/lib/WAM/index.js +1 -0
  222. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +1 -0
  223. package/lib/WAUSync/Protocols/USyncContactProtocol.js +1 -0
  224. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +1 -0
  225. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +1 -0
  226. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +1 -0
  227. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -0
  228. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +1 -0
  229. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +1 -0
  230. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +1 -0
  231. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -0
  232. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +1 -0
  233. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -0
  234. package/lib/WAUSync/Protocols/index.d.ts +1 -0
  235. package/lib/WAUSync/Protocols/index.js +1 -0
  236. package/lib/WAUSync/USyncQuery.d.ts +1 -0
  237. package/lib/WAUSync/USyncQuery.js +1 -0
  238. package/lib/WAUSync/USyncUser.d.ts +1 -0
  239. package/lib/WAUSync/USyncUser.js +1 -0
  240. package/lib/WAUSync/index.d.ts +1 -0
  241. package/lib/WAUSync/index.js +1 -0
  242. package/lib/assets/wasm/loader.js +1 -0
  243. package/lib/assets/wasm/worker-modules.js +1 -0
  244. package/lib/index.d.ts +1 -0
  245. package/lib/index.js +1 -1
  246. package/package.json +33 -14
  247. package/WAProto/GenerateStatics.sh +0 -3
  248. package/WAProto/fix-imports.js +0 -81
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/messages-media */
1
2
  import { Boom } from '@hapi/boom';
2
3
  import { exec } from 'child_process';
3
4
  import * as Crypto from 'crypto';
@@ -12,6 +13,7 @@ import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP } from '../Defau
12
13
  import { getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary/index.js';
13
14
  import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto.js';
14
15
  import { generateMessageIDV2 } from './generics.js';
16
+ import { safeFetch } from './node-security-2026-10.js';
15
17
  const getTmpFilesDirectory = () => tmpdir();
16
18
  const getImageProcessingLibrary = async () => {
17
19
  //@ts-ignore
@@ -295,7 +297,7 @@ export async function generateThumbnail(file, mediaType, options) {
295
297
  };
296
298
  }
297
299
  export const getHttpStream = async (url, options = {}) => {
298
- const response = await fetch(url.toString(), {
300
+ const response = await safeFetch(url.toString(), {
299
301
  dispatcher: options.dispatcher,
300
302
  method: 'GET',
301
303
  headers: options.headers
@@ -491,6 +493,7 @@ export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, {
491
493
  }
492
494
  }
493
495
  });
496
+ fetched.on('error', error => output.destroy(error));
494
497
  return fetched.pipe(output, { end: true });
495
498
  };
496
499
  export function extensionForMediaMessage(message) {
@@ -512,72 +515,13 @@ const isNodeRuntime = () => {
512
515
  typeof process.versions.bun === 'undefined' &&
513
516
  typeof globalThis.Deno === 'undefined');
514
517
  };
515
- export const uploadWithNodeHttp = async ({ url, filePath, headers, timeoutMs, agent }, redirectCount = 0) => {
516
- if (redirectCount > 5) {
517
- throw new Error('Too many redirects');
518
- }
519
- const parsedUrl = new URL(url);
520
- const httpModule = parsedUrl.protocol === 'https:' ? await import('https') : await import('http');
521
- // Get file size for Content-Length header (required for Node.js streaming)
522
- const fileStats = await fs.stat(filePath);
523
- const fileSize = fileStats.size;
524
- return new Promise((resolve, reject) => {
525
- const req = httpModule.request({
526
- hostname: parsedUrl.hostname,
527
- port: parsedUrl.port || (parsedUrl.protocol === 'https:' ? 443 : 80),
528
- path: parsedUrl.pathname + parsedUrl.search,
529
- method: 'POST',
530
- headers: {
531
- ...headers,
532
- 'Content-Length': fileSize
533
- },
534
- agent,
535
- timeout: timeoutMs
536
- }, res => {
537
- // Handle redirects (3xx)
538
- if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
539
- res.resume(); // Consume response to free resources
540
- const newUrl = new URL(res.headers.location, url).toString();
541
- resolve(uploadWithNodeHttp({
542
- url: newUrl,
543
- filePath,
544
- headers,
545
- timeoutMs,
546
- agent
547
- }, redirectCount + 1));
548
- return;
549
- }
550
- let body = '';
551
- res.on('data', chunk => (body += chunk));
552
- res.on('end', () => {
553
- try {
554
- resolve(JSON.parse(body));
555
- }
556
- catch {
557
- resolve(undefined);
558
- }
559
- });
560
- });
561
- req.on('error', reject);
562
- req.on('timeout', () => {
563
- req.destroy();
564
- reject(new Error('Upload timeout'));
565
- });
566
- const stream = createReadStream(filePath);
567
- stream.pipe(req);
568
- stream.on('error', err => {
569
- req.destroy();
570
- reject(err);
571
- });
572
- });
573
- };
574
518
  const uploadWithFetch = async ({ url, filePath, headers, timeoutMs, agent }) => {
575
519
  // Convert Node.js Readable to Web ReadableStream
576
520
  const nodeStream = createReadStream(filePath);
577
521
  const webStream = Readable.toWeb(nodeStream);
578
522
  // Native fetch hanya menerima dispatcher gaya Undici, bukan https.Agent biasa (upstream #2557)
579
523
  const dispatcher = typeof agent?.dispatch === 'function' ? agent : undefined;
580
- const response = await fetch(url, {
524
+ const response = await safeFetch(url, {
581
525
  ...(dispatcher ? { dispatcher } : {}),
582
526
  method: 'POST',
583
527
  body: webStream,
@@ -592,32 +536,15 @@ const uploadWithFetch = async ({ url, filePath, headers, timeoutMs, agent }) =>
592
536
  return undefined;
593
537
  }
594
538
  };
539
+ export const uploadWithNodeHttp = async (params) => {
540
+ return uploadWithFetch(params);
541
+ };
595
542
  /**
596
- * Uploads media to WhatsApp servers.
597
- *
598
- * ## Why we have two upload implementations:
599
- *
600
- * Node.js's native `fetch` (powered by undici) has a known bug where it buffers
601
- * the entire request body in memory before sending, even when using streams.
602
- * This causes memory issues with large files (e.g., 1GB file = 1GB+ memory usage).
603
- * See: https://github.com/nodejs/undici/issues/4058
604
- *
605
- * Other runtimes (Bun, Deno, browsers) correctly stream the request body without
606
- * buffering, so we can use the web-standard Fetch API there.
607
- *
608
- * ## Future considerations:
609
- * Once the undici bug is fixed, we can simplify this to use only the Fetch API
610
- * across all runtimes. Monitor the GitHub issue for updates.
543
+ * Uploads media to WhatsApp servers using Web-standard Fetch API.
611
544
  */
612
545
  const uploadMedia = async (params, logger) => {
613
- if (isNodeRuntime()) {
614
- logger?.debug('Using Node.js https module for upload (avoids undici buffering bug)');
615
- return uploadWithNodeHttp(params);
616
- }
617
- else {
618
- logger?.debug('Using web-standard Fetch API for upload');
619
- return uploadWithFetch(params);
620
- }
546
+ logger?.debug('Using web-standard Fetch API for upload');
547
+ return uploadWithFetch(params);
621
548
  };
622
549
  export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
623
550
  return async (streamOrPath, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
@@ -651,22 +578,29 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
651
578
  if (newsletter && mediaPath) {
652
579
  mediaPath = mediaPath.replace('/mms/', '/newsletter/newsletter-');
653
580
  }
581
+ const dispatcher = typeof fetchAgent?.dispatch === 'function' ? fetchAgent : undefined;
654
582
  for (const { hostname } of hosts) {
655
583
  logger.debug(`uploading to "${hostname}"`);
656
584
  const auth = encodeURIComponent(uploadInfo.auth);
657
585
  const url = `https://${hostname}${mediaPath}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
658
586
  let result;
659
587
  try {
660
- const axios = (await import('axios')).default;
661
- const body = await axios.post(url, reqBuffer, {
662
- headers,
663
- httpsAgent: fetchAgent,
664
- timeout: timeoutMs,
665
- responseType: 'json',
666
- maxBodyLength: Infinity,
667
- maxContentLength: Infinity
588
+ const response = await safeFetch(url, {
589
+ ...(dispatcher ? { dispatcher } : {}),
590
+ method: 'POST',
591
+ body: reqBuffer,
592
+ headers: {
593
+ ...headers,
594
+ 'Content-Length': String(reqBuffer.length)
595
+ },
596
+ signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined
668
597
  });
669
- result = body.data;
598
+ try {
599
+ result = await response.json();
600
+ }
601
+ catch {
602
+ result = undefined;
603
+ }
670
604
  if (result?.url || result?.direct_path) {
671
605
  urls = {
672
606
  mediaUrl: result.url,
@@ -696,7 +630,10 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
696
630
  };
697
631
 
698
632
  const getMediaRetryKey = (mediaKey) => {
699
- return hkdf(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' });
633
+ const keyBuf = typeof mediaKey === 'string'
634
+ ? Buffer.from(mediaKey.replace('data:;base64,', ''), 'base64')
635
+ : mediaKey;
636
+ return hkdf(keyBuf, 32, { info: 'WhatsApp Media Retry Notification' });
700
637
  };
701
638
  /**
702
639
  * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/messages */
1
2
  import { type Transform } from 'stream';
2
3
  import { proto } from '../../WAProto/index.js';
3
4
  import type { AnyMediaMessageContent, AnyMessageContent, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAMessageKey } from '../Types/index.js';
@@ -32,6 +33,10 @@ export declare const getContentType: (content: proto.IMessage | undefined) => ke
32
33
  * @returns
33
34
  */
34
35
  export declare const normalizeMessageContent: (content: WAMessageContent | null | undefined) => WAMessageContent | undefined;
36
+ /**
37
+ * Checks whether a message content (or any of its wrappers) is a view-once message
38
+ */
39
+ export declare const isViewOnceMessage: (content: WAMessageContent | null | undefined) => boolean;
35
40
  /**
36
41
  * Extract the true message content from a message
37
42
  * Eg. extracts the inner message from a disappearing message/view once message
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/messages */
1
2
  import { Boom } from "@hapi/boom";
2
3
  import { randomBytes } from "crypto";
3
4
  import { promises as fs } from "fs";
@@ -974,6 +975,43 @@ export const normalizeMessageContent = (content) => {
974
975
  );
975
976
  }
976
977
  };
978
+ /**
979
+ * Checks whether a message content (or any of its wrappers) is a view-once message
980
+ */
981
+ export const isViewOnceMessage = (content) => {
982
+ if (!content) {
983
+ return false;
984
+ }
985
+ const hasViewOnceFlag = (msg) =>
986
+ Boolean(
987
+ msg?.imageMessage?.viewOnce ||
988
+ msg?.videoMessage?.viewOnce ||
989
+ msg?.audioMessage?.viewOnce,
990
+ );
991
+ for (let i = 0; i < 5 && content; i++) {
992
+ if (
993
+ content.viewOnceMessage ||
994
+ content.viewOnceMessageV2 ||
995
+ content.viewOnceMessageV2Extension ||
996
+ content.viewOnceMessageV3 ||
997
+ hasViewOnceFlag(content)
998
+ ) {
999
+ return true;
1000
+ }
1001
+ const inner =
1002
+ content.ephemeralMessage ||
1003
+ content.documentWithCaptionMessage ||
1004
+ content.editedMessage ||
1005
+ content.associatedChildMessage ||
1006
+ content.groupStatusMessage ||
1007
+ content.groupStatusMessageV2;
1008
+ if (!inner) {
1009
+ break;
1010
+ }
1011
+ content = inner.message;
1012
+ }
1013
+ return false;
1014
+ };
977
1015
  /**
978
1016
  * Extract the true message content from a message
979
1017
  * Eg. extracts the inner message from a disappearing message/view once message
@@ -1158,16 +1196,17 @@ export const aggregateMessageKeysNotFromMe = (keys) => {
1158
1196
  }
1159
1197
  return Object.values(keyMap);
1160
1198
  };
1161
- const REUPLOAD_REQUIRED_STATUS = [410, 404];
1199
+ const REUPLOAD_REQUIRED_STATUS = [403, 404, 410];
1162
1200
  /**
1163
1201
  * Downloads the given message. Throws an error if it's not a media message
1164
1202
  */
1165
1203
  export const downloadMediaMessage = async (message, type, options, ctx) => {
1166
1204
  const result = await downloadMsg().catch(async (error) => {
1205
+ const status = error?.output?.statusCode ?? error?.status;
1167
1206
  if (
1168
1207
  ctx &&
1169
- typeof error?.status === "number" && // treat errors with status as HTTP failures requiring reupload
1170
- REUPLOAD_REQUIRED_STATUS.includes(error.status)
1208
+ typeof status === "number" && // treat errors with status as HTTP failures requiring reupload
1209
+ REUPLOAD_REQUIRED_STATUS.includes(status)
1171
1210
  ) {
1172
1211
  ctx.logger.info(
1173
1212
  { key: message.key },
@@ -1192,12 +1231,18 @@ export const downloadMediaMessage = async (message, type, options, ctx) => {
1192
1231
  if (
1193
1232
  !media ||
1194
1233
  typeof media !== "object" ||
1195
- (!("url" in media) && !("thumbnailDirectPath" in media))
1234
+ (!("url" in media) &&
1235
+ !("directPath" in media) &&
1236
+ !("thumbnailDirectPath" in media))
1196
1237
  ) {
1197
1238
  throw new Boom(`"${contentType}" message is not a media message`);
1198
1239
  }
1199
1240
  let download;
1200
- if ("thumbnailDirectPath" in media && !("url" in media)) {
1241
+ if (
1242
+ "thumbnailDirectPath" in media &&
1243
+ !("url" in media) &&
1244
+ !("directPath" in media)
1245
+ ) {
1201
1246
  download = {
1202
1247
  directPath: media.thumbnailDirectPath,
1203
1248
  mediaKey: media.mediaKey,
@@ -0,0 +1,18 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/node-security-2026-10 */
2
+ export declare const SAFE_ACCEPT_ENCODING = "gzip, deflate";
3
+ export declare const NODE_OCT_2026_CVES: readonly string[];
4
+ export declare const PATCHED_NODE_MIN_VERSIONS: Readonly<Record<number, readonly [number, number, number]>>;
5
+ export declare const parseNodeVersion: (versionStr?: string) => [number, number, number] | null;
6
+ export declare const isNodePatchedOct2026: (versionStr?: string) => boolean;
7
+ export declare const getNodeSecurityStatus: (versionStr?: string) => {
8
+ currentVersion: string;
9
+ patched: boolean;
10
+ eolLine: boolean;
11
+ recommendedVersion: string;
12
+ mitigatedByBibzWhats: boolean;
13
+ cves: readonly string[];
14
+ };
15
+ export declare const isNonCanonicalIpv4Host: (hostname?: string) => boolean;
16
+ export declare const assertSafeUrl: (inputUrl: string | URL) => URL;
17
+ export declare const withSafeFetchHeaders: (headers?: Record<string, string> | [string, string][] | Headers) => Record<string, string>;
18
+ export declare const safeFetch: (inputUrl: string | URL, init?: RequestInit & { dispatcher?: unknown }) => Promise<Response>;
@@ -0,0 +1,236 @@
1
+ /**
2
+ * @module @xbibzlibrary/whatsbibz/lib/Utils/node-security-2026-10
3
+ * Runtime mitigations & URL/HTTP hardening for the Node.js October 21, 2026
4
+ * Security Release (CVE-2026-111497 Brotli RCE, CVE-2026-105482 DNS NUL truncation,
5
+ * CVE-2026-105483 Fullwidth-IP TLS bypass, CVE-2026-106069 & CVE-2026-106072
6
+ * Non-canonical IPv4 TLS hostname bypass, CVE-2026-105481, CVE-2026-106074).
7
+ */
8
+ import { Boom } from '@hapi/boom';
9
+
10
+ /**
11
+ * Safe Accept-Encoding header value that disables automatic Brotli (`br`)
12
+ * decompression on outgoing HTTP/HTTPS requests to mitigate CVE-2026-111497
13
+ * on unpatched Node.js runtimes.
14
+ */
15
+ export const SAFE_ACCEPT_ENCODING = 'gzip, deflate';
16
+
17
+ export const NODE_OCT_2026_CVES = Object.freeze([
18
+ 'CVE-2026-111497',
19
+ 'CVE-2026-105482',
20
+ 'CVE-2026-105483',
21
+ 'CVE-2026-106069',
22
+ 'CVE-2026-105481',
23
+ 'CVE-2026-106072',
24
+ 'CVE-2026-106074',
25
+ 'CVE-2026-106070',
26
+ 'CVE-2026-106071',
27
+ 'CVE-2026-106073'
28
+ ]);
29
+
30
+ export const PATCHED_NODE_MIN_VERSIONS = Object.freeze({
31
+ 22: Object.freeze([22, 23, 4]),
32
+ 24: Object.freeze([24, 22, 1]),
33
+ 26: Object.freeze([26, 12, 1])
34
+ });
35
+
36
+ const FULLWIDTH_DIGIT_OR_DOT_RE = /[\uFF10-\uFF19\uFF0E\u3002\uFF61]/;
37
+ const NUL_BYTE_RE = /\x00|%00/i;
38
+
39
+ /**
40
+ * Parses a Node.js semver string like "22.23.4" or "v24.22.1" into [major, minor, patch].
41
+ */
42
+ export const parseNodeVersion = (versionStr = process?.versions?.node || '') => {
43
+ const cleaned = String(versionStr).trim().replace(/^v/i, '').split('-')[0];
44
+ const parts = cleaned.split('.').map(n => Number.parseInt(n, 10));
45
+ if (parts.length < 3 || parts.some(n => !Number.isFinite(n) || n < 0)) {
46
+ return null;
47
+ }
48
+ return [parts[0], parts[1], parts[2]];
49
+ };
50
+
51
+ /**
52
+ * Returns true if the given Node.js version includes the October 21, 2026 security patches
53
+ * (v22.23.4+, v24.22.1+, v26.12.1+, or v27+). Node 20.x and 25.x are End-of-Life and unpatched.
54
+ */
55
+ export const isNodePatchedOct2026 = (versionStr = process?.versions?.node) => {
56
+ const tuple = parseNodeVersion(versionStr);
57
+ if (!tuple) {
58
+ return false;
59
+ }
60
+ const [major, minor, patch] = tuple;
61
+ if (major >= 27) {
62
+ return true;
63
+ }
64
+ const minTuple = PATCHED_NODE_MIN_VERSIONS[major];
65
+ if (!minTuple) {
66
+ return false;
67
+ }
68
+ if (minor !== minTuple[1]) {
69
+ return minor > minTuple[1];
70
+ }
71
+ return patch >= minTuple[2];
72
+ };
73
+
74
+ /**
75
+ * Returns a structured security assessment for the current or specified Node.js runtime.
76
+ */
77
+ export const getNodeSecurityStatus = (versionStr = process?.versions?.node) => {
78
+ const tuple = parseNodeVersion(versionStr);
79
+ const patched = isNodePatchedOct2026(versionStr);
80
+ const major = tuple?.[0] ?? 0;
81
+ let recommendedVersion = '>=22.23.4 / >=24.22.1 / >=26.12.1';
82
+ if (major === 22) {
83
+ recommendedVersion = '22.23.4';
84
+ }
85
+ else if (major === 24) {
86
+ recommendedVersion = '24.22.1';
87
+ }
88
+ else if (major === 26) {
89
+ recommendedVersion = '26.12.1';
90
+ }
91
+ return {
92
+ currentVersion: String(versionStr || 'unknown'),
93
+ patched,
94
+ eolLine: major > 0 && major < 22 || major === 23 || major === 25,
95
+ recommendedVersion,
96
+ mitigatedByBibzWhats: true,
97
+ cves: NODE_OCT_2026_CVES
98
+ };
99
+ };
100
+
101
+ /**
102
+ * Detects non-canonical IPv4 hostnames (octal 0177.0.0.1, hex 0x7f.0.0.1 / 0x7f000001,
103
+ * integer 2130706433, or 2/3-part shorthand 127.1 / 127.0.1) that trigger
104
+ * CVE-2026-106069 and CVE-2026-106072 in TLS hostname verification.
105
+ */
106
+ export const isNonCanonicalIpv4Host = (hostname = '') => {
107
+ const host = String(hostname).trim().replace(/\.$/, '').toLowerCase();
108
+ if (!host || host.startsWith('[')) {
109
+ return false;
110
+ }
111
+ const labels = host.split('.');
112
+ const isNumericOrHexLabel = (part) => /^(?:0x[0-9a-f]+|\d+)$/i.test(part);
113
+ if (!labels.every(isNumericOrHexLabel)) {
114
+ return false;
115
+ }
116
+ // All labels are numeric or hex -> this is an IPv4 representation, not a normal domain name
117
+ if (labels.length !== 4) {
118
+ // 1-part integer (2130706433), 2-part (127.1), or 3-part (127.0.1) IPv4
119
+ return true;
120
+ }
121
+ for (const label of labels) {
122
+ if (/^0x/i.test(label)) {
123
+ return true;
124
+ }
125
+ if (label.length > 1 && label.startsWith('0')) {
126
+ // Leading zero = octal IPv4 label (e.g. 0177.0.0.1)
127
+ return true;
128
+ }
129
+ const num = Number(label);
130
+ if (!Number.isInteger(num) || num < 0 || num > 255) {
131
+ return true;
132
+ }
133
+ }
134
+ return false;
135
+ };
136
+
137
+ /**
138
+ * Validates a URL against October 2026 Node.js DNS/TLS vulnerabilities:
139
+ * - Rejects NUL bytes / %00 (CVE-2026-105482)
140
+ * - Rejects fullwidth Unicode digits/dots in URL or hostname (CVE-2026-105483)
141
+ * - Rejects non-canonical IPv4 hostnames (CVE-2026-106069 & CVE-2026-106072)
142
+ */
143
+ export const assertSafeUrl = (inputUrl) => {
144
+ const raw = inputUrl instanceof URL ? inputUrl.toString() : String(inputUrl ?? '');
145
+ if (!raw || NUL_BYTE_RE.test(raw)) {
146
+ throw new Boom('Unsafe URL blocked: contains NUL byte (CVE-2026-105482)', { statusCode: 400 });
147
+ }
148
+ if (FULLWIDTH_DIGIT_OR_DOT_RE.test(raw)) {
149
+ throw new Boom('Unsafe URL blocked: contains fullwidth IP digits/dots (CVE-2026-105483)', { statusCode: 400 });
150
+ }
151
+ const rawHostMatch = raw.match(/^[a-z][a-z0-9+.-]*:\/\/(?:[^/?#@]*@)?([^/?#:]+)/i);
152
+ if (rawHostMatch?.[1] && isNonCanonicalIpv4Host(rawHostMatch[1])) {
153
+ throw new Boom(`Unsafe non-canonical IPv4 hostname blocked: ${rawHostMatch[1]} (CVE-2026-106069 / CVE-2026-106072)`, {
154
+ statusCode: 400
155
+ });
156
+ }
157
+ let parsed;
158
+ try {
159
+ parsed = inputUrl instanceof URL ? inputUrl : new URL(raw);
160
+ }
161
+ catch {
162
+ throw new Boom(`Invalid URL: ${raw}`, { statusCode: 400 });
163
+ }
164
+ const hostname = parsed.hostname || '';
165
+ let decodedHost = hostname;
166
+ try {
167
+ decodedHost = decodeURIComponent(hostname);
168
+ }
169
+ catch { }
170
+ if (NUL_BYTE_RE.test(hostname) || NUL_BYTE_RE.test(decodedHost)) {
171
+ throw new Boom('Unsafe URL hostname blocked: contains NUL byte (CVE-2026-105482)', { statusCode: 400 });
172
+ }
173
+ if (FULLWIDTH_DIGIT_OR_DOT_RE.test(hostname) || FULLWIDTH_DIGIT_OR_DOT_RE.test(decodedHost)) {
174
+ throw new Boom('Unsafe URL hostname blocked: contains fullwidth digits (CVE-2026-105483)', { statusCode: 400 });
175
+ }
176
+ if (isNonCanonicalIpv4Host(hostname) || isNonCanonicalIpv4Host(decodedHost)) {
177
+ throw new Boom(`Unsafe non-canonical IPv4 hostname blocked: ${hostname} (CVE-2026-106069 / CVE-2026-106072)`, {
178
+ statusCode: 400
179
+ });
180
+ }
181
+ return parsed;
182
+ };
183
+
184
+ /**
185
+ * Returns a plain headers object with `accept-encoding: gzip, deflate` enforced
186
+ * (removing `br` / Brotli to prevent CVE-2026-111497 RCE on unpatched runtimes).
187
+ */
188
+ export const withSafeFetchHeaders = (headers) => {
189
+ const out = {};
190
+ if (headers) {
191
+ if (typeof headers.entries === 'function') {
192
+ for (const [k, v] of headers.entries()) {
193
+ out[k] = v;
194
+ }
195
+ }
196
+ else if (Array.isArray(headers)) {
197
+ for (const [k, v] of headers) {
198
+ out[k] = v;
199
+ }
200
+ }
201
+ else if (typeof headers === 'object') {
202
+ Object.assign(out, headers);
203
+ }
204
+ }
205
+ const existingKey = Object.keys(out).find(k => k.toLowerCase() === 'accept-encoding');
206
+ if (existingKey) {
207
+ const cleaned = String(out[existingKey])
208
+ .split(',')
209
+ .map(s => s.trim())
210
+ .filter(s => s && !/^br(?:;|$)/i.test(s))
211
+ .join(', ');
212
+ out[existingKey] = cleaned || SAFE_ACCEPT_ENCODING;
213
+ }
214
+ else {
215
+ out['accept-encoding'] = SAFE_ACCEPT_ENCODING;
216
+ }
217
+ return out;
218
+ };
219
+
220
+ /**
221
+ * Hardened `fetch()` wrapper that validates the target URL (and any redirect URL)
222
+ * against CVE-2026-105482, CVE-2026-105483, CVE-2026-106069, CVE-2026-106072
223
+ * and disables Brotli (`br`) negotiation to mitigate CVE-2026-111497.
224
+ */
225
+ export const safeFetch = async (inputUrl, init = {}) => {
226
+ const parsed = assertSafeUrl(inputUrl);
227
+ const headers = withSafeFetchHeaders(init.headers);
228
+ const response = await fetch(parsed.toString(), {
229
+ ...init,
230
+ headers
231
+ });
232
+ if (response.url) {
233
+ assertSafeUrl(response.url);
234
+ }
235
+ return response;
236
+ };
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/noise-handler */
1
2
  import { proto } from '../../WAProto/index.js';
2
3
  import type { KeyPair } from '../Types/index.js';
3
4
  import type { BinaryNode } from '../WABinary/index.js';
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/noise-handler */
1
2
  import { Boom } from '@hapi/boom';
2
3
  import { proto } from '../../WAProto/index.js';
3
4
  import { NOISE_MODE, WA_CERT_DETAILS } from '../Defaults/index.js';
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/offline-node-processor */
1
2
  import type { BinaryNode } from '../WABinary/index.js';
2
3
  export type MessageType = 'message' | 'call' | 'receipt' | 'notification';
3
4
  export type OfflineNodeProcessorDeps = {
@@ -5,6 +6,7 @@ export type OfflineNodeProcessorDeps = {
5
6
  onUnexpectedError: (error: Error, msg: string) => void;
6
7
  yieldToEventLoop: () => Promise<void>;
7
8
  };
9
+ export declare const isOfflineNode: (node: BinaryNode) => boolean;
8
10
  /**
9
11
  * Creates a processor for offline stanza nodes that:
10
12
  * - Queues nodes for sequential processing
@@ -1,3 +1,9 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/offline-node-processor */
2
+ /**
3
+ * Determines whether a binary stanza was queued on the server while the client was offline.
4
+ * WhatsApp sets `offline="1"` for queued stanzas and `offline="0"` for live stanzas.
5
+ */
6
+ export const isOfflineNode = (node) => node?.attrs?.offline === '1';
1
7
  /**
2
8
  * Creates a processor for offline stanza nodes that:
3
9
  * - Queues nodes for sequential processing
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/platform-identity */
1
2
  import type { WABrowserDescription } from '../Types/index.js';
2
3
  export declare const PAIRING_ACCEPTED_OS: readonly string[];
3
4
  export declare const PAIRING_OS_FALLBACK: Readonly<Record<string, string>>;
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/platform-identity */
1
2
  // BibzWhats — identitas platform companion (apa yang WhatsApp "lihat" dari library ini)
2
3
  //
3
4
  // Tiga tempat identitas dipakai, dan ketiganya berbeda aturannya:
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/pre-key-manager */
1
2
  import type { SignalDataSet, SignalDataTypeMap, SignalKeyStore } from '../Types/index.js';
2
3
  import type { ILogger } from './logger.js';
3
4
  /**
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/pre-key-manager */
1
2
  import PQueue from 'p-queue';
2
3
  /**
3
4
  * Manages pre-key operations with proper concurrency control
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/process-message */
1
2
  import { proto } from '../../WAProto/index.js';
2
3
  import type { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SignalRepositoryWithLIDStore, SocketConfig, WAMessage, WAMessageKey } from '../Types/index.js';
3
4
  import type { ILogger } from './logger.js';
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/process-message */
1
2
  import { proto } from '../../WAProto/index.js';
2
3
  import { WAMessageStubType } from '../Types/index.js';
3
4
  import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/reporting-utils */
1
2
  import { proto } from '../../WAProto/index.js';
2
3
  import type { WAMessageContent, WAMessageKey } from '../Types/index.js';
3
4
  import type { BinaryNode } from '../WABinary/index.js';
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/reporting-utils */
1
2
  import { createHmac } from 'crypto';
2
3
  import { proto } from '../../WAProto/index.js';
3
4
  import { hkdf } from './crypto.js';
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/rich-messages */
1
2
  import { proto } from "../../WAProto/index.js";
2
3
  export declare const JS_KEYWORDS: Set<string>;
3
4
  export declare const PYTHON_KEYWORDS: Set<string>;
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/rich-messages */
1
2
  import { proto } from "../../WAProto/index.js";
2
3
  import { generateMessageIDV2 } from "./generics.js";
3
4
  import { randomBytes, randomUUID } from "crypto";
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/signal */
1
2
  import type { SignalRepositoryWithLIDStore } from '../Types/index.js';
2
3
  import type { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth.js';
3
4
  import { type BinaryNode, type FullJid } from '../WABinary/index.js';
@@ -1,3 +1,4 @@
1
+ /** @module @xbibzlibrary/whatsbibz/lib/Utils/signal */
1
2
  import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
2
3
  import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, getServerFromDomainType, jidDecode, S_WHATSAPP_NET, WAJIDDomains } from '../WABinary/index.js';
3
4
  import { Curve, generateSignalPubKey } from './crypto.js';