@lynovratech/baileys 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (787) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1312 -0
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +5479 -0
  5. package/WAProto/fix-imports.js +81 -0
  6. package/WAProto/index.d.ts +14017 -0
  7. package/WAProto/index.js +97687 -0
  8. package/engine-requirements.js +10 -0
  9. package/lib/cjs/Defaults/index.d.ts +74 -0
  10. package/lib/cjs/Defaults/index.d.ts.map +1 -0
  11. package/lib/cjs/Defaults/index.js +134 -0
  12. package/lib/cjs/Defaults/index.js.map +1 -0
  13. package/lib/cjs/Signal/Group/ciphertext-message.d.ts +10 -0
  14. package/lib/cjs/Signal/Group/ciphertext-message.d.ts.map +1 -0
  15. package/lib/cjs/Signal/Group/ciphertext-message.js +16 -0
  16. package/lib/cjs/Signal/Group/ciphertext-message.js.map +1 -0
  17. package/lib/cjs/Signal/Group/group-session-builder.d.ts +15 -0
  18. package/lib/cjs/Signal/Group/group-session-builder.d.ts.map +1 -0
  19. package/lib/cjs/Signal/Group/group-session-builder.js +65 -0
  20. package/lib/cjs/Signal/Group/group-session-builder.js.map +1 -0
  21. package/lib/cjs/Signal/Group/group_cipher.d.ts +17 -0
  22. package/lib/cjs/Signal/Group/group_cipher.d.ts.map +1 -0
  23. package/lib/cjs/Signal/Group/group_cipher.js +83 -0
  24. package/lib/cjs/Signal/Group/group_cipher.js.map +1 -0
  25. package/lib/cjs/Signal/Group/index.d.ts +12 -0
  26. package/lib/cjs/Signal/Group/index.d.ts.map +1 -0
  27. package/lib/cjs/Signal/Group/index.js +58 -0
  28. package/lib/cjs/Signal/Group/index.js.map +1 -0
  29. package/lib/cjs/Signal/Group/keyhelper.d.ts +11 -0
  30. package/lib/cjs/Signal/Group/keyhelper.d.ts.map +1 -0
  31. package/lib/cjs/Signal/Group/keyhelper.js +56 -0
  32. package/lib/cjs/Signal/Group/keyhelper.js.map +1 -0
  33. package/lib/cjs/Signal/Group/sender-chain-key.d.ts +14 -0
  34. package/lib/cjs/Signal/Group/sender-chain-key.d.ts.map +1 -0
  35. package/lib/cjs/Signal/Group/sender-chain-key.js +30 -0
  36. package/lib/cjs/Signal/Group/sender-chain-key.js.map +1 -0
  37. package/lib/cjs/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  38. package/lib/cjs/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  39. package/lib/cjs/Signal/Group/sender-key-distribution-message.js +67 -0
  40. package/lib/cjs/Signal/Group/sender-key-distribution-message.js.map +1 -0
  41. package/lib/cjs/Signal/Group/sender-key-message.d.ts +19 -0
  42. package/lib/cjs/Signal/Group/sender-key-message.d.ts.map +1 -0
  43. package/lib/cjs/Signal/Group/sender-key-message.js +70 -0
  44. package/lib/cjs/Signal/Group/sender-key-message.js.map +1 -0
  45. package/lib/cjs/Signal/Group/sender-key-name.d.ts +18 -0
  46. package/lib/cjs/Signal/Group/sender-key-name.d.ts.map +1 -0
  47. package/lib/cjs/Signal/Group/sender-key-name.js +52 -0
  48. package/lib/cjs/Signal/Group/sender-key-name.js.map +1 -0
  49. package/lib/cjs/Signal/Group/sender-key-record.d.ts +31 -0
  50. package/lib/cjs/Signal/Group/sender-key-record.d.ts.map +1 -0
  51. package/lib/cjs/Signal/Group/sender-key-record.js +45 -0
  52. package/lib/cjs/Signal/Group/sender-key-record.js.map +1 -0
  53. package/lib/cjs/Signal/Group/sender-key-state.d.ts +39 -0
  54. package/lib/cjs/Signal/Group/sender-key-state.d.ts.map +1 -0
  55. package/lib/cjs/Signal/Group/sender-key-state.js +88 -0
  56. package/lib/cjs/Signal/Group/sender-key-state.js.map +1 -0
  57. package/lib/cjs/Signal/Group/sender-message-key.d.ts +12 -0
  58. package/lib/cjs/Signal/Group/sender-message-key.d.ts.map +1 -0
  59. package/lib/cjs/Signal/Group/sender-message-key.js +30 -0
  60. package/lib/cjs/Signal/Group/sender-message-key.js.map +1 -0
  61. package/lib/cjs/Signal/jid-mapping.d.ts +50 -0
  62. package/lib/cjs/Signal/jid-mapping.d.ts.map +1 -0
  63. package/lib/cjs/Signal/jid-mapping.js +218 -0
  64. package/lib/cjs/Signal/jid-mapping.js.map +1 -0
  65. package/lib/cjs/Signal/libsignal.d.ts +7 -0
  66. package/lib/cjs/Signal/libsignal.d.ts.map +1 -0
  67. package/lib/cjs/Signal/libsignal.js +447 -0
  68. package/lib/cjs/Signal/libsignal.js.map +1 -0
  69. package/lib/cjs/Signal/lid-mapping.d.ts +6 -0
  70. package/lib/cjs/Signal/lid-mapping.d.ts.map +1 -0
  71. package/lib/cjs/Signal/lid-mapping.js +10 -0
  72. package/lib/cjs/Signal/lid-mapping.js.map +1 -0
  73. package/lib/cjs/Socket/Client/index.d.ts +3 -0
  74. package/lib/cjs/Socket/Client/index.d.ts.map +1 -0
  75. package/lib/cjs/Socket/Client/index.js +19 -0
  76. package/lib/cjs/Socket/Client/index.js.map +1 -0
  77. package/lib/cjs/Socket/Client/types.d.ts +16 -0
  78. package/lib/cjs/Socket/Client/types.d.ts.map +1 -0
  79. package/lib/cjs/Socket/Client/types.js +14 -0
  80. package/lib/cjs/Socket/Client/types.js.map +1 -0
  81. package/lib/cjs/Socket/Client/websocket.d.ts +13 -0
  82. package/lib/cjs/Socket/Client/websocket.d.ts.map +1 -0
  83. package/lib/cjs/Socket/Client/websocket.js +61 -0
  84. package/lib/cjs/Socket/Client/websocket.js.map +1 -0
  85. package/lib/cjs/Socket/business.d.ts +202 -0
  86. package/lib/cjs/Socket/business.d.ts.map +1 -0
  87. package/lib/cjs/Socket/business.js +383 -0
  88. package/lib/cjs/Socket/business.js.map +1 -0
  89. package/lib/cjs/Socket/chats.d.ts +111 -0
  90. package/lib/cjs/Socket/chats.d.ts.map +1 -0
  91. package/lib/cjs/Socket/chats.js +1006 -0
  92. package/lib/cjs/Socket/chats.js.map +1 -0
  93. package/lib/cjs/Socket/communities.d.ts +258 -0
  94. package/lib/cjs/Socket/communities.d.ts.map +1 -0
  95. package/lib/cjs/Socket/communities.js +439 -0
  96. package/lib/cjs/Socket/communities.js.map +1 -0
  97. package/lib/cjs/Socket/groups.d.ts +150 -0
  98. package/lib/cjs/Socket/groups.d.ts.map +1 -0
  99. package/lib/cjs/Socket/groups.js +335 -0
  100. package/lib/cjs/Socket/groups.js.map +1 -0
  101. package/lib/cjs/Socket/index.d.ts +245 -0
  102. package/lib/cjs/Socket/index.d.ts.map +1 -0
  103. package/lib/cjs/Socket/index.js +14 -0
  104. package/lib/cjs/Socket/index.js.map +1 -0
  105. package/lib/cjs/Socket/messages-recv.d.ts +187 -0
  106. package/lib/cjs/Socket/messages-recv.d.ts.map +1 -0
  107. package/lib/cjs/Socket/messages-recv.js +1325 -0
  108. package/lib/cjs/Socket/messages-recv.js.map +1 -0
  109. package/lib/cjs/Socket/messages-send.d.ts +183 -0
  110. package/lib/cjs/Socket/messages-send.d.ts.map +1 -0
  111. package/lib/cjs/Socket/messages-send.js +1046 -0
  112. package/lib/cjs/Socket/messages-send.js.map +1 -0
  113. package/lib/cjs/Socket/mex.d.ts +3 -0
  114. package/lib/cjs/Socket/mex.d.ts.map +1 -0
  115. package/lib/cjs/Socket/mex.js +46 -0
  116. package/lib/cjs/Socket/mex.js.map +1 -0
  117. package/lib/cjs/Socket/newsletter.d.ts +160 -0
  118. package/lib/cjs/Socket/newsletter.d.ts.map +1 -0
  119. package/lib/cjs/Socket/newsletter.js +185 -0
  120. package/lib/cjs/Socket/newsletter.js.map +1 -0
  121. package/lib/cjs/Socket/socket.d.ts +55 -0
  122. package/lib/cjs/Socket/socket.d.ts.map +1 -0
  123. package/lib/cjs/Socket/socket.js +940 -0
  124. package/lib/cjs/Socket/socket.js.map +1 -0
  125. package/lib/cjs/Types/Auth.d.ts +126 -0
  126. package/lib/cjs/Types/Auth.d.ts.map +1 -0
  127. package/lib/cjs/Types/Auth.js +3 -0
  128. package/lib/cjs/Types/Auth.js.map +1 -0
  129. package/lib/cjs/Types/Bussines.d.ts +25 -0
  130. package/lib/cjs/Types/Bussines.d.ts.map +1 -0
  131. package/lib/cjs/Types/Bussines.js +3 -0
  132. package/lib/cjs/Types/Bussines.js.map +1 -0
  133. package/lib/cjs/Types/Call.d.ts +15 -0
  134. package/lib/cjs/Types/Call.d.ts.map +1 -0
  135. package/lib/cjs/Types/Call.js +3 -0
  136. package/lib/cjs/Types/Call.js.map +1 -0
  137. package/lib/cjs/Types/Chat.d.ts +123 -0
  138. package/lib/cjs/Types/Chat.d.ts.map +1 -0
  139. package/lib/cjs/Types/Chat.js +11 -0
  140. package/lib/cjs/Types/Chat.js.map +1 -0
  141. package/lib/cjs/Types/Contact.d.ts +24 -0
  142. package/lib/cjs/Types/Contact.d.ts.map +1 -0
  143. package/lib/cjs/Types/Contact.js +3 -0
  144. package/lib/cjs/Types/Contact.js.map +1 -0
  145. package/lib/cjs/Types/Events.d.ts +241 -0
  146. package/lib/cjs/Types/Events.d.ts.map +1 -0
  147. package/lib/cjs/Types/Events.js +3 -0
  148. package/lib/cjs/Types/Events.js.map +1 -0
  149. package/lib/cjs/Types/GroupMetadata.d.ts +67 -0
  150. package/lib/cjs/Types/GroupMetadata.d.ts.map +1 -0
  151. package/lib/cjs/Types/GroupMetadata.js +3 -0
  152. package/lib/cjs/Types/GroupMetadata.js.map +1 -0
  153. package/lib/cjs/Types/Label.d.ts +47 -0
  154. package/lib/cjs/Types/Label.d.ts.map +1 -0
  155. package/lib/cjs/Types/Label.js +28 -0
  156. package/lib/cjs/Types/Label.js.map +1 -0
  157. package/lib/cjs/Types/LabelAssociation.d.ts +30 -0
  158. package/lib/cjs/Types/LabelAssociation.d.ts.map +1 -0
  159. package/lib/cjs/Types/LabelAssociation.js +10 -0
  160. package/lib/cjs/Types/LabelAssociation.js.map +1 -0
  161. package/lib/cjs/Types/Message.d.ts +310 -0
  162. package/lib/cjs/Types/Message.d.ts.map +1 -0
  163. package/lib/cjs/Types/Message.js +16 -0
  164. package/lib/cjs/Types/Message.js.map +1 -0
  165. package/lib/cjs/Types/Newsletter.d.ts +135 -0
  166. package/lib/cjs/Types/Newsletter.d.ts.map +1 -0
  167. package/lib/cjs/Types/Newsletter.js +34 -0
  168. package/lib/cjs/Types/Newsletter.js.map +1 -0
  169. package/lib/cjs/Types/Product.d.ts +79 -0
  170. package/lib/cjs/Types/Product.d.ts.map +1 -0
  171. package/lib/cjs/Types/Product.js +3 -0
  172. package/lib/cjs/Types/Product.js.map +1 -0
  173. package/lib/cjs/Types/Signal.d.ts +76 -0
  174. package/lib/cjs/Types/Signal.d.ts.map +1 -0
  175. package/lib/cjs/Types/Signal.js +3 -0
  176. package/lib/cjs/Types/Signal.js.map +1 -0
  177. package/lib/cjs/Types/Socket.d.ts +135 -0
  178. package/lib/cjs/Types/Socket.d.ts.map +1 -0
  179. package/lib/cjs/Types/Socket.js +3 -0
  180. package/lib/cjs/Types/Socket.js.map +1 -0
  181. package/lib/cjs/Types/State.d.ts +39 -0
  182. package/lib/cjs/Types/State.d.ts.map +1 -0
  183. package/lib/cjs/Types/State.js +15 -0
  184. package/lib/cjs/Types/State.js.map +1 -0
  185. package/lib/cjs/Types/USync.d.ts +26 -0
  186. package/lib/cjs/Types/USync.d.ts.map +1 -0
  187. package/lib/cjs/Types/USync.js +3 -0
  188. package/lib/cjs/Types/USync.js.map +1 -0
  189. package/lib/cjs/Types/index.d.ts +65 -0
  190. package/lib/cjs/Types/index.d.ts.map +1 -0
  191. package/lib/cjs/Types/index.js +43 -0
  192. package/lib/cjs/Types/index.js.map +1 -0
  193. package/lib/cjs/Utils/auth-utils.d.ts +19 -0
  194. package/lib/cjs/Utils/auth-utils.d.ts.map +1 -0
  195. package/lib/cjs/Utils/auth-utils.js +299 -0
  196. package/lib/cjs/Utils/auth-utils.js.map +1 -0
  197. package/lib/cjs/Utils/browser-utils.d.ts +4 -0
  198. package/lib/cjs/Utils/browser-utils.d.ts.map +1 -0
  199. package/lib/cjs/Utils/browser-utils.js +32 -0
  200. package/lib/cjs/Utils/browser-utils.js.map +1 -0
  201. package/lib/cjs/Utils/business.d.ts +23 -0
  202. package/lib/cjs/Utils/business.d.ts.map +1 -0
  203. package/lib/cjs/Utils/business.js +241 -0
  204. package/lib/cjs/Utils/business.js.map +1 -0
  205. package/lib/cjs/Utils/chat-utils.d.ts +70 -0
  206. package/lib/cjs/Utils/chat-utils.d.ts.map +1 -0
  207. package/lib/cjs/Utils/chat-utils.js +826 -0
  208. package/lib/cjs/Utils/chat-utils.js.map +1 -0
  209. package/lib/cjs/Utils/crypto.d.ts +37 -0
  210. package/lib/cjs/Utils/crypto.d.ts.map +1 -0
  211. package/lib/cjs/Utils/crypto.js +169 -0
  212. package/lib/cjs/Utils/crypto.js.map +1 -0
  213. package/lib/cjs/Utils/decode-wa-message.d.ts +48 -0
  214. package/lib/cjs/Utils/decode-wa-message.d.ts.map +1 -0
  215. package/lib/cjs/Utils/decode-wa-message.js +291 -0
  216. package/lib/cjs/Utils/decode-wa-message.js.map +1 -0
  217. package/lib/cjs/Utils/event-buffer.d.ts +34 -0
  218. package/lib/cjs/Utils/event-buffer.d.ts.map +1 -0
  219. package/lib/cjs/Utils/event-buffer.js +581 -0
  220. package/lib/cjs/Utils/event-buffer.js.map +1 -0
  221. package/lib/cjs/Utils/generics.d.ts +91 -0
  222. package/lib/cjs/Utils/generics.d.ts.map +1 -0
  223. package/lib/cjs/Utils/generics.js +416 -0
  224. package/lib/cjs/Utils/generics.js.map +1 -0
  225. package/lib/cjs/Utils/history.d.ts +22 -0
  226. package/lib/cjs/Utils/history.d.ts.map +1 -0
  227. package/lib/cjs/Utils/history.js +138 -0
  228. package/lib/cjs/Utils/history.js.map +1 -0
  229. package/lib/cjs/Utils/identity-change-handler.d.ts +38 -0
  230. package/lib/cjs/Utils/identity-change-handler.d.ts.map +1 -0
  231. package/lib/cjs/Utils/identity-change-handler.js +52 -0
  232. package/lib/cjs/Utils/identity-change-handler.js.map +1 -0
  233. package/lib/cjs/Utils/index.d.ts +21 -0
  234. package/lib/cjs/Utils/index.d.ts.map +1 -0
  235. package/lib/cjs/Utils/index.js +37 -0
  236. package/lib/cjs/Utils/index.js.map +1 -0
  237. package/lib/cjs/Utils/link-preview.d.ts +21 -0
  238. package/lib/cjs/Utils/link-preview.d.ts.map +1 -0
  239. package/lib/cjs/Utils/link-preview.js +122 -0
  240. package/lib/cjs/Utils/link-preview.js.map +1 -0
  241. package/lib/cjs/Utils/logger.d.ts +13 -0
  242. package/lib/cjs/Utils/logger.d.ts.map +1 -0
  243. package/lib/cjs/Utils/logger.js +8 -0
  244. package/lib/cjs/Utils/logger.js.map +1 -0
  245. package/lib/cjs/Utils/lt-hash.d.ts +8 -0
  246. package/lib/cjs/Utils/lt-hash.d.ts.map +1 -0
  247. package/lib/cjs/Utils/lt-hash.js +11 -0
  248. package/lib/cjs/Utils/lt-hash.js.map +1 -0
  249. package/lib/cjs/Utils/make-mutex.d.ts +9 -0
  250. package/lib/cjs/Utils/make-mutex.d.ts.map +1 -0
  251. package/lib/cjs/Utils/make-mutex.js +38 -0
  252. package/lib/cjs/Utils/make-mutex.js.map +1 -0
  253. package/lib/cjs/Utils/message-retry-manager.d.ts +110 -0
  254. package/lib/cjs/Utils/message-retry-manager.d.ts.map +1 -0
  255. package/lib/cjs/Utils/message-retry-manager.js +229 -0
  256. package/lib/cjs/Utils/message-retry-manager.js.map +1 -0
  257. package/lib/cjs/Utils/messages-media.d.ts +130 -0
  258. package/lib/cjs/Utils/messages-media.d.ts.map +1 -0
  259. package/lib/cjs/Utils/messages-media.js +835 -0
  260. package/lib/cjs/Utils/messages-media.js.map +1 -0
  261. package/lib/cjs/Utils/messages.d.ts +91 -0
  262. package/lib/cjs/Utils/messages.d.ts.map +1 -0
  263. package/lib/cjs/Utils/messages.js +902 -0
  264. package/lib/cjs/Utils/messages.js.map +1 -0
  265. package/lib/cjs/Utils/noise-handler.d.ts +20 -0
  266. package/lib/cjs/Utils/noise-handler.d.ts.map +1 -0
  267. package/lib/cjs/Utils/noise-handler.js +205 -0
  268. package/lib/cjs/Utils/noise-handler.js.map +1 -0
  269. package/lib/cjs/Utils/offline-node-processor.d.ts +17 -0
  270. package/lib/cjs/Utils/offline-node-processor.d.ts.map +1 -0
  271. package/lib/cjs/Utils/offline-node-processor.js +43 -0
  272. package/lib/cjs/Utils/offline-node-processor.js.map +1 -0
  273. package/lib/cjs/Utils/pre-key-manager.d.ts +28 -0
  274. package/lib/cjs/Utils/pre-key-manager.d.ts.map +1 -0
  275. package/lib/cjs/Utils/pre-key-manager.js +113 -0
  276. package/lib/cjs/Utils/pre-key-manager.js.map +1 -0
  277. package/lib/cjs/Utils/process-message.d.ts +60 -0
  278. package/lib/cjs/Utils/process-message.d.ts.map +1 -0
  279. package/lib/cjs/Utils/process-message.js +539 -0
  280. package/lib/cjs/Utils/process-message.js.map +1 -0
  281. package/lib/cjs/Utils/reporting-utils.d.ts +11 -0
  282. package/lib/cjs/Utils/reporting-utils.d.ts.map +1 -0
  283. package/lib/cjs/Utils/reporting-utils.js +262 -0
  284. package/lib/cjs/Utils/reporting-utils.js.map +1 -0
  285. package/lib/cjs/Utils/signal.d.ts +34 -0
  286. package/lib/cjs/Utils/signal.d.ts.map +1 -0
  287. package/lib/cjs/Utils/signal.js +171 -0
  288. package/lib/cjs/Utils/signal.js.map +1 -0
  289. package/lib/cjs/Utils/stanza-ack.d.ts +11 -0
  290. package/lib/cjs/Utils/stanza-ack.d.ts.map +1 -0
  291. package/lib/cjs/Utils/stanza-ack.js +41 -0
  292. package/lib/cjs/Utils/stanza-ack.js.map +1 -0
  293. package/lib/cjs/Utils/sync-action-utils.d.ts +19 -0
  294. package/lib/cjs/Utils/sync-action-utils.d.ts.map +1 -0
  295. package/lib/cjs/Utils/sync-action-utils.js +52 -0
  296. package/lib/cjs/Utils/sync-action-utils.js.map +1 -0
  297. package/lib/cjs/Utils/tc-token-utils.d.ts +12 -0
  298. package/lib/cjs/Utils/tc-token-utils.d.ts.map +1 -0
  299. package/lib/cjs/Utils/tc-token-utils.js +21 -0
  300. package/lib/cjs/Utils/tc-token-utils.js.map +1 -0
  301. package/lib/cjs/Utils/use-multi-file-auth-state.d.ts +13 -0
  302. package/lib/cjs/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  303. package/lib/cjs/Utils/use-multi-file-auth-state.js +125 -0
  304. package/lib/cjs/Utils/use-multi-file-auth-state.js.map +1 -0
  305. package/lib/cjs/Utils/validate-connection.d.ts +11 -0
  306. package/lib/cjs/Utils/validate-connection.d.ts.map +1 -0
  307. package/lib/cjs/Utils/validate-connection.js +209 -0
  308. package/lib/cjs/Utils/validate-connection.js.map +1 -0
  309. package/lib/cjs/WABinary/constants.d.ts +28 -0
  310. package/lib/cjs/WABinary/constants.d.ts.map +1 -0
  311. package/lib/cjs/WABinary/constants.js +1304 -0
  312. package/lib/cjs/WABinary/constants.js.map +1 -0
  313. package/lib/cjs/WABinary/decode.d.ts +7 -0
  314. package/lib/cjs/WABinary/decode.d.ts.map +1 -0
  315. package/lib/cjs/WABinary/decode.js +301 -0
  316. package/lib/cjs/WABinary/decode.js.map +1 -0
  317. package/lib/cjs/WABinary/encode.d.ts +3 -0
  318. package/lib/cjs/WABinary/encode.d.ts.map +1 -0
  319. package/lib/cjs/WABinary/encode.js +257 -0
  320. package/lib/cjs/WABinary/encode.js.map +1 -0
  321. package/lib/cjs/WABinary/generic-utils.d.ts +15 -0
  322. package/lib/cjs/WABinary/generic-utils.d.ts.map +1 -0
  323. package/lib/cjs/WABinary/generic-utils.js +125 -0
  324. package/lib/cjs/WABinary/generic-utils.js.map +1 -0
  325. package/lib/cjs/WABinary/index.d.ts +6 -0
  326. package/lib/cjs/WABinary/index.d.ts.map +1 -0
  327. package/lib/cjs/WABinary/index.js +22 -0
  328. package/lib/cjs/WABinary/index.js.map +1 -0
  329. package/lib/cjs/WABinary/jid-utils.d.ts +48 -0
  330. package/lib/cjs/WABinary/jid-utils.d.ts.map +1 -0
  331. package/lib/cjs/WABinary/jid-utils.js +115 -0
  332. package/lib/cjs/WABinary/jid-utils.js.map +1 -0
  333. package/lib/cjs/WABinary/types.d.ts +19 -0
  334. package/lib/cjs/WABinary/types.d.ts.map +1 -0
  335. package/lib/cjs/WABinary/types.js +3 -0
  336. package/lib/cjs/WABinary/types.js.map +1 -0
  337. package/lib/cjs/WAM/BinaryInfo.d.ts +9 -0
  338. package/lib/cjs/WAM/BinaryInfo.d.ts.map +1 -0
  339. package/lib/cjs/WAM/BinaryInfo.js +14 -0
  340. package/lib/cjs/WAM/BinaryInfo.js.map +1 -0
  341. package/lib/cjs/WAM/constants.d.ts +40 -0
  342. package/lib/cjs/WAM/constants.d.ts.map +1 -0
  343. package/lib/cjs/WAM/constants.js +22856 -0
  344. package/lib/cjs/WAM/constants.js.map +1 -0
  345. package/lib/cjs/WAM/encode.d.ts +3 -0
  346. package/lib/cjs/WAM/encode.d.ts.map +1 -0
  347. package/lib/cjs/WAM/encode.js +153 -0
  348. package/lib/cjs/WAM/encode.js.map +1 -0
  349. package/lib/cjs/WAM/index.d.ts +4 -0
  350. package/lib/cjs/WAM/index.d.ts.map +1 -0
  351. package/lib/cjs/WAM/index.js +20 -0
  352. package/lib/cjs/WAM/index.js.map +1 -0
  353. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  354. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  355. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  356. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  357. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  358. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  359. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.js +58 -0
  360. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  361. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  362. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  363. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  364. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  365. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  366. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  367. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  368. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  369. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  370. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  371. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.js +54 -0
  372. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  373. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.d.ts +17 -0
  374. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  375. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.js +33 -0
  376. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  377. package/lib/cjs/WAUSync/Protocols/index.d.ts +5 -0
  378. package/lib/cjs/WAUSync/Protocols/index.d.ts.map +1 -0
  379. package/lib/cjs/WAUSync/Protocols/index.js +21 -0
  380. package/lib/cjs/WAUSync/Protocols/index.js.map +1 -0
  381. package/lib/cjs/WAUSync/USyncQuery.d.ts +29 -0
  382. package/lib/cjs/WAUSync/USyncQuery.d.ts.map +1 -0
  383. package/lib/cjs/WAUSync/USyncQuery.js +97 -0
  384. package/lib/cjs/WAUSync/USyncQuery.js.map +1 -0
  385. package/lib/cjs/WAUSync/USyncUser.d.ts +13 -0
  386. package/lib/cjs/WAUSync/USyncUser.d.ts.map +1 -0
  387. package/lib/cjs/WAUSync/USyncUser.js +27 -0
  388. package/lib/cjs/WAUSync/USyncUser.js.map +1 -0
  389. package/lib/cjs/WAUSync/index.d.ts +4 -0
  390. package/lib/cjs/WAUSync/index.d.ts.map +1 -0
  391. package/lib/cjs/WAUSync/index.js +20 -0
  392. package/lib/cjs/WAUSync/index.js.map +1 -0
  393. package/lib/cjs/index.d.ts +12 -0
  394. package/lib/cjs/index.d.ts.map +1 -0
  395. package/lib/cjs/index.js +31 -0
  396. package/lib/cjs/index.js.map +1 -0
  397. package/lib/cjs/package.json +3 -0
  398. package/lib/esm/Defaults/index.d.ts +74 -0
  399. package/lib/esm/Defaults/index.d.ts.map +1 -0
  400. package/lib/esm/Defaults/index.js +128 -0
  401. package/lib/esm/Defaults/index.js.map +1 -0
  402. package/lib/esm/Signal/Group/ciphertext-message.d.ts +10 -0
  403. package/lib/esm/Signal/Group/ciphertext-message.d.ts.map +1 -0
  404. package/lib/esm/Signal/Group/ciphertext-message.js +12 -0
  405. package/lib/esm/Signal/Group/ciphertext-message.js.map +1 -0
  406. package/lib/esm/Signal/Group/group-session-builder.d.ts +15 -0
  407. package/lib/esm/Signal/Group/group-session-builder.d.ts.map +1 -0
  408. package/lib/esm/Signal/Group/group-session-builder.js +30 -0
  409. package/lib/esm/Signal/Group/group-session-builder.js.map +1 -0
  410. package/lib/esm/Signal/Group/group_cipher.d.ts +17 -0
  411. package/lib/esm/Signal/Group/group_cipher.d.ts.map +1 -0
  412. package/lib/esm/Signal/Group/group_cipher.js +82 -0
  413. package/lib/esm/Signal/Group/group_cipher.js.map +1 -0
  414. package/lib/esm/Signal/Group/index.d.ts +12 -0
  415. package/lib/esm/Signal/Group/index.d.ts.map +1 -0
  416. package/lib/esm/Signal/Group/index.js +12 -0
  417. package/lib/esm/Signal/Group/index.js.map +1 -0
  418. package/lib/esm/Signal/Group/keyhelper.d.ts +11 -0
  419. package/lib/esm/Signal/Group/keyhelper.d.ts.map +1 -0
  420. package/lib/esm/Signal/Group/keyhelper.js +18 -0
  421. package/lib/esm/Signal/Group/keyhelper.js.map +1 -0
  422. package/lib/esm/Signal/Group/sender-chain-key.d.ts +14 -0
  423. package/lib/esm/Signal/Group/sender-chain-key.d.ts.map +1 -0
  424. package/lib/esm/Signal/Group/sender-chain-key.js +26 -0
  425. package/lib/esm/Signal/Group/sender-chain-key.js.map +1 -0
  426. package/lib/esm/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  427. package/lib/esm/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  428. package/lib/esm/Signal/Group/sender-key-distribution-message.js +63 -0
  429. package/lib/esm/Signal/Group/sender-key-distribution-message.js.map +1 -0
  430. package/lib/esm/Signal/Group/sender-key-message.d.ts +19 -0
  431. package/lib/esm/Signal/Group/sender-key-message.d.ts.map +1 -0
  432. package/lib/esm/Signal/Group/sender-key-message.js +66 -0
  433. package/lib/esm/Signal/Group/sender-key-message.js.map +1 -0
  434. package/lib/esm/Signal/Group/sender-key-name.d.ts +18 -0
  435. package/lib/esm/Signal/Group/sender-key-name.d.ts.map +1 -0
  436. package/lib/esm/Signal/Group/sender-key-name.js +48 -0
  437. package/lib/esm/Signal/Group/sender-key-name.js.map +1 -0
  438. package/lib/esm/Signal/Group/sender-key-record.d.ts +31 -0
  439. package/lib/esm/Signal/Group/sender-key-record.d.ts.map +1 -0
  440. package/lib/esm/Signal/Group/sender-key-record.js +41 -0
  441. package/lib/esm/Signal/Group/sender-key-record.js.map +1 -0
  442. package/lib/esm/Signal/Group/sender-key-state.d.ts +39 -0
  443. package/lib/esm/Signal/Group/sender-key-state.d.ts.map +1 -0
  444. package/lib/esm/Signal/Group/sender-key-state.js +84 -0
  445. package/lib/esm/Signal/Group/sender-key-state.js.map +1 -0
  446. package/lib/esm/Signal/Group/sender-message-key.d.ts +12 -0
  447. package/lib/esm/Signal/Group/sender-message-key.d.ts.map +1 -0
  448. package/lib/esm/Signal/Group/sender-message-key.js +26 -0
  449. package/lib/esm/Signal/Group/sender-message-key.js.map +1 -0
  450. package/lib/esm/Signal/jid-mapping.d.ts +50 -0
  451. package/lib/esm/Signal/jid-mapping.d.ts.map +1 -0
  452. package/lib/esm/Signal/jid-mapping.js +214 -0
  453. package/lib/esm/Signal/jid-mapping.js.map +1 -0
  454. package/lib/esm/Signal/libsignal.d.ts +7 -0
  455. package/lib/esm/Signal/libsignal.d.ts.map +1 -0
  456. package/lib/esm/Signal/libsignal.js +413 -0
  457. package/lib/esm/Signal/libsignal.js.map +1 -0
  458. package/lib/esm/Signal/lid-mapping.d.ts +6 -0
  459. package/lib/esm/Signal/lid-mapping.d.ts.map +1 -0
  460. package/lib/esm/Signal/lid-mapping.js +6 -0
  461. package/lib/esm/Signal/lid-mapping.js.map +1 -0
  462. package/lib/esm/Socket/Client/index.d.ts +3 -0
  463. package/lib/esm/Socket/Client/index.d.ts.map +1 -0
  464. package/lib/esm/Socket/Client/index.js +3 -0
  465. package/lib/esm/Socket/Client/index.js.map +1 -0
  466. package/lib/esm/Socket/Client/types.d.ts +16 -0
  467. package/lib/esm/Socket/Client/types.d.ts.map +1 -0
  468. package/lib/esm/Socket/Client/types.js +11 -0
  469. package/lib/esm/Socket/Client/types.js.map +1 -0
  470. package/lib/esm/Socket/Client/websocket.d.ts +13 -0
  471. package/lib/esm/Socket/Client/websocket.d.ts.map +1 -0
  472. package/lib/esm/Socket/Client/websocket.js +54 -0
  473. package/lib/esm/Socket/Client/websocket.js.map +1 -0
  474. package/lib/esm/Socket/business.d.ts +202 -0
  475. package/lib/esm/Socket/business.d.ts.map +1 -0
  476. package/lib/esm/Socket/business.js +379 -0
  477. package/lib/esm/Socket/business.js.map +1 -0
  478. package/lib/esm/Socket/chats.d.ts +111 -0
  479. package/lib/esm/Socket/chats.d.ts.map +1 -0
  480. package/lib/esm/Socket/chats.js +999 -0
  481. package/lib/esm/Socket/chats.js.map +1 -0
  482. package/lib/esm/Socket/communities.d.ts +258 -0
  483. package/lib/esm/Socket/communities.d.ts.map +1 -0
  484. package/lib/esm/Socket/communities.js +431 -0
  485. package/lib/esm/Socket/communities.js.map +1 -0
  486. package/lib/esm/Socket/groups.d.ts +150 -0
  487. package/lib/esm/Socket/groups.d.ts.map +1 -0
  488. package/lib/esm/Socket/groups.js +330 -0
  489. package/lib/esm/Socket/groups.js.map +1 -0
  490. package/lib/esm/Socket/index.d.ts +245 -0
  491. package/lib/esm/Socket/index.d.ts.map +1 -0
  492. package/lib/esm/Socket/index.js +12 -0
  493. package/lib/esm/Socket/index.js.map +1 -0
  494. package/lib/esm/Socket/messages-recv.d.ts +187 -0
  495. package/lib/esm/Socket/messages-recv.d.ts.map +1 -0
  496. package/lib/esm/Socket/messages-recv.js +1319 -0
  497. package/lib/esm/Socket/messages-recv.js.map +1 -0
  498. package/lib/esm/Socket/messages-send.d.ts +183 -0
  499. package/lib/esm/Socket/messages-send.d.ts.map +1 -0
  500. package/lib/esm/Socket/messages-send.js +1039 -0
  501. package/lib/esm/Socket/messages-send.js.map +1 -0
  502. package/lib/esm/Socket/mex.d.ts +3 -0
  503. package/lib/esm/Socket/mex.d.ts.map +1 -0
  504. package/lib/esm/Socket/mex.js +42 -0
  505. package/lib/esm/Socket/mex.js.map +1 -0
  506. package/lib/esm/Socket/newsletter.d.ts +160 -0
  507. package/lib/esm/Socket/newsletter.d.ts.map +1 -0
  508. package/lib/esm/Socket/newsletter.js +181 -0
  509. package/lib/esm/Socket/newsletter.js.map +1 -0
  510. package/lib/esm/Socket/socket.d.ts +55 -0
  511. package/lib/esm/Socket/socket.d.ts.map +1 -0
  512. package/lib/esm/Socket/socket.js +936 -0
  513. package/lib/esm/Socket/socket.js.map +1 -0
  514. package/lib/esm/Types/Auth.d.ts +126 -0
  515. package/lib/esm/Types/Auth.d.ts.map +1 -0
  516. package/lib/esm/Types/Auth.js +2 -0
  517. package/lib/esm/Types/Auth.js.map +1 -0
  518. package/lib/esm/Types/Bussines.d.ts +25 -0
  519. package/lib/esm/Types/Bussines.d.ts.map +1 -0
  520. package/lib/esm/Types/Bussines.js +2 -0
  521. package/lib/esm/Types/Bussines.js.map +1 -0
  522. package/lib/esm/Types/Call.d.ts +15 -0
  523. package/lib/esm/Types/Call.d.ts.map +1 -0
  524. package/lib/esm/Types/Call.js +2 -0
  525. package/lib/esm/Types/Call.js.map +1 -0
  526. package/lib/esm/Types/Chat.d.ts +123 -0
  527. package/lib/esm/Types/Chat.d.ts.map +1 -0
  528. package/lib/esm/Types/Chat.js +8 -0
  529. package/lib/esm/Types/Chat.js.map +1 -0
  530. package/lib/esm/Types/Contact.d.ts +24 -0
  531. package/lib/esm/Types/Contact.d.ts.map +1 -0
  532. package/lib/esm/Types/Contact.js +2 -0
  533. package/lib/esm/Types/Contact.js.map +1 -0
  534. package/lib/esm/Types/Events.d.ts +241 -0
  535. package/lib/esm/Types/Events.d.ts.map +1 -0
  536. package/lib/esm/Types/Events.js +2 -0
  537. package/lib/esm/Types/Events.js.map +1 -0
  538. package/lib/esm/Types/GroupMetadata.d.ts +67 -0
  539. package/lib/esm/Types/GroupMetadata.d.ts.map +1 -0
  540. package/lib/esm/Types/GroupMetadata.js +2 -0
  541. package/lib/esm/Types/GroupMetadata.js.map +1 -0
  542. package/lib/esm/Types/Label.d.ts +47 -0
  543. package/lib/esm/Types/Label.d.ts.map +1 -0
  544. package/lib/esm/Types/Label.js +25 -0
  545. package/lib/esm/Types/Label.js.map +1 -0
  546. package/lib/esm/Types/LabelAssociation.d.ts +30 -0
  547. package/lib/esm/Types/LabelAssociation.d.ts.map +1 -0
  548. package/lib/esm/Types/LabelAssociation.js +7 -0
  549. package/lib/esm/Types/LabelAssociation.js.map +1 -0
  550. package/lib/esm/Types/Message.d.ts +310 -0
  551. package/lib/esm/Types/Message.d.ts.map +1 -0
  552. package/lib/esm/Types/Message.js +14 -0
  553. package/lib/esm/Types/Message.js.map +1 -0
  554. package/lib/esm/Types/Newsletter.d.ts +135 -0
  555. package/lib/esm/Types/Newsletter.d.ts.map +1 -0
  556. package/lib/esm/Types/Newsletter.js +31 -0
  557. package/lib/esm/Types/Newsletter.js.map +1 -0
  558. package/lib/esm/Types/Product.d.ts +79 -0
  559. package/lib/esm/Types/Product.d.ts.map +1 -0
  560. package/lib/esm/Types/Product.js +2 -0
  561. package/lib/esm/Types/Product.js.map +1 -0
  562. package/lib/esm/Types/Signal.d.ts +76 -0
  563. package/lib/esm/Types/Signal.d.ts.map +1 -0
  564. package/lib/esm/Types/Signal.js +2 -0
  565. package/lib/esm/Types/Signal.js.map +1 -0
  566. package/lib/esm/Types/Socket.d.ts +135 -0
  567. package/lib/esm/Types/Socket.d.ts.map +1 -0
  568. package/lib/esm/Types/Socket.js +3 -0
  569. package/lib/esm/Types/Socket.js.map +1 -0
  570. package/lib/esm/Types/State.d.ts +39 -0
  571. package/lib/esm/Types/State.d.ts.map +1 -0
  572. package/lib/esm/Types/State.js +13 -0
  573. package/lib/esm/Types/State.js.map +1 -0
  574. package/lib/esm/Types/USync.d.ts +26 -0
  575. package/lib/esm/Types/USync.d.ts.map +1 -0
  576. package/lib/esm/Types/USync.js +2 -0
  577. package/lib/esm/Types/USync.js.map +1 -0
  578. package/lib/esm/Types/index.d.ts +65 -0
  579. package/lib/esm/Types/index.d.ts.map +1 -0
  580. package/lib/esm/Types/index.js +26 -0
  581. package/lib/esm/Types/index.js.map +1 -0
  582. package/lib/esm/Utils/auth-utils.d.ts +19 -0
  583. package/lib/esm/Utils/auth-utils.d.ts.map +1 -0
  584. package/lib/esm/Utils/auth-utils.js +290 -0
  585. package/lib/esm/Utils/auth-utils.js.map +1 -0
  586. package/lib/esm/Utils/browser-utils.d.ts +4 -0
  587. package/lib/esm/Utils/browser-utils.d.ts.map +1 -0
  588. package/lib/esm/Utils/browser-utils.js +28 -0
  589. package/lib/esm/Utils/browser-utils.js.map +1 -0
  590. package/lib/esm/Utils/business.d.ts +23 -0
  591. package/lib/esm/Utils/business.d.ts.map +1 -0
  592. package/lib/esm/Utils/business.js +231 -0
  593. package/lib/esm/Utils/business.js.map +1 -0
  594. package/lib/esm/Utils/chat-utils.d.ts +70 -0
  595. package/lib/esm/Utils/chat-utils.d.ts.map +1 -0
  596. package/lib/esm/Utils/chat-utils.js +812 -0
  597. package/lib/esm/Utils/chat-utils.js.map +1 -0
  598. package/lib/esm/Utils/crypto.d.ts +37 -0
  599. package/lib/esm/Utils/crypto.d.ts.map +1 -0
  600. package/lib/esm/Utils/crypto.js +118 -0
  601. package/lib/esm/Utils/crypto.js.map +1 -0
  602. package/lib/esm/Utils/decode-wa-message.d.ts +48 -0
  603. package/lib/esm/Utils/decode-wa-message.d.ts.map +1 -0
  604. package/lib/esm/Utils/decode-wa-message.js +286 -0
  605. package/lib/esm/Utils/decode-wa-message.js.map +1 -0
  606. package/lib/esm/Utils/event-buffer.d.ts +34 -0
  607. package/lib/esm/Utils/event-buffer.d.ts.map +1 -0
  608. package/lib/esm/Utils/event-buffer.js +574 -0
  609. package/lib/esm/Utils/event-buffer.js.map +1 -0
  610. package/lib/esm/Utils/generics.d.ts +91 -0
  611. package/lib/esm/Utils/generics.d.ts.map +1 -0
  612. package/lib/esm/Utils/generics.js +384 -0
  613. package/lib/esm/Utils/generics.js.map +1 -0
  614. package/lib/esm/Utils/history.d.ts +22 -0
  615. package/lib/esm/Utils/history.d.ts.map +1 -0
  616. package/lib/esm/Utils/history.js +131 -0
  617. package/lib/esm/Utils/history.js.map +1 -0
  618. package/lib/esm/Utils/identity-change-handler.d.ts +38 -0
  619. package/lib/esm/Utils/identity-change-handler.d.ts.map +1 -0
  620. package/lib/esm/Utils/identity-change-handler.js +50 -0
  621. package/lib/esm/Utils/identity-change-handler.js.map +1 -0
  622. package/lib/esm/Utils/index.d.ts +21 -0
  623. package/lib/esm/Utils/index.d.ts.map +1 -0
  624. package/lib/esm/Utils/index.js +21 -0
  625. package/lib/esm/Utils/index.js.map +1 -0
  626. package/lib/esm/Utils/link-preview.d.ts +21 -0
  627. package/lib/esm/Utils/link-preview.d.ts.map +1 -0
  628. package/lib/esm/Utils/link-preview.js +85 -0
  629. package/lib/esm/Utils/link-preview.js.map +1 -0
  630. package/lib/esm/Utils/logger.d.ts +13 -0
  631. package/lib/esm/Utils/logger.d.ts.map +1 -0
  632. package/lib/esm/Utils/logger.js +3 -0
  633. package/lib/esm/Utils/logger.js.map +1 -0
  634. package/lib/esm/Utils/lt-hash.d.ts +8 -0
  635. package/lib/esm/Utils/lt-hash.d.ts.map +1 -0
  636. package/lib/esm/Utils/lt-hash.js +8 -0
  637. package/lib/esm/Utils/lt-hash.js.map +1 -0
  638. package/lib/esm/Utils/make-mutex.d.ts +9 -0
  639. package/lib/esm/Utils/make-mutex.d.ts.map +1 -0
  640. package/lib/esm/Utils/make-mutex.js +33 -0
  641. package/lib/esm/Utils/make-mutex.js.map +1 -0
  642. package/lib/esm/Utils/message-retry-manager.d.ts +110 -0
  643. package/lib/esm/Utils/message-retry-manager.d.ts.map +1 -0
  644. package/lib/esm/Utils/message-retry-manager.js +225 -0
  645. package/lib/esm/Utils/message-retry-manager.js.map +1 -0
  646. package/lib/esm/Utils/messages-media.d.ts +130 -0
  647. package/lib/esm/Utils/messages-media.d.ts.map +1 -0
  648. package/lib/esm/Utils/messages-media.js +774 -0
  649. package/lib/esm/Utils/messages-media.js.map +1 -0
  650. package/lib/esm/Utils/messages.d.ts +91 -0
  651. package/lib/esm/Utils/messages.d.ts.map +1 -0
  652. package/lib/esm/Utils/messages.js +878 -0
  653. package/lib/esm/Utils/messages.js.map +1 -0
  654. package/lib/esm/Utils/noise-handler.d.ts +20 -0
  655. package/lib/esm/Utils/noise-handler.d.ts.map +1 -0
  656. package/lib/esm/Utils/noise-handler.js +201 -0
  657. package/lib/esm/Utils/noise-handler.js.map +1 -0
  658. package/lib/esm/Utils/offline-node-processor.d.ts +17 -0
  659. package/lib/esm/Utils/offline-node-processor.d.ts.map +1 -0
  660. package/lib/esm/Utils/offline-node-processor.js +40 -0
  661. package/lib/esm/Utils/offline-node-processor.js.map +1 -0
  662. package/lib/esm/Utils/pre-key-manager.d.ts +28 -0
  663. package/lib/esm/Utils/pre-key-manager.d.ts.map +1 -0
  664. package/lib/esm/Utils/pre-key-manager.js +106 -0
  665. package/lib/esm/Utils/pre-key-manager.js.map +1 -0
  666. package/lib/esm/Utils/process-message.d.ts +60 -0
  667. package/lib/esm/Utils/process-message.d.ts.map +1 -0
  668. package/lib/esm/Utils/process-message.js +530 -0
  669. package/lib/esm/Utils/process-message.js.map +1 -0
  670. package/lib/esm/Utils/reporting-utils.d.ts +11 -0
  671. package/lib/esm/Utils/reporting-utils.d.ts.map +1 -0
  672. package/lib/esm/Utils/reporting-utils.js +258 -0
  673. package/lib/esm/Utils/reporting-utils.js.map +1 -0
  674. package/lib/esm/Utils/signal.d.ts +34 -0
  675. package/lib/esm/Utils/signal.d.ts.map +1 -0
  676. package/lib/esm/Utils/signal.js +159 -0
  677. package/lib/esm/Utils/signal.js.map +1 -0
  678. package/lib/esm/Utils/stanza-ack.d.ts +11 -0
  679. package/lib/esm/Utils/stanza-ack.d.ts.map +1 -0
  680. package/lib/esm/Utils/stanza-ack.js +38 -0
  681. package/lib/esm/Utils/stanza-ack.js.map +1 -0
  682. package/lib/esm/Utils/sync-action-utils.d.ts +19 -0
  683. package/lib/esm/Utils/sync-action-utils.d.ts.map +1 -0
  684. package/lib/esm/Utils/sync-action-utils.js +48 -0
  685. package/lib/esm/Utils/sync-action-utils.js.map +1 -0
  686. package/lib/esm/Utils/tc-token-utils.d.ts +12 -0
  687. package/lib/esm/Utils/tc-token-utils.d.ts.map +1 -0
  688. package/lib/esm/Utils/tc-token-utils.js +18 -0
  689. package/lib/esm/Utils/tc-token-utils.js.map +1 -0
  690. package/lib/esm/Utils/use-multi-file-auth-state.d.ts +13 -0
  691. package/lib/esm/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  692. package/lib/esm/Utils/use-multi-file-auth-state.js +121 -0
  693. package/lib/esm/Utils/use-multi-file-auth-state.js.map +1 -0
  694. package/lib/esm/Utils/validate-connection.d.ts +11 -0
  695. package/lib/esm/Utils/validate-connection.d.ts.map +1 -0
  696. package/lib/esm/Utils/validate-connection.js +202 -0
  697. package/lib/esm/Utils/validate-connection.js.map +1 -0
  698. package/lib/esm/WABinary/constants.d.ts +28 -0
  699. package/lib/esm/WABinary/constants.d.ts.map +1 -0
  700. package/lib/esm/WABinary/constants.js +1301 -0
  701. package/lib/esm/WABinary/constants.js.map +1 -0
  702. package/lib/esm/WABinary/decode.d.ts +7 -0
  703. package/lib/esm/WABinary/decode.d.ts.map +1 -0
  704. package/lib/esm/WABinary/decode.js +262 -0
  705. package/lib/esm/WABinary/decode.js.map +1 -0
  706. package/lib/esm/WABinary/encode.d.ts +3 -0
  707. package/lib/esm/WABinary/encode.d.ts.map +1 -0
  708. package/lib/esm/WABinary/encode.js +220 -0
  709. package/lib/esm/WABinary/encode.js.map +1 -0
  710. package/lib/esm/WABinary/generic-utils.d.ts +15 -0
  711. package/lib/esm/WABinary/generic-utils.d.ts.map +1 -0
  712. package/lib/esm/WABinary/generic-utils.js +113 -0
  713. package/lib/esm/WABinary/generic-utils.js.map +1 -0
  714. package/lib/esm/WABinary/index.d.ts +6 -0
  715. package/lib/esm/WABinary/index.d.ts.map +1 -0
  716. package/lib/esm/WABinary/index.js +6 -0
  717. package/lib/esm/WABinary/index.js.map +1 -0
  718. package/lib/esm/WABinary/jid-utils.d.ts +48 -0
  719. package/lib/esm/WABinary/jid-utils.d.ts.map +1 -0
  720. package/lib/esm/WABinary/jid-utils.js +96 -0
  721. package/lib/esm/WABinary/jid-utils.js.map +1 -0
  722. package/lib/esm/WABinary/types.d.ts +19 -0
  723. package/lib/esm/WABinary/types.d.ts.map +1 -0
  724. package/lib/esm/WABinary/types.js +2 -0
  725. package/lib/esm/WABinary/types.js.map +1 -0
  726. package/lib/esm/WAM/BinaryInfo.d.ts +9 -0
  727. package/lib/esm/WAM/BinaryInfo.d.ts.map +1 -0
  728. package/lib/esm/WAM/BinaryInfo.js +10 -0
  729. package/lib/esm/WAM/BinaryInfo.js.map +1 -0
  730. package/lib/esm/WAM/constants.d.ts +40 -0
  731. package/lib/esm/WAM/constants.d.ts.map +1 -0
  732. package/lib/esm/WAM/constants.js +22853 -0
  733. package/lib/esm/WAM/constants.js.map +1 -0
  734. package/lib/esm/WAM/encode.d.ts +3 -0
  735. package/lib/esm/WAM/encode.d.ts.map +1 -0
  736. package/lib/esm/WAM/encode.js +150 -0
  737. package/lib/esm/WAM/encode.js.map +1 -0
  738. package/lib/esm/WAM/index.d.ts +4 -0
  739. package/lib/esm/WAM/index.d.ts.map +1 -0
  740. package/lib/esm/WAM/index.js +4 -0
  741. package/lib/esm/WAM/index.js.map +1 -0
  742. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  743. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  744. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.js +29 -0
  745. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  746. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  747. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  748. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  749. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  750. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  751. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  752. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  753. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  754. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  755. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  756. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  757. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  758. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  759. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  760. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  761. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  762. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.d.ts +17 -0
  763. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  764. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  765. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  766. package/lib/esm/WAUSync/Protocols/index.d.ts +5 -0
  767. package/lib/esm/WAUSync/Protocols/index.d.ts.map +1 -0
  768. package/lib/esm/WAUSync/Protocols/index.js +5 -0
  769. package/lib/esm/WAUSync/Protocols/index.js.map +1 -0
  770. package/lib/esm/WAUSync/USyncQuery.d.ts +29 -0
  771. package/lib/esm/WAUSync/USyncQuery.d.ts.map +1 -0
  772. package/lib/esm/WAUSync/USyncQuery.js +94 -0
  773. package/lib/esm/WAUSync/USyncQuery.js.map +1 -0
  774. package/lib/esm/WAUSync/USyncUser.d.ts +13 -0
  775. package/lib/esm/WAUSync/USyncUser.d.ts.map +1 -0
  776. package/lib/esm/WAUSync/USyncUser.js +23 -0
  777. package/lib/esm/WAUSync/USyncUser.js.map +1 -0
  778. package/lib/esm/WAUSync/index.d.ts +4 -0
  779. package/lib/esm/WAUSync/index.d.ts.map +1 -0
  780. package/lib/esm/WAUSync/index.js +4 -0
  781. package/lib/esm/WAUSync/index.js.map +1 -0
  782. package/lib/esm/index.d.ts +12 -0
  783. package/lib/esm/index.d.ts.map +1 -0
  784. package/lib/esm/index.js +11 -0
  785. package/lib/esm/index.js.map +1 -0
  786. package/lib/esm/package.json +3 -0
  787. package/package.json +129 -0
