@d0v3riz/baileys 6.7.19 → 6.7.21

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 (374) hide show
  1. package/README.md +1263 -4
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +4633 -0
  4. package/WAProto/fix-imports.js +29 -0
  5. package/WAProto/index.d.ts +3212 -122
  6. package/WAProto/index.js +13516 -4182
  7. package/lib/Defaults/baileys-version.json +1 -1
  8. package/lib/Defaults/index.d.ts +4 -3
  9. package/lib/Defaults/index.d.ts.map +1 -0
  10. package/lib/Defaults/index.js +50 -54
  11. package/lib/Defaults/index.js.map +1 -0
  12. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  14. package/lib/Signal/Group/ciphertext-message.js +12 -0
  15. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  16. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  18. package/lib/Signal/Group/group-session-builder.js +30 -0
  19. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  20. package/lib/Signal/Group/group_cipher.d.ts +18 -0
  21. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  22. package/lib/Signal/Group/group_cipher.js +94 -0
  23. package/lib/Signal/Group/group_cipher.js.map +1 -0
  24. package/lib/Signal/Group/index.d.ts +12 -0
  25. package/lib/Signal/Group/index.d.ts.map +1 -0
  26. package/lib/Signal/Group/index.js +12 -0
  27. package/lib/Signal/Group/index.js.map +1 -0
  28. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  29. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  30. package/lib/Signal/Group/keyhelper.js +19 -0
  31. package/lib/Signal/Group/keyhelper.js.map +1 -0
  32. package/lib/Signal/Group/queue-job.d.ts +3 -0
  33. package/lib/Signal/Group/queue-job.d.ts.map +1 -0
  34. package/lib/Signal/Group/queue-job.js +57 -0
  35. package/lib/Signal/Group/queue-job.js.map +1 -0
  36. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  37. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  38. package/lib/Signal/Group/sender-chain-key.js +32 -0
  39. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  40. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  41. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  42. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  43. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  44. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  45. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  46. package/lib/Signal/Group/sender-key-message.js +67 -0
  47. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  48. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  49. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  50. package/lib/Signal/Group/sender-key-name.js +48 -0
  51. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  52. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  53. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  54. package/lib/Signal/Group/sender-key-record.js +50 -0
  55. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  56. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  57. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  58. package/lib/Signal/Group/sender-key-state.js +96 -0
  59. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  60. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  61. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  62. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +27 -39
  63. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  64. package/lib/Signal/libsignal.d.ts +3 -2
  65. package/lib/Signal/libsignal.d.ts.map +1 -0
  66. package/lib/Signal/libsignal.js +41 -61
  67. package/lib/Signal/libsignal.js.map +1 -0
  68. package/lib/Socket/Client/index.d.ts +3 -2
  69. package/lib/Socket/Client/index.d.ts.map +1 -0
  70. package/lib/Socket/Client/index.js +3 -18
  71. package/lib/Socket/Client/index.js.map +1 -0
  72. package/lib/Socket/Client/types.d.ts +2 -1
  73. package/lib/Socket/Client/types.d.ts.map +1 -0
  74. package/lib/Socket/Client/types.js +4 -6
  75. package/lib/Socket/Client/types.js.map +1 -0
  76. package/lib/Socket/Client/websocket.d.ts +2 -1
  77. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  78. package/lib/Socket/Client/websocket.js +15 -27
  79. package/lib/Socket/Client/websocket.js.map +1 -0
  80. package/lib/Socket/business.d.ts +92 -62
  81. package/lib/Socket/business.d.ts.map +1 -0
  82. package/lib/Socket/business.js +37 -42
  83. package/lib/Socket/business.js.map +1 -0
  84. package/lib/Socket/chats.d.ts +31 -24
  85. package/lib/Socket/chats.d.ts.map +1 -0
  86. package/lib/Socket/chats.js +251 -198
  87. package/lib/Socket/chats.js.map +1 -0
  88. package/lib/Socket/communities.d.ts +219 -0
  89. package/lib/Socket/communities.d.ts.map +1 -0
  90. package/lib/Socket/communities.js +351 -0
  91. package/lib/Socket/communities.js.map +1 -0
  92. package/lib/Socket/groups.d.ts +47 -39
  93. package/lib/Socket/groups.d.ts.map +1 -0
  94. package/lib/Socket/groups.js +91 -82
  95. package/lib/Socket/groups.js.map +1 -0
  96. package/lib/Socket/index.d.ts +128 -68
  97. package/lib/Socket/index.d.ts.map +1 -0
  98. package/lib/Socket/index.js +16 -9
  99. package/lib/Socket/index.js.map +1 -0
  100. package/lib/Socket/messages-recv.d.ts +79 -49
  101. package/lib/Socket/messages-recv.d.ts.map +1 -0
  102. package/lib/Socket/messages-recv.js +364 -200
  103. package/lib/Socket/messages-recv.js.map +1 -0
  104. package/lib/Socket/messages-send.d.ts +76 -46
  105. package/lib/Socket/messages-send.d.ts.map +1 -0
  106. package/lib/Socket/messages-send.js +144 -120
  107. package/lib/Socket/messages-send.js.map +1 -0
  108. package/lib/Socket/mex.d.ts +3 -0
  109. package/lib/Socket/mex.d.ts.map +1 -0
  110. package/lib/Socket/mex.js +42 -0
  111. package/lib/Socket/mex.js.map +1 -0
  112. package/lib/Socket/newsletter.d.ts +143 -0
  113. package/lib/Socket/newsletter.d.ts.map +1 -0
  114. package/lib/Socket/newsletter.js +179 -0
  115. package/lib/Socket/newsletter.js.map +1 -0
  116. package/lib/Socket/socket.d.ts +15 -14
  117. package/lib/Socket/socket.d.ts.map +1 -0
  118. package/lib/Socket/socket.js +153 -141
  119. package/lib/Socket/socket.js.map +1 -0
  120. package/lib/Socket/usync.d.ts +17 -16
  121. package/lib/Socket/usync.d.ts.map +1 -0
  122. package/lib/Socket/usync.js +19 -26
  123. package/lib/Socket/usync.js.map +1 -0
  124. package/lib/Types/Auth.d.ts +5 -4
  125. package/lib/Types/Auth.d.ts.map +1 -0
  126. package/lib/Types/Auth.js +2 -2
  127. package/lib/Types/Auth.js.map +1 -0
  128. package/lib/Types/Call.d.ts +1 -0
  129. package/lib/Types/Call.d.ts.map +1 -0
  130. package/lib/Types/Call.js +2 -2
  131. package/lib/Types/Call.js.map +1 -0
  132. package/lib/Types/Chat.d.ts +14 -8
  133. package/lib/Types/Chat.d.ts.map +1 -0
  134. package/lib/Types/Chat.js +8 -4
  135. package/lib/Types/Chat.js.map +1 -0
  136. package/lib/Types/Contact.d.ts +5 -0
  137. package/lib/Types/Contact.d.ts.map +1 -0
  138. package/lib/Types/Contact.js +2 -2
  139. package/lib/Types/Contact.js.map +1 -0
  140. package/lib/Types/Events.d.ts +38 -11
  141. package/lib/Types/Events.d.ts.map +1 -0
  142. package/lib/Types/Events.js +2 -2
  143. package/lib/Types/Events.js.map +1 -0
  144. package/lib/Types/GroupMetadata.d.ts +10 -4
  145. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  146. package/lib/Types/GroupMetadata.js +2 -2
  147. package/lib/Types/GroupMetadata.js.map +1 -0
  148. package/lib/Types/Label.d.ts +1 -0
  149. package/lib/Types/Label.d.ts.map +1 -0
  150. package/lib/Types/Label.js +3 -5
  151. package/lib/Types/Label.js.map +1 -0
  152. package/lib/Types/LabelAssociation.d.ts +1 -0
  153. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  154. package/lib/Types/LabelAssociation.js +3 -5
  155. package/lib/Types/LabelAssociation.js.map +1 -0
  156. package/lib/Types/Message.d.ts +21 -9
  157. package/lib/Types/Message.d.ts.map +1 -0
  158. package/lib/Types/Message.js +7 -7
  159. package/lib/Types/Message.js.map +1 -0
  160. package/lib/Types/Newsletter.d.ts +135 -0
  161. package/lib/Types/Newsletter.d.ts.map +1 -0
  162. package/lib/Types/Newsletter.js +31 -0
  163. package/lib/Types/Newsletter.js.map +1 -0
  164. package/lib/Types/Product.d.ts +2 -1
  165. package/lib/Types/Product.d.ts.map +1 -0
  166. package/lib/Types/Product.js +2 -2
  167. package/lib/Types/Product.js.map +1 -0
  168. package/lib/Types/Signal.d.ts +2 -1
  169. package/lib/Types/Signal.d.ts.map +1 -0
  170. package/lib/Types/Signal.js +2 -2
  171. package/lib/Types/Signal.js.map +1 -0
  172. package/lib/Types/Socket.d.ts +11 -10
  173. package/lib/Types/Socket.d.ts.map +1 -0
  174. package/lib/Types/Socket.js +3 -2
  175. package/lib/Types/Socket.js.map +1 -0
  176. package/lib/Types/State.d.ts +14 -2
  177. package/lib/Types/State.d.ts.map +1 -0
  178. package/lib/Types/State.js +13 -2
  179. package/lib/Types/State.js.map +1 -0
  180. package/lib/Types/USync.d.ts +3 -2
  181. package/lib/Types/USync.d.ts.map +1 -0
  182. package/lib/Types/USync.js +2 -2
  183. package/lib/Types/USync.js.map +1 -0
  184. package/lib/Types/index.d.ts +15 -13
  185. package/lib/Types/index.d.ts.map +1 -0
  186. package/lib/Types/index.js +15 -30
  187. package/lib/Types/index.js.map +1 -0
  188. package/lib/Utils/auth-utils.d.ts +3 -2
  189. package/lib/Utils/auth-utils.d.ts.map +1 -0
  190. package/lib/Utils/auth-utils.js +30 -40
  191. package/lib/Utils/auth-utils.js.map +1 -0
  192. package/lib/Utils/baileys-event-stream.d.ts +2 -1
  193. package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
  194. package/lib/Utils/baileys-event-stream.js +15 -22
  195. package/lib/Utils/baileys-event-stream.js.map +1 -0
  196. package/lib/Utils/business.d.ts +3 -2
  197. package/lib/Utils/business.d.ts.map +1 -0
  198. package/lib/Utils/business.js +64 -75
  199. package/lib/Utils/business.js.map +1 -0
  200. package/lib/Utils/chat-utils.d.ts +12 -11
  201. package/lib/Utils/chat-utils.d.ts.map +1 -0
  202. package/lib/Utils/chat-utils.js +195 -194
  203. package/lib/Utils/chat-utils.js.map +1 -0
  204. package/lib/Utils/crypto.d.ts +2 -1
  205. package/lib/Utils/crypto.d.ts.map +1 -0
  206. package/lib/Utils/crypto.js +40 -95
  207. package/lib/Utils/crypto.js.map +1 -0
  208. package/lib/Utils/decode-wa-message.d.ts +7 -7
  209. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  210. package/lib/Utils/decode-wa-message.js +43 -41
  211. package/lib/Utils/decode-wa-message.js.map +1 -0
  212. package/lib/Utils/event-buffer.d.ts +6 -6
  213. package/lib/Utils/event-buffer.d.ts.map +1 -0
  214. package/lib/Utils/event-buffer.js +42 -59
  215. package/lib/Utils/event-buffer.js.map +1 -0
  216. package/lib/Utils/generics.d.ts +11 -9
  217. package/lib/Utils/generics.d.ts.map +1 -0
  218. package/lib/Utils/generics.js +105 -130
  219. package/lib/Utils/generics.js.map +1 -0
  220. package/lib/Utils/history.d.ts +4 -3
  221. package/lib/Utils/history.d.ts.map +1 -0
  222. package/lib/Utils/history.js +37 -46
  223. package/lib/Utils/history.js.map +1 -0
  224. package/lib/Utils/index.d.ts +18 -17
  225. package/lib/Utils/index.d.ts.map +1 -0
  226. package/lib/Utils/index.js +18 -33
  227. package/lib/Utils/index.js.map +1 -0
  228. package/lib/Utils/link-preview.d.ts +4 -3
  229. package/lib/Utils/link-preview.d.ts.map +1 -0
  230. package/lib/Utils/link-preview.js +14 -55
  231. package/lib/Utils/link-preview.js.map +1 -0
  232. package/lib/Utils/logger.d.ts +8 -6
  233. package/lib/Utils/logger.d.ts.map +1 -0
  234. package/lib/Utils/logger.js +3 -7
  235. package/lib/Utils/logger.js.map +1 -0
  236. package/lib/Utils/lt-hash.d.ts +9 -8
  237. package/lib/Utils/lt-hash.d.ts.map +1 -0
  238. package/lib/Utils/lt-hash.js +23 -26
  239. package/lib/Utils/lt-hash.js.map +1 -0
  240. package/lib/Utils/make-mutex.d.ts +1 -0
  241. package/lib/Utils/make-mutex.d.ts.map +1 -0
  242. package/lib/Utils/make-mutex.js +6 -10
  243. package/lib/Utils/make-mutex.js.map +1 -0
  244. package/lib/Utils/messages-media.d.ts +20 -11
  245. package/lib/Utils/messages-media.d.ts.map +1 -0
  246. package/lib/Utils/messages-media.js +215 -253
  247. package/lib/Utils/messages-media.js.map +1 -0
  248. package/lib/Utils/messages.d.ts +9 -8
  249. package/lib/Utils/messages.d.ts.map +1 -0
  250. package/lib/Utils/messages.js +259 -228
  251. package/lib/Utils/messages.js.map +1 -0
  252. package/lib/Utils/noise-handler.d.ts +5 -4
  253. package/lib/Utils/noise-handler.d.ts.map +1 -0
  254. package/lib/Utils/noise-handler.js +22 -26
  255. package/lib/Utils/noise-handler.js.map +1 -0
  256. package/lib/Utils/process-message.d.ts +6 -5
  257. package/lib/Utils/process-message.d.ts.map +1 -0
  258. package/lib/Utils/process-message.js +109 -123
  259. package/lib/Utils/process-message.js.map +1 -0
  260. package/lib/Utils/signal.d.ts +5 -4
  261. package/lib/Utils/signal.d.ts.map +1 -0
  262. package/lib/Utils/signal.js +52 -55
  263. package/lib/Utils/signal.js.map +1 -0
  264. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  265. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  266. package/lib/Utils/use-multi-file-auth-state.js +23 -27
  267. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  268. package/lib/Utils/validate-connection.d.ts +4 -3
  269. package/lib/Utils/validate-connection.d.ts.map +1 -0
  270. package/lib/Utils/validate-connection.js +64 -75
  271. package/lib/Utils/validate-connection.js.map +1 -0
  272. package/lib/WABinary/constants.d.ts +5 -4
  273. package/lib/WABinary/constants.d.ts.map +1 -0
  274. package/lib/WABinary/constants.js +1280 -19
  275. package/lib/WABinary/constants.js.map +1 -0
  276. package/lib/WABinary/decode.d.ts +2 -1
  277. package/lib/WABinary/decode.d.ts.map +1 -0
  278. package/lib/WABinary/decode.js +15 -52
  279. package/lib/WABinary/decode.js.map +1 -0
  280. package/lib/WABinary/encode.d.ts +2 -1
  281. package/lib/WABinary/encode.d.ts.map +1 -0
  282. package/lib/WABinary/encode.js +7 -43
  283. package/lib/WABinary/encode.js.map +1 -0
  284. package/lib/WABinary/generic-utils.d.ts +4 -3
  285. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  286. package/lib/WABinary/generic-utils.js +31 -39
  287. package/lib/WABinary/generic-utils.js.map +1 -0
  288. package/lib/WABinary/index.d.ts +6 -5
  289. package/lib/WABinary/index.d.ts.map +1 -0
  290. package/lib/WABinary/index.js +6 -21
  291. package/lib/WABinary/index.js.map +1 -0
  292. package/lib/WABinary/jid-utils.d.ts +1 -0
  293. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  294. package/lib/WABinary/jid-utils.js +21 -38
  295. package/lib/WABinary/jid-utils.js.map +1 -0
  296. package/lib/WABinary/types.d.ts +2 -1
  297. package/lib/WABinary/types.d.ts.map +1 -0
  298. package/lib/WABinary/types.js +2 -2
  299. package/lib/WABinary/types.js.map +1 -0
  300. package/lib/WAM/BinaryInfo.d.ts +2 -1
  301. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  302. package/lib/WAM/BinaryInfo.js +2 -5
  303. package/lib/WAM/BinaryInfo.js.map +1 -0
  304. package/lib/WAM/constants.d.ts +1 -0
  305. package/lib/WAM/constants.d.ts.map +1 -0
  306. package/lib/WAM/constants.js +2257 -2366
  307. package/lib/WAM/constants.js.map +1 -0
  308. package/lib/WAM/encode.d.ts +2 -1
  309. package/lib/WAM/encode.d.ts.map +1 -0
  310. package/lib/WAM/encode.js +15 -19
  311. package/lib/WAM/encode.js.map +1 -0
  312. package/lib/WAM/index.d.ts +4 -3
  313. package/lib/WAM/index.d.ts.map +1 -0
  314. package/lib/WAM/index.js +4 -19
  315. package/lib/WAM/index.js.map +1 -0
  316. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
  317. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  318. package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
  319. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  320. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
  321. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  322. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
  323. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  324. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
  325. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  326. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
  327. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  328. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
  329. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  330. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
  331. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  332. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
  333. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  334. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
  335. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  336. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -2
  337. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  338. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -6
  339. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  340. package/lib/WAUSync/Protocols/index.d.ts +5 -4
  341. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  342. package/lib/WAUSync/Protocols/index.js +5 -20
  343. package/lib/WAUSync/Protocols/index.js.map +1 -0
  344. package/lib/WAUSync/USyncQuery.d.ts +4 -3
  345. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  346. package/lib/WAUSync/USyncQuery.js +34 -32
  347. package/lib/WAUSync/USyncQuery.js.map +1 -0
  348. package/lib/WAUSync/USyncUser.d.ts +6 -5
  349. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  350. package/lib/WAUSync/USyncUser.js +2 -5
  351. package/lib/WAUSync/USyncUser.js.map +1 -0
  352. package/lib/WAUSync/index.d.ts +4 -3
  353. package/lib/WAUSync/index.d.ts.map +1 -0
  354. package/lib/WAUSync/index.js +4 -19
  355. package/lib/WAUSync/index.js.map +1 -0
  356. package/lib/index.d.ts +9 -8
  357. package/lib/index.d.ts.map +1 -0
  358. package/lib/index.js +11 -30
  359. package/lib/index.js.map +1 -0
  360. package/package.json +36 -31
  361. package/WASignalGroup/GroupProtocol.js +0 -1697
  362. package/WASignalGroup/ciphertext_message.js +0 -16
  363. package/WASignalGroup/group_cipher.js +0 -120
  364. package/WASignalGroup/group_session_builder.js +0 -46
  365. package/WASignalGroup/index.js +0 -5
  366. package/WASignalGroup/keyhelper.js +0 -21
  367. package/WASignalGroup/protobufs.js +0 -3
  368. package/WASignalGroup/queue_job.js +0 -69
  369. package/WASignalGroup/sender_chain_key.js +0 -50
  370. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  371. package/WASignalGroup/sender_key_message.js +0 -92
  372. package/WASignalGroup/sender_key_name.js +0 -70
  373. package/WASignalGroup/sender_key_record.js +0 -56
  374. package/WASignalGroup/sender_key_state.js +0 -129
