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