@fer2809fl/baileys 1.4.9 → 7.0.0

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 (481) hide show
  1. package/LICENSE +21 -674
  2. package/README.md +556 -523
  3. package/WAProto/GenerateStatics.sh +3 -4
  4. package/WAProto/WAProto.proto +1215 -511
  5. package/WAProto/fix-imports.js +85 -0
  6. package/WAProto/index.d.ts +4347 -45387
  7. package/WAProto/index.js +65475 -137445
  8. package/engine-requirements.js +10 -0
  9. package/lib/Defaults/index.d.ts +34 -18
  10. package/lib/Defaults/index.d.ts.map +1 -0
  11. package/lib/Defaults/index.js +95 -67
  12. package/lib/Defaults/index.js.map +1 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts +1 -0
  14. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  15. package/lib/Signal/Group/ciphertext-message.js +2 -5
  16. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts +4 -3
  18. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  19. package/lib/Signal/Group/group-session-builder.js +7 -41
  20. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  21. package/lib/Signal/Group/group_cipher.d.ts +4 -4
  22. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  23. package/lib/Signal/Group/group_cipher.js +37 -60
  24. package/lib/Signal/Group/group_cipher.js.map +1 -0
  25. package/lib/Signal/Group/index.d.ts +12 -11
  26. package/lib/Signal/Group/index.d.ts.map +1 -0
  27. package/lib/Signal/Group/index.js +12 -57
  28. package/lib/Signal/Group/index.js.map +1 -0
  29. package/lib/Signal/Group/keyhelper.d.ts +2 -1
  30. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  31. package/lib/Signal/Group/keyhelper.js +7 -44
  32. package/lib/Signal/Group/keyhelper.js.map +1 -0
  33. package/lib/Signal/Group/sender-chain-key.d.ts +3 -2
  34. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  35. package/lib/Signal/Group/sender-chain-key.js +7 -15
  36. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.d.ts +2 -1
  38. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  39. package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
  40. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  41. package/lib/Signal/Group/sender-key-message.d.ts +2 -1
  42. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  43. package/lib/Signal/Group/sender-key-message.js +9 -12
  44. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  45. package/lib/Signal/Group/sender-key-name.d.ts +1 -0
  46. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  47. package/lib/Signal/Group/sender-key-name.js +2 -5
  48. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  49. package/lib/Signal/Group/sender-key-record.d.ts +3 -2
  50. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  51. package/lib/Signal/Group/sender-key-record.js +12 -37
  52. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  53. package/lib/Signal/Group/sender-key-state.d.ts +7 -6
  54. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  55. package/lib/Signal/Group/sender-key-state.js +27 -42
  56. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  57. package/lib/Signal/Group/sender-message-key.d.ts +1 -0
  58. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  59. package/lib/Signal/Group/sender-message-key.js +4 -7
  60. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  61. package/lib/Signal/libsignal.d.ts +5 -3
  62. package/lib/Signal/libsignal.d.ts.map +1 -0
  63. package/lib/Signal/libsignal.js +347 -90
  64. package/lib/Signal/libsignal.js.map +1 -0
  65. package/lib/Signal/lid-mapping.d.ts +23 -0
  66. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  67. package/lib/Signal/lid-mapping.js +277 -0
  68. package/lib/Signal/lid-mapping.js.map +1 -0
  69. package/lib/Socket/Client/index.d.ts +3 -2
  70. package/lib/Socket/Client/index.d.ts.map +1 -0
  71. package/lib/Socket/Client/index.js +3 -18
  72. package/lib/Socket/Client/index.js.map +1 -0
  73. package/lib/Socket/Client/types.d.ts +4 -4
  74. package/lib/Socket/Client/types.d.ts.map +1 -0
  75. package/lib/Socket/Client/types.js +4 -6
  76. package/lib/Socket/Client/types.js.map +1 -0
  77. package/lib/Socket/Client/websocket.d.ts +3 -3
  78. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  79. package/lib/Socket/Client/websocket.js +21 -78
  80. package/lib/Socket/Client/websocket.js.map +1 -0
  81. package/lib/Socket/business.d.ts +205 -93
  82. package/lib/Socket/business.d.ts.map +1 -0
  83. package/lib/Socket/business.js +162 -43
  84. package/lib/Socket/business.js.map +1 -0
  85. package/lib/Socket/chats.d.ts +77 -28
  86. package/lib/Socket/chats.d.ts.map +1 -0
  87. package/lib/Socket/chats.js +639 -248
  88. package/lib/Socket/chats.js.map +1 -0
  89. package/lib/Socket/communities.d.ts +340 -0
  90. package/lib/Socket/communities.d.ts.map +1 -0
  91. package/lib/Socket/communities.js +434 -0
  92. package/lib/Socket/communities.js.map +1 -0
  93. package/lib/Socket/groups.d.ts +93 -46
  94. package/lib/Socket/groups.d.ts.map +1 -0
  95. package/lib/Socket/groups.js +260 -102
  96. package/lib/Socket/groups.js.map +1 -0
  97. package/lib/Socket/index.d.ts +253 -98
  98. package/lib/Socket/index.d.ts.map +1 -0
  99. package/lib/Socket/index.js +11 -9
  100. package/lib/Socket/index.js.map +1 -0
  101. package/lib/Socket/messages-recv.d.ts +192 -83
  102. package/lib/Socket/messages-recv.d.ts.map +1 -0
  103. package/lib/Socket/messages-recv.js +1314 -559
  104. package/lib/Socket/messages-recv.js.map +1 -0
  105. package/lib/Socket/messages-send.d.ts +190 -75
  106. package/lib/Socket/messages-send.d.ts.map +1 -0
  107. package/lib/Socket/messages-send.js +937 -581
  108. package/lib/Socket/messages-send.js.map +1 -0
  109. package/lib/Socket/mex.d.ts +4 -0
  110. package/lib/Socket/mex.d.ts.map +1 -0
  111. package/lib/Socket/mex.js +62 -0
  112. package/lib/Socket/mex.js.map +1 -0
  113. package/lib/Socket/newsletter.d.ts +129 -73
  114. package/lib/Socket/newsletter.d.ts.map +1 -0
  115. package/lib/Socket/newsletter.js +373 -222
  116. package/lib/Socket/newsletter.js.map +1 -0
  117. package/lib/Socket/smgss.d.ts +119 -0
  118. package/lib/Socket/smgss.d.ts.map +1 -0
  119. package/lib/Socket/smgss.js +453 -0
  120. package/lib/Socket/smgss.js.map +1 -0
  121. package/lib/Socket/socket.d.ts +59 -270
  122. package/lib/Socket/socket.d.ts.map +1 -0
  123. package/lib/Socket/socket.js +738 -326
  124. package/lib/Socket/socket.js.map +1 -0
  125. package/lib/Store/index.d.ts +4 -2
  126. package/lib/Store/index.d.ts.map +1 -0
  127. package/lib/Store/index.js +4 -8
  128. package/lib/Store/index.js.map +1 -0
  129. package/lib/Store/make-in-memory-store.d.ts +74 -60
  130. package/lib/Store/make-in-memory-store.d.ts.map +1 -0
  131. package/lib/Store/make-in-memory-store.js +130 -119
  132. package/lib/Store/make-in-memory-store.js.map +1 -0
  133. package/lib/Store/make-ordered-dictionary.d.ts +4 -3
  134. package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
  135. package/lib/Store/make-ordered-dictionary.js +5 -6
  136. package/lib/Store/make-ordered-dictionary.js.map +1 -0
  137. package/lib/Store/object-repository.d.ts +6 -3
  138. package/lib/Store/object-repository.d.ts.map +1 -0
  139. package/lib/Store/object-repository.js +2 -5
  140. package/lib/Store/object-repository.js.map +1 -0
  141. package/lib/Types/Auth.d.ts +19 -5
  142. package/lib/Types/Auth.d.ts.map +1 -0
  143. package/lib/Types/Auth.js +2 -2
  144. package/lib/Types/Auth.js.map +1 -0
  145. package/lib/Types/Bussines.d.ts +25 -0
  146. package/lib/Types/Bussines.d.ts.map +1 -0
  147. package/lib/Types/Bussines.js +2 -0
  148. package/lib/Types/Bussines.js.map +1 -0
  149. package/lib/Types/Call.d.ts +3 -1
  150. package/lib/Types/Call.d.ts.map +1 -0
  151. package/lib/Types/Call.js +2 -2
  152. package/lib/Types/Call.js.map +1 -0
  153. package/lib/Types/Chat.d.ts +24 -9
  154. package/lib/Types/Chat.d.ts.map +1 -0
  155. package/lib/Types/Chat.js +8 -4
  156. package/lib/Types/Chat.js.map +1 -0
  157. package/lib/Types/Contact.d.ts +7 -4
  158. package/lib/Types/Contact.d.ts.map +1 -0
  159. package/lib/Types/Contact.js +2 -2
  160. package/lib/Types/Contact.js.map +1 -0
  161. package/lib/Types/Events.d.ts +90 -33
  162. package/lib/Types/Events.d.ts.map +1 -0
  163. package/lib/Types/Events.js +2 -2
  164. package/lib/Types/Events.js.map +1 -0
  165. package/lib/Types/GroupMetadata.d.ts +16 -9
  166. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  167. package/lib/Types/GroupMetadata.js +2 -2
  168. package/lib/Types/GroupMetadata.js.map +1 -0
  169. package/lib/Types/Label.d.ts +12 -0
  170. package/lib/Types/Label.d.ts.map +1 -0
  171. package/lib/Types/Label.js +3 -5
  172. package/lib/Types/Label.js.map +1 -0
  173. package/lib/Types/LabelAssociation.d.ts +1 -0
  174. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  175. package/lib/Types/LabelAssociation.js +3 -5
  176. package/lib/Types/LabelAssociation.js.map +1 -0
  177. package/lib/Types/Message.d.ts +176 -148
  178. package/lib/Types/Message.d.ts.map +1 -0
  179. package/lib/Types/Message.js +15 -7
  180. package/lib/Types/Message.js.map +1 -0
  181. package/lib/Types/Mex.d.ts +154 -0
  182. package/lib/Types/Mex.d.ts.map +1 -0
  183. package/lib/Types/Mex.js +39 -0
  184. package/lib/Types/Mex.js.map +1 -0
  185. package/lib/Types/Product.d.ts +2 -1
  186. package/lib/Types/Product.d.ts.map +1 -0
  187. package/lib/Types/Product.js +2 -2
  188. package/lib/Types/Product.js.map +1 -0
  189. package/lib/Types/Signal.d.ts +32 -2
  190. package/lib/Types/Signal.d.ts.map +1 -0
  191. package/lib/Types/Signal.js +2 -2
  192. package/lib/Types/Signal.js.map +1 -0
  193. package/lib/Types/Socket.d.ts +46 -20
  194. package/lib/Types/Socket.d.ts.map +1 -0
  195. package/lib/Types/Socket.js +3 -2
  196. package/lib/Types/Socket.js.map +1 -0
  197. package/lib/Types/State.d.ts +79 -2
  198. package/lib/Types/State.d.ts.map +1 -0
  199. package/lib/Types/State.js +56 -2
  200. package/lib/Types/State.js.map +1 -0
  201. package/lib/Types/USync.d.ts +3 -2
  202. package/lib/Types/USync.d.ts.map +1 -0
  203. package/lib/Types/USync.js +2 -2
  204. package/lib/Types/USync.js.map +1 -0
  205. package/lib/Types/index.d.ts +16 -14
  206. package/lib/Types/index.d.ts.map +1 -0
  207. package/lib/Types/index.js +15 -31
  208. package/lib/Types/index.js.map +1 -0
  209. package/lib/Utils/auth-utils.d.ts +10 -4
  210. package/lib/Utils/auth-utils.d.ts.map +1 -0
  211. package/lib/Utils/auth-utils.js +242 -151
  212. package/lib/Utils/auth-utils.js.map +1 -0
  213. package/lib/Utils/browser-utils.d.ts +4 -0
  214. package/lib/Utils/browser-utils.d.ts.map +1 -0
  215. package/lib/Utils/browser-utils.js +29 -0
  216. package/lib/Utils/browser-utils.js.map +1 -0
  217. package/lib/Utils/business.d.ts +3 -2
  218. package/lib/Utils/business.d.ts.map +1 -0
  219. package/lib/Utils/business.js +66 -69
  220. package/lib/Utils/business.js.map +1 -0
  221. package/lib/Utils/button-handler.d.ts +28 -0
  222. package/lib/Utils/button-handler.d.ts.map +1 -0
  223. package/lib/Utils/button-handler.js +79 -90
  224. package/lib/Utils/button-handler.js.map +1 -0
  225. package/lib/Utils/chat-utils.d.ts +42 -12
  226. package/lib/Utils/chat-utils.d.ts.map +1 -0
  227. package/lib/Utils/chat-utils.js +380 -238
  228. package/lib/Utils/chat-utils.js.map +1 -0
  229. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  230. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  231. package/lib/Utils/companion-reg-client-utils.js +35 -0
  232. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  233. package/lib/Utils/crypto.d.ts +11 -14
  234. package/lib/Utils/crypto.d.ts.map +1 -0
  235. package/lib/Utils/crypto.js +41 -116
  236. package/lib/Utils/crypto.js.map +1 -0
  237. package/lib/Utils/decode-wa-message.d.ts +36 -5
  238. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  239. package/lib/Utils/decode-wa-message.js +173 -63
  240. package/lib/Utils/decode-wa-message.js.map +1 -0
  241. package/lib/Utils/event-buffer.d.ts +8 -7
  242. package/lib/Utils/event-buffer.d.ts.map +1 -0
  243. package/lib/Utils/event-buffer.js +174 -70
  244. package/lib/Utils/event-buffer.js.map +1 -0
  245. package/lib/Utils/generics.d.ts +20 -17
  246. package/lib/Utils/generics.d.ts.map +1 -0
  247. package/lib/Utils/generics.js +159 -207
  248. package/lib/Utils/generics.js.map +1 -0
  249. package/lib/Utils/history.d.ts +16 -11
  250. package/lib/Utils/history.d.ts.map +1 -0
  251. package/lib/Utils/history.js +93 -53
  252. package/lib/Utils/history.js.map +1 -0
  253. package/lib/Utils/identity-change-handler.d.ts +44 -0
  254. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  255. package/lib/Utils/identity-change-handler.js +50 -0
  256. package/lib/Utils/identity-change-handler.js.map +1 -0
  257. package/lib/Utils/index.d.ts +30 -18
  258. package/lib/Utils/index.d.ts.map +1 -0
  259. package/lib/Utils/index.js +30 -34
  260. package/lib/Utils/index.js.map +1 -0
  261. package/lib/Utils/interactive.d.ts +60 -0
  262. package/lib/Utils/interactive.d.ts.map +1 -0
  263. package/lib/Utils/interactive.js +87 -117
  264. package/lib/Utils/interactive.js.map +1 -0
  265. package/lib/Utils/link-preview.d.ts +4 -4
  266. package/lib/Utils/link-preview.d.ts.map +1 -0
  267. package/lib/Utils/link-preview.js +17 -58
  268. package/lib/Utils/link-preview.js.map +1 -0
  269. package/lib/Utils/logger.d.ts +8 -6
  270. package/lib/Utils/logger.d.ts.map +1 -0
  271. package/lib/Utils/logger.js +3 -10
  272. package/lib/Utils/logger.js.map +1 -0
  273. package/lib/Utils/lt-hash.d.ts +8 -12
  274. package/lib/Utils/lt-hash.d.ts.map +1 -0
  275. package/lib/Utils/lt-hash.js +3 -46
  276. package/lib/Utils/lt-hash.js.map +1 -0
  277. package/lib/Utils/make-mutex.d.ts +2 -0
  278. package/lib/Utils/make-mutex.d.ts.map +1 -0
  279. package/lib/Utils/make-mutex.js +24 -34
  280. package/lib/Utils/make-mutex.js.map +1 -0
  281. package/lib/Utils/message-composer.d.ts +93 -0
  282. package/lib/Utils/message-composer.d.ts.map +1 -0
  283. package/lib/Utils/message-composer.js +311 -0
  284. package/lib/Utils/message-composer.js.map +1 -0
  285. package/lib/Utils/message-retry-manager.d.ts +115 -0
  286. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  287. package/lib/Utils/message-retry-manager.js +265 -0
  288. package/lib/Utils/message-retry-manager.js.map +1 -0
  289. package/lib/Utils/messages-media.d.ts +82 -40
  290. package/lib/Utils/messages-media.d.ts.map +1 -0
  291. package/lib/Utils/messages-media.js +674 -677
  292. package/lib/Utils/messages-media.js.map +1 -0
  293. package/lib/Utils/messages-newsletter.d.ts +74 -0
  294. package/lib/Utils/messages-newsletter.d.ts.map +1 -0
  295. package/lib/Utils/messages-newsletter.js +128 -0
  296. package/lib/Utils/messages-newsletter.js.map +1 -0
  297. package/lib/Utils/messages.d.ts +38 -14
  298. package/lib/Utils/messages.d.ts.map +1 -0
  299. package/lib/Utils/messages.js +835 -602
  300. package/lib/Utils/messages.js.map +1 -0
  301. package/lib/Utils/noise-handler.d.ts +9 -8
  302. package/lib/Utils/noise-handler.d.ts.map +1 -0
  303. package/lib/Utils/noise-handler.js +149 -98
  304. package/lib/Utils/noise-handler.js.map +1 -0
  305. package/lib/Utils/offline-node-processor.d.ts +17 -0
  306. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  307. package/lib/Utils/offline-node-processor.js +40 -0
  308. package/lib/Utils/offline-node-processor.js.map +1 -0
  309. package/lib/Utils/pre-key-manager.d.ts +28 -0
  310. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  311. package/lib/Utils/pre-key-manager.js +106 -0
  312. package/lib/Utils/pre-key-manager.js.map +1 -0
  313. package/lib/Utils/process-message.d.ts +30 -12
  314. package/lib/Utils/process-message.d.ts.map +1 -0
  315. package/lib/Utils/process-message.js +438 -230
  316. package/lib/Utils/process-message.js.map +1 -0
  317. package/lib/Utils/reporting-utils.d.ts +11 -0
  318. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  319. package/lib/Utils/reporting-utils.js +258 -0
  320. package/lib/Utils/reporting-utils.js.map +1 -0
  321. package/lib/Utils/shortcake-crypto.d.ts +36 -0
  322. package/lib/Utils/shortcake-crypto.d.ts.map +1 -0
  323. package/lib/Utils/shortcake-crypto.js +71 -0
  324. package/lib/Utils/shortcake-crypto.js.map +1 -0
  325. package/lib/Utils/shortcake.d.ts +36 -0
  326. package/lib/Utils/shortcake.d.ts.map +1 -0
  327. package/lib/Utils/shortcake.js +162 -0
  328. package/lib/Utils/shortcake.js.map +1 -0
  329. package/lib/Utils/signal.d.ts +20 -6
  330. package/lib/Utils/signal.d.ts.map +1 -0
  331. package/lib/Utils/signal.js +112 -64
  332. package/lib/Utils/signal.js.map +1 -0
  333. package/lib/Utils/stanza-ack.d.ts +11 -0
  334. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  335. package/lib/Utils/stanza-ack.js +38 -0
  336. package/lib/Utils/stanza-ack.js.map +1 -0
  337. package/lib/Utils/sync-action-utils.d.ts +19 -0
  338. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  339. package/lib/Utils/sync-action-utils.js +49 -0
  340. package/lib/Utils/sync-action-utils.js.map +1 -0
  341. package/lib/Utils/tc-token-utils.d.ts +37 -0
  342. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  343. package/lib/Utils/tc-token-utils.js +164 -0
  344. package/lib/Utils/tc-token-utils.js.map +1 -0
  345. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  346. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  347. package/lib/Utils/use-multi-file-auth-state.js +40 -64
  348. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  349. package/lib/Utils/use-single-file-auth-state.d.ts +6 -0
  350. package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
  351. package/lib/Utils/use-single-file-auth-state.js +111 -0
  352. package/lib/Utils/use-single-file-auth-state.js.map +1 -0
  353. package/lib/Utils/use-sqlite-auth-state.d.ts +14 -0
  354. package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
  355. package/lib/Utils/use-sqlite-auth-state.js +107 -0
  356. package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
  357. package/lib/Utils/validate-connection.d.ts +5 -3
  358. package/lib/Utils/validate-connection.d.ts.map +1 -0
  359. package/lib/Utils/validate-connection.js +82 -101
  360. package/lib/Utils/validate-connection.js.map +1 -0
  361. package/lib/WABinary/constants.d.ts +1 -0
  362. package/lib/WABinary/constants.d.ts.map +1 -0
  363. package/lib/WABinary/constants.js +10 -12
  364. package/lib/WABinary/constants.js.map +1 -0
  365. package/lib/WABinary/decode.d.ts +2 -1
  366. package/lib/WABinary/decode.d.ts.map +1 -0
  367. package/lib/WABinary/decode.js +49 -52
  368. package/lib/WABinary/decode.js.map +1 -0
  369. package/lib/WABinary/encode.d.ts +2 -1
  370. package/lib/WABinary/encode.d.ts.map +1 -0
  371. package/lib/WABinary/encode.js +19 -49
  372. package/lib/WABinary/encode.js.map +1 -0
  373. package/lib/WABinary/generic-utils.d.ts +5 -4
  374. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  375. package/lib/WABinary/generic-utils.js +46 -43
  376. package/lib/WABinary/generic-utils.js.map +1 -0
  377. package/lib/WABinary/index.d.ts +6 -5
  378. package/lib/WABinary/index.d.ts.map +1 -0
  379. package/lib/WABinary/index.js +6 -21
  380. package/lib/WABinary/index.js.map +1 -0
  381. package/lib/WABinary/jid-utils.d.ts +32 -10
  382. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  383. package/lib/WABinary/jid-utils.js +103 -59
  384. package/lib/WABinary/jid-utils.js.map +1 -0
  385. package/lib/WABinary/types.d.ts +2 -1
  386. package/lib/WABinary/types.d.ts.map +1 -0
  387. package/lib/WABinary/types.js +2 -2
  388. package/lib/WABinary/types.js.map +1 -0
  389. package/lib/WAM/BinaryInfo.d.ts +2 -1
  390. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  391. package/lib/WAM/BinaryInfo.js +2 -5
  392. package/lib/WAM/BinaryInfo.js.map +1 -0
  393. package/lib/WAM/constants.d.ts +5 -3
  394. package/lib/WAM/constants.d.ts.map +1 -0
  395. package/lib/WAM/constants.js +19071 -11568
  396. package/lib/WAM/constants.js.map +1 -0
  397. package/lib/WAM/encode.d.ts +2 -1
  398. package/lib/WAM/encode.d.ts.map +1 -0
  399. package/lib/WAM/encode.js +17 -22
  400. package/lib/WAM/encode.js.map +1 -0
  401. package/lib/WAM/index.d.ts +4 -3
  402. package/lib/WAM/index.d.ts.map +1 -0
  403. package/lib/WAM/index.js +4 -19
  404. package/lib/WAM/index.js.map +1 -0
  405. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
  406. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  407. package/lib/WAUSync/Protocols/USyncContactProtocol.js +33 -13
  408. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  409. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
  410. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  411. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
  412. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  413. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
  414. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  415. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -11
  416. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  417. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
  418. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  419. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
  420. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  421. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  422. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  423. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  424. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  425. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
  426. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  427. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
  428. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  429. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +5 -3
  430. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  431. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
  432. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  433. package/lib/WAUSync/Protocols/index.d.ts +6 -4
  434. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  435. package/lib/WAUSync/Protocols/index.js +6 -20
  436. package/lib/WAUSync/Protocols/index.js.map +1 -0
  437. package/lib/WAUSync/USyncQuery.d.ts +6 -4
  438. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  439. package/lib/WAUSync/USyncQuery.js +44 -35
  440. package/lib/WAUSync/USyncQuery.js.map +1 -0
  441. package/lib/WAUSync/USyncUser.d.ts +10 -5
  442. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  443. package/lib/WAUSync/USyncUser.js +10 -5
  444. package/lib/WAUSync/USyncUser.js.map +1 -0
  445. package/lib/WAUSync/index.d.ts +4 -3
  446. package/lib/WAUSync/index.d.ts.map +1 -0
  447. package/lib/WAUSync/index.js +4 -19
  448. package/lib/WAUSync/index.js.map +1 -0
  449. package/lib/index.d.ts +12 -15
  450. package/lib/index.d.ts.map +1 -0
  451. package/lib/index.js +15 -48
  452. package/lib/index.js.map +1 -0
  453. package/package.json +44 -64
  454. package/WAProto/index.ts.ts +0 -53473
  455. package/WAProto/n +0 -1
  456. package/lib/Baileys.jpeg +0 -0
  457. package/lib/Defaults/baileys-version.json +0 -3
  458. package/lib/Defaults/n +0 -1
  459. package/lib/Signal/Group/queue-job.d.ts +0 -1
  460. package/lib/Signal/Group/queue-job.js +0 -57
  461. package/lib/Signal/n +0 -1
  462. package/lib/Socket/Client/n +0 -1
  463. package/lib/Socket/n +0 -1
  464. package/lib/Socket/setup.js +0 -480
  465. package/lib/Socket/setup.ts +0 -622
  466. package/lib/Socket/usync.d.ts +0 -36
  467. package/lib/Socket/usync.js +0 -70
  468. package/lib/Store/n +0 -1
  469. package/lib/Types/Newsletter.d.ts +0 -79
  470. package/lib/Types/Newsletter.js +0 -18
  471. package/lib/Types/n +0 -1
  472. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  473. package/lib/Utils/baileys-event-stream.js +0 -63
  474. package/lib/Utils/error-handler.js +0 -37
  475. package/lib/Utils/n +0 -1
  476. package/lib/WABinary/jid-utils.js.bak +0 -83
  477. package/lib/WABinary/n +0 -1
  478. package/lib/WAM/n +0 -1
  479. package/lib/WAUSync/Protocols/n +0 -1
  480. package/lib/WAUSync/n +0 -1
  481. package/lib/n +0 -1
