@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,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
  })
@@ -430,7 +414,9 @@ const chatModificationToAppPatch = (mod, jid) => {
430
414
  else if ('clear' in mod) {
431
415
  patch = {
432
416
  syncAction: {
433
- clearChatAction: {} // add message range later
417
+ clearChatAction: {
418
+ messageRange: getMessageRange(mod.lastMessages)
419
+ }
434
420
  },
435
421
  index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
436
422
  type: 'regular_high',
@@ -451,6 +437,17 @@ const chatModificationToAppPatch = (mod, jid) => {
451
437
  operation: OP.SET
452
438
  };
453
439
  }
440
+ else if ('contact' in mod) {
441
+ patch = {
442
+ syncAction: {
443
+ contactAction: mod.contact || {}
444
+ },
445
+ index: ['contact', jid],
446
+ type: 'critical_unblock_low',
447
+ apiVersion: 2,
448
+ operation: mod.contact ? OP.SET : OP.REMOVE
449
+ };
450
+ }
454
451
  else if ('star' in mod) {
455
452
  const key = mod.star.messages[0];
456
453
  patch = {
@@ -514,7 +511,7 @@ const chatModificationToAppPatch = (mod, jid) => {
514
511
  labeled: true
515
512
  }
516
513
  },
517
- index: [LabelAssociation_1.LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
514
+ index: [LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
518
515
  type: 'regular',
519
516
  apiVersion: 3,
520
517
  operation: OP.SET
@@ -527,7 +524,7 @@ const chatModificationToAppPatch = (mod, jid) => {
527
524
  labeled: false
528
525
  }
529
526
  },
530
- index: [LabelAssociation_1.LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
527
+ index: [LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
531
528
  type: 'regular',
532
529
  apiVersion: 3,
533
530
  operation: OP.SET
@@ -540,7 +537,7 @@ const chatModificationToAppPatch = (mod, jid) => {
540
537
  labeled: true
541
538
  }
542
539
  },
543
- index: [LabelAssociation_1.LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
540
+ index: [LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
544
541
  type: 'regular',
545
542
  apiVersion: 3,
546
543
  operation: OP.SET
@@ -554,7 +551,7 @@ const chatModificationToAppPatch = (mod, jid) => {
554
551
  }
555
552
  },
556
553
  index: [
557
- LabelAssociation_1.LabelAssociationType.Message,
554
+ LabelAssociationType.Message,
558
555
  mod.removeMessageLabel.labelId,
559
556
  jid,
560
557
  mod.removeMessageLabel.messageId,
@@ -567,28 +564,26 @@ const chatModificationToAppPatch = (mod, jid) => {
567
564
  };
568
565
  }
569
566
  else {
570
- throw new boom_1.Boom('not supported');
567
+ throw new Boom('not supported');
571
568
  }
572
569
  patch.syncAction.timestamp = Date.now();
573
570
  return patch;
574
571
  };
575
- exports.chatModificationToAppPatch = chatModificationToAppPatch;
576
- const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
577
- var _a, _b, _c, _d;
572
+ export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
578
573
  const isInitialSync = !!initialSyncOpts;
579
- const accountSettings = initialSyncOpts === null || initialSyncOpts === void 0 ? void 0 : initialSyncOpts.accountSettings;
580
- logger === null || logger === void 0 ? void 0 : logger.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
574
+ const accountSettings = initialSyncOpts?.accountSettings;
575
+ logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
581
576
  const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
582
- if (action === null || action === void 0 ? void 0 : action.muteAction) {
577
+ if (action?.muteAction) {
583
578
  ev.emit('chats.update', [
584
579
  {
585
580
  id,
586
- muteEndTime: ((_a = action.muteAction) === null || _a === void 0 ? void 0 : _a.muted) ? (0, generics_1.toNumber)(action.muteAction.muteEndTimestamp) : null,
581
+ muteEndTime: action.muteAction?.muted ? toNumber(action.muteAction.muteEndTimestamp) : null,
587
582
  conditional: getChatUpdateConditional(id, undefined)
588
583
  }
589
584
  ]);
590
585
  }
591
- else if ((action === null || action === void 0 ? void 0 : action.archiveChatAction) || type === 'archive' || type === 'unarchive') {
586
+ else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
592
587
  // okay so we've to do some annoying computation here
593
588
  // when we're initially syncing the app state
594
589
  // there are a few cases we need to handle
@@ -599,14 +594,14 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
599
594
  // we compare the timestamp of latest message from the other person to determine this
600
595
  // 2. if the account unarchiveChats setting is false -- then it doesn't matter,
601
596
  // it'll always take an app state action to mark in unarchived -- which we'll get anyway
602
- const archiveAction = action === null || action === void 0 ? void 0 : action.archiveChatAction;
597
+ const archiveAction = action?.archiveChatAction;
603
598
  const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
604
599
  // // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
605
600
  // // this only applies for the initial sync
606
601
  // if(isInitialSync && !isArchived) {
607
602
  // isArchived = false
608
603
  // }
609
- const msgRange = !(accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats) ? undefined : archiveAction === null || archiveAction === void 0 ? void 0 : archiveAction.messageRange;
604
+ const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange;
610
605
  // logger?.debug({ chat: id, syncAction }, 'message range archive')
611
606
  ev.emit('chats.update', [
612
607
  {
@@ -616,7 +611,7 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
616
611
  }
617
612
  ]);
618
613
  }
619
- else if (action === null || action === void 0 ? void 0 : action.markChatAsReadAction) {
614
+ else if (action?.markChatAsReadAction) {
620
615
  const markReadAction = action.markChatAsReadAction;
621
616
  // basically we don't need to fire an "read" update if the chat is being marked as read
622
617
  // because the chat is read by default
@@ -625,12 +620,12 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
625
620
  ev.emit('chats.update', [
626
621
  {
627
622
  id,
628
- unreadCount: isNullUpdate ? null : !!(markReadAction === null || markReadAction === void 0 ? void 0 : markReadAction.read) ? 0 : -1,
629
- conditional: getChatUpdateConditional(id, markReadAction === null || markReadAction === void 0 ? void 0 : markReadAction.messageRange)
623
+ unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
624
+ conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
630
625
  }
631
626
  ]);
632
627
  }
633
- else if ((action === null || action === void 0 ? void 0 : action.deleteMessageForMeAction) || type === 'deleteMessageForMe') {
628
+ else if (action?.deleteMessageForMeAction || type === 'deleteMessageForMe') {
634
629
  ev.emit('messages.delete', {
635
630
  keys: [
636
631
  {
@@ -641,34 +636,41 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
641
636
  ]
642
637
  });
643
638
  }
644
- else if (action === null || action === void 0 ? void 0 : action.contactAction) {
645
- ev.emit('contacts.upsert', [{ id, name: action.contactAction.fullName }]);
639
+ else if (action?.contactAction) {
640
+ ev.emit('contacts.upsert', [
641
+ {
642
+ id: id,
643
+ name: action.contactAction.fullName,
644
+ lid: action.contactAction.lidJid || undefined,
645
+ jid: isJidUser(id) ? id : undefined
646
+ }
647
+ ]);
646
648
  }
647
- else if (action === null || action === void 0 ? void 0 : action.pushNameSetting) {
648
- const name = (_b = action === null || action === void 0 ? void 0 : action.pushNameSetting) === null || _b === void 0 ? void 0 : _b.name;
649
- if (name && (me === null || me === void 0 ? void 0 : me.name) !== name) {
649
+ else if (action?.pushNameSetting) {
650
+ const name = action?.pushNameSetting?.name;
651
+ if (name && me?.name !== name) {
650
652
  ev.emit('creds.update', { me: { ...me, name } });
651
653
  }
652
654
  }
653
- else if (action === null || action === void 0 ? void 0 : action.pinAction) {
655
+ else if (action?.pinAction) {
654
656
  ev.emit('chats.update', [
655
657
  {
656
658
  id,
657
- pinned: ((_c = action.pinAction) === null || _c === void 0 ? void 0 : _c.pinned) ? (0, generics_1.toNumber)(action.timestamp) : null,
659
+ pinned: action.pinAction?.pinned ? toNumber(action.timestamp) : null,
658
660
  conditional: getChatUpdateConditional(id, undefined)
659
661
  }
660
662
  ]);
661
663
  }
662
- else if (action === null || action === void 0 ? void 0 : action.unarchiveChatsSetting) {
664
+ else if (action?.unarchiveChatsSetting) {
663
665
  const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
664
666
  ev.emit('creds.update', { accountSettings: { unarchiveChats } });
665
- logger === null || logger === void 0 ? void 0 : logger.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
667
+ logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
666
668
  if (accountSettings) {
667
669
  accountSettings.unarchiveChats = unarchiveChats;
668
670
  }
669
671
  }
670
- else if ((action === null || action === void 0 ? void 0 : action.starAction) || type === 'star') {
671
- let starred = (_d = action === null || action === void 0 ? void 0 : action.starAction) === null || _d === void 0 ? void 0 : _d.starred;
672
+ else if (action?.starAction || type === 'star') {
673
+ let starred = action?.starAction?.starred;
672
674
  if (typeof starred !== 'boolean') {
673
675
  starred = syncAction.index[syncAction.index.length - 1] === '1';
674
676
  }
@@ -679,43 +681,43 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
679
681
  }
680
682
  ]);
681
683
  }
682
- else if ((action === null || action === void 0 ? void 0 : action.deleteChatAction) || type === 'deleteChat') {
684
+ else if (action?.deleteChatAction || type === 'deleteChat') {
683
685
  if (!isInitialSync) {
684
686
  ev.emit('chats.delete', [id]);
685
687
  }
686
688
  }
687
- else if (action === null || action === void 0 ? void 0 : action.labelEditAction) {
689
+ else if (action?.labelEditAction) {
688
690
  const { name, color, deleted, predefinedId } = action.labelEditAction;
689
691
  ev.emit('labels.edit', {
690
- id,
692
+ id: id,
691
693
  name: name,
692
694
  color: color,
693
695
  deleted: deleted,
694
696
  predefinedId: predefinedId ? String(predefinedId) : undefined
695
697
  });
696
698
  }
697
- else if (action === null || action === void 0 ? void 0 : action.labelAssociationAction) {
699
+ else if (action?.labelAssociationAction) {
698
700
  ev.emit('labels.association', {
699
701
  type: action.labelAssociationAction.labeled ? 'add' : 'remove',
700
- association: type === LabelAssociation_1.LabelAssociationType.Chat
702
+ association: type === LabelAssociationType.Chat
701
703
  ? {
702
- type: LabelAssociation_1.LabelAssociationType.Chat,
704
+ type: LabelAssociationType.Chat,
703
705
  chatId: syncAction.index[2],
704
706
  labelId: syncAction.index[1]
705
707
  }
706
708
  : {
707
- type: LabelAssociation_1.LabelAssociationType.Message,
709
+ type: LabelAssociationType.Message,
708
710
  chatId: syncAction.index[2],
709
711
  messageId: syncAction.index[3],
710
712
  labelId: syncAction.index[1]
711
713
  }
712
714
  });
713
715
  }
714
- else if (action === null || action === void 0 ? void 0 : action.callLogAction) {
716
+ else if (action?.callLogAction) {
715
717
  ev.emit('call.outgoing', action.callLogAction);
716
718
  }
717
719
  else {
718
- logger === null || logger === void 0 ? void 0 : logger.debug({ syncAction, id }, 'unprocessable update');
720
+ logger?.debug({ syncAction, id }, 'unprocessable update');
719
721
  }
720
722
  function getChatUpdateConditional(id, msgRange) {
721
723
  return isInitialSync
@@ -728,9 +730,9 @@ const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
728
730
  : undefined;
729
731
  }
730
732
  function isValidPatchBasedOnMessageRange(chat, msgRange) {
731
- const lastMsgTimestamp = Number((msgRange === null || msgRange === void 0 ? void 0 : msgRange.lastMessageTimestamp) || (msgRange === null || msgRange === void 0 ? void 0 : msgRange.lastSystemMessageTimestamp) || 0);
732
- const chatLastMsgTimestamp = Number((chat === null || chat === void 0 ? void 0 : chat.lastMessageRecvTimestamp) || 0);
733
+ const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
734
+ const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
733
735
  return lastMsgTimestamp >= chatLastMsgTimestamp;
734
736
  }
735
737
  };
736
- exports.processSyncAction = processSyncAction;
738
+ //# sourceMappingURL=chat-utils.js.map