@lynovratech/baileys 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (787) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1312 -0
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +5479 -0
  5. package/WAProto/fix-imports.js +81 -0
  6. package/WAProto/index.d.ts +14017 -0
  7. package/WAProto/index.js +97687 -0
  8. package/engine-requirements.js +10 -0
  9. package/lib/cjs/Defaults/index.d.ts +74 -0
  10. package/lib/cjs/Defaults/index.d.ts.map +1 -0
  11. package/lib/cjs/Defaults/index.js +134 -0
  12. package/lib/cjs/Defaults/index.js.map +1 -0
  13. package/lib/cjs/Signal/Group/ciphertext-message.d.ts +10 -0
  14. package/lib/cjs/Signal/Group/ciphertext-message.d.ts.map +1 -0
  15. package/lib/cjs/Signal/Group/ciphertext-message.js +16 -0
  16. package/lib/cjs/Signal/Group/ciphertext-message.js.map +1 -0
  17. package/lib/cjs/Signal/Group/group-session-builder.d.ts +15 -0
  18. package/lib/cjs/Signal/Group/group-session-builder.d.ts.map +1 -0
  19. package/lib/cjs/Signal/Group/group-session-builder.js +65 -0
  20. package/lib/cjs/Signal/Group/group-session-builder.js.map +1 -0
  21. package/lib/cjs/Signal/Group/group_cipher.d.ts +17 -0
  22. package/lib/cjs/Signal/Group/group_cipher.d.ts.map +1 -0
  23. package/lib/cjs/Signal/Group/group_cipher.js +83 -0
  24. package/lib/cjs/Signal/Group/group_cipher.js.map +1 -0
  25. package/lib/cjs/Signal/Group/index.d.ts +12 -0
  26. package/lib/cjs/Signal/Group/index.d.ts.map +1 -0
  27. package/lib/cjs/Signal/Group/index.js +58 -0
  28. package/lib/cjs/Signal/Group/index.js.map +1 -0
  29. package/lib/cjs/Signal/Group/keyhelper.d.ts +11 -0
  30. package/lib/cjs/Signal/Group/keyhelper.d.ts.map +1 -0
  31. package/lib/cjs/Signal/Group/keyhelper.js +56 -0
  32. package/lib/cjs/Signal/Group/keyhelper.js.map +1 -0
  33. package/lib/cjs/Signal/Group/sender-chain-key.d.ts +14 -0
  34. package/lib/cjs/Signal/Group/sender-chain-key.d.ts.map +1 -0
  35. package/lib/cjs/Signal/Group/sender-chain-key.js +30 -0
  36. package/lib/cjs/Signal/Group/sender-chain-key.js.map +1 -0
  37. package/lib/cjs/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  38. package/lib/cjs/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  39. package/lib/cjs/Signal/Group/sender-key-distribution-message.js +67 -0
  40. package/lib/cjs/Signal/Group/sender-key-distribution-message.js.map +1 -0
  41. package/lib/cjs/Signal/Group/sender-key-message.d.ts +19 -0
  42. package/lib/cjs/Signal/Group/sender-key-message.d.ts.map +1 -0
  43. package/lib/cjs/Signal/Group/sender-key-message.js +70 -0
  44. package/lib/cjs/Signal/Group/sender-key-message.js.map +1 -0
  45. package/lib/cjs/Signal/Group/sender-key-name.d.ts +18 -0
  46. package/lib/cjs/Signal/Group/sender-key-name.d.ts.map +1 -0
  47. package/lib/cjs/Signal/Group/sender-key-name.js +52 -0
  48. package/lib/cjs/Signal/Group/sender-key-name.js.map +1 -0
  49. package/lib/cjs/Signal/Group/sender-key-record.d.ts +31 -0
  50. package/lib/cjs/Signal/Group/sender-key-record.d.ts.map +1 -0
  51. package/lib/cjs/Signal/Group/sender-key-record.js +45 -0
  52. package/lib/cjs/Signal/Group/sender-key-record.js.map +1 -0
  53. package/lib/cjs/Signal/Group/sender-key-state.d.ts +39 -0
  54. package/lib/cjs/Signal/Group/sender-key-state.d.ts.map +1 -0
  55. package/lib/cjs/Signal/Group/sender-key-state.js +88 -0
  56. package/lib/cjs/Signal/Group/sender-key-state.js.map +1 -0
  57. package/lib/cjs/Signal/Group/sender-message-key.d.ts +12 -0
  58. package/lib/cjs/Signal/Group/sender-message-key.d.ts.map +1 -0
  59. package/lib/cjs/Signal/Group/sender-message-key.js +30 -0
  60. package/lib/cjs/Signal/Group/sender-message-key.js.map +1 -0
  61. package/lib/cjs/Signal/jid-mapping.d.ts +50 -0
  62. package/lib/cjs/Signal/jid-mapping.d.ts.map +1 -0
  63. package/lib/cjs/Signal/jid-mapping.js +218 -0
  64. package/lib/cjs/Signal/jid-mapping.js.map +1 -0
  65. package/lib/cjs/Signal/libsignal.d.ts +7 -0
  66. package/lib/cjs/Signal/libsignal.d.ts.map +1 -0
  67. package/lib/cjs/Signal/libsignal.js +447 -0
  68. package/lib/cjs/Signal/libsignal.js.map +1 -0
  69. package/lib/cjs/Signal/lid-mapping.d.ts +6 -0
  70. package/lib/cjs/Signal/lid-mapping.d.ts.map +1 -0
  71. package/lib/cjs/Signal/lid-mapping.js +10 -0
  72. package/lib/cjs/Signal/lid-mapping.js.map +1 -0
  73. package/lib/cjs/Socket/Client/index.d.ts +3 -0
  74. package/lib/cjs/Socket/Client/index.d.ts.map +1 -0
  75. package/lib/cjs/Socket/Client/index.js +19 -0
  76. package/lib/cjs/Socket/Client/index.js.map +1 -0
  77. package/lib/cjs/Socket/Client/types.d.ts +16 -0
  78. package/lib/cjs/Socket/Client/types.d.ts.map +1 -0
  79. package/lib/cjs/Socket/Client/types.js +14 -0
  80. package/lib/cjs/Socket/Client/types.js.map +1 -0
  81. package/lib/cjs/Socket/Client/websocket.d.ts +13 -0
  82. package/lib/cjs/Socket/Client/websocket.d.ts.map +1 -0
  83. package/lib/cjs/Socket/Client/websocket.js +61 -0
  84. package/lib/cjs/Socket/Client/websocket.js.map +1 -0
  85. package/lib/cjs/Socket/business.d.ts +202 -0
  86. package/lib/cjs/Socket/business.d.ts.map +1 -0
  87. package/lib/cjs/Socket/business.js +383 -0
  88. package/lib/cjs/Socket/business.js.map +1 -0
  89. package/lib/cjs/Socket/chats.d.ts +111 -0
  90. package/lib/cjs/Socket/chats.d.ts.map +1 -0
  91. package/lib/cjs/Socket/chats.js +1006 -0
  92. package/lib/cjs/Socket/chats.js.map +1 -0
  93. package/lib/cjs/Socket/communities.d.ts +258 -0
  94. package/lib/cjs/Socket/communities.d.ts.map +1 -0
  95. package/lib/cjs/Socket/communities.js +439 -0
  96. package/lib/cjs/Socket/communities.js.map +1 -0
  97. package/lib/cjs/Socket/groups.d.ts +150 -0
  98. package/lib/cjs/Socket/groups.d.ts.map +1 -0
  99. package/lib/cjs/Socket/groups.js +335 -0
  100. package/lib/cjs/Socket/groups.js.map +1 -0
  101. package/lib/cjs/Socket/index.d.ts +245 -0
  102. package/lib/cjs/Socket/index.d.ts.map +1 -0
  103. package/lib/cjs/Socket/index.js +14 -0
  104. package/lib/cjs/Socket/index.js.map +1 -0
  105. package/lib/cjs/Socket/messages-recv.d.ts +187 -0
  106. package/lib/cjs/Socket/messages-recv.d.ts.map +1 -0
  107. package/lib/cjs/Socket/messages-recv.js +1325 -0
  108. package/lib/cjs/Socket/messages-recv.js.map +1 -0
  109. package/lib/cjs/Socket/messages-send.d.ts +183 -0
  110. package/lib/cjs/Socket/messages-send.d.ts.map +1 -0
  111. package/lib/cjs/Socket/messages-send.js +1046 -0
  112. package/lib/cjs/Socket/messages-send.js.map +1 -0
  113. package/lib/cjs/Socket/mex.d.ts +3 -0
  114. package/lib/cjs/Socket/mex.d.ts.map +1 -0
  115. package/lib/cjs/Socket/mex.js +46 -0
  116. package/lib/cjs/Socket/mex.js.map +1 -0
  117. package/lib/cjs/Socket/newsletter.d.ts +160 -0
  118. package/lib/cjs/Socket/newsletter.d.ts.map +1 -0
  119. package/lib/cjs/Socket/newsletter.js +185 -0
  120. package/lib/cjs/Socket/newsletter.js.map +1 -0
  121. package/lib/cjs/Socket/socket.d.ts +55 -0
  122. package/lib/cjs/Socket/socket.d.ts.map +1 -0
  123. package/lib/cjs/Socket/socket.js +940 -0
  124. package/lib/cjs/Socket/socket.js.map +1 -0
  125. package/lib/cjs/Types/Auth.d.ts +126 -0
  126. package/lib/cjs/Types/Auth.d.ts.map +1 -0
  127. package/lib/cjs/Types/Auth.js +3 -0
  128. package/lib/cjs/Types/Auth.js.map +1 -0
  129. package/lib/cjs/Types/Bussines.d.ts +25 -0
  130. package/lib/cjs/Types/Bussines.d.ts.map +1 -0
  131. package/lib/cjs/Types/Bussines.js +3 -0
  132. package/lib/cjs/Types/Bussines.js.map +1 -0
  133. package/lib/cjs/Types/Call.d.ts +15 -0
  134. package/lib/cjs/Types/Call.d.ts.map +1 -0
  135. package/lib/cjs/Types/Call.js +3 -0
  136. package/lib/cjs/Types/Call.js.map +1 -0
  137. package/lib/cjs/Types/Chat.d.ts +123 -0
  138. package/lib/cjs/Types/Chat.d.ts.map +1 -0
  139. package/lib/cjs/Types/Chat.js +11 -0
  140. package/lib/cjs/Types/Chat.js.map +1 -0
  141. package/lib/cjs/Types/Contact.d.ts +24 -0
  142. package/lib/cjs/Types/Contact.d.ts.map +1 -0
  143. package/lib/cjs/Types/Contact.js +3 -0
  144. package/lib/cjs/Types/Contact.js.map +1 -0
  145. package/lib/cjs/Types/Events.d.ts +241 -0
  146. package/lib/cjs/Types/Events.d.ts.map +1 -0
  147. package/lib/cjs/Types/Events.js +3 -0
  148. package/lib/cjs/Types/Events.js.map +1 -0
  149. package/lib/cjs/Types/GroupMetadata.d.ts +67 -0
  150. package/lib/cjs/Types/GroupMetadata.d.ts.map +1 -0
  151. package/lib/cjs/Types/GroupMetadata.js +3 -0
  152. package/lib/cjs/Types/GroupMetadata.js.map +1 -0
  153. package/lib/cjs/Types/Label.d.ts +47 -0
  154. package/lib/cjs/Types/Label.d.ts.map +1 -0
  155. package/lib/cjs/Types/Label.js +28 -0
  156. package/lib/cjs/Types/Label.js.map +1 -0
  157. package/lib/cjs/Types/LabelAssociation.d.ts +30 -0
  158. package/lib/cjs/Types/LabelAssociation.d.ts.map +1 -0
  159. package/lib/cjs/Types/LabelAssociation.js +10 -0
  160. package/lib/cjs/Types/LabelAssociation.js.map +1 -0
  161. package/lib/cjs/Types/Message.d.ts +310 -0
  162. package/lib/cjs/Types/Message.d.ts.map +1 -0
  163. package/lib/cjs/Types/Message.js +16 -0
  164. package/lib/cjs/Types/Message.js.map +1 -0
  165. package/lib/cjs/Types/Newsletter.d.ts +135 -0
  166. package/lib/cjs/Types/Newsletter.d.ts.map +1 -0
  167. package/lib/cjs/Types/Newsletter.js +34 -0
  168. package/lib/cjs/Types/Newsletter.js.map +1 -0
  169. package/lib/cjs/Types/Product.d.ts +79 -0
  170. package/lib/cjs/Types/Product.d.ts.map +1 -0
  171. package/lib/cjs/Types/Product.js +3 -0
  172. package/lib/cjs/Types/Product.js.map +1 -0
  173. package/lib/cjs/Types/Signal.d.ts +76 -0
  174. package/lib/cjs/Types/Signal.d.ts.map +1 -0
  175. package/lib/cjs/Types/Signal.js +3 -0
  176. package/lib/cjs/Types/Signal.js.map +1 -0
  177. package/lib/cjs/Types/Socket.d.ts +135 -0
  178. package/lib/cjs/Types/Socket.d.ts.map +1 -0
  179. package/lib/cjs/Types/Socket.js +3 -0
  180. package/lib/cjs/Types/Socket.js.map +1 -0
  181. package/lib/cjs/Types/State.d.ts +39 -0
  182. package/lib/cjs/Types/State.d.ts.map +1 -0
  183. package/lib/cjs/Types/State.js +15 -0
  184. package/lib/cjs/Types/State.js.map +1 -0
  185. package/lib/cjs/Types/USync.d.ts +26 -0
  186. package/lib/cjs/Types/USync.d.ts.map +1 -0
  187. package/lib/cjs/Types/USync.js +3 -0
  188. package/lib/cjs/Types/USync.js.map +1 -0
  189. package/lib/cjs/Types/index.d.ts +65 -0
  190. package/lib/cjs/Types/index.d.ts.map +1 -0
  191. package/lib/cjs/Types/index.js +43 -0
  192. package/lib/cjs/Types/index.js.map +1 -0
  193. package/lib/cjs/Utils/auth-utils.d.ts +19 -0
  194. package/lib/cjs/Utils/auth-utils.d.ts.map +1 -0
  195. package/lib/cjs/Utils/auth-utils.js +299 -0
  196. package/lib/cjs/Utils/auth-utils.js.map +1 -0
  197. package/lib/cjs/Utils/browser-utils.d.ts +4 -0
  198. package/lib/cjs/Utils/browser-utils.d.ts.map +1 -0
  199. package/lib/cjs/Utils/browser-utils.js +32 -0
  200. package/lib/cjs/Utils/browser-utils.js.map +1 -0
  201. package/lib/cjs/Utils/business.d.ts +23 -0
  202. package/lib/cjs/Utils/business.d.ts.map +1 -0
  203. package/lib/cjs/Utils/business.js +241 -0
  204. package/lib/cjs/Utils/business.js.map +1 -0
  205. package/lib/cjs/Utils/chat-utils.d.ts +70 -0
  206. package/lib/cjs/Utils/chat-utils.d.ts.map +1 -0
  207. package/lib/cjs/Utils/chat-utils.js +826 -0
  208. package/lib/cjs/Utils/chat-utils.js.map +1 -0
  209. package/lib/cjs/Utils/crypto.d.ts +37 -0
  210. package/lib/cjs/Utils/crypto.d.ts.map +1 -0
  211. package/lib/cjs/Utils/crypto.js +169 -0
  212. package/lib/cjs/Utils/crypto.js.map +1 -0
  213. package/lib/cjs/Utils/decode-wa-message.d.ts +48 -0
  214. package/lib/cjs/Utils/decode-wa-message.d.ts.map +1 -0
  215. package/lib/cjs/Utils/decode-wa-message.js +291 -0
  216. package/lib/cjs/Utils/decode-wa-message.js.map +1 -0
  217. package/lib/cjs/Utils/event-buffer.d.ts +34 -0
  218. package/lib/cjs/Utils/event-buffer.d.ts.map +1 -0
  219. package/lib/cjs/Utils/event-buffer.js +581 -0
  220. package/lib/cjs/Utils/event-buffer.js.map +1 -0
  221. package/lib/cjs/Utils/generics.d.ts +91 -0
  222. package/lib/cjs/Utils/generics.d.ts.map +1 -0
  223. package/lib/cjs/Utils/generics.js +416 -0
  224. package/lib/cjs/Utils/generics.js.map +1 -0
  225. package/lib/cjs/Utils/history.d.ts +22 -0
  226. package/lib/cjs/Utils/history.d.ts.map +1 -0
  227. package/lib/cjs/Utils/history.js +138 -0
  228. package/lib/cjs/Utils/history.js.map +1 -0
  229. package/lib/cjs/Utils/identity-change-handler.d.ts +38 -0
  230. package/lib/cjs/Utils/identity-change-handler.d.ts.map +1 -0
  231. package/lib/cjs/Utils/identity-change-handler.js +52 -0
  232. package/lib/cjs/Utils/identity-change-handler.js.map +1 -0
  233. package/lib/cjs/Utils/index.d.ts +21 -0
  234. package/lib/cjs/Utils/index.d.ts.map +1 -0
  235. package/lib/cjs/Utils/index.js +37 -0
  236. package/lib/cjs/Utils/index.js.map +1 -0
  237. package/lib/cjs/Utils/link-preview.d.ts +21 -0
  238. package/lib/cjs/Utils/link-preview.d.ts.map +1 -0
  239. package/lib/cjs/Utils/link-preview.js +122 -0
  240. package/lib/cjs/Utils/link-preview.js.map +1 -0
  241. package/lib/cjs/Utils/logger.d.ts +13 -0
  242. package/lib/cjs/Utils/logger.d.ts.map +1 -0
  243. package/lib/cjs/Utils/logger.js +8 -0
  244. package/lib/cjs/Utils/logger.js.map +1 -0
  245. package/lib/cjs/Utils/lt-hash.d.ts +8 -0
  246. package/lib/cjs/Utils/lt-hash.d.ts.map +1 -0
  247. package/lib/cjs/Utils/lt-hash.js +11 -0
  248. package/lib/cjs/Utils/lt-hash.js.map +1 -0
  249. package/lib/cjs/Utils/make-mutex.d.ts +9 -0
  250. package/lib/cjs/Utils/make-mutex.d.ts.map +1 -0
  251. package/lib/cjs/Utils/make-mutex.js +38 -0
  252. package/lib/cjs/Utils/make-mutex.js.map +1 -0
  253. package/lib/cjs/Utils/message-retry-manager.d.ts +110 -0
  254. package/lib/cjs/Utils/message-retry-manager.d.ts.map +1 -0
  255. package/lib/cjs/Utils/message-retry-manager.js +229 -0
  256. package/lib/cjs/Utils/message-retry-manager.js.map +1 -0
  257. package/lib/cjs/Utils/messages-media.d.ts +130 -0
  258. package/lib/cjs/Utils/messages-media.d.ts.map +1 -0
  259. package/lib/cjs/Utils/messages-media.js +835 -0
  260. package/lib/cjs/Utils/messages-media.js.map +1 -0
  261. package/lib/cjs/Utils/messages.d.ts +91 -0
  262. package/lib/cjs/Utils/messages.d.ts.map +1 -0
  263. package/lib/cjs/Utils/messages.js +902 -0
  264. package/lib/cjs/Utils/messages.js.map +1 -0
  265. package/lib/cjs/Utils/noise-handler.d.ts +20 -0
  266. package/lib/cjs/Utils/noise-handler.d.ts.map +1 -0
  267. package/lib/cjs/Utils/noise-handler.js +205 -0
  268. package/lib/cjs/Utils/noise-handler.js.map +1 -0
  269. package/lib/cjs/Utils/offline-node-processor.d.ts +17 -0
  270. package/lib/cjs/Utils/offline-node-processor.d.ts.map +1 -0
  271. package/lib/cjs/Utils/offline-node-processor.js +43 -0
  272. package/lib/cjs/Utils/offline-node-processor.js.map +1 -0
  273. package/lib/cjs/Utils/pre-key-manager.d.ts +28 -0
  274. package/lib/cjs/Utils/pre-key-manager.d.ts.map +1 -0
  275. package/lib/cjs/Utils/pre-key-manager.js +113 -0
  276. package/lib/cjs/Utils/pre-key-manager.js.map +1 -0
  277. package/lib/cjs/Utils/process-message.d.ts +60 -0
  278. package/lib/cjs/Utils/process-message.d.ts.map +1 -0
  279. package/lib/cjs/Utils/process-message.js +539 -0
  280. package/lib/cjs/Utils/process-message.js.map +1 -0
  281. package/lib/cjs/Utils/reporting-utils.d.ts +11 -0
  282. package/lib/cjs/Utils/reporting-utils.d.ts.map +1 -0
  283. package/lib/cjs/Utils/reporting-utils.js +262 -0
  284. package/lib/cjs/Utils/reporting-utils.js.map +1 -0
  285. package/lib/cjs/Utils/signal.d.ts +34 -0
  286. package/lib/cjs/Utils/signal.d.ts.map +1 -0
  287. package/lib/cjs/Utils/signal.js +171 -0
  288. package/lib/cjs/Utils/signal.js.map +1 -0
  289. package/lib/cjs/Utils/stanza-ack.d.ts +11 -0
  290. package/lib/cjs/Utils/stanza-ack.d.ts.map +1 -0
  291. package/lib/cjs/Utils/stanza-ack.js +41 -0
  292. package/lib/cjs/Utils/stanza-ack.js.map +1 -0
  293. package/lib/cjs/Utils/sync-action-utils.d.ts +19 -0
  294. package/lib/cjs/Utils/sync-action-utils.d.ts.map +1 -0
  295. package/lib/cjs/Utils/sync-action-utils.js +52 -0
  296. package/lib/cjs/Utils/sync-action-utils.js.map +1 -0
  297. package/lib/cjs/Utils/tc-token-utils.d.ts +12 -0
  298. package/lib/cjs/Utils/tc-token-utils.d.ts.map +1 -0
  299. package/lib/cjs/Utils/tc-token-utils.js +21 -0
  300. package/lib/cjs/Utils/tc-token-utils.js.map +1 -0
  301. package/lib/cjs/Utils/use-multi-file-auth-state.d.ts +13 -0
  302. package/lib/cjs/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  303. package/lib/cjs/Utils/use-multi-file-auth-state.js +125 -0
  304. package/lib/cjs/Utils/use-multi-file-auth-state.js.map +1 -0
  305. package/lib/cjs/Utils/validate-connection.d.ts +11 -0
  306. package/lib/cjs/Utils/validate-connection.d.ts.map +1 -0
  307. package/lib/cjs/Utils/validate-connection.js +209 -0
  308. package/lib/cjs/Utils/validate-connection.js.map +1 -0
  309. package/lib/cjs/WABinary/constants.d.ts +28 -0
  310. package/lib/cjs/WABinary/constants.d.ts.map +1 -0
  311. package/lib/cjs/WABinary/constants.js +1304 -0
  312. package/lib/cjs/WABinary/constants.js.map +1 -0
  313. package/lib/cjs/WABinary/decode.d.ts +7 -0
  314. package/lib/cjs/WABinary/decode.d.ts.map +1 -0
  315. package/lib/cjs/WABinary/decode.js +301 -0
  316. package/lib/cjs/WABinary/decode.js.map +1 -0
  317. package/lib/cjs/WABinary/encode.d.ts +3 -0
  318. package/lib/cjs/WABinary/encode.d.ts.map +1 -0
  319. package/lib/cjs/WABinary/encode.js +257 -0
  320. package/lib/cjs/WABinary/encode.js.map +1 -0
  321. package/lib/cjs/WABinary/generic-utils.d.ts +15 -0
  322. package/lib/cjs/WABinary/generic-utils.d.ts.map +1 -0
  323. package/lib/cjs/WABinary/generic-utils.js +125 -0
  324. package/lib/cjs/WABinary/generic-utils.js.map +1 -0
  325. package/lib/cjs/WABinary/index.d.ts +6 -0
  326. package/lib/cjs/WABinary/index.d.ts.map +1 -0
  327. package/lib/cjs/WABinary/index.js +22 -0
  328. package/lib/cjs/WABinary/index.js.map +1 -0
  329. package/lib/cjs/WABinary/jid-utils.d.ts +48 -0
  330. package/lib/cjs/WABinary/jid-utils.d.ts.map +1 -0
  331. package/lib/cjs/WABinary/jid-utils.js +115 -0
  332. package/lib/cjs/WABinary/jid-utils.js.map +1 -0
  333. package/lib/cjs/WABinary/types.d.ts +19 -0
  334. package/lib/cjs/WABinary/types.d.ts.map +1 -0
  335. package/lib/cjs/WABinary/types.js +3 -0
  336. package/lib/cjs/WABinary/types.js.map +1 -0
  337. package/lib/cjs/WAM/BinaryInfo.d.ts +9 -0
  338. package/lib/cjs/WAM/BinaryInfo.d.ts.map +1 -0
  339. package/lib/cjs/WAM/BinaryInfo.js +14 -0
  340. package/lib/cjs/WAM/BinaryInfo.js.map +1 -0
  341. package/lib/cjs/WAM/constants.d.ts +40 -0
  342. package/lib/cjs/WAM/constants.d.ts.map +1 -0
  343. package/lib/cjs/WAM/constants.js +22856 -0
  344. package/lib/cjs/WAM/constants.js.map +1 -0
  345. package/lib/cjs/WAM/encode.d.ts +3 -0
  346. package/lib/cjs/WAM/encode.d.ts.map +1 -0
  347. package/lib/cjs/WAM/encode.js +153 -0
  348. package/lib/cjs/WAM/encode.js.map +1 -0
  349. package/lib/cjs/WAM/index.d.ts +4 -0
  350. package/lib/cjs/WAM/index.d.ts.map +1 -0
  351. package/lib/cjs/WAM/index.js +20 -0
  352. package/lib/cjs/WAM/index.js.map +1 -0
  353. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  354. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  355. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  356. package/lib/cjs/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  357. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  358. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  359. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.js +58 -0
  360. package/lib/cjs/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  361. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  362. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  363. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  364. package/lib/cjs/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  365. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  366. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  367. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  368. package/lib/cjs/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  369. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  370. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  371. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.js +54 -0
  372. package/lib/cjs/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  373. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.d.ts +17 -0
  374. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  375. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.js +33 -0
  376. package/lib/cjs/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  377. package/lib/cjs/WAUSync/Protocols/index.d.ts +5 -0
  378. package/lib/cjs/WAUSync/Protocols/index.d.ts.map +1 -0
  379. package/lib/cjs/WAUSync/Protocols/index.js +21 -0
  380. package/lib/cjs/WAUSync/Protocols/index.js.map +1 -0
  381. package/lib/cjs/WAUSync/USyncQuery.d.ts +29 -0
  382. package/lib/cjs/WAUSync/USyncQuery.d.ts.map +1 -0
  383. package/lib/cjs/WAUSync/USyncQuery.js +97 -0
  384. package/lib/cjs/WAUSync/USyncQuery.js.map +1 -0
  385. package/lib/cjs/WAUSync/USyncUser.d.ts +13 -0
  386. package/lib/cjs/WAUSync/USyncUser.d.ts.map +1 -0
  387. package/lib/cjs/WAUSync/USyncUser.js +27 -0
  388. package/lib/cjs/WAUSync/USyncUser.js.map +1 -0
  389. package/lib/cjs/WAUSync/index.d.ts +4 -0
  390. package/lib/cjs/WAUSync/index.d.ts.map +1 -0
  391. package/lib/cjs/WAUSync/index.js +20 -0
  392. package/lib/cjs/WAUSync/index.js.map +1 -0
  393. package/lib/cjs/index.d.ts +12 -0
  394. package/lib/cjs/index.d.ts.map +1 -0
  395. package/lib/cjs/index.js +31 -0
  396. package/lib/cjs/index.js.map +1 -0
  397. package/lib/cjs/package.json +3 -0
  398. package/lib/esm/Defaults/index.d.ts +74 -0
  399. package/lib/esm/Defaults/index.d.ts.map +1 -0
  400. package/lib/esm/Defaults/index.js +128 -0
  401. package/lib/esm/Defaults/index.js.map +1 -0
  402. package/lib/esm/Signal/Group/ciphertext-message.d.ts +10 -0
  403. package/lib/esm/Signal/Group/ciphertext-message.d.ts.map +1 -0
  404. package/lib/esm/Signal/Group/ciphertext-message.js +12 -0
  405. package/lib/esm/Signal/Group/ciphertext-message.js.map +1 -0
  406. package/lib/esm/Signal/Group/group-session-builder.d.ts +15 -0
  407. package/lib/esm/Signal/Group/group-session-builder.d.ts.map +1 -0
  408. package/lib/esm/Signal/Group/group-session-builder.js +30 -0
  409. package/lib/esm/Signal/Group/group-session-builder.js.map +1 -0
  410. package/lib/esm/Signal/Group/group_cipher.d.ts +17 -0
  411. package/lib/esm/Signal/Group/group_cipher.d.ts.map +1 -0
  412. package/lib/esm/Signal/Group/group_cipher.js +82 -0
  413. package/lib/esm/Signal/Group/group_cipher.js.map +1 -0
  414. package/lib/esm/Signal/Group/index.d.ts +12 -0
  415. package/lib/esm/Signal/Group/index.d.ts.map +1 -0
  416. package/lib/esm/Signal/Group/index.js +12 -0
  417. package/lib/esm/Signal/Group/index.js.map +1 -0
  418. package/lib/esm/Signal/Group/keyhelper.d.ts +11 -0
  419. package/lib/esm/Signal/Group/keyhelper.d.ts.map +1 -0
  420. package/lib/esm/Signal/Group/keyhelper.js +18 -0
  421. package/lib/esm/Signal/Group/keyhelper.js.map +1 -0
  422. package/lib/esm/Signal/Group/sender-chain-key.d.ts +14 -0
  423. package/lib/esm/Signal/Group/sender-chain-key.d.ts.map +1 -0
  424. package/lib/esm/Signal/Group/sender-chain-key.js +26 -0
  425. package/lib/esm/Signal/Group/sender-chain-key.js.map +1 -0
  426. package/lib/esm/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  427. package/lib/esm/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  428. package/lib/esm/Signal/Group/sender-key-distribution-message.js +63 -0
  429. package/lib/esm/Signal/Group/sender-key-distribution-message.js.map +1 -0
  430. package/lib/esm/Signal/Group/sender-key-message.d.ts +19 -0
  431. package/lib/esm/Signal/Group/sender-key-message.d.ts.map +1 -0
  432. package/lib/esm/Signal/Group/sender-key-message.js +66 -0
  433. package/lib/esm/Signal/Group/sender-key-message.js.map +1 -0
  434. package/lib/esm/Signal/Group/sender-key-name.d.ts +18 -0
  435. package/lib/esm/Signal/Group/sender-key-name.d.ts.map +1 -0
  436. package/lib/esm/Signal/Group/sender-key-name.js +48 -0
  437. package/lib/esm/Signal/Group/sender-key-name.js.map +1 -0
  438. package/lib/esm/Signal/Group/sender-key-record.d.ts +31 -0
  439. package/lib/esm/Signal/Group/sender-key-record.d.ts.map +1 -0
  440. package/lib/esm/Signal/Group/sender-key-record.js +41 -0
  441. package/lib/esm/Signal/Group/sender-key-record.js.map +1 -0
  442. package/lib/esm/Signal/Group/sender-key-state.d.ts +39 -0
  443. package/lib/esm/Signal/Group/sender-key-state.d.ts.map +1 -0
  444. package/lib/esm/Signal/Group/sender-key-state.js +84 -0
  445. package/lib/esm/Signal/Group/sender-key-state.js.map +1 -0
  446. package/lib/esm/Signal/Group/sender-message-key.d.ts +12 -0
  447. package/lib/esm/Signal/Group/sender-message-key.d.ts.map +1 -0
  448. package/lib/esm/Signal/Group/sender-message-key.js +26 -0
  449. package/lib/esm/Signal/Group/sender-message-key.js.map +1 -0
  450. package/lib/esm/Signal/jid-mapping.d.ts +50 -0
  451. package/lib/esm/Signal/jid-mapping.d.ts.map +1 -0
  452. package/lib/esm/Signal/jid-mapping.js +214 -0
  453. package/lib/esm/Signal/jid-mapping.js.map +1 -0
  454. package/lib/esm/Signal/libsignal.d.ts +7 -0
  455. package/lib/esm/Signal/libsignal.d.ts.map +1 -0
  456. package/lib/esm/Signal/libsignal.js +413 -0
  457. package/lib/esm/Signal/libsignal.js.map +1 -0
  458. package/lib/esm/Signal/lid-mapping.d.ts +6 -0
  459. package/lib/esm/Signal/lid-mapping.d.ts.map +1 -0
  460. package/lib/esm/Signal/lid-mapping.js +6 -0
  461. package/lib/esm/Signal/lid-mapping.js.map +1 -0
  462. package/lib/esm/Socket/Client/index.d.ts +3 -0
  463. package/lib/esm/Socket/Client/index.d.ts.map +1 -0
  464. package/lib/esm/Socket/Client/index.js +3 -0
  465. package/lib/esm/Socket/Client/index.js.map +1 -0
  466. package/lib/esm/Socket/Client/types.d.ts +16 -0
  467. package/lib/esm/Socket/Client/types.d.ts.map +1 -0
  468. package/lib/esm/Socket/Client/types.js +11 -0
  469. package/lib/esm/Socket/Client/types.js.map +1 -0
  470. package/lib/esm/Socket/Client/websocket.d.ts +13 -0
  471. package/lib/esm/Socket/Client/websocket.d.ts.map +1 -0
  472. package/lib/esm/Socket/Client/websocket.js +54 -0
  473. package/lib/esm/Socket/Client/websocket.js.map +1 -0
  474. package/lib/esm/Socket/business.d.ts +202 -0
  475. package/lib/esm/Socket/business.d.ts.map +1 -0
  476. package/lib/esm/Socket/business.js +379 -0
  477. package/lib/esm/Socket/business.js.map +1 -0
  478. package/lib/esm/Socket/chats.d.ts +111 -0
  479. package/lib/esm/Socket/chats.d.ts.map +1 -0
  480. package/lib/esm/Socket/chats.js +999 -0
  481. package/lib/esm/Socket/chats.js.map +1 -0
  482. package/lib/esm/Socket/communities.d.ts +258 -0
  483. package/lib/esm/Socket/communities.d.ts.map +1 -0
  484. package/lib/esm/Socket/communities.js +431 -0
  485. package/lib/esm/Socket/communities.js.map +1 -0
  486. package/lib/esm/Socket/groups.d.ts +150 -0
  487. package/lib/esm/Socket/groups.d.ts.map +1 -0
  488. package/lib/esm/Socket/groups.js +330 -0
  489. package/lib/esm/Socket/groups.js.map +1 -0
  490. package/lib/esm/Socket/index.d.ts +245 -0
  491. package/lib/esm/Socket/index.d.ts.map +1 -0
  492. package/lib/esm/Socket/index.js +12 -0
  493. package/lib/esm/Socket/index.js.map +1 -0
  494. package/lib/esm/Socket/messages-recv.d.ts +187 -0
  495. package/lib/esm/Socket/messages-recv.d.ts.map +1 -0
  496. package/lib/esm/Socket/messages-recv.js +1319 -0
  497. package/lib/esm/Socket/messages-recv.js.map +1 -0
  498. package/lib/esm/Socket/messages-send.d.ts +183 -0
  499. package/lib/esm/Socket/messages-send.d.ts.map +1 -0
  500. package/lib/esm/Socket/messages-send.js +1039 -0
  501. package/lib/esm/Socket/messages-send.js.map +1 -0
  502. package/lib/esm/Socket/mex.d.ts +3 -0
  503. package/lib/esm/Socket/mex.d.ts.map +1 -0
  504. package/lib/esm/Socket/mex.js +42 -0
  505. package/lib/esm/Socket/mex.js.map +1 -0
  506. package/lib/esm/Socket/newsletter.d.ts +160 -0
  507. package/lib/esm/Socket/newsletter.d.ts.map +1 -0
  508. package/lib/esm/Socket/newsletter.js +181 -0
  509. package/lib/esm/Socket/newsletter.js.map +1 -0
  510. package/lib/esm/Socket/socket.d.ts +55 -0
  511. package/lib/esm/Socket/socket.d.ts.map +1 -0
  512. package/lib/esm/Socket/socket.js +936 -0
  513. package/lib/esm/Socket/socket.js.map +1 -0
  514. package/lib/esm/Types/Auth.d.ts +126 -0
  515. package/lib/esm/Types/Auth.d.ts.map +1 -0
  516. package/lib/esm/Types/Auth.js +2 -0
  517. package/lib/esm/Types/Auth.js.map +1 -0
  518. package/lib/esm/Types/Bussines.d.ts +25 -0
  519. package/lib/esm/Types/Bussines.d.ts.map +1 -0
  520. package/lib/esm/Types/Bussines.js +2 -0
  521. package/lib/esm/Types/Bussines.js.map +1 -0
  522. package/lib/esm/Types/Call.d.ts +15 -0
  523. package/lib/esm/Types/Call.d.ts.map +1 -0
  524. package/lib/esm/Types/Call.js +2 -0
  525. package/lib/esm/Types/Call.js.map +1 -0
  526. package/lib/esm/Types/Chat.d.ts +123 -0
  527. package/lib/esm/Types/Chat.d.ts.map +1 -0
  528. package/lib/esm/Types/Chat.js +8 -0
  529. package/lib/esm/Types/Chat.js.map +1 -0
  530. package/lib/esm/Types/Contact.d.ts +24 -0
  531. package/lib/esm/Types/Contact.d.ts.map +1 -0
  532. package/lib/esm/Types/Contact.js +2 -0
  533. package/lib/esm/Types/Contact.js.map +1 -0
  534. package/lib/esm/Types/Events.d.ts +241 -0
  535. package/lib/esm/Types/Events.d.ts.map +1 -0
  536. package/lib/esm/Types/Events.js +2 -0
  537. package/lib/esm/Types/Events.js.map +1 -0
  538. package/lib/esm/Types/GroupMetadata.d.ts +67 -0
  539. package/lib/esm/Types/GroupMetadata.d.ts.map +1 -0
  540. package/lib/esm/Types/GroupMetadata.js +2 -0
  541. package/lib/esm/Types/GroupMetadata.js.map +1 -0
  542. package/lib/esm/Types/Label.d.ts +47 -0
  543. package/lib/esm/Types/Label.d.ts.map +1 -0
  544. package/lib/esm/Types/Label.js +25 -0
  545. package/lib/esm/Types/Label.js.map +1 -0
  546. package/lib/esm/Types/LabelAssociation.d.ts +30 -0
  547. package/lib/esm/Types/LabelAssociation.d.ts.map +1 -0
  548. package/lib/esm/Types/LabelAssociation.js +7 -0
  549. package/lib/esm/Types/LabelAssociation.js.map +1 -0
  550. package/lib/esm/Types/Message.d.ts +310 -0
  551. package/lib/esm/Types/Message.d.ts.map +1 -0
  552. package/lib/esm/Types/Message.js +14 -0
  553. package/lib/esm/Types/Message.js.map +1 -0
  554. package/lib/esm/Types/Newsletter.d.ts +135 -0
  555. package/lib/esm/Types/Newsletter.d.ts.map +1 -0
  556. package/lib/esm/Types/Newsletter.js +31 -0
  557. package/lib/esm/Types/Newsletter.js.map +1 -0
  558. package/lib/esm/Types/Product.d.ts +79 -0
  559. package/lib/esm/Types/Product.d.ts.map +1 -0
  560. package/lib/esm/Types/Product.js +2 -0
  561. package/lib/esm/Types/Product.js.map +1 -0
  562. package/lib/esm/Types/Signal.d.ts +76 -0
  563. package/lib/esm/Types/Signal.d.ts.map +1 -0
  564. package/lib/esm/Types/Signal.js +2 -0
  565. package/lib/esm/Types/Signal.js.map +1 -0
  566. package/lib/esm/Types/Socket.d.ts +135 -0
  567. package/lib/esm/Types/Socket.d.ts.map +1 -0
  568. package/lib/esm/Types/Socket.js +3 -0
  569. package/lib/esm/Types/Socket.js.map +1 -0
  570. package/lib/esm/Types/State.d.ts +39 -0
  571. package/lib/esm/Types/State.d.ts.map +1 -0
  572. package/lib/esm/Types/State.js +13 -0
  573. package/lib/esm/Types/State.js.map +1 -0
  574. package/lib/esm/Types/USync.d.ts +26 -0
  575. package/lib/esm/Types/USync.d.ts.map +1 -0
  576. package/lib/esm/Types/USync.js +2 -0
  577. package/lib/esm/Types/USync.js.map +1 -0
  578. package/lib/esm/Types/index.d.ts +65 -0
  579. package/lib/esm/Types/index.d.ts.map +1 -0
  580. package/lib/esm/Types/index.js +26 -0
  581. package/lib/esm/Types/index.js.map +1 -0
  582. package/lib/esm/Utils/auth-utils.d.ts +19 -0
  583. package/lib/esm/Utils/auth-utils.d.ts.map +1 -0
  584. package/lib/esm/Utils/auth-utils.js +290 -0
  585. package/lib/esm/Utils/auth-utils.js.map +1 -0
  586. package/lib/esm/Utils/browser-utils.d.ts +4 -0
  587. package/lib/esm/Utils/browser-utils.d.ts.map +1 -0
  588. package/lib/esm/Utils/browser-utils.js +28 -0
  589. package/lib/esm/Utils/browser-utils.js.map +1 -0
  590. package/lib/esm/Utils/business.d.ts +23 -0
  591. package/lib/esm/Utils/business.d.ts.map +1 -0
  592. package/lib/esm/Utils/business.js +231 -0
  593. package/lib/esm/Utils/business.js.map +1 -0
  594. package/lib/esm/Utils/chat-utils.d.ts +70 -0
  595. package/lib/esm/Utils/chat-utils.d.ts.map +1 -0
  596. package/lib/esm/Utils/chat-utils.js +812 -0
  597. package/lib/esm/Utils/chat-utils.js.map +1 -0
  598. package/lib/esm/Utils/crypto.d.ts +37 -0
  599. package/lib/esm/Utils/crypto.d.ts.map +1 -0
  600. package/lib/esm/Utils/crypto.js +118 -0
  601. package/lib/esm/Utils/crypto.js.map +1 -0
  602. package/lib/esm/Utils/decode-wa-message.d.ts +48 -0
  603. package/lib/esm/Utils/decode-wa-message.d.ts.map +1 -0
  604. package/lib/esm/Utils/decode-wa-message.js +286 -0
  605. package/lib/esm/Utils/decode-wa-message.js.map +1 -0
  606. package/lib/esm/Utils/event-buffer.d.ts +34 -0
  607. package/lib/esm/Utils/event-buffer.d.ts.map +1 -0
  608. package/lib/esm/Utils/event-buffer.js +574 -0
  609. package/lib/esm/Utils/event-buffer.js.map +1 -0
  610. package/lib/esm/Utils/generics.d.ts +91 -0
  611. package/lib/esm/Utils/generics.d.ts.map +1 -0
  612. package/lib/esm/Utils/generics.js +384 -0
  613. package/lib/esm/Utils/generics.js.map +1 -0
  614. package/lib/esm/Utils/history.d.ts +22 -0
  615. package/lib/esm/Utils/history.d.ts.map +1 -0
  616. package/lib/esm/Utils/history.js +131 -0
  617. package/lib/esm/Utils/history.js.map +1 -0
  618. package/lib/esm/Utils/identity-change-handler.d.ts +38 -0
  619. package/lib/esm/Utils/identity-change-handler.d.ts.map +1 -0
  620. package/lib/esm/Utils/identity-change-handler.js +50 -0
  621. package/lib/esm/Utils/identity-change-handler.js.map +1 -0
  622. package/lib/esm/Utils/index.d.ts +21 -0
  623. package/lib/esm/Utils/index.d.ts.map +1 -0
  624. package/lib/esm/Utils/index.js +21 -0
  625. package/lib/esm/Utils/index.js.map +1 -0
  626. package/lib/esm/Utils/link-preview.d.ts +21 -0
  627. package/lib/esm/Utils/link-preview.d.ts.map +1 -0
  628. package/lib/esm/Utils/link-preview.js +85 -0
  629. package/lib/esm/Utils/link-preview.js.map +1 -0
  630. package/lib/esm/Utils/logger.d.ts +13 -0
  631. package/lib/esm/Utils/logger.d.ts.map +1 -0
  632. package/lib/esm/Utils/logger.js +3 -0
  633. package/lib/esm/Utils/logger.js.map +1 -0
  634. package/lib/esm/Utils/lt-hash.d.ts +8 -0
  635. package/lib/esm/Utils/lt-hash.d.ts.map +1 -0
  636. package/lib/esm/Utils/lt-hash.js +8 -0
  637. package/lib/esm/Utils/lt-hash.js.map +1 -0
  638. package/lib/esm/Utils/make-mutex.d.ts +9 -0
  639. package/lib/esm/Utils/make-mutex.d.ts.map +1 -0
  640. package/lib/esm/Utils/make-mutex.js +33 -0
  641. package/lib/esm/Utils/make-mutex.js.map +1 -0
  642. package/lib/esm/Utils/message-retry-manager.d.ts +110 -0
  643. package/lib/esm/Utils/message-retry-manager.d.ts.map +1 -0
  644. package/lib/esm/Utils/message-retry-manager.js +225 -0
  645. package/lib/esm/Utils/message-retry-manager.js.map +1 -0
  646. package/lib/esm/Utils/messages-media.d.ts +130 -0
  647. package/lib/esm/Utils/messages-media.d.ts.map +1 -0
  648. package/lib/esm/Utils/messages-media.js +774 -0
  649. package/lib/esm/Utils/messages-media.js.map +1 -0
  650. package/lib/esm/Utils/messages.d.ts +91 -0
  651. package/lib/esm/Utils/messages.d.ts.map +1 -0
  652. package/lib/esm/Utils/messages.js +878 -0
  653. package/lib/esm/Utils/messages.js.map +1 -0
  654. package/lib/esm/Utils/noise-handler.d.ts +20 -0
  655. package/lib/esm/Utils/noise-handler.d.ts.map +1 -0
  656. package/lib/esm/Utils/noise-handler.js +201 -0
  657. package/lib/esm/Utils/noise-handler.js.map +1 -0
  658. package/lib/esm/Utils/offline-node-processor.d.ts +17 -0
  659. package/lib/esm/Utils/offline-node-processor.d.ts.map +1 -0
  660. package/lib/esm/Utils/offline-node-processor.js +40 -0
  661. package/lib/esm/Utils/offline-node-processor.js.map +1 -0
  662. package/lib/esm/Utils/pre-key-manager.d.ts +28 -0
  663. package/lib/esm/Utils/pre-key-manager.d.ts.map +1 -0
  664. package/lib/esm/Utils/pre-key-manager.js +106 -0
  665. package/lib/esm/Utils/pre-key-manager.js.map +1 -0
  666. package/lib/esm/Utils/process-message.d.ts +60 -0
  667. package/lib/esm/Utils/process-message.d.ts.map +1 -0
  668. package/lib/esm/Utils/process-message.js +530 -0
  669. package/lib/esm/Utils/process-message.js.map +1 -0
  670. package/lib/esm/Utils/reporting-utils.d.ts +11 -0
  671. package/lib/esm/Utils/reporting-utils.d.ts.map +1 -0
  672. package/lib/esm/Utils/reporting-utils.js +258 -0
  673. package/lib/esm/Utils/reporting-utils.js.map +1 -0
  674. package/lib/esm/Utils/signal.d.ts +34 -0
  675. package/lib/esm/Utils/signal.d.ts.map +1 -0
  676. package/lib/esm/Utils/signal.js +159 -0
  677. package/lib/esm/Utils/signal.js.map +1 -0
  678. package/lib/esm/Utils/stanza-ack.d.ts +11 -0
  679. package/lib/esm/Utils/stanza-ack.d.ts.map +1 -0
  680. package/lib/esm/Utils/stanza-ack.js +38 -0
  681. package/lib/esm/Utils/stanza-ack.js.map +1 -0
  682. package/lib/esm/Utils/sync-action-utils.d.ts +19 -0
  683. package/lib/esm/Utils/sync-action-utils.d.ts.map +1 -0
  684. package/lib/esm/Utils/sync-action-utils.js +48 -0
  685. package/lib/esm/Utils/sync-action-utils.js.map +1 -0
  686. package/lib/esm/Utils/tc-token-utils.d.ts +12 -0
  687. package/lib/esm/Utils/tc-token-utils.d.ts.map +1 -0
  688. package/lib/esm/Utils/tc-token-utils.js +18 -0
  689. package/lib/esm/Utils/tc-token-utils.js.map +1 -0
  690. package/lib/esm/Utils/use-multi-file-auth-state.d.ts +13 -0
  691. package/lib/esm/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  692. package/lib/esm/Utils/use-multi-file-auth-state.js +121 -0
  693. package/lib/esm/Utils/use-multi-file-auth-state.js.map +1 -0
  694. package/lib/esm/Utils/validate-connection.d.ts +11 -0
  695. package/lib/esm/Utils/validate-connection.d.ts.map +1 -0
  696. package/lib/esm/Utils/validate-connection.js +202 -0
  697. package/lib/esm/Utils/validate-connection.js.map +1 -0
  698. package/lib/esm/WABinary/constants.d.ts +28 -0
  699. package/lib/esm/WABinary/constants.d.ts.map +1 -0
  700. package/lib/esm/WABinary/constants.js +1301 -0
  701. package/lib/esm/WABinary/constants.js.map +1 -0
  702. package/lib/esm/WABinary/decode.d.ts +7 -0
  703. package/lib/esm/WABinary/decode.d.ts.map +1 -0
  704. package/lib/esm/WABinary/decode.js +262 -0
  705. package/lib/esm/WABinary/decode.js.map +1 -0
  706. package/lib/esm/WABinary/encode.d.ts +3 -0
  707. package/lib/esm/WABinary/encode.d.ts.map +1 -0
  708. package/lib/esm/WABinary/encode.js +220 -0
  709. package/lib/esm/WABinary/encode.js.map +1 -0
  710. package/lib/esm/WABinary/generic-utils.d.ts +15 -0
  711. package/lib/esm/WABinary/generic-utils.d.ts.map +1 -0
  712. package/lib/esm/WABinary/generic-utils.js +113 -0
  713. package/lib/esm/WABinary/generic-utils.js.map +1 -0
  714. package/lib/esm/WABinary/index.d.ts +6 -0
  715. package/lib/esm/WABinary/index.d.ts.map +1 -0
  716. package/lib/esm/WABinary/index.js +6 -0
  717. package/lib/esm/WABinary/index.js.map +1 -0
  718. package/lib/esm/WABinary/jid-utils.d.ts +48 -0
  719. package/lib/esm/WABinary/jid-utils.d.ts.map +1 -0
  720. package/lib/esm/WABinary/jid-utils.js +96 -0
  721. package/lib/esm/WABinary/jid-utils.js.map +1 -0
  722. package/lib/esm/WABinary/types.d.ts +19 -0
  723. package/lib/esm/WABinary/types.d.ts.map +1 -0
  724. package/lib/esm/WABinary/types.js +2 -0
  725. package/lib/esm/WABinary/types.js.map +1 -0
  726. package/lib/esm/WAM/BinaryInfo.d.ts +9 -0
  727. package/lib/esm/WAM/BinaryInfo.d.ts.map +1 -0
  728. package/lib/esm/WAM/BinaryInfo.js +10 -0
  729. package/lib/esm/WAM/BinaryInfo.js.map +1 -0
  730. package/lib/esm/WAM/constants.d.ts +40 -0
  731. package/lib/esm/WAM/constants.d.ts.map +1 -0
  732. package/lib/esm/WAM/constants.js +22853 -0
  733. package/lib/esm/WAM/constants.js.map +1 -0
  734. package/lib/esm/WAM/encode.d.ts +3 -0
  735. package/lib/esm/WAM/encode.d.ts.map +1 -0
  736. package/lib/esm/WAM/encode.js +150 -0
  737. package/lib/esm/WAM/encode.js.map +1 -0
  738. package/lib/esm/WAM/index.d.ts +4 -0
  739. package/lib/esm/WAM/index.d.ts.map +1 -0
  740. package/lib/esm/WAM/index.js +4 -0
  741. package/lib/esm/WAM/index.js.map +1 -0
  742. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  743. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  744. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.js +29 -0
  745. package/lib/esm/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  746. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  747. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  748. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  749. package/lib/esm/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  750. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  751. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  752. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  753. package/lib/esm/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  754. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  755. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  756. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  757. package/lib/esm/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  758. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  759. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  760. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  761. package/lib/esm/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  762. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.d.ts +17 -0
  763. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  764. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  765. package/lib/esm/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  766. package/lib/esm/WAUSync/Protocols/index.d.ts +5 -0
  767. package/lib/esm/WAUSync/Protocols/index.d.ts.map +1 -0
  768. package/lib/esm/WAUSync/Protocols/index.js +5 -0
  769. package/lib/esm/WAUSync/Protocols/index.js.map +1 -0
  770. package/lib/esm/WAUSync/USyncQuery.d.ts +29 -0
  771. package/lib/esm/WAUSync/USyncQuery.d.ts.map +1 -0
  772. package/lib/esm/WAUSync/USyncQuery.js +94 -0
  773. package/lib/esm/WAUSync/USyncQuery.js.map +1 -0
  774. package/lib/esm/WAUSync/USyncUser.d.ts +13 -0
  775. package/lib/esm/WAUSync/USyncUser.d.ts.map +1 -0
  776. package/lib/esm/WAUSync/USyncUser.js +23 -0
  777. package/lib/esm/WAUSync/USyncUser.js.map +1 -0
  778. package/lib/esm/WAUSync/index.d.ts +4 -0
  779. package/lib/esm/WAUSync/index.d.ts.map +1 -0
  780. package/lib/esm/WAUSync/index.js +4 -0
  781. package/lib/esm/WAUSync/index.js.map +1 -0
  782. package/lib/esm/index.d.ts +12 -0
  783. package/lib/esm/index.d.ts.map +1 -0
  784. package/lib/esm/index.js +11 -0
  785. package/lib/esm/index.js.map +1 -0
  786. package/lib/esm/package.json +3 -0
  787. package/package.json +129 -0
