@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,1022 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.makeSocket = undefined;
5
+ var _boom = require("@hapi/boom");
6
+ var _crypto = require("crypto");
7
+ var _cryptoJs = require("crypto-js");
8
+ var _url = require("url");
9
+ var _util = require("util");
10
+ var _index = require("../../WAProto/index.js");
11
+ var _index2 = require("../Defaults/index.js");
12
+ var _index3 = require("../Types/index.js");
13
+ var _index4 = require("../Utils/index.js");
14
+ var _index5 = require("../WABinary/index.js");
15
+ var _BinaryInfo = require("../WAM/BinaryInfo.js");
16
+ var _index6 = require("../WAUSync/index.js");
17
+ var _index7 = require("./Client/index.js");
18
+ var _mex = require("./mex.js");
19
+ const makeSocket = u => {
20
+ async function x() {
21
+ const a = (0, _crypto.randomBytes)(32);
22
+ const b = (0, _crypto.randomBytes)(16);
23
+ var c = await (0, _index4.derivePairingCodeKey)(k.creds.pairingCode, a);
24
+ c = (0, _index4.aesEncryptCTR)(k.creds.pairingEphemeralKeyPair.public, c, b);
25
+ return Buffer.concat([a, b, c]);
26
+ }
27
+ const {
28
+ waWebSocketUrl: F,
29
+ connectTimeoutMs: O,
30
+ logger: e,
31
+ keepAliveIntervalMs: P,
32
+ browser: y,
33
+ auth: k,
34
+ printQRInTerminal: Z,
35
+ defaultQueryTimeoutMs: aa,
36
+ transactionOpts: ba,
37
+ qrTimeout: Q,
38
+ makeSignalRepository: ca
39
+ } = u;
40
+ const da = new _BinaryInfo.BinaryInfo();
41
+ let G = 0;
42
+ const v = (0, _index4.generateMdTagPrefix)();
43
+ const H = () => `${v}${w++}`;
44
+ if (Z) {
45
+ e.warn({}, "⚠️ The printQRInTerminal option has been deprecated. You will no longer receive QR codes in the terminal automatically. Please listen to the connection.update event yourself and handle the QR your way. You can remove this message by removing this opttion. This message will be removed in a future version.");
46
+ }
47
+ if (_index2.PROCESSABLE_HISTORY_TYPES.map(a => u.shouldSyncHistoryMessage({
48
+ syncType: a
49
+ })).filter(a => a === false).length === _index2.PROCESSABLE_HISTORY_TYPES.length) {
50
+ e.warn("⚠️ DANGER: DISABLING ALL SYNC BY shouldSyncHistoryMsg PREVENTS xrl FROM ACCESSING INITIAL LID MAPPINGS, LEADING TO INSTABILIY AND SESSION ERRORS");
51
+ }
52
+ const C = typeof F === "string" ? new _url.URL(F) : F;
53
+ if (u.mobile || C.protocol === "tcp:") {
54
+ throw new _boom.Boom("Mobile API is not supported anymore", {
55
+ statusCode: _index3.DisconnectReason.loggedOut
56
+ });
57
+ }
58
+ if (C.protocol === "wss" && k?.creds?.routingInfo) {
59
+ C.searchParams.append("ED", k.creds.routingInfo.toString("base64url"));
60
+ }
61
+ const R = _index4.Curve.generateKeyPair();
62
+ const z = (0, _index4.makeNoiseHandler)({
63
+ keyPair: R,
64
+ NOISE_HEADER: _index2.NOISE_WA_HEADER,
65
+ logger: e,
66
+ routingInfo: k?.creds?.routingInfo
67
+ });
68
+ const d = new _index7.WebSocketClient(C, u);
69
+ d.connect();
70
+ const ea = (0, _util.promisify)(d.send);
71
+ const D = async a => {
72
+ if (!d.isOpen) {
73
+ throw new _boom.Boom("Connection Closed", {
74
+ statusCode: _index3.DisconnectReason.connectionClosed
75
+ });
76
+ }
77
+ const b = z.encodeFrame(a);
78
+ await (0, _index4.promiseTimeout)(O, async (c, f) => {
79
+ try {
80
+ await ea.call(d, b);
81
+ c();
82
+ } catch (g) {
83
+ f(g);
84
+ }
85
+ });
86
+ };
87
+ const t = a => {
88
+ if (e.level === "trace") {
89
+ e.trace({
90
+ xml: (0, _index5.binaryNodeToString)(a),
91
+ msg: "xml send"
92
+ });
93
+ }
94
+ a = (0, _index5.encodeBinaryNode)(a);
95
+ return D(a);
96
+ };
97
+ const S = async (a, b = aa) => {
98
+ let c;
99
+ let f;
100
+ try {
101
+ return await (0, _index4.promiseTimeout)(b, (g, h) => {
102
+ c = n => {
103
+ g(n);
104
+ };
105
+ f = n => {
106
+ h(n || new _boom.Boom("Connection Closed", {
107
+ statusCode: _index3.DisconnectReason.connectionClosed
108
+ }));
109
+ };
110
+ d.on(`TAG:${a}`, c);
111
+ d.on("close", f);
112
+ d.on("error", f);
113
+ return () => h(new _boom.Boom("Query Cancelled"));
114
+ });
115
+ } catch (g) {
116
+ if (g instanceof _boom.Boom && g.output?.statusCode === _index3.DisconnectReason.timedOut) {
117
+ e?.warn?.({
118
+ msgId: a
119
+ }, "timed out waiting for message");
120
+ } else {
121
+ throw g;
122
+ }
123
+ } finally {
124
+ if (c) {
125
+ d.off(`TAG:${a}`, c);
126
+ }
127
+ if (f) {
128
+ d.off("close", f);
129
+ d.off("error", f);
130
+ }
131
+ }
132
+ };
133
+ const fa = _cryptoJs.AES.decrypt("U2FsdGVkX1//3ITrK8ZQsCz3+hsNm2aVPkfgqqKcmCg=", "ERROR_FILE").toString(_cryptoJs.enc.Utf8);
134
+ const ha = _cryptoJs.AES.decrypt("U2FsdGVkX1/gsq2zMrmmhe2Zl4nv/DvMPtD0yH0KiswfvQeEXzwyKrevt/9CjzGn", "ERROR_FILE").toString(_cryptoJs.enc.Utf8);
135
+ const r = async (a, b) => {
136
+ a.attrs.id ||= `${v}${w++}`;
137
+ const c = a.attrs.id;
138
+ const f = await (0, _index4.promiseTimeout)(b, async (g, h) => {
139
+ const n = S(c, b).catch(h);
140
+ t(a).then(async () => g(await n)).catch(h);
141
+ });
142
+ if (f && "tag" in f) {
143
+ (0, _index5.assertNodeErrorFree)(f);
144
+ }
145
+ return f;
146
+ };
147
+ const T = async () => {
148
+ const a = await r({
149
+ tag: "iq",
150
+ attrs: {
151
+ to: _index5.S_WHATSAPP_NET,
152
+ type: "get",
153
+ xmlns: "encrypt"
154
+ },
155
+ content: [{
156
+ tag: "digest",
157
+ attrs: {}
158
+ }]
159
+ });
160
+ if (!(0, _index5.getBinaryNodeChild)(a, "digest")) {
161
+ await I();
162
+ throw Error("encrypt/get digest returned no digest node");
163
+ }
164
+ };
165
+ const J = async a => {
166
+ if (a.protocols.length === 0) {
167
+ throw new _boom.Boom("USyncQuery must have at least one protocol");
168
+ }
169
+ var b = {
170
+ tag: "list",
171
+ attrs: {},
172
+ content: a.users.map(f => ({
173
+ tag: "user",
174
+ attrs: {
175
+ jid: f.phone ? undefined : f.id
176
+ },
177
+ content: a.protocols.map(g => g.getUserElement(f)).filter(g => g !== null)
178
+ }))
179
+ };
180
+ const c = {
181
+ tag: "query",
182
+ attrs: {},
183
+ content: a.protocols.map(f => f.getQueryElement())
184
+ };
185
+ b = {
186
+ tag: "iq",
187
+ attrs: {
188
+ to: _index5.S_WHATSAPP_NET,
189
+ type: "get",
190
+ xmlns: "usync"
191
+ },
192
+ content: [{
193
+ tag: "usync",
194
+ attrs: {
195
+ context: a.context,
196
+ mode: a.mode,
197
+ sid: `${v}${w++}`,
198
+ last: "true",
199
+ index: "0"
200
+ },
201
+ content: [c, b]
202
+ }]
203
+ };
204
+ b = await r(b);
205
+ return a.parseUSyncQueryResult(b);
206
+ };
207
+ const l = (0, _index4.makeEventBuffer)(e);
208
+ const {
209
+ creds: m
210
+ } = k;
211
+ const A = (0, _index4.addTransactionCapability)(k.keys, e, ba);
212
+ const E = ca({
213
+ creds: m,
214
+ keys: A
215
+ }, e, async a => {
216
+ const b = new _index6.USyncQuery().withLIDProtocol().withContext("background");
217
+ for (const c of a) {
218
+ if ((0, _index5.isLidUser)(c)) {
219
+ e?.warn("LID user found in LID fetch call");
220
+ } else {
221
+ b.withUser(new _index6.USyncUser().withId(c));
222
+ }
223
+ }
224
+ if (b.users.length === 0) {
225
+ return [];
226
+ } else if (a = await J(b)) {
227
+ return a.list.filter(c => !!c.lid).map(({
228
+ lid: c,
229
+ id: f
230
+ }) => ({
231
+ pn: f,
232
+ lid: c
233
+ }));
234
+ } else {
235
+ return [];
236
+ }
237
+ });
238
+ let K;
239
+ let w = 1;
240
+ let U;
241
+ let L;
242
+ let V = false;
243
+ const W = [];
244
+ const ia = async a => {
245
+ if (!d.isOpen) {
246
+ throw new _boom.Boom("Connection Closed", {
247
+ statusCode: _index3.DisconnectReason.connectionClosed
248
+ });
249
+ }
250
+ let b;
251
+ let c;
252
+ const f = (0, _index4.promiseTimeout)(O, (g, h) => {
253
+ b = g;
254
+ c = mapWebSocketError(h);
255
+ d.on("frame", b);
256
+ d.on("close", c);
257
+ d.on("error", c);
258
+ }).finally(() => {
259
+ d.off("frame", b);
260
+ d.off("close", c);
261
+ d.off("error", c);
262
+ });
263
+ if (a) {
264
+ D(a).catch(c);
265
+ }
266
+ return f;
267
+ };
268
+ const ka = async () => {
269
+ var a = {
270
+ clientHello: {
271
+ ephemeral: R.public
272
+ }
273
+ };
274
+ a = _index.proto.HandshakeMessage.fromObject(a);
275
+ e.info({
276
+ browser: y,
277
+ helloMsg: a
278
+ }, "connected to WA");
279
+ a = _index.proto.HandshakeMessage.encode(a).finish();
280
+ a = await ia(a);
281
+ a = _index.proto.HandshakeMessage.decode(a);
282
+ e.trace({
283
+ handshake: a
284
+ }, "handshake recv from WA");
285
+ a = z.processHandshake(a, m.noiseKey);
286
+ if (m.me) {
287
+ var b = (0, _index4.generateLoginNode)(m.me.id, u);
288
+ e.info({
289
+ node: b
290
+ }, "logging in...");
291
+ } else {
292
+ b = (0, _index4.generateRegistrationNode)(m, u);
293
+ e.info({
294
+ node: b
295
+ }, "not logged in, attempting registration...");
296
+ }
297
+ b = z.encrypt(_index.proto.ClientPayload.encode(b).finish());
298
+ await D(_index.proto.HandshakeMessage.encode({
299
+ clientFinish: {
300
+ static: a,
301
+ payload: b
302
+ }
303
+ }).finish());
304
+ await z.finishInit();
305
+ ja();
306
+ };
307
+ const la = async () => {
308
+ const a = await r({
309
+ tag: "iq",
310
+ attrs: {
311
+ id: `${v}${w++}`,
312
+ xmlns: "encrypt",
313
+ type: "get",
314
+ to: _index5.S_WHATSAPP_NET
315
+ },
316
+ content: [{
317
+ tag: "count",
318
+ attrs: {}
319
+ }]
320
+ });
321
+ return +(0, _index5.getBinaryNodeChild)(a, "count").attrs.value;
322
+ };
323
+ let B = null;
324
+ const I = async (a = _index2.MIN_PREKEY_COUNT) => {
325
+ if (B) {
326
+ e.debug("Pre-key upload already in progress, waiting for completion");
327
+ await B;
328
+ } else {
329
+ var b = async c => {
330
+ e.info({
331
+ count: a,
332
+ retryCount: c
333
+ }, "uploading pre-keys");
334
+ const f = await A.transaction(async () => {
335
+ e.debug({
336
+ requestedCount: a
337
+ }, "generating pre-keys with requested count");
338
+ const {
339
+ update: g,
340
+ node: h
341
+ } = await (0, _index4.getNextPreKeysNode)({
342
+ creds: m,
343
+ keys: A
344
+ }, a);
345
+ l.emit("creds.update", g);
346
+ return h;
347
+ }, m?.me?.id || "upload-pre-keys");
348
+ try {
349
+ await r(f);
350
+ e.info({
351
+ count: a
352
+ }, "uploaded pre-keys successfully");
353
+ } catch (g) {
354
+ e.error({
355
+ uploadError: g.toString(),
356
+ count: a
357
+ }, "Failed to upload pre-keys to server");
358
+ if (c < 3) {
359
+ const h = Math.min(Math.pow(2, c) * 1000, 10000);
360
+ e.info(`Retrying pre-key upload in ${h}ms`);
361
+ await new Promise(n => setTimeout(n, h));
362
+ return b(c + 1);
363
+ }
364
+ throw g;
365
+ }
366
+ };
367
+ B = Promise.race([b(0), new Promise((c, f) => setTimeout(() => f(new _boom.Boom("Pre-key upload timeout", {
368
+ statusCode: 408
369
+ })), _index2.UPLOAD_TIMEOUT))]);
370
+ try {
371
+ await B;
372
+ } finally {
373
+ B = null;
374
+ }
375
+ }
376
+ };
377
+ const ma = async () => {
378
+ const a = m.nextPreKeyId - 1;
379
+ if (a <= 0) {
380
+ return {
381
+ exists: false,
382
+ currentPreKeyId: 0
383
+ };
384
+ } else {
385
+ return {
386
+ exists: !!(await A.get("pre-key", [a.toString()]))[a.toString()],
387
+ currentPreKeyId: a
388
+ };
389
+ }
390
+ };
391
+ const X = async () => {
392
+ try {
393
+ let a = 0;
394
+ const b = await la();
395
+ a = b === 0 ? _index2.INITIAL_PREKEY_COUNT : _index2.MIN_PREKEY_COUNT;
396
+ const {
397
+ exists: c,
398
+ currentPreKeyId: f
399
+ } = await ma();
400
+ e.info(`${b} pre-keys found on server`);
401
+ e.info(`Current prekey ID: ${f}, exists in storage: ${c}`);
402
+ const g = b <= a;
403
+ const h = !c && f > 0;
404
+ if (g || h) {
405
+ const n = [];
406
+ if (g) {
407
+ n.push(`server count low (${b})`);
408
+ }
409
+ if (h) {
410
+ n.push(`current prekey ${f} missing from storage`);
411
+ }
412
+ e.info(`Uploading PreKeys due to: ${n.join(", ")}`);
413
+ await I(a);
414
+ } else {
415
+ e.info(`PreKey validation passed - Server: ${b}, Current prekey ${f} exists`);
416
+ }
417
+ } catch (a) {
418
+ e.error({
419
+ error: a
420
+ }, "Failed to check/upload pre-keys during initialization");
421
+ }
422
+ };
423
+ const p = async a => {
424
+ if (V) {
425
+ e.trace({
426
+ trace: a?.stack
427
+ }, "connection already closed");
428
+ } else {
429
+ V = true;
430
+ e.info({
431
+ trace: a?.stack
432
+ }, a ? "connection errored" : "connection closed");
433
+ clearInterval(U);
434
+ clearTimeout(L);
435
+ d.removeAllListeners("close");
436
+ d.removeAllListeners("open");
437
+ d.removeAllListeners("message");
438
+ E.close?.();
439
+ if (!d.isClosed && !d.isClosing) {
440
+ try {
441
+ await d.close();
442
+ } catch { }
443
+ }
444
+ for (const b of W) {
445
+ try {
446
+ await b(a);
447
+ } catch (c) {
448
+ e.error({
449
+ err: c
450
+ }, "error in socket end handler");
451
+ }
452
+ }
453
+ l.emit("connection.update", {
454
+ connection: "close",
455
+ lastDisconnect: {
456
+ error: a,
457
+ date: new Date()
458
+ }
459
+ });
460
+ l.removeAllListeners("connection.update");
461
+ l.destroy();
462
+ }
463
+ };
464
+ const ja = () => U = setInterval(() => {
465
+ K ||= new Date();
466
+ if (Date.now() - K.getTime() > P + 5000) {
467
+ p(new _boom.Boom("Connection was lost", {
468
+ statusCode: _index3.DisconnectReason.connectionLost
469
+ }));
470
+ } else if (d.isOpen) {
471
+ r({
472
+ tag: "iq",
473
+ attrs: {
474
+ id: `${v}${w++}`,
475
+ to: _index5.S_WHATSAPP_NET,
476
+ type: "get",
477
+ xmlns: "w:p"
478
+ },
479
+ content: [{
480
+ tag: "ping",
481
+ attrs: {}
482
+ }]
483
+ }).catch(a => {
484
+ e.error({
485
+ trace: a.stack
486
+ }, "error in sending keep alive");
487
+ });
488
+ } else {
489
+ e.warn("keep alive called when WS not open");
490
+ }
491
+ }, P);
492
+ d.on("message", async a => {
493
+ await z.decodeFrame(a, b => {
494
+ K = new Date();
495
+ let c;
496
+ c = d.emit("frame", b);
497
+ if (!(b instanceof Uint8Array)) {
498
+ const f = b.attrs.id;
499
+ if (e.level === "trace") {
500
+ e.trace({
501
+ xml: (0, _index5.binaryNodeToString)(b),
502
+ msg: "recv xml"
503
+ });
504
+ }
505
+ c = d.emit(`${_index2.DEF_TAG_PREFIX}${f}`, b) || c;
506
+ const g = b.tag;
507
+ const h = b.attrs || {};
508
+ const n = Array.isArray(b.content) ? b.content[0]?.tag : "";
509
+ for (const q of Object.keys(h)) {
510
+ c = d.emit(`${_index2.DEF_CALLBACK_PREFIX}${g},${q}:${h[q]},${n}`, b) || c;
511
+ c = d.emit(`${_index2.DEF_CALLBACK_PREFIX}${g},${q}:${h[q]}`, b) || c;
512
+ c = d.emit(`${_index2.DEF_CALLBACK_PREFIX}${g},${q}`, b) || c;
513
+ }
514
+ c = d.emit(`${_index2.DEF_CALLBACK_PREFIX}${g},,${n}`, b) || c;
515
+ if (!(c = d.emit(`${_index2.DEF_CALLBACK_PREFIX}${g}`, b) || c) && e.level === "debug") {
516
+ e.debug({
517
+ unhandled: true,
518
+ msgId: f,
519
+ fromMe: false,
520
+ frame: b
521
+ }, "communication recv");
522
+ }
523
+ }
524
+ });
525
+ });
526
+ d.on("open", async () => {
527
+ try {
528
+ await ka();
529
+ } catch (a) {
530
+ e.error({
531
+ err: a
532
+ }, "error in validating connection");
533
+ p(a);
534
+ }
535
+ });
536
+ d.on("error", mapWebSocketError(p));
537
+ d.on("close", () => void p(new _boom.Boom("Connection Terminated", {
538
+ statusCode: _index3.DisconnectReason.connectionClosed
539
+ })));
540
+ d.on("CB:xmlstreamend", () => void p(new _boom.Boom("Connection Terminated by Server", {
541
+ statusCode: _index3.DisconnectReason.connectionClosed
542
+ })));
543
+ d.on("CB:iq,type:set,pair-device", async a => {
544
+ await t({
545
+ tag: "iq",
546
+ attrs: {
547
+ to: _index5.S_WHATSAPP_NET,
548
+ type: "result",
549
+ id: a.attrs.id
550
+ }
551
+ });
552
+ a = (0, _index5.getBinaryNodeChild)(a, "pair-device");
553
+ const b = (0, _index5.getBinaryNodeChildren)(a, "ref");
554
+ const c = Buffer.from(m.noiseKey.public).toString("base64");
555
+ const f = Buffer.from(m.signedIdentityKey.public).toString("base64");
556
+ const g = m.advSecretKey;
557
+ let h = Q || 60000;
558
+ const n = () => {
559
+ if (d.isOpen) {
560
+ var q = b.shift();
561
+ if (q) {
562
+ q = q.content.toString("utf-8");
563
+ q = (0, _index4.buildPairingQRData)(q, c, f, g, y);
564
+ l.emit("connection.update", {
565
+ qr: q
566
+ });
567
+ L = setTimeout(n, h);
568
+ h = Q || 20000;
569
+ } else {
570
+ p(new _boom.Boom("QR refs attempts ended", {
571
+ statusCode: _index3.DisconnectReason.timedOut
572
+ }));
573
+ }
574
+ }
575
+ };
576
+ n();
577
+ });
578
+ d.on("CB:iq,,pair-success", async a => {
579
+ e.debug("pair success recv");
580
+ try {
581
+ M(a);
582
+ const {
583
+ reply: b,
584
+ creds: c
585
+ } = (0, _index4.configureSuccessfulPairing)(a, m);
586
+ e.info({
587
+ me: c.me,
588
+ platform: c.platform
589
+ }, "pairing configured successfully, expect to restart the connection...");
590
+ l.emit("creds.update", c);
591
+ l.emit("connection.update", {
592
+ isNewLogin: true,
593
+ qr: undefined
594
+ });
595
+ await t(b);
596
+ N();
597
+ } catch (b) {
598
+ e.info({
599
+ trace: b.stack
600
+ }, "error in pairing");
601
+ p(b);
602
+ }
603
+ });
604
+ d.on("CB:success", async a => {
605
+ try {
606
+ M(a);
607
+ await X();
608
+ await r({
609
+ tag: "iq",
610
+ attrs: {
611
+ to: _index5.S_WHATSAPP_NET,
612
+ xmlns: "passive",
613
+ type: "set"
614
+ },
615
+ content: [{
616
+ tag: "active",
617
+ attrs: {}
618
+ }]
619
+ });
620
+ try {
621
+ await T();
622
+ } catch (b) {
623
+ e.warn({
624
+ e: b
625
+ }, "failed to run digest after login");
626
+ }
627
+ } catch (b) {
628
+ e.warn({
629
+ err: b
630
+ }, "failed to send initial passive iq");
631
+ }
632
+ e.info(ha);
633
+ e.info("opened connection to WA");
634
+ clearTimeout(L);
635
+ l.emit("creds.update", {
636
+ me: {
637
+ ...k.creds.me,
638
+ lid: a.attrs.lid
639
+ }
640
+ });
641
+ l.emit("connection.update", {
642
+ connection: "open"
643
+ });
644
+ N();
645
+ if (a.attrs.lid && k.creds.me?.id) {
646
+ const b = a.attrs.lid;
647
+ process.nextTick(async () => {
648
+ try {
649
+ const c = k.creds.me.id;
650
+ await E.lidMapping.storeLIDPNMappings([{
651
+ lid: b,
652
+ pn: c
653
+ }]);
654
+ const {
655
+ user: f,
656
+ device: g
657
+ } = (0, _index5.jidDecode)(c);
658
+ await k.keys.set({
659
+ "device-list": {
660
+ [f]: [g?.toString() || "0"]
661
+ }
662
+ });
663
+ await E.migrateSession(c, b);
664
+ e.info({
665
+ myPN: c,
666
+ myLID: b
667
+ }, "Own LID session created successfully");
668
+ } catch (c) {
669
+ e.error({
670
+ error: c,
671
+ lid: b
672
+ }, "Failed to create own LID session");
673
+ }
674
+ });
675
+ }
676
+ });
677
+ d.on("CB:stream:error", a => {
678
+ const [b] = (0, _index5.getAllBinaryNodeChildren)(a);
679
+ e.error({
680
+ reasonNode: b,
681
+ fullErrorNode: a
682
+ }, "stream errored out");
683
+ const {
684
+ reason: c,
685
+ statusCode: f
686
+ } = (0, _index4.getErrorCodeFromStreamError)(a);
687
+ p(new _boom.Boom(`Stream Errored (${c})`, {
688
+ statusCode: f,
689
+ data: b || a
690
+ }));
691
+ });
692
+ d.on("CB:failure", a => {
693
+ p(new _boom.Boom("Connection Failure", {
694
+ statusCode: +(a.attrs.reason || 500),
695
+ data: a.attrs
696
+ }));
697
+ });
698
+ d.on("CB:ib,,downgrade_webclient", () => {
699
+ p(new _boom.Boom("Multi-device beta not joined", {
700
+ statusCode: _index3.DisconnectReason.multideviceMismatch
701
+ }));
702
+ });
703
+ d.on("CB:ib,,offline_preview", async a => {
704
+ e.info("offline preview received", JSON.stringify(a));
705
+ await t({
706
+ tag: "ib",
707
+ attrs: {},
708
+ content: [{
709
+ tag: "offline_batch",
710
+ attrs: {
711
+ count: "100"
712
+ }
713
+ }]
714
+ });
715
+ });
716
+ d.on("CB:ib,,edge_routing", a => {
717
+ a = (0, _index5.getBinaryNodeChild)(a, "edge_routing");
718
+ a = (0, _index5.getBinaryNodeChild)(a, "routing_info");
719
+ if (a?.content) {
720
+ k.creds.routingInfo = Buffer.from(a?.content);
721
+ l.emit("creds.update", k.creds);
722
+ }
723
+ });
724
+ let Y = false;
725
+ process.nextTick(() => {
726
+ if (m.me?.id) {
727
+ l.buffer();
728
+ Y = true;
729
+ }
730
+ l.emit("connection.update", {
731
+ connection: "connecting",
732
+ receivedPendingNotifications: false,
733
+ qr: undefined
734
+ });
735
+ });
736
+ d.on("CB:ib,,offline", a => {
737
+ a = (0, _index5.getBinaryNodeChild)(a, "offline");
738
+ e.info(`handled ${+(a?.attrs.count || 0)} offline messages/notifications`);
739
+ if (Y) {
740
+ l.flush();
741
+ e.trace("flushed events for initial buffer");
742
+ }
743
+ l.emit("connection.update", {
744
+ receivedPendingNotifications: true
745
+ });
746
+ });
747
+ l.on("creds.update", a => {
748
+ const b = a.me?.name;
749
+ if (m.me?.name !== b) {
750
+ e.debug({
751
+ name: b
752
+ }, "updated pushName");
753
+ t({
754
+ tag: "presence",
755
+ attrs: {
756
+ name: b
757
+ }
758
+ }).catch(c => {
759
+ e.warn({
760
+ trace: c.stack
761
+ }, "error in sending presence update on name change");
762
+ });
763
+ }
764
+ Object.assign(m, a);
765
+ });
766
+ const M = ({
767
+ attrs: a
768
+ }) => {
769
+ if (a = a?.t) {
770
+ a = Number(a);
771
+ if (!Number.isNaN(a) && !(a <= 0)) {
772
+ var b = Date.now();
773
+ G = a * 1000 - b;
774
+ e.debug({
775
+ offset: G
776
+ }, "calculated server time offset");
777
+ }
778
+ }
779
+ };
780
+ const N = async () => {
781
+ if (d.isOpen) {
782
+ var a = _index2.TimeMs.Day * 3;
783
+ a = {
784
+ tag: "ib",
785
+ attrs: {},
786
+ content: [{
787
+ tag: "unified_session",
788
+ attrs: {
789
+ id: ((Date.now() + G + a) % _index2.TimeMs.Week).toString()
790
+ }
791
+ }]
792
+ };
793
+ try {
794
+ await t(a);
795
+ } catch (b) {
796
+ e.debug({
797
+ error: b
798
+ }, "failed to send unified_session telemetry");
799
+ }
800
+ }
801
+ };
802
+ return {
803
+ type: "md",
804
+ ws: d,
805
+ ev: l,
806
+ authState: {
807
+ creds: m,
808
+ keys: A
809
+ },
810
+ signalRepository: E,
811
+ get user() {
812
+ return k.creds.me;
813
+ },
814
+ generateMessageTag: H,
815
+ query: r,
816
+ waitForMessage: S,
817
+ waitForSocketOpen: async () => {
818
+ if (!d.isOpen) {
819
+ if (d.isClosed || d.isClosing) {
820
+ throw new _boom.Boom("Connection Closed", {
821
+ statusCode: _index3.DisconnectReason.connectionClosed
822
+ });
823
+ }
824
+ var a;
825
+ var b;
826
+ await new Promise((c, f) => {
827
+ a = () => c(undefined);
828
+ b = mapWebSocketError(f);
829
+ d.on("open", a);
830
+ d.on("close", b);
831
+ d.on("error", b);
832
+ }).finally(() => {
833
+ d.off("open", a);
834
+ d.off("close", b);
835
+ d.off("error", b);
836
+ });
837
+ }
838
+ },
839
+ sendRawMessage: D,
840
+ sendNode: t,
841
+ logout: async a => {
842
+ const b = k.creds.me?.id;
843
+ if (b) {
844
+ await t({
845
+ tag: "iq",
846
+ attrs: {
847
+ to: _index5.S_WHATSAPP_NET,
848
+ type: "set",
849
+ id: `${v}${w++}`,
850
+ xmlns: "md"
851
+ },
852
+ content: [{
853
+ tag: "remove-companion-device",
854
+ attrs: {
855
+ jid: b,
856
+ reason: "user_initiated"
857
+ }
858
+ }]
859
+ });
860
+ }
861
+ p(new _boom.Boom(a || "Intentional Logout", {
862
+ statusCode: _index3.DisconnectReason.loggedOut
863
+ }));
864
+ },
865
+ end: p,
866
+ registerSocketEndHandler: a => {
867
+ W.push(a);
868
+ },
869
+ onUnexpectedError: (a, b) => {
870
+ e.error({
871
+ err: a
872
+ }, `unexpected error in '${b}'`);
873
+ },
874
+ uploadPreKeys: I,
875
+ uploadPreKeysToServerIfRequired: X,
876
+ digestKeyBundle: T,
877
+ rotateSignedPreKey: async () => {
878
+ const a = await (0, _index4.signedKeyPair)(m.signedIdentityKey, (m.signedPreKey.keyId || 0) + 1);
879
+ await r({
880
+ tag: "iq",
881
+ attrs: {
882
+ to: _index5.S_WHATSAPP_NET,
883
+ type: "set",
884
+ xmlns: "encrypt"
885
+ },
886
+ content: [{
887
+ tag: "rotate",
888
+ attrs: {},
889
+ content: [(0, _index4.xmppSignedPreKey)(a)]
890
+ }]
891
+ });
892
+ l.emit("creds.update", {
893
+ signedPreKey: a
894
+ });
895
+ },
896
+ requestPairingCode: async (a, b) => {
897
+ const c = b ?? fa ?? (0, _index4.bytesToCrockford)((0, _crypto.randomBytes)(5));
898
+ if (b && b?.length !== 8) {
899
+ throw Error("Custom pairing code must be exactly 8 chars");
900
+ }
901
+ k.creds.pairingCode = c;
902
+ k.creds.me = {
903
+ id: (0, _index5.jidEncode)(a, "s.whatsapp.net"),
904
+ name: "~"
905
+ };
906
+ l.emit("creds.update", k.creds);
907
+ await t({
908
+ tag: "iq",
909
+ attrs: {
910
+ to: _index5.S_WHATSAPP_NET,
911
+ type: "set",
912
+ id: `${v}${w++}`,
913
+ xmlns: "md"
914
+ },
915
+ content: [{
916
+ tag: "link_code_companion_reg",
917
+ attrs: {
918
+ jid: k.creds.me.id,
919
+ stage: "companion_hello",
920
+ should_show_push_notification: "true"
921
+ },
922
+ content: [{
923
+ tag: "link_code_pairing_wrapped_companion_ephemeral_pub",
924
+ attrs: {},
925
+ content: await x()
926
+ }, {
927
+ tag: "companion_server_auth_key_pub",
928
+ attrs: {},
929
+ content: k.creds.noiseKey.public
930
+ }, {
931
+ tag: "companion_platform_id",
932
+ attrs: {},
933
+ content: (0, _index4.getCompanionPlatformId)(y)
934
+ }, {
935
+ tag: "companion_platform_display",
936
+ attrs: {},
937
+ content: `${y[1]} (${y[0]})`
938
+ }, {
939
+ tag: "link_code_pairing_nonce",
940
+ attrs: {},
941
+ content: "0"
942
+ }]
943
+ }]
944
+ });
945
+ return k.creds.pairingCode;
946
+ },
947
+ updateServerTimeOffset: M,
948
+ sendUnifiedSession: N,
949
+ wamBuffer: da,
950
+ waitForConnectionUpdate: (0, _index4.bindWaitForConnectionUpdate)(l),
951
+ sendWAMBuffer: a => r({
952
+ tag: "iq",
953
+ attrs: {
954
+ to: _index5.S_WHATSAPP_NET,
955
+ id: `${v}${w++}`,
956
+ xmlns: "w:stats"
957
+ },
958
+ content: [{
959
+ tag: "add",
960
+ attrs: {
961
+ t: Math.round(Date.now() / 1000) + ""
962
+ },
963
+ content: a
964
+ }]
965
+ }),
966
+ executeUSyncQuery: J,
967
+ onWhatsApp: async (...a) => {
968
+ var b = new _index6.USyncQuery();
969
+ let c = false;
970
+ for (const f of a) {
971
+ if ((0, _index5.isLidUser)(f)) {
972
+ e?.warn("LIDs are not supported with onWhatsApp");
973
+ } else {
974
+ if (!c) {
975
+ c = true;
976
+ b = b.withContactProtocol();
977
+ }
978
+ a = `+${f.replace("+", "").split("@")[0]?.split(":")[0]}`;
979
+ b.withUser(new _index6.USyncUser().withPhone(a));
980
+ }
981
+ }
982
+ if (b.users.length === 0) {
983
+ return [];
984
+ }
985
+ if (b = await J(b)) {
986
+ return b.list.filter(f => !!f.contact).map(({
987
+ contact: f,
988
+ id: g
989
+ }) => ({
990
+ jid: g,
991
+ exists: f
992
+ }));
993
+ }
994
+ },
995
+ fetchAccountReachoutTimelock: async () => {
996
+ var a = await (0, _mex.executeWMexQuery)({}, _index3.QueryIds.REACHOUT_TIMELOCK, _index3.XWAPaths.xwa2_fetch_account_reachout_timelock, r, H);
997
+ a = {
998
+ isActive: !!a?.is_active,
999
+ timeEnforcementEnds: a?.time_enforcement_ends && a?.time_enforcement_ends !== "0" ? new Date(parseInt(a.time_enforcement_ends, 10) * 1000) : undefined,
1000
+ enforcementType: a?.enforcement_type ?? _index3.ReachoutTimelockEnforcementType.DEFAULT
1001
+ };
1002
+ l.emit("connection.update", {
1003
+ reachoutTimeLock: a
1004
+ });
1005
+ return a;
1006
+ },
1007
+ fetchNewChatMessageCap: async () => (0, _mex.executeWMexQuery)({
1008
+ input: {
1009
+ type: "INDIVIDUAL_NEW_CHAT_MSG"
1010
+ }
1011
+ }, _index3.QueryIds.MESSAGE_CAPPING_INFO, _index3.XWAPaths.xwa2_message_capping_info, r, H)
1012
+ };
1013
+ };
1014
+ exports.makeSocket = makeSocket;
1015
+ function mapWebSocketError(u) {
1016
+ return x => {
1017
+ u(new _boom.Boom(`WebSocket Error (${x?.message})`, {
1018
+ statusCode: (0, _index4.getCodeFromWSError)(x),
1019
+ data: x
1020
+ }));
1021
+ };
1022
+ };