@@ -1,34 +1,31 @@
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.makeChatsSocket = void 0;
7
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
8
- const boom_1 = require("@hapi/boom");
9
- const WAProto_1 = require("../../WAProto");
10
- const Defaults_1 = require("../Defaults");
11
- const Types_1 = require("../Types");
12
- const Utils_1 = require("../Utils");
13
- const make_mutex_1 = require("../Utils/make-mutex");
14
- const process_message_1 = __importDefault(require("../Utils/process-message"));
15
- const WABinary_1 = require("../WABinary");
16
- const WAUSync_1 = require("../WAUSync");
17
- const usync_1 = require("./usync");
1
+ import NodeCache from '@cacheable/node-cache';
2
+ import { Boom } from '@hapi/boom';
3
+ import { proto } from '../../WAProto/index.js';
4
+ import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults/index.js';
5
+ import { ALL_WA_PATCH_NAMES } from '../Types/index.js';
6
+ import { SyncState } from '../Types/State.js';
7
+ import { chatModificationToAppPatch, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils/index.js';
8
+ import { makeMutex } from '../Utils/make-mutex.js';
9
+ import processMessage from '../Utils/process-message.js';
10
+ import { getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser, reduceBinaryNodeToDictionary, S_WHATSAPP_NET } from '../WABinary/index.js';
11
+ import { USyncQuery, USyncUser } from '../WAUSync/index.js';
12
+ import { makeUSyncSocket } from './usync.js';
18
13
  const MAX_SYNC_ATTEMPTS = 2;
19
- const makeChatsSocket = (config) => {
20
- const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
21
- const sock = (0, usync_1.makeUSyncSocket)(config);
22
- const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
14
+ export const makeChatsSocket = (config) => {
15
+ const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
16
+ const sock = makeUSyncSocket(config);
17
+ const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
23
18
  let privacySettings;
24
- let needToFlushWithAppStateSync = false;
25
- let pendingAppStateSync = false;
19
+ let syncState = SyncState.Connecting;
26
20
  /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
27
- const processingMutex = (0, make_mutex_1.makeMutex)();
28
- const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
29
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
30
- useClones: false
31
- });
21
+ const processingMutex = makeMutex();
22
+ // Timeout for AwaitingInitialSync state
23
+ let awaitingSyncTimeout;
24
+ const placeholderResendCache = config.placeholderResendCache ||
25
+ new NodeCache({
26
+ stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
27
+ useClones: false
28
+ });
32
29
  if (!config.placeholderResendCache) {
33
30
  config.placeholderResendCache = placeholderResendCache;
34
31
  }
@@ -43,14 +40,12 @@ const makeChatsSocket = (config) => {
43
40
  tag: 'iq',
44
41
  attrs: {
45
42
  xmlns: 'privacy',
46
- to: WABinary_1.S_WHATSAPP_NET,
43
+ to: S_WHATSAPP_NET,
47
44
  type: 'get'
48
45
  },
49
- content: [
50
- { tag: 'privacy', attrs: {} }
51
- ]
46
+ content: [{ tag: 'privacy', attrs: {} }]
52
47
  });
