@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,835 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.uploadWithNodeHttp = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.getHttpStream = exports.getStream = exports.toBuffer = exports.toReadable = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getRawMediaUploadData = exports.hkdfInfoKey = void 0;
37
+ exports.getMediaKeys = getMediaKeys;
38
+ exports.getAudioDuration = getAudioDuration;
39
+ exports.getAudioWaveform = getAudioWaveform;
40
+ exports.generateThumbnail = generateThumbnail;
41
+ exports.extensionForMediaMessage = extensionForMediaMessage;
42
+ const boom_1 = require("@hapi/boom");
43
+ const child_process_1 = require("child_process");
44
+ const Crypto = __importStar(require("crypto"));
45
+ const events_1 = require("events");
46
+ const fs_1 = require("fs");
47
+ const os_1 = require("os");
48
+ const path_1 = require("path");
49
+ const stream_1 = require("stream");
50
+ const url_1 = require("url");
51
+ const index_js_1 = require("../../WAProto/index.js");
52
+ const Defaults_1 = require("../Defaults");
53
+ const WABinary_1 = require("../WABinary");
54
+ const crypto_1 = require("./crypto");
55
+ const generics_1 = require("./generics");
56
+ const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
57
+ const getImageProcessingLibrary = async () => {
58
+ //@ts-ignore
59
+ const [jimp, sharp] = await Promise.all([Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { }), Promise.resolve().then(() => __importStar(require('sharp'))).catch(() => { })]);
60
+ if (sharp) {
61
+ return { sharp };
62
+ }
63
+ if (jimp) {
64
+ return { jimp };
65
+ }
66
+ throw new boom_1.Boom('No image processing library available');
67
+ };
68
+ const hkdfInfoKey = (type) => {
69
+ const hkdfInfo = Defaults_1.MEDIA_HKDF_KEY_MAPPING[type];
70
+ return `WhatsApp ${hkdfInfo} Keys`;
71
+ };
72
+ exports.hkdfInfoKey = hkdfInfoKey;
73
+ const getRawMediaUploadData = async (media, mediaType, logger) => {
74
+ const { stream } = await (0, exports.getStream)(media);
75
+ logger?.debug('got stream for raw upload');
76
+ const hasher = Crypto.createHash('sha256');
77
+ const filePath = (0, path_1.join)((0, os_1.tmpdir)(), mediaType + (0, generics_1.generateMessageIDV2)());
78
+ const fileWriteStream = (0, fs_1.createWriteStream)(filePath);
79
+ let fileLength = 0;
80
+ try {
81
+ for await (const data of stream) {
82
+ fileLength += data.length;
83
+ hasher.update(data);
84
+ if (!fileWriteStream.write(data)) {
85
+ await (0, events_1.once)(fileWriteStream, 'drain');
86
+ }
87
+ }
88
+ fileWriteStream.end();
89
+ await (0, events_1.once)(fileWriteStream, 'finish');
90
+ stream.destroy();
91
+ const fileSha256 = hasher.digest();
92
+ logger?.debug('hashed data for raw upload');
93
+ return {
94
+ filePath: filePath,
95
+ fileSha256,
96
+ fileLength
97
+ };
98
+ }
99
+ catch (error) {
100
+ fileWriteStream.destroy();
101
+ stream.destroy();
102
+ try {
103
+ await fs_1.promises.unlink(filePath);
104
+ }
105
+ catch {
106
+ //
107
+ }
108
+ throw error;
109
+ }
110
+ };
111
+ exports.getRawMediaUploadData = getRawMediaUploadData;
112
+ /** generates all the keys required to encrypt/decrypt & sign a media message */
113
+ async function getMediaKeys(buffer, mediaType) {
114
+ if (!buffer) {
115
+ throw new boom_1.Boom('Cannot derive from empty media key');
116
+ }
117
+ if (typeof buffer === 'string') {
118
+ buffer = Buffer.from(buffer.replace('data:;base64,', ''), 'base64');
119
+ }
120
+ // expand using HKDF to 112 bytes, also pass in the relevant app info
121
+ const expandedMediaKey = (0, crypto_1.hkdf)(buffer, 112, { info: (0, exports.hkdfInfoKey)(mediaType) });
122
+ return {
123
+ iv: expandedMediaKey.slice(0, 16),
124
+ cipherKey: expandedMediaKey.slice(16, 48),
125
+ macKey: expandedMediaKey.slice(48, 80)
126
+ };
127
+ }
128
+ /** Extracts video thumb using FFMPEG */
129
+ const extractVideoThumb = async (path, destPath, time, size) => new Promise((resolve, reject) => {
130
+ const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`;
131
+ (0, child_process_1.exec)(cmd, err => {
132
+ if (err) {
133
+ reject(err);
134
+ }
135
+ else {
136
+ resolve();
137
+ }
138
+ });
139
+ });
140
+ const extractImageThumb = async (bufferOrFilePath, width = 32) => {
141
+ // TODO: Move entirely to sharp, removing jimp as it supports readable streams
142
+ // This will have positive speed and performance impacts as well as minimizing RAM usage.
143
+ if (bufferOrFilePath instanceof stream_1.Readable) {
144
+ bufferOrFilePath = await (0, exports.toBuffer)(bufferOrFilePath);
145
+ }
146
+ const lib = await getImageProcessingLibrary();
147
+ if ('sharp' in lib && typeof lib.sharp?.default === 'function') {
148
+ const img = lib.sharp.default(bufferOrFilePath);
149
+ const dimensions = await img.metadata();
150
+ const buffer = await img.resize(width).jpeg({ quality: 50 }).toBuffer();
151
+ return {
152
+ buffer,
153
+ original: {
154
+ width: dimensions.width,
155
+ height: dimensions.height
156
+ }
157
+ };
158
+ }
159
+ else if ('jimp' in lib && typeof lib.jimp?.Jimp === 'object') {
160
+ const jimp = await lib.jimp.Jimp.read(bufferOrFilePath);
161
+ const dimensions = {
162
+ width: jimp.width,
163
+ height: jimp.height
164
+ };
165
+ const buffer = await jimp
166
+ .resize({ w: width, mode: lib.jimp.ResizeStrategy.BILINEAR })
167
+ .getBuffer('image/jpeg', { quality: 50 });
168
+ return {
169
+ buffer,
170
+ original: dimensions
171
+ };
172
+ }
173
+ else {
174
+ throw new boom_1.Boom('No image processing library available');
175
+ }
176
+ };
177
+ exports.extractImageThumb = extractImageThumb;
178
+ const encodeBase64EncodedStringForUpload = (b64) => encodeURIComponent(b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, ''));
179
+ exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
180
+ const generateProfilePicture = async (mediaUpload, dimensions) => {
181
+ let buffer;
182
+ const { width: w = 640, height: h = 640 } = dimensions || {};
183
+ if (Buffer.isBuffer(mediaUpload)) {
184
+ buffer = mediaUpload;
185
+ }
186
+ else {
187
+ // Use getStream to handle all WAMediaUpload types (Buffer, Stream, URL)
188
+ const { stream } = await (0, exports.getStream)(mediaUpload);
189
+ // Convert the resulting stream to a buffer
190
+ buffer = await (0, exports.toBuffer)(stream);
191
+ }
192
+ const lib = await getImageProcessingLibrary();
193
+ let img;
194
+ if ('sharp' in lib && typeof lib.sharp?.default === 'function') {
195
+ img = lib.sharp
196
+ .default(buffer)
197
+ .resize(w, h)
198
+ .jpeg({
199
+ quality: 50
200
+ })
201
+ .toBuffer();
202
+ }
203
+ else if ('jimp' in lib && typeof lib.jimp?.Jimp === 'function') {
204
+ const jimp = await lib.jimp.Jimp.read(buffer);
205
+ const min = Math.min(jimp.width, jimp.height);
206
+ const cropped = jimp.crop({ x: 0, y: 0, w: min, h: min });
207
+ img = cropped.resize({ w, h, mode: lib.jimp.ResizeStrategy.BILINEAR }).getBuffer('image/jpeg', { quality: 50 });
208
+ }
209
+ else {
210
+ throw new boom_1.Boom('No image processing library available');
211
+ }
212
+ return {
213
+ img: await img
214
+ };
215
+ };
216
+ exports.generateProfilePicture = generateProfilePicture;
217
+ /** gets the SHA256 of the given media message */
218
+ const mediaMessageSHA256B64 = (message) => {
219
+ const media = Object.values(message)[0];
220
+ return media?.fileSha256 && Buffer.from(media.fileSha256).toString('base64');
221
+ };
222
+ exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
223
+ async function getAudioDuration(buffer) {
224
+ const musicMetadata = await Promise.resolve().then(() => __importStar(require('music-metadata')));
225
+ let metadata;
226
+ const options = {
227
+ duration: true
228
+ };
229
+ if (Buffer.isBuffer(buffer)) {
230
+ metadata = await musicMetadata.parseBuffer(buffer, undefined, options);
231
+ }
232
+ else if (typeof buffer === 'string') {
233
+ metadata = await musicMetadata.parseFile(buffer, options);
234
+ }
235
+ else {
236
+ metadata = await musicMetadata.parseStream(buffer, undefined, options);
237
+ }
238
+ return metadata.format.duration;
239
+ }
240
+ /**
241
+ referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
242
+ */
243
+ async function getAudioWaveform(buffer, logger) {
244
+ try {
245
+ // @ts-ignore
246
+ const { default: decoder } = await Promise.resolve().then(() => __importStar(require('audio-decode')));
247
+ let audioData;
248
+ if (Buffer.isBuffer(buffer)) {
249
+ audioData = buffer;
250
+ }
251
+ else if (typeof buffer === 'string') {
252
+ const rStream = (0, fs_1.createReadStream)(buffer);
253
+ audioData = await (0, exports.toBuffer)(rStream);
254
+ }
255
+ else {
256
+ audioData = await (0, exports.toBuffer)(buffer);
257
+ }
258
+ const audioBuffer = await decoder(audioData);
259
+ const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
260
+ const samples = 64; // Number of samples we want to have in our final data set
261
+ const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
262
+ const filteredData = [];
263
+ for (let i = 0; i < samples; i++) {
264
+ const blockStart = blockSize * i; // the location of the first sample in the block
265
+ let sum = 0;
266
+ for (let j = 0; j < blockSize; j++) {
267
+ sum = sum + Math.abs(rawData[blockStart + j]); // find the sum of all the samples in the block
268
+ }
269
+ filteredData.push(sum / blockSize); // divide the sum by the block size to get the average
270
+ }
271
+ // This guarantees that the largest data point will be set to 1, and the rest of the data will scale proportionally.
272
+ const multiplier = Math.pow(Math.max(...filteredData), -1);
273
+ const normalizedData = filteredData.map(n => n * multiplier);
274
+ // Generate waveform like WhatsApp
275
+ const waveform = new Uint8Array(normalizedData.map(n => Math.floor(100 * n)));
276
+ return waveform;
277
+ }
278
+ catch (e) {
279
+ logger?.debug('Failed to generate waveform: ' + e);
280
+ }
281
+ }
282
+ const toReadable = (buffer) => {
283
+ const readable = new stream_1.Readable({ read: () => { } });
284
+ readable.push(buffer);
285
+ readable.push(null);
286
+ return readable;
287
+ };
288
+ exports.toReadable = toReadable;
289
+ const toBuffer = async (stream) => {
290
+ const chunks = [];
291
+ for await (const chunk of stream) {
292
+ chunks.push(chunk);
293
+ }
294
+ stream.destroy();
295
+ return Buffer.concat(chunks);
296
+ };
297
+ exports.toBuffer = toBuffer;
298
+ const getStream = async (item, opts) => {
299
+ if (Buffer.isBuffer(item)) {
300
+ return { stream: (0, exports.toReadable)(item), type: 'buffer' };
301
+ }
302
+ if ('stream' in item) {
303
+ return { stream: item.stream, type: 'readable' };
304
+ }
305
+ const urlStr = item.url.toString();
306
+ if (urlStr.startsWith('data:')) {
307
+ const buffer = Buffer.from(urlStr.split(',')[1], 'base64');
308
+ return { stream: (0, exports.toReadable)(buffer), type: 'buffer' };
309
+ }
310
+ if (urlStr.startsWith('http://') || urlStr.startsWith('https://')) {
311
+ return { stream: await (0, exports.getHttpStream)(item.url, opts), type: 'remote' };
312
+ }
313
+ return { stream: (0, fs_1.createReadStream)(item.url), type: 'file' };
314
+ };
315
+ exports.getStream = getStream;
316
+ /** generates a thumbnail for a given media, if required */
317
+ async function generateThumbnail(file, mediaType, options) {
318
+ let thumbnail;
319
+ let originalImageDimensions;
320
+ if (mediaType === 'image') {
321
+ const { buffer, original } = await (0, exports.extractImageThumb)(file);
322
+ thumbnail = buffer.toString('base64');
323
+ if (original.width && original.height) {
324
+ originalImageDimensions = {
325
+ width: original.width,
326
+ height: original.height
327
+ };
328
+ }
329
+ }
330
+ else if (mediaType === 'video') {
331
+ const imgFilename = (0, path_1.join)(getTmpFilesDirectory(), (0, generics_1.generateMessageIDV2)() + '.jpg');
332
+ try {
333
+ await extractVideoThumb(file, imgFilename, '00:00:00', { width: 32, height: 32 });
334
+ const buff = await fs_1.promises.readFile(imgFilename);
335
+ thumbnail = buff.toString('base64');
336
+ await fs_1.promises.unlink(imgFilename);
337
+ }
338
+ catch (err) {
339
+ options.logger?.debug('could not generate video thumb: ' + err);
340
+ }
341
+ }
342
+ return {
343
+ thumbnail,
344
+ originalImageDimensions
345
+ };
346
+ }
347
+ const getHttpStream = async (url, options = {}) => {
348
+ const response = await fetch(url.toString(), {
349
+ dispatcher: options.dispatcher,
350
+ method: 'GET',
351
+ headers: options.headers
352
+ });
353
+ if (!response.ok) {
354
+ throw new boom_1.Boom(`Failed to fetch stream from ${url}`, { statusCode: response.status, data: { url } });
355
+ }
356
+ // @ts-ignore Node18+ Readable.fromWeb exists
357
+ return response.body instanceof stream_1.Readable ? response.body : stream_1.Readable.fromWeb(response.body);
358
+ };
359
+ exports.getHttpStream = getHttpStream;
360
+ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
361
+ const { stream, type } = await (0, exports.getStream)(media, opts);
362
+ logger?.debug('fetched media stream');
363
+ const mediaKey = Crypto.randomBytes(32);
364
+ const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType);
365
+ const encFilePath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageIDV2)() + '-enc');
366
+ const encFileWriteStream = (0, fs_1.createWriteStream)(encFilePath);
367
+ let originalFileStream;
368
+ let originalFilePath;
369
+ if (saveOriginalFileIfRequired) {
370
+ originalFilePath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageIDV2)() + '-original');
371
+ originalFileStream = (0, fs_1.createWriteStream)(originalFilePath);
372
+ }
373
+ let fileLength = 0;
374
+ const aes = Crypto.createCipheriv('aes-256-cbc', cipherKey, iv);
375
+ const hmac = Crypto.createHmac('sha256', macKey).update(iv);
376
+ const sha256Plain = Crypto.createHash('sha256');
377
+ const sha256Enc = Crypto.createHash('sha256');
378
+ const onChunk = async (buff) => {
379
+ sha256Enc.update(buff);
380
+ hmac.update(buff);
381
+ // Handle backpressure: if write returns false, wait for drain
382
+ if (!encFileWriteStream.write(buff)) {
383
+ await (0, events_1.once)(encFileWriteStream, 'drain');
384
+ }
385
+ };
386
+ try {
387
+ for await (const data of stream) {
388
+ fileLength += data.length;
389
+ if (type === 'remote' &&
390
+ opts?.maxContentLength &&
391
+ fileLength + data.length > opts.maxContentLength) {
392
+ throw new boom_1.Boom(`content length exceeded when encrypting "${type}"`, {
393
+ data: { media, type }
394
+ });
395
+ }
396
+ if (originalFileStream) {
397
+ if (!originalFileStream.write(data)) {
398
+ await (0, events_1.once)(originalFileStream, 'drain');
399
+ }
400
+ }
401
+ sha256Plain.update(data);
402
+ await onChunk(aes.update(data));
403
+ }
404
+ await onChunk(aes.final());
405
+ const mac = hmac.digest().slice(0, 10);
406
+ sha256Enc.update(mac);
407
+ const fileSha256 = sha256Plain.digest();
408
+ const fileEncSha256 = sha256Enc.digest();
409
+ encFileWriteStream.write(mac);
410
+ const encFinishPromise = (0, events_1.once)(encFileWriteStream, 'finish');
411
+ const originalFinishPromise = originalFileStream ? (0, events_1.once)(originalFileStream, 'finish') : Promise.resolve();
412
+ encFileWriteStream.end();
413
+ originalFileStream?.end?.();
414
+ stream.destroy();
415
+ // Wait for write streams to fully flush to disk
416
+ // This helps reduce memory pressure by allowing OS to release buffers
417
+ await encFinishPromise;
418
+ await originalFinishPromise;
419
+ logger?.debug('encrypted data successfully');
420
+ return {
421
+ mediaKey,
422
+ originalFilePath,
423
+ encFilePath,
424
+ mac,
425
+ fileEncSha256,
426
+ fileSha256,
427
+ fileLength
428
+ };
429
+ }
430
+ catch (error) {
431
+ // destroy all streams with error
432
+ encFileWriteStream.destroy();
433
+ originalFileStream?.destroy?.();
434
+ aes.destroy();
435
+ hmac.destroy();
436
+ sha256Plain.destroy();
437
+ sha256Enc.destroy();
438
+ stream.destroy();
439
+ try {
440
+ await fs_1.promises.unlink(encFilePath);
441
+ if (originalFilePath) {
442
+ await fs_1.promises.unlink(originalFilePath);
443
+ }
444
+ }
445
+ catch (err) {
446
+ logger?.error({ err }, 'failed deleting tmp files');
447
+ }
448
+ throw error;
449
+ }
450
+ };
451
+ exports.encryptedStream = encryptedStream;
452
+ const DEF_HOST = 'mmg.whatsapp.net';
453
+ const AES_CHUNK_SIZE = 16;
454
+ const toSmallestChunkSize = (num) => {
455
+ return Math.floor(num / AES_CHUNK_SIZE) * AES_CHUNK_SIZE;
456
+ };
457
+ const getUrlFromDirectPath = (directPath) => `https://${DEF_HOST}${directPath}`;
458
+ exports.getUrlFromDirectPath = getUrlFromDirectPath;
459
+ const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
460
+ const isValidMediaUrl = url?.startsWith('https://mmg.whatsapp.net/');
461
+ const downloadUrl = isValidMediaUrl ? url : (0, exports.getUrlFromDirectPath)(directPath);
462
+ if (!downloadUrl) {
463
+ throw new boom_1.Boom('No valid media URL or directPath present in message', { statusCode: 400 });
464
+ }
465
+ const keys = await getMediaKeys(mediaKey, type);
466
+ return (0, exports.downloadEncryptedContent)(downloadUrl, keys, opts);
467
+ };
468
+ exports.downloadContentFromMessage = downloadContentFromMessage;
469
+ /**
470
+ * Decrypts and downloads an AES256-CBC encrypted file given the keys.
471
+ * Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
472
+ * */
473
+ const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startByte, endByte, options } = {}) => {
474
+ let bytesFetched = 0;
475
+ let startChunk = 0;
476
+ let firstBlockIsIV = false;
477
+ // if a start byte is specified -- then we need to fetch the previous chunk as that will form the IV
478
+ if (startByte) {
479
+ const chunk = toSmallestChunkSize(startByte || 0);
480
+ if (chunk) {
481
+ startChunk = chunk - AES_CHUNK_SIZE;
482
+ bytesFetched = chunk;
483
+ firstBlockIsIV = true;
484
+ }
485
+ }
486
+ const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined;
487
+ const headersInit = options?.headers ? options.headers : undefined;
488
+ const headers = {
489
+ ...(headersInit
490
+ ? Array.isArray(headersInit)
491
+ ? Object.fromEntries(headersInit)
492
+ : headersInit
493
+ : {}),
494
+ Origin: Defaults_1.DEFAULT_ORIGIN
495
+ };
496
+ if (startChunk || endChunk) {
497
+ headers.Range = `bytes=${startChunk}-`;
498
+ if (endChunk) {
499
+ headers.Range += endChunk;
500
+ }
501
+ }
502
+ // download the message
503
+ const fetched = await (0, exports.getHttpStream)(downloadUrl, {
504
+ ...(options || {}),
505
+ headers
506
+ });
507
+ let remainingBytes = Buffer.from([]);
508
+ let aes;
509
+ const pushBytes = (bytes, push) => {
510
+ if (startByte || endByte) {
511
+ const start = bytesFetched >= startByte ? undefined : Math.max(startByte - bytesFetched, 0);
512
+ const end = bytesFetched + bytes.length < endByte ? undefined : Math.max(endByte - bytesFetched, 0);
513
+ push(bytes.slice(start, end));
514
+ bytesFetched += bytes.length;
515
+ }
516
+ else {
517
+ push(bytes);
518
+ }
519
+ };
520
+ const output = new stream_1.Transform({
521
+ transform(chunk, _, callback) {
522
+ let data = Buffer.concat([remainingBytes, chunk]);
523
+ const decryptLength = toSmallestChunkSize(data.length);
524
+ remainingBytes = data.slice(decryptLength);
525
+ data = data.slice(0, decryptLength);
526
+ if (!aes) {
527
+ let ivValue = iv;
528
+ if (firstBlockIsIV) {
529
+ ivValue = data.slice(0, AES_CHUNK_SIZE);
530
+ data = data.slice(AES_CHUNK_SIZE);
531
+ }
532
+ aes = Crypto.createDecipheriv('aes-256-cbc', cipherKey, ivValue);
533
+ // if an end byte that is not EOF is specified
534
+ // stop auto padding (PKCS7) -- otherwise throws an error for decryption
535
+ if (endByte) {
536
+ aes.setAutoPadding(false);
537
+ }
538
+ }
539
+ try {
540
+ pushBytes(aes.update(data), b => this.push(b));
541
+ callback();
542
+ }
543
+ catch (error) {
544
+ callback(error);
545
+ }
546
+ },
547
+ final(callback) {
548
+ try {
549
+ pushBytes(aes.final(), b => this.push(b));
550
+ callback();
551
+ }
552
+ catch (error) {
553
+ callback(error);
554
+ }
555
+ }
556
+ });
557
+ return fetched.pipe(output, { end: true });
558
+ };
559
+ exports.downloadEncryptedContent = downloadEncryptedContent;
560
+ function extensionForMediaMessage(message) {
561
+ const getExtension = (mimetype) => mimetype.split(';')[0]?.split('/')[1];
562
+ const type = Object.keys(message)[0];
563
+ let extension;
564
+ if (type === 'locationMessage' || type === 'liveLocationMessage' || type === 'productMessage') {
565
+ extension = '.jpeg';
566
+ }
567
+ else {
568
+ const messageContent = message[type];
569
+ extension = getExtension(messageContent.mimetype);
570
+ }
571
+ return extension;
572
+ }
573
+ const isNodeRuntime = () => {
574
+ return (typeof process !== 'undefined' &&
575
+ process.versions?.node !== null &&
576
+ typeof process.versions.bun === 'undefined' &&
577
+ typeof globalThis.Deno === 'undefined');
578
+ };
579
+ const uploadWithNodeHttp = async ({ url, filePath, headers, timeoutMs, agent }, redirectCount = 0) => {
580
+ if (redirectCount > 5) {
581
+ throw new Error('Too many redirects');
582
+ }
583
+ const parsedUrl = new url_1.URL(url);
584
+ const httpModule = parsedUrl.protocol === 'https:' ? await Promise.resolve().then(() => __importStar(require('https'))) : await Promise.resolve().then(() => __importStar(require('http')));
585
+ // Get file size for Content-Length header (required for Node.js streaming)
586
+ const fileStats = await fs_1.promises.stat(filePath);
587
+ const fileSize = fileStats.size;
588
+ return new Promise((resolve, reject) => {
589
+ const req = httpModule.request({
590
+ hostname: parsedUrl.hostname,
591
+ port: parsedUrl.port || (parsedUrl.protocol === 'https:' ? 443 : 80),
592
+ path: parsedUrl.pathname + parsedUrl.search,
593
+ method: 'POST',
594
+ headers: {
595
+ ...headers,
596
+ 'Content-Length': fileSize
597
+ },
598
+ agent,
599
+ timeout: timeoutMs
600
+ }, res => {
601
+ // Handle redirects (3xx)
602
+ if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
603
+ res.resume(); // Consume response to free resources
604
+ const newUrl = new url_1.URL(res.headers.location, url).toString();
605
+ resolve((0, exports.uploadWithNodeHttp)({
606
+ url: newUrl,
607
+ filePath,
608
+ headers,
609
+ timeoutMs,
610
+ agent
611
+ }, redirectCount + 1));
612
+ return;
613
+ }
614
+ let body = '';
615
+ res.on('data', chunk => (body += chunk));
616
+ res.on('end', () => {
617
+ try {
618
+ resolve(JSON.parse(body));
619
+ }
620
+ catch {
621
+ resolve(undefined);
622
+ }
623
+ });
624
+ });
625
+ req.on('error', reject);
626
+ req.on('timeout', () => {
627
+ req.destroy();
628
+ reject(new Error('Upload timeout'));
629
+ });
630
+ const stream = (0, fs_1.createReadStream)(filePath);
631
+ stream.pipe(req);
632
+ stream.on('error', err => {
633
+ req.destroy();
634
+ reject(err);
635
+ });
636
+ });
637
+ };
638
+ exports.uploadWithNodeHttp = uploadWithNodeHttp;
639
+ const uploadWithFetch = async ({ url, filePath, headers, timeoutMs, agent }) => {
640
+ // Convert Node.js Readable to Web ReadableStream
641
+ const nodeStream = (0, fs_1.createReadStream)(filePath);
642
+ const webStream = stream_1.Readable.toWeb(nodeStream);
643
+ const response = await fetch(url, {
644
+ dispatcher: agent,
645
+ method: 'POST',
646
+ body: webStream,
647
+ headers,
648
+ duplex: 'half',
649
+ signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined
650
+ });
651
+ try {
652
+ return (await response.json());
653
+ }
654
+ catch {
655
+ return undefined;
656
+ }
657
+ };
658
+ /**
659
+ * Uploads media to WhatsApp servers.
660
+ *
661
+ * ## Why we have two upload implementations:
662
+ *
663
+ * Node.js's native `fetch` (powered by undici) has a known bug where it buffers
664
+ * the entire request body in memory before sending, even when using streams.
665
+ * This causes memory issues with large files (e.g., 1GB file = 1GB+ memory usage).
666
+ * See: https://github.com/nodejs/undici/issues/4058
667
+ *
668
+ * Other runtimes (Bun, Deno, browsers) correctly stream the request body without
669
+ * buffering, so we can use the web-standard Fetch API there.
670
+ *
671
+ * ## Future considerations:
672
+ * Once the undici bug is fixed, we can simplify this to use only the Fetch API
673
+ * across all runtimes. Monitor the GitHub issue for updates.
674
+ */
675
+ const uploadMedia = async (params, logger) => {
676
+ if (isNodeRuntime()) {
677
+ logger?.debug('Using Node.js https module for upload (avoids undici buffering bug)');
678
+ return (0, exports.uploadWithNodeHttp)(params);
679
+ }
680
+ else {
681
+ logger?.debug('Using web-standard Fetch API for upload');
682
+ return uploadWithFetch(params);
683
+ }
684
+ };
685
+ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
686
+ return async (filePath, { mediaType, fileEncSha256B64, timeoutMs }) => {
687
+ // send a query JSON to obtain the url & auth token to upload our media
688
+ let uploadInfo = await refreshMediaConn(false);
689
+ let urls;
690
+ const hosts = [...customUploadHosts, ...uploadInfo.hosts];
691
+ fileEncSha256B64 = (0, exports.encodeBase64EncodedStringForUpload)(fileEncSha256B64);
692
+ // Prepare common headers
693
+ const customHeaders = (() => {
694
+ const hdrs = options?.headers;
695
+ if (!hdrs)
696
+ return {};
697
+ return Array.isArray(hdrs) ? Object.fromEntries(hdrs) : hdrs;
698
+ })();
699
+ const headers = {
700
+ ...customHeaders,
701
+ 'Content-Type': 'application/octet-stream',
702
+ Origin: Defaults_1.DEFAULT_ORIGIN
703
+ };
704
+ for (const { hostname } of hosts) {
705
+ logger.debug(`uploading to "${hostname}"`);
706
+ const auth = encodeURIComponent(uploadInfo.auth);
707
+ const url = `https://${hostname}${Defaults_1.MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
708
+ let result;
709
+ try {
710
+ result = await uploadMedia({
711
+ url,
712
+ filePath,
713
+ headers,
714
+ timeoutMs,
715
+ agent: fetchAgent
716
+ }, logger);
717
+ if (result?.url || result?.direct_path) {
718
+ urls = {
719
+ mediaUrl: result.url,
720
+ directPath: result.direct_path,
721
+ meta_hmac: result.meta_hmac,
722
+ fbid: result.fbid,
723
+ ts: result.ts
724
+ };
725
+ break;
726
+ }
727
+ else {
728
+ uploadInfo = await refreshMediaConn(true);
729
+ throw new Error(`upload failed, reason: ${JSON.stringify(result)}`);
730
+ }
731
+ }
732
+ catch (error) {
733
+ const isLast = hostname === hosts[uploadInfo.hosts.length - 1]?.hostname;
734
+ logger.warn({ trace: error?.stack, uploadResult: result }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`);
735
+ }
736
+ }
737
+ if (!urls) {
738
+ throw new boom_1.Boom('Media upload failed on all hosts', { statusCode: 500 });
739
+ }
740
+ return urls;
741
+ };
742
+ };
743
+ exports.getWAUploadToServer = getWAUploadToServer;
744
+ const getMediaRetryKey = (mediaKey) => {
745
+ return (0, crypto_1.hkdf)(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' });
746
+ };
747
+ /**
748
+ * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
749
+ */
750
+ const encryptMediaRetryRequest = (key, mediaKey, meId) => {
751
+ const recp = { stanzaId: key.id };
752
+ const recpBuffer = index_js_1.proto.ServerErrorReceipt.encode(recp).finish();
753
+ const iv = Crypto.randomBytes(12);
754
+ const retryKey = getMediaRetryKey(mediaKey);
755
+ const ciphertext = (0, crypto_1.aesEncryptGCM)(recpBuffer, retryKey, iv, Buffer.from(key.id));
756
+ const req = {
757
+ tag: 'receipt',
758
+ attrs: {
759
+ id: key.id,
760
+ to: (0, WABinary_1.jidNormalizedUser)(meId),
761
+ type: 'server-error'
762
+ },
763
+ content: [
764
+ // this encrypt node is actually pretty useless
765
+ // the media is returned even without this node
766
+ // keeping it here to maintain parity with WA Web
767
+ {
768
+ tag: 'encrypt',
769
+ attrs: {},
770
+ content: [
771
+ { tag: 'enc_p', attrs: {}, content: ciphertext },
772
+ { tag: 'enc_iv', attrs: {}, content: iv }
773
+ ]
774
+ },
775
+ {
776
+ tag: 'rmr',
777
+ attrs: {
778
+ jid: key.remoteJid,
779
+ from_me: (!!key.fromMe).toString(),
780
+ // @ts-ignore
781
+ participant: key.participant || undefined
782
+ }
783
+ }
784
+ ]
785
+ };
786
+ return req;
787
+ };
788
+ exports.encryptMediaRetryRequest = encryptMediaRetryRequest;
789
+ const decodeMediaRetryNode = (node) => {
790
+ const rmrNode = (0, WABinary_1.getBinaryNodeChild)(node, 'rmr');
791
+ const event = {
792
+ key: {
793
+ id: node.attrs.id,
794
+ remoteJid: rmrNode.attrs.jid,
795
+ fromMe: rmrNode.attrs.from_me === 'true',
796
+ participant: rmrNode.attrs.participant
797
+ }
798
+ };
799
+ const errorNode = (0, WABinary_1.getBinaryNodeChild)(node, 'error');
800
+ if (errorNode) {
801
+ const errorCode = +errorNode.attrs.code;
802
+ event.error = new boom_1.Boom(`Failed to re-upload media (${errorCode})`, {
803
+ data: errorNode.attrs,
804
+ statusCode: (0, exports.getStatusCodeForMediaRetry)(errorCode)
805
+ });
806
+ }
807
+ else {
808
+ const encryptedInfoNode = (0, WABinary_1.getBinaryNodeChild)(node, 'encrypt');
809
+ const ciphertext = (0, WABinary_1.getBinaryNodeChildBuffer)(encryptedInfoNode, 'enc_p');
810
+ const iv = (0, WABinary_1.getBinaryNodeChildBuffer)(encryptedInfoNode, 'enc_iv');
811
+ if (ciphertext && iv) {
812
+ event.media = { ciphertext, iv };
813
+ }
814
+ else {
815
+ event.error = new boom_1.Boom('Failed to re-upload media (missing ciphertext)', { statusCode: 404 });
816
+ }
817
+ }
818
+ return event;
819
+ };
820
+ exports.decodeMediaRetryNode = decodeMediaRetryNode;
821
+ const decryptMediaRetryData = ({ ciphertext, iv }, mediaKey, msgId) => {
822
+ const retryKey = getMediaRetryKey(mediaKey);
823
+ const plaintext = (0, crypto_1.aesDecryptGCM)(ciphertext, retryKey, iv, Buffer.from(msgId));
824
+ return index_js_1.proto.MediaRetryNotification.decode(plaintext);
825
+ };
826
+ exports.decryptMediaRetryData = decryptMediaRetryData;
827
+ const getStatusCodeForMediaRetry = (code) => MEDIA_RETRY_STATUS_MAP[code];
828
+ exports.getStatusCodeForMediaRetry = getStatusCodeForMediaRetry;
829
+ const MEDIA_RETRY_STATUS_MAP = {
830
+ [index_js_1.proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
831
+ [index_js_1.proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
832
+ [index_js_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
833
+ [index_js_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418
834
+ };
835
+ //# sourceMappingURL=messages-media.js.map