@neelegirl/baileys 1.5.2 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (419) hide show
  1. package/README.md +26 -18
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +291 -665
  4. package/WAProto/fix-imports.js +29 -0
  5. package/WAProto/index.d.ts +2297 -48040
  6. package/WAProto/index.js +45500 -140101
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/index.d.ts +58 -64
  9. package/lib/Defaults/index.d.ts.map +1 -0
  10. package/lib/Defaults/index.js +74 -96
  11. package/lib/Defaults/index.js.map +1 -0
  12. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  14. package/lib/Signal/Group/ciphertext-message.js +12 -0
  15. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  16. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  18. package/lib/Signal/Group/group-session-builder.js +30 -0
  19. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  20. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  21. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  22. package/lib/Signal/Group/group_cipher.js +82 -0
  23. package/lib/Signal/Group/group_cipher.js.map +1 -0
  24. package/lib/Signal/Group/index.d.ts +12 -0
  25. package/lib/Signal/Group/index.d.ts.map +1 -0
  26. package/lib/Signal/Group/index.js +12 -0
  27. package/lib/Signal/Group/index.js.map +1 -0
  28. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  29. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  30. package/lib/Signal/Group/keyhelper.js +18 -0
  31. package/lib/Signal/Group/keyhelper.js.map +1 -0
  32. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  33. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  34. package/lib/Signal/Group/sender-chain-key.js +26 -0
  35. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  36. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  38. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  39. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  40. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  41. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  42. package/lib/Signal/Group/sender-key-message.js +66 -0
  43. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  44. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  45. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  46. package/lib/Signal/Group/sender-key-name.js +48 -0
  47. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  48. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  49. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  50. package/lib/Signal/Group/sender-key-record.js +41 -0
  51. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  52. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  53. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  54. package/lib/Signal/Group/sender-key-state.js +84 -0
  55. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  56. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  57. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  58. package/lib/Signal/{WASignalGroup/sender_message_key.js → Group/sender-message-key.js} +3 -16
  59. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  60. package/lib/Signal/libsignal.d.ts +5 -4
  61. package/lib/Signal/libsignal.d.ts.map +1 -0
  62. package/lib/Signal/libsignal.js +292 -112
  63. package/lib/Signal/libsignal.js.map +1 -0
  64. package/lib/Signal/lid-mapping.d.ts +23 -0
  65. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  66. package/lib/Signal/lid-mapping.js +171 -0
  67. package/lib/Signal/lid-mapping.js.map +1 -0
  68. package/lib/Socket/Client/index.d.ts +3 -2
  69. package/lib/Socket/Client/index.d.ts.map +1 -0
  70. package/lib/Socket/Client/index.js +3 -22
  71. package/lib/Socket/Client/index.js.map +1 -0
  72. package/lib/Socket/Client/types.d.ts +15 -15
  73. package/lib/Socket/Client/types.d.ts.map +1 -0
  74. package/lib/Socket/Client/types.js +8 -15
  75. package/lib/Socket/Client/types.js.map +1 -0
  76. package/lib/Socket/Client/websocket.d.ts +12 -12
  77. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  78. package/lib/Socket/Client/websocket.js +24 -36
  79. package/lib/Socket/Client/websocket.js.map +1 -0
  80. package/lib/Socket/business.d.ts +178 -177
  81. package/lib/Socket/business.d.ts.map +1 -0
  82. package/lib/Socket/business.js +179 -71
  83. package/lib/Socket/business.js.map +1 -0
  84. package/lib/Socket/chats.d.ts +93 -93
  85. package/lib/Socket/chats.d.ts.map +1 -0
  86. package/lib/Socket/chats.js +474 -625
  87. package/lib/Socket/chats.js.map +1 -0
  88. package/lib/Socket/communities.d.ts +83 -62
  89. package/lib/Socket/communities.d.ts.map +1 -0
  90. package/lib/Socket/communities.js +412 -414
  91. package/lib/Socket/communities.js.map +1 -0
  92. package/lib/Socket/groups.d.ts +118 -112
  93. package/lib/Socket/groups.d.ts.map +1 -0
  94. package/lib/Socket/groups.js +146 -171
  95. package/lib/Socket/groups.js.map +1 -0
  96. package/lib/Socket/index.d.ts +222 -182
  97. package/lib/Socket/index.d.ts.map +1 -0
  98. package/lib/Socket/index.js +12 -17
  99. package/lib/Socket/index.js.map +1 -0
  100. package/lib/Socket/messages-recv.d.ts +165 -169
  101. package/lib/Socket/messages-recv.d.ts.map +1 -0
  102. package/lib/Socket/messages-recv.js +1185 -1721
  103. package/lib/Socket/messages-recv.js.map +1 -0
  104. package/lib/Socket/messages-send.d.ts +161 -159
  105. package/lib/Socket/messages-send.d.ts.map +1 -0
  106. package/lib/Socket/messages-send.js +650 -991
  107. package/lib/Socket/messages-send.js.map +1 -0
  108. package/lib/Socket/mex.d.ts +1 -0
  109. package/lib/Socket/mex.d.ts.map +1 -0
  110. package/lib/Socket/mex.js +4 -9
  111. package/lib/Socket/mex.js.map +1 -0
  112. package/lib/Socket/newsletter.d.ts +139 -139
  113. package/lib/Socket/newsletter.d.ts.map +1 -0
  114. package/lib/Socket/newsletter.js +153 -258
  115. package/lib/Socket/newsletter.js.map +1 -0
  116. package/lib/Socket/socket.d.ts +42 -36
  117. package/lib/Socket/socket.d.ts.map +1 -0
  118. package/lib/Socket/socket.js +623 -507
  119. package/lib/Socket/socket.js.map +1 -0
  120. package/lib/Types/Auth.d.ts +87 -96
  121. package/lib/Types/Auth.d.ts.map +1 -0
  122. package/lib/Types/Auth.js +2 -3
  123. package/lib/Types/Auth.js.map +1 -0
  124. package/lib/Types/Bussines.d.ts +25 -0
  125. package/lib/Types/Bussines.d.ts.map +1 -0
  126. package/lib/Types/Bussines.js +2 -0
  127. package/lib/Types/Bussines.js.map +1 -0
  128. package/lib/Types/Call.d.ts +13 -13
  129. package/lib/Types/Call.d.ts.map +1 -0
  130. package/lib/Types/Call.js +2 -3
  131. package/lib/Types/Call.js.map +1 -0
  132. package/lib/Types/Chat.d.ts +79 -94
  133. package/lib/Types/Chat.d.ts.map +1 -0
  134. package/lib/Types/Chat.js +8 -9
  135. package/lib/Types/Chat.js.map +1 -0
  136. package/lib/Types/Contact.d.ts +13 -9
  137. package/lib/Types/Contact.d.ts.map +1 -0
  138. package/lib/Types/Contact.js +2 -3
  139. package/lib/Types/Contact.js.map +1 -0
  140. package/lib/Types/Events.d.ts +152 -179
  141. package/lib/Types/Events.d.ts.map +1 -0
  142. package/lib/Types/Events.js +2 -3
  143. package/lib/Types/Events.js.map +1 -0
  144. package/lib/Types/GroupMetadata.d.ts +49 -48
  145. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  146. package/lib/Types/GroupMetadata.js +2 -3
  147. package/lib/Types/GroupMetadata.js.map +1 -0
  148. package/lib/Types/Label.d.ts +13 -14
  149. package/lib/Types/Label.d.ts.map +1 -0
  150. package/lib/Types/Label.js +24 -30
  151. package/lib/Types/Label.js.map +1 -0
  152. package/lib/Types/LabelAssociation.d.ts +15 -20
  153. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  154. package/lib/Types/LabelAssociation.js +6 -12
  155. package/lib/Types/LabelAssociation.js.map +1 -0
  156. package/lib/Types/Message.d.ts +234 -404
  157. package/lib/Types/Message.d.ts.map +1 -0
  158. package/lib/Types/Message.js +11 -13
  159. package/lib/Types/Message.js.map +1 -0
  160. package/lib/Types/Newsletter.d.ts +130 -104
  161. package/lib/Types/Newsletter.d.ts.map +1 -0
  162. package/lib/Types/Newsletter.js +31 -40
  163. package/lib/Types/Newsletter.js.map +1 -0
  164. package/lib/Types/Product.d.ts +58 -71
  165. package/lib/Types/Product.d.ts.map +1 -0
  166. package/lib/Types/Product.js +2 -3
  167. package/lib/Types/Product.js.map +1 -0
  168. package/lib/Types/Signal.d.ts +63 -55
  169. package/lib/Types/Signal.d.ts.map +1 -0
  170. package/lib/Types/Signal.js +2 -3
  171. package/lib/Types/Signal.js.map +1 -0
  172. package/lib/Types/Socket.d.ts +78 -65
  173. package/lib/Types/Socket.d.ts.map +1 -0
  174. package/lib/Types/Socket.js +3 -3
  175. package/lib/Types/Socket.js.map +1 -0
  176. package/lib/Types/State.d.ts +17 -19
  177. package/lib/Types/State.d.ts.map +1 -0
  178. package/lib/Types/State.js +13 -14
  179. package/lib/Types/State.js.map +1 -0
  180. package/lib/Types/USync.d.ts +8 -8
  181. package/lib/Types/USync.d.ts.map +1 -0
  182. package/lib/Types/USync.js +2 -3
  183. package/lib/Types/USync.js.map +1 -0
  184. package/lib/Types/index.d.ts +47 -61
  185. package/lib/Types/index.d.ts.map +1 -0
  186. package/lib/Types/index.js +26 -48
  187. package/lib/Types/index.js.map +1 -0
  188. package/lib/Utils/auth-utils.d.ts +8 -10
  189. package/lib/Utils/auth-utils.d.ts.map +1 -0
  190. package/lib/Utils/auth-utils.js +206 -154
  191. package/lib/Utils/auth-utils.js.map +1 -0
  192. package/lib/Utils/baileys-event-stream.d.ts +6 -7
  193. package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
  194. package/lib/Utils/baileys-event-stream.js +29 -43
  195. package/lib/Utils/baileys-event-stream.js.map +1 -0
  196. package/lib/Utils/browser-utils.d.ts +4 -0
  197. package/lib/Utils/browser-utils.d.ts.map +1 -0
  198. package/lib/Utils/browser-utils.js +28 -0
  199. package/lib/Utils/browser-utils.js.map +1 -0
  200. package/lib/Utils/business.d.ts +14 -20
  201. package/lib/Utils/business.d.ts.map +1 -0
  202. package/lib/Utils/business.js +110 -134
  203. package/lib/Utils/business.js.map +1 -0
  204. package/lib/Utils/chat-utils.d.ts +57 -69
  205. package/lib/Utils/chat-utils.d.ts.map +1 -0
  206. package/lib/Utils/chat-utils.js +362 -380
  207. package/lib/Utils/chat-utils.js.map +1 -0
  208. package/lib/Utils/crypto.d.ts +30 -45
  209. package/lib/Utils/crypto.d.ts.map +1 -0
  210. package/lib/Utils/crypto.js +141 -178
  211. package/lib/Utils/crypto.js.map +1 -0
  212. package/lib/Utils/decode-wa-message.d.ts +42 -35
  213. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  214. package/lib/Utils/decode-wa-message.js +176 -150
  215. package/lib/Utils/decode-wa-message.js.map +1 -0
  216. package/lib/Utils/event-buffer.d.ts +12 -17
  217. package/lib/Utils/event-buffer.d.ts.map +1 -0
  218. package/lib/Utils/event-buffer.js +269 -286
  219. package/lib/Utils/event-buffer.js.map +1 -0
  220. package/lib/Utils/generics.d.ts +60 -99
  221. package/lib/Utils/generics.d.ts.map +1 -0
  222. package/lib/Utils/generics.js +244 -487
  223. package/lib/Utils/generics.js.map +1 -0
  224. package/lib/Utils/history.d.ts +18 -22
  225. package/lib/Utils/history.d.ts.map +1 -0
  226. package/lib/Utils/history.js +54 -80
  227. package/lib/Utils/history.js.map +1 -0
  228. package/lib/Utils/index.d.ts +20 -19
  229. package/lib/Utils/index.d.ts.map +1 -0
  230. package/lib/Utils/index.js +19 -39
  231. package/lib/Utils/index.js.map +1 -0
  232. package/lib/Utils/link-preview.d.ts +12 -14
  233. package/lib/Utils/link-preview.d.ts.map +1 -0
  234. package/lib/Utils/link-preview.js +40 -75
  235. package/lib/Utils/link-preview.js.map +1 -0
  236. package/lib/Utils/logger.d.ts +10 -11
  237. package/lib/Utils/logger.d.ts.map +1 -0
  238. package/lib/Utils/logger.js +3 -7
  239. package/lib/Utils/logger.js.map +1 -0
  240. package/lib/Utils/lt-hash.d.ts +12 -13
  241. package/lib/Utils/lt-hash.d.ts.map +1 -0
  242. package/lib/Utils/lt-hash.js +27 -37
  243. package/lib/Utils/lt-hash.js.map +1 -0
  244. package/lib/Utils/make-mutex.d.ts +6 -7
  245. package/lib/Utils/make-mutex.d.ts.map +1 -0
  246. package/lib/Utils/make-mutex.js +20 -29
  247. package/lib/Utils/make-mutex.js.map +1 -0
  248. package/lib/Utils/message-retry-manager.d.ts +82 -0
  249. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  250. package/lib/Utils/message-retry-manager.js +149 -0
  251. package/lib/Utils/message-retry-manager.js.map +1 -0
  252. package/lib/Utils/messages-media.d.ts +87 -102
  253. package/lib/Utils/messages-media.d.ts.map +1 -0
  254. package/lib/Utils/messages-media.js +427 -570
  255. package/lib/Utils/messages-media.js.map +1 -0
  256. package/lib/Utils/messages.d.ts +37 -64
  257. package/lib/Utils/messages.d.ts.map +1 -0
  258. package/lib/Utils/messages.js +511 -1270
  259. package/lib/Utils/messages.js.map +1 -0
  260. package/lib/Utils/noise-handler.d.ts +18 -18
  261. package/lib/Utils/noise-handler.d.ts.map +1 -0
  262. package/lib/Utils/noise-handler.js +101 -109
  263. package/lib/Utils/noise-handler.js.map +1 -0
  264. package/lib/Utils/pre-key-manager.d.ts +28 -0
  265. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  266. package/lib/Utils/pre-key-manager.js +106 -0
  267. package/lib/Utils/pre-key-manager.js.map +1 -0
  268. package/lib/Utils/process-message.d.ts +25 -32
  269. package/lib/Utils/process-message.d.ts.map +1 -0
  270. package/lib/Utils/process-message.js +266 -281
  271. package/lib/Utils/process-message.js.map +1 -0
  272. package/lib/Utils/signal.d.ts +24 -32
  273. package/lib/Utils/signal.d.ts.map +1 -0
  274. package/lib/Utils/signal.js +98 -105
  275. package/lib/Utils/signal.js.map +1 -0
  276. package/lib/Utils/use-multi-file-auth-state.d.ts +5 -10
  277. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  278. package/lib/Utils/use-multi-file-auth-state.js +69 -186
  279. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  280. package/lib/Utils/validate-connection.d.ts +11 -13
  281. package/lib/Utils/validate-connection.d.ts.map +1 -0
  282. package/lib/Utils/validate-connection.js +124 -116
  283. package/lib/Utils/validate-connection.js.map +1 -0
  284. package/lib/WABinary/constants.d.ts +25 -27
  285. package/lib/WABinary/constants.d.ts.map +1 -0
  286. package/lib/WABinary/constants.js +1277 -1292
  287. package/lib/WABinary/constants.js.map +1 -0
  288. package/lib/WABinary/decode.d.ts +7 -9
  289. package/lib/WABinary/decode.d.ts.map +1 -0
  290. package/lib/WABinary/decode.js +139 -189
  291. package/lib/WABinary/decode.js.map +1 -0
  292. package/lib/WABinary/encode.d.ts +3 -3
  293. package/lib/WABinary/encode.d.ts.map +1 -0
  294. package/lib/WABinary/encode.js +105 -154
  295. package/lib/WABinary/encode.js.map +1 -0
  296. package/lib/WABinary/generic-utils.d.ts +14 -27
  297. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  298. package/lib/WABinary/generic-utils.js +62 -102
  299. package/lib/WABinary/generic-utils.js.map +1 -0
  300. package/lib/WABinary/index.d.ts +6 -5
  301. package/lib/WABinary/index.d.ts.map +1 -0
  302. package/lib/WABinary/index.js +6 -25
  303. package/lib/WABinary/index.js.map +1 -0
  304. package/lib/WABinary/jid-utils.d.ts +41 -46
  305. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  306. package/lib/WABinary/jid-utils.js +84 -80
  307. package/lib/WABinary/jid-utils.js.map +1 -0
  308. package/lib/WABinary/types.d.ts +10 -13
  309. package/lib/WABinary/types.d.ts.map +1 -0
  310. package/lib/WABinary/types.js +2 -3
  311. package/lib/WABinary/types.js.map +1 -0
  312. package/lib/WAM/BinaryInfo.d.ts +8 -15
  313. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  314. package/lib/WAM/BinaryInfo.js +7 -14
  315. package/lib/WAM/BinaryInfo.js.map +1 -0
  316. package/lib/WAM/constants.d.ts +30 -37
  317. package/lib/WAM/constants.d.ts.map +1 -0
  318. package/lib/WAM/constants.js +19193 -11711
  319. package/lib/WAM/constants.js.map +1 -0
  320. package/lib/WAM/encode.d.ts +3 -3
  321. package/lib/WAM/encode.d.ts.map +1 -0
  322. package/lib/WAM/encode.js +95 -110
  323. package/lib/WAM/encode.js.map +1 -0
  324. package/lib/WAM/index.d.ts +4 -3
  325. package/lib/WAM/index.d.ts.map +1 -0
  326. package/lib/WAM/index.js +4 -23
  327. package/lib/WAM/index.js.map +1 -0
  328. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  329. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  330. package/lib/WAUSync/Protocols/USyncContactProtocol.js +12 -19
  331. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  332. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +19 -22
  333. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  334. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +18 -26
  335. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  336. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +11 -12
  337. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  338. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -20
  339. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  340. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +11 -12
  341. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  342. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +16 -24
  343. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  344. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  345. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  346. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  347. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  348. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  349. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  350. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  351. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  352. package/lib/WAUSync/Protocols/index.d.ts +5 -6
  353. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  354. package/lib/WAUSync/Protocols/index.js +5 -26
  355. package/lib/WAUSync/Protocols/index.js.map +1 -0
  356. package/lib/WAUSync/USyncQuery.d.ts +26 -28
  357. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  358. package/lib/WAUSync/USyncQuery.js +64 -62
  359. package/lib/WAUSync/USyncQuery.js.map +1 -0
  360. package/lib/WAUSync/USyncUser.d.ts +11 -10
  361. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  362. package/lib/WAUSync/USyncUser.js +12 -19
  363. package/lib/WAUSync/USyncUser.js.map +1 -0
  364. package/lib/WAUSync/index.d.ts +4 -3
  365. package/lib/WAUSync/index.d.ts.map +1 -0
  366. package/lib/WAUSync/index.js +4 -23
  367. package/lib/WAUSync/index.js.map +1 -0
  368. package/lib/index.d.ts +10 -11
  369. package/lib/index.d.ts.map +1 -0
  370. package/lib/index.js +11 -33
  371. package/lib/index.js.map +1 -0
  372. package/package.json +48 -43
  373. package/lib/Defaults/baileys-version.json +0 -3
  374. package/lib/Defaults/phonenumber-mcc.json +0 -223
  375. package/lib/Signal/WASignalGroup/GroupProtocol.js +0 -1909
  376. package/lib/Signal/WASignalGroup/ciphertext_message.js +0 -16
  377. package/lib/Signal/WASignalGroup/generate-proto.sh +0 -1
  378. package/lib/Signal/WASignalGroup/group.proto +0 -42
  379. package/lib/Signal/WASignalGroup/group_cipher.js +0 -120
  380. package/lib/Signal/WASignalGroup/group_session_builder.js +0 -46
  381. package/lib/Signal/WASignalGroup/index.js +0 -6
  382. package/lib/Signal/WASignalGroup/keyhelper.js +0 -21
  383. package/lib/Signal/WASignalGroup/protobufs.js +0 -3
  384. package/lib/Signal/WASignalGroup/queue_job.js +0 -69
  385. package/lib/Signal/WASignalGroup/readme.md +0 -6
  386. package/lib/Signal/WASignalGroup/sender_chain_key.js +0 -50
  387. package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +0 -78
  388. package/lib/Signal/WASignalGroup/sender_key_message.js +0 -92
  389. package/lib/Signal/WASignalGroup/sender_key_name.js +0 -70
  390. package/lib/Signal/WASignalGroup/sender_key_record.js +0 -56
  391. package/lib/Signal/WASignalGroup/sender_key_state.js +0 -129
  392. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
  393. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  394. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
  395. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  396. package/lib/Socket/registration.d.ts +0 -266
  397. package/lib/Socket/registration.js +0 -166
  398. package/lib/Socket/usync.d.ts +0 -37
  399. package/lib/Socket/usync.js +0 -83
  400. package/lib/Store/index.d.ts +0 -4
  401. package/lib/Store/index.js +0 -24
  402. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  403. package/lib/Store/make-cache-manager-store.js +0 -90
  404. package/lib/Store/make-in-memory-store.d.ts +0 -123
  405. package/lib/Store/make-in-memory-store.js +0 -429
  406. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  407. package/lib/Store/make-ordered-dictionary.js +0 -86
  408. package/lib/Store/object-repository.d.ts +0 -10
  409. package/lib/Store/object-repository.js +0 -31
  410. package/lib/Types/MexUpdates.d.ts +0 -9
  411. package/lib/Types/MexUpdates.js +0 -18
  412. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  413. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  414. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  415. package/lib/Utils/use-single-file-auth-state.js +0 -80
  416. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  417. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
  418. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -9
  419. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -30
