@d0v3riz/baileys 6.7.19 → 6.7.21

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 (374) hide show
  1. package/README.md +1263 -4
  2. package/WAProto/GenerateStatics.sh +3 -0
  3. package/WAProto/WAProto.proto +4633 -0
  4. package/WAProto/fix-imports.js +29 -0
  5. package/WAProto/index.d.ts +3212 -122
  6. package/WAProto/index.js +13516 -4182
  7. package/lib/Defaults/baileys-version.json +1 -1
  8. package/lib/Defaults/index.d.ts +4 -3
  9. package/lib/Defaults/index.d.ts.map +1 -0
  10. package/lib/Defaults/index.js +50 -54
  11. package/lib/Defaults/index.js.map +1 -0
  12. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  14. package/lib/Signal/Group/ciphertext-message.js +12 -0
  15. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  16. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  18. package/lib/Signal/Group/group-session-builder.js +30 -0
  19. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  20. package/lib/Signal/Group/group_cipher.d.ts +18 -0
  21. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  22. package/lib/Signal/Group/group_cipher.js +94 -0
  23. package/lib/Signal/Group/group_cipher.js.map +1 -0
  24. package/lib/Signal/Group/index.d.ts +12 -0
  25. package/lib/Signal/Group/index.d.ts.map +1 -0
  26. package/lib/Signal/Group/index.js +12 -0
  27. package/lib/Signal/Group/index.js.map +1 -0
  28. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  29. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  30. package/lib/Signal/Group/keyhelper.js +19 -0
  31. package/lib/Signal/Group/keyhelper.js.map +1 -0
  32. package/lib/Signal/Group/queue-job.d.ts +3 -0
  33. package/lib/Signal/Group/queue-job.d.ts.map +1 -0
  34. package/lib/Signal/Group/queue-job.js +57 -0
  35. package/lib/Signal/Group/queue-job.js.map +1 -0
  36. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  37. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  38. package/lib/Signal/Group/sender-chain-key.js +32 -0
  39. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  40. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  41. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  42. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  43. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  44. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  45. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  46. package/lib/Signal/Group/sender-key-message.js +67 -0
  47. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  48. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  49. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  50. package/lib/Signal/Group/sender-key-name.js +48 -0
  51. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  52. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  53. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  54. package/lib/Signal/Group/sender-key-record.js +50 -0
  55. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  56. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  57. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  58. package/lib/Signal/Group/sender-key-state.js +96 -0
  59. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  60. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  61. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  62. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +27 -39
  63. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  64. package/lib/Signal/libsignal.d.ts +3 -2
  65. package/lib/Signal/libsignal.d.ts.map +1 -0
  66. package/lib/Signal/libsignal.js +41 -61
  67. package/lib/Signal/libsignal.js.map +1 -0
  68. package/lib/Socket/Client/index.d.ts +3 -2
  69. package/lib/Socket/Client/index.d.ts.map +1 -0
  70. package/lib/Socket/Client/index.js +3 -18
  71. package/lib/Socket/Client/index.js.map +1 -0
  72. package/lib/Socket/Client/types.d.ts +2 -1
  73. package/lib/Socket/Client/types.d.ts.map +1 -0
  74. package/lib/Socket/Client/types.js +4 -6
  75. package/lib/Socket/Client/types.js.map +1 -0
  76. package/lib/Socket/Client/websocket.d.ts +2 -1
  77. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  78. package/lib/Socket/Client/websocket.js +15 -27
  79. package/lib/Socket/Client/websocket.js.map +1 -0
  80. package/lib/Socket/business.d.ts +92 -62
  81. package/lib/Socket/business.d.ts.map +1 -0
  82. package/lib/Socket/business.js +37 -42
  83. package/lib/Socket/business.js.map +1 -0
  84. package/lib/Socket/chats.d.ts +31 -24
  85. package/lib/Socket/chats.d.ts.map +1 -0
  86. package/lib/Socket/chats.js +251 -198
  87. package/lib/Socket/chats.js.map +1 -0
  88. package/lib/Socket/communities.d.ts +219 -0
  89. package/lib/Socket/communities.d.ts.map +1 -0
  90. package/lib/Socket/communities.js +351 -0
  91. package/lib/Socket/communities.js.map +1 -0
  92. package/lib/Socket/groups.d.ts +47 -39
  93. package/lib/Socket/groups.d.ts.map +1 -0
  94. package/lib/Socket/groups.js +91 -82
  95. package/lib/Socket/groups.js.map +1 -0
  96. package/lib/Socket/index.d.ts +128 -68
  97. package/lib/Socket/index.d.ts.map +1 -0
  98. package/lib/Socket/index.js +16 -9
  99. package/lib/Socket/index.js.map +1 -0
  100. package/lib/Socket/messages-recv.d.ts +79 -49
  101. package/lib/Socket/messages-recv.d.ts.map +1 -0
  102. package/lib/Socket/messages-recv.js +364 -200
  103. package/lib/Socket/messages-recv.js.map +1 -0
  104. package/lib/Socket/messages-send.d.ts +76 -46
  105. package/lib/Socket/messages-send.d.ts.map +1 -0
  106. package/lib/Socket/messages-send.js +144 -120
  107. package/lib/Socket/messages-send.js.map +1 -0
  108. package/lib/Socket/mex.d.ts +3 -0
  109. package/lib/Socket/mex.d.ts.map +1 -0
  110. package/lib/Socket/mex.js +42 -0
  111. package/lib/Socket/mex.js.map +1 -0
  112. package/lib/Socket/newsletter.d.ts +143 -0
  113. package/lib/Socket/newsletter.d.ts.map +1 -0
  114. package/lib/Socket/newsletter.js +179 -0
  115. package/lib/Socket/newsletter.js.map +1 -0
  116. package/lib/Socket/socket.d.ts +15 -14
  117. package/lib/Socket/socket.d.ts.map +1 -0
  118. package/lib/Socket/socket.js +153 -141
  119. package/lib/Socket/socket.js.map +1 -0
  120. package/lib/Socket/usync.d.ts +17 -16
  121. package/lib/Socket/usync.d.ts.map +1 -0
  122. package/lib/Socket/usync.js +19 -26
  123. package/lib/Socket/usync.js.map +1 -0
  124. package/lib/Types/Auth.d.ts +5 -4
  125. package/lib/Types/Auth.d.ts.map +1 -0
  126. package/lib/Types/Auth.js +2 -2
  127. package/lib/Types/Auth.js.map +1 -0
  128. package/lib/Types/Call.d.ts +1 -0
  129. package/lib/Types/Call.d.ts.map +1 -0
  130. package/lib/Types/Call.js +2 -2
  131. package/lib/Types/Call.js.map +1 -0
  132. package/lib/Types/Chat.d.ts +14 -8
  133. package/lib/Types/Chat.d.ts.map +1 -0
  134. package/lib/Types/Chat.js +8 -4
  135. package/lib/Types/Chat.js.map +1 -0
  136. package/lib/Types/Contact.d.ts +5 -0
  137. package/lib/Types/Contact.d.ts.map +1 -0
  138. package/lib/Types/Contact.js +2 -2
  139. package/lib/Types/Contact.js.map +1 -0
  140. package/lib/Types/Events.d.ts +38 -11
  141. package/lib/Types/Events.d.ts.map +1 -0
  142. package/lib/Types/Events.js +2 -2
  143. package/lib/Types/Events.js.map +1 -0
  144. package/lib/Types/GroupMetadata.d.ts +10 -4
  145. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  146. package/lib/Types/GroupMetadata.js +2 -2
  147. package/lib/Types/GroupMetadata.js.map +1 -0
  148. package/lib/Types/Label.d.ts +1 -0
  149. package/lib/Types/Label.d.ts.map +1 -0
  150. package/lib/Types/Label.js +3 -5
  151. package/lib/Types/Label.js.map +1 -0
  152. package/lib/Types/LabelAssociation.d.ts +1 -0
  153. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  154. package/lib/Types/LabelAssociation.js +3 -5
  155. package/lib/Types/LabelAssociation.js.map +1 -0
  156. package/lib/Types/Message.d.ts +21 -9
  157. package/lib/Types/Message.d.ts.map +1 -0
  158. package/lib/Types/Message.js +7 -7
  159. package/lib/Types/Message.js.map +1 -0
  160. package/lib/Types/Newsletter.d.ts +135 -0
  161. package/lib/Types/Newsletter.d.ts.map +1 -0
  162. package/lib/Types/Newsletter.js +31 -0
  163. package/lib/Types/Newsletter.js.map +1 -0
  164. package/lib/Types/Product.d.ts +2 -1
  165. package/lib/Types/Product.d.ts.map +1 -0
  166. package/lib/Types/Product.js +2 -2
  167. package/lib/Types/Product.js.map +1 -0
  168. package/lib/Types/Signal.d.ts +2 -1
  169. package/lib/Types/Signal.d.ts.map +1 -0
  170. package/lib/Types/Signal.js +2 -2
  171. package/lib/Types/Signal.js.map +1 -0
  172. package/lib/Types/Socket.d.ts +11 -10
  173. package/lib/Types/Socket.d.ts.map +1 -0
  174. package/lib/Types/Socket.js +3 -2
  175. package/lib/Types/Socket.js.map +1 -0
  176. package/lib/Types/State.d.ts +14 -2
  177. package/lib/Types/State.d.ts.map +1 -0
  178. package/lib/Types/State.js +13 -2
  179. package/lib/Types/State.js.map +1 -0
  180. package/lib/Types/USync.d.ts +3 -2
  181. package/lib/Types/USync.d.ts.map +1 -0
  182. package/lib/Types/USync.js +2 -2
  183. package/lib/Types/USync.js.map +1 -0
  184. package/lib/Types/index.d.ts +15 -13
  185. package/lib/Types/index.d.ts.map +1 -0
  186. package/lib/Types/index.js +15 -30
  187. package/lib/Types/index.js.map +1 -0
  188. package/lib/Utils/auth-utils.d.ts +3 -2
  189. package/lib/Utils/auth-utils.d.ts.map +1 -0
  190. package/lib/Utils/auth-utils.js +30 -40
  191. package/lib/Utils/auth-utils.js.map +1 -0
  192. package/lib/Utils/baileys-event-stream.d.ts +2 -1
  193. package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
  194. package/lib/Utils/baileys-event-stream.js +15 -22
  195. package/lib/Utils/baileys-event-stream.js.map +1 -0
  196. package/lib/Utils/business.d.ts +3 -2
  197. package/lib/Utils/business.d.ts.map +1 -0
  198. package/lib/Utils/business.js +64 -75
  199. package/lib/Utils/business.js.map +1 -0
  200. package/lib/Utils/chat-utils.d.ts +12 -11
  201. package/lib/Utils/chat-utils.d.ts.map +1 -0
  202. package/lib/Utils/chat-utils.js +195 -194
  203. package/lib/Utils/chat-utils.js.map +1 -0
  204. package/lib/Utils/crypto.d.ts +2 -1
  205. package/lib/Utils/crypto.d.ts.map +1 -0
  206. package/lib/Utils/crypto.js +40 -95
  207. package/lib/Utils/crypto.js.map +1 -0
  208. package/lib/Utils/decode-wa-message.d.ts +7 -7
  209. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  210. package/lib/Utils/decode-wa-message.js +43 -41
  211. package/lib/Utils/decode-wa-message.js.map +1 -0
  212. package/lib/Utils/event-buffer.d.ts +6 -6
  213. package/lib/Utils/event-buffer.d.ts.map +1 -0
  214. package/lib/Utils/event-buffer.js +42 -59
  215. package/lib/Utils/event-buffer.js.map +1 -0
  216. package/lib/Utils/generics.d.ts +11 -9
  217. package/lib/Utils/generics.d.ts.map +1 -0
  218. package/lib/Utils/generics.js +105 -130
  219. package/lib/Utils/generics.js.map +1 -0
  220. package/lib/Utils/history.d.ts +4 -3
  221. package/lib/Utils/history.d.ts.map +1 -0
  222. package/lib/Utils/history.js +37 -46
  223. package/lib/Utils/history.js.map +1 -0
  224. package/lib/Utils/index.d.ts +18 -17
  225. package/lib/Utils/index.d.ts.map +1 -0
  226. package/lib/Utils/index.js +18 -33
  227. package/lib/Utils/index.js.map +1 -0
  228. package/lib/Utils/link-preview.d.ts +4 -3
  229. package/lib/Utils/link-preview.d.ts.map +1 -0
  230. package/lib/Utils/link-preview.js +14 -55
  231. package/lib/Utils/link-preview.js.map +1 -0
  232. package/lib/Utils/logger.d.ts +8 -6
  233. package/lib/Utils/logger.d.ts.map +1 -0
  234. package/lib/Utils/logger.js +3 -7
  235. package/lib/Utils/logger.js.map +1 -0
  236. package/lib/Utils/lt-hash.d.ts +9 -8
  237. package/lib/Utils/lt-hash.d.ts.map +1 -0
  238. package/lib/Utils/lt-hash.js +23 -26
  239. package/lib/Utils/lt-hash.js.map +1 -0
  240. package/lib/Utils/make-mutex.d.ts +1 -0
  241. package/lib/Utils/make-mutex.d.ts.map +1 -0
  242. package/lib/Utils/make-mutex.js +6 -10
  243. package/lib/Utils/make-mutex.js.map +1 -0
  244. package/lib/Utils/messages-media.d.ts +20 -11
  245. package/lib/Utils/messages-media.d.ts.map +1 -0
  246. package/lib/Utils/messages-media.js +215 -253
  247. package/lib/Utils/messages-media.js.map +1 -0
  248. package/lib/Utils/messages.d.ts +9 -8
  249. package/lib/Utils/messages.d.ts.map +1 -0
  250. package/lib/Utils/messages.js +259 -228
  251. package/lib/Utils/messages.js.map +1 -0
  252. package/lib/Utils/noise-handler.d.ts +5 -4
  253. package/lib/Utils/noise-handler.d.ts.map +1 -0
  254. package/lib/Utils/noise-handler.js +22 -26
  255. package/lib/Utils/noise-handler.js.map +1 -0
  256. package/lib/Utils/process-message.d.ts +6 -5
  257. package/lib/Utils/process-message.d.ts.map +1 -0
  258. package/lib/Utils/process-message.js +109 -123
  259. package/lib/Utils/process-message.js.map +1 -0
  260. package/lib/Utils/signal.d.ts +5 -4
  261. package/lib/Utils/signal.d.ts.map +1 -0
  262. package/lib/Utils/signal.js +52 -55
  263. package/lib/Utils/signal.js.map +1 -0
  264. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  265. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  266. package/lib/Utils/use-multi-file-auth-state.js +23 -27
  267. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  268. package/lib/Utils/validate-connection.d.ts +4 -3
  269. package/lib/Utils/validate-connection.d.ts.map +1 -0
  270. package/lib/Utils/validate-connection.js +64 -75
  271. package/lib/Utils/validate-connection.js.map +1 -0
  272. package/lib/WABinary/constants.d.ts +5 -4
  273. package/lib/WABinary/constants.d.ts.map +1 -0
  274. package/lib/WABinary/constants.js +1280 -19
  275. package/lib/WABinary/constants.js.map +1 -0
  276. package/lib/WABinary/decode.d.ts +2 -1
  277. package/lib/WABinary/decode.d.ts.map +1 -0
  278. package/lib/WABinary/decode.js +15 -52
  279. package/lib/WABinary/decode.js.map +1 -0
  280. package/lib/WABinary/encode.d.ts +2 -1
  281. package/lib/WABinary/encode.d.ts.map +1 -0
  282. package/lib/WABinary/encode.js +7 -43
  283. package/lib/WABinary/encode.js.map +1 -0
  284. package/lib/WABinary/generic-utils.d.ts +4 -3
  285. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  286. package/lib/WABinary/generic-utils.js +31 -39
  287. package/lib/WABinary/generic-utils.js.map +1 -0
  288. package/lib/WABinary/index.d.ts +6 -5
  289. package/lib/WABinary/index.d.ts.map +1 -0
  290. package/lib/WABinary/index.js +6 -21
  291. package/lib/WABinary/index.js.map +1 -0
  292. package/lib/WABinary/jid-utils.d.ts +1 -0
  293. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  294. package/lib/WABinary/jid-utils.js +21 -38
  295. package/lib/WABinary/jid-utils.js.map +1 -0
  296. package/lib/WABinary/types.d.ts +2 -1
  297. package/lib/WABinary/types.d.ts.map +1 -0
  298. package/lib/WABinary/types.js +2 -2
  299. package/lib/WABinary/types.js.map +1 -0
  300. package/lib/WAM/BinaryInfo.d.ts +2 -1
  301. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  302. package/lib/WAM/BinaryInfo.js +2 -5
  303. package/lib/WAM/BinaryInfo.js.map +1 -0
  304. package/lib/WAM/constants.d.ts +1 -0
  305. package/lib/WAM/constants.d.ts.map +1 -0
  306. package/lib/WAM/constants.js +2257 -2366
  307. package/lib/WAM/constants.js.map +1 -0
  308. package/lib/WAM/encode.d.ts +2 -1
  309. package/lib/WAM/encode.d.ts.map +1 -0
  310. package/lib/WAM/encode.js +15 -19
  311. package/lib/WAM/encode.js.map +1 -0
  312. package/lib/WAM/index.d.ts +4 -3
  313. package/lib/WAM/index.d.ts.map +1 -0
  314. package/lib/WAM/index.js +4 -19
  315. package/lib/WAM/index.js.map +1 -0
  316. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
  317. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  318. package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
  319. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  320. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
  321. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  322. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
  323. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  324. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
  325. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  326. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
  327. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  328. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
  329. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  330. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
  331. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  332. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
  333. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  334. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
  335. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  336. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -2
  337. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  338. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -6
  339. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  340. package/lib/WAUSync/Protocols/index.d.ts +5 -4
  341. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  342. package/lib/WAUSync/Protocols/index.js +5 -20
  343. package/lib/WAUSync/Protocols/index.js.map +1 -0
  344. package/lib/WAUSync/USyncQuery.d.ts +4 -3
  345. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  346. package/lib/WAUSync/USyncQuery.js +34 -32
  347. package/lib/WAUSync/USyncQuery.js.map +1 -0
  348. package/lib/WAUSync/USyncUser.d.ts +6 -5
  349. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  350. package/lib/WAUSync/USyncUser.js +2 -5
  351. package/lib/WAUSync/USyncUser.js.map +1 -0
  352. package/lib/WAUSync/index.d.ts +4 -3
  353. package/lib/WAUSync/index.d.ts.map +1 -0
  354. package/lib/WAUSync/index.js +4 -19
  355. package/lib/WAUSync/index.js.map +1 -0
  356. package/lib/index.d.ts +9 -8
  357. package/lib/index.d.ts.map +1 -0
  358. package/lib/index.js +11 -30
  359. package/lib/index.js.map +1 -0
  360. package/package.json +36 -31
  361. package/WASignalGroup/GroupProtocol.js +0 -1697
  362. package/WASignalGroup/ciphertext_message.js +0 -16
  363. package/WASignalGroup/group_cipher.js +0 -120
  364. package/WASignalGroup/group_session_builder.js +0 -46
  365. package/WASignalGroup/index.js +0 -5
  366. package/WASignalGroup/keyhelper.js +0 -21
  367. package/WASignalGroup/protobufs.js +0 -3
  368. package/WASignalGroup/queue_job.js +0 -69
  369. package/WASignalGroup/sender_chain_key.js +0 -50
  370. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  371. package/WASignalGroup/sender_key_message.js +0 -92
  372. package/WASignalGroup/sender_key_name.js +0 -70
  373. package/WASignalGroup/sender_key_record.js +0 -56
  374. package/WASignalGroup/sender_key_state.js +0 -129