53
- privacySettings = (0, WABinary_1.reduceBinaryNodeToDictionary)(content === null || content === void 0 ? void 0 : content[0], 'category');
48
+ privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
54
49
  }
55
50
  return privacySettings;
56
51
  };
@@ -60,10 +55,11 @@ const makeChatsSocket = (config) => {
60
55
  tag: 'iq',
61
56
  attrs: {
62
57
  xmlns: 'privacy',
63
- to: WABinary_1.S_WHATSAPP_NET,
58
+ to: S_WHATSAPP_NET,
64
59
  type: 'set'
65
60
  },
66
- content: [{
61
+ content: [
62
+ {
67
63
  tag: 'privacy',
68
64
  attrs: {},
69
65
  content: [
@@ -72,7 +68,8 @@ const makeChatsSocket = (config) => {
72
68
  attrs: { name, value }
73
69
  }
74
70
  ]
75
- }]
71
+ }
72
+ ]
76
73
  });
77
74
  };
78
75
  const updateMessagesPrivacy = async (value) => {
@@ -104,15 +101,17 @@ const makeChatsSocket = (config) => {
104
101
  tag: 'iq',
105
102
  attrs: {
106
103
  xmlns: 'disappearing_mode',
107
- to: WABinary_1.S_WHATSAPP_NET,
104
+ to: S_WHATSAPP_NET,
108
105
  type: 'set'
109
106
  },
110
- content: [{
107
+ content: [
108
+ {
111
109
  tag: 'disappearing_mode',
112
110
  attrs: {
113
111
  duration: duration.toString()
114
112
  }
115
- }]
113
+ }
114
+ ]
116
115
  });