@@ -1,38 +1,39 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
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")
12
- const chats_1 = require("../Socket/chats")
1
+ import { proto } from '../../WAProto/index.js';
2
+ import { WAMessageStubType } from '../Types/index.js';
3
+ import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
4
+ import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
5
+ import { aesDecryptGCM, hmacSign } from './crypto.js';
6
+ import { toNumber } from './generics.js';
7
+ import { downloadAndProcessHistorySyncNotification } from './history.js';
13
8
  const REAL_MSG_STUB_TYPES = new Set([
14
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
15
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
16
- Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
17
- Types_1.WAMessageStubType.CALL_MISSED_VOICE
18
- ])
19
-
20
- const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
21
- Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
22
- ])
23
-
9
+ WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
10
+ WAMessageStubType.CALL_MISSED_GROUP_VOICE,
11
+ WAMessageStubType.CALL_MISSED_VIDEO,
12
+ WAMessageStubType.CALL_MISSED_VOICE
13
+ ]);
14
+ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
24
15
  /** Cleans a received message to further processing */
25
- const cleanMessage = (message, meId) => {
16
+ export const cleanMessage = (message, meId, meLid) => {
26
17
  // ensure remoteJid and participant doesn't have device or agent in it
27
- message.key.remoteJid = WABinary_1.jidNormalizedUser(message.key.remoteJid)
28
- message.key.participant = message.key.participant ? WABinary_1.jidNormalizedUser(message.key.participant) : undefined
29
- const content = messages_1.normalizeMessageContent(message.message)
18
+ if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
19
+ message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
20
+ }
21
+ else {
22
+ message.key.remoteJid = jidNormalizedUser(message.key.remoteJid);
23
+ }
24
+ if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
25
+ message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? 's.whatsapp.net' : 'lid');
26
+ }
27
+ else {
28
+ message.key.participant = jidNormalizedUser(message.key.participant);
29
+ }
30
+ const content = normalizeMessageContent(message.message);
30
31
  // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
