@d0v3riz/baileys 6.7.21 → 6.7.22

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 (356) hide show
  1. package/WAProto/GenerateStatics.sh +2 -3
  2. package/WAProto/index.js +4138 -4136
  3. package/lib/Defaults/index.d.ts +2 -3
  4. package/lib/Defaults/index.js +40 -36
  5. package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
  6. package/lib/Signal/Group/ciphertext-message.js +5 -2
  7. package/lib/Signal/Group/group-session-builder.d.ts +3 -4
  8. package/lib/Signal/Group/group-session-builder.js +41 -7
  9. package/lib/Signal/Group/group_cipher.d.ts +2 -3
  10. package/lib/Signal/Group/group_cipher.js +16 -14
  11. package/lib/Signal/Group/index.d.ts +11 -12
  12. package/lib/Signal/Group/index.js +57 -12
  13. package/lib/Signal/Group/keyhelper.d.ts +1 -2
  14. package/lib/Signal/Group/keyhelper.js +44 -8
  15. package/lib/Signal/Group/queue-job.d.ts +0 -2
  16. package/lib/Signal/Group/queue-job.js +5 -5
  17. package/lib/Signal/Group/sender-chain-key.d.ts +1 -2
  18. package/lib/Signal/Group/sender-chain-key.js +9 -7
  19. package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
  20. package/lib/Signal/Group/sender-key-distribution-message.js +9 -6
  21. package/lib/Signal/Group/sender-key-message.d.ts +1 -2
  22. package/lib/Signal/Group/sender-key-message.js +12 -10
  23. package/lib/Signal/Group/sender-key-name.d.ts +0 -1
  24. package/lib/Signal/Group/sender-key-name.js +5 -2
  25. package/lib/Signal/Group/sender-key-record.d.ts +1 -2
  26. package/lib/Signal/Group/sender-key-record.js +12 -9
  27. package/lib/Signal/Group/sender-key-state.d.ts +2 -3
  28. package/lib/Signal/Group/sender-key-state.js +9 -6
  29. package/lib/Signal/Group/sender-message-key.d.ts +0 -1
  30. package/lib/Signal/Group/sender-message-key.js +7 -5
  31. package/lib/Signal/libsignal.d.ts +2 -3
  32. package/lib/Signal/libsignal.js +55 -22
  33. package/lib/Socket/Client/index.d.ts +2 -3
  34. package/lib/Socket/Client/index.js +18 -3
  35. package/lib/Socket/Client/types.d.ts +1 -2
  36. package/lib/Socket/Client/types.js +6 -4
  37. package/lib/Socket/Client/websocket.d.ts +1 -2
  38. package/lib/Socket/Client/websocket.js +26 -14
  39. package/lib/Socket/business.d.ts +64 -66
  40. package/lib/Socket/business.js +37 -32
  41. package/lib/Socket/chats.d.ts +19 -21
  42. package/lib/Socket/chats.js +141 -176
  43. package/lib/Socket/groups.d.ts +35 -37
  44. package/lib/Socket/groups.js +63 -56
  45. package/lib/Socket/index.d.ts +70 -102
  46. package/lib/Socket/index.js +9 -16
  47. package/lib/Socket/messages-recv.d.ts +49 -51
  48. package/lib/Socket/messages-recv.js +173 -180
  49. package/lib/Socket/messages-send.d.ts +46 -48
  50. package/lib/Socket/messages-send.js +84 -75
  51. package/lib/Socket/mex.d.ts +1 -2
  52. package/lib/Socket/mex.js +16 -12
  53. package/lib/Socket/newsletter.d.ts +44 -46
  54. package/lib/Socket/newsletter.js +27 -23
  55. package/lib/Socket/socket.d.ts +12 -13
  56. package/lib/Socket/socket.js +115 -135
  57. package/lib/Socket/usync.d.ts +14 -15
  58. package/lib/Socket/usync.js +11 -9
  59. package/lib/Types/Auth.d.ts +3 -4
  60. package/lib/Types/Auth.js +2 -2
  61. package/lib/Types/Call.d.ts +0 -1
  62. package/lib/Types/Call.js +2 -2
  63. package/lib/Types/Chat.d.ts +7 -10
  64. package/lib/Types/Chat.js +4 -2
  65. package/lib/Types/Contact.d.ts +0 -1
  66. package/lib/Types/Contact.js +2 -2
  67. package/lib/Types/Events.d.ts +10 -11
  68. package/lib/Types/Events.js +2 -2
  69. package/lib/Types/GroupMetadata.d.ts +2 -3
  70. package/lib/Types/GroupMetadata.js +2 -2
  71. package/lib/Types/Label.d.ts +0 -1
  72. package/lib/Types/Label.js +5 -3
  73. package/lib/Types/LabelAssociation.d.ts +0 -1
  74. package/lib/Types/LabelAssociation.js +5 -3
  75. package/lib/Types/Message.d.ts +7 -9
  76. package/lib/Types/Message.js +7 -7
  77. package/lib/Types/Newsletter.d.ts +0 -1
  78. package/lib/Types/Newsletter.js +7 -5
  79. package/lib/Types/Product.d.ts +1 -2
  80. package/lib/Types/Product.js +2 -2
  81. package/lib/Types/Signal.d.ts +1 -2
  82. package/lib/Types/Signal.js +2 -2
  83. package/lib/Types/Socket.d.ts +7 -8
  84. package/lib/Types/Socket.js +2 -3
  85. package/lib/Types/State.d.ts +2 -14
  86. package/lib/Types/State.js +2 -13
  87. package/lib/Types/USync.d.ts +2 -3
  88. package/lib/Types/USync.js +2 -2
  89. package/lib/Types/index.d.ts +14 -15
  90. package/lib/Types/index.js +31 -15
  91. package/lib/Utils/auth-utils.d.ts +2 -3
  92. package/lib/Utils/auth-utils.js +34 -25
  93. package/lib/Utils/baileys-event-stream.d.ts +1 -2
  94. package/lib/Utils/baileys-event-stream.js +22 -15
  95. package/lib/Utils/business.d.ts +2 -3
  96. package/lib/Utils/business.js +70 -61
  97. package/lib/Utils/chat-utils.d.ts +7 -8
  98. package/lib/Utils/chat-utils.js +137 -130
  99. package/lib/Utils/crypto.d.ts +1 -2
  100. package/lib/Utils/crypto.js +86 -37
  101. package/lib/Utils/decode-wa-message.d.ts +4 -5
  102. package/lib/Utils/decode-wa-message.js +44 -38
  103. package/lib/Utils/event-buffer.d.ts +4 -4
  104. package/lib/Utils/event-buffer.js +50 -37
  105. package/lib/Utils/generics.d.ts +8 -9
  106. package/lib/Utils/generics.js +114 -87
  107. package/lib/Utils/history.d.ts +3 -4
  108. package/lib/Utils/history.js +40 -32
  109. package/lib/Utils/index.d.ts +17 -18
  110. package/lib/Utils/index.js +33 -18
  111. package/lib/Utils/link-preview.d.ts +3 -4
  112. package/lib/Utils/link-preview.js +47 -10
  113. package/lib/Utils/logger.d.ts +6 -8
  114. package/lib/Utils/logger.js +7 -3
  115. package/lib/Utils/lt-hash.d.ts +8 -9
  116. package/lib/Utils/lt-hash.js +26 -23
  117. package/lib/Utils/make-mutex.d.ts +0 -1
  118. package/lib/Utils/make-mutex.js +9 -5
  119. package/lib/Utils/messages-media.d.ts +10 -11
  120. package/lib/Utils/messages-media.js +203 -141
  121. package/lib/Utils/messages.d.ts +6 -7
  122. package/lib/Utils/messages.js +199 -190
  123. package/lib/Utils/noise-handler.d.ts +4 -5
  124. package/lib/Utils/noise-handler.js +26 -22
  125. package/lib/Utils/process-message.d.ts +4 -5
  126. package/lib/Utils/process-message.js +104 -95
  127. package/lib/Utils/signal.d.ts +4 -5
  128. package/lib/Utils/signal.js +52 -47
  129. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
  130. package/lib/Utils/use-multi-file-auth-state.js +26 -23
  131. package/lib/Utils/validate-connection.d.ts +3 -4
  132. package/lib/Utils/validate-connection.js +58 -52
  133. package/lib/WABinary/constants.d.ts +0 -1
  134. package/lib/WABinary/constants.js +11 -9
  135. package/lib/WABinary/decode.d.ts +1 -2
  136. package/lib/WABinary/decode.js +51 -13
  137. package/lib/WABinary/encode.d.ts +1 -2
  138. package/lib/WABinary/encode.js +41 -5
  139. package/lib/WABinary/generic-utils.d.ts +3 -4
  140. package/lib/WABinary/generic-utils.js +38 -30
  141. package/lib/WABinary/index.d.ts +5 -6
  142. package/lib/WABinary/index.js +21 -6
  143. package/lib/WABinary/jid-utils.d.ts +0 -1
  144. package/lib/WABinary/jid-utils.js +35 -21
  145. package/lib/WABinary/types.d.ts +1 -2
  146. package/lib/WABinary/types.js +2 -2
  147. package/lib/WAM/BinaryInfo.d.ts +1 -2
  148. package/lib/WAM/BinaryInfo.js +5 -2
  149. package/lib/WAM/constants.d.ts +0 -1
  150. package/lib/WAM/constants.js +6 -4
  151. package/lib/WAM/encode.d.ts +1 -2
  152. package/lib/WAM/encode.js +14 -12
  153. package/lib/WAM/index.d.ts +3 -4
  154. package/lib/WAM/index.js +19 -4
  155. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
  156. package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -6
  157. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
  158. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +12 -9
  159. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
  160. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -6
  161. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
  162. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +11 -7
  163. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
  164. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +21 -19
  165. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +2 -3
  166. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +5 -2
  167. package/lib/WAUSync/Protocols/index.d.ts +4 -5
  168. package/lib/WAUSync/Protocols/index.js +20 -5
  169. package/lib/WAUSync/USyncQuery.d.ts +3 -4
  170. package/lib/WAUSync/USyncQuery.js +20 -18
  171. package/lib/WAUSync/USyncUser.d.ts +5 -6
  172. package/lib/WAUSync/USyncUser.js +5 -2
  173. package/lib/WAUSync/index.d.ts +3 -4
  174. package/lib/WAUSync/index.js +19 -4
  175. package/lib/index.d.ts +8 -9
  176. package/lib/index.js +30 -11
  177. package/package.json +26 -26
  178. package/WAProto/fix-imports.js +0 -29
  179. package/lib/Defaults/index.d.ts.map +0 -1
  180. package/lib/Defaults/index.js.map +0 -1
  181. package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
  182. package/lib/Signal/Group/ciphertext-message.js.map +0 -1
  183. package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
  184. package/lib/Signal/Group/group-session-builder.js.map +0 -1
  185. package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
  186. package/lib/Signal/Group/group_cipher.js.map +0 -1
  187. package/lib/Signal/Group/index.d.ts.map +0 -1
  188. package/lib/Signal/Group/index.js.map +0 -1
  189. package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
  190. package/lib/Signal/Group/keyhelper.js.map +0 -1
  191. package/lib/Signal/Group/queue-job.d.ts.map +0 -1
  192. package/lib/Signal/Group/queue-job.js.map +0 -1
  193. package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
  194. package/lib/Signal/Group/sender-chain-key.js.map +0 -1
  195. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
  196. package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
  197. package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
  198. package/lib/Signal/Group/sender-key-message.js.map +0 -1
  199. package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
  200. package/lib/Signal/Group/sender-key-name.js.map +0 -1
  201. package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
  202. package/lib/Signal/Group/sender-key-record.js.map +0 -1
  203. package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
  204. package/lib/Signal/Group/sender-key-state.js.map +0 -1
  205. package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
  206. package/lib/Signal/Group/sender-message-key.js.map +0 -1
  207. package/lib/Signal/libsignal.d.ts.map +0 -1
  208. package/lib/Signal/libsignal.js.map +0 -1
  209. package/lib/Socket/Client/index.d.ts.map +0 -1
  210. package/lib/Socket/Client/index.js.map +0 -1
  211. package/lib/Socket/Client/types.d.ts.map +0 -1
  212. package/lib/Socket/Client/types.js.map +0 -1
  213. package/lib/Socket/Client/websocket.d.ts.map +0 -1
  214. package/lib/Socket/Client/websocket.js.map +0 -1
  215. package/lib/Socket/business.d.ts.map +0 -1
  216. package/lib/Socket/business.js.map +0 -1
  217. package/lib/Socket/chats.d.ts.map +0 -1
  218. package/lib/Socket/chats.js.map +0 -1
  219. package/lib/Socket/communities.d.ts +0 -219
  220. package/lib/Socket/communities.d.ts.map +0 -1
  221. package/lib/Socket/communities.js +0 -351
  222. package/lib/Socket/communities.js.map +0 -1
  223. package/lib/Socket/groups.d.ts.map +0 -1
  224. package/lib/Socket/groups.js.map +0 -1
  225. package/lib/Socket/index.d.ts.map +0 -1
  226. package/lib/Socket/index.js.map +0 -1
  227. package/lib/Socket/messages-recv.d.ts.map +0 -1
  228. package/lib/Socket/messages-recv.js.map +0 -1
  229. package/lib/Socket/messages-send.d.ts.map +0 -1
  230. package/lib/Socket/messages-send.js.map +0 -1
  231. package/lib/Socket/mex.d.ts.map +0 -1
  232. package/lib/Socket/mex.js.map +0 -1
  233. package/lib/Socket/newsletter.d.ts.map +0 -1
  234. package/lib/Socket/newsletter.js.map +0 -1
  235. package/lib/Socket/socket.d.ts.map +0 -1
  236. package/lib/Socket/socket.js.map +0 -1
  237. package/lib/Socket/usync.d.ts.map +0 -1
  238. package/lib/Socket/usync.js.map +0 -1
  239. package/lib/Types/Auth.d.ts.map +0 -1
  240. package/lib/Types/Auth.js.map +0 -1
  241. package/lib/Types/Call.d.ts.map +0 -1
  242. package/lib/Types/Call.js.map +0 -1
  243. package/lib/Types/Chat.d.ts.map +0 -1
  244. package/lib/Types/Chat.js.map +0 -1
  245. package/lib/Types/Contact.d.ts.map +0 -1
  246. package/lib/Types/Contact.js.map +0 -1
  247. package/lib/Types/Events.d.ts.map +0 -1
  248. package/lib/Types/Events.js.map +0 -1
  249. package/lib/Types/GroupMetadata.d.ts.map +0 -1
  250. package/lib/Types/GroupMetadata.js.map +0 -1
  251. package/lib/Types/Label.d.ts.map +0 -1
  252. package/lib/Types/Label.js.map +0 -1
  253. package/lib/Types/LabelAssociation.d.ts.map +0 -1
  254. package/lib/Types/LabelAssociation.js.map +0 -1
  255. package/lib/Types/Message.d.ts.map +0 -1
  256. package/lib/Types/Message.js.map +0 -1
  257. package/lib/Types/Newsletter.d.ts.map +0 -1
  258. package/lib/Types/Newsletter.js.map +0 -1
  259. package/lib/Types/Product.d.ts.map +0 -1
  260. package/lib/Types/Product.js.map +0 -1
  261. package/lib/Types/Signal.d.ts.map +0 -1
  262. package/lib/Types/Signal.js.map +0 -1
  263. package/lib/Types/Socket.d.ts.map +0 -1
  264. package/lib/Types/Socket.js.map +0 -1
  265. package/lib/Types/State.d.ts.map +0 -1
  266. package/lib/Types/State.js.map +0 -1
  267. package/lib/Types/USync.d.ts.map +0 -1
  268. package/lib/Types/USync.js.map +0 -1
  269. package/lib/Types/index.d.ts.map +0 -1
  270. package/lib/Types/index.js.map +0 -1
  271. package/lib/Utils/auth-utils.d.ts.map +0 -1
  272. package/lib/Utils/auth-utils.js.map +0 -1
  273. package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
  274. package/lib/Utils/baileys-event-stream.js.map +0 -1
  275. package/lib/Utils/business.d.ts.map +0 -1
  276. package/lib/Utils/business.js.map +0 -1
  277. package/lib/Utils/chat-utils.d.ts.map +0 -1
  278. package/lib/Utils/chat-utils.js.map +0 -1
  279. package/lib/Utils/crypto.d.ts.map +0 -1
  280. package/lib/Utils/crypto.js.map +0 -1
  281. package/lib/Utils/decode-wa-message.d.ts.map +0 -1
  282. package/lib/Utils/decode-wa-message.js.map +0 -1
  283. package/lib/Utils/event-buffer.d.ts.map +0 -1
  284. package/lib/Utils/event-buffer.js.map +0 -1
  285. package/lib/Utils/generics.d.ts.map +0 -1
  286. package/lib/Utils/generics.js.map +0 -1
  287. package/lib/Utils/history.d.ts.map +0 -1
  288. package/lib/Utils/history.js.map +0 -1
  289. package/lib/Utils/index.d.ts.map +0 -1
  290. package/lib/Utils/index.js.map +0 -1
  291. package/lib/Utils/link-preview.d.ts.map +0 -1
  292. package/lib/Utils/link-preview.js.map +0 -1
  293. package/lib/Utils/logger.d.ts.map +0 -1
  294. package/lib/Utils/logger.js.map +0 -1
  295. package/lib/Utils/lt-hash.d.ts.map +0 -1
  296. package/lib/Utils/lt-hash.js.map +0 -1
  297. package/lib/Utils/make-mutex.d.ts.map +0 -1
  298. package/lib/Utils/make-mutex.js.map +0 -1
  299. package/lib/Utils/messages-media.d.ts.map +0 -1
  300. package/lib/Utils/messages-media.js.map +0 -1
  301. package/lib/Utils/messages.d.ts.map +0 -1
  302. package/lib/Utils/messages.js.map +0 -1
  303. package/lib/Utils/noise-handler.d.ts.map +0 -1
  304. package/lib/Utils/noise-handler.js.map +0 -1
  305. package/lib/Utils/process-message.d.ts.map +0 -1
  306. package/lib/Utils/process-message.js.map +0 -1
  307. package/lib/Utils/signal.d.ts.map +0 -1
  308. package/lib/Utils/signal.js.map +0 -1
  309. package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
  310. package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
  311. package/lib/Utils/validate-connection.d.ts.map +0 -1
  312. package/lib/Utils/validate-connection.js.map +0 -1
  313. package/lib/WABinary/constants.d.ts.map +0 -1
  314. package/lib/WABinary/constants.js.map +0 -1
  315. package/lib/WABinary/decode.d.ts.map +0 -1
  316. package/lib/WABinary/decode.js.map +0 -1
  317. package/lib/WABinary/encode.d.ts.map +0 -1
  318. package/lib/WABinary/encode.js.map +0 -1
  319. package/lib/WABinary/generic-utils.d.ts.map +0 -1
  320. package/lib/WABinary/generic-utils.js.map +0 -1
  321. package/lib/WABinary/index.d.ts.map +0 -1
  322. package/lib/WABinary/index.js.map +0 -1
  323. package/lib/WABinary/jid-utils.d.ts.map +0 -1
  324. package/lib/WABinary/jid-utils.js.map +0 -1
  325. package/lib/WABinary/types.d.ts.map +0 -1
  326. package/lib/WABinary/types.js.map +0 -1
  327. package/lib/WAM/BinaryInfo.d.ts.map +0 -1
  328. package/lib/WAM/BinaryInfo.js.map +0 -1
  329. package/lib/WAM/constants.d.ts.map +0 -1
  330. package/lib/WAM/constants.js.map +0 -1
  331. package/lib/WAM/encode.d.ts.map +0 -1
  332. package/lib/WAM/encode.js.map +0 -1
  333. package/lib/WAM/index.d.ts.map +0 -1
  334. package/lib/WAM/index.js.map +0 -1
  335. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
  336. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
  337. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
  338. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
  339. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
  340. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
  341. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
  342. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
  343. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
  344. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
  345. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
  346. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
  347. package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
  348. package/lib/WAUSync/Protocols/index.js.map +0 -1
  349. package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
  350. package/lib/WAUSync/USyncQuery.js.map +0 -1
  351. package/lib/WAUSync/USyncUser.d.ts.map +0 -1
  352. package/lib/WAUSync/USyncUser.js.map +0 -1
  353. package/lib/WAUSync/index.d.ts.map +0 -1
  354. package/lib/WAUSync/index.js.map +0 -1
  355. package/lib/index.d.ts.map +0 -1
  356. package/lib/index.js.map +0 -1