@@ -0,0 +1,940 @@
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 index_js_1 = require("../../WAProto/index.js");
9
+ const Defaults_1 = require("../Defaults");
10
+ const Types_1 = require("../Types");
11
+ const Utils_1 = require("../Utils");
12
+ const browser_utils_1 = require("../Utils/browser-utils");
13
+ const WABinary_1 = require("../WABinary");
14
+ const BinaryInfo_js_1 = require("../WAM/BinaryInfo.js");
15
+ const WAUSync_1 = require("../WAUSync/");
16
+ const Client_1 = require("./Client");
17
+ /**
18
+ * Connects to WA servers and performs:
19
+ * - simple queries (no retry mechanism, wait for connection establishment)
20
+ * - listen to messages and emit events
21
+ * - query phone connection
22
+ */
23
+ const makeSocket = (config) => {
24
+ const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository } = config;
25
+ const publicWAMBuffer = new BinaryInfo_js_1.BinaryInfo();
26
+ let serverTimeOffsetMs = 0;
27
+ const uqTagId = (0, Utils_1.generateMdTagPrefix)();
28
+ const generateMessageTag = () => `${uqTagId}${epoch++}`;
29
+ if (printQRInTerminal) {
30
+ logger.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.');
31
+ }
32
+ const syncDisabled = Defaults_1.PROCESSABLE_HISTORY_TYPES.map(syncType => config.shouldSyncHistoryMessage({ syncType })).filter(x => x === false)
33
+ .length === Defaults_1.PROCESSABLE_HISTORY_TYPES.length;
34
+ if (syncDisabled) {
35
+ logger.warn('⚠️ DANGER: DISABLING ALL SYNC BY shouldSyncHistoryMsg PREVENTS BAILEYS FROM ACCESSING INITIAL LID MAPPINGS, LEADING TO INSTABILIY AND SESSION ERRORS');
36
+ }
37
+ const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
38
+ if (config.mobile || url.protocol === 'tcp:') {
39
+ throw new boom_1.Boom('Mobile API is not supported anymore', { statusCode: Types_1.DisconnectReason.loggedOut });
40
+ }
41
+ if (url.protocol === 'wss' && authState?.creds?.routingInfo) {
42
+ url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
43
+ }
44
+ /** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
45
+ const ephemeralKeyPair = Utils_1.Curve.generateKeyPair();
46
+ /** WA noise protocol wrapper */
47
+ const noise = (0, Utils_1.makeNoiseHandler)({
48
+ keyPair: ephemeralKeyPair,
49
+ NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
50
+ logger,
51
+ routingInfo: authState?.creds?.routingInfo
52
+ });
53
+ const ws = new Client_1.WebSocketClient(url, config);
54
+ ws.connect();
55
+ const sendPromise = (0, util_1.promisify)(ws.send);
56
+ /** send a raw buffer */
57
+ const sendRawMessage = async (data) => {
58
+ if (!ws.isOpen) {
59
+ throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
60
+ }
61
+ const bytes = noise.encodeFrame(data);
62
+ await (0, Utils_1.promiseTimeout)(connectTimeoutMs, async (resolve, reject) => {
63
+ try {
64
+ await sendPromise.call(ws, bytes);
65
+ resolve();
66
+ }
67
+ catch (error) {
68
+ reject(error);
69
+ }
70
+ });
71
+ };
72
+ /** send a binary node */
73
+ const sendNode = (frame) => {
74
+ if (logger.level === 'trace') {
75
+ logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'xml send' });
76
+ }
77
+ const buff = (0, WABinary_1.encodeBinaryNode)(frame);
78
+ return sendRawMessage(buff);
79
+ };
80
+ /**
81
+ * Wait for a message with a certain tag to be received
82
+ * @param msgId the message tag to await
83
+ * @param timeoutMs timeout after which the promise will reject
84
+ */
85
+ const waitForMessage = async (msgId, timeoutMs = defaultQueryTimeoutMs) => {
86
+ let onRecv;
87
+ let onErr;
88
+ try {
89
+ const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
90
+ onRecv = data => {
91
+ resolve(data);
92
+ };
93
+ onErr = err => {
94
+ reject(err ||
95
+ new boom_1.Boom('Connection Closed', {
96
+ statusCode: Types_1.DisconnectReason.connectionClosed
97
+ }));
98
+ };
99
+ ws.on(`TAG:${msgId}`, onRecv);
100
+ ws.on('close', onErr);
101
+ ws.on('error', onErr);
102
+ return () => reject(new boom_1.Boom('Query Cancelled'));
103
+ });
104
+ return result;
105
+ }
106
+ catch (error) {
107
+ // Catch timeout and return undefined instead of throwing
108
+ if (error instanceof boom_1.Boom && error.output?.statusCode === Types_1.DisconnectReason.timedOut) {
109
+ logger?.warn?.({ msgId }, 'timed out waiting for message');
110
+ return undefined;
111
+ }
112
+ throw error;
113
+ }
114
+ finally {
115
+ if (onRecv)
116
+ ws.off(`TAG:${msgId}`, onRecv);
117
+ if (onErr) {
118
+ ws.off('close', onErr);
119
+ ws.off('error', onErr);
120
+ }
121
+ }
122
+ };
123
+ /** send a query, and wait for its response. auto-generates message ID if not provided */
124
+ const query = async (node, timeoutMs) => {
125
+ if (!node.attrs.id) {
126
+ node.attrs.id = generateMessageTag();
127
+ }
128
+ const msgId = node.attrs.id;
129
+ const result = await (0, Utils_1.promiseTimeout)(timeoutMs, async (resolve, reject) => {
130
+ const result = waitForMessage(msgId, timeoutMs).catch(reject);
131
+ sendNode(node)
132
+ .then(async () => resolve(await result))
133
+ .catch(reject);
134
+ });
135
+ if (result && 'tag' in result) {
136
+ (0, WABinary_1.assertNodeErrorFree)(result);
137
+ }
138
+ return result;
139
+ };
140
+ // Validate current key-bundle on server; on failure, trigger pre-key upload and rethrow
141
+ const digestKeyBundle = async () => {
142
+ const res = await query({
143
+ tag: 'iq',
144
+ attrs: { to: WABinary_1.S_WHATSAPP_NET, type: 'get', xmlns: 'encrypt' },
145
+ content: [{ tag: 'digest', attrs: {} }]
146
+ });
147
+ const digestNode = (0, WABinary_1.getBinaryNodeChild)(res, 'digest');
148
+ if (!digestNode) {
149
+ await uploadPreKeys();
150
+ throw new Error('encrypt/get digest returned no digest node');
151
+ }
152
+ };
153
+ // Rotate our signed pre-key on server; on failure, run digest as fallback and rethrow
154
+ const rotateSignedPreKey = async () => {
155
+ const newId = (creds.signedPreKey.keyId || 0) + 1;
156
+ const skey = await (0, Utils_1.signedKeyPair)(creds.signedIdentityKey, newId);
157
+ await query({
158
+ tag: 'iq',
159
+ attrs: { to: WABinary_1.S_WHATSAPP_NET, type: 'set', xmlns: 'encrypt' },
160
+ content: [
161
+ {
162
+ tag: 'rotate',
163
+ attrs: {},
164
+ content: [(0, Utils_1.xmppSignedPreKey)(skey)]
165
+ }
166
+ ]
167
+ });
168
+ // Persist new signed pre-key in creds
169
+ ev.emit('creds.update', { signedPreKey: skey });
170
+ };
171
+ const executeUSyncQuery = async (usyncQuery) => {
172
+ if (usyncQuery.protocols.length === 0) {
173
+ throw new boom_1.Boom('USyncQuery must have at least one protocol');
174
+ }
175
+ // todo: validate users, throw WARNING on no valid users
176
+ // variable below has only validated users
177
+ const validUsers = usyncQuery.users;
178
+ const userNodes = validUsers.map(user => {
179
+ return {
180
+ tag: 'user',
181
+ attrs: {
182
+ jid: !user.phone ? user.id : undefined
183
+ },
184
+ content: usyncQuery.protocols.map(a => a.getUserElement(user)).filter(a => a !== null)
185
+ };
186
+ });
187
+ const listNode = {
188
+ tag: 'list',
189
+ attrs: {},
190
+ content: userNodes
191
+ };
192
+ const queryNode = {
193
+ tag: 'query',
194
+ attrs: {},
195
+ content: usyncQuery.protocols.map(a => a.getQueryElement())
196
+ };
197
+ const iq = {
198
+ tag: 'iq',
199
+ attrs: {
200
+ to: WABinary_1.S_WHATSAPP_NET,
201
+ type: 'get',
202
+ xmlns: 'usync'
203
+ },
204
+ content: [
205
+ {
206
+ tag: 'usync',
207
+ attrs: {
208
+ context: usyncQuery.context,
209
+ mode: usyncQuery.mode,
210
+ sid: generateMessageTag(),
211
+ last: 'true',
212
+ index: '0'
213
+ },
214
+ content: [queryNode, listNode]
215
+ }
216
+ ]
217
+ };
218
+ const result = await query(iq);
219
+ return usyncQuery.parseUSyncQueryResult(result);
220
+ };
221
+ const onWhatsApp = async (...phoneNumber) => {
222
+ let usyncQuery = new WAUSync_1.USyncQuery();
223
+ let contactEnabled = false;
224
+ for (const jid of phoneNumber) {
225
+ if ((0, WABinary_1.isLidUser)(jid)) {
226
+ logger?.warn('LIDs are not supported with onWhatsApp');
227
+ continue;
228
+ }
229
+ else {
230
+ if (!contactEnabled) {
231
+ contactEnabled = true;
232
+ usyncQuery = usyncQuery.withContactProtocol();
233
+ }
234
+ const phone = `+${jid.replace('+', '').split('@')[0]?.split(':')[0]}`;
235
+ usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
236
+ }
237
+ }
238
+ if (usyncQuery.users.length === 0) {
239
+ return []; // return early without forcing an empty query
240
+ }
241
+ const results = await executeUSyncQuery(usyncQuery);
242
+ if (results) {
243
+ return results.list.filter(a => !!a.contact).map(({ contact, id }) => ({ jid: id, exists: contact }));
244
+ }
245
+ };
246
+ const pnFromJIDUSync = async (jids) => {
247
+ const usyncQuery = new WAUSync_1.USyncQuery().withLIDProtocol().withContext('background');
248
+ for (const jid of jids) {
249
+ if ((0, WABinary_1.isLidUser)(jid)) {
250
+ logger?.warn('LID user found in LID fetch call');
251
+ continue;
252
+ }
253
+ else {
254
+ usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
255
+ }
256
+ }
257
+ if (usyncQuery.users.length === 0) {
258
+ return []; // return early without forcing an empty query
259
+ }
260
+ const results = await executeUSyncQuery(usyncQuery);
261
+ if (results) {
262
+ // JID-first: map results — if server returns lid, store it for resolution; return pn as jid
263
+ return results.list.map(({ lid, id }) => ({ pn: id, jid: lid ? lid : id }));
264
+ }
265
+ return [];
266
+ };
267
+ const ev = (0, Utils_1.makeEventBuffer)(logger);
268
+ const { creds } = authState;
269
+ // add transaction capability
270
+ const keys = (0, Utils_1.addTransactionCapability)(authState.keys, logger, transactionOpts);
271
+ const signalRepository = makeSignalRepository({ creds, keys }, logger, pnFromJIDUSync);
272
+ let lastDateRecv;
273
+ let epoch = 1;
274
+ let keepAliveReq;
275
+ let qrTimer;
276
+ let closed = false;
277
+ /** log & process any unexpected errors */
278
+ const onUnexpectedError = (err, msg) => {
279
+ logger.error({ err }, `unexpected error in '${msg}'`);
280
+ };
281
+ /** await the next incoming message */
282
+ const awaitNextMessage = async (sendMsg) => {
283
+ if (!ws.isOpen) {
284
+ throw new boom_1.Boom('Connection Closed', {
285
+ statusCode: Types_1.DisconnectReason.connectionClosed
286
+ });
287
+ }
288
+ let onOpen;
289
+ let onClose;
290
+ const result = (0, Utils_1.promiseTimeout)(connectTimeoutMs, (resolve, reject) => {
291
+ onOpen = resolve;
292
+ onClose = mapWebSocketError(reject);
293
+ ws.on('frame', onOpen);
294
+ ws.on('close', onClose);
295
+ ws.on('error', onClose);
296
+ }).finally(() => {
297
+ ws.off('frame', onOpen);
298
+ ws.off('close', onClose);
299
+ ws.off('error', onClose);
300
+ });
301
+ if (sendMsg) {
302
+ sendRawMessage(sendMsg).catch(onClose);
303
+ }
304
+ return result;
305
+ };
306
+ /** connection handshake */
307
+ const validateConnection = async () => {
308
+ let helloMsg = {
309
+ clientHello: { ephemeral: ephemeralKeyPair.public }
310
+ };
311
+ helloMsg = index_js_1.proto.HandshakeMessage.fromObject(helloMsg);
312
+ logger.info({ browser, helloMsg }, 'connected to WA');
313
+ const init = index_js_1.proto.HandshakeMessage.encode(helloMsg).finish();
314
+ const result = await awaitNextMessage(init);
315
+ const handshake = index_js_1.proto.HandshakeMessage.decode(result);
316
+ logger.trace({ handshake }, 'handshake recv from WA');
317
+ const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
318
+ let node;
319
+ if (!creds.me) {
320
+ node = (0, Utils_1.generateRegistrationNode)(creds, config);
321
+ logger.info({ node }, 'not logged in, attempting registration...');
322
+ }
323
+ else {
324
+ node = (0, Utils_1.generateLoginNode)(creds.me.id, config);
325
+ logger.info({ node }, 'logging in...');
326
+ }
327
+ const payloadEnc = noise.encrypt(index_js_1.proto.ClientPayload.encode(node).finish());
328
+ await sendRawMessage(index_js_1.proto.HandshakeMessage.encode({
329
+ clientFinish: {
330
+ static: keyEnc,
331
+ payload: payloadEnc
332
+ }
333
+ }).finish());
334
+ await noise.finishInit();
335
+ startKeepAliveRequest();
336
+ };
337
+ const getAvailablePreKeysOnServer = async () => {
338
+ const result = await query({
339
+ tag: 'iq',
340
+ attrs: {
341
+ id: generateMessageTag(),
342
+ xmlns: 'encrypt',
343
+ type: 'get',
344
+ to: WABinary_1.S_WHATSAPP_NET
345
+ },
346
+ content: [{ tag: 'count', attrs: {} }]
347
+ });
348
+ const countChild = (0, WABinary_1.getBinaryNodeChild)(result, 'count');
349
+ return +countChild.attrs.value;
350
+ };
351
+ // Pre-key upload state management
352
+ let uploadPreKeysPromise = null;
353
+ let lastUploadTime = 0;
354
+ /** generates and uploads a set of pre-keys to the server */
355
+ const uploadPreKeys = async (count = Defaults_1.MIN_PREKEY_COUNT, retryCount = 0) => {
356
+ // Check minimum interval (except for retries)
357
+ if (retryCount === 0) {
358
+ const timeSinceLastUpload = Date.now() - lastUploadTime;
359
+ if (timeSinceLastUpload < Defaults_1.MIN_UPLOAD_INTERVAL) {
360
+ logger.debug(`Skipping upload, only ${timeSinceLastUpload}ms since last upload`);
361
+ return;
362
+ }
363
+ }
364
+ // Prevent multiple concurrent uploads
365
+ if (uploadPreKeysPromise) {
366
+ logger.debug('Pre-key upload already in progress, waiting for completion');
367
+ await uploadPreKeysPromise;
368
+ }
369
+ const uploadLogic = async () => {
370
+ logger.info({ count, retryCount }, 'uploading pre-keys');
371
+ // Generate and save pre-keys atomically (prevents ID collisions on retry)
372
+ const node = await keys.transaction(async () => {
373
+ logger.debug({ requestedCount: count }, 'generating pre-keys with requested count');
374
+ const { update, node } = await (0, Utils_1.getNextPreKeysNode)({ creds, keys }, count);
375
+ // Update credentials immediately to prevent duplicate IDs on retry
376
+ ev.emit('creds.update', update);
377
+ return node; // Only return node since update is already used
378
+ }, creds?.me?.id || 'upload-pre-keys');
379
+ // Upload to server (outside transaction, can fail without affecting local keys)
380
+ try {
381
+ await query(node);
382
+ logger.info({ count }, 'uploaded pre-keys successfully');
383
+ lastUploadTime = Date.now();
384
+ }
385
+ catch (uploadError) {
386
+ logger.error({ uploadError: uploadError.toString(), count }, 'Failed to upload pre-keys to server');
387
+ // Exponential backoff retry (max 3 retries)
388
+ if (retryCount < 3) {
389
+ const backoffDelay = Math.min(1000 * Math.pow(2, retryCount), 10000);
390
+ logger.info(`Retrying pre-key upload in ${backoffDelay}ms`);
391
+ await new Promise(resolve => setTimeout(resolve, backoffDelay));
392
+ return uploadPreKeys(count, retryCount + 1);
393
+ }
394
+ throw uploadError;
395
+ }
396
+ };
397
+ // Add timeout protection
398
+ uploadPreKeysPromise = Promise.race([
399
+ uploadLogic(),
400
+ new Promise((_, reject) => setTimeout(() => reject(new boom_1.Boom('Pre-key upload timeout', { statusCode: 408 })), Defaults_1.UPLOAD_TIMEOUT))
401
+ ]);
402
+ try {
403
+ await uploadPreKeysPromise;
404
+ }
405
+ finally {
406
+ uploadPreKeysPromise = null;
407
+ }
408
+ };
409
+ const verifyCurrentPreKeyExists = async () => {
410
+ const currentPreKeyId = creds.nextPreKeyId - 1;
411
+ if (currentPreKeyId <= 0) {
412
+ return { exists: false, currentPreKeyId: 0 };
413
+ }
414
+ const preKeys = await keys.get('pre-key', [currentPreKeyId.toString()]);
415
+ const exists = !!preKeys[currentPreKeyId.toString()];
416
+ return { exists, currentPreKeyId };
417
+ };
418
+ const uploadPreKeysToServerIfRequired = async () => {
419
+ try {
420
+ let count = 0;
421
+ const preKeyCount = await getAvailablePreKeysOnServer();
422
+ if (preKeyCount === 0)
423
+ count = Defaults_1.INITIAL_PREKEY_COUNT;
424
+ else
425
+ count = Defaults_1.MIN_PREKEY_COUNT;
426
+ const { exists: currentPreKeyExists, currentPreKeyId } = await verifyCurrentPreKeyExists();
427
+ logger.info(`${preKeyCount} pre-keys found on server`);
428
+ logger.info(`Current prekey ID: ${currentPreKeyId}, exists in storage: ${currentPreKeyExists}`);
429
+ const lowServerCount = preKeyCount <= count;
430
+ const missingCurrentPreKey = !currentPreKeyExists && currentPreKeyId > 0;
431
+ const shouldUpload = lowServerCount || missingCurrentPreKey;
432
+ if (shouldUpload) {
433
+ const reasons = [];
434
+ if (lowServerCount)
435
+ reasons.push(`server count low (${preKeyCount})`);
436
+ if (missingCurrentPreKey)
437
+ reasons.push(`current prekey ${currentPreKeyId} missing from storage`);
438
+ logger.info(`Uploading PreKeys due to: ${reasons.join(', ')}`);
439
+ await uploadPreKeys(count);
440
+ }
441
+ else {
442
+ logger.info(`PreKey validation passed - Server: ${preKeyCount}, Current prekey ${currentPreKeyId} exists`);
443
+ }
444
+ }
445
+ catch (error) {
446
+ logger.error({ error }, 'Failed to check/upload pre-keys during initialization');
447
+ // Don't throw - allow connection to continue even if pre-key check fails
448
+ }
449
+ };
450
+ const onMessageReceived = async (data) => {
451
+ await noise.decodeFrame(data, frame => {
452
+ // reset ping timeout
453
+ lastDateRecv = new Date();
454
+ let anyTriggered = false;
455
+ anyTriggered = ws.emit('frame', frame);
456
+ // if it's a binary node
457
+ if (!(frame instanceof Uint8Array)) {
458
+ const msgId = frame.attrs.id;
459
+ if (logger.level === 'trace') {
460
+ logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'recv xml' });
461
+ }
462
+ /* Check if this is a response to a message we sent */
463
+ anyTriggered = ws.emit(`${Defaults_1.DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
464
+ /* Check if this is a response to a message we are expecting */
465
+ const l0 = frame.tag;
466
+ const l1 = frame.attrs || {};
467
+ const l2 = Array.isArray(frame.content) ? frame.content[0]?.tag : '';
468
+ for (const key of Object.keys(l1)) {
469
+ anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
470
+ anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
471
+ anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
472
+ }
473
+ anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
474
+ anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
475
+ if (!anyTriggered && logger.level === 'debug') {
476
+ logger.debug({ unhandled: true, msgId, fromMe: false, frame }, 'communication recv');
477
+ }
478
+ }
479
+ });
480
+ };
481
+ const end = async (error) => {
482
+ if (closed) {
483
+ logger.trace({ trace: error?.stack }, 'connection already closed');
484
+ return;
485
+ }
486
+ closed = true;
487
+ logger.info({ trace: error?.stack }, error ? 'connection errored' : 'connection closed');
488
+ clearInterval(keepAliveReq);
489
+ clearTimeout(qrTimer);
490
+ ws.removeAllListeners('close');
491
+ ws.removeAllListeners('open');
492
+ ws.removeAllListeners('message');
493
+ if (!ws.isClosed && !ws.isClosing) {
494
+ try {
495
+ await ws.close();
496
+ }
497
+ catch { }
498
+ }
499
+ ev.emit('connection.update', {
500
+ connection: 'close',
501
+ lastDisconnect: {
502
+ error,
503
+ date: new Date()
504
+ }
505
+ });
506
+ ev.removeAllListeners('connection.update');
507
+ };
508
+ const waitForSocketOpen = async () => {
509
+ if (ws.isOpen) {
510
+ return;
511
+ }
512
+ if (ws.isClosed || ws.isClosing) {
513
+ throw new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed });
514
+ }
515
+ let onOpen;
516
+ let onClose;
517
+ await new Promise((resolve, reject) => {
518
+ onOpen = () => resolve(undefined);
519
+ onClose = mapWebSocketError(reject);
520
+ ws.on('open', onOpen);
521
+ ws.on('close', onClose);
522
+ ws.on('error', onClose);
523
+ }).finally(() => {
524
+ ws.off('open', onOpen);
525
+ ws.off('close', onClose);
526
+ ws.off('error', onClose);
527
+ });
528
+ };
529
+ const startKeepAliveRequest = () => (keepAliveReq = setInterval(() => {
530
+ if (!lastDateRecv) {
531
+ lastDateRecv = new Date();
532
+ }
533
+ const diff = Date.now() - lastDateRecv.getTime();
534
+ /*
535
+ check if it's been a suspicious amount of time since the server responded with our last seen
536
+ it could be that the network is down
537
+ */
538
+ if (diff > keepAliveIntervalMs + 5000) {
539
+ void end(new boom_1.Boom('Connection was lost', { statusCode: Types_1.DisconnectReason.connectionLost }));
540
+ }
541
+ else if (ws.isOpen) {
542
+ // if its all good, send a keep alive request
543
+ query({
544
+ tag: 'iq',
545
+ attrs: {
546
+ id: generateMessageTag(),
547
+ to: WABinary_1.S_WHATSAPP_NET,
548
+ type: 'get',
549
+ xmlns: 'w:p'
550
+ },
551
+ content: [{ tag: 'ping', attrs: {} }]
552
+ }).catch(err => {
553
+ logger.error({ trace: err.stack }, 'error in sending keep alive');
554
+ });
555
+ }
556
+ else {
557
+ logger.warn('keep alive called when WS not open');
558
+ }
559
+ }, keepAliveIntervalMs));
560
+ /** i have no idea why this exists. pls enlighten me */
561
+ const sendPassiveIq = (tag) => query({
562
+ tag: 'iq',
563
+ attrs: {
564
+ to: WABinary_1.S_WHATSAPP_NET,
565
+ xmlns: 'passive',
566
+ type: 'set'
567
+ },
568
+ content: [{ tag, attrs: {} }]
569
+ });
570
+ /** logout & invalidate connection */
571
+ const logout = async (msg) => {
572
+ const jid = authState.creds.me?.id;
573
+ if (jid) {
574
+ await sendNode({
575
+ tag: 'iq',
576
+ attrs: {
577
+ to: WABinary_1.S_WHATSAPP_NET,
578
+ type: 'set',
579
+ id: generateMessageTag(),
580
+ xmlns: 'md'
581
+ },
582
+ content: [
583
+ {
584
+ tag: 'remove-companion-device',
585
+ attrs: {
586
+ jid,
587
+ reason: 'user_initiated'
588
+ }
589
+ }
590
+ ]
591
+ });
592
+ }
593
+ void end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
594
+ };
595
+ const requestPairingCode = async (phoneNumber, customPairingCode) => {
596
+ const pairingCode = customPairingCode ?? (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
597
+ if (customPairingCode && customPairingCode?.length !== 8) {
598
+ throw new Error('Custom pairing code must be exactly 8 chars');
599
+ }
600
+ authState.creds.pairingCode = pairingCode;
601
+ authState.creds.me = {
602
+ id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
603
+ name: '~'
604
+ };
605
+ ev.emit('creds.update', authState.creds);
606
+ await sendNode({
607
+ tag: 'iq',
608
+ attrs: {
609
+ to: WABinary_1.S_WHATSAPP_NET,
610
+ type: 'set',
611
+ id: generateMessageTag(),
612
+ xmlns: 'md'
613
+ },
614
+ content: [
615
+ {
616
+ tag: 'link_code_companion_reg',
617
+ attrs: {
618
+ jid: authState.creds.me.id,
619
+ stage: 'companion_hello',
620
+ should_show_push_notification: 'true'
621
+ },
622
+ content: [
623
+ {
624
+ tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
625
+ attrs: {},
626
+ content: await generatePairingKey()
627
+ },
628
+ {
629
+ tag: 'companion_server_auth_key_pub',
630
+ attrs: {},
631
+ content: authState.creds.noiseKey.public
632
+ },
633
+ {
634
+ tag: 'companion_platform_id',
635
+ attrs: {},
636
+ content: (0, browser_utils_1.getPlatformId)(browser[1])
637
+ },
638
+ {
639
+ tag: 'companion_platform_display',
640
+ attrs: {},
641
+ content: `${browser[1]} (${browser[0]})`
642
+ },
643
+ {
644
+ tag: 'link_code_pairing_nonce',
645
+ attrs: {},
646
+ content: '0'
647
+ }
648
+ ]
649
+ }
650
+ ]
651
+ });
652
+ return authState.creds.pairingCode;
653
+ };
654
+ async function generatePairingKey() {
655
+ const salt = (0, crypto_1.randomBytes)(32);
656
+ const randomIv = (0, crypto_1.randomBytes)(16);
657
+ const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
658
+ const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
659
+ return Buffer.concat([salt, randomIv, ciphered]);
660
+ }
661
+ const sendWAMBuffer = (wamBuffer) => {
662
+ return query({
663
+ tag: 'iq',
664
+ attrs: {
665
+ to: WABinary_1.S_WHATSAPP_NET,
666
+ id: generateMessageTag(),
667
+ xmlns: 'w:stats'
668
+ },
669
+ content: [
670
+ {
671
+ tag: 'add',
672
+ attrs: { t: Math.round(Date.now() / 1000) + '' },
673
+ content: wamBuffer
674
+ }
675
+ ]
676
+ });
677
+ };
678
+ ws.on('message', onMessageReceived);
679
+ ws.on('open', async () => {
680
+ try {
681
+ await validateConnection();
682
+ }
683
+ catch (err) {
684
+ logger.error({ err }, 'error in validating connection');
685
+ void end(err);
686
+ }
687
+ });
688
+ ws.on('error', mapWebSocketError(end));
689
+ ws.on('close', () => void end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
690
+ // the server terminated the connection
691
+ ws.on('CB:xmlstreamend', () => void end(new boom_1.Boom('Connection Terminated by Server', { statusCode: Types_1.DisconnectReason.connectionClosed })));
692
+ // QR gen
693
+ ws.on('CB:iq,type:set,pair-device', async (stanza) => {
694
+ const iq = {
695
+ tag: 'iq',
696
+ attrs: {
697
+ to: WABinary_1.S_WHATSAPP_NET,
698
+ type: 'result',
699
+ id: stanza.attrs.id
700
+ }
701
+ };
702
+ await sendNode(iq);
703
+ const pairDeviceNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-device');
704
+ const refNodes = (0, WABinary_1.getBinaryNodeChildren)(pairDeviceNode, 'ref');
705
+ const noiseKeyB64 = Buffer.from(creds.noiseKey.public).toString('base64');
706
+ const identityKeyB64 = Buffer.from(creds.signedIdentityKey.public).toString('base64');
707
+ const advB64 = creds.advSecretKey;
708
+ let qrMs = qrTimeout || 60000; // time to let a QR live
709
+ const genPairQR = () => {
710
+ if (!ws.isOpen) {
711
+ return;
712
+ }
713
+ const refNode = refNodes.shift();
714
+ if (!refNode) {
715
+ void end(new boom_1.Boom('QR refs attempts ended', { statusCode: Types_1.DisconnectReason.timedOut }));
716
+ return;
717
+ }
718
+ const ref = refNode.content.toString('utf-8');
719
+ const qr = [ref, noiseKeyB64, identityKeyB64, advB64].join(',');
720
+ ev.emit('connection.update', { qr });
721
+ qrTimer = setTimeout(genPairQR, qrMs);
722
+ qrMs = qrTimeout || 20000; // shorter subsequent qrs
723
+ };
724
+ genPairQR();
725
+ });
726
+ // device paired for the first time
727
+ // if device pairs successfully, the server asks to restart the connection
728
+ ws.on('CB:iq,,pair-success', async (stanza) => {
729
+ logger.debug('pair success recv');
730
+ try {
731
+ updateServerTimeOffset(stanza);
732
+ const { reply, creds: updatedCreds } = (0, Utils_1.configureSuccessfulPairing)(stanza, creds);
733
+ logger.info({ me: updatedCreds.me, platform: updatedCreds.platform }, 'pairing configured successfully, expect to restart the connection...');
734
+ ev.emit('creds.update', updatedCreds);
735
+ ev.emit('connection.update', { isNewLogin: true, qr: undefined });
736
+ await sendNode(reply);
737
+ void sendUnifiedSession();
738
+ }
739
+ catch (error) {
740
+ logger.info({ trace: error.stack }, 'error in pairing');
741
+ void end(error);
742
+ }
743
+ });
744
+ // login complete
745
+ ws.on('CB:success', async (node) => {
746
+ try {
747
+ updateServerTimeOffset(node);
748
+ await uploadPreKeysToServerIfRequired();
749
+ await sendPassiveIq('active');
750
+ // After successful login, validate our key-bundle against server
751
+ try {
752
+ await digestKeyBundle();
753
+ }
754
+ catch (e) {
755
+ logger.warn({ e }, 'failed to run digest after login');
756
+ }
757
+ }
758
+ catch (err) {
759
+ logger.warn({ err }, 'failed to send initial passive iq');
760
+ }
761
+ logger.info('opened connection to WA');
762
+ clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
763
+ // Store lid in creds for backwards compat (server still sends it)
764
+ ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
765
+ ev.emit('connection.update', { connection: 'open' });
766
+ void sendUnifiedSession();
767
+ if (node.attrs.lid && authState.creds.me?.id) {
768
+ const myLID = node.attrs.lid;
769
+ process.nextTick(async () => {
770
+ try {
771
+ const myPN = authState.creds.me.id;
772
+ // JID-first: store LID→JID mapping so incoming LID messages resolve correctly
773
+ await signalRepository.jidMapping.storeLIDPNMappings([{ lid: myLID, pn: myPN }]);
774
+ // Create device list for our own user
775
+ const { user, device } = (0, WABinary_1.jidDecode)(myPN);
776
+ await authState.keys.set({
777
+ 'device-list': {
778
+ [user]: [device?.toString() || '0']
779
+ }
780
+ });
781
+ logger.info({ myPN, myLID }, 'LID→JID mapping stored (JID-first mode)');
782
+ }
783
+ catch (error) {
784
+ logger.error({ error, lid: myLID }, 'Failed to store LID→JID mapping');
785
+ }
786
+ });
787
+ }
788
+ });
789
+ ws.on('CB:stream:error', (node) => {
790
+ const [reasonNode] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
791
+ logger.error({ reasonNode, fullErrorNode: node }, 'stream errored out');
792
+ const { reason, statusCode } = (0, Utils_1.getErrorCodeFromStreamError)(node);
793
+ void end(new boom_1.Boom(`Stream Errored (${reason})`, { statusCode, data: reasonNode || node }));
794
+ });
795
+ // stream fail, possible logout
796
+ ws.on('CB:failure', (node) => {
797
+ const reason = +(node.attrs.reason || 500);
798
+ void end(new boom_1.Boom('Connection Failure', { statusCode: reason, data: node.attrs }));
799
+ });
800
+ ws.on('CB:ib,,downgrade_webclient', () => {
801
+ void end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
802
+ });
803
+ ws.on('CB:ib,,offline_preview', async (node) => {
804
+ logger.info('offline preview received', JSON.stringify(node));
805
+ await sendNode({
806
+ tag: 'ib',
807
+ attrs: {},
808
+ content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
809
+ });
810
+ });
811
+ ws.on('CB:ib,,edge_routing', (node) => {
812
+ const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
813
+ const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
814
+ if (routingInfo?.content) {
815
+ authState.creds.routingInfo = Buffer.from(routingInfo?.content);
816
+ ev.emit('creds.update', authState.creds);
817
+ }
818
+ });
819
+ let didStartBuffer = false;
820
+ process.nextTick(() => {
821
+ if (creds.me?.id) {
822
+ // start buffering important events
823
+ // if we're logged in
824
+ ev.buffer();
825
+ didStartBuffer = true;
826
+ }
827
+ ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
828
+ });
829
+ // called when all offline notifs are handled
830
+ ws.on('CB:ib,,offline', (node) => {
831
+ const child = (0, WABinary_1.getBinaryNodeChild)(node, 'offline');
832
+ const offlineNotifs = +(child?.attrs.count || 0);
833
+ logger.info(`handled ${offlineNotifs} offline messages/notifications`);
834
+ if (didStartBuffer) {
835
+ ev.flush();
836
+ logger.trace('flushed events for initial buffer');
837
+ }
838
+ ev.emit('connection.update', { receivedPendingNotifications: true });
839
+ });
840
+ // update credentials when required
841
+ ev.on('creds.update', update => {
842
+ const name = update.me?.name;
843
+ // if name has just been received
844
+ if (creds.me?.name !== name) {
845
+ logger.debug({ name }, 'updated pushName');
846
+ sendNode({
847
+ tag: 'presence',
848
+ attrs: { name: name }
849
+ }).catch(err => {
850
+ logger.warn({ trace: err.stack }, 'error in sending presence update on name change');
851
+ });
852
+ }
853
+ Object.assign(creds, update);
854
+ });
855
+ const updateServerTimeOffset = ({ attrs }) => {
856
+ const tValue = attrs?.t;
857
+ if (!tValue) {
858
+ return;
859
+ }
860
+ const parsed = Number(tValue);
861
+ if (Number.isNaN(parsed) || parsed <= 0) {
862
+ return;
863
+ }
864
+ const localMs = Date.now();
865
+ serverTimeOffsetMs = parsed * 1000 - localMs;
866
+ logger.debug({ offset: serverTimeOffsetMs }, 'calculated server time offset');
867
+ };
868
+ const getUnifiedSessionId = () => {
869
+ const offsetMs = 3 * Defaults_1.TimeMs.Day;
870
+ const now = Date.now() + serverTimeOffsetMs;
871
+ const id = (now + offsetMs) % Defaults_1.TimeMs.Week;
872
+ return id.toString();
873
+ };
874
+ const sendUnifiedSession = async () => {
875
+ if (!ws.isOpen) {
876
+ return;
877
+ }
878
+ const node = {
879
+ tag: 'ib',
880
+ attrs: {},
881
+ content: [
882
+ {
883
+ tag: 'unified_session',
884
+ attrs: {
885
+ id: getUnifiedSessionId()
886
+ }
887
+ }
888
+ ]
889
+ };
890
+ try {
891
+ await sendNode(node);
892
+ }
893
+ catch (error) {
894
+ logger.debug({ error }, 'failed to send unified_session telemetry');
895
+ }
896
+ };
897
+ return {
898
+ type: 'md',
899
+ ws,
900
+ ev,
901
+ authState: { creds, keys },
902
+ signalRepository,
903
+ get user() {
904
+ return authState.creds.me;
905
+ },
906
+ generateMessageTag,
907
+ query,
908
+ waitForMessage,
909
+ waitForSocketOpen,
910
+ sendRawMessage,
911
+ sendNode,
912
+ logout,
913
+ end,
914
+ onUnexpectedError,
915
+ uploadPreKeys,
916
+ uploadPreKeysToServerIfRequired,
917
+ digestKeyBundle,
918
+ rotateSignedPreKey,
919
+ requestPairingCode,
920
+ updateServerTimeOffset,
921
+ sendUnifiedSession,
922
+ wamBuffer: publicWAMBuffer,
923
+ /** Waits for the connection to WA to reach a state */
924
+ waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
925
+ sendWAMBuffer,
926
+ executeUSyncQuery,
927
+ onWhatsApp
928
+ };
929
+ };
930
+ exports.makeSocket = makeSocket;
931
+ /**
932
+ * map the websocket error to the right type
933
+ * so it can be retried by the caller
934
+ * */
935
+ function mapWebSocketError(handler) {
936
+ return (error) => {
937
+ handler(new boom_1.Boom(`WebSocket Error (${error?.message})`, { statusCode: (0, Utils_1.getCodeFromWSError)(error), data: error }));
938
+ };
939
+ }
940
+ //# sourceMappingURL=socket.js.map