@@ -1,66 +1,63 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeSocket = void 0;
4
- const boom_1 = require("@hapi/boom");
5
- const crypto_1 = require("crypto");
6
- const url_1 = require("url");
7
- const util_1 = require("util");
8
- const WAProto_1 = require("../../WAProto");
9
- const Defaults_1 = require("../Defaults");
10
- const Types_1 = require("../Types");
11
- const Utils_1 = require("../Utils");
12
- const WABinary_1 = require("../WABinary");
13
- const Client_1 = require("./Client");
1
+ import { Boom } from '@hapi/boom';
2
+ import { randomBytes } from 'crypto';
3
+ import { URL } from 'url';
4
+ import { promisify } from 'util';
5
+ import { proto } from '../../WAProto/index.js';
6
+ import { DEF_CALLBACK_PREFIX, DEF_TAG_PREFIX, INITIAL_PREKEY_COUNT, MIN_PREKEY_COUNT, NOISE_WA_HEADER } from '../Defaults/index.js';
7
+ import { cleanupQueues } from '../Signal/Group/queue-job.js';
8
+ import { DisconnectReason } from '../Types/index.js';
9
+ import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, bytesToCrockford, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode, getCodeFromWSError, getErrorCodeFromStreamError, getNextPreKeysNode, getPlatformId, makeEventBuffer, makeNoiseHandler, promiseTimeout } from '../Utils/index.js';
10
+ import { assertNodeErrorFree, binaryNodeToString, encodeBinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidEncode, S_WHATSAPP_NET } from '../WABinary/index.js';
11
+ import { WebSocketClient } from './Client/index.js';
14
12
  /**
15
13
  * Connects to WA servers and performs:
16
14
  * - simple queries (no retry mechanism, wait for connection establishment)
17
15
  * - listen to messages and emit events
18
16
  * - query phone connection
19
17
  */