@@ -0,0 +1,1319 @@
1
+ import NodeCache from '@cacheable/node-cache';
2
+ import { Boom } from '@hapi/boom';
3
+ import { randomBytes } from 'crypto';
4
+ import Long from 'long';
5
+ import { proto } from '../../WAProto/index.js';
6
+ import { DEFAULT_CACHE_TTLS, KEY_BUNDLE_TYPE, MIN_PREKEY_COUNT, PLACEHOLDER_MAX_AGE_SECONDS, STATUS_EXPIRY_SECONDS } from '../Defaults/index.js';
7
+ import { WAMessageStatus, WAMessageStubType } from '../Types/index.js';
8
+ import { aesDecryptCTR, aesEncryptGCM, cleanMessage, Curve, decodeMediaRetryNode, decodeMessageNode, decryptMessageNode, delay, derivePairingCodeKey, encodeBigEndian, encodeSignedDeviceIdentity, extractAddressingContext, getCallStatusFromNode, getHistoryMsg, getNextPreKeys, getStatusFromReceiptType, handleIdentityChange, hkdf, MISSING_KEYS_ERROR_TEXT, NACK_REASONS, NO_MESSAGE_FOUND_ERROR_TEXT, toNumber, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils/index.js';
9
+ import { makeMutex } from '../Utils/make-mutex.js';
10
+ import { makeOfflineNodeProcessor } from '../Utils/offline-node-processor.js';
11
+ import { buildAckStanza } from '../Utils/stanza-ack.js';
12
+ import { areJidsSameUser, binaryNodeToString, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildString, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser, jidDecode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
13
+ import { extractGroupMetadata } from './groups.js';
14
+ import { makeMessagesSocket } from './messages-send.js';
15
+ export const makeMessagesRecvSocket = (config) => {
16
+ const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid, enableAutoSessionRecreation } = config;
17
+ const sock = makeMessagesSocket(config);
18
+ const { ev, authState, ws, messageMutex, notificationMutex, receiptMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, messageRetryManager } = sock;
19
+ /** this mutex ensures that each retryRequest will wait for the previous one to finish */
20
+ const retryMutex = makeMutex();
21
+ const msgRetryCache = config.msgRetryCounterCache ||
22
+ new NodeCache({
23
+ stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
24
+ useClones: false
25
+ });
26
+ const callOfferCache = config.callOfferCache ||
27
+ new NodeCache({
28
+ stdTTL: DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
29
+ useClones: false
30
+ });
31
+ const placeholderResendCache = config.placeholderResendCache ||
32
+ new NodeCache({
33
+ stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
34
+ useClones: false
35
+ });
36
+ // Debounce identity-change session refreshes per JID to avoid bursts
37
+ const identityAssertDebounce = new NodeCache({ stdTTL: 5, useClones: false });
38
+ let sendActiveReceipts = false;
39
+ const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
40
+ if (!authState.creds.me?.id) {
41
+ throw new Boom('Not authenticated');
42
+ }
43
+ const pdoMessage = {
44
+ historySyncOnDemandRequest: {
45
+ chatJid: oldestMsgKey.remoteJid,
46
+ oldestMsgFromMe: oldestMsgKey.fromMe,
47
+ oldestMsgId: oldestMsgKey.id,
48
+ oldestMsgTimestampMs: oldestMsgTimestamp,
49
+ onDemandMsgCount: count
50
+ },
51
+ peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
52
+ };
53
+ return sendPeerDataOperationMessage(pdoMessage);
54
+ };
55
+ const requestPlaceholderResend = async (messageKey, msgData) => {
56
+ if (!authState.creds.me?.id) {
57
+ throw new Boom('Not authenticated');
58
+ }
59
+ if (await placeholderResendCache.get(messageKey?.id)) {
60
+ logger.debug({ messageKey }, 'already requested resend');
61
+ return;
62
+ }
63
+ else {
64
+ // Store original message data so PDO response handler can preserve
65
+ // metadata (LID details, timestamps, etc.) that the phone may omit
66
+ await placeholderResendCache.set(messageKey?.id, msgData || true);
67
+ }
68
+ await delay(2000);
69
+ if (!(await placeholderResendCache.get(messageKey?.id))) {
70
+ logger.debug({ messageKey }, 'message received while resend requested');
71
+ return 'RESOLVED';
72
+ }
73
+ const pdoMessage = {
74
+ placeholderMessageResendRequest: [
75
+ {
76
+ messageKey
77
+ }
78
+ ],
79
+ peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
80
+ };
81
+ setTimeout(async () => {
82
+ if (await placeholderResendCache.get(messageKey?.id)) {
83
+ logger.debug({ messageKey }, 'PDO message without response after 8 seconds. Phone possibly offline');
84
+ await placeholderResendCache.del(messageKey?.id);
85
+ }
86
+ }, 8000);
87
+ return sendPeerDataOperationMessage(pdoMessage);
88
+ };
89
+ // Handles mex newsletter notifications
90
+ const handleMexNewsletterNotification = async (node) => {
91
+ const mexNode = getBinaryNodeChild(node, 'mex');
92
+ if (!mexNode?.content) {
93
+ logger.warn({ node }, 'Invalid mex newsletter notification');
94
+ return;
95
+ }
96
+ let data;
97
+ try {
98
+ data = JSON.parse(mexNode.content.toString());
99
+ }
100
+ catch (error) {
101
+ logger.error({ err: error, node }, 'Failed to parse mex newsletter notification');
102
+ return;
103
+ }
104
+ const operation = data?.operation;
105
+ const updates = data?.updates;
106
+ if (!updates || !operation) {
107
+ logger.warn({ data }, 'Invalid mex newsletter notification content');
108
+ return;
109
+ }
110
+ logger.info({ operation, updates }, 'got mex newsletter notification');
111
+ switch (operation) {
112
+ case 'NotificationNewsletterUpdate':
113
+ for (const update of updates) {
114
+ if (update.jid && update.settings && Object.keys(update.settings).length > 0) {
115
+ ev.emit('newsletter-settings.update', {
116
+ id: update.jid,
117
+ update: update.settings
118
+ });
119
+ }
120
+ }
121
+ break;
122
+ case 'NotificationNewsletterAdminPromote':
123
+ for (const update of updates) {
124
+ if (update.jid && update.user) {
125
+ ev.emit('newsletter-participants.update', {
126
+ id: update.jid,
127
+ author: node.attrs.from,
128
+ user: update.user,
129
+ new_role: 'ADMIN',
130
+ action: 'promote'
131
+ });
132
+ }
133
+ }
134
+ break;
135
+ default:
136
+ logger.info({ operation, data }, 'Unhandled mex newsletter notification');
137
+ break;
138
+ }
139
+ };
140
+ // Handles newsletter notifications
141
+ const handleNewsletterNotification = async (node) => {
142
+ const from = node.attrs.from;
143
+ const child = getAllBinaryNodeChildren(node)[0];
144
+ const author = node.attrs.participant;
145
+ logger.info({ from, child }, 'got newsletter notification');
146
+ switch (child.tag) {
147
+ case 'reaction':
148
+ const reactionUpdate = {
149
+ id: from,
150
+ server_id: child.attrs.message_id,
151
+ reaction: {
152
+ code: getBinaryNodeChildString(child, 'reaction'),
153
+ count: 1
154
+ }
155
+ };
156
+ ev.emit('newsletter.reaction', reactionUpdate);
157
+ break;
158
+ case 'view':
159
+ const viewUpdate = {
160
+ id: from,
161
+ server_id: child.attrs.message_id,
162
+ count: parseInt(child.content?.toString() || '0', 10)
163
+ };
164
+ ev.emit('newsletter.view', viewUpdate);
165
+ break;
166
+ case 'participant':
167
+ const participantUpdate = {
168
+ id: from,
169
+ author,
170
+ user: child.attrs.jid,
171
+ action: child.attrs.action,
172
+ new_role: child.attrs.role
173
+ };
174
+ ev.emit('newsletter-participants.update', participantUpdate);
175
+ break;
176
+ case 'update':
177
+ const settingsNode = getBinaryNodeChild(child, 'settings');
178
+ if (settingsNode) {
179
+ const update = {};
180
+ const nameNode = getBinaryNodeChild(settingsNode, 'name');
181
+ if (nameNode?.content)
182
+ update.name = nameNode.content.toString();
183
+ const descriptionNode = getBinaryNodeChild(settingsNode, 'description');
184
+ if (descriptionNode?.content)
185
+ update.description = descriptionNode.content.toString();
186
+ ev.emit('newsletter-settings.update', {
187
+ id: from,
188
+ update
189
+ });
190
+ }
191
+ break;
192
+ case 'message':
193
+ const plaintextNode = getBinaryNodeChild(child, 'plaintext');
194
+ if (plaintextNode?.content) {
195
+ try {
196
+ const contentBuf = typeof plaintextNode.content === 'string'
197
+ ? Buffer.from(plaintextNode.content, 'binary')
198
+ : Buffer.from(plaintextNode.content);
199
+ const messageProto = proto.Message.decode(contentBuf).toJSON();
200
+ const fullMessage = proto.WebMessageInfo.fromObject({
201
+ key: {
202
+ remoteJid: from,
203
+ id: child.attrs.message_id || child.attrs.server_id,
204
+ fromMe: false // TODO: is this really true though
205
+ },
206
+ message: messageProto,
207
+ messageTimestamp: +child.attrs.t
208
+ }).toJSON();
209
+ await upsertMessage(fullMessage, 'append');
210
+ logger.info('Processed plaintext newsletter message');
211
+ }
212
+ catch (error) {
213
+ logger.error({ error }, 'Failed to decode plaintext newsletter message');
214
+ }
215
+ }
216
+ break;
217
+ default:
218
+ logger.warn({ node }, 'Unknown newsletter notification');
219
+ break;
220
+ }
221
+ };
222
+ const sendMessageAck = async (node, errorCode) => {
223
+ const stanza = buildAckStanza(node, errorCode, authState.creds.me.id);
224
+ logger.debug({ recv: { tag: node.tag, attrs: node.attrs }, sent: stanza.attrs }, 'sent ack');
225
+ await sendNode(stanza);
226
+ };
227
+ const rejectCall = async (callId, callFrom) => {
228
+ const stanza = {
229
+ tag: 'call',
230
+ attrs: {
231
+ from: authState.creds.me.id,
232
+ to: callFrom
233
+ },
234
+ content: [
235
+ {
236
+ tag: 'reject',
237
+ attrs: {
238
+ 'call-id': callId,
239
+ 'call-creator': callFrom,
240
+ count: '0'
241
+ },
242
+ content: undefined
243
+ }
244
+ ]
245
+ };
246
+ await query(stanza);
247
+ };
248
+ const sendRetryRequest = async (node, forceIncludeKeys = false) => {
249
+ const { fullMessage } = decodeMessageNode(node, authState.creds.me.id, '' /* lid unused in JID-first */);
250
+ const { key: msgKey } = fullMessage;
251
+ const msgId = msgKey.id;
252
+ if (messageRetryManager) {
253
+ // Check if we've exceeded max retries using the new system
254
+ if (messageRetryManager.hasExceededMaxRetries(msgId)) {
255
+ logger.debug({ msgId }, 'reached retry limit with new retry manager, clearing');
256
+ messageRetryManager.markRetryFailed(msgId);
257
+ return;
258
+ }
259
+ // Increment retry count using new system
260
+ const retryCount = messageRetryManager.incrementRetryCount(msgId);
261
+ // Use the new retry count for the rest of the logic
262
+ const key = `${msgId}:${msgKey?.participant}`;
263
+ await msgRetryCache.set(key, retryCount);
264
+ }
265
+ else {
266
+ // Fallback to old system
267
+ const key = `${msgId}:${msgKey?.participant}`;
268
+ let retryCount = (await msgRetryCache.get(key)) || 0;
269
+ if (retryCount >= maxMsgRetryCount) {
270
+ logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
271
+ await msgRetryCache.del(key);
272
+ return;
273
+ }
274
+ retryCount += 1;
275
+ await msgRetryCache.set(key, retryCount);
276
+ }
277
+ const key = `${msgId}:${msgKey?.participant}`;
278
+ const retryCount = (await msgRetryCache.get(key)) || 1;
279
+ const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds;
280
+ const fromJid = node.attrs.from;
281
+ // Check if we should recreate the session
282
+ let shouldRecreateSession = false;
283
+ let recreateReason = '';
284
+ if (enableAutoSessionRecreation && messageRetryManager && retryCount > 1) {
285
+ try {
286
+ // Check if we have a session with this JID
287
+ const sessionId = signalRepository.jidToSignalProtocolAddress(fromJid);
288
+ const hasSession = await signalRepository.validateSession(fromJid);
289
+ const result = messageRetryManager.shouldRecreateSession(fromJid, hasSession.exists);
290
+ shouldRecreateSession = result.recreate;
291
+ recreateReason = result.reason;
292
+ if (shouldRecreateSession) {
293
+ logger.debug({ fromJid, retryCount, reason: recreateReason }, 'recreating session for retry');
294
+ // Delete existing session to force recreation
295
+ await authState.keys.set({ session: { [sessionId]: null } });
296
+ forceIncludeKeys = true;
297
+ }
298
+ }
299
+ catch (error) {
300
+ logger.warn({ error, fromJid }, 'failed to check session recreation');
301
+ }
302
+ }
303
+ if (retryCount <= 2) {
304
+ // Use new retry manager for phone requests if available
305
+ if (messageRetryManager) {
306
+ // Schedule phone request with delay (like whatsmeow)
307
+ messageRetryManager.schedulePhoneRequest(msgId, async () => {
308
+ try {
309
+ const requestId = await requestPlaceholderResend(msgKey);
310
+ logger.debug(`sendRetryRequest: requested placeholder resend (${requestId}) for message ${msgId} (scheduled)`);
311
+ }
312
+ catch (error) {
313
+ logger.warn({ error, msgId }, 'failed to send scheduled phone request');
314
+ }
315
+ });
316
+ }
317
+ else {
318
+ // Fallback to immediate request
319
+ const msgId = await requestPlaceholderResend(msgKey);
320
+ logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
321
+ }
322
+ }
323
+ const deviceIdentity = encodeSignedDeviceIdentity(account, true);
324
+ await authState.keys.transaction(async () => {
325
+ const receipt = {
326
+ tag: 'receipt',
327
+ attrs: {
328
+ id: msgId,
329
+ type: 'retry',
330
+ to: node.attrs.from
331
+ },
332
+ content: [
333
+ {
334
+ tag: 'retry',
335
+ attrs: {
336
+ count: retryCount.toString(),
337
+ id: node.attrs.id,
338
+ t: node.attrs.t,
339
+ v: '1',
340
+ // ADD ERROR FIELD
341
+ error: '0'
342
+ }
343
+ },
344
+ {
345
+ tag: 'registration',
346
+ attrs: {},
347
+ content: encodeBigEndian(authState.creds.registrationId)
348
+ }
349
+ ]
350
+ };
351
+ if (node.attrs.recipient) {
352
+ receipt.attrs.recipient = node.attrs.recipient;
353
+ }
354
+ if (node.attrs.participant) {
355
+ receipt.attrs.participant = node.attrs.participant;
356
+ }
357
+ if (retryCount > 1 || forceIncludeKeys || shouldRecreateSession) {
358
+ const { update, preKeys } = await getNextPreKeys(authState, 1);
359
+ const [keyId] = Object.keys(preKeys);
360
+ const key = preKeys[+keyId];
361
+ const content = receipt.content;
362
+ content.push({
363
+ tag: 'keys',
364
+ attrs: {},
365
+ content: [
366
+ { tag: 'type', attrs: {}, content: Buffer.from(KEY_BUNDLE_TYPE) },
367
+ { tag: 'identity', attrs: {}, content: identityKey.public },
368
+ xmppPreKey(key, +keyId),
369
+ xmppSignedPreKey(signedPreKey),
370
+ { tag: 'device-identity', attrs: {}, content: deviceIdentity }
371
+ ]
372
+ });
373
+ ev.emit('creds.update', update);
374
+ }
375
+ await sendNode(receipt);
376
+ logger.info({ msgAttrs: node.attrs, retryCount }, 'sent retry receipt');
377
+ }, authState?.creds?.me?.id || 'sendRetryRequest');
378
+ };
379
+ const handleEncryptNotification = async (node) => {
380
+ const from = node.attrs.from;
381
+ if (from === S_WHATSAPP_NET) {
382
+ const countChild = getBinaryNodeChild(node, 'count');
383
+ const count = +countChild.attrs.value;
384
+ const shouldUploadMorePreKeys = count < MIN_PREKEY_COUNT;
385
+ logger.debug({ count, shouldUploadMorePreKeys }, 'recv pre-key count');
386
+ if (shouldUploadMorePreKeys) {
387
+ await uploadPreKeys();
388
+ }
389
+ }
390
+ else {
391
+ const result = await handleIdentityChange(node, {
392
+ meId: authState.creds.me?.id,
393
+ meLid: undefined, // JID-first: not using LID
394
+ validateSession: signalRepository.validateSession,
395
+ assertSessions,
396
+ debounceCache: identityAssertDebounce,
397
+ logger
398
+ });
399
+ if (result.action === 'no_identity_node') {
400
+ logger.info({ node }, 'unknown encrypt notification');
401
+ }
402
+ }
403
+ };
404
+ const handleGroupNotification = (fullNode, child, msg) => {
405
+ // TODO: Support PN/LID (Here is only LID now)
406
+ const actingParticipantLid = fullNode.attrs.participant;
407
+ const actingParticipantPn = fullNode.attrs.participant_pn;
408
+ const affectedParticipantLid = getBinaryNodeChild(child, 'participant')?.attrs?.jid || actingParticipantLid;
409
+ const affectedParticipantPn = getBinaryNodeChild(child, 'participant')?.attrs?.phone_number || actingParticipantPn;
410
+ switch (child?.tag) {
411
+ case 'create':
412
+ const metadata = extractGroupMetadata(child);
413
+ msg.messageStubType = WAMessageStubType.GROUP_CREATE;
414
+ msg.messageStubParameters = [metadata.subject];
415
+ msg.key = { participant: metadata.owner, participantAlt: metadata.ownerPn };
416
+ ev.emit('chats.upsert', [
417
+ {
418
+ id: metadata.id,
419
+ name: metadata.subject,
420
+ conversationTimestamp: metadata.creation
421
+ }
422
+ ]);
423
+ ev.emit('groups.upsert', [
424
+ {
425
+ ...metadata,
426
+ author: actingParticipantLid,
427
+ authorPn: actingParticipantPn
428
+ }
429
+ ]);
430
+ break;
431
+ case 'ephemeral':
432
+ case 'not_ephemeral':
433
+ msg.message = {
434
+ protocolMessage: {
435
+ type: proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
436
+ ephemeralExpiration: +(child.attrs.expiration || 0)
437
+ }
438
+ };
439
+ break;
440
+ case 'modify':
441
+ const oldNumber = getBinaryNodeChildren(child, 'participant').map(p => p.attrs.jid);
442
+ msg.messageStubParameters = oldNumber || [];
443
+ msg.messageStubType = WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
444
+ break;
445
+ case 'promote':
446
+ case 'demote':
447
+ case 'remove':
448
+ case 'add':
449
+ case 'leave':
450
+ const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
451
+ msg.messageStubType = WAMessageStubType[stubType];
452
+ const participants = getBinaryNodeChildren(child, 'participant').map(({ attrs }) => {
453
+ // JID-first: if server sends a LID jid, store the LID→JID mapping
454
+ // and return phone number as the canonical id
455
+ const participantId = isLidUser(attrs.jid) && isPnUser(attrs.phone_number)
456
+ ? attrs.phone_number // use phone JID as canonical id
457
+ : attrs.jid;
458
+ if (isLidUser(attrs.jid) && isPnUser(attrs.phone_number)) {
459
+ // store mapping async so we can resolve later
460
+ void signalRepository.jidMapping.storeLIDPNMappings([{ lid: attrs.jid, pn: attrs.phone_number }]);
461
+ }
462
+ return {
463
+ id: participantId,
464
+ phoneNumber: isPnUser(participantId) ? participantId : attrs.phone_number,
465
+ lid: undefined, // JID-first: deprecated field
466
+ admin: (attrs.type || null)
467
+ };
468
+ });
469
+ if (participants.length === 1 &&
470
+ // if recv. "remove" message and sender removed themselves
471
+ // mark as left
472
+ (areJidsSameUser(participants[0].id, actingParticipantLid) ||
473
+ areJidsSameUser(participants[0].id, actingParticipantPn)) &&
474
+ child.tag === 'remove') {
475
+ msg.messageStubType = WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
476
+ }
477
+ msg.messageStubParameters = participants.map(a => JSON.stringify(a));
478
+ break;
479
+ case 'subject':
480
+ msg.messageStubType = WAMessageStubType.GROUP_CHANGE_SUBJECT;
481
+ msg.messageStubParameters = [child.attrs.subject];
482
+ break;
483
+ case 'description':
484
+ const description = getBinaryNodeChild(child, 'body')?.content?.toString();
485
+ msg.messageStubType = WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
486
+ msg.messageStubParameters = description ? [description] : undefined;
487
+ break;
488
+ case 'announcement':
489
+ case 'not_announcement':
490
+ msg.messageStubType = WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
491
+ msg.messageStubParameters = [child.tag === 'announcement' ? 'on' : 'off'];
492
+ break;
493
+ case 'locked':
494
+ case 'unlocked':
495
+ msg.messageStubType = WAMessageStubType.GROUP_CHANGE_RESTRICT;
496
+ msg.messageStubParameters = [child.tag === 'locked' ? 'on' : 'off'];
497
+ break;
498
+ case 'invite':
499
+ msg.messageStubType = WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
500
+ msg.messageStubParameters = [child.attrs.code];
501
+ break;
502
+ case 'member_add_mode':
503
+ const addMode = child.content;
504
+ if (addMode) {
505
+ msg.messageStubType = WAMessageStubType.GROUP_MEMBER_ADD_MODE;
506
+ msg.messageStubParameters = [addMode.toString()];
507
+ }
508
+ break;
509
+ case 'membership_approval_mode':
510
+ const approvalMode = getBinaryNodeChild(child, 'group_join');
511
+ if (approvalMode) {
512
+ msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
513
+ msg.messageStubParameters = [approvalMode.attrs.state];
514
+ }
515
+ break;
516
+ case 'created_membership_requests':
517
+ msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
518
+ msg.messageStubParameters = [
519
+ JSON.stringify({ lid: affectedParticipantLid, pn: affectedParticipantPn }),
520
+ 'created',
521
+ child.attrs.request_method
522
+ ];
523
+ break;
524
+ case 'revoked_membership_requests':
525
+ const isDenied = areJidsSameUser(affectedParticipantLid, actingParticipantLid);
526
+ // TODO: LIDMAPPING SUPPORT
527
+ msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
528
+ msg.messageStubParameters = [
529
+ JSON.stringify({ lid: affectedParticipantLid, pn: affectedParticipantPn }),
530
+ isDenied ? 'revoked' : 'rejected'
531
+ ];
532
+ break;
533
+ }
534
+ };
535
+ const processNotification = async (node) => {
536
+ const result = {};
537
+ const [child] = getAllBinaryNodeChildren(node);
538
+ const nodeType = node.attrs.type;
539
+ const from = jidNormalizedUser(node.attrs.from);
540
+ switch (nodeType) {
541
+ case 'newsletter':
542
+ await handleNewsletterNotification(node);
543
+ break;
544
+ case 'mex':
545
+ await handleMexNewsletterNotification(node);
546
+ break;
547
+ case 'w:gp2':
548
+ // TODO: HANDLE PARTICIPANT_PN
549
+ handleGroupNotification(node, child, result);
550
+ break;
551
+ case 'mediaretry':
552
+ const event = decodeMediaRetryNode(node);
553
+ ev.emit('messages.media-update', [event]);
554
+ break;
555
+ case 'encrypt':
556
+ await handleEncryptNotification(node);
557
+ break;
558
+ case 'devices':
559
+ const devices = getBinaryNodeChildren(child, 'device');
560
+ if (areJidsSameUser(child.attrs.jid, authState.creds.me.id) // JID-first: match by JID only
561
+ ) {
562
+ const deviceData = devices.map(d => ({ id: d.attrs.jid, lid: d.attrs.lid }));
563
+ logger.info({ deviceData }, 'my own devices changed');
564
+ }
565
+ //TODO: drop a new event, add hashes
566
+ break;
567
+ case 'server_sync':
568
+ const update = getBinaryNodeChild(node, 'collection');
569
+ if (update) {
570
+ const name = update.attrs.name;
571
+ await resyncAppState([name], false);
572
+ }
573
+ break;
574
+ case 'picture':
575
+ const setPicture = getBinaryNodeChild(node, 'set');
576
+ const delPicture = getBinaryNodeChild(node, 'delete');
577
+ // TODO: WAJIDHASH stuff proper support inhouse
578
+ ev.emit('contacts.update', [
579
+ {
580
+ id: jidNormalizedUser(node?.attrs?.from) || (setPicture || delPicture)?.attrs?.hash || '',
581
+ imgUrl: setPicture ? 'changed' : 'removed'
582
+ }
583
+ ]);
584
+ if (isJidGroup(from)) {
585
+ const node = setPicture || delPicture;
586
+ result.messageStubType = WAMessageStubType.GROUP_CHANGE_ICON;
587
+ if (setPicture) {
588
+ result.messageStubParameters = [setPicture.attrs.id];
589
+ }
590
+ result.participant = node?.attrs.author;
591
+ result.key = {
592
+ ...(result.key || {}),
593
+ participant: setPicture?.attrs.author
594
+ };
595
+ }
596
+ break;
597
+ case 'account_sync':
598
+ if (child.tag === 'disappearing_mode') {
599
+ const newDuration = +child.attrs.duration;
600
+ const timestamp = +child.attrs.t;
601
+ logger.info({ newDuration }, 'updated account disappearing mode');
602
+ ev.emit('creds.update', {
603
+ accountSettings: {
604
+ ...authState.creds.accountSettings,
605
+ defaultDisappearingMode: {
606
+ ephemeralExpiration: newDuration,
607
+ ephemeralSettingTimestamp: timestamp
608
+ }
609
+ }
610
+ });
611
+ }
612
+ else if (child.tag === 'blocklist') {
613
+ const blocklists = getBinaryNodeChildren(child, 'item');
614
+ for (const { attrs } of blocklists) {
615
+ const blocklist = [attrs.jid];
616
+ const type = attrs.action === 'block' ? 'add' : 'remove';
617
+ ev.emit('blocklist.update', { blocklist, type });
618
+ }
619
+ }
620
+ break;
621
+ case 'link_code_companion_reg':
622
+ const linkCodeCompanionReg = getBinaryNodeChild(node, 'link_code_companion_reg');
623
+ const ref = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_ref'));
624
+ const primaryIdentityPublicKey = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'primary_identity_pub'));
625
+ const primaryEphemeralPublicKeyWrapped = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
626
+ const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
627
+ const companionSharedKey = Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
628
+ const random = randomBytes(32);
629
+ const linkCodeSalt = randomBytes(32);
630
+ const linkCodePairingExpanded = hkdf(companionSharedKey, 32, {
631
+ salt: linkCodeSalt,
632
+ info: 'link_code_pairing_key_bundle_encryption_key'
633
+ });
634
+ const encryptPayload = Buffer.concat([
635
+ Buffer.from(authState.creds.signedIdentityKey.public),
636
+ primaryIdentityPublicKey,
637
+ random
638
+ ]);
639
+ const encryptIv = randomBytes(12);
640
+ const encrypted = aesEncryptGCM(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
641
+ const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
642
+ const identitySharedKey = Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
643
+ const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
644
+ authState.creds.advSecretKey = Buffer.from(hkdf(identityPayload, 32, { info: 'adv_secret' })).toString('base64');
645
+ await query({
646
+ tag: 'iq',
647
+ attrs: {
648
+ to: S_WHATSAPP_NET,
649
+ type: 'set',
650
+ id: sock.generateMessageTag(),
651
+ xmlns: 'md'
652
+ },
653
+ content: [
654
+ {
655
+ tag: 'link_code_companion_reg',
656
+ attrs: {
657
+ jid: authState.creds.me.id,
658
+ stage: 'companion_finish'
659
+ },
660
+ content: [
661
+ {
662
+ tag: 'link_code_pairing_wrapped_key_bundle',
663
+ attrs: {},
664
+ content: encryptedPayload
665
+ },
666
+ {
667
+ tag: 'companion_identity_public',
668
+ attrs: {},
669
+ content: authState.creds.signedIdentityKey.public
670
+ },
671
+ {
672
+ tag: 'link_code_pairing_ref',
673
+ attrs: {},
674
+ content: ref
675
+ }
676
+ ]
677
+ }
678
+ ]
679
+ });
680
+ authState.creds.registered = true;
681
+ ev.emit('creds.update', authState.creds);
682
+ break;
683
+ case 'privacy_token':
684
+ await handlePrivacyTokenNotification(node);
685
+ break;
686
+ }
687
+ if (Object.keys(result).length) {
688
+ return result;
689
+ }
690
+ };
691
+ const handlePrivacyTokenNotification = async (node) => {
692
+ const tokensNode = getBinaryNodeChild(node, 'tokens');
693
+ const from = jidNormalizedUser(node.attrs.from);
694
+ if (!tokensNode)
695
+ return;
696
+ const tokenNodes = getBinaryNodeChildren(tokensNode, 'token');
697
+ for (const tokenNode of tokenNodes) {
698
+ const { attrs, content } = tokenNode;
699
+ const type = attrs.type;
700
+ const timestamp = attrs.t;
701
+ if (type === 'trusted_contact' && content instanceof Buffer) {
702
+ logger.debug({
703
+ from,
704
+ timestamp,
705
+ tcToken: content
706
+ }, 'received trusted contact token');
707
+ await authState.keys.set({
708
+ tctoken: { [from]: { token: content, timestamp } }
709
+ });
710
+ }
711
+ }
712
+ };
713
+ async function decipherLinkPublicKey(data) {
714
+ const buffer = toRequiredBuffer(data);
715
+ const salt = buffer.slice(0, 32);
716
+ const secretKey = await derivePairingCodeKey(authState.creds.pairingCode, salt);
717
+ const iv = buffer.slice(32, 48);
718
+ const payload = buffer.slice(48, 80);
719
+ return aesDecryptCTR(payload, secretKey, iv);
720
+ }
721
+ function toRequiredBuffer(data) {
722
+ if (data === undefined) {
723
+ throw new Boom('Invalid buffer', { statusCode: 400 });
724
+ }
725
+ return data instanceof Buffer ? data : Buffer.from(data);
726
+ }
727
+ const willSendMessageAgain = async (id, participant) => {
728
+ const key = `${id}:${participant}`;
729
+ const retryCount = (await msgRetryCache.get(key)) || 0;
730
+ return retryCount < maxMsgRetryCount;
731
+ };
732
+ const updateSendMessageAgainCount = async (id, participant) => {
733
+ const key = `${id}:${participant}`;
734
+ const newValue = ((await msgRetryCache.get(key)) || 0) + 1;
735
+ await msgRetryCache.set(key, newValue);
736
+ };
737
+ const sendMessagesAgain = async (key, ids, retryNode) => {
738
+ const remoteJid = key.remoteJid;
739
+ const participant = key.participant || remoteJid;
740
+ const retryCount = +retryNode.attrs.count || 1;
741
+ // Try to get messages from cache first, then fallback to getMessage
742
+ const msgs = [];
743
+ for (const id of ids) {
744
+ let msg;
745
+ // Try to get from retry cache first if enabled
746
+ if (messageRetryManager) {
747
+ const cachedMsg = messageRetryManager.getRecentMessage(remoteJid, id);
748
+ if (cachedMsg) {
749
+ msg = cachedMsg.message;
750
+ logger.debug({ jid: remoteJid, id }, 'found message in retry cache');
751
+ // Mark retry as successful since we found the message
752
+ messageRetryManager.markRetrySuccess(id);
753
+ }
754
+ }
755
+ // Fallback to getMessage if not found in cache
756
+ if (!msg) {
757
+ msg = await getMessage({ ...key, id });
758
+ if (msg) {
759
+ logger.debug({ jid: remoteJid, id }, 'found message via getMessage');
760
+ // Also mark as successful if found via getMessage
761
+ if (messageRetryManager) {
762
+ messageRetryManager.markRetrySuccess(id);
763
+ }
764
+ }
765
+ }
766
+ msgs.push(msg);
767
+ }
768
+ // if it's the primary jid sending the request
769
+ // just re-send the message to everyone
770
+ // prevents the first message decryption failure
771
+ const sendToAll = !jidDecode(participant)?.device;
772
+ // Check if we should recreate session for this retry
773
+ let shouldRecreateSession = false;
774
+ let recreateReason = '';
775
+ if (enableAutoSessionRecreation && messageRetryManager && retryCount > 1) {
776
+ try {
777
+ const sessionId = signalRepository.jidToSignalProtocolAddress(participant);
778
+ const hasSession = await signalRepository.validateSession(participant);
779
+ const result = messageRetryManager.shouldRecreateSession(participant, hasSession.exists);
780
+ shouldRecreateSession = result.recreate;
781
+ recreateReason = result.reason;
782
+ if (shouldRecreateSession) {
783
+ logger.debug({ participant, retryCount, reason: recreateReason }, 'recreating session for outgoing retry');
784
+ await authState.keys.set({ session: { [sessionId]: null } });
785
+ }
786
+ }
787
+ catch (error) {
788
+ logger.warn({ error, participant }, 'failed to check session recreation for outgoing retry');
789
+ }
790
+ }
791
+ await assertSessions([participant], true);
792
+ if (isJidGroup(remoteJid)) {
793
+ await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
794
+ }
795
+ logger.debug({ participant, sendToAll, shouldRecreateSession, recreateReason }, 'forced new session for retry recp');
796
+ for (const [i, msg] of msgs.entries()) {
797
+ if (!ids[i])
798
+ continue;
799
+ if (msg && (await willSendMessageAgain(ids[i], participant))) {
800
+ await updateSendMessageAgainCount(ids[i], participant);
801
+ const msgRelayOpts = { messageId: ids[i] };
802
+ if (sendToAll) {
803
+ msgRelayOpts.useUserDevicesCache = false;
804
+ }
805
+ else {
806
+ msgRelayOpts.participant = {
807
+ jid: participant,
808
+ count: +retryNode.attrs.count
809
+ };
810
+ }
811
+ await relayMessage(key.remoteJid, msg, msgRelayOpts);
812
+ }
813
+ else {
814
+ logger.debug({ jid: key.remoteJid, id: ids[i] }, 'recv retry request, but message not available');
815
+ }
816
+ }
817
+ };
818
+ const handleReceipt = async (node) => {
819
+ const { attrs, content } = node;
820
+ const isLid = attrs.from.includes('lid'); // kept for server-side compat
821
+ const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, authState.creds.me?.id // JID-first: always compare to phone number JID
822
+ );
823
+ const remoteJid = !isNodeFromMe || isJidGroup(attrs.from) ? attrs.from : attrs.recipient;
824
+ const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
825
+ const key = {
826
+ remoteJid,
827
+ id: '',
828
+ fromMe,
829
+ participant: attrs.participant
830
+ };
831
+ if (shouldIgnoreJid(remoteJid) && remoteJid !== S_WHATSAPP_NET) {
832
+ logger.debug({ remoteJid }, 'ignoring receipt from jid');
833
+ await sendMessageAck(node);
834
+ return;
835
+ }
836
+ const ids = [attrs.id];
837
+ if (Array.isArray(content)) {
838
+ const items = getBinaryNodeChildren(content[0], 'item');
839
+ ids.push(...items.map(i => i.attrs.id));
840
+ }
841
+ try {
842
+ await Promise.all([
843
+ receiptMutex.mutex(async () => {
844
+ const status = getStatusFromReceiptType(attrs.type);
845
+ if (typeof status !== 'undefined' &&
846
+ // basically, we only want to know when a message from us has been delivered to/read by the other person
847
+ // or another device of ours has read some messages
848
+ (status >= proto.WebMessageInfo.Status.SERVER_ACK || !isNodeFromMe)) {
849
+ if (isJidGroup(remoteJid) || isJidStatusBroadcast(remoteJid)) {
850
+ if (attrs.participant) {
851
+ const updateKey = status === proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
852
+ ev.emit('message-receipt.update', ids.map(id => ({
853
+ key: { ...key, id },
854
+ receipt: {
855
+ userJid: jidNormalizedUser(attrs.participant),
856
+ [updateKey]: +attrs.t
857
+ }
858
+ })));
859
+ }
860
+ }
861
+ else {
862
+ ev.emit('messages.update', ids.map(id => ({
863
+ key: { ...key, id },
864
+ update: { status, messageTimestamp: toNumber(+(attrs.t ?? 0)) }
865
+ })));
866
+ }
867
+ }
868
+ if (attrs.type === 'retry') {
869
+ // correctly set who is asking for the retry
870
+ key.participant = key.participant || attrs.from;
871
+ const retryNode = getBinaryNodeChild(node, 'retry');
872
+ if (ids[0] && key.participant && (await willSendMessageAgain(ids[0], key.participant))) {
873
+ if (key.fromMe) {
874
+ try {
875
+ await updateSendMessageAgainCount(ids[0], key.participant);
876
+ logger.debug({ attrs, key }, 'recv retry request');
877
+ await sendMessagesAgain(key, ids, retryNode);
878
+ }
879
+ catch (error) {
880
+ logger.error({ key, ids, trace: error instanceof Error ? error.stack : 'Unknown error' }, 'error in sending message again');
881
+ }
882
+ }
883
+ else {
884
+ logger.info({ attrs, key }, 'recv retry for not fromMe message');
885
+ }
886
+ }
887
+ else {
888
+ logger.info({ attrs, key }, 'will not send message again, as sent too many times');
889
+ }
890
+ }
891
+ })
892
+ ]);
893
+ }
894
+ finally {
895
+ await sendMessageAck(node).catch(ackErr => logger.error({ ackErr }, 'failed to ack receipt'));
896
+ }
897
+ };
898
+ const handleNotification = async (node) => {
899
+ const remoteJid = node.attrs.from;
900
+ if (shouldIgnoreJid(remoteJid) && remoteJid !== S_WHATSAPP_NET) {
901
+ logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification');
902
+ await sendMessageAck(node);
903
+ return;
904
+ }
905
+ try {
906
+ await Promise.all([
907
+ notificationMutex.mutex(async () => {
908
+ const msg = await processNotification(node);
909
+ if (msg) {
910
+ const fromMe = areJidsSameUser(node.attrs.participant || remoteJid, authState.creds.me.id);
911
+ const { senderAlt: participantAlt, addressingMode } = extractAddressingContext(node);
912
+ msg.key = {
913
+ remoteJid,
914
+ fromMe,
915
+ participant: node.attrs.participant,
916
+ participantAlt,
917
+ addressingMode,
918
+ id: node.attrs.id,
919
+ ...(msg.key || {})
920
+ };
921
+ msg.participant ?? (msg.participant = node.attrs.participant);
922
+ msg.messageTimestamp = +node.attrs.t;
923
+ const fullMsg = proto.WebMessageInfo.fromObject(msg);
924
+ await upsertMessage(fullMsg, 'append');
925
+ }
926
+ })
927
+ ]);
928
+ }
929
+ finally {
930
+ await sendMessageAck(node).catch(ackErr => logger.error({ ackErr }, 'failed to ack notification'));
931
+ }
932
+ };
933
+ const handleMessage = async (node) => {
934
+ if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== S_WHATSAPP_NET) {
935
+ logger.debug({ key: node.attrs.key }, 'ignored message');
936
+ await sendMessageAck(node, NACK_REASONS.UnhandledError);
937
+ return;
938
+ }
939
+ const encNode = getBinaryNodeChild(node, 'enc');
940
+ // TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
941
+ if (encNode?.attrs.type === 'msmsg') {
942
+ logger.debug({ key: node.attrs.key }, 'ignored msmsg');
943
+ await sendMessageAck(node, NACK_REASONS.MissingMessageSecret);
944
+ return;
945
+ }
946
+ let acked = false;
947
+ try {
948
+ const { fullMessage: msg, category, author, decrypt } = decryptMessageNode(node, authState.creds.me.id, signalRepository, logger);
949
+ const alt = msg.key.participantAlt || msg.key.remoteJidAlt;
950
+ // store new mappings we didn't have before
951
+ if (!!alt) {
952
+ const altServer = jidDecode(alt)?.server;
953
+ const primaryJid = msg.key.participant || msg.key.remoteJid;
954
+ if (altServer === 'lid') {
955
+ // LID received — store mapping so we can resolve to JID
956
+ if (!(await signalRepository.jidMapping.getPNForLID(alt))) {
957
+ await signalRepository.jidMapping.storeLIDPNMappings([{ lid: alt, pn: primaryJid }]);
958
+ await signalRepository.migrateSession(primaryJid, alt);
959
+ }
960
+ }
961
+ else {
962
+ await signalRepository.jidMapping.storeLIDPNMappings([{ lid: primaryJid, pn: alt }]);
963
+ await signalRepository.migrateSession(alt, primaryJid);
964
+ }
965
+ }
966
+ await messageMutex.mutex(async () => {
967
+ await decrypt();
968
+ if (msg.key?.remoteJid && msg.key?.id && msg.message && messageRetryManager) {
969
+ messageRetryManager.addRecentMessage(msg.key.remoteJid, msg.key.id, msg.message);
970
+ }
971
+ // message failed to decrypt
972
+ if (msg.messageStubType === proto.WebMessageInfo.StubType.CIPHERTEXT && msg.category !== 'peer') {
973
+ if (msg?.messageStubParameters?.[0] === MISSING_KEYS_ERROR_TEXT) {
974
+ acked = true;
975
+ return sendMessageAck(node, NACK_REASONS.ParsingError);
976
+ }
977
+ if (msg.messageStubParameters?.[0] === NO_MESSAGE_FOUND_ERROR_TEXT) {
978
+ // Message arrived without encryption (e.g. CTWA ads messages).
979
+ // Check if this is eligible for placeholder resend (matching WA Web filters).
980
+ const unavailableNode = getBinaryNodeChild(node, 'unavailable');
981
+ const unavailableType = unavailableNode?.attrs?.type;
982
+ if (unavailableType === 'bot_unavailable_fanout' ||
983
+ unavailableType === 'hosted_unavailable_fanout' ||
984
+ unavailableType === 'view_once_unavailable_fanout') {
985
+ logger.debug({ msgId: msg.key.id, unavailableType }, 'skipping placeholder resend for excluded unavailable type');
986
+ acked = true;
987
+ return sendMessageAck(node);
988
+ }
989
+ const messageAge = unixTimestampSeconds() - toNumber(msg.messageTimestamp);
990
+ if (messageAge > PLACEHOLDER_MAX_AGE_SECONDS) {
991
+ logger.debug({ msgId: msg.key.id, messageAge }, 'skipping placeholder resend for old message');
992
+ acked = true;
993
+ return sendMessageAck(node);
994
+ }
995
+ // Request the real content from the phone via placeholder resend PDO.
996
+ // Upsert the CIPHERTEXT stub as a placeholder (like WA Web's processPlaceholderMsg),
997
+ // and store the requestId in stubParameters[1] so users can correlate
998
+ // with the incoming PDO response event.
999
+ const cleanKey = {
1000
+ remoteJid: msg.key.remoteJid,
1001
+ fromMe: msg.key.fromMe,
1002
+ id: msg.key.id,
1003
+ participant: msg.key.participant
1004
+ };
1005
+ // Cache the original message metadata so the PDO response handler
1006
+ // can preserve key fields (LID details etc.) that the phone may omit
1007
+ const msgData = {
1008
+ key: msg.key,
1009
+ messageTimestamp: msg.messageTimestamp,
1010
+ pushName: msg.pushName,
1011
+ participant: msg.participant,
1012
+ verifiedBizName: msg.verifiedBizName
1013
+ };
1014
+ requestPlaceholderResend(cleanKey, msgData)
1015
+ .then(requestId => {
1016
+ if (requestId && requestId !== 'RESOLVED') {
1017
+ logger.debug({ msgId: msg.key.id, requestId }, 'requested placeholder resend for unavailable message');
1018
+ ev.emit('messages.update', [
1019
+ {
1020
+ key: msg.key,
1021
+ update: { messageStubParameters: [NO_MESSAGE_FOUND_ERROR_TEXT, requestId] }
1022
+ }
1023
+ ]);
1024
+ }
1025
+ })
1026
+ .catch(err => {
1027
+ logger.warn({ err, msgId: msg.key.id }, 'failed to request placeholder resend for unavailable message');
1028
+ });
1029
+ acked = true;
1030
+ await sendMessageAck(node);
1031
+ // Don't return — fall through to upsertMessage so the stub is emitted
1032
+ }
1033
+ else {
1034
+ // Skip retry for expired status messages (>24h old)
1035
+ if (isJidStatusBroadcast(msg.key.remoteJid)) {
1036
+ const messageAge = unixTimestampSeconds() - toNumber(msg.messageTimestamp);
1037
+ if (messageAge > STATUS_EXPIRY_SECONDS) {
1038
+ logger.debug({ msgId: msg.key.id, messageAge, remoteJid: msg.key.remoteJid }, 'skipping retry for expired status message');
1039
+ acked = true;
1040
+ return sendMessageAck(node);
1041
+ }
1042
+ }
1043
+ const errorMessage = msg?.messageStubParameters?.[0] || '';
1044
+ const isPreKeyError = errorMessage.includes('PreKey');
1045
+ logger.debug(`[handleMessage] Attempting retry request for failed decryption`);
1046
+ // Handle both pre-key and normal retries in single mutex
1047
+ await retryMutex.mutex(async () => {
1048
+ try {
1049
+ if (!ws.isOpen) {
1050
+ logger.debug({ node }, 'Connection closed, skipping retry');
1051
+ return;
1052
+ }
1053
+ // Handle pre-key errors with upload and delay
1054
+ if (isPreKeyError) {
1055
+ logger.info({ error: errorMessage }, 'PreKey error detected, uploading and retrying');
1056
+ try {
1057
+ logger.debug('Uploading pre-keys for error recovery');
1058
+ await uploadPreKeys(5);
1059
+ logger.debug('Waiting for server to process new pre-keys');
1060
+ await delay(1000);
1061
+ }
1062
+ catch (uploadErr) {
1063
+ logger.error({ uploadErr }, 'Pre-key upload failed, proceeding with retry anyway');
1064
+ }
1065
+ }
1066
+ const encNode = getBinaryNodeChild(node, 'enc');
1067
+ await sendRetryRequest(node, !encNode);
1068
+ if (retryRequestDelayMs) {
1069
+ await delay(retryRequestDelayMs);
1070
+ }
1071
+ }
1072
+ catch (err) {
1073
+ logger.error({ err, isPreKeyError }, 'Failed to handle retry, attempting basic retry');
1074
+ // Still attempt retry even if pre-key upload failed
1075
+ try {
1076
+ const encNode = getBinaryNodeChild(node, 'enc');
1077
+ await sendRetryRequest(node, !encNode);
1078
+ }
1079
+ catch (retryErr) {
1080
+ logger.error({ retryErr }, 'Failed to send retry after error handling');
1081
+ }
1082
+ }
1083
+ acked = true;
1084
+ await sendMessageAck(node, NACK_REASONS.UnhandledError);
1085
+ });
1086
+ }
1087
+ }
1088
+ else {
1089
+ if (messageRetryManager && msg.key.id) {
1090
+ messageRetryManager.cancelPendingPhoneRequest(msg.key.id);
1091
+ }
1092
+ const isNewsletter = isJidNewsletter(msg.key.remoteJid);
1093
+ if (!isNewsletter) {
1094
+ // no type in the receipt => message delivered
1095
+ let type = undefined;
1096
+ let participant = msg.key.participant;
1097
+ if (category === 'peer') {
1098
+ // special peer message
1099
+ type = 'peer_msg';
1100
+ }
1101
+ else if (msg.key.fromMe) {
1102
+ // message was sent by us from a different device
1103
+ type = 'sender';
1104
+ // need to specially handle this case
1105
+ // JID-first: resolve LID remoteJid before sending receipt
1106
+ if (isLidUser(msg.key.remoteJid) || isLidUser(msg.key.remoteJidAlt)) {
1107
+ participant = author;
1108
+ }
1109
+ }
1110
+ else if (!sendActiveReceipts) {
1111
+ type = 'inactive';
1112
+ }
1113
+ acked = true;
1114
+ await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
1115
+ // send ack for history message
1116
+ const isAnyHistoryMsg = getHistoryMsg(msg.message);
1117
+ if (isAnyHistoryMsg) {
1118
+ const jid = jidNormalizedUser(msg.key.remoteJid);
1119
+ await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync'); // TODO: investigate
1120
+ }
1121
+ }
1122
+ else {
1123
+ acked = true;
1124
+ await sendMessageAck(node);
1125
+ logger.debug({ key: msg.key }, 'processed newsletter message without receipts');
1126
+ }
1127
+ }
1128
+ cleanMessage(msg, authState.creds.me.id, '' /* JID-first */);
1129
+ await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
1130
+ });
1131
+ }
1132
+ catch (error) {
1133
+ logger.error({ error, node: binaryNodeToString(node) }, 'error in handling message');
1134
+ if (!acked) {
1135
+ await sendMessageAck(node, NACK_REASONS.UnhandledError).catch(ackErr => logger.error({ ackErr }, 'failed to ack message after error'));
1136
+ }
1137
+ }
1138
+ };
1139
+ const handleCall = async (node) => {
1140
+ try {
1141
+ const { attrs } = node;
1142
+ const [infoChild] = getAllBinaryNodeChildren(node);
1143
+ if (!infoChild) {
1144
+ throw new Boom('Missing call info in call node');
1145
+ }
1146
+ const status = getCallStatusFromNode(infoChild);
1147
+ const callId = infoChild.attrs['call-id'];
1148
+ const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
1149
+ const call = {
1150
+ chatId: attrs.from,
1151
+ from,
1152
+ callerPn: infoChild.attrs['caller_pn'],
1153
+ id: callId,
1154
+ date: new Date(+attrs.t * 1000),
1155
+ offline: !!attrs.offline,
1156
+ status
1157
+ };
1158
+ if (status === 'offer') {
1159
+ call.isVideo = !!getBinaryNodeChild(infoChild, 'video');
1160
+ call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
1161
+ call.groupJid = infoChild.attrs['group-jid'];
1162
+ await callOfferCache.set(call.id, call);
1163
+ }
1164
+ const existingCall = await callOfferCache.get(call.id);
1165
+ // use existing call info to populate this event
1166
+ if (existingCall) {
1167
+ call.isVideo = existingCall.isVideo;
1168
+ call.isGroup = existingCall.isGroup;
1169
+ call.callerPn = call.callerPn || existingCall.callerPn;
1170
+ }
1171
+ // delete data once call has ended
1172
+ if (status === 'reject' || status === 'accept' || status === 'timeout' || status === 'terminate') {
1173
+ await callOfferCache.del(call.id);
1174
+ }
1175
+ ev.emit('call', [call]);
1176
+ }
1177
+ catch (error) {
1178
+ logger.error({ error, node: binaryNodeToString(node) }, 'error in handling call');
1179
+ }
1180
+ finally {
1181
+ await sendMessageAck(node).catch(ackErr => logger.error({ ackErr }, 'failed to ack call'));
1182
+ }
1183
+ };
1184
+ const handleBadAck = async ({ attrs }) => {
1185
+ const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
1186
+ // WARNING: REFRAIN FROM ENABLING THIS FOR NOW. IT WILL CAUSE A LOOP
1187
+ // // current hypothesis is that if pash is sent in the ack
1188
+ // // it means -- the message hasn't reached all devices yet
1189
+ // // we'll retry sending the message here
1190
+ // if(attrs.phash) {
1191
+ // logger.info({ attrs }, 'received phash in ack, resending message...')
1192
+ // const msg = await getMessage(key)
1193
+ // if(msg) {
1194
+ // await relayMessage(key.remoteJid!, msg, { messageId: key.id!, useUserDevicesCache: false })
1195
+ // } else {
1196
+ // logger.warn({ attrs }, 'could not send message again, as it was not found')
1197
+ // }
1198
+ // }
1199
+ // error in acknowledgement,
1200
+ // device could not display the message
1201
+ if (attrs.error) {
1202
+ logger.warn({ attrs }, 'received error in ack');
1203
+ ev.emit('messages.update', [
1204
+ {
1205
+ key,
1206
+ update: {
1207
+ status: WAMessageStatus.ERROR,
1208
+ messageStubParameters: [attrs.error]
1209
+ }
1210
+ }
1211
+ ]);
1212
+ // resend the message with device_fanout=false, use at your own risk
1213
+ // if (attrs.error === '475') {
1214
+ // const msg = await getMessage(key)
1215
+ // if (msg) {
1216
+ // await relayMessage(key.remoteJid!, msg, {
1217
+ // messageId: key.id!,
1218
+ // useUserDevicesCache: false,
1219
+ // additionalAttributes: {
1220
+ // device_fanout: 'false'
1221
+ // }
1222
+ // })
1223
+ // }
1224
+ // }
1225
+ }
1226
+ };
1227
+ /// processes a node with the given function
1228
+ /// and adds the task to the existing buffer if we're buffering events
1229
+ const processNodeWithBuffer = async (node, identifier, exec) => {
1230
+ ev.buffer();
1231
+ await execTask();
1232
+ ev.flush();
1233
+ function execTask() {
1234
+ return exec(node, false).catch(err => onUnexpectedError(err, identifier));
1235
+ }
1236
+ };
1237
+ const offlineNodeProcessor = makeOfflineNodeProcessor(new Map([
1238
+ ['message', handleMessage],
1239
+ ['call', handleCall],
1240
+ ['receipt', handleReceipt],
1241
+ ['notification', handleNotification]
1242
+ ]), {
1243
+ isWsOpen: () => ws.isOpen,
1244
+ onUnexpectedError,
1245
+ yieldToEventLoop: () => new Promise(resolve => setImmediate(resolve))
1246
+ });
1247
+ const processNode = async (type, node, identifier, exec) => {
1248
+ const isOffline = !!node.attrs.offline;
1249
+ if (isOffline) {
1250
+ offlineNodeProcessor.enqueue(type, node);
1251
+ }
1252
+ else {
1253
+ await processNodeWithBuffer(node, identifier, exec);
1254
+ }
1255
+ };
1256
+ // recv a message
1257
+ ws.on('CB:message', async (node) => {
1258
+ await processNode('message', node, 'processing message', handleMessage);
1259
+ });
1260
+ ws.on('CB:call', async (node) => {
1261
+ await processNode('call', node, 'handling call', handleCall);
1262
+ });
1263
+ ws.on('CB:receipt', async (node) => {
1264
+ await processNode('receipt', node, 'handling receipt', handleReceipt);
1265
+ });
1266
+ ws.on('CB:notification', async (node) => {
1267
+ await processNode('notification', node, 'handling notification', handleNotification);
1268
+ });
1269
+ ws.on('CB:ack,class:message', (node) => {
1270
+ handleBadAck(node).catch(error => onUnexpectedError(error, 'handling bad ack'));
1271
+ });
1272
+ ev.on('call', async ([call]) => {
1273
+ if (!call) {
1274
+ return;
1275
+ }
1276
+ // missed call + group call notification message generation
1277
+ if (call.status === 'timeout' || (call.status === 'offer' && call.isGroup)) {
1278
+ const msg = {
1279
+ key: {
1280
+ remoteJid: call.chatId,
1281
+ id: call.id,
1282
+ fromMe: false
1283
+ },
1284
+ messageTimestamp: unixTimestampSeconds(call.date)
1285
+ };
1286
+ if (call.status === 'timeout') {
1287
+ if (call.isGroup) {
1288
+ msg.messageStubType = call.isVideo
1289
+ ? WAMessageStubType.CALL_MISSED_GROUP_VIDEO
1290
+ : WAMessageStubType.CALL_MISSED_GROUP_VOICE;
1291
+ }
1292
+ else {
1293
+ msg.messageStubType = call.isVideo ? WAMessageStubType.CALL_MISSED_VIDEO : WAMessageStubType.CALL_MISSED_VOICE;
1294
+ }
1295
+ }
1296
+ else {
1297
+ msg.message = { call: { callKey: Buffer.from(call.id) } };
1298
+ }
1299
+ const protoMsg = proto.WebMessageInfo.fromObject(msg);
1300
+ await upsertMessage(protoMsg, call.offline ? 'append' : 'notify');
1301
+ }
1302
+ });
1303
+ ev.on('connection.update', ({ isOnline }) => {
1304
+ if (typeof isOnline !== 'undefined') {
1305
+ sendActiveReceipts = isOnline;
1306
+ logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`);
1307
+ }
1308
+ });
1309
+ return {
1310
+ ...sock,
1311
+ sendMessageAck,
1312
+ sendRetryRequest,
1313
+ rejectCall,
1314
+ fetchMessageHistory,
1315
+ requestPlaceholderResend,
1316
+ messageRetryManager
1317
+ };
1318
+ };
1319
+ //# sourceMappingURL=messages-recv.js.map