@vanzxysenpai/baileys 0.0.0-stage → 0.0.2

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 (431) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +25 -0
  3. package/NOTICE.md +158 -0
  4. package/README.md +5294 -2
  5. package/VanzxyBanner.js +134 -0
  6. package/WAProto/index.d.ts +13317 -0
  7. package/WAProto/index.js +147553 -0
  8. package/lib/Builders/A2UI.d.ts +131 -0
  9. package/lib/Builders/A2UI.js +343 -0
  10. package/lib/Builders/AIRich.d.ts +1021 -0
  11. package/lib/Builders/AIRich.js +2889 -0
  12. package/lib/Builders/Album.d.ts +51 -0
  13. package/lib/Builders/Album.js +99 -0
  14. package/lib/Builders/Button.d.ts +137449 -0
  15. package/lib/Builders/Button.js +1054 -0
  16. package/lib/Builders/ButtonV2.d.ts +43 -0
  17. package/lib/Builders/ButtonV2.js +175 -0
  18. package/lib/Builders/ButtonV3.d.ts +35 -0
  19. package/lib/Builders/ButtonV3.js +189 -0
  20. package/lib/Builders/Carousel.d.ts +68 -0
  21. package/lib/Builders/Carousel.js +161 -0
  22. package/lib/Builders/Event.d.ts +61 -0
  23. package/lib/Builders/Event.js +118 -0
  24. package/lib/Builders/Expiring.d.ts +17 -0
  25. package/lib/Builders/Expiring.js +27 -0
  26. package/lib/Builders/Poll.d.ts +63 -0
  27. package/lib/Builders/Poll.js +139 -0
  28. package/lib/Builders/VanzxyBaileys.d.ts +42 -0
  29. package/lib/Builders/VanzxyBaileys.js +110 -0
  30. package/lib/Builders/errors.d.ts +25 -0
  31. package/lib/Builders/errors.js +29 -0
  32. package/lib/Builders/index.d.ts +14 -0
  33. package/lib/Builders/index.js +23 -0
  34. package/lib/Builders/shared.d.ts +395 -0
  35. package/lib/Builders/shared.js +738 -0
  36. package/lib/Defaults/bot-jid.d.ts +1 -0
  37. package/lib/Defaults/bot-jid.js +1 -0
  38. package/lib/Defaults/index.d.ts +161 -0
  39. package/lib/Defaults/index.js +165 -0
  40. package/lib/Defaults/version.d.ts +1 -0
  41. package/lib/Defaults/version.js +1 -0
  42. package/lib/Framework/Bot.d.ts +865 -0
  43. package/lib/Framework/Bot.js +230 -0
  44. package/lib/Framework/Context.d.ts +17 -0
  45. package/lib/Framework/Context.js +90 -0
  46. package/lib/Framework/MediaManager.d.ts +15 -0
  47. package/lib/Framework/MediaManager.js +154 -0
  48. package/lib/Framework/SessionManager.d.ts +10 -0
  49. package/lib/Framework/SessionManager.js +34 -0
  50. package/lib/Framework/StatsManager.d.ts +20 -0
  51. package/lib/Framework/StatsManager.js +117 -0
  52. package/lib/Framework/Store/SQLiteStore.d.ts +13 -0
  53. package/lib/Framework/Store/SQLiteStore.js +68 -0
  54. package/lib/Framework/index.d.ts +6 -0
  55. package/lib/Framework/index.js +11 -0
  56. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  57. package/lib/Signal/Group/ciphertext-message.js +11 -0
  58. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  59. package/lib/Signal/Group/group-session-builder.js +29 -0
  60. package/lib/Signal/Group/group_cipher.d.ts +10 -0
  61. package/lib/Signal/Group/group_cipher.js +81 -0
  62. package/lib/Signal/Group/index.d.ts +11 -0
  63. package/lib/Signal/Group/index.js +11 -0
  64. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  65. package/lib/Signal/Group/keyhelper.js +17 -0
  66. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  67. package/lib/Signal/Group/sender-chain-key.js +25 -0
  68. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  69. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  70. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  71. package/lib/Signal/Group/sender-key-message.js +65 -0
  72. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  73. package/lib/Signal/Group/sender-key-name.js +47 -0
  74. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  75. package/lib/Signal/Group/sender-key-record.js +40 -0
  76. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  77. package/lib/Signal/Group/sender-key-state.js +83 -0
  78. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  79. package/lib/Signal/Group/sender-message-key.js +25 -0
  80. package/lib/Signal/libsignal.d.ts +58 -0
  81. package/lib/Signal/libsignal.js +436 -0
  82. package/lib/Signal/lid-mapping.d.ts +20 -0
  83. package/lib/Signal/lid-mapping.js +276 -0
  84. package/lib/Socket/Client/index.d.ts +2 -0
  85. package/lib/Socket/Client/index.js +2 -0
  86. package/lib/Socket/Client/types.d.ts +5 -0
  87. package/lib/Socket/Client/types.js +10 -0
  88. package/lib/Socket/Client/websocket.d.ts +12 -0
  89. package/lib/Socket/Client/websocket.js +53 -0
  90. package/lib/Socket/business.d.ts +674 -0
  91. package/lib/Socket/business.js +379 -0
  92. package/lib/Socket/chats.d.ts +137 -0
  93. package/lib/Socket/chats.js +1299 -0
  94. package/lib/Socket/communities.d.ts +805 -0
  95. package/lib/Socket/communities.js +454 -0
  96. package/lib/Socket/dugong.d.ts +118 -0
  97. package/lib/Socket/dugong.js +810 -0
  98. package/lib/Socket/groups.d.ts +287 -0
  99. package/lib/Socket/groups.js +386 -0
  100. package/lib/Socket/index.d.ts +826 -0
  101. package/lib/Socket/index.js +35 -0
  102. package/lib/Socket/messages-recv.d.ts +613 -0
  103. package/lib/Socket/messages-recv.js +1851 -0
  104. package/lib/Socket/messages-send.d.ts +608 -0
  105. package/lib/Socket/messages-send.js +1574 -0
  106. package/lib/Socket/mex-fallback.d.ts +51 -0
  107. package/lib/Socket/mex-fallback.js +97 -0
  108. package/lib/Socket/mex.d.ts +1 -0
  109. package/lib/Socket/mex.js +41 -0
  110. package/lib/Socket/newsletter-ext.d.ts +47 -0
  111. package/lib/Socket/newsletter-ext.js +262 -0
  112. package/lib/Socket/newsletter.d.ts +285 -0
  113. package/lib/Socket/newsletter.js +223 -0
  114. package/lib/Socket/socket.d.ts +60 -0
  115. package/lib/Socket/socket.js +1001 -0
  116. package/lib/Socket/username.d.ts +842 -0
  117. package/lib/Socket/username.js +156 -0
  118. package/lib/Store/index.d.ts +3 -0
  119. package/lib/Store/index.js +3 -0
  120. package/lib/Store/make-in-memory-store.d.ts +62 -0
  121. package/lib/Store/make-in-memory-store.js +425 -0
  122. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  123. package/lib/Store/make-ordered-dictionary.js +78 -0
  124. package/lib/Store/object-repository.d.ts +10 -0
  125. package/lib/Store/object-repository.js +23 -0
  126. package/lib/Types/Auth.d.ts +1 -0
  127. package/lib/Types/Auth.js +1 -0
  128. package/lib/Types/Bussines.d.ts +1 -0
  129. package/lib/Types/Bussines.js +1 -0
  130. package/lib/Types/Call.d.ts +1 -0
  131. package/lib/Types/Call.js +1 -0
  132. package/lib/Types/Chat.d.ts +1 -0
  133. package/lib/Types/Chat.js +7 -0
  134. package/lib/Types/Contact.d.ts +1 -0
  135. package/lib/Types/Contact.js +1 -0
  136. package/lib/Types/Events.d.ts +1 -0
  137. package/lib/Types/Events.js +1 -0
  138. package/lib/Types/GroupMetadata.d.ts +1 -0
  139. package/lib/Types/GroupMetadata.js +1 -0
  140. package/lib/Types/Label.d.ts +2 -0
  141. package/lib/Types/Label.js +24 -0
  142. package/lib/Types/LabelAssociation.d.ts +2 -0
  143. package/lib/Types/LabelAssociation.js +6 -0
  144. package/lib/Types/Message.d.ts +11 -0
  145. package/lib/Types/Message.js +17 -0
  146. package/lib/Types/Mex.d.ts +2 -0
  147. package/lib/Types/Mex.js +38 -0
  148. package/lib/Types/Product.d.ts +1 -0
  149. package/lib/Types/Product.js +1 -0
  150. package/lib/Types/RichType.d.ts +2 -0
  151. package/lib/Types/RichType.js +22 -0
  152. package/lib/Types/Signal.d.ts +1 -0
  153. package/lib/Types/Signal.js +1 -0
  154. package/lib/Types/Socket.d.ts +1 -0
  155. package/lib/Types/Socket.js +1 -0
  156. package/lib/Types/State.d.ts +5 -0
  157. package/lib/Types/State.js +55 -0
  158. package/lib/Types/USync.d.ts +1 -0
  159. package/lib/Types/USync.js +1 -0
  160. package/lib/Types/index.d.ts +15 -0
  161. package/lib/Types/index.js +27 -0
  162. package/lib/Utils/PersistentStore.d.ts +83 -0
  163. package/lib/Utils/PersistentStore.js +592 -0
  164. package/lib/Utils/anchor-guard.d.ts +31 -0
  165. package/lib/Utils/anchor-guard.js +329 -0
  166. package/lib/Utils/android-stanza-id.d.ts +4 -0
  167. package/lib/Utils/android-stanza-id.js +21 -0
  168. package/lib/Utils/anti-delete.d.ts +62 -0
  169. package/lib/Utils/anti-delete.js +212 -0
  170. package/lib/Utils/auth-secure.d.ts +180 -0
  171. package/lib/Utils/auth-secure.js +791 -0
  172. package/lib/Utils/auth-utils.d.ts +59 -0
  173. package/lib/Utils/auth-utils.js +326 -0
  174. package/lib/Utils/auto-reconnect.d.ts +8 -0
  175. package/lib/Utils/auto-reconnect.js +204 -0
  176. package/lib/Utils/auto-reply.d.ts +35 -0
  177. package/lib/Utils/auto-reply.js +152 -0
  178. package/lib/Utils/bad-mac-handler.d.ts +59 -0
  179. package/lib/Utils/bad-mac-handler.js +119 -0
  180. package/lib/Utils/baileys-event-stream.d.ts +5 -0
  181. package/lib/Utils/baileys-event-stream.js +62 -0
  182. package/lib/Utils/browser-utils.d.ts +9 -0
  183. package/lib/Utils/browser-utils.js +29 -0
  184. package/lib/Utils/business.d.ts +49 -0
  185. package/lib/Utils/business.js +236 -0
  186. package/lib/Utils/button-helper-utils.d.ts +59 -0
  187. package/lib/Utils/button-helper-utils.js +266 -0
  188. package/lib/Utils/button-sender.d.ts +164 -0
  189. package/lib/Utils/button-sender.js +845 -0
  190. package/lib/Utils/chat-control.d.ts +98 -0
  191. package/lib/Utils/chat-control.js +231 -0
  192. package/lib/Utils/chat-history-helpers.d.ts +4 -0
  193. package/lib/Utils/chat-history-helpers.js +70 -0
  194. package/lib/Utils/chat-utils.d.ts +408 -0
  195. package/lib/Utils/chat-utils.js +879 -0
  196. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  197. package/lib/Utils/companion-reg-client-utils.js +39 -0
  198. package/lib/Utils/connection-watchdog.d.ts +10 -0
  199. package/lib/Utils/connection-watchdog.js +74 -0
  200. package/lib/Utils/crypto.d.ts +41 -0
  201. package/lib/Utils/crypto.js +145 -0
  202. package/lib/Utils/decode-wa-message.d.ts +83 -0
  203. package/lib/Utils/decode-wa-message.js +315 -0
  204. package/lib/Utils/disconnect-reason.d.ts +13 -0
  205. package/lib/Utils/disconnect-reason.js +36 -0
  206. package/lib/Utils/event-buffer.d.ts +12 -0
  207. package/lib/Utils/event-buffer.js +640 -0
  208. package/lib/Utils/fetch-timeout.d.ts +4 -0
  209. package/lib/Utils/fetch-timeout.js +14 -0
  210. package/lib/Utils/ffmpeg-path.d.ts +5 -0
  211. package/lib/Utils/ffmpeg-path.js +130 -0
  212. package/lib/Utils/generics.d.ts +79 -0
  213. package/lib/Utils/generics.js +426 -0
  214. package/lib/Utils/group-metadata-cache.d.ts +3 -0
  215. package/lib/Utils/group-metadata-cache.js +25 -0
  216. package/lib/Utils/group-status-detection.d.ts +5 -0
  217. package/lib/Utils/group-status-detection.js +114 -0
  218. package/lib/Utils/history.d.ts +91 -0
  219. package/lib/Utils/history.js +144 -0
  220. package/lib/Utils/html-app.d.ts +14 -0
  221. package/lib/Utils/html-app.js +97 -0
  222. package/lib/Utils/html-multiplayer.d.ts +8 -0
  223. package/lib/Utils/html-multiplayer.js +90 -0
  224. package/lib/Utils/humanizer.d.ts +8 -0
  225. package/lib/Utils/humanizer.js +74 -0
  226. package/lib/Utils/identity-change-handler.d.ts +13 -0
  227. package/lib/Utils/identity-change-handler.js +49 -0
  228. package/lib/Utils/index.d.ts +88 -0
  229. package/lib/Utils/index.js +93 -0
  230. package/lib/Utils/jid-tools.d.ts +3 -0
  231. package/lib/Utils/jid-tools.js +78 -0
  232. package/lib/Utils/link-preview-metadata.d.ts +47 -0
  233. package/lib/Utils/link-preview-metadata.js +90 -0
  234. package/lib/Utils/link-preview.d.ts +12 -0
  235. package/lib/Utils/link-preview.js +84 -0
  236. package/lib/Utils/lock-manager.d.ts +5 -0
  237. package/lib/Utils/lock-manager.js +50 -0
  238. package/lib/Utils/logger.d.ts +2 -0
  239. package/lib/Utils/logger.js +2 -0
  240. package/lib/Utils/lt-hash.d.ts +12 -0
  241. package/lib/Utils/lt-hash.js +26 -0
  242. package/lib/Utils/make-mutex.d.ts +6 -0
  243. package/lib/Utils/make-mutex.js +32 -0
  244. package/lib/Utils/media-messages.d.ts +35 -0
  245. package/lib/Utils/media-messages.js +70 -0
  246. package/lib/Utils/media-processor.d.ts +6 -0
  247. package/lib/Utils/media-processor.js +174 -0
  248. package/lib/Utils/media-set.d.ts +6 -0
  249. package/lib/Utils/media-set.js +169 -0
  250. package/lib/Utils/message-kind.d.ts +26 -0
  251. package/lib/Utils/message-kind.js +138 -0
  252. package/lib/Utils/message-retry-manager.d.ts +79 -0
  253. package/lib/Utils/message-retry-manager.js +264 -0
  254. package/lib/Utils/message-search.d.ts +40 -0
  255. package/lib/Utils/message-search.js +181 -0
  256. package/lib/Utils/messages-media.d.ts +136 -0
  257. package/lib/Utils/messages-media.js +867 -0
  258. package/lib/Utils/messages.d.ts +66 -0
  259. package/lib/Utils/messages.js +2271 -0
  260. package/lib/Utils/meta-ai-msmsg.d.ts +3 -0
  261. package/lib/Utils/meta-ai-msmsg.js +132 -0
  262. package/lib/Utils/meta-ai.d.ts +4 -0
  263. package/lib/Utils/meta-ai.js +75 -0
  264. package/lib/Utils/migrate-auth-state.d.ts +23 -0
  265. package/lib/Utils/migrate-auth-state.js +126 -0
  266. package/lib/Utils/mini-app.d.ts +20 -0
  267. package/lib/Utils/mini-app.js +215 -0
  268. package/lib/Utils/mock-socket.d.ts +67 -0
  269. package/lib/Utils/mock-socket.js +254 -0
  270. package/lib/Utils/modern-messages.d.ts +64 -0
  271. package/lib/Utils/modern-messages.js +497 -0
  272. package/lib/Utils/native-flow.d.ts +19 -0
  273. package/lib/Utils/native-flow.js +112 -0
  274. package/lib/Utils/newsletter-status.d.ts +157 -0
  275. package/lib/Utils/newsletter-status.js +652 -0
  276. package/lib/Utils/noise-handler.d.ts +20 -0
  277. package/lib/Utils/noise-handler.js +200 -0
  278. package/lib/Utils/offline-node-processor.d.ts +9 -0
  279. package/lib/Utils/offline-node-processor.js +39 -0
  280. package/lib/Utils/pairing-utils.d.ts +5 -0
  281. package/lib/Utils/pairing-utils.js +29 -0
  282. package/lib/Utils/passkey.d.ts +4 -0
  283. package/lib/Utils/passkey.js +11 -0
  284. package/lib/Utils/past-participants.d.ts +2 -0
  285. package/lib/Utils/past-participants.js +40 -0
  286. package/lib/Utils/payment-detection.d.ts +40 -0
  287. package/lib/Utils/payment-detection.js +213 -0
  288. package/lib/Utils/payment-guard.d.ts +28 -0
  289. package/lib/Utils/payment-guard.js +143 -0
  290. package/lib/Utils/payment-messages.d.ts +42 -0
  291. package/lib/Utils/payment-messages.js +161 -0
  292. package/lib/Utils/payment-utils.d.ts +75 -0
  293. package/lib/Utils/payment-utils.js +145 -0
  294. package/lib/Utils/phone-utils.d.ts +3 -0
  295. package/lib/Utils/phone-utils.js +29 -0
  296. package/lib/Utils/pre-key-manager.d.ts +25 -0
  297. package/lib/Utils/pre-key-manager.js +105 -0
  298. package/lib/Utils/process-message.d.ts +103 -0
  299. package/lib/Utils/process-message.js +868 -0
  300. package/lib/Utils/qr-terminal.d.ts +1 -0
  301. package/lib/Utils/qr-terminal.js +16 -0
  302. package/lib/Utils/reconnect-backoff.d.ts +25 -0
  303. package/lib/Utils/reconnect-backoff.js +47 -0
  304. package/lib/Utils/reporting-utils.d.ts +12 -0
  305. package/lib/Utils/reporting-utils.js +257 -0
  306. package/lib/Utils/rich-message-utils.d.ts +54 -0
  307. package/lib/Utils/rich-message-utils.js +435 -0
  308. package/lib/Utils/rich-messages.d.ts +298 -0
  309. package/lib/Utils/rich-messages.js +1145 -0
  310. package/lib/Utils/scheduled-message.d.ts +81 -0
  311. package/lib/Utils/scheduled-message.js +101 -0
  312. package/lib/Utils/scheduling.d.ts +59 -0
  313. package/lib/Utils/scheduling.js +139 -0
  314. package/lib/Utils/signal.d.ts +82 -0
  315. package/lib/Utils/signal.js +200 -0
  316. package/lib/Utils/stanza-ack.d.ts +16 -0
  317. package/lib/Utils/stanza-ack.js +37 -0
  318. package/lib/Utils/status-stickers.d.ts +79 -0
  319. package/lib/Utils/status-stickers.js +261 -0
  320. package/lib/Utils/status.d.ts +107 -0
  321. package/lib/Utils/status.js +131 -0
  322. package/lib/Utils/sticker-pack-maker.d.ts +20 -0
  323. package/lib/Utils/sticker-pack-maker.js +112 -0
  324. package/lib/Utils/stickerpack.d.ts +18 -0
  325. package/lib/Utils/stickerpack.js +316 -0
  326. package/lib/Utils/sync-action-utils.d.ts +2 -0
  327. package/lib/Utils/sync-action-utils.js +48 -0
  328. package/lib/Utils/tag.d.ts +8 -0
  329. package/lib/Utils/tag.js +45 -0
  330. package/lib/Utils/tc-token-utils.d.ts +29 -0
  331. package/lib/Utils/tc-token-utils.js +162 -0
  332. package/lib/Utils/templates.d.ts +86 -0
  333. package/lib/Utils/templates.js +148 -0
  334. package/lib/Utils/text-format.d.ts +13 -0
  335. package/lib/Utils/text-format.js +81 -0
  336. package/lib/Utils/text-tools.d.ts +3 -0
  337. package/lib/Utils/text-tools.js +38 -0
  338. package/lib/Utils/ttl-cache.d.ts +29 -0
  339. package/lib/Utils/ttl-cache.js +123 -0
  340. package/lib/Utils/use-cache-manager-auth-state.d.ts +22 -0
  341. package/lib/Utils/use-cache-manager-auth-state.js +86 -0
  342. package/lib/Utils/use-multi-file-auth-state.d.ts +20 -0
  343. package/lib/Utils/use-multi-file-auth-state.js +201 -0
  344. package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
  345. package/lib/Utils/use-single-file-auth-state.js +111 -0
  346. package/lib/Utils/use-sqlite-auth-state.d.ts +13 -0
  347. package/lib/Utils/use-sqlite-auth-state.js +171 -0
  348. package/lib/Utils/username.d.ts +22 -0
  349. package/lib/Utils/username.js +59 -0
  350. package/lib/Utils/validate-connection.d.ts +43 -0
  351. package/lib/Utils/validate-connection.js +197 -0
  352. package/lib/Utils/vcard.d.ts +40 -0
  353. package/lib/Utils/vcard.js +92 -0
  354. package/lib/Utils/voice-note.d.ts +13 -0
  355. package/lib/Utils/voice-note.js +47 -0
  356. package/lib/VoIP/audio-feeder.d.ts +15 -0
  357. package/lib/VoIP/audio-feeder.js +132 -0
  358. package/lib/VoIP/index.d.ts +22 -0
  359. package/lib/VoIP/index.js +277 -0
  360. package/lib/VoIP/relay-transport.d.ts +16 -0
  361. package/lib/VoIP/relay-transport.js +559 -0
  362. package/lib/VoIP/signaling.d.ts +16 -0
  363. package/lib/VoIP/signaling.js +624 -0
  364. package/lib/VoIP/types.d.ts +11 -0
  365. package/lib/VoIP/types.js +17 -0
  366. package/lib/VoIP/wasm-engine.d.ts +28 -0
  367. package/lib/VoIP/wasm-engine.js +1214 -0
  368. package/lib/VoIP/worker-bootstrap.d.ts +1 -0
  369. package/lib/VoIP/worker-bootstrap.js +1042 -0
  370. package/lib/WABinary/constants.d.ts +61 -0
  371. package/lib/WABinary/constants.js +1466 -0
  372. package/lib/WABinary/decode.d.ts +9 -0
  373. package/lib/WABinary/decode.js +261 -0
  374. package/lib/WABinary/encode.d.ts +2 -0
  375. package/lib/WABinary/encode.js +219 -0
  376. package/lib/WABinary/generic-utils.d.ts +45 -0
  377. package/lib/WABinary/generic-utils.js +285 -0
  378. package/lib/WABinary/index.d.ts +5 -0
  379. package/lib/WABinary/index.js +5 -0
  380. package/lib/WABinary/jid-utils.d.ts +32 -0
  381. package/lib/WABinary/jid-utils.js +102 -0
  382. package/lib/WABinary/types.d.ts +1 -0
  383. package/lib/WABinary/types.js +1 -0
  384. package/lib/WAM/BinaryInfo.d.ts +7 -0
  385. package/lib/WAM/BinaryInfo.js +9 -0
  386. package/lib/WAM/constants.d.ts +34926 -0
  387. package/lib/WAM/constants.js +22852 -0
  388. package/lib/WAM/encode.d.ts +1 -0
  389. package/lib/WAM/encode.js +149 -0
  390. package/lib/WAM/index.d.ts +3 -0
  391. package/lib/WAM/index.js +3 -0
  392. package/lib/WAUSync/Protocols/USyncBusinessProtocol.d.ts +43 -0
  393. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +32 -0
  394. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  395. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  396. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
  397. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +60 -0
  398. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  399. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  400. package/lib/WAUSync/Protocols/USyncFeatureProtocol.d.ts +13 -0
  401. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +28 -0
  402. package/lib/WAUSync/Protocols/USyncPictureProtocol.d.ts +22 -0
  403. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  404. package/lib/WAUSync/Protocols/USyncSidelistProtocol.d.ts +20 -0
  405. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +23 -0
  406. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  407. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  408. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.d.ts +14 -0
  409. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +24 -0
  410. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  411. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  412. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  413. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +49 -0
  414. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  415. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  416. package/lib/WAUSync/Protocols/index.d.ts +12 -0
  417. package/lib/WAUSync/Protocols/index.js +12 -0
  418. package/lib/WAUSync/USyncQuery.d.ts +25 -0
  419. package/lib/WAUSync/USyncQuery.js +140 -0
  420. package/lib/WAUSync/USyncUser.d.ts +24 -0
  421. package/lib/WAUSync/USyncUser.js +47 -0
  422. package/lib/WAUSync/index.d.ts +3 -0
  423. package/lib/WAUSync/index.js +3 -0
  424. package/lib/assets/wasm/loader.js +5 -0
  425. package/lib/assets/wasm/whatsapp.wasm +0 -0
  426. package/lib/assets/wasm/worker-modules.js +273 -0
  427. package/lib/exports-extra.d.ts +45 -0
  428. package/lib/exports-extra.js +47 -0
  429. package/lib/index.d.ts +16 -0
  430. package/lib/index.js +24 -0
  431. package/package.json +161 -4
