@bellachu/xteambail 2.0.0

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