@queenanya/baileys 8.6.0-beta → 9.0.2

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