@violetix/baileys 0.0.0-stage → 0.3.18

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 (452) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +2843 -2
  3. package/WAProto/index.d.ts +15932 -0
  4. package/WAProto/index.js +115856 -0
  5. package/engine-requirements.js +13 -0
  6. package/lib/Defaults/index.d.ts +145 -0
  7. package/lib/Defaults/index.d.ts.map +1 -0
  8. package/lib/Defaults/index.js +157 -0
  9. package/lib/Defaults/index.js.map +1 -0
  10. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  12. package/lib/Signal/Group/ciphertext-message.js +12 -0
  13. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  14. package/lib/Signal/Group/group-session-builder.d.ts +8 -0
  15. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  16. package/lib/Signal/Group/group-session-builder.js +30 -0
  17. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  18. package/lib/Signal/Group/group_cipher.d.ts +11 -0
  19. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  20. package/lib/Signal/Group/group_cipher.js +82 -0
  21. package/lib/Signal/Group/group_cipher.js.map +1 -0
  22. package/lib/Signal/Group/index.d.ts +12 -0
  23. package/lib/Signal/Group/index.d.ts.map +1 -0
  24. package/lib/Signal/Group/index.js +12 -0
  25. package/lib/Signal/Group/index.js.map +1 -0
  26. package/lib/Signal/Group/keyhelper.d.ts +7 -0
  27. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  28. package/lib/Signal/Group/keyhelper.js +18 -0
  29. package/lib/Signal/Group/keyhelper.js.map +1 -0
  30. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  31. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  32. package/lib/Signal/Group/sender-chain-key.js +26 -0
  33. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  34. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  35. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  36. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  38. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  39. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  40. package/lib/Signal/Group/sender-key-message.js +66 -0
  41. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  42. package/lib/Signal/Group/sender-key-name.d.ts +12 -0
  43. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  44. package/lib/Signal/Group/sender-key-name.js +48 -0
  45. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  46. package/lib/Signal/Group/sender-key-record.d.ts +13 -0
  47. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  48. package/lib/Signal/Group/sender-key-record.js +41 -0
  49. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  50. package/lib/Signal/Group/sender-key-state.d.ts +17 -0
  51. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  52. package/lib/Signal/Group/sender-key-state.js +84 -0
  53. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  54. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  55. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  56. package/lib/Signal/Group/sender-message-key.js +26 -0
  57. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  58. package/lib/Signal/libsignal.d.ts +55 -0
  59. package/lib/Signal/libsignal.d.ts.map +1 -0
  60. package/lib/Signal/libsignal.js +403 -0
  61. package/lib/Signal/libsignal.js.map +1 -0
  62. package/lib/Signal/lid-mapping.d.ts +21 -0
  63. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  64. package/lib/Signal/lid-mapping.js +277 -0
  65. package/lib/Signal/lid-mapping.js.map +1 -0
  66. package/lib/Socket/Client/index.d.ts +3 -0
  67. package/lib/Socket/Client/index.d.ts.map +1 -0
  68. package/lib/Socket/Client/index.js +3 -0
  69. package/lib/Socket/Client/index.js.map +1 -0
  70. package/lib/Socket/Client/types.d.ts +6 -0
  71. package/lib/Socket/Client/types.d.ts.map +1 -0
  72. package/lib/Socket/Client/types.js +93 -0
  73. package/lib/Socket/Client/types.js.map +1 -0
  74. package/lib/Socket/Client/websocket.d.ts +13 -0
  75. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  76. package/lib/Socket/Client/websocket.js +57 -0
  77. package/lib/Socket/Client/websocket.js.map +1 -0
  78. package/lib/Socket/business.d.ts +428 -0
  79. package/lib/Socket/business.d.ts.map +1 -0
  80. package/lib/Socket/business.js +380 -0
  81. package/lib/Socket/business.js.map +1 -0
  82. package/lib/Socket/chats.d.ts +176 -0
  83. package/lib/Socket/chats.d.ts.map +1 -0
  84. package/lib/Socket/chats.js +1238 -0
  85. package/lib/Socket/chats.js.map +1 -0
  86. package/lib/Socket/communities.d.ts +595 -0
  87. package/lib/Socket/communities.d.ts.map +1 -0
  88. package/lib/Socket/communities.js +432 -0
  89. package/lib/Socket/communities.js.map +1 -0
  90. package/lib/Socket/graphql.js +908 -0
  91. package/lib/Socket/groups.d.ts +318 -0
  92. package/lib/Socket/groups.d.ts.map +1 -0
  93. package/lib/Socket/groups.js +364 -0
  94. package/lib/Socket/groups.js.map +1 -0
  95. package/lib/Socket/index.d.ts +940 -0
  96. package/lib/Socket/index.d.ts.map +1 -0
  97. package/lib/Socket/index.js +19 -0
  98. package/lib/Socket/index.js.map +1 -0
  99. package/lib/Socket/interop.js +562 -0
  100. package/lib/Socket/managed-account.js +210 -0
  101. package/lib/Socket/messages-recv.d.ts +367 -0
  102. package/lib/Socket/messages-recv.d.ts.map +1 -0
  103. package/lib/Socket/messages-recv.js +2199 -0
  104. package/lib/Socket/messages-recv.js.map +1 -0
  105. package/lib/Socket/messages-send.d.ts +364 -0
  106. package/lib/Socket/messages-send.d.ts.map +1 -0
  107. package/lib/Socket/messages-send.js +1501 -0
  108. package/lib/Socket/messages-send.js.map +1 -0
  109. package/lib/Socket/mex.d.ts +2 -0
  110. package/lib/Socket/mex.d.ts.map +1 -0
  111. package/lib/Socket/mex.js +42 -0
  112. package/lib/Socket/mex.js.map +1 -0
  113. package/lib/Socket/newsletter.d.ts +315 -0
  114. package/lib/Socket/newsletter.d.ts.map +1 -0
  115. package/lib/Socket/newsletter.js +235 -0
  116. package/lib/Socket/newsletter.js.map +1 -0
  117. package/lib/Socket/privacy.js +448 -0
  118. package/lib/Socket/registration.js +430 -0
  119. package/lib/Socket/socket.d.ts +93 -0
  120. package/lib/Socket/socket.d.ts.map +1 -0
  121. package/lib/Socket/socket.js +1272 -0
  122. package/lib/Socket/socket.js.map +1 -0
  123. package/lib/Store/index.d.ts +4 -0
  124. package/lib/Store/index.d.ts.map +1 -0
  125. package/lib/Store/index.js +4 -0
  126. package/lib/Store/index.js.map +1 -0
  127. package/lib/Store/make-in-memory-store.d.ts +63 -0
  128. package/lib/Store/make-in-memory-store.d.ts.map +1 -0
  129. package/lib/Store/make-in-memory-store.js +462 -0
  130. package/lib/Store/make-in-memory-store.js.map +1 -0
  131. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  132. package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
  133. package/lib/Store/make-ordered-dictionary.js +79 -0
  134. package/lib/Store/make-ordered-dictionary.js.map +1 -0
  135. package/lib/Store/object-repository.d.ts +11 -0
  136. package/lib/Store/object-repository.d.ts.map +1 -0
  137. package/lib/Store/object-repository.js +24 -0
  138. package/lib/Store/object-repository.js.map +1 -0
  139. package/lib/Types/Auth.d.ts +60 -0
  140. package/lib/Types/Auth.d.ts.map +1 -0
  141. package/lib/Types/Auth.js +2 -0
  142. package/lib/Types/Auth.js.map +1 -0
  143. package/lib/Types/Bussines.d.ts +9 -0
  144. package/lib/Types/Bussines.d.ts.map +1 -0
  145. package/lib/Types/Bussines.js +2 -0
  146. package/lib/Types/Bussines.js.map +1 -0
  147. package/lib/Types/Call.d.ts +22 -0
  148. package/lib/Types/Call.d.ts.map +1 -0
  149. package/lib/Types/Call.js +2 -0
  150. package/lib/Types/Call.js.map +1 -0
  151. package/lib/Types/Chat.d.ts +3 -0
  152. package/lib/Types/Chat.d.ts.map +1 -0
  153. package/lib/Types/Chat.js +8 -0
  154. package/lib/Types/Chat.js.map +1 -0
  155. package/lib/Types/Contact.d.ts +11 -0
  156. package/lib/Types/Contact.d.ts.map +1 -0
  157. package/lib/Types/Contact.js +2 -0
  158. package/lib/Types/Contact.js.map +1 -0
  159. package/lib/Types/Events.d.ts +41 -0
  160. package/lib/Types/Events.d.ts.map +1 -0
  161. package/lib/Types/Events.js +2 -0
  162. package/lib/Types/Events.js.map +1 -0
  163. package/lib/Types/GroupMetadata.d.ts +36 -0
  164. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  165. package/lib/Types/GroupMetadata.js +2 -0
  166. package/lib/Types/GroupMetadata.js.map +1 -0
  167. package/lib/Types/Label.d.ts +3 -0
  168. package/lib/Types/Label.d.ts.map +1 -0
  169. package/lib/Types/Label.js +25 -0
  170. package/lib/Types/Label.js.map +1 -0
  171. package/lib/Types/LabelAssociation.d.ts +3 -0
  172. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  173. package/lib/Types/LabelAssociation.js +7 -0
  174. package/lib/Types/LabelAssociation.js.map +1 -0
  175. package/lib/Types/Message.d.ts +22 -0
  176. package/lib/Types/Message.d.ts.map +1 -0
  177. package/lib/Types/Message.js +18 -0
  178. package/lib/Types/Message.js.map +1 -0
  179. package/lib/Types/Mex.d.ts +3 -0
  180. package/lib/Types/Mex.d.ts.map +1 -0
  181. package/lib/Types/Mex.js +49 -0
  182. package/lib/Types/Mex.js.map +1 -0
  183. package/lib/Types/Product.d.ts +5 -0
  184. package/lib/Types/Product.d.ts.map +1 -0
  185. package/lib/Types/Product.js +2 -0
  186. package/lib/Types/Product.js.map +1 -0
  187. package/lib/Types/RichType.d.ts +3 -0
  188. package/lib/Types/RichType.d.ts.map +1 -0
  189. package/lib/Types/RichType.js +23 -0
  190. package/lib/Types/RichType.js.map +1 -0
  191. package/lib/Types/Signal.d.ts +10 -0
  192. package/lib/Types/Signal.d.ts.map +1 -0
  193. package/lib/Types/Signal.js +2 -0
  194. package/lib/Types/Signal.js.map +1 -0
  195. package/lib/Types/Socket.d.ts +33 -0
  196. package/lib/Types/Socket.d.ts.map +1 -0
  197. package/lib/Types/Socket.js +2 -0
  198. package/lib/Types/Socket.js.map +1 -0
  199. package/lib/Types/State.d.ts +6 -0
  200. package/lib/Types/State.d.ts.map +1 -0
  201. package/lib/Types/State.js +56 -0
  202. package/lib/Types/State.js.map +1 -0
  203. package/lib/Types/USync.d.ts +9 -0
  204. package/lib/Types/USync.d.ts.map +1 -0
  205. package/lib/Types/USync.js +2 -0
  206. package/lib/Types/USync.js.map +1 -0
  207. package/lib/Types/index.d.ts +16 -0
  208. package/lib/Types/index.d.ts.map +1 -0
  209. package/lib/Types/index.js +26 -0
  210. package/lib/Types/index.js.map +1 -0
  211. package/lib/Utils/async-utils.js +7 -0
  212. package/lib/Utils/auth-utils.d.ts +59 -0
  213. package/lib/Utils/auth-utils.d.ts.map +1 -0
  214. package/lib/Utils/auth-utils.js +306 -0
  215. package/lib/Utils/auth-utils.js.map +1 -0
  216. package/lib/Utils/browser-utils.d.ts +10 -0
  217. package/lib/Utils/browser-utils.d.ts.map +1 -0
  218. package/lib/Utils/browser-utils.js +29 -0
  219. package/lib/Utils/browser-utils.js.map +1 -0
  220. package/lib/Utils/business.d.ts +50 -0
  221. package/lib/Utils/business.d.ts.map +1 -0
  222. package/lib/Utils/business.js +231 -0
  223. package/lib/Utils/business.js.map +1 -0
  224. package/lib/Utils/chat-utils.d.ts +409 -0
  225. package/lib/Utils/chat-utils.d.ts.map +1 -0
  226. package/lib/Utils/chat-utils.js +872 -0
  227. package/lib/Utils/chat-utils.js.map +1 -0
  228. package/lib/Utils/companion-reg-client-utils.d.ts +10 -0
  229. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  230. package/lib/Utils/companion-reg-client-utils.js +69 -0
  231. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  232. package/lib/Utils/crypto-worker.js +20 -0
  233. package/lib/Utils/crypto.d.ts +40 -0
  234. package/lib/Utils/crypto.d.ts.map +1 -0
  235. package/lib/Utils/crypto.js +118 -0
  236. package/lib/Utils/crypto.js.map +1 -0
  237. package/lib/Utils/decode-wa-message.d.ts +85 -0
  238. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  239. package/lib/Utils/decode-wa-message.js +467 -0
  240. package/lib/Utils/decode-wa-message.js.map +1 -0
  241. package/lib/Utils/event-buffer.d.ts +13 -0
  242. package/lib/Utils/event-buffer.d.ts.map +1 -0
  243. package/lib/Utils/event-buffer.js +651 -0
  244. package/lib/Utils/event-buffer.js.map +1 -0
  245. package/lib/Utils/generics.d.ts +64 -0
  246. package/lib/Utils/generics.d.ts.map +1 -0
  247. package/lib/Utils/generics.js +442 -0
  248. package/lib/Utils/generics.js.map +1 -0
  249. package/lib/Utils/history.d.ts +77 -0
  250. package/lib/Utils/history.d.ts.map +1 -0
  251. package/lib/Utils/history.js +188 -0
  252. package/lib/Utils/history.js.map +1 -0
  253. package/lib/Utils/identity-change-handler.d.ts +14 -0
  254. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  255. package/lib/Utils/identity-change-handler.js +50 -0
  256. package/lib/Utils/identity-change-handler.js.map +1 -0
  257. package/lib/Utils/index.d.ts +26 -0
  258. package/lib/Utils/index.d.ts.map +1 -0
  259. package/lib/Utils/index.js +26 -0
  260. package/lib/Utils/index.js.map +1 -0
  261. package/lib/Utils/link-preview.d.ts +13 -0
  262. package/lib/Utils/link-preview.d.ts.map +1 -0
  263. package/lib/Utils/link-preview.js +85 -0
  264. package/lib/Utils/link-preview.js.map +1 -0
  265. package/lib/Utils/listener-guard.js +48 -0
  266. package/lib/Utils/logger.d.ts +3 -0
  267. package/lib/Utils/logger.d.ts.map +1 -0
  268. package/lib/Utils/logger.js +3 -0
  269. package/lib/Utils/logger.js.map +1 -0
  270. package/lib/Utils/lt-hash.d.ts +7 -0
  271. package/lib/Utils/lt-hash.d.ts.map +1 -0
  272. package/lib/Utils/lt-hash.js +8 -0
  273. package/lib/Utils/lt-hash.js.map +1 -0
  274. package/lib/Utils/make-mutex.d.ts +7 -0
  275. package/lib/Utils/make-mutex.d.ts.map +1 -0
  276. package/lib/Utils/make-mutex.js +33 -0
  277. package/lib/Utils/make-mutex.js.map +1 -0
  278. package/lib/Utils/message-retry-manager.d.ts +80 -0
  279. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  280. package/lib/Utils/message-retry-manager.js +285 -0
  281. package/lib/Utils/message-retry-manager.js.map +1 -0
  282. package/lib/Utils/messages-media.d.ts +166 -0
  283. package/lib/Utils/messages-media.d.ts.map +1 -0
  284. package/lib/Utils/messages-media.js +957 -0
  285. package/lib/Utils/messages-media.js.map +1 -0
  286. package/lib/Utils/messages.d.ts +46 -0
  287. package/lib/Utils/messages.d.ts.map +1 -0
  288. package/lib/Utils/messages.js +1887 -0
  289. package/lib/Utils/messages.js.map +1 -0
  290. package/lib/Utils/meta-ai-msmsg.d.ts +12 -0
  291. package/lib/Utils/meta-ai-msmsg.js +124 -0
  292. package/lib/Utils/noise-handler.d.ts +21 -0
  293. package/lib/Utils/noise-handler.d.ts.map +1 -0
  294. package/lib/Utils/noise-handler.js +206 -0
  295. package/lib/Utils/noise-handler.js.map +1 -0
  296. package/lib/Utils/offline-node-processor.d.ts +10 -0
  297. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  298. package/lib/Utils/offline-node-processor.js +40 -0
  299. package/lib/Utils/offline-node-processor.js.map +1 -0
  300. package/lib/Utils/pre-key-manager.d.ts +26 -0
  301. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  302. package/lib/Utils/pre-key-manager.js +106 -0
  303. package/lib/Utils/pre-key-manager.js.map +1 -0
  304. package/lib/Utils/process-message.d.ts +102 -0
  305. package/lib/Utils/process-message.d.ts.map +1 -0
  306. package/lib/Utils/process-message.js +798 -0
  307. package/lib/Utils/process-message.js.map +1 -0
  308. package/lib/Utils/reporting-utils.d.ts +13 -0
  309. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  310. package/lib/Utils/reporting-utils.js +258 -0
  311. package/lib/Utils/reporting-utils.js.map +1 -0
  312. package/lib/Utils/rich-message-utils.d.ts +49 -0
  313. package/lib/Utils/rich-message-utils.d.ts.map +1 -0
  314. package/lib/Utils/rich-message-utils.js +369 -0
  315. package/lib/Utils/rich-message-utils.js.map +1 -0
  316. package/lib/Utils/session-queue.js +33 -0
  317. package/lib/Utils/signal.d.ts +83 -0
  318. package/lib/Utils/signal.d.ts.map +1 -0
  319. package/lib/Utils/signal.js +201 -0
  320. package/lib/Utils/signal.js.map +1 -0
  321. package/lib/Utils/stanza-ack.d.ts +22 -0
  322. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  323. package/lib/Utils/stanza-ack.js +72 -0
  324. package/lib/Utils/stanza-ack.js.map +1 -0
  325. package/lib/Utils/sync-action-utils.d.ts +3 -0
  326. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  327. package/lib/Utils/sync-action-utils.js +49 -0
  328. package/lib/Utils/sync-action-utils.js.map +1 -0
  329. package/lib/Utils/tc-token-utils.d.ts +30 -0
  330. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  331. package/lib/Utils/tc-token-utils.js +164 -0
  332. package/lib/Utils/tc-token-utils.js.map +1 -0
  333. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  334. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  335. package/lib/Utils/use-multi-file-auth-state.js +175 -0
  336. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  337. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  338. package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
  339. package/lib/Utils/use-single-file-auth-state.js +109 -0
  340. package/lib/Utils/use-single-file-auth-state.js.map +1 -0
  341. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  342. package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
  343. package/lib/Utils/use-sqlite-auth-state.js +109 -0
  344. package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
  345. package/lib/Utils/validate-connection.d.ts +44 -0
  346. package/lib/Utils/validate-connection.d.ts.map +1 -0
  347. package/lib/Utils/validate-connection.js +210 -0
  348. package/lib/Utils/validate-connection.js.map +1 -0
  349. package/lib/Utils/worker-pool.js +73 -0
  350. package/lib/WABinary/constants.d.ts +62 -0
  351. package/lib/WABinary/constants.d.ts.map +1 -0
  352. package/lib/WABinary/constants.js +1467 -0
  353. package/lib/WABinary/constants.js.map +1 -0
  354. package/lib/WABinary/decode.d.ts +10 -0
  355. package/lib/WABinary/decode.d.ts.map +1 -0
  356. package/lib/WABinary/decode.js +262 -0
  357. package/lib/WABinary/decode.js.map +1 -0
  358. package/lib/WABinary/encode.d.ts +3 -0
  359. package/lib/WABinary/encode.d.ts.map +1 -0
  360. package/lib/WABinary/encode.js +220 -0
  361. package/lib/WABinary/encode.js.map +1 -0
  362. package/lib/WABinary/generic-utils.d.ts +77 -0
  363. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  364. package/lib/WABinary/generic-utils.js +226 -0
  365. package/lib/WABinary/generic-utils.js.map +1 -0
  366. package/lib/WABinary/index.d.ts +6 -0
  367. package/lib/WABinary/index.d.ts.map +1 -0
  368. package/lib/WABinary/index.js +6 -0
  369. package/lib/WABinary/index.js.map +1 -0
  370. package/lib/WABinary/jid-utils.d.ts +29 -0
  371. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  372. package/lib/WABinary/jid-utils.js +96 -0
  373. package/lib/WABinary/jid-utils.js.map +1 -0
  374. package/lib/WABinary/types.d.ts +6 -0
  375. package/lib/WABinary/types.d.ts.map +1 -0
  376. package/lib/WABinary/types.js +2 -0
  377. package/lib/WABinary/types.js.map +1 -0
  378. package/lib/WAM/BinaryInfo.d.ts +8 -0
  379. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  380. package/lib/WAM/BinaryInfo.js +10 -0
  381. package/lib/WAM/BinaryInfo.js.map +1 -0
  382. package/lib/WAM/constants.d.ts +34927 -0
  383. package/lib/WAM/constants.d.ts.map +1 -0
  384. package/lib/WAM/constants.js +22853 -0
  385. package/lib/WAM/constants.js.map +1 -0
  386. package/lib/WAM/encode.d.ts +2 -0
  387. package/lib/WAM/encode.d.ts.map +1 -0
  388. package/lib/WAM/encode.js +150 -0
  389. package/lib/WAM/encode.js.map +1 -0
  390. package/lib/WAM/index.d.ts +4 -0
  391. package/lib/WAM/index.d.ts.map +1 -0
  392. package/lib/WAM/index.js +4 -0
  393. package/lib/WAM/index.js.map +1 -0
  394. package/lib/WAUSync/Protocols/USyncBusinessProtocol.d.ts +8 -0
  395. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +99 -0
  396. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
  397. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  398. package/lib/WAUSync/Protocols/USyncContactProtocol.js +53 -0
  399. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  400. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  401. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  402. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  403. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  404. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  405. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  406. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  407. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  408. package/lib/WAUSync/Protocols/USyncFeatureProtocol.d.ts +9 -0
  409. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +70 -0
  410. package/lib/WAUSync/Protocols/USyncPictureProtocol.d.ts +12 -0
  411. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  412. package/lib/WAUSync/Protocols/USyncSidelistProtocol.d.ts +10 -0
  413. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +25 -0
  414. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  415. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  416. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  417. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  418. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.d.ts +11 -0
  419. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +34 -0
  420. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  421. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  422. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +31 -0
  423. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  424. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  425. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  426. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  427. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  428. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
  429. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  430. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  431. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  432. package/lib/WAUSync/Protocols/index.d.ts +11 -0
  433. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  434. package/lib/WAUSync/Protocols/index.js +11 -0
  435. package/lib/WAUSync/Protocols/index.js.map +1 -0
  436. package/lib/WAUSync/USyncQuery.d.ts +32 -0
  437. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  438. package/lib/WAUSync/USyncQuery.js +185 -0
  439. package/lib/WAUSync/USyncQuery.js.map +1 -0
  440. package/lib/WAUSync/USyncUser.d.ts +25 -0
  441. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  442. package/lib/WAUSync/USyncUser.js +48 -0
  443. package/lib/WAUSync/USyncUser.js.map +1 -0
  444. package/lib/WAUSync/index.d.ts +4 -0
  445. package/lib/WAUSync/index.d.ts.map +1 -0
  446. package/lib/WAUSync/index.js +4 -0
  447. package/lib/WAUSync/index.js.map +1 -0
  448. package/lib/index.d.ts +12 -0
  449. package/lib/index.d.ts.map +1 -0
  450. package/lib/index.js +12 -0
  451. package/lib/index.js.map +1 -0
  452. package/package.json +122 -5