117
116
  };
118
117
  const getBotListV2 = async () => {
@@ -120,21 +119,23 @@ const makeChatsSocket = (config) => {
120
119
  tag: 'iq',
121
120
  attrs: {
122
121
  xmlns: 'bot',
123
- to: WABinary_1.S_WHATSAPP_NET,
122
+ to: S_WHATSAPP_NET,
124
123
  type: 'get'
125
124
  },
126
- content: [{
125
+ content: [
126
+ {
127
127
  tag: 'bot',
128
128
  attrs: {
129
129
  v: '2'
130
130
  }
131
- }]
131
+ }
132
+ ]
132
133
  });
133
- const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
134
+ const botNode = getBinaryNodeChild(resp, 'bot');
134
135
  const botList = [];
135
- for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
136
+ for (const section of getBinaryNodeChildren(botNode, 'section')) {
136
137
  if (section.attrs.type === 'all') {
137
- for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
138
+ for (const bot of getBinaryNodeChildren(section, 'bot')) {
138
139
  botList.push({
139
140
  jid: bot.attrs.jid,
140
141
  personaId: bot.attrs['persona_id']
@@ -145,23 +146,20 @@ const makeChatsSocket = (config) => {
145
146
  return botList;
146
147
  };
147
148
  const onWhatsApp = async (...jids) => {
148
- const usyncQuery = new WAUSync_1.USyncQuery()
149
- .withContactProtocol()
150
- .withLIDProtocol();
149
+ const usyncQuery = new USyncQuery().withContactProtocol().withLIDProtocol();
151
150
  for (const jid of jids) {
152
- const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
153
- usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
151
+ const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`;
152
+ usyncQuery.withUser(new USyncUser().withPhone(phone));
154
153
  }
155
154
  const results = await sock.executeUSyncQuery(usyncQuery);
156
155
  if (results) {
157
- return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
156
+ return results.list.filter(a => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
158
157
  }
159
158
  };
160
159
  const fetchStatus = async (...jids) => {
161
- const usyncQuery = new WAUSync_1.USyncQuery()
162
- .withStatusProtocol();
160
+ const usyncQuery = new USyncQuery().withStatusProtocol();
163
161
  for (const jid of jids) {
164
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
162
+ usyncQuery.withUser(new USyncUser().withId(jid));
165
163
  }
166
164
  const result = await sock.executeUSyncQuery(usyncQuery);
167
165
  if (result) {
@@ -169,10 +167,9 @@ const makeChatsSocket = (config) => {
169
167
  }
170
168
  };
171
169
  const fetchDisappearingDuration = async (...jids) => {
172
- const usyncQuery = new WAUSync_1.USyncQuery()
173
- .withDisappearingModeProtocol();
170
+ const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
174
171
  for (const jid of jids) {
175
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
172
+ usyncQuery.withUser(new USyncUser().withId(jid));
176
173
  }
177
174
  const result = await sock.executeUSyncQuery(usyncQuery);
178
175
  if (result) {
@@ -180,22 +177,25 @@ const makeChatsSocket = (config) => {
180
177
  }
181
178
  };
182
179
  /** update the profile picture for yourself or a group */
183
- const updateProfilePicture = async (jid, content) => {
180
+ const updateProfilePicture = async (jid, content, dimensions) => {
184
181
  let targetJid;
185
182
  if (!jid) {
186
- throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
183
+ throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
187
184
  }
188
- if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
189
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
185
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
186
+ targetJid = jidNormalizedUser(jid); // in case it is someone other than us
187
+ }
188
+ else {
189
+ targetJid = undefined;
190
190
  }
191
- const { img } = await (0, Utils_1.generateProfilePicture)(content);
191
+ const { img } = await generateProfilePicture(content, dimensions);
192
192
  await query({
193
193
  tag: 'iq',
194
194
  attrs: {
195
- target: targetJid,
196
- to: WABinary_1.S_WHATSAPP_NET,
195
+ to: S_WHATSAPP_NET,
197
196
  type: 'set',
198
- xmlns: 'w:profile:picture'
197
+ xmlns: 'w:profile:picture',
198
+ ...(targetJid ? { target: targetJid } : {})
199
199
  },
200
200
  content: [
201
201
  {
@@ -210,18 +210,21 @@ const makeChatsSocket = (config) => {
210
210
  const removeProfilePicture = async (jid) => {
211
211
  let targetJid;
212
212
  if (!jid) {
213
- throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
213
+ throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
214
+ }
215
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
216
+ targetJid = jidNormalizedUser(jid); // in case it is someone other than us
214
217
  }
215
- if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
216
- targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
218
+ else {
219
+ targetJid = undefined;
217
220
  }
218
221
  await query({
219
222
  tag: 'iq',
220
223
  attrs: {
221
- target: targetJid,
222
- to: WABinary_1.S_WHATSAPP_NET,
224
+ to: S_WHATSAPP_NET,
223
225
  type: 'set',
224
- xmlns: 'w:profile:picture'
226
+ xmlns: 'w:profile:picture',
227
+ ...(targetJid ? { target: targetJid } : {})
225
228
  }
226
229
  });
227
230
  };
@@ -230,7 +233,7 @@ const makeChatsSocket = (config) => {
230
233
  await query({
231
234
  tag: 'iq',
232
235
  attrs: {
233
- to: WABinary_1.S_WHATSAPP_NET,
236
+ to: S_WHATSAPP_NET,
234
237
  type: 'set',
235
238
  xmlns: 'status'
236
239
  },
@@ -251,20 +254,19 @@ const makeChatsSocket = (config) => {
251
254
  tag: 'iq',
252
255
  attrs: {
253
256
  xmlns: 'blocklist',
254
- to: WABinary_1.S_WHATSAPP_NET,
257
+ to: S_WHATSAPP_NET,
255
258
  type: 'get'
256
259
  }
257
260
  });
258
- const listNode = (0, WABinary_1.getBinaryNodeChild)(result, 'list');
259
- return (0, WABinary_1.getBinaryNodeChildren)(listNode, 'item')
260
- .map(n => n.attrs.jid);
261
+ const listNode = getBinaryNodeChild(result, 'list');
262
+ return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
261
263
  };
262
264
  const updateBlockStatus = async (jid, action) => {
263
265
  await query({
264
266
  tag: 'iq',
265
267
  attrs: {
266
268
  xmlns: 'blocklist',
267
- to: WABinary_1.S_WHATSAPP_NET,
269
+ to: S_WHATSAPP_NET,
268
270
  type: 'set'
269
271
  },
270
272
  content: [
@@ -279,7 +281,6 @@ const makeChatsSocket = (config) => {
279
281
  });
280
282
  };
281
283
  const getBusinessProfile = async (jid) => {
282
- var _a, _b, _c, _d, _e, _f, _g;
283
284
  const results = await query({
284
285
  tag: 'iq',
285
286
  attrs: {
@@ -287,38 +288,42 @@ const makeChatsSocket = (config) => {
287
288
  xmlns: 'w:biz',
288
289
  type: 'get'
289
290
  },
290
- content: [{
291
+ content: [
292
+ {
291
293
  tag: 'business_profile',
292
294
  attrs: { v: '244' },
293
- content: [{
295
+ content: [
296
+ {
294
297
  tag: 'profile',
295
298
  attrs: { jid }
296
- }]
297
- }]
299
+ }
300
+ ]
301
+ }
302
+ ]
298
303
  });
299
- const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
300
- const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
304
+ const profileNode = getBinaryNodeChild(results, 'business_profile');
305
+ const profiles = getBinaryNodeChild(profileNode, 'profile');
301
306
  if (profiles) {
302
- const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
303
- const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
304
- const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
305
- const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
306
- const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
307
- const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
307
+ const address = getBinaryNodeChild(profiles, 'address');
308
+ const description = getBinaryNodeChild(profiles, 'description');
309
+ const website = getBinaryNodeChild(profiles, 'website');
310
+ const email = getBinaryNodeChild(profiles, 'email');
311
+ const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
312
+ const businessHours = getBinaryNodeChild(profiles, 'business_hours');
308
313
  const businessHoursConfig = businessHours
309
- ? (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config')
314
+ ? getBinaryNodeChildren(businessHours, 'business_hours_config')
310
315
  : undefined;
311
- const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
316
+ const websiteStr = website?.content?.toString();
312
317
  return {
313
- wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
314
- address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
315
- description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
318
+ wid: profiles.attrs?.jid,
319
+ address: address?.content?.toString(),
320
+ description: description?.content?.toString() || '',
316
321
  website: websiteStr ? [websiteStr] : [],
317
- email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
318
- category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
319
- 'business_hours': {
320
- timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
321
- 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
322
+ email: email?.content?.toString(),
323
+ category: category?.content?.toString(),
324
+ business_hours: {
325
+ timezone: businessHours?.attrs?.timezone,
326
+ business_config: businessHoursConfig?.map(({ attrs }) => attrs)
322
327
  }
323
328
  };
324
329
  }
@@ -328,17 +333,17 @@ const makeChatsSocket = (config) => {
328
333
  await sendNode({
329
334
  tag: 'iq',
330
335
  attrs: {
331
- to: WABinary_1.S_WHATSAPP_NET,
336
+ to: S_WHATSAPP_NET,
332
337
  type: 'set',
333
338
  xmlns: 'urn:xmpp:whatsapp:dirty',
334
- id: generateMessageTag(),
339
+ id: generateMessageTag()
335
340
  },
336
341
  content: [
337
342
  {
338
343
  tag: 'clean',
339
344
  attrs: {
340
345
  type,
341
- ...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null),
346
+ ...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
342
347
  }
343
348
  }
344
349
  ]
@@ -347,7 +352,7 @@ const makeChatsSocket = (config) => {
347
352
  const newAppStateChunkHandler = (isInitialSync) => {
348
353
  return {
349
354
  onMutation(mutation) {
350
- (0, Utils_1.processSyncAction)(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
355
+ processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
351
356
  }
352
357
  };
353
358
  };
@@ -357,7 +362,6 @@ const makeChatsSocket = (config) => {
357
362
  const initialVersionMap = {};
358
363
  const globalMutationMap = {};
359
364
  await authState.keys.transaction(async () => {
360
- var _a;
361
365
  const collectionsToHandle = new Set(collections);
362
366
  // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
363
367
  const attemptsMap = {};
@@ -376,7 +380,7 @@ const makeChatsSocket = (config) => {
376
380
  }
377
381
  }
378
382
  else {
379
- state = (0, Utils_1.newLTHashState)();
383
+ state = newLTHashState();
380
384
  }
381
385
  states[name] = state;
382
386
  logger.info(`resyncing ${name} from v${state.version}`);
@@ -386,14 +390,14 @@ const makeChatsSocket = (config) => {
386
390
  name,
387
391
  version: state.version.toString(),
388
392
  // return snapshot if being synced from scratch
389
- 'return_snapshot': (!state.version).toString()
393
+ return_snapshot: (!state.version).toString()
390
394
  }
391
395
  });
392
396
  }
393
397
  const result = await query({
394
398
  tag: 'iq',
395
399
  attrs: {
396
- to: WABinary_1.S_WHATSAPP_NET,
400
+ to: S_WHATSAPP_NET,
397
401
  xmlns: 'w:sync:app:state',
398
402
  type: 'set'
399
403
  },
@@ -406,13 +410,13 @@ const makeChatsSocket = (config) => {
406
410
  ]
407
411
  });
408
412
  // extract from binary node
409
- const decoded = await (0, Utils_1.extractSyncdPatches)(result, config === null || config === void 0 ? void 0 : config.options);
413
+ const decoded = await extractSyncdPatches(result, config?.options);
410
414
  for (const key in decoded) {
411
415
  const name = key;
412
416
  const { patches, hasMorePatches, snapshot } = decoded[name];
413
417
  try {
414
418
  if (snapshot) {
415
- const { state: newState, mutationMap } = await (0, Utils_1.decodeSyncdSnapshot)(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
419
+ const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
416
420
  states[name] = newState;
417
421
  Object.assign(globalMutationMap, mutationMap);
418
422
  logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
@@ -420,7 +424,7 @@ const makeChatsSocket = (config) => {
420
424
  }
421
425
  // only process if there are syncd patches
422
426
  if (patches.length) {
423
- const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
427
+ const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
424
428
  await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
425
429
  logger.info(`synced ${name} to v${newState.version}`);
426
430
  initialVersionMap[name] = newState.version;
@@ -429,16 +433,17 @@ const makeChatsSocket = (config) => {
429
433
  if (hasMorePatches) {
430
434
  logger.info(`${name} has more patches...`);
431
435
  }
432
- else { // collection is done with sync
436
+ else {
437
+ // collection is done with sync
433
438
  collectionsToHandle.delete(name);
434
439
  }
435
440
  }
436
441
  catch (error) {
437
442
  // if retry attempts overshoot
438
443
  // or key not found
439
- const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
440
- || ((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404
441
- || error.name === 'TypeError';
444
+ const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
445
+ error.output?.statusCode === 404 ||
446
+ error.name === 'TypeError';
442
447
  logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
443
448
  await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
444
449
  // increment number of retries
@@ -462,22 +467,19 @@ const makeChatsSocket = (config) => {
462
467
  * type = "image for the high res picture"
463
468
  */
464
469
  const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
465
- var _a;
466
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
470
+ jid = jidNormalizedUser(jid);
467
471
  const result = await query({
468
472
  tag: 'iq',
469
473
  attrs: {
470
474
  target: jid,
471
- to: WABinary_1.S_WHATSAPP_NET,
475
+ to: S_WHATSAPP_NET,
472
476
  type: 'get',
473
477
  xmlns: 'w:profile:picture'
474
478
  },
475
- content: [
476
- { tag: 'picture', attrs: { type, query: 'url' } }
477
- ]
479
+ content: [{ tag: 'picture', attrs: { type, query: 'url' } }]
478
480
  }, timeoutMs);
479
- const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
480
- return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
481
+ const child = getBinaryNodeChild(result, 'picture');
482
+ return child?.attrs?.url;
481
483
  };
482
484
  const sendPresenceUpdate = async (type, toJid) => {
483
485
  const me = authState.creds.me;
@@ -490,17 +492,19 @@ const makeChatsSocket = (config) => {
490
492
  await sendNode({
491
493
  tag: 'presence',
492
494
  attrs: {
493
- name: me.name,
495
+ name: me.name.replace(/@/g, ''),
494
496
  type
495
497
  }
496
498
  });
497
499
  }
498
500
  else {
501
+ const { server } = jidDecode(toJid);
502
+ const isLid = server === 'lid';
499
503
  await sendNode({
500
504
  tag: 'chatstate',
501
505
  attrs: {
502
- from: me.id,
503
- to: toJid,
506
+ from: isLid ? me.lid : me.id,
507
+ to: toJid
504
508
  },
505
509
  content: [
506
510
  {
@@ -515,7 +519,7 @@ const makeChatsSocket = (config) => {
515
519
  * @param toJid the jid to subscribe to
516
520
  * @param tcToken token for subscription, use if present
517
521
  */
518
- const presenceSubscribe = (toJid, tcToken) => (sendNode({
522
+ const presenceSubscribe = (toJid, tcToken) => sendNode({
519
523
  tag: 'presence',
520
524
  attrs: {
521
525
  to: toJid,
@@ -531,9 +535,8 @@ const makeChatsSocket = (config) => {
531
535
  }
532
536
  ]
533
537
  : undefined
534
- }));
538
+ });
535
539
  const handlePresenceUpdate = ({ tag, attrs, content }) => {
536
- var _a;
537
540
  let presence;
538
541
  const jid = attrs.from;
539
542
  const participant = attrs.participant || attrs.from;
@@ -552,7 +555,7 @@ const makeChatsSocket = (config) => {
552
555
  if (type === 'paused') {
553
556
  type = 'available';
554
557
  }
555
- if (((_a = firstChild.attrs) === null || _a === void 0 ? void 0 : _a.media) === 'audio') {
558
+ if (firstChild.attrs?.media === 'audio') {
556
559
  type = 'recording';
557
560
  }
558
561
  presence = { lastKnownPresence: type };
@@ -568,7 +571,7 @@ const makeChatsSocket = (config) => {
568
571
  const name = patchCreate.type;
569
572
  const myAppStateKeyId = authState.creds.myAppStateKeyId;
570
573
  if (!myAppStateKeyId) {
571
- throw new boom_1.Boom('App state key not present!', { statusCode: 400 });
574
+ throw new Boom('App state key not present!', { statusCode: 400 });
572
575
  }
573
576
  let initial;
574
577
  let encodeResult;
@@ -577,13 +580,13 @@ const makeChatsSocket = (config) => {
577
580
  logger.debug({ patch: patchCreate }, 'applying app patch');
578
581
  await resyncAppState([name], false);
579
582
  const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
580
- initial = currentSyncVersion || (0, Utils_1.newLTHashState)();
581
- encodeResult = await (0, Utils_1.encodeSyncdPatch)(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
583
+ initial = currentSyncVersion || newLTHashState();
584
+ encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
582
585
  const { patch, state } = encodeResult;
583
586
  const node = {
584
587
  tag: 'iq',
585
588
  attrs: {
586
- to: WABinary_1.S_WHATSAPP_NET,
589
+ to: S_WHATSAPP_NET,
587
590
  type: 'set',
588
591
  xmlns: 'w:sync:app:state'
589
592
  },
@@ -597,13 +600,13 @@ const makeChatsSocket = (config) => {
597
600
  attrs: {
598
601
  name,
599
602
  version: (state.version - 1).toString(),
600
- 'return_snapshot': 'false'
603
+ return_snapshot: 'false'
601
604
  },
602
605
  content: [
603
606
  {
604
607
  tag: 'patch',
605
608
  attrs: {},
606
- content: WAProto_1.proto.SyncdPatch.encode(patch).finish()
609
+ content: proto.SyncdPatch.encode(patch).finish()
607
610
  }
608
611
  ]
609
612
  }
@@ -617,7 +620,7 @@ const makeChatsSocket = (config) => {
617
620
  });
618
621
  if (config.emitOwnEvents) {
619
622
  const { onMutation } = newAppStateChunkHandler(false);
620
- const { mutationMap } = await (0, Utils_1.decodePatches)(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version }, }], initial, getAppStateSyncKey, config.options, undefined, logger);
623
+ const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
621
624
  for (const key in mutationMap) {
622
625
  onMutation(mutationMap[key]);
623
626
  }
@@ -625,29 +628,32 @@ const makeChatsSocket = (config) => {
625
628
  };
626
629
  /** sending non-abt props may fix QR scan fail if server expects */
627
630
  const fetchProps = async () => {
628
- var _a, _b, _c;
629
631
  const resultNode = await query({
630
632
  tag: 'iq',
631
633
  attrs: {
632
- to: WABinary_1.S_WHATSAPP_NET,
634
+ to: S_WHATSAPP_NET,
633
635
  xmlns: 'w',
634
- type: 'get',
636
+ type: 'get'
635
637
  },
636
638
  content: [
637
- { tag: 'props', attrs: {
639
+ {
640
+ tag: 'props',
641
+ attrs: {
638
642
  protocol: '2',
639
- hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
640
- } }
643
+ hash: authState?.creds?.lastPropHash || ''
644
+ }
645
+ }
641
646
  ]
642
647
  });
643
- const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
648
+ const propsNode = getBinaryNodeChild(resultNode, 'props');
644
649
  let props = {};
645
650
  if (propsNode) {
646
- if ((_b = propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash) { // on some clients, the hash is returning as undefined
647
- authState.creds.lastPropHash = (_c = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _c === void 0 ? void 0 : _c.hash;
651
+ if (propsNode.attrs?.hash) {
652
+ // on some clients, the hash is returning as undefined
653
+ authState.creds.lastPropHash = propsNode?.attrs?.hash;
648
654
  ev.emit('creds.update', authState.creds);
649
655
  }
650
- props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
656
+ props = reduceBinaryNodeToDictionary(propsNode, 'prop');
651
657
  }
652
658
  logger.debug('fetched props');
653
659
  return props;
@@ -656,11 +662,19 @@ const makeChatsSocket = (config) => {
656
662
  * modify a chat -- mark unread, read etc.
657
663
  * lastMessages must be sorted in reverse chronologically
658
664
  * requires the last messages till the last message received; required for archive & unread
659
- */
665
+ */
660
666
  const chatModify = (mod, jid) => {
661
- const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
667
+ const patch = chatModificationToAppPatch(mod, jid);
662
668
  return appPatch(patch);
663
669
  };
670
+ /**
671
+ * Enable/Disable link preview privacy, not related to baileys link preview generation
672
+ */
673
+ const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
674
+ return chatModify({
675
+ disableLinkPreviews: { isPreviewsDisabled }
676
+ }, '');
677
+ };
664
678
  /**
665
679
  * Star or Unstar a message
666
680
  */
@@ -672,6 +686,22 @@ const makeChatsSocket = (config) => {
672
686
  }
673
687
  }, jid);
674
688
  };
689
+ /**
690
+ * Add or Edit Contact
691
+ */
692
+ const addOrEditContact = (jid, contact) => {
693
+ return chatModify({
694
+ contact
695
+ }, jid);
696
+ };
697
+ /**
698
+ * Remove Contact
699
+ */
700
+ const removeContact = (jid) => {
701
+ return chatModify({
702
+ contact: null
703
+ }, jid);
704
+ };
675
705
  /**
676
706
  * Adds label
677
707
  */
@@ -729,75 +759,80 @@ const makeChatsSocket = (config) => {
729
759
  * help ensure parity with WA Web
730
760
  * */
731
761
  const executeInitQueries = async () => {
732
- await Promise.all([
733
- fetchProps(),
734
- fetchBlocklist(),
735
- fetchPrivacySettings(),
736
- ]);
762
+ await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
737
763
  };
738
764
  const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
739
- var _a, _b, _c;
740
765
  ev.emit('messages.upsert', { messages: [msg], type });
741
766
  if (!!msg.pushName) {
742
- let jid = msg.key.fromMe ? authState.creds.me.id : (msg.key.participant || msg.key.remoteJid);
743
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
767
+ let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
768
+ jid = jidNormalizedUser(jid);
744
769
  if (!msg.key.fromMe) {
745
770
  ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
746
771
  }
747
772
  // update our pushname too
748
- if (msg.key.fromMe && msg.pushName && ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.name) !== msg.pushName) {
773
+ if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
749
774
  ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
750
775
  }
751
776
  }
752
- const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
777
+ const historyMsg = getHistoryMsg(msg.message);
753
778
  const shouldProcessHistoryMsg = historyMsg
754
- ? (shouldSyncHistoryMessage(historyMsg)
755
- && Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType))
779
+ ? shouldSyncHistoryMessage(historyMsg) && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
756
780
  : false;
757
- if (historyMsg && !authState.creds.myAppStateKeyId) {
758
- logger.warn('skipping app state sync, as myAppStateKeyId is not set');
759
- pendingAppStateSync = true;
781
+ // State machine: decide on sync and flush
782
+ if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
783
+ if (awaitingSyncTimeout) {
784
+ clearTimeout(awaitingSyncTimeout);
785
+ awaitingSyncTimeout = undefined;
786
+ }
787
+ if (shouldProcessHistoryMsg) {
788
+ syncState = SyncState.Syncing;
789
+ logger.info('Transitioned to Syncing state');
790
+ // Let doAppStateSync handle the final flush after it's done
791
+ }
792
+ else {
793
+ syncState = SyncState.Online;
794
+ logger.info('History sync skipped, transitioning to Online state and flushing buffer');
795
+ ev.flush();
796
+ }
760
797
  }
798
+ const doAppStateSync = async () => {
799
+ if (syncState === SyncState.Syncing) {
800
+ logger.info('Doing app state sync');
801
+ await resyncAppState(ALL_WA_PATCH_NAMES, true);
802
+ // Sync is complete, go online and flush everything
803
+ syncState = SyncState.Online;
804
+ logger.info('App state sync complete, transitioning to Online state and flushing buffer');
805
+ ev.flush();
806
+ const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
807
+ ev.emit('creds.update', { accountSyncCounter });
808
+ }
809
+ };
761
810
  await Promise.all([
762
811
  (async () => {
763
- if (historyMsg
764
- && authState.creds.myAppStateKeyId) {
765
- pendingAppStateSync = false;
812
+ if (shouldProcessHistoryMsg) {
766
813
  await doAppStateSync();
767
814
  }
768
815
  })(),
769
- (0, process_message_1.default)(msg, {
816
+ processMessage(msg, {
770
817
  shouldProcessHistoryMsg,
771
818
  placeholderResendCache,
772
819
  ev,
773
820
  creds: authState.creds,
774
821
  keyStore: authState.keys,
775
822
  logger,
776
- options: config.options,
823
+ options: config.options
777
824
  })
778
825
  ]);
779
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
780
- && pendingAppStateSync) {
826
+ // If the app state key arrives and we are waiting to sync, trigger the sync now.
827
+ if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
828
+ logger.info('App state sync key arrived, triggering app state sync');
781
829
  await doAppStateSync();
782
- pendingAppStateSync = false;
783
- }
784
- async function doAppStateSync() {
785
- if (!authState.creds.accountSyncCounter) {
786
- logger.info('doing initial app state sync');
787
- await resyncAppState(Types_1.ALL_WA_PATCH_NAMES, true);
788
- const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
789
- ev.emit('creds.update', { accountSyncCounter });
790
- if (needToFlushWithAppStateSync) {
791
- logger.debug('flushing with app state sync');
792
- ev.flush();
793
- }
794
- }
795
830
  }
796
831
  });
797
832
  ws.on('CB:presence', handlePresenceUpdate);
798
833
  ws.on('CB:chatstate', handlePresenceUpdate);
799
834
  ws.on('CB:ib,,dirty', async (node) => {
800
- const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
835
+ const { attrs } = getBinaryNodeChild(node, 'dirty');
801
836
  const type = attrs.type;
802
837
  switch (type) {
803
838
  case 'account_sync':
@@ -819,23 +854,38 @@ const makeChatsSocket = (config) => {
819
854
  }
820
855
  });
821
856
  ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
822
- var _a;
823
857
  if (connection === 'open') {
824
858
  if (fireInitQueries) {
825
- executeInitQueries()
826
- .catch(error => onUnexpectedError(error, 'init queries'));
859
+ executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
827
860
  }
828
- sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
829
- .catch(error => onUnexpectedError(error, 'presence update requests'));
861
+ sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
830
862
  }
831
- if (receivedPendingNotifications && // if we don't have the app state key
832
- // we keep buffering events until we finally have
833
- // the key and can sync the messages
834
- // todo scrutinize
835
- !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
836
- ev.buffer();
837
- needToFlushWithAppStateSync = true;
863
+ if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
864
+ return;
838
865
  }
866
+ syncState = SyncState.AwaitingInitialSync;
867
+ logger.info('Connection is now AwaitingInitialSync, buffering events');
868
+ ev.buffer();
869
+ const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.fromObject({
870
+ syncType: proto.HistorySync.HistorySyncType.RECENT
871
+ }));
872
+ if (!willSyncHistory) {
873
+ logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
874
+ syncState = SyncState.Online;
875
+ setTimeout(() => ev.flush(), 0);
876
+ return;
877
+ }
878
+ logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
879
+ if (awaitingSyncTimeout) {
880
+ clearTimeout(awaitingSyncTimeout);
881
+ }
882
+ awaitingSyncTimeout = setTimeout(() => {
883
+ if (syncState === SyncState.AwaitingInitialSync) {
884
+ logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
885
+ syncState = SyncState.Online;
886
+ ev.flush();
887
+ }
888
+ }, 20000);
839
889
  });
840
890
  return {
841
891
  ...sock,
@@ -856,6 +906,7 @@ const makeChatsSocket = (config) => {
856
906
  updateProfileStatus,
857
907
  updateProfileName,
858
908
  updateBlockStatus,
909
+ updateDisableLinkPreviewsPrivacy,
859
910
  updateCallPrivacy,
860
911
  updateMessagesPrivacy,
861
912
  updateLastSeenPrivacy,
@@ -869,6 +920,8 @@ const makeChatsSocket = (config) => {
869
920
  resyncAppState,
870
921
  chatModify,
871
922
  cleanDirtyBits,
923
+ addOrEditContact,
924
+ removeContact,
872
925
  addLabel,
873
926
  addChatLabel,
874
927
  removeChatLabel,
@@ -877,4 +930,4 @@ const makeChatsSocket = (config) => {
877
930
  star
878
931
  };
879
932
  };
880
- exports.makeChatsSocket = makeChatsSocket;
933
+ //# sourceMappingURL=chats.js.map