@neykoor/baileys 7.0.0-rc13

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 (465) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -0
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +5479 -0
  5. package/WAProto/fix-imports.js +85 -0
  6. package/WAProto/index.d.ts +14017 -0
  7. package/WAProto/index.js +97691 -0
  8. package/engine-requirements.js +10 -0
  9. package/lib/Defaults/index.d.ts +78 -0
  10. package/lib/Defaults/index.d.ts.map +1 -0
  11. package/lib/Defaults/index.js +145 -0
  12. package/lib/Defaults/index.js.map +1 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  14. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  15. package/lib/Signal/Group/ciphertext-message.js +12 -0
  16. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  18. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  19. package/lib/Signal/Group/group-session-builder.js +30 -0
  20. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  21. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  22. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  23. package/lib/Signal/Group/group_cipher.js +83 -0
  24. package/lib/Signal/Group/group_cipher.js.map +1 -0
  25. package/lib/Signal/Group/index.d.ts +12 -0
  26. package/lib/Signal/Group/index.d.ts.map +1 -0
  27. package/lib/Signal/Group/index.js +12 -0
  28. package/lib/Signal/Group/index.js.map +1 -0
  29. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  30. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  31. package/lib/Signal/Group/keyhelper.js +18 -0
  32. package/lib/Signal/Group/keyhelper.js.map +1 -0
  33. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  34. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  35. package/lib/Signal/Group/sender-chain-key.js +26 -0
  36. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  38. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  39. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  40. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  41. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  42. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  43. package/lib/Signal/Group/sender-key-message.js +66 -0
  44. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  45. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  46. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  47. package/lib/Signal/Group/sender-key-name.js +48 -0
  48. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  49. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  50. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  51. package/lib/Signal/Group/sender-key-record.js +41 -0
  52. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  53. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  54. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  55. package/lib/Signal/Group/sender-key-state.js +84 -0
  56. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  57. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  58. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  59. package/lib/Signal/Group/sender-message-key.js +31 -0
  60. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  61. package/lib/Signal/libsignal.d.ts +5 -0
  62. package/lib/Signal/libsignal.d.ts.map +1 -0
  63. package/lib/Signal/libsignal.js +431 -0
  64. package/lib/Signal/libsignal.js.map +1 -0
  65. package/lib/Signal/lid-mapping.d.ts +20 -0
  66. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  67. package/lib/Signal/lid-mapping.js +281 -0
  68. package/lib/Signal/lid-mapping.js.map +1 -0
  69. package/lib/Socket/Client/index.d.ts +3 -0
  70. package/lib/Socket/Client/index.d.ts.map +1 -0
  71. package/lib/Socket/Client/index.js +3 -0
  72. package/lib/Socket/Client/index.js.map +1 -0
  73. package/lib/Socket/Client/types.d.ts +16 -0
  74. package/lib/Socket/Client/types.d.ts.map +1 -0
  75. package/lib/Socket/Client/types.js +11 -0
  76. package/lib/Socket/Client/types.js.map +1 -0
  77. package/lib/Socket/Client/websocket.d.ts +13 -0
  78. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  79. package/lib/Socket/Client/websocket.js +54 -0
  80. package/lib/Socket/Client/websocket.js.map +1 -0
  81. package/lib/Socket/business.d.ts +271 -0
  82. package/lib/Socket/business.d.ts.map +1 -0
  83. package/lib/Socket/business.js +379 -0
  84. package/lib/Socket/business.js.map +1 -0
  85. package/lib/Socket/chats.d.ts +128 -0
  86. package/lib/Socket/chats.d.ts.map +1 -0
  87. package/lib/Socket/chats.js +1150 -0
  88. package/lib/Socket/chats.js.map +1 -0
  89. package/lib/Socket/communities.d.ts +316 -0
  90. package/lib/Socket/communities.d.ts.map +1 -0
  91. package/lib/Socket/communities.js +415 -0
  92. package/lib/Socket/communities.js.map +1 -0
  93. package/lib/Socket/groups.d.ts +160 -0
  94. package/lib/Socket/groups.d.ts.map +1 -0
  95. package/lib/Socket/groups.js +498 -0
  96. package/lib/Socket/groups.js.map +1 -0
  97. package/lib/Socket/index.d.ts +314 -0
  98. package/lib/Socket/index.d.ts.map +1 -0
  99. package/lib/Socket/index.js +12 -0
  100. package/lib/Socket/index.js.map +1 -0
  101. package/lib/Socket/messages-recv.d.ts +257 -0
  102. package/lib/Socket/messages-recv.d.ts.map +1 -0
  103. package/lib/Socket/messages-recv.js +1697 -0
  104. package/lib/Socket/messages-recv.js.map +1 -0
  105. package/lib/Socket/messages-send.d.ts +253 -0
  106. package/lib/Socket/messages-send.d.ts.map +1 -0
  107. package/lib/Socket/messages-send.js +1309 -0
  108. package/lib/Socket/messages-send.js.map +1 -0
  109. package/lib/Socket/mex.d.ts +4 -0
  110. package/lib/Socket/mex.d.ts.map +1 -0
  111. package/lib/Socket/mex.js +62 -0
  112. package/lib/Socket/mex.js.map +1 -0
  113. package/lib/Socket/newsletter.d.ts +192 -0
  114. package/lib/Socket/newsletter.d.ts.map +1 -0
  115. package/lib/Socket/newsletter.js +419 -0
  116. package/lib/Socket/newsletter.js.map +1 -0
  117. package/lib/Socket/socket.d.ts +59 -0
  118. package/lib/Socket/socket.d.ts.map +1 -0
  119. package/lib/Socket/socket.js +983 -0
  120. package/lib/Socket/socket.js.map +1 -0
  121. package/lib/Store/index.d.ts +5 -0
  122. package/lib/Store/index.d.ts.map +1 -0
  123. package/lib/Store/index.js +5 -0
  124. package/lib/Store/index.js.map +1 -0
  125. package/lib/Store/make-in-memory-store.d.ts +115 -0
  126. package/lib/Store/make-in-memory-store.d.ts.map +1 -0
  127. package/lib/Store/make-in-memory-store.js +428 -0
  128. package/lib/Store/make-in-memory-store.js.map +1 -0
  129. package/lib/Store/make-ordered-dictionary.d.ts +14 -0
  130. package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
  131. package/lib/Store/make-ordered-dictionary.js +87 -0
  132. package/lib/Store/make-ordered-dictionary.js.map +1 -0
  133. package/lib/Store/make-sqlite-store.d.ts +41 -0
  134. package/lib/Store/make-sqlite-store.d.ts.map +1 -0
  135. package/lib/Store/make-sqlite-store.js +254 -0
  136. package/lib/Store/make-sqlite-store.js.map +1 -0
  137. package/lib/Store/object-repository.d.ts +13 -0
  138. package/lib/Store/object-repository.d.ts.map +1 -0
  139. package/lib/Store/object-repository.js +24 -0
  140. package/lib/Store/object-repository.js.map +1 -0
  141. package/lib/Types/Auth.d.ts +117 -0
  142. package/lib/Types/Auth.d.ts.map +1 -0
  143. package/lib/Types/Auth.js +2 -0
  144. package/lib/Types/Auth.js.map +1 -0
  145. package/lib/Types/Bussines.d.ts +25 -0
  146. package/lib/Types/Bussines.d.ts.map +1 -0
  147. package/lib/Types/Bussines.js +2 -0
  148. package/lib/Types/Bussines.js.map +1 -0
  149. package/lib/Types/Call.d.ts +15 -0
  150. package/lib/Types/Call.d.ts.map +1 -0
  151. package/lib/Types/Call.js +2 -0
  152. package/lib/Types/Call.js.map +1 -0
  153. package/lib/Types/Chat.d.ts +124 -0
  154. package/lib/Types/Chat.d.ts.map +1 -0
  155. package/lib/Types/Chat.js +8 -0
  156. package/lib/Types/Chat.js.map +1 -0
  157. package/lib/Types/Contact.d.ts +26 -0
  158. package/lib/Types/Contact.d.ts.map +1 -0
  159. package/lib/Types/Contact.js +2 -0
  160. package/lib/Types/Contact.js.map +1 -0
  161. package/lib/Types/Events.d.ts +256 -0
  162. package/lib/Types/Events.d.ts.map +1 -0
  163. package/lib/Types/Events.js +2 -0
  164. package/lib/Types/Events.js.map +1 -0
  165. package/lib/Types/GroupMetadata.d.ts +71 -0
  166. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  167. package/lib/Types/GroupMetadata.js +2 -0
  168. package/lib/Types/GroupMetadata.js.map +1 -0
  169. package/lib/Types/Label.d.ts +47 -0
  170. package/lib/Types/Label.d.ts.map +1 -0
  171. package/lib/Types/Label.js +25 -0
  172. package/lib/Types/Label.js.map +1 -0
  173. package/lib/Types/LabelAssociation.d.ts +30 -0
  174. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  175. package/lib/Types/LabelAssociation.js +7 -0
  176. package/lib/Types/LabelAssociation.js.map +1 -0
  177. package/lib/Types/Message.d.ts +302 -0
  178. package/lib/Types/Message.d.ts.map +1 -0
  179. package/lib/Types/Message.js +10 -0
  180. package/lib/Types/Message.js.map +1 -0
  181. package/lib/Types/Mex.d.ts +154 -0
  182. package/lib/Types/Mex.d.ts.map +1 -0
  183. package/lib/Types/Mex.js +39 -0
  184. package/lib/Types/Mex.js.map +1 -0
  185. package/lib/Types/Product.d.ts +79 -0
  186. package/lib/Types/Product.d.ts.map +1 -0
  187. package/lib/Types/Product.js +2 -0
  188. package/lib/Types/Product.js.map +1 -0
  189. package/lib/Types/Signal.d.ts +87 -0
  190. package/lib/Types/Signal.d.ts.map +1 -0
  191. package/lib/Types/Signal.js +2 -0
  192. package/lib/Types/Signal.js.map +1 -0
  193. package/lib/Types/Socket.d.ts +141 -0
  194. package/lib/Types/Socket.d.ts.map +1 -0
  195. package/lib/Types/Socket.js +3 -0
  196. package/lib/Types/Socket.js.map +1 -0
  197. package/lib/Types/State.d.ts +100 -0
  198. package/lib/Types/State.d.ts.map +1 -0
  199. package/lib/Types/State.js +56 -0
  200. package/lib/Types/State.js.map +1 -0
  201. package/lib/Types/USync.d.ts +26 -0
  202. package/lib/Types/USync.d.ts.map +1 -0
  203. package/lib/Types/USync.js +2 -0
  204. package/lib/Types/USync.js.map +1 -0
  205. package/lib/Types/index.d.ts +66 -0
  206. package/lib/Types/index.d.ts.map +1 -0
  207. package/lib/Types/index.js +26 -0
  208. package/lib/Types/index.js.map +1 -0
  209. package/lib/Utils/auth-utils.d.ts +24 -0
  210. package/lib/Utils/auth-utils.d.ts.map +1 -0
  211. package/lib/Utils/auth-utils.js +302 -0
  212. package/lib/Utils/auth-utils.js.map +1 -0
  213. package/lib/Utils/browser-utils.d.ts +4 -0
  214. package/lib/Utils/browser-utils.d.ts.map +1 -0
  215. package/lib/Utils/browser-utils.js +29 -0
  216. package/lib/Utils/browser-utils.js.map +1 -0
  217. package/lib/Utils/business.d.ts +17 -0
  218. package/lib/Utils/business.d.ts.map +1 -0
  219. package/lib/Utils/business.js +226 -0
  220. package/lib/Utils/business.js.map +1 -0
  221. package/lib/Utils/chat-utils.d.ts +100 -0
  222. package/lib/Utils/chat-utils.d.ts.map +1 -0
  223. package/lib/Utils/chat-utils.js +872 -0
  224. package/lib/Utils/chat-utils.js.map +1 -0
  225. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  226. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  227. package/lib/Utils/companion-reg-client-utils.js +35 -0
  228. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  229. package/lib/Utils/crypto.d.ts +38 -0
  230. package/lib/Utils/crypto.d.ts.map +1 -0
  231. package/lib/Utils/crypto.js +118 -0
  232. package/lib/Utils/crypto.js.map +1 -0
  233. package/lib/Utils/decode-wa-message.d.ts +66 -0
  234. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  235. package/lib/Utils/decode-wa-message.js +321 -0
  236. package/lib/Utils/decode-wa-message.js.map +1 -0
  237. package/lib/Utils/event-buffer.d.ts +14 -0
  238. package/lib/Utils/event-buffer.d.ts.map +1 -0
  239. package/lib/Utils/event-buffer.js +597 -0
  240. package/lib/Utils/event-buffer.js.map +1 -0
  241. package/lib/Utils/generics.d.ts +92 -0
  242. package/lib/Utils/generics.d.ts.map +1 -0
  243. package/lib/Utils/generics.js +393 -0
  244. package/lib/Utils/generics.js.map +1 -0
  245. package/lib/Utils/history.d.ts +24 -0
  246. package/lib/Utils/history.d.ts.map +1 -0
  247. package/lib/Utils/history.js +134 -0
  248. package/lib/Utils/history.js.map +1 -0
  249. package/lib/Utils/identity-change-handler.d.ts +38 -0
  250. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  251. package/lib/Utils/identity-change-handler.js +50 -0
  252. package/lib/Utils/identity-change-handler.js.map +1 -0
  253. package/lib/Utils/index.d.ts +33 -0
  254. package/lib/Utils/index.d.ts.map +1 -0
  255. package/lib/Utils/index.js +33 -0
  256. package/lib/Utils/index.js.map +1 -0
  257. package/lib/Utils/link-preview.d.ts +21 -0
  258. package/lib/Utils/link-preview.d.ts.map +1 -0
  259. package/lib/Utils/link-preview.js +85 -0
  260. package/lib/Utils/link-preview.js.map +1 -0
  261. package/lib/Utils/logger-sinks.d.ts +9 -0
  262. package/lib/Utils/logger-sinks.d.ts.map +1 -0
  263. package/lib/Utils/logger-sinks.js +30 -0
  264. package/lib/Utils/logger-sinks.js.map +1 -0
  265. package/lib/Utils/logger.d.ts +13 -0
  266. package/lib/Utils/logger.d.ts.map +1 -0
  267. package/lib/Utils/logger.js +3 -0
  268. package/lib/Utils/logger.js.map +1 -0
  269. package/lib/Utils/lt-hash.d.ts +8 -0
  270. package/lib/Utils/lt-hash.d.ts.map +1 -0
  271. package/lib/Utils/lt-hash.js +8 -0
  272. package/lib/Utils/lt-hash.js.map +1 -0
  273. package/lib/Utils/make-mutex.d.ts +9 -0
  274. package/lib/Utils/make-mutex.d.ts.map +1 -0
  275. package/lib/Utils/make-mutex.js +33 -0
  276. package/lib/Utils/make-mutex.js.map +1 -0
  277. package/lib/Utils/media-cache.d.ts +17 -0
  278. package/lib/Utils/media-cache.d.ts.map +1 -0
  279. package/lib/Utils/media-cache.js +72 -0
  280. package/lib/Utils/media-cache.js.map +1 -0
  281. package/lib/Utils/message-composer.d.ts +93 -0
  282. package/lib/Utils/message-composer.d.ts.map +1 -0
  283. package/lib/Utils/message-composer.js +311 -0
  284. package/lib/Utils/message-composer.js.map +1 -0
  285. package/lib/Utils/message-retry-manager.d.ts +75 -0
  286. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  287. package/lib/Utils/message-retry-manager.js +239 -0
  288. package/lib/Utils/message-retry-manager.js.map +1 -0
  289. package/lib/Utils/messages-media.d.ts +162 -0
  290. package/lib/Utils/messages-media.d.ts.map +1 -0
  291. package/lib/Utils/messages-media.js +977 -0
  292. package/lib/Utils/messages-media.js.map +1 -0
  293. package/lib/Utils/messages-newsletter.d.ts +40 -0
  294. package/lib/Utils/messages-newsletter.d.ts.map +1 -0
  295. package/lib/Utils/messages-newsletter.js +61 -0
  296. package/lib/Utils/messages-newsletter.js.map +1 -0
  297. package/lib/Utils/messages.d.ts +92 -0
  298. package/lib/Utils/messages.d.ts.map +1 -0
  299. package/lib/Utils/messages.js +1050 -0
  300. package/lib/Utils/messages.js.map +1 -0
  301. package/lib/Utils/middleware.d.ts +29 -0
  302. package/lib/Utils/middleware.d.ts.map +1 -0
  303. package/lib/Utils/middleware.js +72 -0
  304. package/lib/Utils/middleware.js.map +1 -0
  305. package/lib/Utils/noise-handler.d.ts +20 -0
  306. package/lib/Utils/noise-handler.d.ts.map +1 -0
  307. package/lib/Utils/noise-handler.js +201 -0
  308. package/lib/Utils/noise-handler.js.map +1 -0
  309. package/lib/Utils/offline-node-processor.d.ts +12 -0
  310. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  311. package/lib/Utils/offline-node-processor.js +47 -0
  312. package/lib/Utils/offline-node-processor.js.map +1 -0
  313. package/lib/Utils/pre-key-manager.d.ts +13 -0
  314. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  315. package/lib/Utils/pre-key-manager.js +99 -0
  316. package/lib/Utils/pre-key-manager.js.map +1 -0
  317. package/lib/Utils/process-message.d.ts +60 -0
  318. package/lib/Utils/process-message.d.ts.map +1 -0
  319. package/lib/Utils/process-message.js +633 -0
  320. package/lib/Utils/process-message.js.map +1 -0
  321. package/lib/Utils/reconnect-manager.d.ts +21 -0
  322. package/lib/Utils/reconnect-manager.d.ts.map +1 -0
  323. package/lib/Utils/reconnect-manager.js +71 -0
  324. package/lib/Utils/reconnect-manager.js.map +1 -0
  325. package/lib/Utils/reporting-utils.d.ts +11 -0
  326. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  327. package/lib/Utils/reporting-utils.js +258 -0
  328. package/lib/Utils/reporting-utils.js.map +1 -0
  329. package/lib/Utils/session-manager.d.ts +22 -0
  330. package/lib/Utils/session-manager.d.ts.map +1 -0
  331. package/lib/Utils/session-manager.js +70 -0
  332. package/lib/Utils/session-manager.js.map +1 -0
  333. package/lib/Utils/shortcake-crypto.d.ts +27 -0
  334. package/lib/Utils/shortcake-crypto.d.ts.map +1 -0
  335. package/lib/Utils/shortcake-crypto.js +65 -0
  336. package/lib/Utils/shortcake-crypto.js.map +1 -0
  337. package/lib/Utils/shortcake.d.ts +31 -0
  338. package/lib/Utils/shortcake.d.ts.map +1 -0
  339. package/lib/Utils/shortcake.js +156 -0
  340. package/lib/Utils/shortcake.js.map +1 -0
  341. package/lib/Utils/signal.d.ts +47 -0
  342. package/lib/Utils/signal.d.ts.map +1 -0
  343. package/lib/Utils/signal.js +201 -0
  344. package/lib/Utils/signal.js.map +1 -0
  345. package/lib/Utils/stanza-ack.d.ts +11 -0
  346. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  347. package/lib/Utils/stanza-ack.js +38 -0
  348. package/lib/Utils/stanza-ack.js.map +1 -0
  349. package/lib/Utils/sync-action-utils.d.ts +19 -0
  350. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  351. package/lib/Utils/sync-action-utils.js +49 -0
  352. package/lib/Utils/sync-action-utils.js.map +1 -0
  353. package/lib/Utils/tc-token-utils.d.ts +37 -0
  354. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  355. package/lib/Utils/tc-token-utils.js +164 -0
  356. package/lib/Utils/tc-token-utils.js.map +1 -0
  357. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  358. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  359. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  360. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  361. package/lib/Utils/use-single-file-auth-state.d.ts +6 -0
  362. package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
  363. package/lib/Utils/use-single-file-auth-state.js +111 -0
  364. package/lib/Utils/use-single-file-auth-state.js.map +1 -0
  365. package/lib/Utils/use-sqlite-auth-state.d.ts +14 -0
  366. package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
  367. package/lib/Utils/use-sqlite-auth-state.js +107 -0
  368. package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
  369. package/lib/Utils/validate-connection.d.ts +12 -0
  370. package/lib/Utils/validate-connection.d.ts.map +1 -0
  371. package/lib/Utils/validate-connection.js +210 -0
  372. package/lib/Utils/validate-connection.js.map +1 -0
  373. package/lib/WABinary/constants.d.ts +28 -0
  374. package/lib/WABinary/constants.d.ts.map +1 -0
  375. package/lib/WABinary/constants.js +1301 -0
  376. package/lib/WABinary/constants.js.map +1 -0
  377. package/lib/WABinary/decode.d.ts +7 -0
  378. package/lib/WABinary/decode.d.ts.map +1 -0
  379. package/lib/WABinary/decode.js +262 -0
  380. package/lib/WABinary/decode.js.map +1 -0
  381. package/lib/WABinary/encode.d.ts +3 -0
  382. package/lib/WABinary/encode.d.ts.map +1 -0
  383. package/lib/WABinary/encode.js +220 -0
  384. package/lib/WABinary/encode.js.map +1 -0
  385. package/lib/WABinary/generic-utils.d.ts +15 -0
  386. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  387. package/lib/WABinary/generic-utils.js +113 -0
  388. package/lib/WABinary/generic-utils.js.map +1 -0
  389. package/lib/WABinary/index.d.ts +6 -0
  390. package/lib/WABinary/index.d.ts.map +1 -0
  391. package/lib/WABinary/index.js +6 -0
  392. package/lib/WABinary/index.js.map +1 -0
  393. package/lib/WABinary/jid-utils.d.ts +48 -0
  394. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  395. package/lib/WABinary/jid-utils.js +96 -0
  396. package/lib/WABinary/jid-utils.js.map +1 -0
  397. package/lib/WABinary/types.d.ts +19 -0
  398. package/lib/WABinary/types.d.ts.map +1 -0
  399. package/lib/WABinary/types.js +2 -0
  400. package/lib/WABinary/types.js.map +1 -0
  401. package/lib/WAM/BinaryInfo.d.ts +9 -0
  402. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  403. package/lib/WAM/BinaryInfo.js +10 -0
  404. package/lib/WAM/BinaryInfo.js.map +1 -0
  405. package/lib/WAM/constants.d.ts +40 -0
  406. package/lib/WAM/constants.d.ts.map +1 -0
  407. package/lib/WAM/constants.js +22853 -0
  408. package/lib/WAM/constants.js.map +1 -0
  409. package/lib/WAM/encode.d.ts +3 -0
  410. package/lib/WAM/encode.d.ts.map +1 -0
  411. package/lib/WAM/encode.js +150 -0
  412. package/lib/WAM/encode.js.map +1 -0
  413. package/lib/WAM/index.d.ts +4 -0
  414. package/lib/WAM/index.d.ts.map +1 -0
  415. package/lib/WAM/index.js +4 -0
  416. package/lib/WAM/index.js.map +1 -0
  417. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  418. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  419. package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
  420. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  421. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  422. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  423. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  424. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  425. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  426. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  427. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  428. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  429. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  430. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  431. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  432. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  433. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  434. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  435. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  436. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  437. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  438. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  439. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  440. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  441. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  442. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  443. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  444. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  445. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  446. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  447. package/lib/WAUSync/Protocols/index.js +6 -0
  448. package/lib/WAUSync/Protocols/index.js.map +1 -0
  449. package/lib/WAUSync/USyncQuery.d.ts +30 -0
  450. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  451. package/lib/WAUSync/USyncQuery.js +98 -0
  452. package/lib/WAUSync/USyncQuery.js.map +1 -0
  453. package/lib/WAUSync/USyncUser.d.ts +17 -0
  454. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  455. package/lib/WAUSync/USyncUser.js +31 -0
  456. package/lib/WAUSync/USyncUser.js.map +1 -0
  457. package/lib/WAUSync/index.d.ts +4 -0
  458. package/lib/WAUSync/index.d.ts.map +1 -0
  459. package/lib/WAUSync/index.js +4 -0
  460. package/lib/WAUSync/index.js.map +1 -0
  461. package/lib/index.d.ts +13 -0
  462. package/lib/index.d.ts.map +1 -0
  463. package/lib/index.js +12 -0
  464. package/lib/index.js.map +1 -0
  465. package/package.json +83 -0
