@lynovratech/baileys 1.0.0

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