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