@@ -1,47 +1,87 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
4
- exports.decryptPollVote = decryptPollVote;
5
- const WAProto_1 = require("../../WAProto");
6
- const Types_1 = require("../Types");
7
- const messages_1 = require("../Utils/messages");
8
- const WABinary_1 = require("../WABinary");
9
- const crypto_1 = require("./crypto");
10
- const generics_1 = require("./generics");
11
- const history_1 = require("./history");
1
+ import { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto/index.js';
3
+ import { WAMessageStubType } from '../Types/index.js';
4
+ import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
5
+ import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, isLidUser, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
6
+ import { aesDecryptGCM, hmacSign } from './crypto.js';
7
+ import { getKeyAuthor, toNumber } from './generics.js';
8
+ import { downloadAndProcessHistorySyncNotification } from './history.js';
9
+ import { buildMergedTcTokenIndexWrite, resolveTcTokenJid } from './tc-token-utils.js';
12
10
  const REAL_MSG_STUB_TYPES = new Set([
13
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
14
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
15
- Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
16
- Types_1.WAMessageStubType.CALL_MISSED_VOICE
11
+ WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
12
+ WAMessageStubType.CALL_MISSED_GROUP_VOICE,
13
+ WAMessageStubType.CALL_MISSED_VIDEO,
14
+ WAMessageStubType.CALL_MISSED_VOICE
17
15
  ]);
18
- const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
19
- Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
20
- ]);
21
- /** Cleans a received message to further processing */
22
- const cleanMessage = (message, meId) => {
23
- // ensure remoteJid and participant doesn't have device or agent in it
24
- // normalize JIDs but catch errors to avoid throwing on invalid LIDs/JIDs
25
- try {
26
- message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
16
+ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
17
+ async function storeTcTokensFromHistorySync(chats, signalRepository, keyStore, logger) {
18
+ const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
19
+ const candidates = [];
20
+ for (const chat of chats) {
21
+ const ts = chat.tcTokenTimestamp ? toNumber(chat.tcTokenTimestamp) : 0;
22
+ if (chat.tcToken?.length && ts > 0) {
23
+ const jid = jidNormalizedUser(chat.id);
24
+ const storageJid = await resolveTcTokenJid(jid, getLIDForPN);
25
+ candidates.push({
26
+ storageJid,
27
+ token: Buffer.from(chat.tcToken),
28
+ ts,
29
+ senderTs: chat.tcTokenSenderTimestamp ? toNumber(chat.tcTokenSenderTimestamp) : undefined
30
+ });
31
+ }
32
+ }
33
+ if (!candidates.length) {
34
+ return;
27
35
  }
28
- catch (_e) {
29
- // if normalization fails, retain original remoteJid
36
+ const jids = candidates.map(c => c.storageJid);
37
+ const existing = await keyStore.get('tctoken', jids);
38
+ const entries = {};
39
+ for (const c of candidates) {
40
+ const existingEntry = existing[c.storageJid];
41
+ const existingTs = existingEntry?.timestamp ? Number(existingEntry.timestamp) : 0;
42
+ if (existingTs > 0 && existingTs >= c.ts) {
43
+ continue;
44
+ }
45
+ entries[c.storageJid] = {
46
+ ...existingEntry,
47
+ token: c.token,
48
+ timestamp: String(c.ts),
49
+ ...(c.senderTs !== undefined ? { senderTimestamp: c.senderTs } : {})
50
+ };
30
51
  }
31
- if (message.key.participant) {
52
+ if (Object.keys(entries).length) {
53
+ logger?.debug({ count: Object.keys(entries).length }, 'storing tctokens from history sync');
32
54
  try {
33
- message.key.participant = (0, WABinary_1.jidNormalizedUser)(message.key.participant);
55
+ // Include updated __index so cross-session pruning picks these JIDs up.
56
+ const indexWrite = await buildMergedTcTokenIndexWrite(keyStore, Object.keys(entries));
57
+ await keyStore.set({ tctoken: { ...entries, ...indexWrite } });
34
58
  }
35
- catch (_e) {
36
- // ignore if can't normalize participant
59
+ catch (err) {
60
+ logger?.warn({ err }, 'failed to store tctokens from history sync');
37
61
  }
38
62
  }
39
- const content = (0, messages_1.normalizeMessageContent)(message.message);
63
+ }
64
+ /** Cleans a received message to further processing */
65
+ export const cleanMessage = (message, meId, meLid) => {
66
+ // ensure remoteJid and participant doesn't have device or agent in it
67
+ if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
68
+ message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
69
+ }
70
+ else {
71
+ message.key.remoteJid = jidNormalizedUser(message.key.remoteJid);
72
+ }
73
+ if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
74
+ message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? 's.whatsapp.net' : 'lid');
75
+ }
76
+ else {
77
+ message.key.participant = jidNormalizedUser(message.key.participant);
78
+ }
79
+ const content = normalizeMessageContent(message.message);
40
80
  // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
41
- if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
81
+ if (content?.reactionMessage) {
42
82
  normaliseKey(content.reactionMessage.key);
43
83
  }
44
- if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
84
+ if (content?.pollUpdateMessage) {
45
85
  normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
46
86
  }
47
87
  function normaliseKey(msgKey) {
@@ -51,138 +91,167 @@ const cleanMessage = (message, meId) => {
51
91
  // if the sender believed the message being reacted to is not from them
52
92
  // we've to correct the key to be from them, or some other participant
53
93
  msgKey.fromMe = !msgKey.fromMe
54
- ? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId)
55
- // if the message being reacted to, was from them
56
- // fromMe automatically becomes false
57
- : false;
94
+ ? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
95
+ areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
96
+ : // if the message being reacted to, was from them
97
+ // fromMe automatically becomes false
98
+ false;
58
99
  // set the remoteJid to being the same as the chat the message came from
100
+ // TODO: investigate inconsistencies
59
101
  msgKey.remoteJid = message.key.remoteJid;
60
102
  // set participant of the message
61
103
  msgKey.participant = msgKey.participant || message.key.participant;
62
104
  }
63
105
  }
64
106
  };
65
- exports.cleanMessage = cleanMessage;
66
- const isRealMessage = (message, meId) => {
67
- var _a;
68
- const normalizedContent = (0, messages_1.normalizeMessageContent)(message.message);
69
- const hasSomeContent = !!(0, messages_1.getContentType)(normalizedContent);
70
- return (!!normalizedContent
71
- || REAL_MSG_STUB_TYPES.has(message.messageStubType)
72
- || (REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)
73
- && ((_a = message.messageStubParameters) === null || _a === void 0 ? void 0 : _a.some(p => (0, WABinary_1.areJidsSameUser)(meId, p)))))
74
- && hasSomeContent
75
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage)
76
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.reactionMessage)
77
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.pollUpdateMessage);
107
+ // TODO: target:audit AUDIT THIS FUNCTION AGAIN
108
+ export const isRealMessage = (message) => {
109
+ const normalizedContent = normalizeMessageContent(message.message);
110
+ const hasSomeContent = !!getContentType(normalizedContent);
111
+ return ((!!normalizedContent ||
112
+ REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
113
+ REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
114
+ hasSomeContent &&
115
+ !normalizedContent?.protocolMessage &&
116
+ !normalizedContent?.reactionMessage &&
117
+ !normalizedContent?.pollUpdateMessage);
78
118
  };
79
- exports.isRealMessage = isRealMessage;
80
- const shouldIncrementChatUnread = (message) => (!message.key.fromMe && !message.messageStubType);
81
- exports.shouldIncrementChatUnread = shouldIncrementChatUnread;
119
+ export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
82
120
  /**
83
121
  * Get the ID of the chat from the given key.
84
122
  * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
85
123
  */
86
- const getChatId = ({ remoteJid, participant, fromMe }) => {
87
- if ((0, WABinary_1.isJidBroadcast)(remoteJid)
88
- && !(0, WABinary_1.isJidStatusBroadcast)(remoteJid)
89
- && !fromMe) {
124
+ export const getChatId = ({ remoteJid, participant, fromMe }) => {
125
+ if (!remoteJid) {
126
+ throw new Boom('Cannot derive chat id: message key is missing remoteJid', {
127
+ data: { remoteJid, participant, fromMe }
128
+ });
129
+ }
130
+ if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
131
+ if (!participant) {
132
+ throw new Boom('Cannot derive chat id: broadcast message key is missing participant', {
133
+ data: { remoteJid, fromMe }
134
+ });
135
+ }
90
136
  return participant;
91
137
  }
92
138
  return remoteJid;
93
139
  };
94
- exports.getChatId = getChatId;
95
140
  /**
96
141
  * Decrypt a poll vote
97
142
  * @param vote encrypted vote
98
143
  * @param ctx additional info about the poll required for decryption
99
144
  * @returns list of SHA256 options
100
145
  */
101
- // 🔧 REPARADO: Agregado try-catch completo
102
- function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }) {
103
- try {
104
- // Validar que tenemos todos los datos necesarios
105
- if (!encPayload || !encIv || !pollEncKey) {
106
- return null;
107
- }
108
-
109
- const sign = Buffer.concat([
110
- toBinary(pollMsgId),
111
- toBinary(pollCreatorJid),
112
- toBinary(voterJid),
113
- toBinary('Poll Vote'),
114
- new Uint8Array([1])
115
- ]);
116
- const key0 = (0, crypto_1.hmacSign)(pollEncKey, new Uint8Array(32), 'sha256');
117
- const decKey = (0, crypto_1.hmacSign)(sign, key0, 'sha256');
118
- const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
119
- const decrypted = (0, crypto_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
120
- return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted);
121
- } catch (err) {
122
- // Silenciar errores de desencriptación de polls - no son críticos
123
- return null;
146
+ export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
147
+ const sign = Buffer.concat([
148
+ toBinary(pollMsgId),
149
+ toBinary(pollCreatorJid),
150
+ toBinary(voterJid),
151
+ toBinary('Poll Vote'),
152
+ new Uint8Array([1])
153
+ ]);
154
+ const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256');
155
+ const decKey = hmacSign(sign, key0, 'sha256');
156
+ const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
157
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
158
+ return proto.Message.PollVoteMessage.decode(decrypted);
159
+ function toBinary(txt) {
160
+ return Buffer.from(txt);
124
161
  }
125
-
162
+ }
163
+ /**
164
+ * Decrypt an event response
165
+ * @param response encrypted event response
166
+ * @param ctx additional info about the event required for decryption
167
+ * @returns event response message
168
+ */
169
+ export function decryptEventResponse({ encPayload, encIv }, { eventCreatorJid, eventMsgId, eventEncKey, responderJid }) {
170
+ const sign = Buffer.concat([
171
+ toBinary(eventMsgId),
172
+ toBinary(eventCreatorJid),
173
+ toBinary(responderJid),
174
+ toBinary('Event Response'),
175
+ new Uint8Array([1])
176
+ ]);
177
+ const key0 = hmacSign(eventEncKey, new Uint8Array(32), 'sha256');
178
+ const decKey = hmacSign(sign, key0, 'sha256');
179
+ const aad = toBinary(`${eventMsgId}\u0000${responderJid}`);
180
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
181
+ return proto.Message.EventResponseMessage.decode(decrypted);
126
182
  function toBinary(txt) {
127
183
  return Buffer.from(txt);
128
184
  }
129
185
  }
130
- const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
131
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
186
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options, getMessage }) => {
132
187
  const meId = creds.me.id;
133
188
  const { accountSettings } = creds;
134
- const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
135
- const isRealMsg = (0, exports.isRealMessage)(message, meId);
189
+ const chat = { id: jidNormalizedUser(getChatId(message.key)) };
190
+ const isRealMsg = isRealMessage(message);
136
191
  if (isRealMsg) {
137
192
  chat.messages = [{ message }];
138
- chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
193
+ chat.conversationTimestamp = toNumber(message.messageTimestamp);
139
194
  // only increment unread count if not CIPHERTEXT and from another person
140
- if ((0, exports.shouldIncrementChatUnread)(message)) {
195
+ if (shouldIncrementChatUnread(message)) {
141
196
  chat.unreadCount = (chat.unreadCount || 0) + 1;
142
197
  }
143
198
  }
144
- const content = (0, messages_1.normalizeMessageContent)(message.message);
145
- const senderId = message.key.participant || message.key.remoteJid;
146
- if ((0, WABinary_1.isLidUser)(senderId)) {
147
- const jid = (0, WABinary_1.lidToJid)(senderId);
148
- if (message.key.participant) {
149
- message.key.participant = jid;
150
- }
151
- else {
152
- message.key.remoteJid = jid;
153
- }
154
- }
155
- const mJids = content && content.contextInfo && content.contextInfo.mentionedJid ? content.contextInfo.mentionedJid : [];
156
- for (let i = 0; i < mJids.length; i++) {
157
- if ((0, WABinary_1.isLidUser)(mJids[i])) {
158
- mJids[i] = (0, WABinary_1.lidToJid)(mJids[i]);
159
- }
160
- }
161
- if (content && content.contextInfo && content.contextInfo.participant && (0, WABinary_1.isLidUser)(content.contextInfo.participant)) {
162
- content.contextInfo.participant = (0, WABinary_1.lidToJid)(content.contextInfo.participant);
163
- }
199
+ const content = normalizeMessageContent(message.message);
164
200
  // unarchive chat if it's a real message, or someone reacted to our message
165
201
  // and we've the unarchive chats setting on
166
- if ((isRealMsg || ((_b = (_a = content === null || content === void 0 ? void 0 : content.reactionMessage) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.fromMe))
167
- && (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
202
+ if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
168
203
  chat.archived = false;
169
204
  chat.readOnly = false;
170
205
  }
171
- const protocolMsg = content === null || content === void 0 ? void 0 : content.protocolMessage;
206
+ const protocolMsg = content?.protocolMessage;
172
207
  if (protocolMsg) {
208
+ // Mirror whatsmeow's `handleProtocolMessage` guard, but applied only to
209
+ // the protocol message types that originate from our own device — an
210
+ // attacker could otherwise spoof any of these to manipulate local state.
211
+ //
212
+ // Self-only types (drop if `!fromMe`):
213
+ // - HISTORY_SYNC_NOTIFICATION (our phone driving history sync)
214
+ // - APP_STATE_SYNC_KEY_SHARE (key share between our devices)
215
+ // - LID_MIGRATION_MAPPING_SYNC (server-initiated via our phone)
216
+ // - PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE (response from our phone to our PDO request)
217
+ //
218
+ // Cross-user types (must NOT be dropped — legitimately arrive from others):
219
+ // - REVOKE
220
+ // - MESSAGE_EDIT
221
+ // - EPHEMERAL_SETTING
222
+ // - GROUP_MEMBER_LABEL_CHANGE
223
+ //
224
+ // See https://github.com/tulir/whatsmeow/blob/8d3700152a/message.go#L842-L845
225
+ // for the reference architecture — whatsmeow's `handleProtocolMessage`
226
+ // only contains self-only types because edits are unwrapped from
227
+ // `EditedMessage` BEFORE this dispatch and revokes aren't routed here.
228
+ const SELF_ONLY_TYPES = new Set([
229
+ proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION,
230
+ proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE,
231
+ proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC,
232
+ proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE
233
+ ]);
234
+ if (protocolMsg.type !== null &&
235
+ protocolMsg.type !== undefined &&
236
+ SELF_ONLY_TYPES.has(protocolMsg.type) &&
237
+ !message.key.fromMe) {
238
+ logger?.warn({ msgId: message.key.id, type: protocolMsg.type, from: message.key.participant || message.key.remoteJid }, 'dropping spoofed self-only protocolMessage from non-self origin');
239
+ return;
240
+ }
173
241
  switch (protocolMsg.type) {
174
- case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
242
+ case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
175
243
  const histNotification = protocolMsg.historySyncNotification;
176
244
  const process = shouldProcessHistoryMsg;
177
- const isLatest = !((_c = creds.processedHistoryMessages) === null || _c === void 0 ? void 0 : _c.length);
178
- logger === null || logger === void 0 ? void 0 : logger.info({
245
+ const isLatest = !creds.processedHistoryMessages?.length;
246
+ logger?.info({
179
247
  histNotification,
180
248
  process,
181
249
  id: message.key.id,
182
- isLatest,
250
+ isLatest
183
251
  }, 'got history notification');
184
252
  if (process) {
185
- if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
253
+ // TODO: investigate
254
+ if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
186
255
  ev.emit('creds.update', {
187
256
  processedHistoryMessages: [
188
257
  ...(creds.processedHistoryMessages || []),
@@ -190,19 +259,25 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
190
259
  ]
191
260
  });
192
261
  }
193
- const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
262
+ const data = await downloadAndProcessHistorySyncNotification(histNotification, options, logger);
263
+ if (data.lidPnMappings?.length) {
264
+ logger?.debug({ count: data.lidPnMappings.length }, 'processing LID-PN mappings from history sync');
265
+ await signalRepository.lidMapping
266
+ .storeLIDPNMappings(data.lidPnMappings)
267
+ .catch(err => logger?.warn({ err }, 'failed to store LID-PN mappings from history sync'));
268
+ }
269
+ await storeTcTokensFromHistorySync(data.chats, signalRepository, keyStore, logger);
194
270
  ev.emit('messaging-history.set', {
195
271
  ...data,
196
- isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
197
- ? isLatest
198
- : undefined,
272
+ isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
273
+ chunkOrder: histNotification.chunkOrder,
199
274
  peerDataRequestSessionId: histNotification.peerDataRequestSessionId
200
275
  });
201
276
  }
202
277
  break;
203
- case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
278
+ case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
204
279
  const keys = protocolMsg.appStateSyncKeyShare.keys;
205
- if (keys === null || keys === void 0 ? void 0 : keys.length) {
280
+ if (keys?.length) {
206
281
  let newAppStateSyncKeyId = '';
207
282
  await keyStore.transaction(async () => {
208
283
  const newKeys = [];
@@ -212,57 +287,85 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
212
287
  await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
213
288
  newAppStateSyncKeyId = strKeyId;
214
289
  }
215
- logger === null || logger === void 0 ? void 0 : logger.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
216
- });
290
+ logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
291
+ }, meId);
217
292
  ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
218
293
  }
219
294
  else {
220
- logger === null || logger === void 0 ? void 0 : logger.info({ protocolMsg }, 'recv app state sync with 0 keys');
295
+ logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
221
296
  }
222
297
  break;
223
- case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
298
+ case proto.Message.ProtocolMessage.Type.REVOKE:
224
299
  ev.emit('messages.update', [
225
300
  {
226
301
  key: {
227
302
  ...message.key,
228
303
  id: protocolMsg.key.id
229
304
  },
230
- update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
305
+ update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
231
306
  }
232
307
  ]);
233
308
  break;
234
- case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
309
+ case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
235
310
  Object.assign(chat, {
236
- ephemeralSettingTimestamp: (0, generics_1.toNumber)(message.messageTimestamp),
311
+ ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
237
312
  ephemeralExpiration: protocolMsg.ephemeralExpiration || null
238
313
  });
239
314
  break;
240
- case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
315
+ case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
241
316
  const response = protocolMsg.peerDataOperationRequestResponseMessage;
242
317
  if (response) {
243
- placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
244
318
  // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
245
- const { peerDataOperationResult } = response;
319
+ const peerDataOperationResult = response.peerDataOperationResult || [];
246
320
  for (const result of peerDataOperationResult) {
247
- const { placeholderMessageResendResponse: retryResponse } = result;
248
- if (retryResponse) {
249
- const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
250
- // wait till another upsert event is available, don't want it to be part of the PDO response message
251
- setTimeout(() => {
252
- ev.emit('messages.upsert', {
253
- messages: [webMessageInfo],
254
- type: 'notify',
255
- requestId: response.stanzaId
256
- });
257
- }, 500);
321
+ const retryResponse = result?.placeholderMessageResendResponse;
322
+ //eslint-disable-next-line max-depth
323
+ if (!retryResponse?.webMessageInfoBytes) {
324
+ continue;
325
+ }
326
+ //eslint-disable-next-line max-depth
327
+ try {
328
+ const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
329
+ const msgId = webMessageInfo.key?.id;
330
+ // Retrieve cached original message data (preserves LID details,
331
+ // timestamps, etc. that the phone may omit in its PDO response)
332
+ const cachedData = msgId ? await placeholderResendCache?.get(msgId) : undefined;
333
+ //eslint-disable-next-line max-depth
334
+ if (msgId) {
335
+ await placeholderResendCache?.del(msgId);
336
+ }
337
+ let finalMsg;
338
+ //eslint-disable-next-line max-depth
339
+ if (cachedData && typeof cachedData === 'object') {
340
+ // Apply decoded message content onto cached metadata (preserves LID etc.)
341
+ cachedData.message = webMessageInfo.message;
342
+ //eslint-disable-next-line max-depth
343
+ if (webMessageInfo.messageTimestamp) {
344
+ cachedData.messageTimestamp = webMessageInfo.messageTimestamp;
345
+ }
346
+ finalMsg = cachedData;
347
+ }
348
+ else {
349
+ finalMsg = webMessageInfo;
350
+ }
351
+ logger?.debug({ msgId, requestId: response.stanzaId }, 'received placeholder resend');
352
+ ev.emit('messages.upsert', {
353
+ messages: [finalMsg],
354
+ type: 'notify',
355
+ requestId: response.stanzaId
356
+ });
357
+ }
358
+ catch (err) {
359
+ logger?.warn({ err, stanzaId: response.stanzaId }, 'failed to decode placeholder resend response');
258
360
  }
259
361
  }
260
362
  }
261
- case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
363
+ break;
364
+ case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
262
365
  ev.emit('messages.update', [
263
366
  {
264
367
  // flip the sender / fromMe properties because they're in the perspective of the sender
265
- key: { ...message.key, id: (_d = protocolMsg.key) === null || _d === void 0 ? void 0 : _d.id },
368
+ key: { ...message.key, id: protocolMsg.key?.id },
266
369
  update: {
267
370
  message: {
268
371
  editedMessage: {
@@ -270,153 +373,258 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
270
373
  }
271
374
  },
272
375
  messageTimestamp: protocolMsg.timestampMs
273
- ? Math.floor((0, generics_1.toNumber)(protocolMsg.timestampMs) / 1000)
376
+ ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
274
377
  : message.messageTimestamp
275
378
  }
276
379
  }
277
380
  ]);
278
381
  break;
382
+ case proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE:
383
+ const labelAssociationMsg = protocolMsg.memberLabel;
384
+ if (labelAssociationMsg?.label) {
385
+ ev.emit('group.member-tag.update', {
386
+ groupId: chat.id,
387
+ label: labelAssociationMsg.label,
388
+ participant: message.key.participant,
389
+ participantAlt: message.key.participantAlt,
390
+ messageTimestamp: Number(message.messageTimestamp)
391
+ });
392
+ }
393
+ break;
394
+ case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
395
+ const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
396
+ const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
397
+ logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
398
+ const pairs = [];
399
+ for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
400
+ const lid = latestLid || assignedLid;
401
+ pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
402
+ }
403
+ await signalRepository.lidMapping.storeLIDPNMappings(pairs);
404
+ if (pairs.length) {
405
+ for (const { pn, lid } of pairs) {
406
+ await signalRepository.migrateSession(pn, lid);
407
+ }
408
+ }
279
409
  }
280
410
  }
281
- else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
411
+ else if (content?.reactionMessage) {
282
412
  const reaction = {
283
413
  ...content.reactionMessage,
284
- key: message.key,
414
+ key: message.key
285
415
  };
286
- ev.emit('messages.reaction', [{
416
+ ev.emit('messages.reaction', [
417
+ {
287
418
  reaction,
288
- key: (_e = content.reactionMessage) === null || _e === void 0 ? void 0 : _e.key,
289
- }]);
419
+ key: content.reactionMessage?.key
420
+ }
421
+ ]);
422
+ }
423
+ else if (content?.encEventResponseMessage) {
424
+ const encEventResponse = content.encEventResponseMessage;
425
+ const creationMsgKey = encEventResponse.eventCreationMessageKey;
426
+ // we need to fetch the event creation message to get the event enc key
427
+ const eventMsg = await getMessage(creationMsgKey);
428
+ if (eventMsg) {
429
+ try {
430
+ const meIdNormalised = jidNormalizedUser(meId);
431
+ // all jids need to be PN
432
+ const eventCreatorKey = creationMsgKey.participant || creationMsgKey.remoteJid;
433
+ const eventCreatorPn = isLidUser(eventCreatorKey)
434
+ ? await signalRepository.lidMapping.getPNForLID(eventCreatorKey)
435
+ : eventCreatorKey;
436
+ const eventCreatorJid = getKeyAuthor({ remoteJid: jidNormalizedUser(eventCreatorPn), fromMe: meIdNormalised === eventCreatorPn }, meIdNormalised);
437
+ const responderJid = getKeyAuthor(message.key, meIdNormalised);
438
+ const eventEncKey = eventMsg?.messageContextInfo?.messageSecret;
439
+ if (!eventEncKey) {
440
+ logger?.warn({ creationMsgKey }, 'event response: missing messageSecret for decryption');
441
+ }
442
+ else {
443
+ const responseMsg = decryptEventResponse(encEventResponse, {
444
+ eventEncKey,
445
+ eventCreatorJid,
446
+ eventMsgId: creationMsgKey.id,
447
+ responderJid
448
+ });
449
+ const eventResponse = {
450
+ eventResponseMessageKey: message.key,
451
+ senderTimestampMs: responseMsg.timestampMs,
452
+ response: responseMsg
453
+ };
454
+ ev.emit('messages.update', [
455
+ {
456
+ key: creationMsgKey,
457
+ update: {
458
+ eventResponses: [eventResponse]
459
+ }
460
+ }
461
+ ]);
462
+ }
463
+ }
464
+ catch (err) {
465
+ logger?.warn({ err, creationMsgKey }, 'failed to decrypt event response');
466
+ }
467
+ }
468
+ else {
469
+ logger?.warn({ creationMsgKey }, 'event creation message not found, cannot decrypt response');
470
+ }
290
471
  }
291
472
  else if (message.messageStubType) {
292
- const jid = (_f = message.key) === null || _f === void 0 ? void 0 : _f.remoteJid;
473
+ const jid = message.key?.remoteJid;
293
474
  //let actor = whatsappID (message.participant)
294
475
  let participants;
295
- const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
476
+ const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
477
+ id: jid,
478
+ author: message.key.participant,
479
+ authorPn: message.key.participantAlt,
480
+ authorUsername: message.key.participantUsername,
481
+ participants,
482
+ action
483
+ });
296
484
  const emitGroupUpdate = (update) => {
297
- var _a;
298
- ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
485
+ ev.emit('groups.update', [
486
+ {
487
+ id: jid,
488
+ ...update,
489
+ author: message.key.participant ?? undefined,
490
+ authorPn: message.key.participantAlt,
491
+ authorUsername: message.key.participantUsername
492
+ }
493
+ ]);
299
494
  };
300
495
  const emitGroupRequestJoin = (participant, action, method) => {
301
- ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method });
496
+ ev.emit('group.join-request', {
497
+ id: jid,
498
+ author: message.key.participant,
499
+ authorPn: message.key.participantAlt,
500
+ authorUsername: message.key.participantUsername,
501
+ participant: participant.lid,
502
+ participantPn: participant.pn,
503
+ action,
504
+ method: method
505
+ });
302
506
  };