@@ -0,0 +1,798 @@
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
+ // TODO: target:audit AUDIT THIS FUNCTION AGAIN
108
+ export const isRealMessage = (message) => {
109
+ const normalizedContent = normalizeMessageContent(message.message);
110
+ const hasSomeContent = !!getContentType(normalizedContent);
111
+ return ((!!normalizedContent ||
112
+ REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
113
+ REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
114
+ hasSomeContent &&
115
+ !normalizedContent?.protocolMessage &&
116
+ !normalizedContent?.reactionMessage &&
117
+ !normalizedContent?.pollUpdateMessage);
118
+ };
119
+ export const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
120
+ /**
121
+ * Get the ID of the chat from the given key.
122
+ * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
123
+ */
124
+ export const getChatId = ({ remoteJid, participant, fromMe }) => {
125
+ if (!remoteJid) {
126
+ throw new Boom('Cannot derive chat id: message key is missing remoteJid', {
127
+ data: { remoteJid, participant, fromMe }
128
+ });
129
+ }
130
+ if (isJidBroadcast(remoteJid) && !isJidStatusBroadcast(remoteJid) && !fromMe) {
131
+ if (!participant) {
132
+ throw new Boom('Cannot derive chat id: broadcast message key is missing participant', {
133
+ data: { remoteJid, fromMe }
134
+ });
135
+ }
136
+ return participant;
137
+ }
138
+ return remoteJid;
139
+ };
140
+ /**
141
+ * Decrypt a poll vote
142
+ * @param vote encrypted vote
143
+ * @param ctx additional info about the poll required for decryption
144
+ * @returns list of SHA256 options
145
+ */
146
+ export function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
147
+ const sign = Buffer.concat([
148
+ toBinary(pollMsgId),
149
+ toBinary(pollCreatorJid),
150
+ toBinary(voterJid),
151
+ toBinary('Poll Vote'),
152
+ new Uint8Array([1])
153
+ ]);
154
+ const key0 = hmacSign(pollEncKey, new Uint8Array(32), 'sha256');
155
+ const decKey = hmacSign(sign, key0, 'sha256');
156
+ const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
157
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
158
+ return proto.Message.PollVoteMessage.decode(decrypted);
159
+ function toBinary(txt) {
160
+ return Buffer.from(txt);
161
+ }
162
+ }
163
+ const uniqueJids = (jids) => [...new Set(jids.filter(j => typeof j === 'string' && j.length > 0))];
164
+ /**
165
+ * Try every (creator, voter) pair until one decrypts. Voters derive the key from the creator
166
+ * JID in `pollCreationMessageKey` (LID after the addressing migration, PN before), while the
167
+ * poll secret may have been stored under the other form, so a single pair is not enough.
168
+ */
169
+ export function decryptPollVoteWithFallback(vote, { pollCreatorJids, voterJids, pollMsgId, pollEncKey }) {
170
+ let lastErr;
171
+ for (const pollCreatorJid of uniqueJids(pollCreatorJids)) {
172
+ for (const voterJid of uniqueJids(voterJids)) {
173
+ try {
174
+ return decryptPollVote(vote, { pollCreatorJid, pollMsgId, pollEncKey, voterJid });
175
+ }
176
+ catch (err) {
177
+ lastErr = err;
178
+ }
179
+ }
180
+ }
181
+ throw lastErr || new Boom('no jid candidates to decrypt poll vote', { statusCode: 400 });
182
+ }
183
+ /** Same candidate walk as {@link decryptPollVoteWithFallback} for event responses. */
184
+ export function decryptEventResponseWithFallback(response, { eventCreatorJids, responderJids, eventMsgId, eventEncKey }) {
185
+ let lastErr;
186
+ for (const eventCreatorJid of uniqueJids(eventCreatorJids)) {
187
+ for (const responderJid of uniqueJids(responderJids)) {
188
+ try {
189
+ return decryptEventResponse(response, { eventCreatorJid, eventMsgId, eventEncKey, responderJid });
190
+ }
191
+ catch (err) {
192
+ lastErr = err;
193
+ }
194
+ }
195
+ }
196
+ throw lastErr || new Boom('no jid candidates to decrypt event response', { statusCode: 400 });
197
+ }
198
+ /**
199
+ * Decrypt an event response
200
+ * @param response encrypted event response
201
+ * @param ctx additional info about the event required for decryption
202
+ * @returns event response message
203
+ */
204
+ export function decryptEventResponse({ encPayload, encIv }, { eventCreatorJid, eventMsgId, eventEncKey, responderJid }) {
205
+ const sign = Buffer.concat([
206
+ toBinary(eventMsgId),
207
+ toBinary(eventCreatorJid),
208
+ toBinary(responderJid),
209
+ toBinary('Event Response'),
210
+ new Uint8Array([1])
211
+ ]);
212
+ const key0 = hmacSign(eventEncKey, new Uint8Array(32), 'sha256');
213
+ const decKey = hmacSign(sign, key0, 'sha256');
214
+ const aad = toBinary(`${eventMsgId}\u0000${responderJid}`);
215
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
216
+ return proto.Message.EventResponseMessage.decode(decrypted);
217
+ function toBinary(txt) {
218
+ return Buffer.from(txt);
219
+ }
220
+ }
221
+ /**
222
+ * Decrypt a `secretEncryptedMessage` carrying a `MESSAGE_EDIT` payload.
223
+ *
224
+ * WhatsApp started wrapping message edits in an E2EE envelope (May 2026).
225
+ * The new content is encrypted with a key derived from the original
226
+ * message's `messageContextInfo.messageSecret` using HKDF-SHA256
227
+ * + AES-256-GCM, same family as polls and event responses but with
228
+ * different constants (validated against live WhatsApp Android traffic):
229
+ *
230
+ * info = msgId || origSenderJid || editorJid || "Message Edit"
231
+ * aad = (empty) <-- differs from Poll Vote / Event Response
232
+ * key = HKDF-SHA256(salt=zeros, ikm=messageSecret, info, L=32)
233
+ *
234
+ * The decrypted plaintext is a regular `proto.Message` whose
235
+ * `protocolMessage.editedMessage` field holds the new content — same
236
+ * shape as the legacy `protocolMessage.editedMessage` edit path, so
237
+ * consumers can treat the result identically.
238
+ *
239
+ * @param edit encrypted edit payload (encPayload + encIv from SecretEncryptedMessage)
240
+ * @param ctx info about the original message required for decryption
241
+ * @returns decoded outer `Message` whose `protocolMessage.editedMessage`
242
+ * carries the new content (extendedTextMessage / conversation / etc.)
243
+ */
244
+ export function decryptMessageEdit({ encPayload, encIv }, { originalSenderJid, originalMsgId, editEncKey, editorJid }) {
245
+ const sign = Buffer.concat([
246
+ toBinary(originalMsgId),
247
+ toBinary(originalSenderJid),
248
+ toBinary(editorJid),
249
+ toBinary('Message Edit'),
250
+ new Uint8Array([1])
251
+ ]);
252
+ const key0 = hmacSign(editEncKey, new Uint8Array(32), 'sha256');
253
+ const decKey = hmacSign(sign, key0, 'sha256');
254
+ // AAD is intentionally empty for MESSAGE_EDIT — unlike Poll Vote and
255
+ // Event Response, WA does not include `${msgId}\0${editor}` in the AAD here.
256
+ const aad = Buffer.alloc(0);
257
+ const decrypted = aesDecryptGCM(encPayload, decKey, encIv, aad);
258
+ return proto.Message.decode(decrypted);
259
+ function toBinary(txt) {
260
+ return Buffer.from(txt);
261
+ }
262
+ }
263
+ const buildEditUpdate = (args) => {
264
+ const editedInner = decryptMessageEdit({ encPayload: args.encPayload, encIv: args.encIv }, {
265
+ editEncKey: args.editEncKey,
266
+ originalSenderJid: args.originalSenderJid,
267
+ originalMsgId: args.originalMsgId,
268
+ editorJid: args.editorJid
269
+ });
270
+ const editProtocol = editedInner.protocolMessage;
271
+ const innerEdited = editProtocol?.editedMessage;
272
+ if (!innerEdited) {
273
+ args.logger?.warn({ targetKey: args.targetKey }, 'decrypted MESSAGE_EDIT plaintext had no protocolMessage.editedMessage — skipping update');
274
+ return null;
275
+ }
276
+ return {
277
+ key: { ...args.messageKey, id: args.targetKeyId },
278
+ update: {
279
+ message: {
280
+ editedMessage: {
281
+ message: innerEdited
282
+ }
283
+ },
284
+ messageTimestamp: editProtocol?.timestampMs
285
+ ? Math.floor(toNumber(editProtocol.timestampMs) / 1000)
286
+ : args.fallbackTimestamp
287
+ }
288
+ };
289
+ };
290
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options, getMessage }) => {
291
+ const meId = creds.me.id;
292
+ const { accountSettings } = creds;
293
+ const chat = { id: jidNormalizedUser(getChatId(message.key)) };
294
+ const isRealMsg = isRealMessage(message);
295
+ if (isRealMsg) {
296
+ chat.messages = [{ message }];
297
+ chat.conversationTimestamp = toNumber(message.messageTimestamp);
298
+ // only increment unread count if not CIPHERTEXT and from another person
299
+ if (shouldIncrementChatUnread(message)) {
300
+ chat.unreadCount = (chat.unreadCount || 0) + 1;
301
+ }
302
+ }
303
+ const content = normalizeMessageContent(message.message);
304
+ // unarchive chat if it's a real message, or someone reacted to our message
305
+ // and we've the unarchive chats setting on
306
+ if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
307
+ chat.archived = false;
308
+ chat.readOnly = false;
309
+ }
310
+ const protocolMsg = content?.protocolMessage;
311
+ if (protocolMsg) {
312
+ // Mirror whatsmeow's `handleProtocolMessage` guard, but applied only to
313
+ // the protocol message types that originate from our own device — an
314
+ // attacker could otherwise spoof any of these to manipulate local state.
315
+ //
316
+ // Self-only types (drop if `!fromMe`):
317
+ // - HISTORY_SYNC_NOTIFICATION (our phone driving history sync)
318
+ // - APP_STATE_SYNC_KEY_SHARE (key share between our devices)
319
+ // - LID_MIGRATION_MAPPING_SYNC (server-initiated via our phone)
320
+ // - PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE (response from our phone to our PDO request)
321
+ //
322
+ // Cross-user types (must NOT be dropped — legitimately arrive from others):
323
+ // - REVOKE
324
+ // - MESSAGE_EDIT
325
+ // - EPHEMERAL_SETTING
326
+ // - GROUP_MEMBER_LABEL_CHANGE
327
+ //
328
+ // See https://github.com/tulir/whatsmeow/blob/8d3700152a/message.go#L842-L845
329
+ // for the reference architecture — whatsmeow's `handleProtocolMessage`
330
+ // only contains self-only types because edits are unwrapped from
331
+ // `EditedMessage` BEFORE this dispatch and revokes aren't routed here.
332
+ const SELF_ONLY_TYPES = new Set([
333
+ proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION,
334
+ proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE,
335
+ proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC,
336
+ proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE
337
+ ]);
338
+ if (protocolMsg.type !== null &&
339
+ protocolMsg.type !== undefined &&
340
+ SELF_ONLY_TYPES.has(protocolMsg.type) &&
341
+ !message.key.fromMe) {
342
+ 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');
343
+ return;
344
+ }
345
+ switch (protocolMsg.type) {
346
+ case proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
347
+ const histNotification = protocolMsg.historySyncNotification;
348
+ const process = shouldProcessHistoryMsg;
349
+ const isLatest = !creds.processedHistoryMessages?.length;
350
+ logger?.info({
351
+ histNotification,
352
+ process,
353
+ id: message.key.id,
354
+ isLatest
355
+ }, 'got history notification');
356
+ if (process) {
357
+ // TODO: investigate
358
+ if (histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND) {
359
+ ev.emit('creds.update', {
360
+ processedHistoryMessages: [
361
+ ...(creds.processedHistoryMessages || []),
362
+ { key: message.key, messageTimestamp: message.messageTimestamp }
363
+ ]
364
+ });
365
+ }
366
+ const data = await downloadAndProcessHistorySyncNotification(histNotification, options, logger);
367
+ if (data.lidPnMappings?.length) {
368
+ logger?.debug({ count: data.lidPnMappings.length }, 'processing LID-PN mappings from history sync');
369
+ await signalRepository.lidMapping
370
+ .storeLIDPNMappings(data.lidPnMappings)
371
+ .catch(err => logger?.warn({ err }, 'failed to store LID-PN mappings from history sync'));
372
+ }
373
+ await storeTcTokensFromHistorySync(data.chats, signalRepository, keyStore, logger);
374
+ ev.emit('messaging-history.set', {
375
+ ...data,
376
+ isLatest: histNotification.syncType !== proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
377
+ chunkOrder: histNotification.chunkOrder,
378
+ peerDataRequestSessionId: histNotification.peerDataRequestSessionId
379
+ });
380
+ }
381
+ break;
382
+ case proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
383
+ const keys = protocolMsg.appStateSyncKeyShare.keys;
384
+ if (keys?.length) {
385
+ let newAppStateSyncKeyId = '';
386
+ await keyStore.transaction(async () => {
387
+ const newKeys = [];
388
+ for (const { keyData, keyId } of keys) {
389
+ const strKeyId = Buffer.from(keyId.keyId).toString('base64');
390
+ newKeys.push(strKeyId);
391
+ await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
392
+ newAppStateSyncKeyId = strKeyId;
393
+ }
394
+ logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
395
+ }, meId);
396
+ ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
397
+ }
398
+ else {
399
+ logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
400
+ }
401
+ break;
402
+ case proto.Message.ProtocolMessage.Type.REVOKE:
403
+ ev.emit('messages.update', [
404
+ {
405
+ key: {
406
+ ...message.key,
407
+ id: protocolMsg.key.id
408
+ },
409
+ update: { message: null, messageStubType: WAMessageStubType.REVOKE, key: message.key }
410
+ }
411
+ ]);
412
+ break;
413
+ case proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
414
+ Object.assign(chat, {
415
+ ephemeralSettingTimestamp: toNumber(message.messageTimestamp),
416
+ ephemeralExpiration: protocolMsg.ephemeralExpiration || null
417
+ });
418
+ break;
419
+ case proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
420
+ const response = protocolMsg.peerDataOperationRequestResponseMessage;
421
+ if (response) {
422
+ // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
423
+ const peerDataOperationResult = response.peerDataOperationResult || [];
424
+ for (const result of peerDataOperationResult) {
425
+ const retryResponse = result?.placeholderMessageResendResponse;
426
+ //eslint-disable-next-line max-depth
427
+ if (!retryResponse?.webMessageInfoBytes) {
428
+ continue;
429
+ }
430
+ //eslint-disable-next-line max-depth
431
+ try {
432
+ const webMessageInfo = proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
433
+ const msgId = webMessageInfo.key?.id;
434
+ // Retrieve cached original message data (preserves LID details,
435
+ // timestamps, etc. that the phone may omit in its PDO response)
436
+ const cachedData = msgId ? await placeholderResendCache?.get(msgId) : undefined;
437
+ //eslint-disable-next-line max-depth
438
+ if (msgId) {
439
+ await placeholderResendCache?.del(msgId);
440
+ }
441
+ let finalMsg;
442
+ //eslint-disable-next-line max-depth
443
+ if (cachedData && typeof cachedData === 'object') {
444
+ // Apply decoded message content onto cached metadata (preserves LID etc.)
445
+ cachedData.message = webMessageInfo.message;
446
+ //eslint-disable-next-line max-depth
447
+ if (webMessageInfo.messageTimestamp) {
448
+ cachedData.messageTimestamp = webMessageInfo.messageTimestamp;
449
+ }
450
+ finalMsg = cachedData;
451
+ }
452
+ else {
453
+ finalMsg = webMessageInfo;
454
+ }
455
+ logger?.debug({ msgId, requestId: response.stanzaId }, 'received placeholder resend');
456
+ ev.emit('messages.upsert', {
457
+ messages: [finalMsg],
458
+ type: 'notify',
459
+ requestId: response.stanzaId
460
+ });
461
+ }
462
+ catch (err) {
463
+ logger?.warn({ err, stanzaId: response.stanzaId }, 'failed to decode placeholder resend response');
464
+ }
465
+ }
466
+ }
467
+ break;
468
+ case proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
469
+ ev.emit('messages.update', [
470
+ {
471
+ // flip the sender / fromMe properties because they're in the perspective of the sender
472
+ key: { ...message.key, id: protocolMsg.key?.id },
473
+ update: {
474
+ message: {
475
+ editedMessage: {
476
+ message: protocolMsg.editedMessage
477
+ }
478
+ },
479
+ messageTimestamp: protocolMsg.timestampMs
480
+ ? Math.floor(toNumber(protocolMsg.timestampMs) / 1000)
481
+ : message.messageTimestamp
482
+ }
483
+ }
484
+ ]);
485
+ break;
486
+ case proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE:
487
+ const labelAssociationMsg = protocolMsg.memberLabel;
488
+ if (labelAssociationMsg?.label) {
489
+ ev.emit('group.member-tag.update', {
490
+ groupId: chat.id,
491
+ label: labelAssociationMsg.label,
492
+ participant: message.key.participant,
493
+ participantAlt: message.key.participantAlt,
494
+ messageTimestamp: Number(message.messageTimestamp)
495
+ });
496
+ }
497
+ break;
498
+ case proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
499
+ const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
500
+ const { pnToLidMappings, chatDbMigrationTimestamp } = proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
501
+ logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
502
+ const pairs = [];
503
+ for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
504
+ const lid = latestLid || assignedLid;
505
+ pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
506
+ }
507
+ await signalRepository.lidMapping.storeLIDPNMappings(pairs);
508
+ if (pairs.length) {
509
+ for (const { pn, lid } of pairs) {
510
+ await signalRepository.migrateSession(pn, lid);
511
+ }
512
+ }
513
+ }
514
+ }
515
+ else if (content?.reactionMessage) {
516
+ const reaction = {
517
+ ...content.reactionMessage,
518
+ key: message.key
519
+ };
520
+ ev.emit('messages.reaction', [
521
+ {
522
+ reaction,
523
+ key: content.reactionMessage?.key
524
+ }
525
+ ]);
526
+ }
527
+ else if (content?.encEventResponseMessage) {
528
+ const encEventResponse = content.encEventResponseMessage;
529
+ const creationMsgKey = encEventResponse.eventCreationMessageKey;
530
+ // we need to fetch the event creation message to get the event enc key
531
+ const eventMsg = await getMessage(creationMsgKey);
532
+ if (eventMsg) {
533
+ try {
534
+ const meIdNormalised = jidNormalizedUser(meId);
535
+ const meLidNormalised = creds.me.lid ? jidNormalizedUser(creds.me.lid) : undefined;
536
+ // the responder encrypted with whichever form of the creator JID it holds (PN or
537
+ // LID); try the PN form first (previous behaviour), then the other form
538
+ const eventCreatorKey = jidNormalizedUser(creationMsgKey.participant || creationMsgKey.remoteJid);
539
+ const eventCreatorAlt = isLidUser(eventCreatorKey)
540
+ ? await signalRepository.lidMapping.getPNForLID(eventCreatorKey)
541
+ : await signalRepository.lidMapping.getLIDForPN(eventCreatorKey);
542
+ const eventCreatorAltNorm = eventCreatorAlt ? jidNormalizedUser(eventCreatorAlt) : undefined;
543
+ const eventCreatorJids = creationMsgKey.fromMe
544
+ ? [meIdNormalised, meLidNormalised]
545
+ : isLidUser(eventCreatorKey)
546
+ ? [eventCreatorAltNorm, eventCreatorKey]
547
+ : [eventCreatorKey, eventCreatorAltNorm];
548
+ const responderJids = [
549
+ getKeyAuthor(message.key, meIdNormalised),
550
+ jidNormalizedUser(message.key.participant || message.key.remoteJid || ''),
551
+ message.key.fromMe ? meLidNormalised : undefined
552
+ ];
553
+ const eventEncKey = eventMsg?.messageContextInfo?.messageSecret;
554
+ if (!eventEncKey) {
555
+ logger?.warn({ creationMsgKey }, 'event response: missing messageSecret for decryption');
556
+ }
557
+ else {
558
+ const responseMsg = decryptEventResponseWithFallback(encEventResponse, {
559
+ eventEncKey,
560
+ eventCreatorJids,
561
+ eventMsgId: creationMsgKey.id,
562
+ responderJids
563
+ });
564
+ const eventResponse = {
565
+ eventResponseMessageKey: message.key,
566
+ senderTimestampMs: responseMsg.timestampMs,
567
+ response: responseMsg
568
+ };
569
+ ev.emit('messages.update', [
570
+ {
571
+ key: creationMsgKey,
572
+ update: {
573
+ eventResponses: [eventResponse]
574
+ }
575
+ }
576
+ ]);
577
+ }
578
+ }
579
+ catch (err) {
580
+ logger?.warn({ err, creationMsgKey }, 'failed to decrypt event response');
581
+ }
582
+ }
583
+ else {
584
+ logger?.warn({ creationMsgKey }, 'event creation message not found, cannot decrypt response');
585
+ }
586
+ }
587
+ else if (content?.secretEncryptedMessage &&
588
+ content.secretEncryptedMessage.secretEncType === proto.Message.SecretEncryptedMessage.SecretEncType.MESSAGE_EDIT) {
589
+ // E2EE message edit envelope (new in 2026-05). Replaces the older
590
+ // `protocolMessage.editedMessage` path for direct text edits.
591
+ // We fetch the target message to obtain its `messageSecret`, derive the
592
+ // decryption key, and surface the decoded inner Message via the same
593
+ // `messages.update` event used by the legacy edit path so consumers do
594
+ // not need a new event type.
595
+ const secEnc = content.secretEncryptedMessage;
596
+ const targetKey = secEnc.targetMessageKey;
597
+ const targetMsg = await getMessage(targetKey);
598
+ if (targetMsg) {
599
+ try {
600
+ const meIdNormalised = jidNormalizedUser(meId);
601
+ const origSenderRaw = targetKey.participant || targetKey.remoteJid;
602
+ const origSenderPn = isLidUser(origSenderRaw)
603
+ ? await signalRepository.lidMapping.getPNForLID(origSenderRaw)
604
+ : origSenderRaw;
605
+ const originalSenderJid = getKeyAuthor({ remoteJid: jidNormalizedUser(origSenderPn), fromMe: meIdNormalised === origSenderPn }, meIdNormalised);
606
+ const editorJid = getKeyAuthor(message.key, meIdNormalised);
607
+ const editEncKey = targetMsg?.messageContextInfo?.messageSecret;
608
+ if (!editEncKey) {
609
+ logger?.warn({ targetKey }, 'message edit: missing messageSecret on original message — cannot decrypt');
610
+ return;
611
+ }
612
+ const update = buildEditUpdate({
613
+ editEncKey,
614
+ encPayload: secEnc.encPayload,
615
+ encIv: secEnc.encIv,
616
+ originalSenderJid,
617
+ originalMsgId: targetKey.id,
618
+ editorJid,
619
+ messageKey: message.key,
620
+ targetKeyId: targetKey.id,
621
+ fallbackTimestamp: toNumber(message.messageTimestamp),
622
+ logger,
623
+ targetKey
624
+ });
625
+ if (update) {
626
+ ev.emit('messages.update', [update]);
627
+ }
628
+ }
629
+ catch (err) {
630
+ logger?.warn({ err, targetKey }, 'failed to decrypt secretEncryptedMessage MESSAGE_EDIT');
631
+ }
632
+ }
633
+ else {
634
+ logger?.warn({ targetKey }, 'original message not found in store, cannot decrypt secretEncryptedMessage edit');
635
+ }
636
+ }
637
+ else if (message.messageStubType) {
638
+ const jid = message.key?.remoteJid;
639
+ //let actor = whatsappID (message.participant)
640
+ let participants;
641
+ const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', {
642
+ id: jid,
643
+ author: message.key.participant,
644
+ authorPn: message.key.participantAlt,
645
+ authorUsername: message.key.participantUsername,
646
+ participants,
647
+ action
648
+ });
649
+ const emitGroupUpdate = (update) => {
650
+ ev.emit('groups.update', [
651
+ {
652
+ id: jid,
653
+ ...update,
654
+ author: message.key.participant ?? undefined,
655
+ authorPn: message.key.participantAlt,
656
+ authorUsername: message.key.participantUsername
657
+ }
658
+ ]);
659
+ };
660
+ const emitGroupRequestJoin = (participant, action, method) => {
661
+ ev.emit('group.join-request', {
662
+ id: jid,
663
+ author: message.key.participant,
664
+ authorPn: message.key.participantAlt,
665
+ authorUsername: message.key.participantUsername,
666
+ participant: participant.lid,
667
+ participantPn: participant.pn,
668
+ action,
669
+ method: method
670
+ });
671
+ };
672
+ const participantsIncludesMe = () => participants.find(jid => areJidsSameUser(meId, jid.phoneNumber)); // ADD SUPPORT FOR LID
673
+ switch (message.messageStubType) {
674
+ case WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
675
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
676
+ emitParticipantsUpdate('modify');
677
+ break;
678
+ case WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
679
+ case WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
680
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
681
+ emitParticipantsUpdate('remove');
682
+ // mark the chat read only if you left the group
683
+ if (participantsIncludesMe()) {
684
+ chat.readOnly = true;
685
+ }
686
+ break;
687
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD:
688
+ case WAMessageStubType.GROUP_PARTICIPANT_INVITE:
689
+ case WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
690
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
691
+ if (participantsIncludesMe()) {
692
+ chat.readOnly = false;
693
+ }
694
+ emitParticipantsUpdate('add');
695
+ break;
696
+ case WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
697
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
698
+ emitParticipantsUpdate('demote');
699
+ break;
700
+ case WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
701
+ participants = message.messageStubParameters.map((a) => JSON.parse(a)) || [];
702
+ emitParticipantsUpdate('promote');
703
+ break;
704
+ case WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
705
+ const announceValue = message.messageStubParameters?.[0];
706
+ emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
707
+ break;
708
+ case WAMessageStubType.GROUP_CHANGE_RESTRICT:
709
+ const restrictValue = message.messageStubParameters?.[0];
710
+ emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
711
+ break;
712
+ case WAMessageStubType.GROUP_CHANGE_SUBJECT:
713
+ const name = message.messageStubParameters?.[0];
714
+ chat.name = name;
715
+ emitGroupUpdate({ subject: name });
716
+ break;
717
+ case WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
718
+ const description = message.messageStubParameters?.[0];
719
+ chat.description = description;
720
+ emitGroupUpdate({ desc: description });
721
+ break;
722
+ case WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
723
+ const code = message.messageStubParameters?.[0];
724
+ emitGroupUpdate({ inviteCode: code });
725
+ break;
726
+ case WAMessageStubType.GROUP_MEMBER_ADD_MODE:
727
+ const memberAddValue = message.messageStubParameters?.[0];
728
+ emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
729
+ break;
730
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
731
+ const approvalMode = message.messageStubParameters?.[0];
732
+ emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
733
+ break;
734
+ case WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD: // TODO: Add other events
735
+ const participant = JSON.parse(message.messageStubParameters?.[0]);
736
+ const action = message.messageStubParameters?.[1];
737
+ const method = message.messageStubParameters?.[2];
738
+ emitGroupRequestJoin(participant, action, method);
739
+ break;
740
+ }
741
+ }
742
+ else if (content?.pollUpdateMessage) {
743
+ const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey;
744
+ // the poll secret lives on the creation message; without it there is nothing to decrypt with
745
+ const pollMsg = creationMsgKey ? await getMessage(creationMsgKey) : undefined;
746
+ const pollEncKey = pollMsg?.messageContextInfo?.messageSecret;
747
+ if (!pollEncKey) {
748
+ logger?.debug({ creationMsgKey }, 'poll creation message or its secret not found, cannot decrypt vote');
749
+ }
750
+ else {
751
+ try {
752
+ const meIdNormalised = jidNormalizedUser(meId);
753
+ const meLidNormalised = creds.me.lid ? jidNormalizedUser(creds.me.lid) : undefined;
754
+ // voters derive the key from whichever form (PN or LID) of the creator JID they hold
755
+ const creatorPrimary = jidNormalizedUser(creationMsgKey.participant || creationMsgKey.remoteJid || '');
756
+ const creatorAlt = isLidUser(creatorPrimary)
757
+ ? await signalRepository.lidMapping.getPNForLID(creatorPrimary)
758
+ : await signalRepository.lidMapping.getLIDForPN(creatorPrimary);
759
+ const pollCreatorJids = creationMsgKey.fromMe
760
+ ? [meIdNormalised, meLidNormalised]
761
+ : [getKeyAuthor(creationMsgKey, meIdNormalised), creatorPrimary, creatorAlt ? jidNormalizedUser(creatorAlt) : undefined];
762
+ const voterJids = [
763
+ getKeyAuthor(message.key, meIdNormalised),
764
+ jidNormalizedUser(message.key.participant || message.key.remoteJid || ''),
765
+ message.key.fromMe ? meLidNormalised : undefined
766
+ ];
767
+ const vote = decryptPollVoteWithFallback(content.pollUpdateMessage.vote, {
768
+ pollEncKey,
769
+ pollCreatorJids,
770
+ voterJids,
771
+ pollMsgId: creationMsgKey.id
772
+ });
773
+ ev.emit('messages.update', [
774
+ {
775
+ key: creationMsgKey,
776
+ update: {
777
+ pollUpdates: [
778
+ {
779
+ pollUpdateMessageKey: message.key,
780
+ vote,
781
+ senderTimestampMs: toNumber(content.pollUpdateMessage.senderTimestampMs)
782
+ }
783
+ ]
784
+ }
785
+ }
786
+ ]);
787
+ }
788
+ catch (err) {
789
+ logger?.warn({ err, creationMsgKey }, 'failed to decrypt poll vote');
790
+ }
791
+ }
792
+ }
793
+ if (Object.keys(chat).length > 1) {
794
+ ev.emit('chats.update', [chat]);
795
+ }
796
+ };
797
+ export default processMessage;
798
+ //# sourceMappingURL=process-message.js.map