31
32
  if (content?.reactionMessage) {
32
- normaliseKey(content.reactionMessage.key)
33
+ normaliseKey(content.reactionMessage.key);
33
34
  }
34
35
  if (content?.pollUpdateMessage) {
35
- normaliseKey(content.pollUpdateMessage.pollCreationMessageKey)
36
+ normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
36
37
  }
37
38
  function normaliseKey(msgKey) {
38
39
  // if the reaction is from another user
@@ -41,188 +42,178 @@ const cleanMessage = (message, meId) => {
41
42
  // if the sender believed the message being reacted to is not from them
42
43
  // we've to correct the key to be from them, or some other participant
43
44
  msgKey.fromMe = !msgKey.fromMe
44
- ? WABinary_1.areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId)
45
- // if the message being reacted to, was from them
46
- // fromMe automatically becomes false
47
- : false
45
+ ? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
46
+ areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
47
+ : // if the message being reacted to, was from them
48
+ // fromMe automatically becomes false
49
+ false;
48
50
  // set the remoteJid to being the same as the chat the message came from
49
- msgKey.remoteJid = message.key.remoteJid
51
+ // TODO: investigate inconsistencies
52
+ msgKey.remoteJid = message.key.remoteJid;
50
53
  // set participant of the message
51
- msgKey.participant = msgKey.participant || message.key.participant
54
+ msgKey.participant = msgKey.participant || message.key.participant;
52
55
  }