@@ -0,0 +1,633 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto/index.js';
3
+ import { WAMessageStubType } from '../Types/index.js';
4
+ import { getContentType, normalizeMessageContent } from '../Utils/messages.js';
5
+ import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidStatusBroadcast, isLidUser, jidDecode, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
6
+ import { aesDecryptGCM, hmacSign } from './crypto.js';
7
+ import { getKeyAuthor, toNumber } from './generics.js';
8
+ import { downloadAndProcessHistorySyncNotification } from './history.js';
9
+ import { buildMergedTcTokenIndexWrite, resolveTcTokenJid } from './tc-token-utils.js';
10
+ const REAL_MSG_STUB_TYPES = new Set([
11
+ WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
12
+ WAMessageStubType.CALL_MISSED_GROUP_VOICE,
13
+ WAMessageStubType.CALL_MISSED_VIDEO,
14
+ WAMessageStubType.CALL_MISSED_VOICE
15
+ ]);
16
+ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([WAMessageStubType.GROUP_PARTICIPANT_ADD]);
17
+ async function storeTcTokensFromHistorySync(chats, signalRepository, keyStore, logger) {
18
+ const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
19
+ const candidates = [];
20
+ for (const chat of chats) {
21
+ const ts = chat.tcTokenTimestamp ? toNumber(chat.tcTokenTimestamp) : 0;
22
+ if (chat.tcToken?.length && ts > 0) {
23
+ const jid = jidNormalizedUser(chat.id);
24
+ const storageJid = await resolveTcTokenJid(jid, getLIDForPN);
25
+ candidates.push({
26
+ storageJid,
27
+ token: Buffer.from(chat.tcToken),
28
+ ts,
29
+ senderTs: chat.tcTokenSenderTimestamp ? toNumber(chat.tcTokenSenderTimestamp) : undefined
30
+ });
31
+ }
32
+ }
33
+ if (!candidates.length) {
34
+ return;
35
+ }
36
+ const jids = candidates.map(c => c.storageJid);
37
+ const existing = await keyStore.get('tctoken', jids);
38
+ const entries = {};
39
+ for (const c of candidates) {
40
+ const existingEntry = existing[c.storageJid];
41
+ const existingTs = existingEntry?.timestamp ? Number(existingEntry.timestamp) : 0;
42
+ if (existingTs > 0 && existingTs >= c.ts) {
43
+ continue;
44
+ }
45
+ entries[c.storageJid] = {
46
+ ...existingEntry,
47
+ token: c.token,
48
+ timestamp: String(c.ts),
49
+ ...(c.senderTs !== undefined ? { senderTimestamp: c.senderTs } : {})
50
+ };
51
+ }
52
+ if (Object.keys(entries).length) {
53
+ logger?.debug({ count: Object.keys(entries).length }, 'storing tctokens from history sync');
54
+ try {
55
+ // Include updated __index so cross-session pruning picks these JIDs up.
56
+ const indexWrite = await buildMergedTcTokenIndexWrite(keyStore, Object.keys(entries));
57
+ await keyStore.set({ tctoken: { ...entries, ...indexWrite } });
58
+ }
59
+ catch (err) {
60
+ logger?.warn({ err }, 'failed to store tctokens from history sync');
61
+ }
62
+ }
63
+ }
64
+ /** Cleans a received message to further processing */
65
+ export const cleanMessage = (message, meId, meLid) => {
66
+ // ensure remoteJid and participant doesn't have device or agent in it
67
+ if (isHostedPnUser(message.key.remoteJid) || isHostedLidUser(message.key.remoteJid)) {
68
+ message.key.remoteJid = jidEncode(jidDecode(message.key?.remoteJid)?.user, isHostedPnUser(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
69
+ }
70
+ else {
71
+ message.key.remoteJid = jidNormalizedUser(message.key.remoteJid);
72
+ }
73
+ if (isHostedPnUser(message.key.participant) || isHostedLidUser(message.key.participant)) {
74
+ message.key.participant = jidEncode(jidDecode(message.key.participant)?.user, isHostedPnUser(message.key.participant) ? 's.whatsapp.net' : 'lid');
75
+ }
76
+ else {
77
+ message.key.participant = jidNormalizedUser(message.key.participant);
78
+ }
79
+ const content = normalizeMessageContent(message.message);
80
+ // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
81
+ if (content?.reactionMessage) {
82
+ normaliseKey(content.reactionMessage.key);
83
+ }
84
+ if (content?.pollUpdateMessage) {
85
+ normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
86
+ }
87
+ function normaliseKey(msgKey) {
88
+ // if the reaction is from another user
89
+ // we've to correctly map the key to this user's perspective
90
+ if (!message.key.fromMe) {
91
+ // if the sender believed the message being reacted to is not from them
92
+ // we've to correct the key to be from them, or some other participant
93
+ msgKey.fromMe = !msgKey.fromMe
94
+ ? areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId) ||
95
+ areJidsSameUser(msgKey.participant || msgKey.remoteJid, meLid)
96
+ : // if the message being reacted to, was from them
97
+ // fromMe automatically becomes false
98
+ false;
99
+ // set the remoteJid to being the same as the chat the message came from
100
+ // TODO: investigate inconsistencies
101
+ msgKey.remoteJid = message.key.remoteJid;
102
+ // set participant of the message
103
+ msgKey.participant = msgKey.participant || message.key.participant;
104
+ }
105
+ }
106
+ };
107
+ export const isRealMessage = (message) => {
108
+ if (REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
109
+ REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) {
110
+ return true;
111
+ }
112
+ const normalizedContent = normalizeMessageContent(message.message);
113
+ if (!normalizedContent) {
114
+ return false;
115
+ }
116
+ const hasSomeContent = !!getContentType(normalizedContent);
117
+ return (hasSomeContent &&
118
+ !normalizedContent.protocolMessage &&
119
+ !normalizedContent.reactionMessage &&
120
+ !normalizedContent.pollUpdateMessage);
121
+ };
122
+ export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
123
+ /**
124
+ * Get the ID of the chat from the given key.
125
+ * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
126
+ */
127
+ export const getChatId = ({ remoteJid, participant, fromMe }) => {
128
+ if (!remoteJid) {
129
+ throw new Boom('Cannot derive chat id: message key is missing remoteJid', {
130
+ data: { remoteJid, participant, fromMe }
131
+ });
132
+ }
133
+ if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
134
+ if (!participant) {
135
+ throw new Boom('Cannot derive chat id: broadcast message key is missing participant', {
136
+ data: { remoteJid, fromMe }
137
+ });
138
+ }
139
+ return participant;
140
+ }
141
+ return remoteJid;
142
+ };
143
+ /**
144
+ * Decrypt a poll vote
145
+ * @param vote encrypted vote
146
+ * @param ctx additional info about the poll required for decryption
147
+ * @returns list of SHA256 options
148
+ */
149
+ export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
150
+ const sign = Buffer.concat([
151
+ toBinary(pollMsgId),
152
+ toBinary(pollCreatorJid),
153
+ toBinary(voterJid),
154
+ toBinary('Poll Vote'),
155
+ new Uint8Array([1])
156
+ ]);
157
+ const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256');
158
+ const decKey = hmacSign(sign, key0, 'sha256');
159
+ const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
160
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
161
+ return proto.Message.PollVoteMessage.decode(decrypted);
162
+ function toBinary(txt) {
163
+ return Buffer.from(txt);
164
+ }
165
+ }
166
+ /**
167
+ * Decrypt an event response
168
+ * @param response encrypted event response
169
+ * @param ctx additional info about the event required for decryption
170
+ * @returns event response message
171
+ */
172
+ export function decryptEventResponse({ encPayload, encIv }, { eventCreatorJid, eventMsgId, eventEncKey, responderJid }) {
173
+ const sign = Buffer.concat([
174
+ toBinary(eventMsgId),
175
+ toBinary(eventCreatorJid),
176
+ toBinary(responderJid),
177
+ toBinary('Event Response'),
178
+ new Uint8Array([1])
179
+ ]);
180
+ const key0 = hmacSign(eventEncKey, new Uint8Array(32), 'sha256');
181
+ const decKey = hmacSign(sign, key0, 'sha256');
182
+ const aad = toBinary(`${eventMsgId}\u0000${responderJid}`);
183
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
184
+ return proto.Message.EventResponseMessage.decode(decrypted);
185
+ function toBinary(txt) {
186
+ return Buffer.from(txt);
187
+ }
188
+ }
189
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options, getMessage }) => {
190
+ const meId = creds.me.id;
191
+ const { accountSettings } = creds;
192
+ const chat = { id: jidNormalizedUser(getChatId(message.key)) };
193
+ const isRealMsg = isRealMessage(message);
194
+ if (isRealMsg) {
195
+ chat.messages = [{ message }];
196
+ chat.conversationTimestamp = toNumber(message.messageTimestamp);
197
+ // only increment unread count if not CIPHERTEXT and from another person
198
+ if (shouldIncrementChatUnread(message)) {
199
+ chat.unreadCount = (chat.unreadCount || 0) + 1;
200
+ }
201
+ }
202
+ const content = normalizeMessageContent(message.message);
203
+ // unarchive chat if it's a real message, or someone reacted to our message
204
+ // and we've the unarchive chats setting on
205
+ if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
206
+ chat.archived = false;
207
+ chat.readOnly = false;
208
+ }
209
+ const protocolMsg = content?.protocolMessage;
210
+ if (protocolMsg) {
211
+ // Mirror whatsmeow's `handleProtocolMessage` guard, but applied only to
212
+ // the protocol message types that originate from our own device — an
213
+ // attacker could otherwise spoof any of these to manipulate local state.
214
+ //
215
+ // Self-only types (drop if `!fromMe`):
216
+ // - HISTORY_SYNC_NOTIFICATION (our phone driving history sync)
217
+ // - APP_STATE_SYNC_KEY_SHARE (key share between our devices)
218
+ // - LID_MIGRATION_MAPPING_SYNC (server-initiated via our phone)
219
+ // - PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE (response from our phone to our PDO request)
220
+ //
221
+ // Cross-user types (must NOT be dropped — legitimately arrive from others):
222
+ // - REVOKE
223
+ // - MESSAGE_EDIT
224
+ // - EPHEMERAL_SETTING
225
+ // - GROUP_MEMBER_LABEL_CHANGE
226
+ //
227
+ // See https://github.com/tulir/whatsmeow/blob/8d3700152a/message.go#L842-L845
228
+ // for the reference architecture — whatsmeow's `handleProtocolMessage`
229
+ // only contains self-only types because edits are unwrapped from
230
+ // `EditedMessage` BEFORE this dispatch and revokes aren't routed here.
231
+ const SELF_ONLY_TYPES = new Set([
232
+ proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION,
233
+ proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE,
234
+ proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC,
235
+ proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE
236
+ ]);
237
+ if (protocolMsg.type !== null &&
238
+ protocolMsg.type !== undefined &&
239
+ SELF_ONLY_TYPES.has(protocolMsg.type) &&
240
+ !message.key.fromMe) {
241
+ logger?.warn({ msgId: message.key.id, type: protocolMsg.type, from: message.key.participant || message.key.remoteJid }, 'dropping spoofed self-only protocolMessage from non-self origin');
242
+ return;
243
+ }
244
+ switch (protocolMsg.type) {
245
+ case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
246
+ const histNotification = protocolMsg.historySyncNotification;
247
+ const process = shouldProcessHistoryMsg;
248
+ const isLatest = !creds.processedHistoryMessages?.length;
249
+ logger?.info({
250
+ histNotification,
251
+ process,
252
+ id: message.key.id,
253
+ isLatest
254
+ }, 'got history notification');
255
+ if (process) {
256
+ // TODO: investigate
257
+ if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
258
+ ev.emit('creds.update', {
259
+ processedHistoryMessages: [
260
+ ...(creds.processedHistoryMessages || []),
261
+ { key: message.key, messageTimestamp: message.messageTimestamp }
262
+ ]
263
+ });
264
+ }
265
+ const data = await downloadAndProcessHistorySyncNotification(histNotification, options, logger);
266
+ if (data.lidPnMappings?.length) {
267
+ logger?.debug({ count: data.lidPnMappings.length }, 'processing LID-PN mappings from history sync');
268
+ await signalRepository.lidMapping
269
+ .storeLIDPNMappings(data.lidPnMappings)
270
+ .catch(err => logger?.warn({ err }, 'failed to store LID-PN mappings from history sync'));
271
+ }
272
+ await storeTcTokensFromHistorySync(data.chats, signalRepository, keyStore, logger);
273
+ ev.emit('messaging-history.set', {
274
+ ...data,
275
+ isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
276
+ chunkOrder: histNotification.chunkOrder,
277
+ peerDataRequestSessionId: histNotification.peerDataRequestSessionId
278
+ });
279
+ }
280
+ break;
281
+ case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
282
+ const keys = protocolMsg.appStateSyncKeyShare.keys;
283
+ if (keys?.length) {
284
+ let newAppStateSyncKeyId = '';
285
+ await keyStore.transaction(async () => {
286
+ const newKeys = [];
287
+ for (const { keyData, keyId } of keys) {
288
+ const strKeyId = Buffer.from(keyId.keyId).toString('base64');
289
+ newKeys.push(strKeyId);
290
+ await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
291
+ newAppStateSyncKeyId = strKeyId;
292
+ }
293
+ logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
294
+ }, meId);
295
+ ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
296
+ }
297
+ else {
298
+ logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
299
+ }
300
+ break;
301
+ case proto.Message.ProtocolMessage.Type.REVOKE:
302
+ ev.emit('messages.update', [
303
+ {
304
+ key: {
305
+ ...message.key,
306
+ id: protocolMsg.key.id
307
+ },
308
+ update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
309
+ }
310
+ ]);
311
+ break;
312
+ case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
313
+ Object.assign(chat, {
314
+ ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
315
+ ephemeralExpiration: protocolMsg.ephemeralExpiration || null
316
+ });
317
+ break;
318
+ case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
319
+ const response = protocolMsg.peerDataOperationRequestResponseMessage;
320
+ if (response) {
321
+ // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
322
+ const peerDataOperationResult = response.peerDataOperationResult || [];
323
+ for (const result of peerDataOperationResult) {
324
+ const retryResponse = result?.placeholderMessageResendResponse;
325
+ //eslint-disable-next-line max-depth
326
+ if (!retryResponse?.webMessageInfoBytes) {
327
+ continue;
328
+ }
329
+ //eslint-disable-next-line max-depth
330
+ try {
331
+ const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
332
+ const msgId = webMessageInfo.key?.id;
333
+ // Retrieve cached original message data (preserves LID details,
334
+ // timestamps, etc. that the phone may omit in its PDO response)
335
+ const cachedData = msgId ? await placeholderResendCache?.get(msgId) : undefined;
336
+ //eslint-disable-next-line max-depth
337
+ if (msgId) {
338
+ await placeholderResendCache?.del(msgId);
339
+ }
340
+ let finalMsg;
341
+ //eslint-disable-next-line max-depth
342
+ if (cachedData && typeof cachedData === 'object') {
343
+ // Apply decoded message content onto cached metadata (preserves LID etc.)
344
+ cachedData.message = webMessageInfo.message;
345
+ //eslint-disable-next-line max-depth
346
+ if (webMessageInfo.messageTimestamp) {
347
+ cachedData.messageTimestamp = webMessageInfo.messageTimestamp;
348
+ }
349
+ finalMsg = cachedData;
350
+ }
351
+ else {
352
+ finalMsg = webMessageInfo;
353
+ }
354
+ logger?.debug({ msgId, requestId: response.stanzaId }, 'received placeholder resend');
355
+ ev.emit('messages.upsert', {
356
+ messages: [finalMsg],
357
+ type: 'notify',
358
+ requestId: response.stanzaId
359
+ });
360
+ }
361
+ catch (err) {
362
+ logger?.warn({ err, stanzaId: response.stanzaId }, 'failed to decode placeholder resend response');
363
+ }
364
+ }
365
+ }
366
+ break;
367
+ case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
368
+ ev.emit('messages.update', [
369
+ {
370
+ // flip the sender / fromMe properties because they're in the perspective of the sender
371
+ key: { ...message.key, id: protocolMsg.key?.id },
372
+ update: {
373
+ message: {
374
+ editedMessage: {
375
+ message: protocolMsg.editedMessage
376
+ }
377
+ },
378
+ messageTimestamp: protocolMsg.timestampMs
379
+ ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
380
+ : message.messageTimestamp
381
+ }
382
+ }
383
+ ]);
384
+ break;
385
+ case proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE:
386
+ const labelAssociationMsg = protocolMsg.memberLabel;
387
+ if (labelAssociationMsg?.label) {
388
+ ev.emit('group.member-tag.update', {
389
+ groupId: chat.id,
390
+ label: labelAssociationMsg.label,
391
+ participant: message.key.participant,
392
+ participantAlt: message.key.participantAlt,
393
+ messageTimestamp: Number(message.messageTimestamp)
394
+ });
395
+ }
396
+ break;
397
+ case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
398
+ const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
399
+ const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
400
+ logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
401
+ const pairs = [];
402
+ for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
403
+ const lid = latestLid || assignedLid;
404
+ pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
405
+ }
406
+ await signalRepository.lidMapping.storeLIDPNMappings(pairs);
407
+ if (pairs.length) {
408
+ for (const { pn, lid } of pairs) {
409
+ await signalRepository.migrateSession(pn, lid);
410
+ }
411
+ }
412
+ }
413
+ }
414
+ else if (content?.reactionMessage) {
415
+ const reaction = {
416
+ ...content.reactionMessage,
417
+ key: message.key
418
+ };
419
+ ev.emit('messages.reaction', [
420
+ {
421
+ reaction,
422
+ key: content.reactionMessage?.key
423
+ }
424
+ ]);
425
+ }
426
+ else if (content?.encEventResponseMessage) {
427
+ const encEventResponse = content.encEventResponseMessage;
428
+ const creationMsgKey = encEventResponse.eventCreationMessageKey;
429
+ // we need to fetch the event creation message to get the event enc key
430
+ const eventMsg = await getMessage(creationMsgKey);
431
+ if (eventMsg) {
432
+ try {
433
+ const meIdNormalised = jidNormalizedUser(meId);
434
+ // all jids need to be PN
435
+ const eventCreatorKey = creationMsgKey.participant || creationMsgKey.remoteJid;
436
+ const eventCreatorPn = isLidUser(eventCreatorKey)
437
+ ? await signalRepository.lidMapping.getPNForLID(eventCreatorKey)
438
+ : eventCreatorKey;
439
+ const eventCreatorJid = getKeyAuthor({ remoteJid: jidNormalizedUser(eventCreatorPn), fromMe: meIdNormalised === eventCreatorPn }, meIdNormalised);
440
+ const responderJid = getKeyAuthor(message.key, meIdNormalised);
441
+ const eventEncKey = eventMsg?.messageContextInfo?.messageSecret;
442
+ if (!eventEncKey) {
443
+ logger?.warn({ creationMsgKey }, 'event response: missing messageSecret for decryption');
444
+ }
445
+ else {
446
+ const responseMsg = decryptEventResponse(encEventResponse, {
447
+ eventEncKey,
448
+ eventCreatorJid,
449
+ eventMsgId: creationMsgKey.id,
450
+ responderJid
451
+ });
452
+ const eventResponse = {
453
+ eventResponseMessageKey: message.key,
454
+ senderTimestampMs: responseMsg.timestampMs,
455
+ response: responseMsg
456
+ };
457
+ ev.emit('messages.update', [
458
+ {
459
+ key: creationMsgKey,
460
+ update: {
461
+ eventResponses: [eventResponse]
462
+ }
463
+ }
464
+ ]);
465
+ }
466
+ }
467
+ catch (err) {
468
+ logger?.warn({ err, creationMsgKey }, 'failed to decrypt event response');
469
+ }
470
+ }
471
+ else {
472
+ logger?.warn({ creationMsgKey }, 'event creation message not found, cannot decrypt response');
473
+ }
474
+ }
475
+ else if (message.messageStubType) {
476
+ const jid = message.key?.remoteJid;
477
+ //let actor = whatsappID (message.participant)
478
+ let participants;
479
+ const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
480
+ id: jid,
481
+ author: message.key.participant,
482
+ authorPn: message.key.participantAlt,
483
+ authorUsername: message.key.participantUsername,
484
+ participants,
485
+ action
486
+ });
487
+ const emitGroupUpdate = (update) => {
488
+ ev.emit('groups.update', [
489
+ {
490
+ id: jid,
491
+ ...update,
492
+ author: message.key.participant ?? undefined,
493
+ authorPn: message.key.participantAlt,
494
+ authorUsername: message.key.participantUsername
495
+ }
496
+ ]);
497
+ };
498
+ const emitGroupRequestJoin = (participant, action, method) => {
499
+ ev.emit('group.join-request', {
500
+ id: jid,
501
+ author: message.key.participant,
502
+ authorPn: message.key.participantAlt,
503
+ authorUsername: message.key.participantUsername,
504
+ participant: participant.lid,
505
+ participantPn: participant.pn,
506
+ action,
507
+ method: method
508
+ });
509
+ };
510
+ const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber)); // ADD SUPPORT FOR LID
511
+ switch (message.messageStubType) {
512
+ case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
513
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
514
+ emitParticipantsUpdate('modify');
515
+ break;
516
+ case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
517
+ case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
518
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
519
+ emitParticipantsUpdate('remove');
520
+ // mark the chat read only if you left the group
521
+ if (participantsIncludesMe()) {
522
+ chat.readOnly = true;
523
+ }
524
+ break;
525
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD:
526
+ case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
527
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
528
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
529
+ if (participantsIncludesMe()) {
530
+ chat.readOnly = false;
531
+ }
532
+ emitParticipantsUpdate('add');
533
+ break;
534
+ case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
535
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
536
+ emitParticipantsUpdate('demote');
537
+ break;
538
+ case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
539
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
540
+ emitParticipantsUpdate('promote');
541
+ break;
542
+ case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
543
+ const announceValue = message.messageStubParameters?.[0];
544
+ emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
545
+ break;
546
+ case WAMessageStubType.GROUP_CHANGE_RESTRICT:
547
+ const restrictValue = message.messageStubParameters?.[0];
548
+ emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
549
+ break;
550
+ case WAMessageStubType.GROUP_CHANGE_SUBJECT:
551
+ const name = message.messageStubParameters?.[0];
552
+ chat.name = name;
553
+ emitGroupUpdate({ subject: name });
554
+ break;
555
+ case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
556
+ const description = message.messageStubParameters?.[0];
557
+ chat.description = description;
558
+ emitGroupUpdate({ desc: description });
559
+ break;
560
+ case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
561
+ const code = message.messageStubParameters?.[0];
562
+ emitGroupUpdate({ inviteCode: code });
563
+ break;
564
+ case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
565
+ const memberAddValue = message.messageStubParameters?.[0];
566
+ emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
567
+ break;
568
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
569
+ const approvalMode = message.messageStubParameters?.[0];
570
+ emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
571
+ break;
572
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
573
+ const participant = JSON.parse(message.messageStubParameters?.[0]);
574
+ const action = message.messageStubParameters?.[1];
575
+ const method = message.messageStubParameters?.[2];
576
+ emitGroupRequestJoin(participant, action, method);
577
+ break;
578
+ }
579
+ } /* else if(content?.pollUpdateMessage) {
580
+ const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey!
581
+ // we need to fetch the poll creation message to get the poll enc key
582
+ // TODO: make standalone, remove getMessage reference
583
+ // TODO: Remove entirely
584
+ const pollMsg = await getMessage(creationMsgKey)
585
+ if(pollMsg) {
586
+ const meIdNormalised = jidNormalizedUser(meId)
587
+ const pollCreatorJid = getKeyAuthor(creationMsgKey, meIdNormalised)
588
+ const voterJid = getKeyAuthor(message.key, meIdNormalised)
589
+ const pollEncKey = pollMsg.messageContextInfo?.messageSecret!
590
+
591
+ try {
592
+ const voteMsg = decryptPollVote(
593
+ content.pollUpdateMessage.vote!,
594
+ {
595
+ pollEncKey,
596
+ pollCreatorJid,
597
+ pollMsgId: creationMsgKey.id!,
598
+ voterJid,
599
+ }
600
+ )
601
+ ev.emit('messages.update', [
602
+ {
603
+ key: creationMsgKey,
604
+ update: {
605
+ pollUpdates: [
606
+ {
607
+ pollUpdateMessageKey: message.key,
608
+ vote: voteMsg,
609
+ senderTimestampMs: (content.pollUpdateMessage.senderTimestampMs! as Long).toNumber(),
610
+ }
611
+ ]
612
+ }
613
+ }
614
+ ])
615
+ } catch(err) {
616
+ logger?.warn(
617
+ { err, creationMsgKey },
618
+ 'failed to decrypt poll vote'
619
+ )
620
+ }
621
+ } else {
622
+ logger?.warn(
623
+ { creationMsgKey },
624
+ 'poll creation message not found, cannot decrypt update'
625
+ )
626
+ }
627
+ } */
628
+ if (Object.keys(chat).length > 1) {
629
+ ev.emit('chats.update', [chat]);
630
+ }
631
+ };
632
+ export default processMessage;
633
+ //# sourceMappingURL=process-message.js.map