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