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