@srlczinn/new-baileys 7.0.0-rc.9-patch.1

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 (398) hide show
  1. package/LICENSE +21 -0
  2. package/NEW_BAILEYS_CHANGES.txt +7 -0
  3. package/README.md +161 -0
  4. package/WAProto/GenerateStatics.sh +3 -0
  5. package/WAProto/WAProto.proto +5479 -0
  6. package/WAProto/fix-imports.js +85 -0
  7. package/WAProto/index.d.ts +14017 -0
  8. package/WAProto/index.js +97691 -0
  9. package/engine-requirements.js +10 -0
  10. package/lib/Defaults/index.d.ts +76 -0
  11. package/lib/Defaults/index.d.ts.map +1 -0
  12. package/lib/Defaults/index.js +130 -0
  13. package/lib/Defaults/index.js.map +1 -0
  14. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  15. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  16. package/lib/Signal/Group/ciphertext-message.js +12 -0
  17. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  18. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  19. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  20. package/lib/Signal/Group/group-session-builder.js +30 -0
  21. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  22. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  23. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  24. package/lib/Signal/Group/group_cipher.js +82 -0
  25. package/lib/Signal/Group/group_cipher.js.map +1 -0
  26. package/lib/Signal/Group/index.d.ts +12 -0
  27. package/lib/Signal/Group/index.d.ts.map +1 -0
  28. package/lib/Signal/Group/index.js +12 -0
  29. package/lib/Signal/Group/index.js.map +1 -0
  30. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  31. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  32. package/lib/Signal/Group/keyhelper.js +18 -0
  33. package/lib/Signal/Group/keyhelper.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 +26 -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 +66 -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 +41 -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 +84 -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/lib/Signal/Group/sender-message-key.js +26 -0
  61. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  62. package/lib/Signal/libsignal.d.ts +5 -0
  63. package/lib/Signal/libsignal.d.ts.map +1 -0
  64. package/lib/Signal/libsignal.js +403 -0
  65. package/lib/Signal/libsignal.js.map +1 -0
  66. package/lib/Signal/lid-mapping.d.ts +19 -0
  67. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  68. package/lib/Signal/lid-mapping.js +271 -0
  69. package/lib/Signal/lid-mapping.js.map +1 -0
  70. package/lib/Socket/Client/index.d.ts +3 -0
  71. package/lib/Socket/Client/index.d.ts.map +1 -0
  72. package/lib/Socket/Client/index.js +3 -0
  73. package/lib/Socket/Client/index.js.map +1 -0
  74. package/lib/Socket/Client/types.d.ts +16 -0
  75. package/lib/Socket/Client/types.d.ts.map +1 -0
  76. package/lib/Socket/Client/types.js +11 -0
  77. package/lib/Socket/Client/types.js.map +1 -0
  78. package/lib/Socket/Client/websocket.d.ts +13 -0
  79. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  80. package/lib/Socket/Client/websocket.js +54 -0
  81. package/lib/Socket/Client/websocket.js.map +1 -0
  82. package/lib/Socket/business.d.ts +211 -0
  83. package/lib/Socket/business.d.ts.map +1 -0
  84. package/lib/Socket/business.js +379 -0
  85. package/lib/Socket/business.js.map +1 -0
  86. package/lib/Socket/chats.d.ts +123 -0
  87. package/lib/Socket/chats.d.ts.map +1 -0
  88. package/lib/Socket/chats.js +1183 -0
  89. package/lib/Socket/chats.js.map +1 -0
  90. package/lib/Socket/communities.d.ts +267 -0
  91. package/lib/Socket/communities.d.ts.map +1 -0
  92. package/lib/Socket/communities.js +431 -0
  93. package/lib/Socket/communities.js.map +1 -0
  94. package/lib/Socket/groups.d.ts +159 -0
  95. package/lib/Socket/groups.d.ts.map +1 -0
  96. package/lib/Socket/groups.js +333 -0
  97. package/lib/Socket/groups.js.map +1 -0
  98. package/lib/Socket/index.d.ts +254 -0
  99. package/lib/Socket/index.d.ts.map +1 -0
  100. package/lib/Socket/index.js +12 -0
  101. package/lib/Socket/index.js.map +1 -0
  102. package/lib/Socket/messages-recv.d.ts +196 -0
  103. package/lib/Socket/messages-recv.d.ts.map +1 -0
  104. package/lib/Socket/messages-recv.js +1477 -0
  105. package/lib/Socket/messages-recv.js.map +1 -0
  106. package/lib/Socket/messages-send.d.ts +192 -0
  107. package/lib/Socket/messages-send.d.ts.map +1 -0
  108. package/lib/Socket/messages-send.js +1150 -0
  109. package/lib/Socket/messages-send.js.map +1 -0
  110. package/lib/Socket/mex.d.ts +3 -0
  111. package/lib/Socket/mex.d.ts.map +1 -0
  112. package/lib/Socket/mex.js +42 -0
  113. package/lib/Socket/mex.js.map +1 -0
  114. package/lib/Socket/newsletter.d.ts +169 -0
  115. package/lib/Socket/newsletter.d.ts.map +1 -0
  116. package/lib/Socket/newsletter.js +181 -0
  117. package/lib/Socket/newsletter.js.map +1 -0
  118. package/lib/Socket/socket.d.ts +59 -0
  119. package/lib/Socket/socket.d.ts.map +1 -0
  120. package/lib/Socket/socket.js +943 -0
  121. package/lib/Socket/socket.js.map +1 -0
  122. package/lib/Types/Auth.d.ts +117 -0
  123. package/lib/Types/Auth.d.ts.map +1 -0
  124. package/lib/Types/Auth.js +2 -0
  125. package/lib/Types/Auth.js.map +1 -0
  126. package/lib/Types/Bussines.d.ts +25 -0
  127. package/lib/Types/Bussines.d.ts.map +1 -0
  128. package/lib/Types/Bussines.js +2 -0
  129. package/lib/Types/Bussines.js.map +1 -0
  130. package/lib/Types/Call.d.ts +15 -0
  131. package/lib/Types/Call.d.ts.map +1 -0
  132. package/lib/Types/Call.js +2 -0
  133. package/lib/Types/Call.js.map +1 -0
  134. package/lib/Types/Chat.d.ts +123 -0
  135. package/lib/Types/Chat.d.ts.map +1 -0
  136. package/lib/Types/Chat.js +8 -0
  137. package/lib/Types/Chat.js.map +1 -0
  138. package/lib/Types/Contact.d.ts +26 -0
  139. package/lib/Types/Contact.d.ts.map +1 -0
  140. package/lib/Types/Contact.js +2 -0
  141. package/lib/Types/Contact.js.map +1 -0
  142. package/lib/Types/Events.d.ts +253 -0
  143. package/lib/Types/Events.d.ts.map +1 -0
  144. package/lib/Types/Events.js +2 -0
  145. package/lib/Types/Events.js.map +1 -0
  146. package/lib/Types/GroupMetadata.d.ts +71 -0
  147. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  148. package/lib/Types/GroupMetadata.js +2 -0
  149. package/lib/Types/GroupMetadata.js.map +1 -0
  150. package/lib/Types/Label.d.ts +47 -0
  151. package/lib/Types/Label.d.ts.map +1 -0
  152. package/lib/Types/Label.js +25 -0
  153. package/lib/Types/Label.js.map +1 -0
  154. package/lib/Types/LabelAssociation.d.ts +30 -0
  155. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  156. package/lib/Types/LabelAssociation.js +7 -0
  157. package/lib/Types/LabelAssociation.js.map +1 -0
  158. package/lib/Types/Message.d.ts +346 -0
  159. package/lib/Types/Message.d.ts.map +1 -0
  160. package/lib/Types/Message.js +11 -0
  161. package/lib/Types/Message.js.map +1 -0
  162. package/lib/Types/Newsletter.d.ts +135 -0
  163. package/lib/Types/Newsletter.d.ts.map +1 -0
  164. package/lib/Types/Newsletter.js +31 -0
  165. package/lib/Types/Newsletter.js.map +1 -0
  166. package/lib/Types/Product.d.ts +79 -0
  167. package/lib/Types/Product.d.ts.map +1 -0
  168. package/lib/Types/Product.js +2 -0
  169. package/lib/Types/Product.js.map +1 -0
  170. package/lib/Types/Signal.d.ts +76 -0
  171. package/lib/Types/Signal.d.ts.map +1 -0
  172. package/lib/Types/Signal.js +2 -0
  173. package/lib/Types/Signal.js.map +1 -0
  174. package/lib/Types/Socket.d.ts +133 -0
  175. package/lib/Types/Socket.d.ts.map +1 -0
  176. package/lib/Types/Socket.js +3 -0
  177. package/lib/Types/Socket.js.map +1 -0
  178. package/lib/Types/State.d.ts +39 -0
  179. package/lib/Types/State.d.ts.map +1 -0
  180. package/lib/Types/State.js +13 -0
  181. package/lib/Types/State.js.map +1 -0
  182. package/lib/Types/USync.d.ts +26 -0
  183. package/lib/Types/USync.d.ts.map +1 -0
  184. package/lib/Types/USync.js +2 -0
  185. package/lib/Types/USync.js.map +1 -0
  186. package/lib/Types/index.d.ts +65 -0
  187. package/lib/Types/index.d.ts.map +1 -0
  188. package/lib/Types/index.js +26 -0
  189. package/lib/Types/index.js.map +1 -0
  190. package/lib/Utils/auth-utils.d.ts +19 -0
  191. package/lib/Utils/auth-utils.d.ts.map +1 -0
  192. package/lib/Utils/auth-utils.js +290 -0
  193. package/lib/Utils/auth-utils.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 +23 -0
  199. package/lib/Utils/business.d.ts.map +1 -0
  200. package/lib/Utils/business.js +231 -0
  201. package/lib/Utils/business.js.map +1 -0
  202. package/lib/Utils/chat-utils.d.ts +100 -0
  203. package/lib/Utils/chat-utils.d.ts.map +1 -0
  204. package/lib/Utils/chat-utils.js +838 -0
  205. package/lib/Utils/chat-utils.js.map +1 -0
  206. package/lib/Utils/crypto.d.ts +37 -0
  207. package/lib/Utils/crypto.d.ts.map +1 -0
  208. package/lib/Utils/crypto.js +118 -0
  209. package/lib/Utils/crypto.js.map +1 -0
  210. package/lib/Utils/decode-wa-message.d.ts +60 -0
  211. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  212. package/lib/Utils/decode-wa-message.js +299 -0
  213. package/lib/Utils/decode-wa-message.js.map +1 -0
  214. package/lib/Utils/event-buffer.d.ts +34 -0
  215. package/lib/Utils/event-buffer.d.ts.map +1 -0
  216. package/lib/Utils/event-buffer.js +576 -0
  217. package/lib/Utils/event-buffer.js.map +1 -0
  218. package/lib/Utils/generics.d.ts +91 -0
  219. package/lib/Utils/generics.d.ts.map +1 -0
  220. package/lib/Utils/generics.js +393 -0
  221. package/lib/Utils/generics.js.map +1 -0
  222. package/lib/Utils/history.d.ts +22 -0
  223. package/lib/Utils/history.d.ts.map +1 -0
  224. package/lib/Utils/history.js +133 -0
  225. package/lib/Utils/history.js.map +1 -0
  226. package/lib/Utils/identity-change-handler.d.ts +44 -0
  227. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  228. package/lib/Utils/identity-change-handler.js +50 -0
  229. package/lib/Utils/identity-change-handler.js.map +1 -0
  230. package/lib/Utils/index.d.ts +21 -0
  231. package/lib/Utils/index.d.ts.map +1 -0
  232. package/lib/Utils/index.js +21 -0
  233. package/lib/Utils/index.js.map +1 -0
  234. package/lib/Utils/link-preview.d.ts +21 -0
  235. package/lib/Utils/link-preview.d.ts.map +1 -0
  236. package/lib/Utils/link-preview.js +85 -0
  237. package/lib/Utils/link-preview.js.map +1 -0
  238. package/lib/Utils/logger.d.ts +13 -0
  239. package/lib/Utils/logger.d.ts.map +1 -0
  240. package/lib/Utils/logger.js +3 -0
  241. package/lib/Utils/logger.js.map +1 -0
  242. package/lib/Utils/lt-hash.d.ts +8 -0
  243. package/lib/Utils/lt-hash.d.ts.map +1 -0
  244. package/lib/Utils/lt-hash.js +8 -0
  245. package/lib/Utils/lt-hash.js.map +1 -0
  246. package/lib/Utils/make-mutex.d.ts +9 -0
  247. package/lib/Utils/make-mutex.d.ts.map +1 -0
  248. package/lib/Utils/make-mutex.js +33 -0
  249. package/lib/Utils/make-mutex.js.map +1 -0
  250. package/lib/Utils/message-retry-manager.d.ts +110 -0
  251. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  252. package/lib/Utils/message-retry-manager.js +225 -0
  253. package/lib/Utils/message-retry-manager.js.map +1 -0
  254. package/lib/Utils/messages-media.d.ts +130 -0
  255. package/lib/Utils/messages-media.d.ts.map +1 -0
  256. package/lib/Utils/messages-media.js +774 -0
  257. package/lib/Utils/messages-media.js.map +1 -0
  258. package/lib/Utils/messages.d.ts +91 -0
  259. package/lib/Utils/messages.d.ts.map +1 -0
  260. package/lib/Utils/messages.js +1011 -0
  261. package/lib/Utils/messages.js.map +1 -0
  262. package/lib/Utils/noise-handler.d.ts +20 -0
  263. package/lib/Utils/noise-handler.d.ts.map +1 -0
  264. package/lib/Utils/noise-handler.js +201 -0
  265. package/lib/Utils/noise-handler.js.map +1 -0
  266. package/lib/Utils/offline-node-processor.d.ts +17 -0
  267. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  268. package/lib/Utils/offline-node-processor.js +40 -0
  269. package/lib/Utils/offline-node-processor.js.map +1 -0
  270. package/lib/Utils/pre-key-manager.d.ts +28 -0
  271. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  272. package/lib/Utils/pre-key-manager.js +106 -0
  273. package/lib/Utils/pre-key-manager.js.map +1 -0
  274. package/lib/Utils/process-message.d.ts +60 -0
  275. package/lib/Utils/process-message.d.ts.map +1 -0
  276. package/lib/Utils/process-message.js +586 -0
  277. package/lib/Utils/process-message.js.map +1 -0
  278. package/lib/Utils/reporting-utils.d.ts +11 -0
  279. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  280. package/lib/Utils/reporting-utils.js +258 -0
  281. package/lib/Utils/reporting-utils.js.map +1 -0
  282. package/lib/Utils/signal.d.ts +34 -0
  283. package/lib/Utils/signal.d.ts.map +1 -0
  284. package/lib/Utils/signal.js +159 -0
  285. package/lib/Utils/signal.js.map +1 -0
  286. package/lib/Utils/stanza-ack.d.ts +11 -0
  287. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  288. package/lib/Utils/stanza-ack.js +38 -0
  289. package/lib/Utils/stanza-ack.js.map +1 -0
  290. package/lib/Utils/sync-action-utils.d.ts +19 -0
  291. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  292. package/lib/Utils/sync-action-utils.js +49 -0
  293. package/lib/Utils/sync-action-utils.js.map +1 -0
  294. package/lib/Utils/tc-token-utils.d.ts +37 -0
  295. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  296. package/lib/Utils/tc-token-utils.js +163 -0
  297. package/lib/Utils/tc-token-utils.js.map +1 -0
  298. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  299. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  300. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  301. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  302. package/lib/Utils/validate-connection.d.ts +11 -0
  303. package/lib/Utils/validate-connection.d.ts.map +1 -0
  304. package/lib/Utils/validate-connection.js +200 -0
  305. package/lib/Utils/validate-connection.js.map +1 -0
  306. package/lib/WABinary/constants.d.ts +28 -0
  307. package/lib/WABinary/constants.d.ts.map +1 -0
  308. package/lib/WABinary/constants.js +1301 -0
  309. package/lib/WABinary/constants.js.map +1 -0
  310. package/lib/WABinary/decode.d.ts +7 -0
  311. package/lib/WABinary/decode.d.ts.map +1 -0
  312. package/lib/WABinary/decode.js +262 -0
  313. package/lib/WABinary/decode.js.map +1 -0
  314. package/lib/WABinary/encode.d.ts +3 -0
  315. package/lib/WABinary/encode.d.ts.map +1 -0
  316. package/lib/WABinary/encode.js +220 -0
  317. package/lib/WABinary/encode.js.map +1 -0
  318. package/lib/WABinary/generic-utils.d.ts +15 -0
  319. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  320. package/lib/WABinary/generic-utils.js +113 -0
  321. package/lib/WABinary/generic-utils.js.map +1 -0
  322. package/lib/WABinary/index.d.ts +6 -0
  323. package/lib/WABinary/index.d.ts.map +1 -0
  324. package/lib/WABinary/index.js +6 -0
  325. package/lib/WABinary/index.js.map +1 -0
  326. package/lib/WABinary/jid-utils.d.ts +48 -0
  327. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  328. package/lib/WABinary/jid-utils.js +96 -0
  329. package/lib/WABinary/jid-utils.js.map +1 -0
  330. package/lib/WABinary/types.d.ts +19 -0
  331. package/lib/WABinary/types.d.ts.map +1 -0
  332. package/lib/WABinary/types.js +2 -0
  333. package/lib/WABinary/types.js.map +1 -0
  334. package/lib/WAM/BinaryInfo.d.ts +9 -0
  335. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  336. package/lib/WAM/BinaryInfo.js +10 -0
  337. package/lib/WAM/BinaryInfo.js.map +1 -0
  338. package/lib/WAM/constants.d.ts +40 -0
  339. package/lib/WAM/constants.d.ts.map +1 -0
  340. package/lib/WAM/constants.js +22853 -0
  341. package/lib/WAM/constants.js.map +1 -0
  342. package/lib/WAM/encode.d.ts +3 -0
  343. package/lib/WAM/encode.d.ts.map +1 -0
  344. package/lib/WAM/encode.js +150 -0
  345. package/lib/WAM/encode.js.map +1 -0
  346. package/lib/WAM/index.d.ts +4 -0
  347. package/lib/WAM/index.d.ts.map +1 -0
  348. package/lib/WAM/index.js +4 -0
  349. package/lib/WAM/index.js.map +1 -0
  350. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  351. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  352. package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
  353. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  354. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  355. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  356. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  357. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  358. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  359. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  360. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  361. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  362. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  363. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  364. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  365. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  366. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  367. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  368. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  369. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  370. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  371. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  372. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  373. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  374. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  375. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  376. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  377. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  378. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  379. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  380. package/lib/WAUSync/Protocols/index.js +6 -0
  381. package/lib/WAUSync/Protocols/index.js.map +1 -0
  382. package/lib/WAUSync/USyncQuery.d.ts +30 -0
  383. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  384. package/lib/WAUSync/USyncQuery.js +98 -0
  385. package/lib/WAUSync/USyncQuery.js.map +1 -0
  386. package/lib/WAUSync/USyncUser.d.ts +17 -0
  387. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  388. package/lib/WAUSync/USyncUser.js +31 -0
  389. package/lib/WAUSync/USyncUser.js.map +1 -0
  390. package/lib/WAUSync/index.d.ts +4 -0
  391. package/lib/WAUSync/index.d.ts.map +1 -0
  392. package/lib/WAUSync/index.js +4 -0
  393. package/lib/WAUSync/index.js.map +1 -0
  394. package/lib/index.d.ts +12 -0
  395. package/lib/index.d.ts.map +1 -0
  396. package/lib/index.js +11 -0
  397. package/lib/index.js.map +1 -0
  398. package/package.json +128 -0