53
56
  }
54
- }
55
-
56
- const isRealMessage = (message, meId) => {
57
- const normalizedContent = messages_1.normalizeMessageContent(message.message)
58
- const hasSomeContent = !!messages_1.getContentType(normalizedContent)
59
- return (
60
- !!normalizedContent ||
57
+ };
58
+ // TODO: target:audit AUDIT THIS FUNCTION AGAIN
59
+ export const isRealMessage = (message) => {
60
+ const normalizedContent = normalizeMessageContent(message.message);
61
+ const hasSomeContent = !!getContentType(normalizedContent);
62
+ return ((!!normalizedContent ||
61
63
  REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
62
- (
63
- REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType) &&
64
- message.messageStubParameters?.some(p => WABinary_1.areJidsSameUser(meId, p))
65
- )
66
- ) &&
67
- hasSomeContent &&
68
- !normalizedContent?.protocolMessage &&
69
- !normalizedContent?.reactionMessage &&
70
- !normalizedContent?.pollUpdateMessage
71
- }
72
-
73
- const shouldIncrementChatUnread = (message) => (!message.key.fromMe && !message.messageStubType)
74
-
64
+ REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
65
+ hasSomeContent &&
66
+ !normalizedContent?.protocolMessage &&
67
+ !normalizedContent?.reactionMessage &&
68
+ !normalizedContent?.pollUpdateMessage);
69
+ };
70
+ export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
75
71
  /**
76
72
  * Get the ID of the chat from the given key.
77
73
  * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
78
74
  */