20
- const makeSocket = (config) => {
21
- var _a, _b;
22
- const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
18
+ export const makeSocket = (config) => {
19
+ const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository } = config;
23
20
  if (printQRInTerminal) {
24
21
  console.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.');
25
22
  }
26
- const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
23
+ const url = typeof waWebSocketUrl === 'string' ? new URL(waWebSocketUrl) : waWebSocketUrl;
27
24
  if (config.mobile || url.protocol === 'tcp:') {
28
- throw new boom_1.Boom('Mobile API is not supported anymore', { statusCode: Types_1.DisconnectReason.loggedOut });
25
+ throw new Boom('Mobile API is not supported anymore', { statusCode: DisconnectReason.loggedOut });
29
26
  }
30
- if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
27
+ if (url.protocol === 'wss' && authState?.creds?.routingInfo) {
31
28
  url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
32
29
  }
33
- const ws = new Client_1.WebSocketClient(url, config);
30
+ const ws = new WebSocketClient(url, config);
34
31
  ws.connect();
35
- const ev = (0, Utils_1.makeEventBuffer)(logger);
32
+ const ev = makeEventBuffer(logger);
36
33
  /** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
37
- const ephemeralKeyPair = Utils_1.Curve.generateKeyPair();
34
+ const ephemeralKeyPair = Curve.generateKeyPair();
38
35
  /** WA noise protocol wrapper */
39
- const noise = (0, Utils_1.makeNoiseHandler)({
36
+ const noise = makeNoiseHandler({
40
37
  keyPair: ephemeralKeyPair,
41
- NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
38
+ NOISE_HEADER: NOISE_WA_HEADER,
42
39
  logger,
43
- routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
40
+ routingInfo: authState?.creds?.routingInfo
44
41
  });
45
42
  const { creds } = authState;
46
43
  // add transaction capability
47
- const keys = (0, Utils_1.addTransactionCapability)(authState.keys, logger, transactionOpts);
44
+ const keys = addTransactionCapability(authState.keys, logger, transactionOpts);
48
45
  const signalRepository = makeSignalRepository({ creds, keys });
49
46
  let lastDateRecv;
50
47
  let epoch = 1;
51
48
  let keepAliveReq;
52
49
  let qrTimer;
53
50
  let closed = false;
54
- const uqTagId = (0, Utils_1.generateMdTagPrefix)();
51
+ const uqTagId = generateMdTagPrefix();
55
52
  const generateMessageTag = () => `${uqTagId}${epoch++}`;
56
- const sendPromise = (0, util_1.promisify)(ws.send);
53
+ const sendPromise = promisify(ws.send);
57
54
  /** send a raw buffer */
58
55
  const sendRawMessage = async (data) => {
59
56
  if (!ws.isOpen) {
60
- throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
57
+ throw new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed });
61
58
  }
62
59
  const bytes = noise.encodeFrame(data);
63
- await (0, Utils_1.promiseTimeout)(connectTimeoutMs, async (resolve, reject) => {
60
+ await promiseTimeout(connectTimeoutMs, async (resolve, reject) => {
64
61
  try {
65
62
  await sendPromise.call(ws, bytes);
66
63
  resolve();
@@ -73,9 +70,9 @@ const makeSocket = (config) => {
73
70
  /** send a binary node */
74
71
  const sendNode = (frame) => {
75
72
  if (logger.level === 'trace') {
76
- logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'xml send' });
73
+ logger.trace({ xml: binaryNodeToString(frame), msg: 'xml send' });
77
74
  }
78
- const buff = (0, WABinary_1.encodeBinaryNode)(frame);
75
+ const buff = encodeBinaryNode(frame);
79
76
  return sendRawMessage(buff);
80
77
  };
81
78
  /** log & process any unexpected errors */
@@ -85,20 +82,19 @@ const makeSocket = (config) => {
85
82
  /** await the next incoming message */
86
83
  const awaitNextMessage = async (sendMsg) => {
87
84
  if (!ws.isOpen) {
88
- throw new boom_1.Boom('Connection Closed', {
89
- statusCode: Types_1.DisconnectReason.connectionClosed
85
+ throw new Boom('Connection Closed', {
86
+ statusCode: DisconnectReason.connectionClosed
90
87
  });
91
88
  }
92
89
  let onOpen;
93
90
  let onClose;
94
- const result = (0, Utils_1.promiseTimeout)(connectTimeoutMs, (resolve, reject) => {
91
+ const result = promiseTimeout(connectTimeoutMs, (resolve, reject) => {
95
92
  onOpen = resolve;
96
93
  onClose = mapWebSocketError(reject);
97
94
  ws.on('frame', onOpen);
98
95
  ws.on('close', onClose);
99
96
  ws.on('error', onClose);
100
- })
101
- .finally(() => {
97
+ }).finally(() => {
102
98
  ws.off('frame', onOpen);
103
99
  ws.off('close', onClose);
104
100
  ws.off('error', onClose);
@@ -117,21 +113,38 @@ const makeSocket = (config) => {
117
113
  let onRecv;
118
114
  let onErr;
119
115
  try {
120
- const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
121
- onRecv = resolve;
116
+ const result = await promiseTimeout(timeoutMs, (resolve, reject) => {
117
+ onRecv = data => {
118
+ resolve(data);
119
+ };
122
120
  onErr = err => {
123
- reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
121
+ reject(err ||
122
+ new Boom('Connection Closed', {
123
+ statusCode: DisconnectReason.connectionClosed
124
+ }));
124
125
  };
125
126
  ws.on(`TAG:${msgId}`, onRecv);
126
- ws.on('close', onErr); // if the socket closes, you'll never receive the message
127
- ws.off('error', onErr);
127
+ ws.on('close', onErr);
128
+ ws.on('error', onErr);
129
+ return () => reject(new Boom('Query Cancelled'));
128
130
  });
129
131
  return result;
130
132
  }
133
+ catch (error) {
134
+ // Catch timeout and return undefined instead of throwing
135
+ if (error instanceof Boom && error.output?.statusCode === DisconnectReason.timedOut) {
136
+ logger?.warn?.({ msgId }, 'timed out waiting for message');
137
+ return undefined;
138
+ }
139
+ throw error;
140
+ }
131
141
  finally {
132
- ws.off(`TAG:${msgId}`, onRecv);
133
- ws.off('close', onErr); // if the socket closes, you'll never receive the message
134
- ws.off('error', onErr);
142
+ if (onRecv)
143
+ ws.off(`TAG:${msgId}`, onRecv);
144
+ if (onErr) {
145
+ ws.off('close', onErr);
146
+ ws.off('error', onErr);
147
+ }
135
148
  }
136
149
  };
137
150
  /** send a query, and wait for its response. auto-generates message ID if not provided */
@@ -140,12 +153,14 @@ const makeSocket = (config) => {
140
153
  node.attrs.id = generateMessageTag();
141
154
  }
142
155
  const msgId = node.attrs.id;
143
- const [result] = await Promise.all([
144
- waitForMessage(msgId, timeoutMs),
156
+ const result = await promiseTimeout(timeoutMs, async (resolve, reject) => {
157
+ const result = await waitForMessage(msgId, timeoutMs).catch(reject);
145
158
  sendNode(node)
146
- ]);
147
- if ('tag' in result) {
148
- (0, WABinary_1.assertNodeErrorFree)(result);
159
+ .then(() => resolve(result))
160
+ .catch(reject);
161
+ });
162
+ if (result && 'tag' in result) {
163
+ assertNodeErrorFree(result);
149
164
  }
150
165
  return result;
151
166
  };
@@ -154,28 +169,28 @@ const makeSocket = (config) => {
154
169
  let helloMsg = {
155
170
  clientHello: { ephemeral: ephemeralKeyPair.public }
156
171
  };
157
- helloMsg = WAProto_1.proto.HandshakeMessage.fromObject(helloMsg);
172
+ helloMsg = proto.HandshakeMessage.fromObject(helloMsg);
158
173
  logger.info({ browser, helloMsg }, 'connected to WA');
159
- const init = WAProto_1.proto.HandshakeMessage.encode(helloMsg).finish();
174
+ const init = proto.HandshakeMessage.encode(helloMsg).finish();
160
175
  const result = await awaitNextMessage(init);
161
- const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
176
+ const handshake = proto.HandshakeMessage.decode(result);
162
177
  logger.trace({ handshake }, 'handshake recv from WA');
163
178
  const keyEnc = await noise.processHandshake(handshake, creds.noiseKey);
164
179
  let node;
165
180
  if (!creds.me) {
166
- node = (0, Utils_1.generateRegistrationNode)(creds, config);
181
+ node = generateRegistrationNode(creds, config);
167
182
  logger.info({ node }, 'not logged in, attempting registration...');
168
183
  }
169
184
  else {
170
- node = (0, Utils_1.generateLoginNode)(creds.me.id, config);
185
+ node = generateLoginNode(creds.me.id, config);
171
186
  logger.info({ node }, 'logging in...');
172
187
  }
173
- const payloadEnc = noise.encrypt(WAProto_1.proto.ClientPayload.encode(node).finish());
174
- await sendRawMessage(WAProto_1.proto.HandshakeMessage.encode({
188
+ const payloadEnc = noise.encrypt(proto.ClientPayload.encode(node).finish());
189
+ await sendRawMessage(proto.HandshakeMessage.encode({
175
190
  clientFinish: {
176
191
  static: keyEnc,
177
- payload: payloadEnc,
178
- },
192
+ payload: payloadEnc
193
+ }
179
194
  }).finish());
180
195
  noise.finishInit();
181
196
  startKeepAliveRequest();
@@ -187,20 +202,18 @@ const makeSocket = (config) => {
187
202
  id: generateMessageTag(),
188
203
  xmlns: 'encrypt',
189
204
  type: 'get',
190
- to: WABinary_1.S_WHATSAPP_NET
205
+ to: S_WHATSAPP_NET
191
206
  },
192
- content: [
193
- { tag: 'count', attrs: {} }
194
- ]
207
+ content: [{ tag: 'count', attrs: {} }]
195
208
  });
196
- const countChild = (0, WABinary_1.getBinaryNodeChild)(result, 'count');
209
+ const countChild = getBinaryNodeChild(result, 'count');
197
210
  return +countChild.attrs.value;
198
211
  };
199
212
  /** generates and uploads a set of pre-keys to the server */
200
- const uploadPreKeys = async (count = Defaults_1.INITIAL_PREKEY_COUNT) => {
213
+ const uploadPreKeys = async (count = INITIAL_PREKEY_COUNT) => {
201
214
  await keys.transaction(async () => {
202
215
  logger.info({ count }, 'uploading pre-keys');
203
- const { update, node } = await (0, Utils_1.getNextPreKeysNode)({ creds, keys }, count);
216
+ const { update, node } = await getNextPreKeysNode({ creds, keys }, count);
204
217
  await query(node);
205
218
  ev.emit('creds.update', update);
206
219
  logger.info({ count }, 'uploaded pre-keys');
@@ -209,13 +222,12 @@ const makeSocket = (config) => {
209
222
  const uploadPreKeysToServerIfRequired = async () => {
210
223
  const preKeyCount = await getAvailablePreKeysOnServer();
211
224
  logger.info(`${preKeyCount} pre-keys found on server`);
212
- if (preKeyCount <= Defaults_1.MIN_PREKEY_COUNT) {
225
+ if (preKeyCount <= MIN_PREKEY_COUNT) {
213
226
  await uploadPreKeys();
214
227
  }
215
228
  };
216
229
  const onMessageReceived = (data) => {
217
230
  noise.decodeFrame(data, frame => {
218
- var _a;
219
231
  // reset ping timeout
220
232
  lastDateRecv = new Date();
221
233
  let anyTriggered = false;
@@ -224,21 +236,21 @@ const makeSocket = (config) => {
224
236
  if (!(frame instanceof Uint8Array)) {
225
237
  const msgId = frame.attrs.id;
226
238
  if (logger.level === 'trace') {
227
- logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'recv xml' });
239
+ logger.trace({ xml: binaryNodeToString(frame), msg: 'recv xml' });
228
240
  }
229
241
  /* Check if this is a response to a message we sent */
230
- anyTriggered = ws.emit(`${Defaults_1.DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
242
+ anyTriggered = ws.emit(`${DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
231
243
  /* Check if this is a response to a message we are expecting */
232
244
  const l0 = frame.tag;
233
245
  const l1 = frame.attrs || {};
234
- const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
246
+ const l2 = Array.isArray(frame.content) ? frame.content[0]?.tag : '';
235
247
  for (const key of Object.keys(l1)) {
236
- anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
237
- anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
238
- anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
248
+ anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
249
+ anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
250
+ anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
239
251
  }
240
- anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
241
- anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
252
+ anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
253
+ anyTriggered = ws.emit(`${DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
242
254
  if (!anyTriggered && logger.level === 'debug') {
243
255
  logger.debug({ unhandled: true, msgId, fromMe: false, frame }, 'communication recv');
244
256
  }
@@ -247,22 +259,22 @@ const makeSocket = (config) => {
247
259
  };
248
260
  const end = (error) => {
249
261
  if (closed) {
250
- logger.trace({ trace: error === null || error === void 0 ? void 0 : error.stack }, 'connection already closed');
262
+ logger.trace({ trace: error?.stack }, 'connection already closed');
251
263
  return;
252
264
  }
265
+ cleanupQueues();
253
266
  closed = true;
254
- logger.info({ trace: error === null || error === void 0 ? void 0 : error.stack }, error ? 'connection errored' : 'connection closed');
267
+ logger.info({ trace: error?.stack }, error ? 'connection errored' : 'connection closed');
255
268
  clearInterval(keepAliveReq);
256
269
  clearTimeout(qrTimer);
257
270
  ws.removeAllListeners('close');
258
- ws.removeAllListeners('error');
259
271
  ws.removeAllListeners('open');
260
272
  ws.removeAllListeners('message');
261
273
  if (!ws.isClosed && !ws.isClosing) {
262
274
  try {
263
275
  ws.close();
264
276
  }
265
- catch (_a) { }
277
+ catch { }
266
278
  }
267
279
  ev.emit('connection.update', {
268
280
  connection: 'close',
@@ -278,7 +290,7 @@ const makeSocket = (config) => {
278
290
  return;
279
291
  }
280
292
  if (ws.isClosed || ws.isClosing) {
281
- throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
293
+ throw new Boom('Connection Closed', { statusCode: DisconnectReason.connectionClosed });
282
294
  }
283
295
  let onOpen;
284
296
  let onClose;
@@ -288,8 +300,7 @@ const makeSocket = (config) => {
288
300
  ws.on('open', onOpen);
289
301
  ws.on('close', onClose);
290
302
  ws.on('error', onClose);
291
- })
292
- .finally(() => {
303
+ }).finally(() => {
293
304
  ws.off('open', onOpen);
294
305
  ws.off('close', onClose);
295
306
  ws.off('error', onClose);
@@ -305,7 +316,7 @@ const makeSocket = (config) => {
305
316
  it could be that the network is down
306
317
  */
307
318
  if (diff > keepAliveIntervalMs + 5000) {
308
- end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
319
+ end(new Boom('Connection was lost', { statusCode: DisconnectReason.connectionLost }));
309
320
  }
310
321
  else if (ws.isOpen) {
311
322
  // if its all good, send a keep alive request
@@ -313,13 +324,12 @@ const makeSocket = (config) => {
313
324
  tag: 'iq',
314
325
  attrs: {
315
326
  id: generateMessageTag(),
316
- to: WABinary_1.S_WHATSAPP_NET,
327
+ to: S_WHATSAPP_NET,
317
328
  type: 'get',
318
- xmlns: 'w:p',
329
+ xmlns: 'w:p'
319
330
  },
320
331
  content: [{ tag: 'ping', attrs: {} }]
321
- })
322
- .catch(err => {
332
+ }).catch(err => {
323
333
  logger.error({ trace: err.stack }, 'error in sending keep alive');
324
334
  });
325
335
  }
@@ -328,26 +338,23 @@ const makeSocket = (config) => {
328
338
  }
329
339
  }, keepAliveIntervalMs));
330
340
  /** i have no idea why this exists. pls enlighten me */
331
- const sendPassiveIq = (tag) => (query({
341
+ const sendPassiveIq = (tag) => query({
332
342
  tag: 'iq',
333
343
  attrs: {
334
- to: WABinary_1.S_WHATSAPP_NET,
344
+ to: S_WHATSAPP_NET,
335
345
  xmlns: 'passive',
336
- type: 'set',
346
+ type: 'set'
337
347
  },
338
- content: [
339
- { tag, attrs: {} }
340
- ]
341
- }));
348
+ content: [{ tag, attrs: {} }]
349
+ });
342
350
  /** logout & invalidate connection */
343
351
  const logout = async (msg) => {
344
- var _a;
345
- const jid = (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id;
352
+ const jid = authState.creds.me?.id;
346
353
  if (jid) {
347
354
  await sendNode({
348
355
  tag: 'iq',
349
356
  attrs: {
350
- to: WABinary_1.S_WHATSAPP_NET,
357
+ to: S_WHATSAPP_NET,
351
358
  type: 'set',
352
359
  id: generateMessageTag(),
353
360
  xmlns: 'md'
@@ -363,19 +370,23 @@ const makeSocket = (config) => {
363
370
  ]
364
371
  });
365
372
  }
366
- end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
373
+ end(new Boom(msg || 'Intentional Logout', { statusCode: DisconnectReason.loggedOut }));
367
374
  };
368
- const requestPairingCode = async (phoneNumber) => {
369
- authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
375
+ const requestPairingCode = async (phoneNumber, customPairingCode) => {
376
+ const pairingCode = customPairingCode ?? bytesToCrockford(randomBytes(5));
377
+ if (customPairingCode && customPairingCode?.length !== 8) {
378
+ throw new Error('Custom pairing code must be exactly 8 chars');
379
+ }
380
+ authState.creds.pairingCode = pairingCode;
370
381
  authState.creds.me = {
371
- id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
382
+ id: jidEncode(phoneNumber, 's.whatsapp.net'),
372
383
  name: '~'
373
384
  };
374
385
  ev.emit('creds.update', authState.creds);
375
386
  await sendNode({
376
387
  tag: 'iq',
377
388
  attrs: {
378
- to: WABinary_1.S_WHATSAPP_NET,
389
+ to: S_WHATSAPP_NET,
379
390
  type: 'set',
380
391
  id: generateMessageTag(),
381
392
  xmlns: 'md'
@@ -386,7 +397,6 @@ const makeSocket = (config) => {
386
397
  attrs: {
387
398
  jid: authState.creds.me.id,
388
399
  stage: 'companion_hello',
389
- // eslint-disable-next-line camelcase
390
400
  should_show_push_notification: 'true'
391
401
  },
392
402
  content: [
@@ -403,7 +413,7 @@ const makeSocket = (config) => {
403
413
  {
404
414
  tag: 'companion_platform_id',
405
415
  attrs: {},
406
- content: (0, Utils_1.getPlatformId)(browser[1])
416
+ content: getPlatformId(browser[1])
407
417
  },
408
418
  {
409
419
  tag: 'companion_platform_display',
@@ -422,17 +432,17 @@ const makeSocket = (config) => {
422
432
  return authState.creds.pairingCode;
423
433
  };
424
434
  async function generatePairingKey() {
425
- const salt = (0, crypto_1.randomBytes)(32);
426
- const randomIv = (0, crypto_1.randomBytes)(16);
427
- const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
428
- const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
435
+ const salt = randomBytes(32);
436
+ const randomIv = randomBytes(16);
437
+ const key = await derivePairingCodeKey(authState.creds.pairingCode, salt);
438
+ const ciphered = aesEncryptCTR(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
429
439
  return Buffer.concat([salt, randomIv, ciphered]);
430
440
  }
431
441
  const sendWAMBuffer = (wamBuffer) => {
432
442
  return query({
433
443
  tag: 'iq',
434
444
  attrs: {
435
- to: WABinary_1.S_WHATSAPP_NET,
445
+ to: S_WHATSAPP_NET,
436
446
  id: generateMessageTag(),
437
447
  xmlns: 'w:stats'
438
448
  },
@@ -456,22 +466,22 @@ const makeSocket = (config) => {
456
466
  }
457
467
  });
458
468
  ws.on('error', mapWebSocketError(end));
459
- ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
469
+ ws.on('close', () => end(new Boom('Connection Terminated', { statusCode: DisconnectReason.connectionClosed })));
460
470
  // the server terminated the connection
461
- ws.on('CB:xmlstreamend', () => end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
471
+ ws.on('CB:xmlstreamend', () => end(new Boom('Connection Terminated by Server', { statusCode: DisconnectReason.connectionClosed })));
462
472
  // QR gen
463
473
  ws.on('CB:iq,type:set,pair-device', async (stanza) => {
464
474
  const iq = {
465
475
  tag: 'iq',
466
476
  attrs: {
467
- to: WABinary_1.S_WHATSAPP_NET,
477
+ to: S_WHATSAPP_NET,
468
478
  type: 'result',
469
- id: stanza.attrs.id,
479
+ id: stanza.attrs.id
470
480
  }
471
481
  };
472
482
  await sendNode(iq);
473
- const pairDeviceNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-device');
474
- const refNodes = (0, WABinary_1.getBinaryNodeChildren)(pairDeviceNode, 'ref');
483
+ const pairDeviceNode = getBinaryNodeChild(stanza, 'pair-device');
484
+ const refNodes = getBinaryNodeChildren(pairDeviceNode, 'ref');
475
485
  const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
476
486
  const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64');
477
487
  const advB64 = creds.advSecretKey;
@@ -482,7 +492,7 @@ const makeSocket = (config) => {
482
492
  }
483
493
  const refNode = refNodes.shift();
484
494
  if (!refNode) {
485
- end(new boom_1.Boom('QR refs attempts ended', { statusCode: Types_1.DisconnectReason.timedOut }));
495
+ end(new Boom('QR refs attempts ended', { statusCode: DisconnectReason.timedOut }));
486
496
  return;
487
497
  }
488
498
  const ref = refNode.content.toString('utf-8');
@@ -498,7 +508,7 @@ const makeSocket = (config) => {
498
508
  ws.on('CB:iq,,pair-success', async (stanza) => {
499
509
  logger.debug('pair success recv');
500
510
  try {
501
- const { reply, creds: updatedCreds } = (0, Utils_1.configureSuccessfulPairing)(stanza, creds);
511
+ const { reply, creds: updatedCreds } = configureSuccessfulPairing(stanza, creds);
502
512
  logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...');
503
513
  ev.emit('creds.update', updatedCreds);
504
514
  ev.emit('connection.update', { isNewLogin: true, qr: undefined });
@@ -511,8 +521,13 @@ const makeSocket = (config) => {
511
521
  });
512
522
  // login complete
513
523
  ws.on('CB:success', async (node) => {
514
- await uploadPreKeysToServerIfRequired();
515
- await sendPassiveIq('active');
524
+ try {
525
+ await uploadPreKeysToServerIfRequired();
526
+ await sendPassiveIq('active');
527
+ }
528
+ catch (err) {
529
+ logger.warn({ err }, 'failed to send initial passive iq');
530
+ }
516
531
  logger.info('opened connection to WA');
517
532
  clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
518
533
  ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
@@ -520,16 +535,16 @@ const makeSocket = (config) => {
520
535
  });
521
536
  ws.on('CB:stream:error', (node) => {
522
537
  logger.error({ node }, 'stream errored out');
523
- const { reason, statusCode } = (0, Utils_1.getErrorCodeFromStreamError)(node);
524
- end(new boom_1.Boom(`Stream Errored (${reason})`, { statusCode, data: node }));
538
+ const { reason, statusCode } = getErrorCodeFromStreamError(node);
539
+ end(new Boom(`Stream Errored (${reason})`, { statusCode, data: node }));
525
540
  });
526
541
  // stream fail, possible logout
527
542
  ws.on('CB:failure', (node) => {
528
543
  const reason = +(node.attrs.reason || 500);
529
- end(new boom_1.Boom('Connection Failure', { statusCode: reason, data: node.attrs }));
544
+ end(new Boom('Connection Failure', { statusCode: reason, data: node.attrs }));
530
545
  });
531
546
  ws.on('CB:ib,,downgrade_webclient', () => {
532
- end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
547
+ end(new Boom('Multi-device beta not joined', { statusCode: DisconnectReason.multideviceMismatch }));
533
548
  });
534
549
  ws.on('CB:ib,,offline_preview', (node) => {
535
550
  logger.info('offline preview received', JSON.stringify(node));
@@ -540,17 +555,16 @@ const makeSocket = (config) => {
540
555
  });
541
556
  });
542
557
  ws.on('CB:ib,,edge_routing', (node) => {
543
- const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
544
- const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
545
- if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
546
- authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
558
+ const edgeRoutingNode = getBinaryNodeChild(node, 'edge_routing');
559
+ const routingInfo = getBinaryNodeChild(edgeRoutingNode, 'routing_info');
560
+ if (routingInfo?.content) {
561
+ authState.creds.routingInfo = Buffer.from(routingInfo?.content);
547
562
  ev.emit('creds.update', authState.creds);
548
563
  }
549
564
  });
550
565
  let didStartBuffer = false;
551
566
  process.nextTick(() => {
552
- var _a;
553
- if ((_a = creds.me) === null || _a === void 0 ? void 0 : _a.id) {
567
+ if (creds.me?.id) {
554
568
  // start buffering important events
555
569
  // if we're logged in
556
570
  ev.buffer();
@@ -560,8 +574,8 @@ const makeSocket = (config) => {
560
574
  });
561
575
  // called when all offline notifs are handled
562
576
  ws.on('CB:ib,,offline', (node) => {
563
- const child = (0, WABinary_1.getBinaryNodeChild)(node, 'offline');
564
- const offlineNotifs = +((child === null || child === void 0 ? void 0 : child.attrs.count) || 0);
577
+ const child = getBinaryNodeChild(node, 'offline');
578
+ const offlineNotifs = +(child?.attrs.count || 0);
565
579
  logger.info(`handled ${offlineNotifs} offline messages/notifications`);
566
580
  if (didStartBuffer) {
567
581
  ev.flush();
@@ -571,16 +585,14 @@ const makeSocket = (config) => {
571
585
  });
572
586
  // update credentials when required
573
587
  ev.on('creds.update', update => {
574
- var _a, _b;
575
- const name = (_a = update.me) === null || _a === void 0 ? void 0 : _a.name;
588
+ const name = update.me?.name;
576
589
  // if name has just been received
577
- if (((_b = creds.me) === null || _b === void 0 ? void 0 : _b.name) !== name) {
590
+ if (creds.me?.name !== name) {
578
591
  logger.debug({ name }, 'updated pushName');
579
592
  sendNode({
580
593
  tag: 'presence',
581
594
  attrs: { name: name }
582
- })
583
- .catch(err => {
595
+ }).catch(err => {
584
596
  logger.warn({ trace: err.stack }, 'error in sending presence update on name change');
585
597
  });
586
598
  }
@@ -608,17 +620,17 @@ const makeSocket = (config) => {
608
620
  uploadPreKeysToServerIfRequired,
609
621
  requestPairingCode,
610
622
  /** Waits for the connection to WA to reach a state */
611
- waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
612
- sendWAMBuffer,
623
+ waitForConnectionUpdate: bindWaitForConnectionUpdate(ev),
624
+ sendWAMBuffer
613
625
  };
614
626
  };
615
- exports.makeSocket = makeSocket;
616
627
  /**
617
628
  * map the websocket error to the right type
618
629
  * so it can be retried by the caller
619
630
  * */
620
631
  function mapWebSocketError(handler) {
621
632
  return (error) => {
622
- handler(new boom_1.Boom(`WebSocket Error (${error === null || error === void 0 ? void 0 : error.message})`, { statusCode: (0, Utils_1.getCodeFromWSError)(error), data: error }));
633
+ handler(new Boom(`WebSocket Error (${error?.message})`, { statusCode: getCodeFromWSError(error), data: error }));
623
634
  };
624
635
  }
636
+ //# sourceMappingURL=socket.js.map