@@ -1,34 +1,39 @@
1
- import NodeCache from '@cacheable/node-cache';
2
- import { Boom } from '@hapi/boom';
3
- import { randomBytes } from 'crypto';
4
- import Long from 'long';
5
- import { proto } from '../../WAProto/index.js';
6
- import { DEFAULT_CACHE_TTLS, KEY_BUNDLE_TYPE, MIN_PREKEY_COUNT } from '../Defaults/index.js';
7
- import { WAMessageStatus, WAMessageStubType } from '../Types/index.js';
8
- import { aesDecryptCTR, aesEncryptGCM, cleanMessage, Curve, decodeMediaRetryNode, decodeMessageNode, decryptMessageNode, delay, derivePairingCodeKey, encodeBigEndian, encodeSignedDeviceIdentity, getCallStatusFromNode, getHistoryMsg, getNextPreKeys, getStatusFromReceiptType, hkdf, MISSING_KEYS_ERROR_TEXT, NACK_REASONS, NO_MESSAGE_FOUND_ERROR_TEXT, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils/index.js';
9
- import { makeMutex } from '../Utils/make-mutex.js';
10
- import { areJidsSameUser, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildString, isJidGroup, isJidStatusBroadcast, isJidUser, isLidUser, jidDecode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
11
- import { extractGroupMetadata } from './groups.js';
12
- import { makeMessagesSocket } from './messages-send.js';
13
- export const makeMessagesRecvSocket = (config) => {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.makeMessagesRecvSocket = void 0;
7
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
8
+ const boom_1 = require("@hapi/boom");
9
+ const crypto_1 = require("crypto");
10
+ const WAProto_1 = require("../../WAProto");
11
+ const Defaults_1 = require("../Defaults");
12
+ const Types_1 = require("../Types");
13
+ const Utils_1 = require("../Utils");
14
+ const make_mutex_1 = require("../Utils/make-mutex");
15
+ const WABinary_1 = require("../WABinary");
16
+ const groups_1 = require("./groups");
17
+ const messages_send_1 = require("./messages-send");
18
+ const makeMessagesRecvSocket = (config) => {
14
19
  const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
15
- const sock = makeMessagesSocket(config);
20
+ const sock = (0, messages_send_1.makeMessagesSocket)(config);
16
21
  const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage } = sock;
17
22
  /** this mutex ensures that each retryRequest will wait for the previous one to finish */
18
- const retryMutex = makeMutex();
23
+ const retryMutex = (0, make_mutex_1.makeMutex)();
19
24
  const msgRetryCache = config.msgRetryCounterCache ||
20
- new NodeCache({
21
- stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
25
+ new node_cache_1.default({
26
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
22
27
  useClones: false
23
28
  });
24
29
  const callOfferCache = config.callOfferCache ||
25
- new NodeCache({
26
- stdTTL: DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
30
+ new node_cache_1.default({
31
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
27
32
  useClones: false
28
33
  });
29
34
  const placeholderResendCache = config.placeholderResendCache ||
30
- new NodeCache({
31
- stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
35
+ new node_cache_1.default({
36
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
32
37
  useClones: false
33
38
  });
34
39
  let sendActiveReceipts = false;
@@ -51,10 +56,10 @@ export const makeMessagesRecvSocket = (config) => {
51
56
  stanza.attrs.recipient = attrs.recipient;
52
57
  }
53
58
  if (!!attrs.type &&
54
- (tag !== 'message' || getBinaryNodeChild({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
59
+ (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
55
60
  stanza.attrs.type = attrs.type;
56
61
  }
57
- if (tag === 'message' && getBinaryNodeChild({ tag, attrs, content }, 'unavailable')) {
62
+ if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
58
63
  stanza.attrs.from = authState.creds.me.id;
59
64
  }
60
65
  logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
@@ -82,10 +87,10 @@ export const makeMessagesRecvSocket = (config) => {
82
87
  await query(stanza);
83
88
  };
84
89
  const sendRetryRequest = async (node, forceIncludeKeys = false) => {
85
- const { fullMessage } = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '');
90
+ const { fullMessage } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '');
86
91
  const { key: msgKey } = fullMessage;
87
92
  const msgId = msgKey.id;
88
- const key = `${msgId}:${msgKey?.participant}`;
93
+ const key = `${msgId}:${msgKey === null || msgKey === void 0 ? void 0 : msgKey.participant}`;
89
94
  let retryCount = msgRetryCache.get(key) || 0;
90
95
  if (retryCount >= maxMsgRetryCount) {
91
96
  logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
@@ -100,7 +105,7 @@ export const makeMessagesRecvSocket = (config) => {
100
105
  const msgId = await requestPlaceholderResend(msgKey);
101
106
  logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
102
107
  }
103
- const deviceIdentity = encodeSignedDeviceIdentity(account, true);
108
+ const deviceIdentity = (0, Utils_1.encodeSignedDeviceIdentity)(account, true);
104
109
  await authState.keys.transaction(async () => {
105
110
  const receipt = {
106
111
  tag: 'receipt',
@@ -122,7 +127,7 @@ export const makeMessagesRecvSocket = (config) => {
122
127
  {
123
128
  tag: 'registration',
124
129
  attrs: {},
125
- content: encodeBigEndian(authState.creds.registrationId)
130
+ content: (0, Utils_1.encodeBigEndian)(authState.creds.registrationId)
126
131
  }
127
132
  ]
128
133
  };
@@ -133,7 +138,7 @@ export const makeMessagesRecvSocket = (config) => {
133
138
  receipt.attrs.participant = node.attrs.participant;
134
139
  }
135
140
  if (retryCount > 1 || forceIncludeKeys) {
136
- const { update, preKeys } = await getNextPreKeys(authState, 1);
141
+ const { update, preKeys } = await (0, Utils_1.getNextPreKeys)(authState, 1);
137
142
  const [keyId] = Object.keys(preKeys);
138
143
  const key = preKeys[+keyId];
139
144
  const content = receipt.content;
@@ -141,10 +146,10 @@ export const makeMessagesRecvSocket = (config) => {
141
146
  tag: 'keys',
142
147
  attrs: {},
143
148
  content: [
144
- { tag: 'type', attrs: {}, content: Buffer.from(KEY_BUNDLE_TYPE) },
149
+ { tag: 'type', attrs: {}, content: Buffer.from(Defaults_1.KEY_BUNDLE_TYPE) },
145
150
  { tag: 'identity', attrs: {}, content: identityKey.public },
146
- xmppPreKey(key, +keyId),
147
- xmppSignedPreKey(signedPreKey),
151
+ (0, Utils_1.xmppPreKey)(key, +keyId),
152
+ (0, Utils_1.xmppSignedPreKey)(signedPreKey),
148
153
  { tag: 'device-identity', attrs: {}, content: deviceIdentity }
149
154
  ]
150
155
  });
@@ -156,17 +161,17 @@ export const makeMessagesRecvSocket = (config) => {
156
161
  };
157
162
  const handleEncryptNotification = async (node) => {
158
163
  const from = node.attrs.from;
159
- if (from === S_WHATSAPP_NET) {
160
- const countChild = getBinaryNodeChild(node, 'count');
164
+ if (from === WABinary_1.S_WHATSAPP_NET) {
165
+ const countChild = (0, WABinary_1.getBinaryNodeChild)(node, 'count');
161
166
  const count = +countChild.attrs.value;
162
- const shouldUploadMorePreKeys = count < MIN_PREKEY_COUNT;
167
+ const shouldUploadMorePreKeys = count < Defaults_1.MIN_PREKEY_COUNT;
163
168
  logger.debug({ count, shouldUploadMorePreKeys }, 'recv pre-key count');
164
169
  if (shouldUploadMorePreKeys) {
165
170
  await uploadPreKeys();
166
171
  }
167
172
  }
168
173
  else {
169
- const identityNode = getBinaryNodeChild(node, 'identity');
174
+ const identityNode = (0, WABinary_1.getBinaryNodeChild)(node, 'identity');
170
175
  if (identityNode) {
171
176
  logger.info({ jid: from }, 'identity changed');
172
177
  // not handling right now
@@ -178,11 +183,12 @@ export const makeMessagesRecvSocket = (config) => {
178
183
  }
179
184
  };
180
185
  const handleGroupNotification = (participant, child, msg) => {
181
- const participantJid = getBinaryNodeChild(child, 'participant')?.attrs?.jid || participant;
182
- switch (child?.tag) {
186
+ var _a, _b, _c, _d;
187
+ const participantJid = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(child, 'participant')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.jid) || participant;
188
+ switch (child === null || child === void 0 ? void 0 : child.tag) {
183
189
  case 'create':
184
- const metadata = extractGroupMetadata(child);
185
- msg.messageStubType = WAMessageStubType.GROUP_CREATE;
190
+ const metadata = (0, groups_1.extractGroupMetadata)(child);
191
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CREATE;
186
192
  msg.messageStubParameters = [metadata.subject];
187
193
  msg.key = { participant: metadata.owner };
188
194
  ev.emit('chats.upsert', [
@@ -203,15 +209,15 @@ export const makeMessagesRecvSocket = (config) => {
203
209
  case 'not_ephemeral':
204
210
  msg.message = {
205
211
  protocolMessage: {
206
- type: proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
212
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
207
213
  ephemeralExpiration: +(child.attrs.expiration || 0)
208
214
  }
209
215
  };
210
216
  break;
211
217
  case 'modify':
212
- const oldNumber = getBinaryNodeChildren(child, 'participant').map(p => p.attrs.jid);
218
+ const oldNumber = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
213
219
  msg.messageStubParameters = oldNumber || [];
214
- msg.messageStubType = WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
220
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
215
221
  break;
216
222
  case 'promote':
217
223
  case 'demote':
@@ -219,73 +225,74 @@ export const makeMessagesRecvSocket = (config) => {
219
225
  case 'add':
220
226
  case 'leave':
221
227
  const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
222
- msg.messageStubType = WAMessageStubType[stubType];
223
- const participants = getBinaryNodeChildren(child, 'participant').map(p => p.attrs.jid);
228
+ msg.messageStubType = Types_1.WAMessageStubType[stubType];
229
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
224
230
  if (participants.length === 1 &&
225
231
  // if recv. "remove" message and sender removed themselves
226
232
  // mark as left
227
- areJidsSameUser(participants[0], participant) &&
233
+ (0, WABinary_1.areJidsSameUser)(participants[0], participant) &&
228
234
  child.tag === 'remove') {
229
- msg.messageStubType = WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
235
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
230
236
  }
231
237
  msg.messageStubParameters = participants;
232
238
  break;
233
239
  case 'subject':
234
- msg.messageStubType = WAMessageStubType.GROUP_CHANGE_SUBJECT;
240
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT;
235
241
  msg.messageStubParameters = [child.attrs.subject];
236
242
  break;
237
243
  case 'description':
238
- const description = getBinaryNodeChild(child, 'body')?.content?.toString();
239
- msg.messageStubType = WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
244
+ const description = (_d = (_c = (0, WABinary_1.getBinaryNodeChild)(child, 'body')) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.toString();
245
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
240
246
  msg.messageStubParameters = description ? [description] : undefined;
241
247
  break;
242
248
  case 'announcement':
243
249
  case 'not_announcement':
244
- msg.messageStubType = WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
250
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
245
251
  msg.messageStubParameters = [child.tag === 'announcement' ? 'on' : 'off'];
246
252
  break;
247
253
  case 'locked':
248
254
  case 'unlocked':
249
- msg.messageStubType = WAMessageStubType.GROUP_CHANGE_RESTRICT;
255
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT;
250
256
  msg.messageStubParameters = [child.tag === 'locked' ? 'on' : 'off'];
251
257
  break;
252
258
  case 'invite':
253
- msg.messageStubType = WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
259
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
254
260
  msg.messageStubParameters = [child.attrs.code];
255
261
  break;
256
262
  case 'member_add_mode':
257
263
  const addMode = child.content;
258
264
  if (addMode) {
259
- msg.messageStubType = WAMessageStubType.GROUP_MEMBER_ADD_MODE;
265
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE;
260
266
  msg.messageStubParameters = [addMode.toString()];
261
267
  }
262
268
  break;
263
269
  case 'membership_approval_mode':
264
- const approvalMode = getBinaryNodeChild(child, 'group_join');
270
+ const approvalMode = (0, WABinary_1.getBinaryNodeChild)(child, 'group_join');
265
271
  if (approvalMode) {
266
- msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
272
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
267
273
  msg.messageStubParameters = [approvalMode.attrs.state];
268
274
  }
269
275
  break;
270
276
  case 'created_membership_requests':
271
- msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
277
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
272
278
  msg.messageStubParameters = [participantJid, 'created', child.attrs.request_method];
273
279
  break;
274
280
  case 'revoked_membership_requests':
275
- const isDenied = areJidsSameUser(participantJid, participant);
276
- msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
281
+ const isDenied = (0, WABinary_1.areJidsSameUser)(participantJid, participant);
282
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
277
283
  msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
278
284
  break;
279
285
  }
280
286
  };
281
287
  const processNotification = async (node) => {
288
+ var _a, _b, _c;
282
289
  const result = {};
283
- const [child] = getAllBinaryNodeChildren(node);
290
+ const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
284
291
  const nodeType = node.attrs.type;
285
- const from = jidNormalizedUser(node.attrs.from);
292
+ const from = (0, WABinary_1.jidNormalizedUser)(node.attrs.from);
286
293
  switch (nodeType) {
287
294
  case 'privacy_token':
288
- const tokenList = getBinaryNodeChildren(child, 'token');
295
+ const tokenList = (0, WABinary_1.getBinaryNodeChildren)(child, 'token');
289
296
  for (const { attrs, content } of tokenList) {
290
297
  const jid = attrs.jid;
291
298
  ev.emit('chats.update', [
@@ -307,45 +314,45 @@ export const makeMessagesRecvSocket = (config) => {
307
314
  handleGroupNotification(node.attrs.participant, child, result);
308
315
  break;
309
316
  case 'mediaretry':
310
- const event = decodeMediaRetryNode(node);
317
+ const event = (0, Utils_1.decodeMediaRetryNode)(node);
311
318
  ev.emit('messages.media-update', [event]);
312
319
  break;
313
320
  case 'encrypt':
314
321
  await handleEncryptNotification(node);
315
322
  break;
316
323
  case 'devices':
317
- const devices = getBinaryNodeChildren(child, 'device');
318
- if (areJidsSameUser(child.attrs.jid, authState.creds.me.id)) {
324
+ const devices = (0, WABinary_1.getBinaryNodeChildren)(child, 'device');
325
+ if ((0, WABinary_1.areJidsSameUser)(child.attrs.jid, authState.creds.me.id)) {
319
326
  const deviceJids = devices.map(d => d.attrs.jid);
320
327
  logger.info({ deviceJids }, 'got my own devices');
321
328
  }
322
329
  break;
323
330
  case 'server_sync':
324
- const update = getBinaryNodeChild(node, 'collection');
331
+ const update = (0, WABinary_1.getBinaryNodeChild)(node, 'collection');
325
332
  if (update) {
326
333
  const name = update.attrs.name;
327
334
  await resyncAppState([name], false);
328
335
  }
329
336
  break;
330
337
  case 'picture':
331
- const setPicture = getBinaryNodeChild(node, 'set');
332
- const delPicture = getBinaryNodeChild(node, 'delete');
338
+ const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
339
+ const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
333
340
  ev.emit('contacts.update', [
334
341
  {
335
- id: jidNormalizedUser(node?.attrs?.from) || (setPicture || delPicture)?.attrs?.hash || '',
342
+ id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.from) || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
336
343
  imgUrl: setPicture ? 'changed' : 'removed'
337
344
  }
338
345
  ]);
339
- if (isJidGroup(from)) {
346
+ if ((0, WABinary_1.isJidGroup)(from)) {
340
347
  const node = setPicture || delPicture;
341
- result.messageStubType = WAMessageStubType.GROUP_CHANGE_ICON;
348
+ result.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ICON;
342
349
  if (setPicture) {
343
350
  result.messageStubParameters = [setPicture.attrs.id];
344
351
  }
345
- result.participant = node?.attrs.author;
352
+ result.participant = node === null || node === void 0 ? void 0 : node.attrs.author;
346
353
  result.key = {
347
354
  ...(result.key || {}),
348
- participant: setPicture?.attrs.author
355
+ participant: setPicture === null || setPicture === void 0 ? void 0 : setPicture.attrs.author
349
356
  };
350
357
  }
351
358
  break;
@@ -365,7 +372,7 @@ export const makeMessagesRecvSocket = (config) => {
365
372
  });
366
373
  }
367
374
  else if (child.tag === 'blocklist') {
368
- const blocklists = getBinaryNodeChildren(child, 'item');
375
+ const blocklists = (0, WABinary_1.getBinaryNodeChildren)(child, 'item');
369
376
  for (const { attrs } of blocklists) {
370
377
  const blocklist = [attrs.jid];
371
378
  const type = attrs.action === 'block' ? 'add' : 'remove';
@@ -374,15 +381,15 @@ export const makeMessagesRecvSocket = (config) => {
374
381
  }
375
382
  break;
376
383
  case 'link_code_companion_reg':
377
- const linkCodeCompanionReg = getBinaryNodeChild(node, 'link_code_companion_reg');
378
- const ref = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_ref'));
379
- const primaryIdentityPublicKey = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'primary_identity_pub'));
380
- const primaryEphemeralPublicKeyWrapped = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
384
+ const linkCodeCompanionReg = (0, WABinary_1.getBinaryNodeChild)(node, 'link_code_companion_reg');
385
+ const ref = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_ref'));
386
+ const primaryIdentityPublicKey = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'primary_identity_pub'));
387
+ const primaryEphemeralPublicKeyWrapped = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
381
388
  const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
382
- const companionSharedKey = Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
383
- const random = randomBytes(32);
384
- const linkCodeSalt = randomBytes(32);
385
- const linkCodePairingExpanded = await hkdf(companionSharedKey, 32, {
389
+ const companionSharedKey = Utils_1.Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
390
+ const random = (0, crypto_1.randomBytes)(32);
391
+ const linkCodeSalt = (0, crypto_1.randomBytes)(32);
392
+ const linkCodePairingExpanded = await (0, Utils_1.hkdf)(companionSharedKey, 32, {
386
393
  salt: linkCodeSalt,
387
394
  info: 'link_code_pairing_key_bundle_encryption_key'
388
395
  });
@@ -391,16 +398,16 @@ export const makeMessagesRecvSocket = (config) => {
391
398
  primaryIdentityPublicKey,
392
399
  random
393
400
  ]);
394
- const encryptIv = randomBytes(12);
395
- const encrypted = aesEncryptGCM(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
401
+ const encryptIv = (0, crypto_1.randomBytes)(12);
402
+ const encrypted = (0, Utils_1.aesEncryptGCM)(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
396
403
  const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
397
- const identitySharedKey = Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
404
+ const identitySharedKey = Utils_1.Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
398
405
  const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
399
- authState.creds.advSecretKey = (await hkdf(identityPayload, 32, { info: 'adv_secret' })).toString('base64');
406
+ authState.creds.advSecretKey = (await (0, Utils_1.hkdf)(identityPayload, 32, { info: 'adv_secret' })).toString('base64');
400
407
  await query({
401
408
  tag: 'iq',
402
409
  attrs: {
403
- to: S_WHATSAPP_NET,
410
+ to: WABinary_1.S_WHATSAPP_NET,
404
411
  type: 'set',
405
412
  id: sock.generateMessageTag(),
406
413
  xmlns: 'md'
@@ -442,14 +449,14 @@ export const makeMessagesRecvSocket = (config) => {
442
449
  async function decipherLinkPublicKey(data) {
443
450
  const buffer = toRequiredBuffer(data);
444
451
  const salt = buffer.slice(0, 32);
445
- const secretKey = await derivePairingCodeKey(authState.creds.pairingCode, salt);
452
+ const secretKey = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
446
453
  const iv = buffer.slice(32, 48);
447
454
  const payload = buffer.slice(48, 80);
448
- return aesDecryptCTR(payload, secretKey, iv);
455
+ return (0, Utils_1.aesDecryptCTR)(payload, secretKey, iv);
449
456
  }
450
457
  function toRequiredBuffer(data) {
451
458
  if (data === undefined) {
452
- throw new Boom('Invalid buffer', { statusCode: 400 });
459
+ throw new boom_1.Boom('Invalid buffer', { statusCode: 400 });
453
460
  }
454
461
  return data instanceof Buffer ? data : Buffer.from(data);
455
462
  }
@@ -464,6 +471,7 @@ export const makeMessagesRecvSocket = (config) => {
464
471
  msgRetryCache.set(key, newValue);
465
472
  };
466
473
  const sendMessagesAgain = async (key, ids, retryNode) => {
474
+ var _a;
467
475
  // todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
468
476
  const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
469
477
  const remoteJid = key.remoteJid;
@@ -471,9 +479,9 @@ export const makeMessagesRecvSocket = (config) => {
471
479
  // if it's the primary jid sending the request
472
480
  // just re-send the message to everyone
473
481
  // prevents the first message decryption failure
474
- const sendToAll = !jidDecode(participant)?.device;
482
+ const sendToAll = !((_a = (0, WABinary_1.jidDecode)(participant)) === null || _a === void 0 ? void 0 : _a.device);
475
483
  await assertSessions([participant], true);
476
- if (isJidGroup(remoteJid)) {
484
+ if ((0, WABinary_1.isJidGroup)(remoteJid)) {
477
485
  await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
478
486
  }
479
487
  logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
@@ -498,10 +506,11 @@ export const makeMessagesRecvSocket = (config) => {
498
506
  }
499
507
  };
500
508
  const handleReceipt = async (node) => {
509
+ var _a, _b;
501
510
  const { attrs, content } = node;
502
511
  const isLid = attrs.from.includes('lid');
503
- const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, isLid ? authState.creds.me?.lid : authState.creds.me?.id);
504
- const remoteJid = !isNodeFromMe || isJidGroup(attrs.from) ? attrs.from : attrs.recipient;
512
+ const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(attrs.participant || attrs.from, isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
513
+ const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
505
514
  const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
506
515
  const key = {
507
516
  remoteJid,
@@ -516,24 +525,24 @@ export const makeMessagesRecvSocket = (config) => {
516
525
  }
517
526
  const ids = [attrs.id];
518
527
  if (Array.isArray(content)) {
519
- const items = getBinaryNodeChildren(content[0], 'item');
528
+ const items = (0, WABinary_1.getBinaryNodeChildren)(content[0], 'item');
520
529
  ids.push(...items.map(i => i.attrs.id));
521
530
  }
522
531
  try {
523
532
  await Promise.all([
524
533
  processingMutex.mutex(async () => {
525
- const status = getStatusFromReceiptType(attrs.type);
534
+ const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
526
535
  if (typeof status !== 'undefined' &&
527
536
  // basically, we only want to know when a message from us has been delivered to/read by the other person
528
537
  // or another device of ours has read some messages
529
- (status >= proto.WebMessageInfo.Status.SERVER_ACK || !isNodeFromMe)) {
530
- if (isJidGroup(remoteJid) || isJidStatusBroadcast(remoteJid)) {
538
+ (status >= WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK || !isNodeFromMe)) {
539
+ if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
531
540
  if (attrs.participant) {
532
- const updateKey = status === proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
541
+ const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
533
542
  ev.emit('message-receipt.update', ids.map(id => ({
534
543
  key: { ...key, id },
535
544
  receipt: {
536
- userJid: jidNormalizedUser(attrs.participant),
545
+ userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
537
546
  [updateKey]: +attrs.t
538
547
  }
539
548
  })));
@@ -549,7 +558,7 @@ export const makeMessagesRecvSocket = (config) => {
549
558
  if (attrs.type === 'retry') {
550
559
  // correctly set who is asking for the retry
551
560
  key.participant = key.participant || attrs.from;
552
- const retryNode = getBinaryNodeChild(node, 'retry');
561
+ const retryNode = (0, WABinary_1.getBinaryNodeChild)(node, 'retry');
553
562
  if (willSendMessageAgain(ids[0], key.participant)) {
554
563
  if (key.fromMe) {
555
564
  try {
@@ -585,9 +594,10 @@ export const makeMessagesRecvSocket = (config) => {
585
594
  try {
586
595
  await Promise.all([
587
596
  processingMutex.mutex(async () => {
597
+ var _a;
588
598
  const msg = await processNotification(node);
589
599
  if (msg) {
590
- const fromMe = areJidsSameUser(node.attrs.participant || remoteJid, authState.creds.me.id);
600
+ const fromMe = (0, WABinary_1.areJidsSameUser)(node.attrs.participant || remoteJid, authState.creds.me.id);
591
601
  msg.key = {
592
602
  remoteJid,
593
603
  fromMe,
@@ -595,9 +605,9 @@ export const makeMessagesRecvSocket = (config) => {
595
605
  id: node.attrs.id,
596
606
  ...(msg.key || {})
597
607
  };
598
- msg.participant ?? (msg.participant = node.attrs.participant);
608
+ (_a = msg.participant) !== null && _a !== void 0 ? _a : (msg.participant = node.attrs.participant);
599
609
  msg.messageTimestamp = +node.attrs.t;
600
- const fullMsg = proto.WebMessageInfo.fromObject(msg);
610
+ const fullMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
601
611
  await upsertMessage(fullMsg, 'append');
602
612
  }
603
613
  })
@@ -608,12 +618,13 @@ export const makeMessagesRecvSocket = (config) => {
608
618
  }
609
619
  };
610
620
  const handleMessage = async (node) => {
621
+ var _a, _b, _c;
611
622
  if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
612
623
  logger.debug({ key: node.attrs.key }, 'ignored message');
613
624
  await sendMessageAck(node);
614
625
  return;
615
626
  }
616
- const encNode = getBinaryNodeChild(node, 'enc');
627
+ const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
617
628
  // TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
618
629
  if (encNode && encNode.attrs.type === 'msmsg') {
619
630
  logger.debug({ key: node.attrs.key }, 'ignored msmsg');
@@ -621,9 +632,9 @@ export const makeMessagesRecvSocket = (config) => {
621
632
  return;
622
633
  }
623
634
  let response;
624
- if (getBinaryNodeChild(node, 'unavailable') && !encNode) {
635
+ if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !encNode) {
625
636
  await sendMessageAck(node);
626
- const { key } = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
637
+ const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
627
638
  response = await requestPlaceholderResend(key);
628
639
  if (response === 'RESOLVED') {
629
640
  return;
@@ -635,32 +646,33 @@ export const makeMessagesRecvSocket = (config) => {
635
646
  placeholderResendCache.del(node.attrs.id);
636
647
  }
637
648
  }
638
- const { fullMessage: msg, category, author, decrypt } = decryptMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
639
- if (response && msg?.messageStubParameters?.[0] === NO_MESSAGE_FOUND_ERROR_TEXT) {
640
- msg.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, response];
649
+ const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
650
+ if (response && ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT) {
651
+ msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
641
652
  }
642
- if (msg.message?.protocolMessage?.type === proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER &&
653
+ if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER &&
643
654
  node.attrs.sender_pn) {
644
655
  ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
645
656
  }
646
657
  try {
647
658
  await Promise.all([
648
659
  processingMutex.mutex(async () => {
660
+ var _a;
649
661
  await decrypt();
650
662
  // message failed to decrypt
651
- if (msg.messageStubType === proto.WebMessageInfo.StubType.CIPHERTEXT) {
652
- if (msg?.messageStubParameters?.[0] === MISSING_KEYS_ERROR_TEXT) {
653
- return sendMessageAck(node, NACK_REASONS.ParsingError);
663
+ if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
664
+ if (((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.MISSING_KEYS_ERROR_TEXT) {
665
+ return sendMessageAck(node, Utils_1.NACK_REASONS.ParsingError);
654
666
  }
655
667
  retryMutex.mutex(async () => {
656
668
  if (ws.isOpen) {
657
- if (getBinaryNodeChild(node, 'unavailable')) {
669
+ if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable')) {
658
670
  return;
659
671
  }
660
- const encNode = getBinaryNodeChild(node, 'enc');
672
+ const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
661
673
  await sendRetryRequest(node, !encNode);
662
674
  if (retryRequestDelayMs) {
663
- await delay(retryRequestDelayMs);
675
+ await (0, Utils_1.delay)(retryRequestDelayMs);
664
676
  }
665
677
  }
666
678
  else {
@@ -680,7 +692,7 @@ export const makeMessagesRecvSocket = (config) => {
680
692
  // message was sent by us from a different device
681
693
  type = 'sender';
682
694
  // need to specially handle this case
683
- if (isJidUser(msg.key.remoteJid)) {
695
+ if ((0, WABinary_1.isJidUser)(msg.key.remoteJid)) {
684
696
  participant = author;
685
697
  }
686
698
  }
@@ -689,13 +701,13 @@ export const makeMessagesRecvSocket = (config) => {
689
701
  }
690
702
  await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
691
703
  // send ack for history message
692
- const isAnyHistoryMsg = getHistoryMsg(msg.message);
704
+ const isAnyHistoryMsg = (0, Utils_1.getHistoryMsg)(msg.message);
693
705
  if (isAnyHistoryMsg) {
694
- const jid = jidNormalizedUser(msg.key.remoteJid);
706
+ const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
695
707
  await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
696
708
  }
697
709
  }
698
- cleanMessage(msg, authState.creds.me.id);
710
+ (0, Utils_1.cleanMessage)(msg, authState.creds.me.id);
699
711
  await sendMessageAck(node);
700
712
  await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
701
713
  })
@@ -706,8 +718,9 @@ export const makeMessagesRecvSocket = (config) => {
706
718
  }
707
719
  };
708
720
  const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
709
- if (!authState.creds.me?.id) {
710
- throw new Boom('Not authenticated');
721
+ var _a;
722
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
723
+ throw new boom_1.Boom('Not authenticated');
711
724
  }
712
725
  const pdoMessage = {
713
726
  historySyncOnDemandRequest: {
@@ -717,23 +730,24 @@ export const makeMessagesRecvSocket = (config) => {
717
730
  oldestMsgTimestampMs: oldestMsgTimestamp,
718
731
  onDemandMsgCount: count
719
732
  },
720
- peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
733
+ peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
721
734
  };
722
735
  return sendPeerDataOperationMessage(pdoMessage);
723
736
  };
724
737
  const requestPlaceholderResend = async (messageKey) => {
725
- if (!authState.creds.me?.id) {
726
- throw new Boom('Not authenticated');
738
+ var _a;
739
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
740
+ throw new boom_1.Boom('Not authenticated');
727
741
  }
728
- if (placeholderResendCache.get(messageKey?.id)) {
742
+ if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
729
743
  logger.debug({ messageKey }, 'already requested resend');
730
744
  return;
731
745
  }
732
746
  else {
733
- placeholderResendCache.set(messageKey?.id, true);
747
+ placeholderResendCache.set(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id, true);
734
748
  }
735
- await delay(5000);
736
- if (!placeholderResendCache.get(messageKey?.id)) {
749
+ await (0, Utils_1.delay)(5000);
750
+ if (!placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
737
751
  logger.debug({ messageKey }, 'message received while resend requested');
738
752
  return 'RESOLVED';
739
753
  }
@@ -743,41 +757,22 @@ export const makeMessagesRecvSocket = (config) => {
743
757
  messageKey
744
758
  }
745
759
  ],
746
- peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
760
+ peerDataOperationRequestType: WAProto_1.proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
747
761
  };
748
762
  setTimeout(() => {
749
- if (placeholderResendCache.get(messageKey?.id)) {
763
+ if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
750
764
  logger.debug({ messageKey }, 'PDO message without response after 15 seconds. Phone possibly offline');
751
- placeholderResendCache.del(messageKey?.id);
765
+ placeholderResendCache.del(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id);
752
766
  }
753
767
  }, 15000);
754
768
  return sendPeerDataOperationMessage(pdoMessage);
755
769
  };
756
770
  const handleCall = async (node) => {
757
- let status;
758
771
  const { attrs } = node;
759
- const [infoChild] = getAllBinaryNodeChildren(node);
760
- if (!infoChild) {
761
- throw new Boom('Missing call info in call node');
762
- }
772
+ const [infoChild] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
763
773
  const callId = infoChild.attrs['call-id'];
764
774
  const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
765
- status = getCallStatusFromNode(infoChild);
766
- if (isLidUser(from) && infoChild.tag === 'relaylatency') {
767
- const verify = callOfferCache.get(callId);
768
- if (!verify) {
769
- status = 'offer';
770
- const callLid = {
771
- chatId: attrs.from,
772
- from,
773
- id: callId,
774
- date: new Date(+attrs.t * 1000),
775
- offline: !!attrs.offline,
776
- status
777
- };
778
- callOfferCache.set(callId, callLid);
779
- }
780
- }
775
+ const status = (0, Utils_1.getCallStatusFromNode)(infoChild);
781
776
  const call = {
782
777
  chatId: attrs.from,
783
778
  from,
@@ -787,7 +782,7 @@ export const makeMessagesRecvSocket = (config) => {
787
782
  status
788
783
  };
789
784
  if (status === 'offer') {
790
- call.isVideo = !!getBinaryNodeChild(infoChild, 'video');
785
+ call.isVideo = !!(0, WABinary_1.getBinaryNodeChild)(infoChild, 'video');
791
786
  call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
792
787
  call.groupJid = infoChild.attrs['group-jid'];
793
788
  callOfferCache.set(call.id, call);
@@ -828,7 +823,7 @@ export const makeMessagesRecvSocket = (config) => {
828
823
  {
829
824
  key,
830
825
  update: {
831
- status: WAMessageStatus.ERROR,
826
+ status: Types_1.WAMessageStatus.ERROR,
832
827
  messageStubParameters: [attrs.error]
833
828
  }
834
829
  }
@@ -888,8 +883,9 @@ export const makeMessagesRecvSocket = (config) => {
888
883
  };
889
884
  // Handles newsletter notifications
890
885
  async function handleNewsletterNotification(node) {
886
+ var _a;
891
887
  const from = node.attrs.from;
892
- const child = getAllBinaryNodeChildren(node)[0];
888
+ const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
893
889
  const author = node.attrs.participant;
894
890
  logger.info({ from, child }, 'got newsletter notification');
895
891
  switch (child.tag) {
@@ -898,7 +894,7 @@ export const makeMessagesRecvSocket = (config) => {
898
894
  id: from,
899
895
  server_id: child.attrs.message_id,
900
896
  reaction: {
901
- code: getBinaryNodeChildString(child, 'reaction'),
897
+ code: (0, WABinary_1.getBinaryNodeChildString)(child, 'reaction'),
902
898
  count: 1
903
899
  }
904
900
  };
@@ -908,7 +904,7 @@ export const makeMessagesRecvSocket = (config) => {
908
904
  const viewUpdate = {
909
905
  id: from,
910
906
  server_id: child.attrs.message_id,
911
- count: parseInt(child.content?.toString() || '0', 10)
907
+ count: parseInt(((_a = child.content) === null || _a === void 0 ? void 0 : _a.toString()) || '0', 10)
912
908
  };
913
909
  ev.emit('newsletter.view', viewUpdate);
914
910
  break;
@@ -923,14 +919,14 @@ export const makeMessagesRecvSocket = (config) => {
923
919
  ev.emit('newsletter-participants.update', participantUpdate);
924
920
  break;
925
921
  case 'update':
926
- const settingsNode = getBinaryNodeChild(child, 'settings');
922
+ const settingsNode = (0, WABinary_1.getBinaryNodeChild)(child, 'settings');
927
923
  if (settingsNode) {
928
924
  const update = {};
929
- const nameNode = getBinaryNodeChild(settingsNode, 'name');
930
- if (nameNode?.content)
925
+ const nameNode = (0, WABinary_1.getBinaryNodeChild)(settingsNode, 'name');
926
+ if (nameNode === null || nameNode === void 0 ? void 0 : nameNode.content)
931
927
  update.name = nameNode.content.toString();
932
- const descriptionNode = getBinaryNodeChild(settingsNode, 'description');
933
- if (descriptionNode?.content)
928
+ const descriptionNode = (0, WABinary_1.getBinaryNodeChild)(settingsNode, 'description');
929
+ if (descriptionNode === null || descriptionNode === void 0 ? void 0 : descriptionNode.content)
934
930
  update.description = descriptionNode.content.toString();
935
931
  ev.emit('newsletter-settings.update', {
936
932
  id: from,
@@ -939,14 +935,14 @@ export const makeMessagesRecvSocket = (config) => {
939
935
  }
940
936
  break;
941
937
  case 'message':
942
- const plaintextNode = getBinaryNodeChild(child, 'plaintext');
943
- if (plaintextNode?.content) {
938
+ const plaintextNode = (0, WABinary_1.getBinaryNodeChild)(child, 'plaintext');
939
+ if (plaintextNode === null || plaintextNode === void 0 ? void 0 : plaintextNode.content) {
944
940
  try {
945
941
  const contentBuf = typeof plaintextNode.content === 'string'
946
942
  ? Buffer.from(plaintextNode.content, 'binary')
947
943
  : Buffer.from(plaintextNode.content);
948
- const messageProto = proto.Message.decode(contentBuf);
949
- const fullMessage = proto.WebMessageInfo.fromObject({
944
+ const messageProto = WAProto_1.proto.Message.decode(contentBuf);
945
+ const fullMessage = WAProto_1.proto.WebMessageInfo.fromObject({
950
946
  key: {
951
947
  remoteJid: from,
952
948
  id: child.attrs.message_id || child.attrs.server_id,
@@ -970,8 +966,8 @@ export const makeMessagesRecvSocket = (config) => {
970
966
  }
971
967
  // Handles mex newsletter notifications
972
968
  async function handleMexNewsletterNotification(node) {
973
- const mexNode = getBinaryNodeChild(node, 'mex');
974
- if (!mexNode?.content) {
969
+ const mexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'mex');
970
+ if (!(mexNode === null || mexNode === void 0 ? void 0 : mexNode.content)) {
975
971
  logger.warn({ node }, 'Invalid mex newsletter notification');
976
972
  return;
977
973
  }
@@ -983,8 +979,8 @@ export const makeMessagesRecvSocket = (config) => {
983
979
  logger.error({ err: error, node }, 'Failed to parse mex newsletter notification');
984
980
  return;
985
981
  }
986
- const operation = data?.operation;
987
- const updates = data?.updates;
982
+ const operation = data === null || data === void 0 ? void 0 : data.operation;
983
+ const updates = data === null || data === void 0 ? void 0 : data.updates;
988
984
  if (!updates || !operation) {
989
985
  logger.warn({ data }, 'Invalid mex newsletter notification content');
990
986
  return;
@@ -1036,9 +1032,6 @@ export const makeMessagesRecvSocket = (config) => {
1036
1032
  handleBadAck(node).catch(error => onUnexpectedError(error, 'handling bad ack'));
1037
1033
  });
1038
1034
  ev.on('call', ([call]) => {
1039
- if (!call) {
1040
- return;
1041
- }
1042
1035
  // missed call + group call notification message generation
1043
1036
  if (call.status === 'timeout' || (call.status === 'offer' && call.isGroup)) {
1044
1037
  const msg = {
@@ -1047,22 +1040,22 @@ export const makeMessagesRecvSocket = (config) => {
1047
1040
  id: call.id,
1048
1041
  fromMe: false
1049
1042
  },
1050
- messageTimestamp: unixTimestampSeconds(call.date)
1043
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)(call.date)
1051
1044
  };
1052
1045
  if (call.status === 'timeout') {
1053
1046
  if (call.isGroup) {
1054
1047
  msg.messageStubType = call.isVideo
1055
- ? WAMessageStubType.CALL_MISSED_GROUP_VIDEO
1056
- : WAMessageStubType.CALL_MISSED_GROUP_VOICE;
1048
+ ? Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO
1049
+ : Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE;
1057
1050
  }
1058
1051
  else {
1059
- msg.messageStubType = call.isVideo ? WAMessageStubType.CALL_MISSED_VIDEO : WAMessageStubType.CALL_MISSED_VOICE;
1052
+ msg.messageStubType = call.isVideo ? Types_1.WAMessageStubType.CALL_MISSED_VIDEO : Types_1.WAMessageStubType.CALL_MISSED_VOICE;
1060
1053
  }
1061
1054
  }
1062
1055
  else {
1063
1056
  msg.message = { call: { callKey: Buffer.from(call.id) } };
1064
1057
  }
1065
- const protoMsg = proto.WebMessageInfo.fromObject(msg);
1058
+ const protoMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
1066
1059
  upsertMessage(protoMsg, call.offline ? 'append' : 'notify');
1067
1060
  }
1068
1061
  });
@@ -1081,4 +1074,4 @@ export const makeMessagesRecvSocket = (config) => {
1081
1074
  requestPlaceholderResend
1082
1075
  };
1083
1076
  };
1084
- //# sourceMappingURL=messages-recv.js.map
1077
+ exports.makeMessagesRecvSocket = makeMessagesRecvSocket;