79
- const getChatId = ({ remoteJid, participant, fromMe }) => {
80
- if (WABinary_1.isJidBroadcast(remoteJid)
81
- && !WABinary_1.isJidStatusBroadcast(remoteJid)
82
- && !fromMe) {
83
- return participant
75
+ export const getChatId = ({ remoteJid, participant, fromMe }) => {
76
+ if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
77
+ return participant;
84
78
  }
85
- return remoteJid
86
- }
87
-
79
+ return remoteJid;
80
+ };
88
81
  /**
89
82
  * Decrypt a poll vote
90
83
  * @param vote encrypted vote
91
84
  * @param ctx additional info about the poll required for decryption
92
85
  * @returns list of SHA256 options
93
86
  */
94
- function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }) {
87
+ export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
95
88
  const sign = Buffer.concat([
96
89
  toBinary(pollMsgId),
97
90
  toBinary(pollCreatorJid),
98
91
  toBinary(voterJid),
99
92
  toBinary('Poll Vote'),
100
93
  new Uint8Array([1])
101
- ])
102
- const key0 = crypto_1.hmacSign(pollEncKey, new Uint8Array(32), 'sha256')
103
- const decKey = crypto_1.hmacSign(sign, key0, 'sha256')
104
- const aad = toBinary(`${pollMsgId}\u0000${voterJid}`)
105
- const decrypted = crypto_1.aesDecryptGCM(encPayload, decKey, encIv, aad)
106
- return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted)
94
+ ]);
95
+ const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256');
96
+ const decKey = hmacSign(sign, key0, 'sha256');
97
+ const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
98
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
99
+ return proto.Message.PollVoteMessage.decode(decrypted);
107
100
  function toBinary(txt) {
108
- return Buffer.from(txt)
101
+ return Buffer.from(txt);
109
102
  }
110
103
  }
