lordceaser-baileys 2.0.38 → 2.0.39

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