303
- const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
507
+ const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber)); // ADD SUPPORT FOR LID
304
508
  switch (message.messageStubType) {
305
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
306
- participants = message.messageStubParameters || [];
509
+ case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
510
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
307
511
  emitParticipantsUpdate('modify');
308
512
  break;
309
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
310
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
311
- participants = message.messageStubParameters || [];
513
+ case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
514
+ case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
515
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
312
516
  emitParticipantsUpdate('remove');
313
517
  // mark the chat read only if you left the group
314
518
  if (participantsIncludesMe()) {
315
519
  chat.readOnly = true;
316
520
  }
317
521
  break;
318
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
319
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
320
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
321
- participants = message.messageStubParameters || [];
522
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD:
523
+ case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
524
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
525
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
322
526
  if (participantsIncludesMe()) {
323
527
  chat.readOnly = false;
324
528
  }
325
529
  emitParticipantsUpdate('add');
326
530
  break;
327
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
328
- participants = message.messageStubParameters || [];
531
+ case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
532
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
329
533
  emitParticipantsUpdate('demote');
330
534
  break;
331
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
332
- participants = message.messageStubParameters || [];
535
+ case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
536
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
333
537
  emitParticipantsUpdate('promote');
334
538
  break;
335
- case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
336
- const announceValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
539
+ case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
540
+ const announceValue = message.messageStubParameters?.[0];
337
541
  emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
338
542
  break;
339
- case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
340
- const restrictValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
543
+ case WAMessageStubType.GROUP_CHANGE_RESTRICT:
544
+ const restrictValue = message.messageStubParameters?.[0];
341
545
  emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
342
546
  break;
343
- case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
344
- const name = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
547
+ case WAMessageStubType.GROUP_CHANGE_SUBJECT:
548
+ const name = message.messageStubParameters?.[0];
345
549
  chat.name = name;
346
550
  emitGroupUpdate({ subject: name });
347
551
  break;
348
- case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
349
- const description = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
552
+ case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
553
+ const description = message.messageStubParameters?.[0];
350
554
  chat.description = description;
351
555
  emitGroupUpdate({ desc: description });
352
556
  break;
353
- case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
354
- const code = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
557
+ case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
558
+ const code = message.messageStubParameters?.[0];
355
559
  emitGroupUpdate({ inviteCode: code });
356
560
  break;
357
- case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
358
- const memberAddValue = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
561
+ case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
562
+ const memberAddValue = message.messageStubParameters?.[0];
359
563
  emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
360
564
  break;
361
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
362
- const approvalMode = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
565
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
566
+ const approvalMode = message.messageStubParameters?.[0];
363
567
  emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
364
568
  break;
365
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
366
- const participant = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[0];
367
- const action = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[1];
368
- const method = (_r = message.messageStubParameters) === null || _r === void 0 ? void 0 : _r[2];
569
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
570
+ const participant = JSON.parse(message.messageStubParameters?.[0]);
571
+ const action = message.messageStubParameters?.[1];
572
+ const method = message.messageStubParameters?.[2];
369
573
  emitGroupRequestJoin(participant, action, method);
370
574
  break;
371
575
  }