111
-
112
- const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
113
- const meId = creds.me.id
114
- const { accountSettings } = creds
115
- const chat = { id: WABinary_1.jidNormalizedUser(getChatId(message.key)) }
116
- const isRealMsg = isRealMessage(message, meId)
104
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options }) => {
105
+ const meId = creds.me.id;
106
+ const { accountSettings } = creds;
107
+ const chat = { id: jidNormalizedUser(getChatId(message.key)) };
108
+ const isRealMsg = isRealMessage(message);
117
109
  if (isRealMsg) {
118
- chat.messages = [{ message }]
119
- chat.conversationTimestamp = generics_1.toNumber(message.messageTimestamp)
110
+ chat.messages = [{ message }];
111
+ chat.conversationTimestamp = toNumber(message.messageTimestamp);
120
112
  // only increment unread count if not CIPHERTEXT and from another person
121
113
  if (shouldIncrementChatUnread(message)) {
122
- chat.unreadCount = (chat.unreadCount || 0) + 1
114
+ chat.unreadCount = (chat.unreadCount || 0) + 1;
123
115
  }
124
116
  }
125
- const content = messages_1.normalizeMessageContent(message.message)
117
+ const content = normalizeMessageContent(message.message);
126
118
  // unarchive chat if it's a real message, or someone reacted to our message
127
119
  // and we've the unarchive chats setting on
128
- if (isRealMsg || content?.reactionMessage?.key?.fromMe
129
- && accountSettings?.unarchiveChats) {
130
- chat.archived = false
131
- chat.readOnly = false
120
+ if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
121
+ chat.archived = false;
122
+ chat.readOnly = false;
132
123
  }
133
- const protocolMsg = content?.protocolMessage
124
+ const protocolMsg = content?.protocolMessage;
134
125
  if (protocolMsg) {
135
126
  switch (protocolMsg.type) {
136
- case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
137
- const histNotification = protocolMsg.historySyncNotification
138
- const process = shouldProcessHistoryMsg
139
- const isLatest = !creds.processedHistoryMessages?.length
127
+ case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
128
+ const histNotification = protocolMsg.historySyncNotification;
129
+ const process = shouldProcessHistoryMsg;
130
+ const isLatest = !creds.processedHistoryMessages?.length;
140
131
  logger?.info({
141
132
  histNotification,
142
133
  process,
143
134
  id: message.key.id,
144
- isLatest,
145
- }, 'got history notification')
135
+ isLatest
136
+ }, 'got history notification');
146
137
  if (process) {
147
- if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
138
+ // TODO: investigate
139
+ if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
148
140
  ev.emit('creds.update', {
149
141
  processedHistoryMessages: [
150
142
  ...(creds.processedHistoryMessages || []),
151
143
  { key: message.key, messageTimestamp: message.messageTimestamp }
152
144
  ]
153
- })
145
+ });
154
146
  }
155
- const data = await history_1.downloadAndProcessHistorySyncNotification(histNotification, options)
147
+ const data = await downloadAndProcessHistorySyncNotification(histNotification, options);
156
148
  ev.emit('messaging-history.set', {
157
149
  ...data,
158
- isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
159
- ? isLatest
160
- : undefined,
150
+ isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
161
151
  peerDataRequestSessionId: histNotification.peerDataRequestSessionId
162
- })
152
+ });
163
153
  }
164
- break
165
- case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
166
- const keys = protocolMsg.appStateSyncKeyShare.keys
154
+ break;
155
+ case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
156
+ const keys = protocolMsg.appStateSyncKeyShare.keys;
167
157
  if (keys?.length) {
168
- let newAppStateSyncKeyId = ''
158
+ let newAppStateSyncKeyId = '';
169
159
  await keyStore.transaction(async () => {
170
- const newKeys = []
160
+ const newKeys = [];
171
161
  for (const { keyData, keyId } of keys) {
172
- const strKeyId = Buffer.from(keyId.keyId).toString('base64')
173
- newKeys.push(strKeyId)
174
- await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } })
175
- newAppStateSyncKeyId = strKeyId
162
+ const strKeyId = Buffer.from(keyId.keyId).toString('base64');
163
+ newKeys.push(strKeyId);
164
+ await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
165
+ newAppStateSyncKeyId = strKeyId;
176
166
  }
177
- logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys')
178
- })
179
- ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId })
167
+ logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
168
+ }, meId);
169
+ ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
180
170
  }
181
171
  else {
182
- logger?.info({ protocolMsg }, 'recv app state sync with 0 keys')
172
+ logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
183
173
  }
184
- break
185
- case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
174
+ break;
175
+ case proto.Message.ProtocolMessage.Type.REVOKE:
186
176
  ev.emit('messages.update', [
187
177
  {
188
178
  key: {
189
179
  ...message.key,
190
180
  id: protocolMsg.key.id
191
181
  },
192
- update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
182
+ update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
193
183
  }
194
- ])
195
- break
196
- case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
184
+ ]);
185
+ break;
186
+ case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
197
187
  Object.assign(chat, {
198
- ephemeralSettingTimestamp: generics_1.toNumber(message.messageTimestamp),
188
+ ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
199
189
  ephemeralExpiration: protocolMsg.ephemeralExpiration || null
200
- })
201
- break
202
- case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
203
- const response = protocolMsg.peerDataOperationRequestResponseMessage
190
+ });
191
+ break;
192
+ case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
193
+ const response = protocolMsg.peerDataOperationRequestResponseMessage;
204
194
  if (response) {
205
- placeholderResendCache?.del(response.stanzaId)
195
+ await placeholderResendCache?.del(response.stanzaId);
206
196
  // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
207
- const { peerDataOperationResult } = response
197
+ const { peerDataOperationResult } = response;
208
198
  for (const result of peerDataOperationResult) {
209
- const { placeholderMessageResendResponse: retryResponse } = result
199
+ const { placeholderMessageResendResponse: retryResponse } = result;
210
200
  //eslint-disable-next-line max-depth
211
201
  if (retryResponse) {
212
- const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes)
202
+ const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
213
203
  // wait till another upsert event is available, don't want it to be part of the PDO response message
204
+ // TODO: parse through proper message handling utilities (to add relevant key fields)
214
205
  setTimeout(() => {
215
206
  ev.emit('messages.upsert', {
216
207
  messages: [webMessageInfo],
217
208
  type: 'notify',
218
209
  requestId: response.stanzaId
219
- })
220
- }, 500)
210
+ });
211
+ }, 500);
221
212
  }
222
213
  }
223
214
  }
224
- break
225
- case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
215
+ break;
216
+ case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
226
217
  ev.emit('messages.update', [
227
218
  {
228
219
  // flip the sender / fromMe properties because they're in the perspective of the sender
@@ -234,162 +225,159 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
234
225
  }
235
226
  },
236
227
  messageTimestamp: protocolMsg.timestampMs
237
- ? Math.floor(generics_1.toNumber(protocolMsg.timestampMs) / 1000)
228
+ ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
238
229
  : message.messageTimestamp
239
230
  }
