xspacesocket 0.0.0-stage → 1.3.1

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