@@ -0,0 +1,838 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { expandAppStateKeys } from 'whatsapp-rust-bridge';
3
+ import { proto } from '../../WAProto/index.js';
4
+ import { LabelAssociationType } from '../Types/LabelAssociation.js';
5
+ import { getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, jidNormalizedUser } from '../WABinary/index.js';
6
+ import { aesDecrypt, aesEncrypt, hmacSign } from './crypto.js';
7
+ import { toNumber } from './generics.js';
8
+ import { LT_HASH_ANTI_TAMPERING } from './lt-hash.js';
9
+ import { downloadContentFromMessage } from './messages-media.js';
10
+ import { emitSyncActionResults, processContactAction } from './sync-action-utils.js';
11
+ const mutationKeys = (keydata) => {
12
+ const keys = expandAppStateKeys(keydata);
13
+ return {
14
+ indexKey: keys.indexKey,
15
+ valueEncryptionKey: keys.valueEncryptionKey,
16
+ valueMacKey: keys.valueMacKey,
17
+ snapshotMacKey: keys.snapshotMacKey,
18
+ patchMacKey: keys.patchMacKey
19
+ };
20
+ };
21
+ const generateMac = (operation, data, keyId, key) => {
22
+ const opByte = operation === proto.SyncdMutation.SyncdOperation.SET ? 0x01 : 0x02;
23
+ const keyIdBuffer = typeof keyId === 'string' ? Buffer.from(keyId, 'base64') : keyId;
24
+ const keyData = new Uint8Array(1 + keyIdBuffer.length);
25
+ keyData[0] = opByte;
26
+ keyData.set(keyIdBuffer, 1);
27
+ const last = new Uint8Array(8);
28
+ last[7] = keyData.length;
29
+ const total = new Uint8Array(keyData.length + data.length + last.length);
30
+ total.set(keyData, 0);
31
+ total.set(data, keyData.length);
32
+ total.set(last, keyData.length + data.length);
33
+ const hmac = hmacSign(total, key, 'sha512');
34
+ return hmac.subarray(0, 32);
35
+ };
36
+ const to64BitNetworkOrder = (e) => {
37
+ const buff = Buffer.alloc(8);
38
+ buff.writeUint32BE(e, 4);
39
+ return buff;
40
+ };
41
+ export const makeLtHashGenerator = ({ indexValueMap, hash }) => {
42
+ indexValueMap = { ...indexValueMap };
43
+ const addBuffs = [];
44
+ const subBuffs = [];
45
+ return {
46
+ mix: ({ indexMac, valueMac, operation }) => {
47
+ const indexMacBase64 = Buffer.from(indexMac).toString('base64');
48
+ const prevOp = indexValueMap[indexMacBase64];
49
+ if (operation === proto.SyncdMutation.SyncdOperation.REMOVE) {
50
+ if (!prevOp) {
51
+ // WA Web does not throw here — it logs a warning and skips the subtract.
52
+ // The missing REMOVE will cause an LTHash mismatch, which is handled
53
+ // by the MAC validation layer (snapshot recovery or retry).
54
+ return;
55
+ }
56
+ // remove from index value mac, since this mutation is erased
57
+ delete indexValueMap[indexMacBase64];
58
+ }
59
+ else {
60
+ addBuffs.push(valueMac);
61
+ // add this index into the history map
62
+ indexValueMap[indexMacBase64] = { valueMac };
63
+ }
64
+ if (prevOp) {
65
+ subBuffs.push(prevOp.valueMac);
66
+ }
67
+ },
68
+ finish: () => {
69
+ const result = LT_HASH_ANTI_TAMPERING.subtractThenAdd(hash, subBuffs, addBuffs);
70
+ return {
71
+ hash: Buffer.from(result),
72
+ indexValueMap
73
+ };
74
+ }
75
+ };
76
+ };
77
+ const generateSnapshotMac = (lthash, version, name, key) => {
78
+ const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, 'utf-8')]);
79
+ return hmacSign(total, key, 'sha256');
80
+ };
81
+ const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
82
+ const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, 'utf-8')]);
83
+ return hmacSign(total, key);
84
+ };
85
+ export const newLTHashState = () => ({ version: 0, hash: Buffer.alloc(128), indexValueMap: {} });
86
+ export const ensureLTHashStateVersion = (state) => {
87
+ if (typeof state.version !== 'number' || isNaN(state.version)) {
88
+ state.version = 0;
89
+ }
90
+ return state;
91
+ };
92
+ export const MAX_SYNC_ATTEMPTS = 2;
93
+ /**
94
+ * Check if an error is a missing app state sync key.
95
+ * WA Web treats these as "Blocked" (waits for key arrival), not fatal.
96
+ * In Baileys we retry with a snapshot which may use a different key.
97
+ */
98
+ export const isMissingKeyError = (error) => {
99
+ return error?.data?.isMissingKey === true;
100
+ };
101
+ /**
102
+ * Determines if an app state sync error is unrecoverable.
103
+ * TypeError indicates a WASM crash; otherwise we give up after MAX_SYNC_ATTEMPTS.
104
+ * Missing keys are NOT checked here — they are handled separately as "Blocked".
105
+ */
106
+ export const isAppStateSyncIrrecoverable = (error, attempts) => {
107
+ return attempts >= MAX_SYNC_ATTEMPTS || error?.name === 'TypeError';
108
+ };
109
+ export const encodeSyncdPatch = async ({ type, index, syncAction, apiVersion, operation }, myAppStateKeyId, state, getAppStateSyncKey) => {
110
+ const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
111
+ if (!key) {
112
+ throw new Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, { data: { isMissingKey: true } });
113
+ }
114
+ const encKeyId = Buffer.from(myAppStateKeyId, 'base64');
115
+ state = { ...state, indexValueMap: { ...state.indexValueMap } };
116
+ const indexBuffer = Buffer.from(JSON.stringify(index));
117
+ const dataProto = proto.SyncActionData.fromObject({
118
+ index: indexBuffer,
119
+ value: syncAction,
120
+ padding: new Uint8Array(0),
121
+ version: apiVersion
122
+ });
123
+ const encoded = proto.SyncActionData.encode(dataProto).finish();
124
+ const keyValue = mutationKeys(key.keyData);
125
+ const encValue = aesEncrypt(encoded, keyValue.valueEncryptionKey);
126
+ const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
127
+ const indexMac = hmacSign(indexBuffer, keyValue.indexKey);
128
+ // update LT hash
129
+ const generator = makeLtHashGenerator(state);
130
+ generator.mix({ indexMac, valueMac, operation });
131
+ Object.assign(state, generator.finish());
132
+ state.version += 1;
133
+ const snapshotMac = generateSnapshotMac(state.hash, state.version, type, keyValue.snapshotMacKey);
134
+ const patch = {
135
+ patchMac: generatePatchMac(snapshotMac, [valueMac], state.version, type, keyValue.patchMacKey),
136
+ snapshotMac: snapshotMac,
137
+ keyId: { id: encKeyId },
138
+ mutations: [
139
+ {
140
+ operation: operation,
141
+ record: {
142
+ index: {
143
+ blob: indexMac
144
+ },
145
+ value: {
146
+ blob: Buffer.concat([encValue, valueMac])
147
+ },
148
+ keyId: { id: encKeyId }
149
+ }
150
+ }
151
+ ]
152
+ };
153
+ const base64Index = indexMac.toString('base64');
154
+ state.indexValueMap[base64Index] = { valueMac };
155
+ return { patch, state };
156
+ };
157
+ export const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
158
+ const ltGenerator = makeLtHashGenerator(initialState);
159
+ const derivedKeyCache = new Map();
160
+ // indexKey used to HMAC sign record.index.blob
161
+ // valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
162
+ // the remaining record.value.blob[0:-32] is the mac, it the HMAC sign of key.keyId + decoded proto data + length of bytes in keyId
163
+ for (const msgMutation of msgMutations) {
164
+ // if it's a syncdmutation, get the operation property
165
+ // otherwise, if it's only a record -- it'll be a SET mutation
166
+ const operation = 'operation' in msgMutation ? msgMutation.operation : proto.SyncdMutation.SyncdOperation.SET;
167
+ const record = 'record' in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
168
+ const key = await getKey(record.keyId.id);
169
+ const content = record.value.blob;
170
+ const encContent = content.subarray(0, -32);
171
+ const ogValueMac = content.subarray(-32);
172
+ if (validateMacs) {
173
+ const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
174
+ if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
175
+ throw new Boom('HMAC content verification failed');
176
+ }
177
+ }
178
+ const result = aesDecrypt(encContent, key.valueEncryptionKey);
179
+ const syncAction = proto.SyncActionData.decode(result);
180
+ if (validateMacs) {
181
+ const hmac = hmacSign(syncAction.index, key.indexKey);
182
+ if (Buffer.compare(hmac, record.index.blob) !== 0) {
183
+ throw new Boom('HMAC index verification failed');
184
+ }
185
+ }
186
+ const indexStr = Buffer.from(syncAction.index).toString();
187
+ onMutation({ syncAction, index: JSON.parse(indexStr) });
188
+ ltGenerator.mix({
189
+ indexMac: record.index.blob,
190
+ valueMac: ogValueMac,
191
+ operation: operation
192
+ });
193
+ }
194
+ return ltGenerator.finish();
195
+ async function getKey(keyId) {
196
+ const base64Key = Buffer.from(keyId).toString('base64');
197
+ const cached = derivedKeyCache.get(base64Key);
198
+ if (cached) {
199
+ return cached;
200
+ }
201
+ const keyEnc = await getAppStateSyncKey(base64Key);
202
+ if (!keyEnc) {
203
+ throw new Boom(`failed to find key "${base64Key}" to decode mutation`, {
204
+ data: { isMissingKey: true, msgMutations }
205
+ });
206
+ }
207
+ const keys = mutationKeys(keyEnc.keyData);
208
+ derivedKeyCache.set(base64Key, keys);
209
+ return keys;
210
+ }
211
+ };
212
+ export const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
213
+ if (validateMacs) {
214
+ const base64Key = Buffer.from(msg.keyId.id).toString('base64');
215
+ const mainKeyObj = await getAppStateSyncKey(base64Key);
216
+ if (!mainKeyObj) {
217
+ throw new Boom(`failed to find key "${base64Key}" to decode patch`, { data: { isMissingKey: true, msg } });
218
+ }
219
+ const mainKey = mutationKeys(mainKeyObj.keyData);
220
+ const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
221
+ const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, toNumber(msg.version.version), name, mainKey.patchMacKey);
222
+ if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
223
+ throw new Boom('Invalid patch mac');
224
+ }
225
+ }
226
+ const result = await decodeSyncdMutations(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
227
+ return result;
228
+ };
229
+ export const extractSyncdPatches = async (result, options) => {
230
+ const syncNode = getBinaryNodeChild(result, 'sync');
231
+ const collectionNodes = getBinaryNodeChildren(syncNode, 'collection');
232
+ const final = {};
233
+ await Promise.all(collectionNodes.map(async (collectionNode) => {
234
+ const patchesNode = getBinaryNodeChild(collectionNode, 'patches');
235
+ const patches = getBinaryNodeChildren(patchesNode || collectionNode, 'patch');
236
+ const snapshotNode = getBinaryNodeChild(collectionNode, 'snapshot');
237
+ const syncds = [];
238
+ const name = collectionNode.attrs.name;
239
+ const hasMorePatches = collectionNode.attrs.has_more_patches === 'true';
240
+ let snapshot = undefined;
241
+ if (snapshotNode && !!snapshotNode.content) {
242
+ if (!Buffer.isBuffer(snapshotNode)) {
243
+ snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
244
+ }
245
+ const blobRef = proto.ExternalBlobReference.decode(snapshotNode.content);
246
+ const data = await downloadExternalBlob(blobRef, options);
247
+ snapshot = proto.SyncdSnapshot.decode(data);
248
+ }
249
+ for (let { content } of patches) {
250
+ if (content) {
251
+ if (!Buffer.isBuffer(content)) {
252
+ content = Buffer.from(Object.values(content));
253
+ }
254
+ const syncd = proto.SyncdPatch.decode(content);
255
+ if (!syncd.version) {
256
+ syncd.version = { version: +collectionNode.attrs.version + 1 };
257
+ }
258
+ syncds.push(syncd);
259
+ }
260
+ }
261
+ final[name] = { patches: syncds, hasMorePatches, snapshot };
262
+ }));
263
+ return final;
264
+ };
265
+ export const downloadExternalBlob = async (blob, options) => {
266
+ const stream = await downloadContentFromMessage(blob, 'md-app-state', { options });
267
+ const bufferArray = [];
268
+ for await (const chunk of stream) {
269
+ bufferArray.push(chunk);
270
+ }
271
+ return Buffer.concat(bufferArray);
272
+ };
273
+ export const downloadExternalPatch = async (blob, options) => {
274
+ const buffer = await downloadExternalBlob(blob, options);
275
+ const syncData = proto.SyncdMutations.decode(buffer);
276
+ return syncData;
277
+ };
278
+ export const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
279
+ const newState = newLTHashState();
280
+ newState.version = toNumber(snapshot.version.version);
281
+ const mutationMap = {};
282
+ const areMutationsRequired = typeof minimumVersionNumber === 'undefined' || newState.version > minimumVersionNumber;
283
+ const { hash, indexValueMap } = await decodeSyncdMutations(snapshot.records, newState, getAppStateSyncKey, areMutationsRequired
284
+ ? mutation => {
285
+ const index = mutation.syncAction.index?.toString();
286
+ mutationMap[index] = mutation;
287
+ }
288
+ : () => { }, validateMacs);
289
+ newState.hash = hash;
290
+ newState.indexValueMap = indexValueMap;
291
+ if (validateMacs) {
292
+ const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
293
+ const keyEnc = await getAppStateSyncKey(base64Key);
294
+ if (!keyEnc) {
295
+ throw new Boom(`failed to find key "${base64Key}" to decode mutation`, { data: { isMissingKey: true } });
296
+ }
297
+ const result = mutationKeys(keyEnc.keyData);
298
+ const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
299
+ if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
300
+ throw new Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
301
+ }
302
+ }
303
+ return {
304
+ state: newState,
305
+ mutationMap
306
+ };
307
+ };
308
+ export const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
309
+ const newState = {
310
+ ...initial,
311
+ indexValueMap: { ...initial.indexValueMap }
312
+ };
313
+ const mutationMap = {};
314
+ for (const syncd of syncds) {
315
+ const { version, keyId, snapshotMac } = syncd;
316
+ if (syncd.externalMutations) {
317
+ logger?.trace({ name, version }, 'downloading external patch');
318
+ const ref = await downloadExternalPatch(syncd.externalMutations, options);
319
+ logger?.debug({ name, version, mutations: ref.mutations.length }, 'downloaded external patch');
320
+ syncd.mutations?.push(...ref.mutations);
321
+ }
322
+ const patchVersion = toNumber(version.version);
323
+ newState.version = patchVersion;
324
+ const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
325
+ const decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate
326
+ ? mutation => {
327
+ const index = mutation.syncAction.index?.toString();
328
+ mutationMap[index] = mutation;
329
+ }
330
+ : () => { }, true);
331
+ newState.hash = decodeResult.hash;
332
+ newState.indexValueMap = decodeResult.indexValueMap;
333
+ if (validateMacs) {
334
+ const base64Key = Buffer.from(keyId.id).toString('base64');
335
+ const keyEnc = await getAppStateSyncKey(base64Key);
336
+ if (!keyEnc) {
337
+ throw new Boom(`failed to find key "${base64Key}" to decode mutation`, { data: { isMissingKey: true } });
338
+ }
339
+ const result = mutationKeys(keyEnc.keyData);
340
+ const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
341
+ if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
342
+ throw new Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
343
+ }
344
+ }
345
+ // clear memory used up by the mutations
346
+ syncd.mutations = [];
347
+ }
348
+ return { state: newState, mutationMap };
349
+ };
350
+ export const chatModificationToAppPatch = (mod, jid) => {
351
+ const OP = proto.SyncdMutation.SyncdOperation;
352
+ const getMessageRange = (lastMessages) => {
353
+ let messageRange;
354
+ if (Array.isArray(lastMessages)) {
355
+ const lastMsg = lastMessages[lastMessages.length - 1];
356
+ messageRange = {
357
+ lastMessageTimestamp: lastMsg?.messageTimestamp,
358
+ messages: lastMessages?.length
359
+ ? lastMessages.map(m => {
360
+ if (!m.key?.id || !m.key?.remoteJid) {
361
+ throw new Boom('Incomplete key', { statusCode: 400, data: m });
362
+ }
363
+ if (isJidGroup(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
364
+ throw new Boom('Expected not from me message to have participant', { statusCode: 400, data: m });
365
+ }
366
+ if (!m.messageTimestamp || !toNumber(m.messageTimestamp)) {
367
+ throw new Boom('Missing timestamp in last message list', { statusCode: 400, data: m });
368
+ }
369
+ if (m.key.participant) {
370
+ m.key.participant = jidNormalizedUser(m.key.participant);
371
+ }
372
+ return m;
373
+ })
374
+ : undefined
375
+ };
376
+ }
377
+ else {
378
+ messageRange = lastMessages;
379
+ }
380
+ return messageRange;
381
+ };
382
+ let patch;
383
+ if ('mute' in mod) {
384
+ patch = {
385
+ syncAction: {
386
+ muteAction: {
387
+ muted: !!mod.mute,
388
+ muteEndTimestamp: mod.mute || undefined
389
+ }
390
+ },
391
+ index: ['mute', jid],
392
+ type: 'regular_high',
393
+ apiVersion: 2,
394
+ operation: OP.SET
395
+ };
396
+ }
397
+ else if ('archive' in mod) {
398
+ patch = {
399
+ syncAction: {
400
+ archiveChatAction: {
401
+ archived: !!mod.archive,
402
+ messageRange: getMessageRange(mod.lastMessages)
403
+ }
404
+ },
405
+ index: ['archive', jid],
406
+ type: 'regular_low',
407
+ apiVersion: 3,
408
+ operation: OP.SET
409
+ };
410
+ }
411
+ else if ('markRead' in mod) {
412
+ patch = {
413
+ syncAction: {
414
+ markChatAsReadAction: {
415
+ read: mod.markRead,
416
+ messageRange: getMessageRange(mod.lastMessages)
417
+ }
418
+ },
419
+ index: ['markChatAsRead', jid],
420
+ type: 'regular_low',
421
+ apiVersion: 3,
422
+ operation: OP.SET
423
+ };
424
+ }
425
+ else if ('deleteForMe' in mod) {
426
+ const { timestamp, key, deleteMedia } = mod.deleteForMe;
427
+ patch = {
428
+ syncAction: {
429
+ deleteMessageForMeAction: {
430
+ deleteMedia,
431
+ messageTimestamp: timestamp
432
+ }
433
+ },
434
+ index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
435
+ type: 'regular_high',
436
+ apiVersion: 3,
437
+ operation: OP.SET
438
+ };
439
+ }
440
+ else if ('clear' in mod) {
441
+ patch = {
442
+ syncAction: {
443
+ clearChatAction: {
444
+ messageRange: getMessageRange(mod.lastMessages)
445
+ }
446
+ },
447
+ index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
448
+ type: 'regular_high',
449
+ apiVersion: 6,
450
+ operation: OP.SET
451
+ };
452
+ }
453
+ else if ('pin' in mod) {
454
+ patch = {
455
+ syncAction: {
456
+ pinAction: {
457
+ pinned: !!mod.pin
458
+ }
459
+ },
460
+ index: ['pin_v1', jid],
461
+ type: 'regular_low',
462
+ apiVersion: 5,
463
+ operation: OP.SET
464
+ };
465
+ }
466
+ else if ('contact' in mod) {
467
+ patch = {
468
+ syncAction: {
469
+ contactAction: mod.contact || {}
470
+ },
471
+ index: ['contact', jid],
472
+ type: 'critical_unblock_low',
473
+ apiVersion: 2,
474
+ operation: mod.contact ? OP.SET : OP.REMOVE
475
+ };
476
+ }
477
+ else if ('disableLinkPreviews' in mod) {
478
+ patch = {
479
+ syncAction: {
480
+ privacySettingDisableLinkPreviewsAction: mod.disableLinkPreviews || {}
481
+ },
482
+ index: ['setting_disableLinkPreviews'],
483
+ type: 'regular',
484
+ apiVersion: 8,
485
+ operation: OP.SET
486
+ };
487
+ }
488
+ else if ('star' in mod) {
489
+ const key = mod.star.messages[0];
490
+ patch = {
491
+ syncAction: {
492
+ starAction: {
493
+ starred: !!mod.star.star
494
+ }
495
+ },
496
+ index: ['star', jid, key.id, key.fromMe ? '1' : '0', '0'],
497
+ type: 'regular_low',
498
+ apiVersion: 2,
499
+ operation: OP.SET
500
+ };
501
+ }
502
+ else if ('delete' in mod) {
503
+ patch = {
504
+ syncAction: {
505
+ deleteChatAction: {
506
+ messageRange: getMessageRange(mod.lastMessages)
507
+ }
508
+ },
509
+ index: ['deleteChat', jid, '1'],
510
+ type: 'regular_high',
511
+ apiVersion: 6,
512
+ operation: OP.SET
513
+ };
514
+ }
515
+ else if ('pushNameSetting' in mod) {
516
+ patch = {
517
+ syncAction: {
518
+ pushNameSetting: {
519
+ name: mod.pushNameSetting
520
+ }
521
+ },
522
+ index: ['setting_pushName'],
523
+ type: 'critical_block',
524
+ apiVersion: 1,
525
+ operation: OP.SET
526
+ };
527
+ }
528
+ else if ('quickReply' in mod) {
529
+ patch = {
530
+ syncAction: {
531
+ quickReplyAction: {
532
+ count: 0,
533
+ deleted: mod.quickReply.deleted || false,
534
+ keywords: [],
535
+ message: mod.quickReply.message || '',
536
+ shortcut: mod.quickReply.shortcut || ''
537
+ }
538
+ },
539
+ index: ['quick_reply', mod.quickReply.timestamp || String(Math.floor(Date.now() / 1000))],
540
+ type: 'regular',
541
+ apiVersion: 2,
542
+ operation: OP.SET
543
+ };
544
+ }
545
+ else if ('addLabel' in mod) {
546
+ patch = {
547
+ syncAction: {
548
+ labelEditAction: {
549
+ name: mod.addLabel.name,
550
+ color: mod.addLabel.color,
551
+ predefinedId: mod.addLabel.predefinedId,
552
+ deleted: mod.addLabel.deleted
553
+ }
554
+ },
555
+ index: ['label_edit', mod.addLabel.id],
556
+ type: 'regular',
557
+ apiVersion: 3,
558
+ operation: OP.SET
559
+ };
560
+ }
561
+ else if ('addChatLabel' in mod) {
562
+ patch = {
563
+ syncAction: {
564
+ labelAssociationAction: {
565
+ labeled: true
566
+ }
567
+ },
568
+ index: [LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
569
+ type: 'regular',
570
+ apiVersion: 3,
571
+ operation: OP.SET
572
+ };
573
+ }
574
+ else if ('removeChatLabel' in mod) {
575
+ patch = {
576
+ syncAction: {
577
+ labelAssociationAction: {
578
+ labeled: false
579
+ }
580
+ },
581
+ index: [LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
582
+ type: 'regular',
583
+ apiVersion: 3,
584
+ operation: OP.SET
585
+ };
586
+ }
587
+ else if ('addMessageLabel' in mod) {
588
+ patch = {
589
+ syncAction: {
590
+ labelAssociationAction: {
591
+ labeled: true
592
+ }
593
+ },
594
+ index: [LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
595
+ type: 'regular',
596
+ apiVersion: 3,
597
+ operation: OP.SET
598
+ };
599
+ }
600
+ else if ('removeMessageLabel' in mod) {
601
+ patch = {
602
+ syncAction: {
603
+ labelAssociationAction: {
604
+ labeled: false
605
+ }
606
+ },
607
+ index: [
608
+ LabelAssociationType.Message,
609
+ mod.removeMessageLabel.labelId,
610
+ jid,
611
+ mod.removeMessageLabel.messageId,
612
+ '0',
613
+ '0'
614
+ ],
615
+ type: 'regular',
616
+ apiVersion: 3,
617
+ operation: OP.SET
618
+ };
619
+ }
620
+ else {
621
+ throw new Boom('not supported');
622
+ }
623
+ patch.syncAction.timestamp = Date.now();
624
+ return patch;
625
+ };
626
+ export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
627
+ const isInitialSync = !!initialSyncOpts;
628
+ const accountSettings = initialSyncOpts?.accountSettings;
629
+ logger?.trace({ syncAction, initialSync: !!initialSyncOpts }, 'processing sync action');
630
+ const { syncAction: { value: action }, index: [type, id, msgId, fromMe] } = syncAction;
631
+ if (action?.muteAction) {
632
+ ev.emit('chats.update', [
633
+ {
634
+ id,
635
+ muteEndTime: action.muteAction?.muted ? toNumber(action.muteAction.muteEndTimestamp) : null,
636
+ conditional: getChatUpdateConditional(id, undefined)
637
+ }
638
+ ]);
639
+ }
640
+ else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
641
+ // okay so we've to do some annoying computation here
642
+ // when we're initially syncing the app state
643
+ // there are a few cases we need to handle
644
+ // 1. if the account unarchiveChats setting is true
645
+ // a. if the chat is archived, and no further messages have been received -- simple, keep archived
646
+ // b. if the chat was archived, and the user received messages from the other person afterwards
647
+ // then the chat should be marked unarchved --
648
+ // we compare the timestamp of latest message from the other person to determine this
649
+ // 2. if the account unarchiveChats setting is false -- then it doesn't matter,
650
+ // it'll always take an app state action to mark in unarchived -- which we'll get anyway
651
+ const archiveAction = action?.archiveChatAction;
652
+ const isArchived = archiveAction ? archiveAction.archived : type === 'archive';
653
+ // // basically we don't need to fire an "archive" update if the chat is being marked unarchvied
654
+ // // this only applies for the initial sync
655
+ // if(isInitialSync && !isArchived) {
656
+ // isArchived = false
657
+ // }
658
+ const msgRange = !accountSettings?.unarchiveChats ? undefined : archiveAction?.messageRange;
659
+ // logger?.debug({ chat: id, syncAction }, 'message range archive')
660
+ ev.emit('chats.update', [
661
+ {
662
+ id,
663
+ archived: isArchived,
664
+ conditional: getChatUpdateConditional(id, msgRange)
665
+ }
666
+ ]);
667
+ }
668
+ else if (action?.markChatAsReadAction) {
669
+ const markReadAction = action.markChatAsReadAction;
670
+ // basically we don't need to fire an "read" update if the chat is being marked as read
671
+ // because the chat is read by default
672
+ // this only applies for the initial sync
673
+ const isNullUpdate = isInitialSync && markReadAction.read;
674
+ ev.emit('chats.update', [
675
+ {
676
+ id,
677
+ unreadCount: isNullUpdate ? null : !!markReadAction?.read ? 0 : -1,
678
+ conditional: getChatUpdateConditional(id, markReadAction?.messageRange)
679
+ }
680
+ ]);
681
+ }
682
+ else if (action?.deleteMessageForMeAction || type === 'deleteMessageForMe') {
683
+ ev.emit('messages.delete', {
684
+ keys: [
685
+ {
686
+ remoteJid: id,
687
+ id: msgId,
688
+ fromMe: fromMe === '1'
689
+ }
690
+ ]
691
+ });
692
+ }
693
+ else if (action?.contactAction) {
694
+ const results = processContactAction(action.contactAction, id, logger);
695
+ emitSyncActionResults(ev, results);
696
+ }
697
+ else if (action?.pushNameSetting) {
698
+ const name = action?.pushNameSetting?.name;
699
+ if (name && me?.name !== name) {
700
+ ev.emit('creds.update', { me: { ...me, name } });
701
+ }
702
+ }
703
+ else if (action?.pinAction) {
704
+ ev.emit('chats.update', [
705
+ {
706
+ id,
707
+ pinned: action.pinAction?.pinned ? toNumber(action.timestamp) : null,
708
+ conditional: getChatUpdateConditional(id, undefined)
709
+ }
710
+ ]);
711
+ }
712
+ else if (action?.unarchiveChatsSetting) {
713
+ const unarchiveChats = !!action.unarchiveChatsSetting.unarchiveChats;
714
+ ev.emit('creds.update', { accountSettings: { unarchiveChats } });
715
+ logger?.info(`archive setting updated => '${action.unarchiveChatsSetting.unarchiveChats}'`);
716
+ if (accountSettings) {
717
+ accountSettings.unarchiveChats = unarchiveChats;
718
+ }
719
+ }
720
+ else if (action?.starAction || type === 'star') {
721
+ let starred = action?.starAction?.starred;
722
+ if (typeof starred !== 'boolean') {
723
+ starred = syncAction.index[syncAction.index.length - 1] === '1';
724
+ }
725
+ ev.emit('messages.update', [
726
+ {
727
+ key: { remoteJid: id, id: msgId, fromMe: fromMe === '1' },
728
+ update: { starred }
729
+ }
730
+ ]);
731
+ }
732
+ else if (action?.deleteChatAction || type === 'deleteChat') {
733
+ if (!isInitialSync) {
734
+ ev.emit('chats.delete', [id]);
735
+ }
736
+ }
737
+ else if (action?.labelEditAction) {
738
+ const { name, color, deleted, predefinedId } = action.labelEditAction;
739
+ ev.emit('labels.edit', {
740
+ id: id,
741
+ name: name,
742
+ color: color,
743
+ deleted: deleted,
744
+ predefinedId: predefinedId ? String(predefinedId) : undefined
745
+ });
746
+ }
747
+ else if (action?.labelAssociationAction) {
748
+ ev.emit('labels.association', {
749
+ type: action.labelAssociationAction.labeled ? 'add' : 'remove',
750
+ association: type === LabelAssociationType.Chat
751
+ ? {
752
+ type: LabelAssociationType.Chat,
753
+ chatId: syncAction.index[2],
754
+ labelId: syncAction.index[1]
755
+ }
756
+ : {
757
+ type: LabelAssociationType.Message,
758
+ chatId: syncAction.index[2],
759
+ messageId: syncAction.index[3],
760
+ labelId: syncAction.index[1]
761
+ }
762
+ });
763
+ }
764
+ else if (action?.localeSetting?.locale) {
765
+ ev.emit('settings.update', { setting: 'locale', value: action.localeSetting.locale });
766
+ }
767
+ else if (action?.timeFormatAction) {
768
+ ev.emit('settings.update', { setting: 'timeFormat', value: action.timeFormatAction });
769
+ }
770
+ else if (action?.pnForLidChatAction) {
771
+ if (action.pnForLidChatAction.pnJid) {
772
+ ev.emit('lid-mapping.update', { lid: id, pn: action.pnForLidChatAction.pnJid });
773
+ }
774
+ }
775
+ else if (action?.privacySettingRelayAllCalls) {
776
+ ev.emit('settings.update', {
777
+ setting: 'privacySettingRelayAllCalls',
778
+ value: action.privacySettingRelayAllCalls
779
+ });
780
+ }
781
+ else if (action?.statusPrivacy) {
782
+ ev.emit('settings.update', { setting: 'statusPrivacy', value: action.statusPrivacy });
783
+ }
784
+ else if (action?.lockChatAction) {
785
+ ev.emit('chats.lock', { id: id, locked: !!action.lockChatAction.locked });
786
+ }
787
+ else if (action?.privacySettingDisableLinkPreviewsAction) {
788
+ ev.emit('settings.update', {
789
+ setting: 'disableLinkPreviews',
790
+ value: action.privacySettingDisableLinkPreviewsAction
791
+ });
792
+ }
793
+ else if (action?.notificationActivitySettingAction?.notificationActivitySetting) {
794
+ ev.emit('settings.update', {
795
+ setting: 'notificationActivitySetting',
796
+ value: action.notificationActivitySettingAction.notificationActivitySetting
797
+ });
798
+ }
799
+ else if (action?.lidContactAction) {
800
+ ev.emit('contacts.upsert', [
801
+ {
802
+ id: id,
803
+ name: action.lidContactAction.fullName ||
804
+ action.lidContactAction.firstName ||
805
+ action.lidContactAction.username ||
806
+ undefined,
807
+ username: action.lidContactAction.username || undefined,
808
+ lid: id,
809
+ phoneNumber: undefined
810
+ }
811
+ ]);
812
+ }
813
+ else if (action?.privacySettingChannelsPersonalisedRecommendationAction) {
814
+ ev.emit('settings.update', {
815
+ setting: 'channelsPersonalisedRecommendation',
816
+ value: action.privacySettingChannelsPersonalisedRecommendationAction
817
+ });
818
+ }
819
+ else {
820
+ logger?.debug({ syncAction, id }, 'unprocessable update');
821
+ }
822
+ function getChatUpdateConditional(id, msgRange) {
823
+ return isInitialSync
824
+ ? data => {
825
+ const chat = data.historySets.chats[id] || data.chatUpserts[id];
826
+ if (chat) {
827
+ return msgRange ? isValidPatchBasedOnMessageRange(chat, msgRange) : true;
828
+ }
829
+ }
830
+ : undefined;
831
+ }
832
+ function isValidPatchBasedOnMessageRange(chat, msgRange) {
833
+ const lastMsgTimestamp = Number(msgRange?.lastMessageTimestamp || msgRange?.lastSystemMessageTimestamp || 0);
834
+ const chatLastMsgTimestamp = Number(chat?.lastMessageRecvTimestamp || 0);
835
+ return lastMsgTimestamp >= chatLastMsgTimestamp;
836
+ }
837
+ };
838
+ //# sourceMappingURL=chat-utils.js.map