240
231
  }
241
- ])
242
- break
243
- case WAProto_1.proto.Message.ProtocolMessage.Type.LIMIT_SHARING:
244
- ev.emit('limit-sharing.update', {
245
- id: protocolMsg.key.remoteJid,
246
- author: WABinary_1.areJidsSameUser(message.key.remoteJid, protocolMsg.key.remoteJid) ? WABinary_1.jidNormalizedUser(meId) : message.key.remoteJid,
247
- action: `${protocolMsg.limitSharing.sharingLimited ? 'on' : 'off'}`,
248
- trigger: protocolMsg.limitSharing.trigger,
249
- update_time: protocolMsg.limitSharing.limitSharingSettingTimestamp
250
- })
251
- break
232
+ ]);
233
+ break;
234
+ case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
235
+ const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
236
+ const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
237
+ logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
238
+ const pairs = [];
239
+ for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
240
+ const lid = latestLid || assignedLid;
241
+ pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
242
+ }
243
+ await signalRepository.lidMapping.storeLIDPNMappings(pairs);
244
+ if (pairs.length) {
245
+ for (const { pn, lid } of pairs) {
246
+ await signalRepository.migrateSession(pn, lid);
247
+ }
248
+ }
252
249
  }
253
250
  }
254
251
  else if (content?.reactionMessage) {
255
252
  const reaction = {
256
253
  ...content.reactionMessage,
257
- key: message.key,
258
- }
259
- ev.emit('messages.reaction', [{
254
+ key: message.key
255
+ };
256
+ ev.emit('messages.reaction', [
257
+ {
260
258
  reaction,
261
259
  key: content.reactionMessage?.key
262
- }])
260
+ }
261
+ ]);
263
262
  }
264
263
  else if (message.messageStubType) {
265
- const jid = message.key?.remoteJid
266
-
264
+ const jid = message.key?.remoteJid;
267
265
  //let actor = whatsappID (message.participant)
268
- let participants
269
-
270
- const jid2 = message.key.participant;
271
- const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: jid2, participants, action}))
266
+ let participants;
267
+ const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
268
+ id: jid,
269
+ author: message.key.participant,
270
+ authorPn: message.key.participantAlt,
271
+ participants,
272
+ action
273
+ });
272
274
  const emitGroupUpdate = (update) => {
273
- ev.emit('groups.update', [{ id: jid, ...update, author: message.participant ? message.participant : undefined }])
274
- }
275
- const emitCommunityUpdate = (update) => {
276
- ev.emit('communities.update', [{ id: jid, ...update, author: message.participant ? message.participant : undefined }])
277
- }
275
+ ev.emit('groups.update', [
276
+ { id: jid, ...update, author: message.key.participant ?? undefined, authorPn: message.key.participantAlt }
277
+ ]);
278
+ };
278
279
  const emitGroupRequestJoin = (participant, action, method) => {
279
- ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method })
280
- }
281
- const participantsIncludesMe = () => participants.find(jid => WABinary_1.areJidsSameUser(meId, jid))
280
+ ev.emit('group.join-request', {
281
+ id: jid,
282
+ author: message.key.participant,
283
+ authorPn: message.key.participantAlt,
284
+ participant: participant.lid,
285
+ participantPn: participant.pn,
286
+ action,
287
+ method: method
288
+ });
289
+ };
290
+ const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber)); // ADD SUPPORT FOR LID
282
291
  switch (message.messageStubType) {
283
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
284
- participants = message.messageStubParameters || []
285
- emitParticipantsUpdate('modify')
286
- break
287
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
288
- participants = message.messageStubParameters || [];
289
- emitParticipantsUpdate('leave');
290
- // mark the chat read only if you left the group
291
- if (participantsIncludesMe()) {
292
- chat.readOnly = true;
293
- }
294
- break;
295
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
296
- participants = message.messageStubParameters || []
297
- emitParticipantsUpdate('remove')
292
+ case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
293
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
294
+ emitParticipantsUpdate('modify');
295
+ break;
296
+ case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
297
+ case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
298
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
299
+ emitParticipantsUpdate('remove');
298
300
  // mark the chat read only if you left the group
299
301
  if (participantsIncludesMe()) {
300
- chat.readOnly = true
302
+ chat.readOnly = true;
301
303
  }
302
- break
303
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
304
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
305
- let actionGp = 'invite'
306
- participants = message.messageStubParameters || []
307
- if (participantsIncludesMe()) chat.readOnly = false;
308
- if (message?.key?.participant && !participants.includes(message?.key?.participant)) {
309
- actionGp = 'approval-invite'
310
- }
311
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
312
- participants = message.messageStubParameters || []
304
+ break;
305
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD:
306
+ case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
307
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
308
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
313
309
  if (participantsIncludesMe()) {
314
- chat.readOnly = false
310
+ chat.readOnly = false;
315
311
  }
316
- emitParticipantsUpdate('add')
317
- break
318
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
319
- case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_DEMOTE:
320
- participants = message.messageStubParameters || []
321
- emitParticipantsUpdate('demote')
322
- break
323
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
324
- case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_PROMOTE:
325
- participants = message.messageStubParameters || []
326
- emitParticipantsUpdate('promote')
327
- break
328
- case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
329
- const announceValue = message.messageStubParameters?.[0]
330
- emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' })
331
- break
332
- case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
333
- const restrictValue = message.messageStubParameters?.[0]
334
- emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' })
335
- break
336
- case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
337
- const name = message.messageStubParameters?.[0]
338
- chat.name = name
339
- emitGroupUpdate({ subject: name })
340
- break
341
- case Types_1.WAMessageStubType.COMMUNITY_PARENT_GROUP_SUBJECT_CHANGED:
342
- const name2 = message.messageStubParameters?.[0]
343
- chat.name2 = name2
344
- emitCommunityUpdate({ subject: name2 })
345
- break
346
- case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
347
- const description = message.messageStubParameters?.[0]
348
- chat.description = description
349
- emitGroupUpdate({ desc: description })
350
- break
351
- case Types_1.WAMessageStubType.COMMUNITY_CHANGE_DESCRIPTION:
352
- const description2 = message.messageStubParameters?.[0]
353
- chat.description2 = description2
354
- emitCommunityUpdate({ desc: description2 })
355
- break
356
- case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
357
- const code = message.messageStubParameters?.[0]
358
- emitGroupUpdate({ inviteCode: code })
359
- break
360
- case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
361
- const memberAddValue = message.messageStubParameters?.[0]
362
- emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' })
363
- break
364
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
365
- const approvalMode = message.messageStubParameters?.[0]
366
- emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' })
367
- break
368
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
369
- const participant = message.messageStubParameters?.[0]
370
- const action = message.messageStubParameters?.[1]
371
- const method = message.messageStubParameters?.[2]
372
- emitGroupRequestJoin(participant, action, method)
373
- break
312
+ emitParticipantsUpdate('add');
313
+ break;
314
+ case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
315
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
316
+ emitParticipantsUpdate('demote');
317
+ break;
318
+ case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
319
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
320
+ emitParticipantsUpdate('promote');
321
+ break;
322
+ case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
323
+ const announceValue = message.messageStubParameters?.[0];
324
+ emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
325
+ break;
326
+ case WAMessageStubType.GROUP_CHANGE_RESTRICT:
327
+ const restrictValue = message.messageStubParameters?.[0];
328
+ emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
329
+ break;
330
+ case WAMessageStubType.GROUP_CHANGE_SUBJECT:
331
+ const name = message.messageStubParameters?.[0];
332
+ chat.name = name;
333
+ emitGroupUpdate({ subject: name });
334
+ break;
335
+ case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
336
+ const description = message.messageStubParameters?.[0];
337
+ chat.description = description;
338
+ emitGroupUpdate({ desc: description });
339
+ break;
340
+ case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
341
+ const code = message.messageStubParameters?.[0];
342
+ emitGroupUpdate({ inviteCode: code });
343
+ break;
344
+ case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
345
+ const memberAddValue = message.messageStubParameters?.[0];
346
+ emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
347
+ break;
348
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
349
+ const approvalMode = message.messageStubParameters?.[0];
350
+ emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
351
+ break;
352
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
353
+ const participant = JSON.parse(message.messageStubParameters?.[0]);
354
+ const action = message.messageStubParameters?.[1];
355
+ const method = message.messageStubParameters?.[2];
356
+ emitGroupRequestJoin(participant, action, method);
357
+ break;
374
358
  }