372
- }
373
- else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
374
- const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey;
576
+ } /* else if(content?.pollUpdateMessage) {
577
+ const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey!
375
578
  // we need to fetch the poll creation message to get the poll enc key
376
- const pollMsg = await getMessage(creationMsgKey);
377
- if (pollMsg) {
378
- const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
379
- const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
380
- const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
381
- const pollEncKey = (_s = pollMsg.messageContextInfo) === null || _s === void 0 ? void 0 : _s.messageSecret;
382
-
383
- // 🔧 REPARADO: Manejo seguro de decryptPollVote
579
+ // TODO: make standalone, remove getMessage reference
580
+ // TODO: Remove entirely
581
+ const pollMsg = await getMessage(creationMsgKey)
582
+ if(pollMsg) {
583
+ const meIdNormalised = jidNormalizedUser(meId)
584
+ const pollCreatorJid = getKeyAuthor(creationMsgKey, meIdNormalised)
585
+ const voterJid = getKeyAuthor(message.key, meIdNormalised)
586
+ const pollEncKey = pollMsg.messageContextInfo?.messageSecret!
587
+
384
588
  try {
385
- const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
386
- pollEncKey,
387
- pollCreatorJid,
388
- pollMsgId: creationMsgKey.id,
389
- voterJid,
390
- });
391
-
392
- // Solo emitir si se desencriptó correctamente
393
- if (voteMsg) {
394
- ev.emit('messages.update', [
395
- {
396
- key: creationMsgKey,
397
- update: {
398
- pollUpdates: [
399
- {
400
- pollUpdateMessageKey: message.key,
401
- vote: voteMsg,
402
- senderTimestampMs: content.pollUpdateMessage.senderTimestampMs.toNumber(),
403
- }
404
- ]
405
- }
589
+ const voteMsg = decryptPollVote(
590
+ content.pollUpdateMessage.vote!,
591
+ {
592
+ pollEncKey,
593
+ pollCreatorJid,
594
+ pollMsgId: creationMsgKey.id!,
595
+ voterJid,
596
+ }
597
+ )
598
+ ev.emit('messages.update', [
599
+ {
600
+ key: creationMsgKey,
601
+ update: {
602
+ pollUpdates: [
603
+ {
604
+ pollUpdateMessageKey: message.key,
605
+ vote: voteMsg,
606
+ senderTimestampMs: (content.pollUpdateMessage.senderTimestampMs! as Long).toNumber(),
607
+ }
608
+ ]
406
609
  }
407
- ]);
408
- }
409
- }
410
- catch (err) {
411
- logger === null || logger === void 0 ? void 0 : logger.warn({ err, creationMsgKey }, 'failed to decrypt poll vote');
610
+ }
611
+ ])
612
+ } catch(err) {
613
+ logger?.warn(
614
+ { err, creationMsgKey },
615
+ 'failed to decrypt poll vote'
616
+ )
412
617
  }
618
+ } else {
619
+ logger?.warn(
620
+ { creationMsgKey },
621
+ 'poll creation message not found, cannot decrypt update'
622
+ )
413
623
  }
414
- else {
415
- logger === null || logger === void 0 ? void 0 : logger.warn({ creationMsgKey }, 'poll creation message not found, cannot decrypt update');
416
- }
417
- }
624
+ } */
418
625
  if (Object.keys(chat).length > 1) {
419
626
  ev.emit('chats.update', [chat]);
420
627
  }
421
628
  };
422
- exports.default = processMessage;
629
+ export default processMessage;
630
+ //# sourceMappingURL=process-message.js.map