@d0v3riz/baileys 6.7.22 → 6.7.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (356) hide show
  1. package/WAProto/GenerateStatics.sh +3 -2
  2. package/WAProto/fix-imports.js +29 -0
  3. package/WAProto/index.js +4136 -4138
  4. package/lib/Defaults/index.d.ts +3 -2
  5. package/lib/Defaults/index.d.ts.map +1 -0
  6. package/lib/Defaults/index.js +36 -40
  7. package/lib/Defaults/index.js.map +1 -0
  8. package/lib/Signal/Group/ciphertext-message.d.ts +1 -0
  9. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  10. package/lib/Signal/Group/ciphertext-message.js +2 -5
  11. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  12. package/lib/Signal/Group/group-session-builder.d.ts +4 -3
  13. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  14. package/lib/Signal/Group/group-session-builder.js +7 -41
  15. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  16. package/lib/Signal/Group/group_cipher.d.ts +3 -2
  17. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  18. package/lib/Signal/Group/group_cipher.js +14 -16
  19. package/lib/Signal/Group/group_cipher.js.map +1 -0
  20. package/lib/Signal/Group/index.d.ts +12 -11
  21. package/lib/Signal/Group/index.d.ts.map +1 -0
  22. package/lib/Signal/Group/index.js +12 -57
  23. package/lib/Signal/Group/index.js.map +1 -0
  24. package/lib/Signal/Group/keyhelper.d.ts +2 -1
  25. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  26. package/lib/Signal/Group/keyhelper.js +8 -44
  27. package/lib/Signal/Group/keyhelper.js.map +1 -0
  28. package/lib/Signal/Group/queue-job.d.ts +2 -0
  29. package/lib/Signal/Group/queue-job.d.ts.map +1 -0
  30. package/lib/Signal/Group/queue-job.js +5 -5
  31. package/lib/Signal/Group/queue-job.js.map +1 -0
  32. package/lib/Signal/Group/sender-chain-key.d.ts +2 -1
  33. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  34. package/lib/Signal/Group/sender-chain-key.js +7 -9
  35. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  36. package/lib/Signal/Group/sender-key-distribution-message.d.ts +2 -1
  37. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  38. package/lib/Signal/Group/sender-key-distribution-message.js +6 -9
  39. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  40. package/lib/Signal/Group/sender-key-message.d.ts +2 -1
  41. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  42. package/lib/Signal/Group/sender-key-message.js +10 -12
  43. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  44. package/lib/Signal/Group/sender-key-name.d.ts +1 -0
  45. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  46. package/lib/Signal/Group/sender-key-name.js +2 -5
  47. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  48. package/lib/Signal/Group/sender-key-record.d.ts +2 -1
  49. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  50. package/lib/Signal/Group/sender-key-record.js +9 -12
  51. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  52. package/lib/Signal/Group/sender-key-state.d.ts +3 -2
  53. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  54. package/lib/Signal/Group/sender-key-state.js +6 -9
  55. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  56. package/lib/Signal/Group/sender-message-key.d.ts +1 -0
  57. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  58. package/lib/Signal/Group/sender-message-key.js +5 -7
  59. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  60. package/lib/Signal/libsignal.d.ts +3 -2
  61. package/lib/Signal/libsignal.d.ts.map +1 -0
  62. package/lib/Signal/libsignal.js +22 -55
  63. package/lib/Signal/libsignal.js.map +1 -0
  64. package/lib/Socket/Client/index.d.ts +3 -2
  65. package/lib/Socket/Client/index.d.ts.map +1 -0
  66. package/lib/Socket/Client/index.js +3 -18
  67. package/lib/Socket/Client/index.js.map +1 -0
  68. package/lib/Socket/Client/types.d.ts +2 -1
  69. package/lib/Socket/Client/types.d.ts.map +1 -0
  70. package/lib/Socket/Client/types.js +4 -6
  71. package/lib/Socket/Client/types.js.map +1 -0
  72. package/lib/Socket/Client/websocket.d.ts +2 -1
  73. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  74. package/lib/Socket/Client/websocket.js +14 -26
  75. package/lib/Socket/Client/websocket.js.map +1 -0
  76. package/lib/Socket/business.d.ts +66 -64
  77. package/lib/Socket/business.d.ts.map +1 -0
  78. package/lib/Socket/business.js +32 -37
  79. package/lib/Socket/business.js.map +1 -0
  80. package/lib/Socket/chats.d.ts +21 -19
  81. package/lib/Socket/chats.d.ts.map +1 -0
  82. package/lib/Socket/chats.js +176 -141
  83. package/lib/Socket/chats.js.map +1 -0
  84. package/lib/Socket/communities.d.ts +219 -0
  85. package/lib/Socket/communities.d.ts.map +1 -0
  86. package/lib/Socket/communities.js +351 -0
  87. package/lib/Socket/communities.js.map +1 -0
  88. package/lib/Socket/groups.d.ts +37 -35
  89. package/lib/Socket/groups.d.ts.map +1 -0
  90. package/lib/Socket/groups.js +56 -63
  91. package/lib/Socket/groups.js.map +1 -0
  92. package/lib/Socket/index.d.ts +102 -70
  93. package/lib/Socket/index.d.ts.map +1 -0
  94. package/lib/Socket/index.js +16 -9
  95. package/lib/Socket/index.js.map +1 -0
  96. package/lib/Socket/messages-recv.d.ts +51 -49
  97. package/lib/Socket/messages-recv.d.ts.map +1 -0
  98. package/lib/Socket/messages-recv.js +180 -173
  99. package/lib/Socket/messages-recv.js.map +1 -0
  100. package/lib/Socket/messages-send.d.ts +48 -46
  101. package/lib/Socket/messages-send.d.ts.map +1 -0
  102. package/lib/Socket/messages-send.js +75 -84
  103. package/lib/Socket/messages-send.js.map +1 -0
  104. package/lib/Socket/mex.d.ts +2 -1
  105. package/lib/Socket/mex.d.ts.map +1 -0
  106. package/lib/Socket/mex.js +12 -16
  107. package/lib/Socket/mex.js.map +1 -0
  108. package/lib/Socket/newsletter.d.ts +46 -44
  109. package/lib/Socket/newsletter.d.ts.map +1 -0
  110. package/lib/Socket/newsletter.js +23 -27
  111. package/lib/Socket/newsletter.js.map +1 -0
  112. package/lib/Socket/socket.d.ts +13 -12
  113. package/lib/Socket/socket.d.ts.map +1 -0
  114. package/lib/Socket/socket.js +135 -115
  115. package/lib/Socket/socket.js.map +1 -0
  116. package/lib/Socket/usync.d.ts +15 -14
  117. package/lib/Socket/usync.d.ts.map +1 -0
  118. package/lib/Socket/usync.js +9 -11
  119. package/lib/Socket/usync.js.map +1 -0
  120. package/lib/Types/Auth.d.ts +4 -3
  121. package/lib/Types/Auth.d.ts.map +1 -0
  122. package/lib/Types/Auth.js +2 -2
  123. package/lib/Types/Auth.js.map +1 -0
  124. package/lib/Types/Call.d.ts +1 -0
  125. package/lib/Types/Call.d.ts.map +1 -0
  126. package/lib/Types/Call.js +2 -2
  127. package/lib/Types/Call.js.map +1 -0
  128. package/lib/Types/Chat.d.ts +10 -7
  129. package/lib/Types/Chat.d.ts.map +1 -0
  130. package/lib/Types/Chat.js +2 -4
  131. package/lib/Types/Chat.js.map +1 -0
  132. package/lib/Types/Contact.d.ts +1 -0
  133. package/lib/Types/Contact.d.ts.map +1 -0
  134. package/lib/Types/Contact.js +2 -2
  135. package/lib/Types/Contact.js.map +1 -0
  136. package/lib/Types/Events.d.ts +11 -10
  137. package/lib/Types/Events.d.ts.map +1 -0
  138. package/lib/Types/Events.js +2 -2
  139. package/lib/Types/Events.js.map +1 -0
  140. package/lib/Types/GroupMetadata.d.ts +3 -2
  141. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  142. package/lib/Types/GroupMetadata.js +2 -2
  143. package/lib/Types/GroupMetadata.js.map +1 -0
  144. package/lib/Types/Label.d.ts +1 -0
  145. package/lib/Types/Label.d.ts.map +1 -0
  146. package/lib/Types/Label.js +3 -5
  147. package/lib/Types/Label.js.map +1 -0
  148. package/lib/Types/LabelAssociation.d.ts +1 -0
  149. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  150. package/lib/Types/LabelAssociation.js +3 -5
  151. package/lib/Types/LabelAssociation.js.map +1 -0
  152. package/lib/Types/Message.d.ts +9 -7
  153. package/lib/Types/Message.d.ts.map +1 -0
  154. package/lib/Types/Message.js +7 -7
  155. package/lib/Types/Message.js.map +1 -0
  156. package/lib/Types/Newsletter.d.ts +1 -0
  157. package/lib/Types/Newsletter.d.ts.map +1 -0
  158. package/lib/Types/Newsletter.js +5 -7
  159. package/lib/Types/Newsletter.js.map +1 -0
  160. package/lib/Types/Product.d.ts +2 -1
  161. package/lib/Types/Product.d.ts.map +1 -0
  162. package/lib/Types/Product.js +2 -2
  163. package/lib/Types/Product.js.map +1 -0
  164. package/lib/Types/Signal.d.ts +2 -1
  165. package/lib/Types/Signal.d.ts.map +1 -0
  166. package/lib/Types/Signal.js +2 -2
  167. package/lib/Types/Signal.js.map +1 -0
  168. package/lib/Types/Socket.d.ts +8 -7
  169. package/lib/Types/Socket.d.ts.map +1 -0
  170. package/lib/Types/Socket.js +3 -2
  171. package/lib/Types/Socket.js.map +1 -0
  172. package/lib/Types/State.d.ts +14 -2
  173. package/lib/Types/State.d.ts.map +1 -0
  174. package/lib/Types/State.js +13 -2
  175. package/lib/Types/State.js.map +1 -0
  176. package/lib/Types/USync.d.ts +3 -2
  177. package/lib/Types/USync.d.ts.map +1 -0
  178. package/lib/Types/USync.js +2 -2
  179. package/lib/Types/USync.js.map +1 -0
  180. package/lib/Types/index.d.ts +15 -14
  181. package/lib/Types/index.d.ts.map +1 -0
  182. package/lib/Types/index.js +15 -31
  183. package/lib/Types/index.js.map +1 -0
  184. package/lib/Utils/auth-utils.d.ts +3 -2
  185. package/lib/Utils/auth-utils.d.ts.map +1 -0
  186. package/lib/Utils/auth-utils.js +25 -34
  187. package/lib/Utils/auth-utils.js.map +1 -0
  188. package/lib/Utils/baileys-event-stream.d.ts +2 -1
  189. package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
  190. package/lib/Utils/baileys-event-stream.js +15 -22
  191. package/lib/Utils/baileys-event-stream.js.map +1 -0
  192. package/lib/Utils/business.d.ts +3 -2
  193. package/lib/Utils/business.d.ts.map +1 -0
  194. package/lib/Utils/business.js +61 -70
  195. package/lib/Utils/business.js.map +1 -0
  196. package/lib/Utils/chat-utils.d.ts +8 -7
  197. package/lib/Utils/chat-utils.d.ts.map +1 -0
  198. package/lib/Utils/chat-utils.js +130 -137
  199. package/lib/Utils/chat-utils.js.map +1 -0
  200. package/lib/Utils/crypto.d.ts +2 -1
  201. package/lib/Utils/crypto.d.ts.map +1 -0
  202. package/lib/Utils/crypto.js +37 -86
  203. package/lib/Utils/crypto.js.map +1 -0
  204. package/lib/Utils/decode-wa-message.d.ts +5 -4
  205. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  206. package/lib/Utils/decode-wa-message.js +38 -44
  207. package/lib/Utils/decode-wa-message.js.map +1 -0
  208. package/lib/Utils/event-buffer.d.ts +4 -4
  209. package/lib/Utils/event-buffer.d.ts.map +1 -0
  210. package/lib/Utils/event-buffer.js +37 -50
  211. package/lib/Utils/event-buffer.js.map +1 -0
  212. package/lib/Utils/generics.d.ts +9 -8
  213. package/lib/Utils/generics.d.ts.map +1 -0
  214. package/lib/Utils/generics.js +87 -114
  215. package/lib/Utils/generics.js.map +1 -0
  216. package/lib/Utils/history.d.ts +4 -3
  217. package/lib/Utils/history.d.ts.map +1 -0
  218. package/lib/Utils/history.js +32 -40
  219. package/lib/Utils/history.js.map +1 -0
  220. package/lib/Utils/index.d.ts +18 -17
  221. package/lib/Utils/index.d.ts.map +1 -0
  222. package/lib/Utils/index.js +18 -33
  223. package/lib/Utils/index.js.map +1 -0
  224. package/lib/Utils/link-preview.d.ts +4 -3
  225. package/lib/Utils/link-preview.d.ts.map +1 -0
  226. package/lib/Utils/link-preview.js +10 -47
  227. package/lib/Utils/link-preview.js.map +1 -0
  228. package/lib/Utils/logger.d.ts +8 -6
  229. package/lib/Utils/logger.d.ts.map +1 -0
  230. package/lib/Utils/logger.js +3 -7
  231. package/lib/Utils/logger.js.map +1 -0
  232. package/lib/Utils/lt-hash.d.ts +9 -8
  233. package/lib/Utils/lt-hash.d.ts.map +1 -0
  234. package/lib/Utils/lt-hash.js +23 -26
  235. package/lib/Utils/lt-hash.js.map +1 -0
  236. package/lib/Utils/make-mutex.d.ts +1 -0
  237. package/lib/Utils/make-mutex.d.ts.map +1 -0
  238. package/lib/Utils/make-mutex.js +5 -9
  239. package/lib/Utils/make-mutex.js.map +1 -0
  240. package/lib/Utils/messages-media.d.ts +11 -10
  241. package/lib/Utils/messages-media.d.ts.map +1 -0
  242. package/lib/Utils/messages-media.js +141 -203
  243. package/lib/Utils/messages-media.js.map +1 -0
  244. package/lib/Utils/messages.d.ts +7 -6
  245. package/lib/Utils/messages.d.ts.map +1 -0
  246. package/lib/Utils/messages.js +190 -199
  247. package/lib/Utils/messages.js.map +1 -0
  248. package/lib/Utils/noise-handler.d.ts +5 -4
  249. package/lib/Utils/noise-handler.d.ts.map +1 -0
  250. package/lib/Utils/noise-handler.js +22 -26
  251. package/lib/Utils/noise-handler.js.map +1 -0
  252. package/lib/Utils/process-message.d.ts +5 -4
  253. package/lib/Utils/process-message.d.ts.map +1 -0
  254. package/lib/Utils/process-message.js +95 -104
  255. package/lib/Utils/process-message.js.map +1 -0
  256. package/lib/Utils/signal.d.ts +5 -4
  257. package/lib/Utils/signal.d.ts.map +1 -0
  258. package/lib/Utils/signal.js +47 -52
  259. package/lib/Utils/signal.js.map +1 -0
  260. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  261. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  262. package/lib/Utils/use-multi-file-auth-state.js +23 -26
  263. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  264. package/lib/Utils/validate-connection.d.ts +4 -3
  265. package/lib/Utils/validate-connection.d.ts.map +1 -0
  266. package/lib/Utils/validate-connection.js +52 -58
  267. package/lib/Utils/validate-connection.js.map +1 -0
  268. package/lib/WABinary/constants.d.ts +1 -0
  269. package/lib/WABinary/constants.d.ts.map +1 -0
  270. package/lib/WABinary/constants.js +9 -11
  271. package/lib/WABinary/constants.js.map +1 -0
  272. package/lib/WABinary/decode.d.ts +2 -1
  273. package/lib/WABinary/decode.d.ts.map +1 -0
  274. package/lib/WABinary/decode.js +13 -51
  275. package/lib/WABinary/decode.js.map +1 -0
  276. package/lib/WABinary/encode.d.ts +2 -1
  277. package/lib/WABinary/encode.d.ts.map +1 -0
  278. package/lib/WABinary/encode.js +5 -41
  279. package/lib/WABinary/encode.js.map +1 -0
  280. package/lib/WABinary/generic-utils.d.ts +4 -3
  281. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  282. package/lib/WABinary/generic-utils.js +30 -38
  283. package/lib/WABinary/generic-utils.js.map +1 -0
  284. package/lib/WABinary/index.d.ts +6 -5
  285. package/lib/WABinary/index.d.ts.map +1 -0
  286. package/lib/WABinary/index.js +6 -21
  287. package/lib/WABinary/index.js.map +1 -0
  288. package/lib/WABinary/jid-utils.d.ts +1 -0
  289. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  290. package/lib/WABinary/jid-utils.js +21 -35
  291. package/lib/WABinary/jid-utils.js.map +1 -0
  292. package/lib/WABinary/types.d.ts +2 -1
  293. package/lib/WABinary/types.d.ts.map +1 -0
  294. package/lib/WABinary/types.js +2 -2
  295. package/lib/WABinary/types.js.map +1 -0
  296. package/lib/WAM/BinaryInfo.d.ts +2 -1
  297. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  298. package/lib/WAM/BinaryInfo.js +2 -5
  299. package/lib/WAM/BinaryInfo.js.map +1 -0
  300. package/lib/WAM/constants.d.ts +1 -0
  301. package/lib/WAM/constants.d.ts.map +1 -0
  302. package/lib/WAM/constants.js +4 -6
  303. package/lib/WAM/constants.js.map +1 -0
  304. package/lib/WAM/encode.d.ts +2 -1
  305. package/lib/WAM/encode.d.ts.map +1 -0
  306. package/lib/WAM/encode.js +12 -14
  307. package/lib/WAM/encode.js.map +1 -0
  308. package/lib/WAM/index.d.ts +4 -3
  309. package/lib/WAM/index.d.ts.map +1 -0
  310. package/lib/WAM/index.js +4 -19
  311. package/lib/WAM/index.js.map +1 -0
  312. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
  313. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  314. package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -9
  315. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  316. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
  317. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  318. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -12
  319. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  320. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
  321. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  322. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -9
  323. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  324. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
  325. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  326. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -11
  327. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  328. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
  329. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  330. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +19 -21
  331. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  332. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -2
  333. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  334. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +2 -5
  335. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  336. package/lib/WAUSync/Protocols/index.d.ts +5 -4
  337. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  338. package/lib/WAUSync/Protocols/index.js +5 -20
  339. package/lib/WAUSync/Protocols/index.js.map +1 -0
  340. package/lib/WAUSync/USyncQuery.d.ts +4 -3
  341. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  342. package/lib/WAUSync/USyncQuery.js +18 -20
  343. package/lib/WAUSync/USyncQuery.js.map +1 -0
  344. package/lib/WAUSync/USyncUser.d.ts +6 -5
  345. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  346. package/lib/WAUSync/USyncUser.js +2 -5
  347. package/lib/WAUSync/USyncUser.js.map +1 -0
  348. package/lib/WAUSync/index.d.ts +4 -3
  349. package/lib/WAUSync/index.d.ts.map +1 -0
  350. package/lib/WAUSync/index.js +4 -19
  351. package/lib/WAUSync/index.js.map +1 -0
  352. package/lib/index.d.ts +9 -8
  353. package/lib/index.d.ts.map +1 -0
  354. package/lib/index.js +11 -30
  355. package/lib/index.js.map +1 -0
  356. package/package.json +26 -26
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.processSyncAction = exports.chatModificationToAppPatch = exports.decodePatches = exports.decodeSyncdSnapshot = exports.downloadExternalPatch = exports.downloadExternalBlob = exports.extractSyncdPatches = exports.decodeSyncdPatch = exports.decodeSyncdMutations = exports.encodeSyncdPatch = exports.newLTHashState = void 0;
4
- const boom_1 = require("@hapi/boom");
5
- const WAProto_1 = require("../../WAProto");
6
- const LabelAssociation_1 = require("../Types/LabelAssociation");
7
- const WABinary_1 = require("../WABinary");
8
- const crypto_1 = require("./crypto");
9
- const generics_1 = require("./generics");
10
- const lt_hash_1 = require("./lt-hash");
11
- const messages_media_1 = require("./messages-media");
1
+ import { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto/index.js';
3
+ import { LabelAssociationType } from '../Types/LabelAssociation.js';
4
+ import { getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidNormalizedUser } from '../WABinary/index.js';
5
+ import { aesDecrypt, aesEncrypt, hkdf, hmacSign } from './crypto.js';
6
+ import { toNumber } from './generics.js';
7
+ import { LT_HASH_ANTI_TAMPERING } from './lt-hash.js';
8
+ import { downloadContentFromMessage } from './messages-media.js';
12
9
  const mutationKeys = async (keydata) => {
13
- const expanded = await (0, crypto_1.hkdf)(keydata, 160, { info: 'WhatsApp Mutation Keys' });
10
+ const expanded = await hkdf(keydata, 160, { info: 'WhatsApp Mutation Keys' });
14
11
  return {
15
12
  indexKey: expanded.slice(0, 32),
16
13
  valueEncryptionKey: expanded.slice(32, 64),
@@ -23,10 +20,10 @@ const generateMac = (operation, data, keyId, key) => {
23
20
  const getKeyData = () => {
24
21
  let r;
25
22
  switch (operation) {
26
- case WAProto_1.proto.SyncdMutation.SyncdOperation.SET:
23
+ case proto.SyncdMutation.SyncdOperation.SET:
27
24
  r = 0x01;
28
25
  break;
29
- case WAProto_1.proto.SyncdMutation.SyncdOperation.REMOVE:
26
+ case proto.SyncdMutation.SyncdOperation.REMOVE:
30
27
  r = 0x02;
31
28
  break;
32
29
  }
@@ -37,7 +34,7 @@ const generateMac = (operation, data, keyId, key) => {
37
34
  const last = Buffer.alloc(8); // 8 bytes
38
35
  last.set([keyData.length], last.length - 1);
39
36
  const total = Buffer.concat([keyData, data, last]);
40
- const hmac = (0, crypto_1.hmacSign)(total, key, 'sha512');
37
+ const hmac = hmacSign(total, key, 'sha512');
41
38
  return hmac.slice(0, 32);
42
39
  };
43
40
  const to64BitNetworkOrder = (e) => {
@@ -53,9 +50,9 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
53
50
  mix: ({ indexMac, valueMac, operation }) => {
54
51
  const indexMacBase64 = Buffer.from(indexMac).toString('base64');
55
52
  const prevOp = indexValueMap[indexMacBase64];
56
- if (operation === WAProto_1.proto.SyncdMutation.SyncdOperation.REMOVE) {
53
+ if (operation === proto.SyncdMutation.SyncdOperation.REMOVE) {
57
54
  if (!prevOp) {
58
- throw new boom_1.Boom('tried remove, but no previous op', { data: { indexMac, valueMac } });
55
+ throw new Boom('tried remove, but no previous op', { data: { indexMac, valueMac } });
59
56
  }
60
57
  // remove from index value mac, since this mutation is erased
61
58
  delete indexValueMap[indexMacBase64];
@@ -71,7 +68,7 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
71
68
  },
72
69
  finish: async () => {
73
70
  const hashArrayBuffer = new Uint8Array(hash).buffer;
74
- const result = await lt_hash_1.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
71
+ const result = await LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
75
72
  const buffer = Buffer.from(result);
76
73
  return {
77
74
  hash: buffer,
@@ -82,33 +79,32 @@ const makeLtHashGenerator = ({ indexValueMap, hash }) => {
82
79
  };
83
80
  const generateSnapshotMac = (lthash, version, name, key) => {
84
81
  const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, 'utf-8')]);
85
- return (0, crypto_1.hmacSign)(total, key, 'sha256');
82
+ return hmacSign(total, key, 'sha256');
86
83
  };
87
84
  const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
88
85
  const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, 'utf-8')]);
89
- return (0, crypto_1.hmacSign)(total, key);
86
+ return hmacSign(total, key);
90
87
  };
91
- const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
92
- exports.newLTHashState = newLTHashState;
93
- const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
88
+ export const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
89
+ export const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
94
90
  const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
95
91
  if (!key) {
96
- throw new boom_1.Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { statusCode: 404 });
92
+ throw new Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { statusCode: 404 });
97
93
  }
98
94
  const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
99
95
  state = { ...state, indexValueMap: { ...state.indexValueMap } };
100
96
  const indexBuffer = Buffer.from(JSON.stringify(index));
101
- const dataProto = WAProto_1.proto.SyncActionData.fromObject({
97
+ const dataProto = proto.SyncActionData.fromObject({
102
98
  index: indexBuffer,
103
99
  value: syncAction,
104
100
  padding: new Uint8Array(0),
105
101
  version: apiVersion
106
102
  });
107
- const encoded = WAProto_1.proto.SyncActionData.encode(dataProto).finish();
103
+ const encoded = proto.SyncActionData.encode(dataProto).finish();
108
104
  const keyValue = await mutationKeys(key.keyData);
109
- const encValue = (0, crypto_1.aesEncrypt)(encoded, keyValue.valueEncryptionKey);
105
+ const encValue = aesEncrypt(encoded, keyValue.valueEncryptionKey);
110
106
  const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
111
- const indexMac = (0, crypto_1.hmacSign)(indexBuffer, keyValue.indexKey);
107
+ const indexMac = hmacSign(indexBuffer, keyValue.indexKey);
112
108
  // update LT hash
113
109
  const generator = makeLtHashGenerator(state);
114
110
  generator.mix({ indexMac, valueMac, operation });
@@ -138,8 +134,7 @@ const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation
138
134
  state.indexValueMap[base64Index] = { valueMac };
139
135
  return { patch, state };
140
136
  };
141
- exports.encodeSyncdPatch = encodeSyncdPatch;
142
- const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
137
+ export const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
143
138
  const ltGenerator = makeLtHashGenerator(initialState);
144
139
  // indexKey used to HMAC sign record.index.blob
145
140
  // valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
@@ -147,7 +142,7 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
147
142
  for (const msgMutation of msgMutations) {
148
143
  // if it's a syncdmutation, get the operation property
149
144
  // otherwise, if it's only a record -- it'll be a SET mutation
150
- const operation = 'operation' in msgMutation ? msgMutation.operation : WAProto_1.proto.SyncdMutation.SyncdOperation.SET;
145
+ const operation = 'operation' in msgMutation ? msgMutation.operation : proto.SyncdMutation.SyncdOperation.SET;
151
146
  const record = 'record' in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
152
147
  const key = await getKey(record.keyId.id);
153
148
  const content = Buffer.from(record.value.blob);
@@ -156,15 +151,15 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
156
151
  if (validateMacs) {
157
152
  const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
158
153
  if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
159
- throw new boom_1.Boom('HMAC content verification failed');
154
+ throw new Boom('HMAC content verification failed');
160
155
  }
161
156
  }
162
- const result = (0, crypto_1.aesDecrypt)(encContent, key.valueEncryptionKey);
163
- const syncAction = WAProto_1.proto.SyncActionData.decode(result);
157
+ const result = aesDecrypt(encContent, key.valueEncryptionKey);
158
+ const syncAction = proto.SyncActionData.decode(result);
164
159
  if (validateMacs) {
165
- const hmac = (0, crypto_1.hmacSign)(syncAction.index, key.indexKey);
160
+ const hmac = hmacSign(syncAction.index, key.indexKey);
166
161
  if (Buffer.compare(hmac, record.index.blob) !== 0) {
167
- throw new boom_1.Boom('HMAC index verification failed');
162
+ throw new Boom('HMAC index verification failed');
168
163
  }
169
164
  }
170
165
  const indexStr = Buffer.from(syncAction.index).toString();
@@ -180,7 +175,7 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
180
175
  const base64Key = Buffer.from(keyId).toString('base64');
181
176
  const keyEnc = await getAppStateSyncKey(base64Key);
182
177
  if (!keyEnc) {
183
- throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`, {
178
+ throw new Boom(`failed to find key "${base64Key}" to decode mutation`, {
184
179
  statusCode: 404,
185
180
  data: { msgMutations }
186
181
  });
@@ -188,33 +183,31 @@ const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncK
188
183
  return mutationKeys(keyEnc.keyData);
189
184
  }
190
185
  };
191
- exports.decodeSyncdMutations = decodeSyncdMutations;
192
- const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
186
+ export const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
193
187
  if (validateMacs) {
194
188
  const base64Key = Buffer.from(msg.keyId.id).toString('base64');
195
189
  const mainKeyObj = await getAppStateSyncKey(base64Key);
196
190
  if (!mainKeyObj) {
197
- throw new boom_1.Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
191
+ throw new Boom(`failed to find key "${base64Key}" to decode patch`, { statusCode: 404, data: { msg } });
198
192
  }
199
193
  const mainKey = await mutationKeys(mainKeyObj.keyData);
200
194
  const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
201
- const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, (0, generics_1.toNumber)(msg.version.version), name, mainKey.patchMacKey);
195
+ const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, toNumber(msg.version.version), name, mainKey.patchMacKey);
202
196
  if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
203
- throw new boom_1.Boom('Invalid patch mac');
197
+ throw new Boom('Invalid patch mac');
204
198
  }
205
199
  }
206
- const result = await (0, exports.decodeSyncdMutations)(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
200
+ const result = await decodeSyncdMutations(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
207
201
  return result;
208
202
  };
209
- exports.decodeSyncdPatch = decodeSyncdPatch;
210
- const extractSyncdPatches = async (result, options) => {
211
- const syncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'sync');
212
- const collectionNodes = (0, WABinary_1.getBinaryNodeChildren)(syncNode, 'collection');
203
+ export const extractSyncdPatches = async (result, options) => {
204
+ const syncNode = getBinaryNodeChild(result, 'sync');
205
+ const collectionNodes = getBinaryNodeChildren(syncNode, 'collection');
213
206
  const final = {};
214
207
  await Promise.all(collectionNodes.map(async (collectionNode) => {
215
- const patchesNode = (0, WABinary_1.getBinaryNodeChild)(collectionNode, 'patches');
216
- const patches = (0, WABinary_1.getBinaryNodeChildren)(patchesNode || collectionNode, 'patch');
217
- const snapshotNode = (0, WABinary_1.getBinaryNodeChild)(collectionNode, 'snapshot');
208
+ const patchesNode = getBinaryNodeChild(collectionNode, 'patches');
209
+ const patches = getBinaryNodeChildren(patchesNode || collectionNode, 'patch');
210
+ const snapshotNode = getBinaryNodeChild(collectionNode, 'snapshot');
218
211
  const syncds = [];
219
212
  const name = collectionNode.attrs.name;
220
213
  const hasMorePatches = collectionNode.attrs.has_more_patches === 'true';
@@ -223,16 +216,16 @@ const extractSyncdPatches = async (result, options) => {
223
216
  if (!Buffer.isBuffer(snapshotNode)) {
224
217
  snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
225
218
  }
226
- const blobRef = WAProto_1.proto.ExternalBlobReference.decode(snapshotNode.content);
227
- const data = await (0, exports.downloadExternalBlob)(blobRef, options);
228
- snapshot = WAProto_1.proto.SyncdSnapshot.decode(data);
219
+ const blobRef = proto.ExternalBlobReference.decode(snapshotNode.content);
220
+ const data = await downloadExternalBlob(blobRef, options);
221
+ snapshot = proto.SyncdSnapshot.decode(data);
229
222
  }
230
223
  for (let { content } of patches) {
231
224
  if (content) {
232
225
  if (!Buffer.isBuffer(content)) {
233
226
  content = Buffer.from(Object.values(content));
234
227
  }
235
- const syncd = WAProto_1.proto.SyncdPatch.decode(content);
228
+ const syncd = proto.SyncdPatch.decode(content);
236
229
  if (!syncd.version) {
237
230
  syncd.version = { version: +collectionNode.attrs.version + 1 };
238
231
  }
@@ -243,31 +236,27 @@ const extractSyncdPatches = async (result, options) => {
243
236
  }));
244
237
  return final;
245
238
  };
246
- exports.extractSyncdPatches = extractSyncdPatches;
247
- const downloadExternalBlob = async (blob, options) => {
248
- const stream = await (0, messages_media_1.downloadContentFromMessage)(blob, 'md-app-state', { options });
239
+ export const downloadExternalBlob = async (blob, options) => {
240
+ const stream = await downloadContentFromMessage(blob, 'md-app-state', { options });
249
241
  const bufferArray = [];
250
242
  for await (const chunk of stream) {
251
243
  bufferArray.push(chunk);
252
244
  }
253
245
  return Buffer.concat(bufferArray);
254
246
  };
255
- exports.downloadExternalBlob = downloadExternalBlob;
256
- const downloadExternalPatch = async (blob, options) => {
257
- const buffer = await (0, exports.downloadExternalBlob)(blob, options);
258
- const syncData = WAProto_1.proto.SyncdMutations.decode(buffer);
247
+ export const downloadExternalPatch = async (blob, options) => {
248
+ const buffer = await downloadExternalBlob(blob, options);
249
+ const syncData = proto.SyncdMutations.decode(buffer);
259
250
  return syncData;
260
251
  };
261
- exports.downloadExternalPatch = downloadExternalPatch;
262
- const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
263
- const newState = (0, exports.newLTHashState)();
264
- newState.version = (0, generics_1.toNumber)(snapshot.version.version);
252
+ export const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
253
+ const newState = newLTHashState();
254
+ newState.version = toNumber(snapshot.version.version);
265
255
  const mutationMap = {};
266
256
  const areMutationsRequired = typeof minimumVersionNumber === 'undefined' || newState.version > minimumVersionNumber;
267
- const { hash, indexValueMap } = await (0, exports.decodeSyncdMutations)(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
257
+ const { hash, indexValueMap } = await decodeSyncdMutations(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
268
258
  ? mutation => {
269
- var _a;
270
- const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
259
+ const index = mutation.syncAction.index?.toString();
271
260
  mutationMap[index] = mutation;
272
261
  }
273
262
  : () => { }, validateMacs);
@@ -277,12 +266,12 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
277
266
  const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
278
267
  const keyEnc = await getAppStateSyncKey(base64Key);
279
268
  if (!keyEnc) {
280
- throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
269
+ throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
281
270
  }
282
271
  const result = await mutationKeys(keyEnc.keyData);
283
272
  const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
284
273
  if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
285
- throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
274
+ throw new Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
286
275
  }
287
276
  }
288
277
  return {
@@ -290,9 +279,7 @@ const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVe
290
279
  mutationMap
291
280
  };
292
281
  };
293
- exports.decodeSyncdSnapshot = decodeSyncdSnapshot;
294
- const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
295
- var _a;
282
+ export const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
296
283
  const newState = {
297
284
  ...initial,
298
285
  indexValueMap: { ...initial.indexValueMap }
@@ -301,18 +288,17 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
301
288
  for (const syncd of syncds) {
302
289
  const { version, keyId, snapshotMac } = syncd;
303
290
  if (syncd.externalMutations) {
304
- logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
305
- const ref = await (0, exports.downloadExternalPatch)(syncd.externalMutations, options);
306
- logger === null || logger === void 0 ? void 0 : logger.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch');
307
- (_a = syncd.mutations) === null || _a === void 0 ? void 0 : _a.push(...ref.mutations);
291
+ logger?.trace({ name, version }, 'downloading external patch');
292
+ const ref = await downloadExternalPatch(syncd.externalMutations, options);
293
+ logger?.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch');
294
+ syncd.mutations?.push(...ref.mutations);
308
295
  }
309
- const patchVersion = (0, generics_1.toNumber)(version.version);
296
+ const patchVersion = toNumber(version.version);
310
297
  newState.version = patchVersion;
311
298
  const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
312
- const decodeResult = await (0, exports.decodeSyncdPatch)(syncd, name, newState, getAppStateSyncKey, shouldMutate
299
+ const decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate
313
300
  ? mutation => {
314
- var _a;
315
- const index = (_a = mutation.syncAction.index) === null || _a === void 0 ? void 0 : _a.toString();
301
+ const index = mutation.syncAction.index?.toString();
316
302
  mutationMap[index] = mutation;
317
303
  }
318
304
  : () => { }, true);
@@ -322,12 +308,12 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
322
308
  const base64Key = Buffer.from(keyId.id).toString('base64');
323
309
  const keyEnc = await getAppStateSyncKey(base64Key);
324
310
  if (!keyEnc) {
325
- throw new boom_1.Boom(`failed to find key "${base64Key}" to decode mutation`);
311
+ throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
326
312
  }
327
313
  const result = await mutationKeys(keyEnc.keyData);
328
314
  const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
329
315
  if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
330
- throw new boom_1.Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
316
+ throw new Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
331
317
  }
332
318
  }
333
319
  // clear memory used up by the mutations
@@ -335,29 +321,27 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
335
321
  }
336
322
  return { state: newState, mutationMap };
337
323
  };
338
- exports.decodePatches = decodePatches;
339
- const chatModificationToAppPatch = (mod, jid) => {
340
- const OP = WAProto_1.proto.SyncdMutation.SyncdOperation;
324
+ export const chatModificationToAppPatch = (mod, jid) => {
325
+ const OP = proto.SyncdMutation.SyncdOperation;
341
326
  const getMessageRange = (lastMessages) => {
342
327
  let messageRange;
343
328
  if (Array.isArray(lastMessages)) {
344
329
  const lastMsg = lastMessages[lastMessages.length - 1];
345
330
  messageRange = {
346
- lastMessageTimestamp: lastMsg === null || lastMsg === void 0 ? void 0 : lastMsg.messageTimestamp,
347
- messages: (lastMessages === null || lastMessages === void 0 ? void 0 : lastMessages.length)
331
+ lastMessageTimestamp: lastMsg?.messageTimestamp,
332
+ messages: lastMessages?.length
348
333
  ? lastMessages.map(m => {
349
- var _a, _b;
350
- if (!((_a = m.key) === null || _a === void 0 ? void 0 : _a.id) || !((_b = m.key) === null || _b === void 0 ? void 0 : _b.remoteJid)) {
351
- throw new boom_1.Boom('Incomplete key', { statusCode: 400, data: m });
334
+ if (!m.key?.id || !m.key?.remoteJid) {
335
+ throw new Boom('Incomplete key', { statusCode: 400, data: m });
352
336
  }
353
- if ((0, WABinary_1.isJidGroup)(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
354
- throw new boom_1.Boom('Expected not from me message to have participant', { statusCode: 400, data: m });
337
+ if (isJidGroup(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
338
+ throw new Boom('Expected not from me message to have participant', { statusCode: 400, data: m });
355
339
  }
356
- if (!m.messageTimestamp || !(0, generics_1.toNumber)(m.messageTimestamp)) {
357
- throw new boom_1.Boom('Missing timestamp in last message list', { statusCode: 400, data: m });
340
+ if (!m.messageTimestamp || !toNumber(m.messageTimestamp)) {
341
+ throw new Boom('Missing timestamp in last message list', { statusCode: 400, data: m });
358
342
  }
359
343
  if (m.key.participant) {
360
- m.key.participant = (0, WABinary_1.jidNormalizedUser)(m.key.participant);
344
+ m.key.participant = jidNormalizedUser(m.key.participant);
361
345
  }
362
346
  return m;
363
347
  })
@@ -464,6 +448,17 @@ const chatModificationToAppPatch = (mod, jid) => {
464
448
  operation: mod.contact ? OP.SET : OP.REMOVE
465
449
  };
466
450
  }
451
+ else if ('disableLinkPreviews' in mod) {
452
+ patch = {
453
+ syncAction: {
454
+ privacySettingDisableLinkPreviewsAction: mod.disableLinkPreviews || {}
455
+ },
456
+ index: ['setting_disableLinkPreviews'],
457
+ type: 'regular',
458
+ apiVersion: 8,
459
+ operation: OP.SET
460
+ };
461
+ }
467
462
  else if ('star' in mod) {
468
463
  const key = mod.star.messages[0];
469
464
  patch = {
@@ -527,7 +522,7 @@ const chatModificationToAppPatch = (mod, jid) => {
527
522
  labeled: true
528
523
  }
529
524
  },
530
- index: [LabelAssociation_1.LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
525
+ index: [LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
531
526
  type: 'regular',
532
527
  apiVersion: 3,
533
528
  operation: OP.SET
@@ -540,7 +535,7 @@ const chatModificationToAppPatch = (mod, jid) => {
540
535
  labeled: false
541
536
  }
542
537
  },
543
- index: [LabelAssociation_1.LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
538
+ index: [LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
544
539
  type: 'regular',
545
540
  apiVersion: 3,
546
541
  operation: OP.SET
@@ -553,7 +548,7 @@ const chatModificationToAppPatch = (mod, jid) => {
553
548
  labeled: true
554
549
  }
555
550
  },
556
- index: [LabelAssociation_1.LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
551
+ index: [LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
557
552
  type: 'regular',
558
553
  apiVersion: 3,
559
554
  operation: OP.SET
@@ -567,7 +562,7 @@ const chatModificationToAppPatch = (mod, jid) => {
567
562
  }
568
563
  },
569
564
  index: [
570
- LabelAssociation_1.LabelAssociationType.Message,
565
+ LabelAssociationType.Message,
571
566
  mod.removeMessageLabel.labelId,
572
567
  jid,
573
568
  mod.removeMessageLabel.messageId,
@@ -580,28 +575,26 @@ const chatModificationToAppPatch = (mod, jid) => {
580
575
  };
581
576
  }
582
577
  else {
583
- throw new boom_1.Boom('not supported');
578
+ throw new Boom('not supported');
584
579
  }
585
580
  patch.syncAction.timestamp = Date.now();
586
581
  return patch;
587
582
  };
588
- exports.chatModificationToAppPatch = chatModificationToAppPatch;
589
- const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
590
- var _a, _b, _c, _d;
583
+ export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
591
584
  const isInitialSync = !!initialSyncOpts;
592
- const accountSettings = initialSyncOpts === null || initialSyncOpts === void 0 ? void 0 : initialSyncOpts.accountSettings;
593
- logger === null || logger === void 0 ? void 0 : logger.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
585
+ const accountSettings = initialSyncOpts?.accountSettings;
586
+ logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
594
587
  const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
595
- if (action === null || action === void 0 ? void 0 : action.muteAction) {
588
+ if (action?.muteAction) {
596
589
  ev.emit('chats.update', [
597
590
  {
598
591
  id,
599
- muteEndTime: ((_a = action.muteAction) === null || _a === void 0 ? void 0 : _a.muted) ? (0, generics_1.toNumber)(action.muteAction.muteEndTimestamp) : null,
592
+ muteEndTime: action.muteAction?.muted ? toNumber(action.muteAction.muteEndTimestamp) : null,
600
593
  conditional: getChatUpdateConditional(id, undefined)
601
594
  }
602
595
  ]);
603
596
  }
604
- else if ((action === null || action === void 0 ? void 0 : action.archiveChatAction) || type === 'archive' || type === 'unarchive') {
597
+ else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
605
598
  // okay so we've to do some annoying computation here
606
599
  // when we're initially syncing the app state
607
600
  // there are a few cases we need to handle
@@ -612,14 +605,14 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
612
605
  // we compare the timestamp of latest message from the other person to determine this
613
606
  // 2. if the account unarchiveChats setting is false -- then it doesn't matter,
614
607
  // it'll always take an app state action to mark in unarchived -- which we'll get anyway
615
- const archiveAction = action === null || action === void 0 ? void 0 : action.archiveChatAction;
608
+ const archiveAction = action?.archiveChatAction;
616
609
  const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
617
610
  // // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
618
611
  // // this only applies for the initial sync
619
612
  // if(isInitialSync && !isArchived) {
620
613
  // isArchived = false
621
614
  // }
622
- const msgRange = !(accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats) ? undefined : archiveAction === null || archiveAction === void 0 ? void 0 : archiveAction.messageRange;
615
+ const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange;
623
616
  // logger?.debug({ chat: id, syncAction }, 'message range archive')
624
617
  ev.emit('chats.update', [
625
618
  {
@@ -629,7 +622,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
629
622
  }
630
623
  ]);
631
624
  }
632
- else if (action === null || action === void 0 ? void 0 : action.markChatAsReadAction) {
625
+ else if (action?.markChatAsReadAction) {
633
626
  const markReadAction = action.markChatAsReadAction;
634
627
  // basically we don't need to fire an "read" update if the chat is being marked as read
635
628
  // because the chat is read by default
@@ -638,12 +631,12 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
638
631
  ev.emit('chats.update', [
639
632
  {
640
633
  id,
641
- unreadCount: isNullUpdate ? null : !!(markReadAction === null || markReadAction === void 0 ? void 0 : markReadAction.read) ? 0 : -1,
642
- conditional: getChatUpdateConditional(id, markReadAction === null || markReadAction === void 0 ? void 0 : markReadAction.messageRange)
634
+ unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
635
+ conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
643
636
  }
644
637
  ]);
645
638
  }
646
- else if ((action === null || action === void 0 ? void 0 : action.deleteMessageForMeAction) || type === 'deleteMessageForMe') {
639
+ else if (action?.deleteMessageForMeAction || type === 'deleteMessageForMe') {
647
640
  ev.emit('messages.delete', {
648
641
  keys: [
649
642
  {
@@ -654,41 +647,41 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
654
647
  ]
655
648
  });
656
649
  }
657
- else if (action === null || action === void 0 ? void 0 : action.contactAction) {
650
+ else if (action?.contactAction) {
658
651
  ev.emit('contacts.upsert', [
659
652
  {
660
653
  id: id,
661
654
  name: action.contactAction.fullName,
662
655
  lid: action.contactAction.lidJid || undefined,
663
- jid: (0, WABinary_1.isJidUser)(id) ? id : undefined
656
+ jid: isJidUser(id) ? id : undefined
664
657
  }
665
658
  ]);
666
659
  }
667
- else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
668
- const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
669
- if (name && (me === null || me === void 0 ? void 0 : me.name) !== name) {
660
+ else if (action?.pushNameSetting) {
661
+ const name = action?.pushNameSetting?.name;
662
+ if (name && me?.name !== name) {
670
663
  ev.emit('creds.update', { me: { ...me, name } });
671
664
  }
672
665
  }
673
- else if (action === null || action === void 0 ? void 0 : action.pinAction) {
666
+ else if (action?.pinAction) {
674
667
  ev.emit('chats.update', [
675
668
  {
676
669
  id,
677
- pinned: ((_c = action.pinAction) === null || _c === void 0 ? void 0 : _c.pinned) ? (0, generics_1.toNumber)(action.timestamp) : null,
670
+ pinned: action.pinAction?.pinned ? toNumber(action.timestamp) : null,
678
671
  conditional: getChatUpdateConditional(id, undefined)
679
672
  }
680
673
  ]);
681
674
  }
682
- else if (action === null || action === void 0 ? void 0 : action.unarchiveChatsSetting) {
675
+ else if (action?.unarchiveChatsSetting) {
683
676
  const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
684
677
  ev.emit('creds.update', { accountSettings: { unarchiveChats } });
685
- logger === null || logger === void 0 ? void 0 : logger.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
678
+ logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
686
679
  if (accountSettings) {
687
680
  accountSettings.unarchiveChats = unarchiveChats;
688
681
  }
689
682
  }
690
- else if ((action === null || action === void 0 ? void 0 : action.starAction) || type === 'star') {
691
- let starred = (_d = action === null || action === void 0 ? void 0 : action.starAction) === null || _d === void 0 ? void 0 : _d.starred;
683
+ else if (action?.starAction || type === 'star') {
684
+ let starred = action?.starAction?.starred;
692
685
  if (typeof starred !== 'boolean') {
693
686
  starred = syncAction.index[syncAction.index.length - 1] === '1';
694
687
  }
@@ -699,32 +692,32 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
699
692
  }
700
693
  ]);
701
694
  }
702
- else if ((action === null || action === void 0 ? void 0 : action.deleteChatAction) || type === 'deleteChat') {
695
+ else if (action?.deleteChatAction || type === 'deleteChat') {
703
696
  if (!isInitialSync) {
704
697
  ev.emit('chats.delete', [id]);
705
698
  }
706
699
  }
707
- else if (action === null || action === void 0 ? void 0 : action.labelEditAction) {
700
+ else if (action?.labelEditAction) {
708
701
  const { name, color, deleted, predefinedId } = action.labelEditAction;
709
702
  ev.emit('labels.edit', {
710
- id,
703
+ id: id,
711
704
  name: name,
712
705
  color: color,
713
706
  deleted: deleted,
714
707
  predefinedId: predefinedId ? String(predefinedId) : undefined
715
708
  });
716
709
  }
717
- else if (action === null || action === void 0 ? void 0 : action.labelAssociationAction) {
710
+ else if (action?.labelAssociationAction) {
718
711
  ev.emit('labels.association', {
719
712
  type: action.labelAssociationAction.labeled ? 'add' : 'remove',
720
- association: type === LabelAssociation_1.LabelAssociationType.Chat
713
+ association: type === LabelAssociationType.Chat
721
714
  ? {
722
- type: LabelAssociation_1.LabelAssociationType.Chat,
715
+ type: LabelAssociationType.Chat,
723
716
  chatId: syncAction.index[2],
724
717
  labelId: syncAction.index[1]
725
718
  }
726
719
  : {
727
- type: LabelAssociation_1.LabelAssociationType.Message,
720
+ type: LabelAssociationType.Message,
728
721
  chatId: syncAction.index[2],
729
722
  messageId: syncAction.index[3],
730
723
  labelId: syncAction.index[1]
@@ -732,7 +725,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
732
725
  });
733
726
  }
734
727
  else {
735
- logger === null || logger === void 0 ? void 0 : logger.debug({ syncAction, id }, 'unprocessable update');
728
+ logger?.debug({ syncAction, id }, 'unprocessable update');
736
729
  }
737
730
  function getChatUpdateConditional(id, msgRange) {
738
731
  return isInitialSync
@@ -745,9 +738,9 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
745
738
  : undefined;
746
739
  }
747
740
  function isValidPatchBasedOnMessageRange(chat, msgRange) {
748
- const lastMsgTimestamp = Number((msgRange === null || msgRange === void 0 ? void 0 : msgRange.lastMessageTimestamp) || (msgRange === null || msgRange === void 0 ? void 0 : msgRange.lastSystemMessageTimestamp) || 0);
749
- const chatLastMsgTimestamp = Number((chat === null || chat === void 0 ? void 0 : chat.lastMessageRecvTimestamp) || 0);
741
+ const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
742
+ const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
750
743
  return lastMsgTimestamp >= chatLastMsgTimestamp;
751
744
  }
752
745
  };
753
- exports.processSyncAction = processSyncAction;
746
+ //# sourceMappingURL=chat-utils.js.map