375
- }
376
- else if (content?.pollUpdateMessage) {
377
- const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey
359
+ } /* else if(content?.pollUpdateMessage) {
360
+ const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey!
378
361
  // we need to fetch the poll creation message to get the poll enc key
379
- const pollMsg2 = await getMessage(creationMsgKey);
380
- const pollMsg = pollMsg.botInvokeMessage?.message || pollMsg2;
381
- if (pollMsg) {
382
- const meIdNormalised = WABinary_1.jidNormalizedUser(meId)
383
- const pollCreatorJid = generics_1.getKeyAuthor(creationMsgKey, meIdNormalised)
384
- const voterJid = generics_1.getKeyAuthor(message.key, meIdNormalised)
385
- const pollEncKey = pollMsg.messageContextInfo?.messageSecret
362
+ // TODO: make standalone, remove getMessage reference
363
+ // TODO: Remove entirely
364
+ const pollMsg = await getMessage(creationMsgKey)
365
+ if(pollMsg) {
366
+ const meIdNormalised = jidNormalizedUser(meId)
367
+ const pollCreatorJid = getKeyAuthor(creationMsgKey, meIdNormalised)
368
+ const voterJid = getKeyAuthor(message.key, meIdNormalised)
369
+ const pollEncKey = pollMsg.messageContextInfo?.messageSecret!
370
+
386
371
  try {
387
- const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
388
- pollEncKey,
389
- pollCreatorJid,
390
- pollMsgId: creationMsgKey.id,
391
- voterJid,
392
- })
372
+ const voteMsg = decryptPollVote(
373
+ content.pollUpdateMessage.vote!,
374
+ {
375
+ pollEncKey,
376
+ pollCreatorJid,
377
+ pollMsgId: creationMsgKey.id!,
378
+ voterJid,
379
+ }
380
+ )
393
381
  ev.emit('messages.update', [
394
382
  {
395
383
  key: creationMsgKey,
@@ -398,31 +386,28 @@ const jid2 = message.key.participant;
398
386
  {
399
387
  pollUpdateMessageKey: message.key,
400
388
  vote: voteMsg,
401
- senderTimestampMs: content.pollUpdateMessage.senderTimestampMs.toNumber(),
389
+ senderTimestampMs: (content.pollUpdateMessage.senderTimestampMs! as Long).toNumber(),
402
390
  }
403
391
  ]
404
392
  }
405
393
  }
406
394
  ])
395
+ } catch(err) {
396
+ logger?.warn(
397
+ { err, creationMsgKey },
398
+ 'failed to decrypt poll vote'
399
+ )
407
400
  }
408
- catch (err) {
409
- logger?.warn({ err, creationMsgKey }, 'failed to decrypt poll vote')
410
- }
411
- }
412
- else {
413
- logger?.warn({ creationMsgKey }, 'poll creation message not found, cannot decrypt update')
401
+ } else {
402
+ logger?.warn(
403
+ { creationMsgKey },
404
+ 'poll creation message not found, cannot decrypt update'
405
+ )
414
406
  }
415
- }
407
+ } */
416
408
  if (Object.keys(chat).length > 1) {
417
- ev.emit('chats.update', [chat])
409
+ ev.emit('chats.update', [chat]);
418
410
  }
419
- }
420
-
421
- module.exports = {
422
- cleanMessage,
423
- isRealMessage,
424
- shouldIncrementChatUnread,
425
- getChatId,
426
- decryptPollVote,
427
- processMessage
428
- }
411
+ };
412
+ export default processMessage;
413
+ //# sourceMappingURL=process-message.js.map