@@ -0,0 +1,329 @@
1
+ // Ported into @vanzxysenpai/baileys 0.0.1 from @rennzsync/baileys 10.7.4 (originally @rexxhayanasi/elaina-anchorguard), MIT. See NOTICE.md.
2
+ // Elaina AnchorGuard — anti force-close guard for WhatsApp.
3
+ // Ported from @rexxhayanasi/elaina-anchorguard (MIT) into @rennzsync/baileys.
4
+ // Detects payloads that crash/force-close WhatsApp clients (combining/invisible
5
+ // char floods, mention bombs, oversized native-flow/list/carousel payloads,
6
+ // broken buttonParamsJson, over-deep/nested or circular message structures),
7
+ // then auto-deletes them and optionally blocks the sender.
8
+ export const ANCHORGUARD_DEFAULTS = {
9
+ maxText: 65536,
10
+ maxCaption: 32768,
11
+ maxMentions: 1500,
12
+ maxGroupMentions: 200,
13
+ maxButtons: 100,
14
+ maxSections: 100,
15
+ maxRows: 300,
16
+ maxCards: 60,
17
+ maxDepth: 12,
18
+ maxNodes: 20000,
19
+ maxBytes: 3 * 1024 * 1024,
20
+ maxParamsJson: 262144,
21
+ maxInvisibleRun: 500,
22
+ maxCombiningRun: 100,
23
+ maxNewlines: 20000
24
+ };
25
+ const INVISIBLE = /[\u200b-\u200f\u202a-\u202e\u2060-\u2064\u206a-\u206f\ufeff\ufff9-\ufffb]/;
26
+ const COMBINING = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u0610-\u061a\u064b-\u065f\u0670\u06d6-\u06dc\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\uaa70\uaaf6\uabed\ufe20-\ufe2f]/;
27
+ const longestRun = (text, matcher) => {
28
+ let run = 0;
29
+ let best = 0;
30
+ for (const ch of text) {
31
+ if (matcher.test(ch)) {
32
+ run += 1;
33
+ if (run > best)
34
+ best = run;
35
+ }
36
+ else {
37
+ run = 0;
38
+ }
39
+ }
40
+ return best;
41
+ };
42
+ const countChar = (text, ch) => {
43
+ let n = 0;
44
+ for (let i = 0; i < text.length; i += 1) {
45
+ if (text[i] === ch)
46
+ n += 1;
47
+ }
48
+ return n;
49
+ };
50
+ const unwrapContent = (message) => {
51
+ let current = message;
52
+ let depth = 0;
53
+ const wrappers = [
54
+ 'ephemeralMessage',
55
+ 'viewOnceMessage',
56
+ 'viewOnceMessageV2',
57
+ 'viewOnceMessageV2Extension',
58
+ 'documentWithCaptionMessage',
59
+ 'editedMessage',
60
+ 'deviceSentMessage',
61
+ 'botInvokeMessage'
62
+ ];
63
+ while (current && typeof current === 'object' && depth < 64) {
64
+ const wrapper = wrappers.find((w) => current[w]?.message);
65
+ if (!wrapper)
66
+ break;
67
+ current = current[wrapper].message;
68
+ depth += 1;
69
+ }
70
+ return { content: current, wrapDepth: depth };
71
+ };
72
+ export const detectBug = (message, options = {}) => {
73
+ const limits = { ...ANCHORGUARD_DEFAULTS, ...options };
74
+ const reasons = [];
75
+ if (!message || typeof message !== 'object')
76
+ return { flagged: false, reasons };
77
+ const { content, wrapDepth } = unwrapContent(message);
78
+ if (wrapDepth >= 6)
79
+ reasons.push(`wrapper nesting ${wrapDepth}`);
80
+ let nodes = 0;
81
+ const seen = new WeakSet();
82
+ const walk = (value, depth) => {
83
+ if (reasons.length > 40)
84
+ return;
85
+ nodes += 1;
86
+ if (nodes > limits.maxNodes) {
87
+ reasons.push(`node count > ${limits.maxNodes}`);
88
+ return;
89
+ }
90
+ if (depth > limits.maxDepth) {
91
+ reasons.push(`structure depth > ${limits.maxDepth}`);
92
+ return;
93
+ }
94
+ if (typeof value === 'string') {
95
+ if (value.length > limits.maxText)
96
+ reasons.push(`string length ${value.length} > ${limits.maxText}`);
97
+ if (countChar(value, '\n') > limits.maxNewlines)
98
+ reasons.push('excessive newlines');
99
+ const invisibleRun = longestRun(value, INVISIBLE);
100
+ if (invisibleRun > limits.maxInvisibleRun)
101
+ reasons.push(`invisible-char run ${invisibleRun}`);
102
+ const combiningRun = longestRun(value, COMBINING);
103
+ if (combiningRun > limits.maxCombiningRun)
104
+ reasons.push(`combining-char run ${combiningRun}`);
105
+ return;
106
+ }
107
+ if (Array.isArray(value)) {
108
+ for (const item of value)
109
+ walk(item, depth + 1);
110
+ return;
111
+ }
112
+ if (value && typeof value === 'object') {
113
+ if (seen.has(value)) {
114
+ reasons.push('circular structure');
115
+ return;
116
+ }
117
+ seen.add(value);
118
+ for (const key of Object.keys(value))
119
+ walk(value[key], depth + 1);
120
+ }
121
+ };
122
+ walk(content, 0);
123
+ const collectContextInfo = (node) => {
124
+ if (!node || typeof node !== 'object')
125
+ return;
126
+ for (const key of Object.keys(node)) {
127
+ const child = node[key];
128
+ if (key === 'contextInfo' && child && typeof child === 'object') {
129
+ if (Array.isArray(child.mentionedJid) && child.mentionedJid.length > limits.maxMentions)
130
+ reasons.push(`mentionedJid ${child.mentionedJid.length} > ${limits.maxMentions}`);
131
+ if (Array.isArray(child.groupMentions) && child.groupMentions.length > limits.maxGroupMentions)
132
+ reasons.push(`groupMentions ${child.groupMentions.length} > ${limits.maxGroupMentions}`);
133
+ }
134
+ if (child && typeof child === 'object')
135
+ collectContextInfo(child);
136
+ }
137
+ };
138
+ collectContextInfo(content);
139
+ const inspectInteractive = (node) => {
140
+ if (!node || typeof node !== 'object')
141
+ return;
142
+ const nativeFlow = node.nativeFlowMessage || node.interactiveMessage?.nativeFlowMessage;
143
+ if (nativeFlow?.buttons) {
144
+ if (nativeFlow.buttons.length > limits.maxButtons)
145
+ reasons.push(`nativeFlow buttons ${nativeFlow.buttons.length} > ${limits.maxButtons}`);
146
+ for (const button of nativeFlow.buttons) {
147
+ const params = button?.buttonParamsJson;
148
+ if (typeof params === 'string') {
149
+ if (params.length > limits.maxParamsJson)
150
+ reasons.push(`buttonParamsJson length ${params.length}`);
151
+ else if (params.length) {
152
+ try {
153
+ JSON.parse(params);
154
+ }
155
+ catch {
156
+ reasons.push('buttonParamsJson invalid');
157
+ }
158
+ }
159
+ }
160
+ }
161
+ }
162
+ const list = node.listMessage || node.interactiveMessage?.carouselMessage;
163
+ if (list?.sections && list.sections.length > limits.maxSections)
164
+ reasons.push(`list sections ${list.sections.length} > ${limits.maxSections}`);
165
+ if (Array.isArray(list?.sections)) {
166
+ let rows = 0;
167
+ for (const section of list.sections)
168
+ rows += Array.isArray(section?.rows) ? section.rows.length : 0;
169
+ if (rows > limits.maxRows)
170
+ reasons.push(`list rows ${rows} > ${limits.maxRows}`);
171
+ }
172
+ const cards = node.interactiveMessage?.carouselMessage?.cards;
173
+ if (Array.isArray(cards) && cards.length > limits.maxCards)
174
+ reasons.push(`carousel cards ${cards.length} > ${limits.maxCards}`);
175
+ };
176
+ inspectInteractive(content);
177
+ if (typeof options.byteLength === 'number' && options.byteLength > limits.maxBytes)
178
+ reasons.push(`encoded size ${options.byteLength} > ${limits.maxBytes}`);
179
+ if (options.proto?.Message) {
180
+ try {
181
+ const encoded = options.proto.Message.encode(options.proto.Message.fromObject(message)).finish();
182
+ if (encoded.length > limits.maxBytes)
183
+ reasons.push(`encoded size ${encoded.length} > ${limits.maxBytes}`);
184
+ }
185
+ catch (error) {
186
+ reasons.push(`proto encode failed: ${error.message}`);
187
+ }
188
+ }
189
+ return { flagged: reasons.length > 0, reasons };
190
+ };
191
+ // --- burst / group-add guarding (rennzsync additions, not in upstream elaina-anchorguard) ---
192
+ const isMetaAiJid = (jid) => typeof jid === 'string' && jid.startsWith('13135550002');
193
+ export const createAnchorGuard = (sock, options = {}) => {
194
+ const config = {
195
+ autoDelete: true,
196
+ deleteMode: 'auto',
197
+ guardIncoming: true,
198
+ guardOutgoing: true,
199
+ blockOnBug: false,
200
+ selfOnly: false,
201
+ thresholds: {},
202
+ onDetect: null,
203
+ proto: null,
204
+ burstThreshold: 0, // messages within burstWindowMs from same sender before flagged as burst; 0 = disabled
205
+ burstWindowMs: 4000,
206
+ kickOnBurst: false, // remove sender from group on burst (needs group admin)
207
+ guardGroupAdds: false, // flag/kick when added to a group by a burst-flagged / unknown inviter pattern
208
+ metaAiNumbers: false, // include Meta AI's JIDs in guarding instead of ignoring them
209
+ logger: sock?.logger,
210
+ ...options
211
+ };
212
+ const ownJid = config.ownJid || sock?.user?.id;
213
+ const detectOptions = { ...config.thresholds, proto: config.proto };
214
+ const burstLog = new Map(); // sender -> timestamps[]
215
+ const removeMessage = async (jid, key) => {
216
+ if (!config.autoDelete)
217
+ return;
218
+ const revoke = config.deleteMode === 'everyone' || (config.deleteMode === 'auto' && key?.fromMe);
219
+ try {
220
+ if (revoke) {
221
+ await sock.sendMessage(jid, { delete: key });
222
+ }
223
+ else if (typeof sock.chatModify === 'function') {
224
+ await sock.chatModify({ deleteForMe: { key, timestamp: Date.now(), deleteMedia: false } }, jid);
225
+ }
226
+ }
227
+ catch (error) {
228
+ config.logger?.warn?.({ error: error.message }, 'anchorguard delete failed');
229
+ }
230
+ };
231
+ const maybeBlock = async (jid, key) => {
232
+ if (!config.blockOnBug || key?.fromMe || typeof sock.updateBlockStatus !== 'function')
233
+ return;
234
+ try {
235
+ await sock.updateBlockStatus(jid, 'block');
236
+ }
237
+ catch (error) {
238
+ config.logger?.warn?.({ error: error.message }, 'anchorguard block failed');
239
+ }
240
+ };
241
+ const maybeKickBurst = async (groupJid, sender) => {
242
+ if (!config.kickOnBurst || !groupJid?.endsWith('@g.us') || typeof sock.groupParticipantsUpdate !== 'function')
243
+ return;
244
+ try {
245
+ await sock.groupParticipantsUpdate(groupJid, [sender], 'remove');
246
+ }
247
+ catch (error) {
248
+ config.logger?.warn?.({ error: error.message }, 'anchorguard kick-on-burst failed');
249
+ }
250
+ };
251
+ const checkBurst = (jid, sender) => {
252
+ if (!config.burstThreshold || !sender)
253
+ return false;
254
+ const now = Date.now();
255
+ const stamps = (burstLog.get(sender) || []).filter((t) => now - t < config.burstWindowMs);
256
+ stamps.push(now);
257
+ burstLog.set(sender, stamps);
258
+ return stamps.length > config.burstThreshold;
259
+ };
260
+ const handleUpsert = async ({ messages }) => {
261
+ if (!config.guardIncoming || !Array.isArray(messages))
262
+ return;
263
+ for (const msg of messages) {
264
+ const content = msg?.message;
265
+ if (!content)
266
+ continue;
267
+ const jid = msg.key?.remoteJid;
268
+ const sender = msg.key?.participant || jid;
269
+ if (config.selfOnly && jid !== ownJid && !msg.key?.fromMe)
270
+ continue;
271
+ if (!config.metaAiNumbers && isMetaAiJid(sender))
272
+ continue;
273
+ const result = detectBug(content, detectOptions);
274
+ const burst = checkBurst(jid, sender);
275
+ if (!result.flagged && !burst)
276
+ continue;
277
+ const reasons = burst ? [...result.reasons, `burst > ${config.burstThreshold}/${config.burstWindowMs}ms`] : result.reasons;
278
+ config.logger?.warn?.({ jid, sender, reasons }, 'anchorguard flagged incoming message');
279
+ await config.onDetect?.({ direction: 'incoming', message: msg, jid, sender, reasons, burst });
280
+ if (result.flagged)
281
+ await removeMessage(jid, msg.key);
282
+ await maybeBlock(sender, msg.key);
283
+ if (burst)
284
+ await maybeKickBurst(jid, sender);
285
+ }
286
+ };
287
+ const handleGroupParticipantsUpdate = async (update) => {
288
+ if (!config.guardGroupAdds || update?.action !== 'add')
289
+ return;
290
+ const inviter = update?.author;
291
+ if (inviter && !config.metaAiNumbers && isMetaAiJid(inviter))
292
+ return;
293
+ if (inviter && checkBurst(update.id, inviter)) {
294
+ config.logger?.warn?.({ group: update.id, inviter }, 'anchorguard flagged burst group-add');
295
+ await config.onDetect?.({ direction: 'group-add', jid: update.id, sender: inviter, reasons: ['burst group-add'], burst: true });
296
+ await maybeKickBurst(update.id, inviter);
297
+ }
298
+ };
299
+ if (config.guardIncoming && sock?.ev?.on)
300
+ sock.ev.on('messages.upsert', handleUpsert);
301
+ if (config.guardGroupAdds && sock?.ev?.on)
302
+ sock.ev.on('group-participants.update', handleGroupParticipantsUpdate);
303
+ let originalSend = null;
304
+ if (config.guardOutgoing && typeof sock?.sendMessage === 'function') {
305
+ originalSend = sock.sendMessage.bind(sock);
306
+ sock.sendMessage = async (jid, content, sendOptions) => {
307
+ const probe = detectBug(content, detectOptions);
308
+ if (probe.flagged) {
309
+ config.logger?.warn?.({ jid, reasons: probe.reasons }, 'anchorguard blocked outgoing message');
310
+ await config.onDetect?.({ direction: 'outgoing', jid, content, reasons: probe.reasons });
311
+ throw new Error(`anchorguard blocked outgoing message: ${probe.reasons.join('; ')}`);
312
+ }
313
+ return originalSend(jid, content, sendOptions);
314
+ };
315
+ }
316
+ return {
317
+ detect: (message) => detectBug(message, detectOptions),
318
+ stop: () => {
319
+ if (config.guardIncoming && sock?.ev?.off)
320
+ sock.ev.off('messages.upsert', handleUpsert);
321
+ if (config.guardGroupAdds && sock?.ev?.off)
322
+ sock.ev.off('group-participants.update', handleGroupParticipantsUpdate);
323
+ if (originalSend)
324
+ sock.sendMessage = originalSend;
325
+ }
326
+ };
327
+ };
328
+ // kept for drop-in parity with @rexxhayanasi/elaina-anchorguard's export name
329
+ export const createAntiBugGuard = createAnchorGuard;
@@ -0,0 +1,4 @@
1
+ export function generateAndroidStanzaId(): string;
2
+ export function patchAndroidStanzaId(sock: object, logger?: {
3
+ success?: Function;
4
+ }): any;
@@ -0,0 +1,21 @@
1
+ import { randomBytes } from 'node:crypto';
2
+
3
+
4
+ /** @returns {string} A fresh Android-style message id. */
5
+ export const generateAndroidStanzaId = () => 'AC' + randomBytes(10).toString('hex').toUpperCase().slice(0, 19);
6
+
7
+ /**
8
+ * Patch `sock.relayMessage` and `sock.sendMessage` so every message without an explicit `messageId`
9
+ * gets an Android-style id. Idempotent per socket.
10
+ * @param {object} sock Active socket. @param {{ success?: Function }} [logger] Optional logger.
11
+ */
12
+ export const patchAndroidStanzaId = (sock, logger) => {
13
+ if (!sock || sock._androidIdPatched) return sock;
14
+ sock._androidIdPatched = true;
15
+ const relay = sock.relayMessage.bind(sock);
16
+ sock.relayMessage = (jid, message, options = {}) => relay(jid, message, options.messageId ? options : { ...options, messageId: generateAndroidStanzaId() });
17
+ const send = sock.sendMessage.bind(sock);
18
+ sock.sendMessage = (jid, content, options = {}) => send(jid, content, options.messageId ? options : { ...options, messageId: generateAndroidStanzaId() });
19
+ logger?.success?.('[Android ID] sock.relayMessage + sock.sendMessage patched');
20
+ return sock;
21
+ };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * In-memory, TTL-bounded store of recently seen messages, used to recover the
3
+ * original content of a message after WhatsApp delivers a REVOKE (delete-for-everyone)
4
+ * protocol message, which itself carries no content — only a reference key.
5
+ */
6
+ export class MessageStore {
7
+ constructor(options?: {});
8
+ store: Map<any, any>;
9
+ deletedMessages: Map<any, any>;
10
+ cleanupTimer: any;
11
+ options: {
12
+ maxMessagesPerChat: any;
13
+ ttl: any;
14
+ cleanupInterval: any;
15
+ };
16
+ startCleanup(): void;
17
+ stopCleanup(): void;
18
+ cleanup(): void;
19
+ getKey(key: any): string;
20
+ storeMessage(message: any): void;
21
+ storeMessages(messages: any): void;
22
+ getMessage(key: any): any;
23
+ getOriginalMessage(key: any): any;
24
+ markAsDeleted(key: any, deletedBy: any): {
25
+ originalMessage: any;
26
+ key: any;
27
+ deletedAt: number;
28
+ deletedBy: any;
29
+ isRevokedBySender: boolean;
30
+ };
31
+ getDeletedMessage(key: any): any;
32
+ getAllDeletedMessages(): any[];
33
+ getDeletedMessagesByChat(chatId: any): any[];
34
+ getChatMessages(chatId: any): any[];
35
+ getChatIds(): any[];
36
+ getStats(): {
37
+ totalChats: number;
38
+ totalMessages: number;
39
+ totalDeleted: number;
40
+ };
41
+ clear(): void;
42
+ clearChat(chatId: any): void;
43
+ getAllMessages(): {};
44
+ }
45
+ export function isDeleteMessage(message: any): boolean;
46
+ export function getDeletedMessageKey(message: any): any;
47
+ export function createAntiDeleteHandler(store: any, onDelete: any): (updates: any) => any[];
48
+ export function createAntiDeleteUpsertHandler(store: any, onDelete: any): (opts1: { [key: string]: any;
49
+ messages: any;
50
+ }) => any[];
51
+ export function createMessageStoreHandler(store: any): (opts2: { [key: string]: any;
52
+ messages: any;
53
+ }) => void;
54
+ declare namespace _default {
55
+ export { MessageStore };
56
+ export { isDeleteMessage };
57
+ export { getDeletedMessageKey };
58
+ export { createAntiDeleteHandler };
59
+ export { createAntiDeleteUpsertHandler };
60
+ export { createMessageStoreHandler };
61
+ }
62
+ export default _default;
@@ -0,0 +1,212 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ // ── MessageStore ───────────────────────────────────────────────────────────
3
+ /**
4
+ * In-memory, TTL-bounded store of recently seen messages, used to recover the
5
+ * original content of a message after WhatsApp delivers a REVOKE (delete-for-everyone)
6
+ * protocol message, which itself carries no content — only a reference key.
7
+ */
8
+ export class MessageStore {
9
+ store = new Map();
10
+ deletedMessages = new Map();
11
+ cleanupTimer = null;
12
+ options;
13
+ constructor(options = {}) {
14
+ this.options = {
15
+ maxMessagesPerChat: options.maxMessagesPerChat ?? 1000,
16
+ ttl: options.ttl ?? 24 * 60 * 60 * 1000,
17
+ cleanupInterval: options.cleanupInterval ?? 60 * 60 * 1000
18
+ };
19
+ this.startCleanup();
20
+ }
21
+ startCleanup() {
22
+ this.cleanupTimer = setInterval(() => this.cleanup(), this.options.cleanupInterval);
23
+ this.cleanupTimer?.unref?.();
24
+ }
25
+ stopCleanup() {
26
+ if (this.cleanupTimer)
27
+ clearInterval(this.cleanupTimer);
28
+ }
29
+ cleanup() {
30
+ const cutoff = Date.now() - this.options.ttl;
31
+ for (const [chatId, messages] of this.store) {
32
+ for (const [msgId, stored] of messages) {
33
+ if (stored.storedAt < cutoff)
34
+ messages.delete(msgId);
35
+ }
36
+ if (messages.size === 0)
37
+ this.store.delete(chatId);
38
+ }
39
+ for (const [key, info] of this.deletedMessages) {
40
+ if (info.deletedAt < cutoff)
41
+ this.deletedMessages.delete(key);
42
+ }
43
+ }
44
+ getKey(key) {
45
+ return `${key.remoteJid}:${key.id}`;
46
+ }
47
+ storeMessage(message) {
48
+ const chatId = message.key.remoteJid;
49
+ if (!chatId || !message.key.id)
50
+ return;
51
+ let chatMessages = this.store.get(chatId);
52
+ if (!chatMessages) {
53
+ chatMessages = new Map();
54
+ this.store.set(chatId, chatMessages);
55
+ }
56
+ if (chatMessages.size >= this.options.maxMessagesPerChat) {
57
+ const oldestKey = chatMessages.keys().next().value;
58
+ if (oldestKey)
59
+ chatMessages.delete(oldestKey);
60
+ }
61
+ chatMessages.set(message.key.id, { message, storedAt: Date.now(), isDeleted: false });
62
+ }
63
+ storeMessages(messages) {
64
+ for (const msg of messages)
65
+ this.storeMessage(msg);
66
+ }
67
+ getMessage(key) {
68
+ return this.store.get(key.remoteJid)?.get(key.id);
69
+ }
70
+ getOriginalMessage(key) {
71
+ return this.getMessage(key)?.message;
72
+ }
73
+ markAsDeleted(key, deletedBy) {
74
+ const stored = this.getMessage(key);
75
+ if (!stored)
76
+ return null;
77
+ const now = Date.now();
78
+ stored.isDeleted = true;
79
+ stored.deletedAt = now;
80
+ stored.deletedBy = deletedBy;
81
+ const isGroupMessage = !!stored.message.key.participant;
82
+ const info = {
83
+ originalMessage: stored.message,
84
+ key,
85
+ deletedAt: now,
86
+ deletedBy,
87
+ isRevokedBySender: !deletedBy || !isGroupMessage || deletedBy === stored.message.key.participant
88
+ };
89
+ this.deletedMessages.set(this.getKey(key), info);
90
+ return info;
91
+ }
92
+ getDeletedMessage(key) {
93
+ return this.deletedMessages.get(this.getKey(key));
94
+ }
95
+ getAllDeletedMessages() {
96
+ return Array.from(this.deletedMessages.values());
97
+ }
98
+ getDeletedMessagesByChat(chatId) {
99
+ return Array.from(this.deletedMessages.values()).filter((i) => i.key.remoteJid === chatId);
100
+ }
101
+ getChatMessages(chatId) {
102
+ return Array.from(this.store.get(chatId)?.values() ?? []).map((s) => s.message);
103
+ }
104
+ getChatIds() {
105
+ return Array.from(this.store.keys());
106
+ }
107
+ getStats() {
108
+ let totalMessages = 0;
109
+ for (const messages of this.store.values())
110
+ totalMessages += messages.size;
111
+ return { totalChats: this.store.size, totalMessages, totalDeleted: this.deletedMessages.size };
112
+ }
113
+ clear() {
114
+ this.store.clear();
115
+ this.deletedMessages.clear();
116
+ }
117
+ clearChat(chatId) {
118
+ this.store.delete(chatId);
119
+ }
120
+ getAllMessages() {
121
+ const all = {};
122
+ for (const [chatId, messages] of this.store) {
123
+ all[chatId] = Array.from(messages.values()).map((s) => s.message);
124
+ }
125
+ return all;
126
+ }
127
+ }
128
+ // ── Helpers ────────────────────────────────────────────────────────────────
129
+ export const isDeleteMessage = (message) => {
130
+ return message.message?.protocolMessage?.type === proto.Message.ProtocolMessage.Type.REVOKE;
131
+ };
132
+ export const getDeletedMessageKey = (message) => {
133
+ const protoMsg = message.message?.protocolMessage;
134
+ if (protoMsg?.type !== proto.Message.ProtocolMessage.Type.REVOKE)
135
+ return null;
136
+ return protoMsg.key ?? null;
137
+ };
138
+ /**
139
+ * Wire this into `sock.ev.on('messages.update', ...)`. Fires `onDelete` for
140
+ * every update in the batch whose stub type is REVOKE, using `store` to look
141
+ * up the original content that WhatsApp's own update payload omits.
142
+ */
143
+ export const createAntiDeleteHandler = (store, onDelete) => {
144
+ return (updates) => {
145
+ const deletedMessages = [];
146
+ for (const { key, update } of updates) {
147
+ if (update.messageStubType === proto.WebMessageInfo.StubType.REVOKE) {
148
+ const info = store.markAsDeleted(key, update.messageStubParameters?.[0]);
149
+ if (info) {
150
+ deletedMessages.push(info);
151
+ onDelete?.(info);
152
+ }
153
+ }
154
+ }
155
+ return deletedMessages;
156
+ };
157
+ };
158
+ /**
159
+ * `createAntiDeleteHandler` above only listens on
160
+ * `messages.update` with `messageStubType === REVOKE`. In practice, most
161
+ * delete-for-everyone events actually arrive as a *new* message on
162
+ * `messages.upsert` carrying a `protocolMessage` of type REVOKE (the
163
+ * `isDeleteMessage`/`getDeletedMessageKey` helpers above existed for this but
164
+ * were never wired to anything). Wire this into `sock.ev.on('messages.upsert', ...)`
165
+ * alongside `createMessageStoreHandler` to actually catch those.
166
+ */
167
+ export const createAntiDeleteUpsertHandler = (store, onDelete) => {
168
+ return ({ messages }) => {
169
+ const deletedMessages = [];
170
+ for (const message of messages) {
171
+ if (!isDeleteMessage(message))
172
+ continue;
173
+ const key = getDeletedMessageKey(message);
174
+ if (!key)
175
+ continue;
176
+ const deletedBy = message.key.participant || message.key.remoteJid;
177
+ const info = store.markAsDeleted(key, deletedBy);
178
+ if (info) {
179
+ deletedMessages.push(info);
180
+ onDelete?.(info);
181
+ }
182
+ }
183
+ return deletedMessages;
184
+ };
185
+ };
186
+ /**
187
+ * Wire this into `sock.ev.on('messages.upsert', ...)` to keep `store` populated.
188
+ * Skips protocol/sender-key-distribution messages, which carry no user content.
189
+ */
190
+ export const createMessageStoreHandler = (store) => {
191
+ return ({ messages }) => {
192
+ const regular = messages.filter((msg) => {
193
+ const c = msg.message;
194
+ if (!c)
195
+ return false;
196
+ if (c.protocolMessage)
197
+ return false;
198
+ if (c.senderKeyDistributionMessage)
199
+ return false;
200
+ return true;
201
+ });
202
+ store.storeMessages(regular);
203
+ };
204
+ };
205
+ export default {
206
+ MessageStore,
207
+ isDeleteMessage,
208
+ getDeletedMessageKey,
209
+ createAntiDeleteHandler,
210
+ createAntiDeleteUpsertHandler,
211
+ createMessageStoreHandler
212
+ };