@neelegirl/baileys 1.5.6 → 1.5.8

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