@violetix/baileys 0.0.0-stage → 0.4.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 (458) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +3017 -2
  3. package/WAProto/index.d.ts +15932 -0
  4. package/WAProto/index.js +115856 -0
  5. package/engine-requirements.js +13 -0
  6. package/lib/Defaults/index.d.ts +145 -0
  7. package/lib/Defaults/index.d.ts.map +1 -0
  8. package/lib/Defaults/index.js +157 -0
  9. package/lib/Defaults/index.js.map +1 -0
  10. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  11. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  12. package/lib/Signal/Group/ciphertext-message.js +12 -0
  13. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  14. package/lib/Signal/Group/group-session-builder.d.ts +8 -0
  15. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  16. package/lib/Signal/Group/group-session-builder.js +30 -0
  17. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  18. package/lib/Signal/Group/group_cipher.d.ts +11 -0
  19. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  20. package/lib/Signal/Group/group_cipher.js +82 -0
  21. package/lib/Signal/Group/group_cipher.js.map +1 -0
  22. package/lib/Signal/Group/index.d.ts +12 -0
  23. package/lib/Signal/Group/index.d.ts.map +1 -0
  24. package/lib/Signal/Group/index.js +12 -0
  25. package/lib/Signal/Group/index.js.map +1 -0
  26. package/lib/Signal/Group/keyhelper.d.ts +7 -0
  27. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  28. package/lib/Signal/Group/keyhelper.js +18 -0
  29. package/lib/Signal/Group/keyhelper.js.map +1 -0
  30. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  31. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  32. package/lib/Signal/Group/sender-chain-key.js +26 -0
  33. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  34. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  35. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  36. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  38. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  39. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  40. package/lib/Signal/Group/sender-key-message.js +66 -0
  41. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  42. package/lib/Signal/Group/sender-key-name.d.ts +12 -0
  43. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  44. package/lib/Signal/Group/sender-key-name.js +48 -0
  45. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  46. package/lib/Signal/Group/sender-key-record.d.ts +13 -0
  47. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  48. package/lib/Signal/Group/sender-key-record.js +41 -0
  49. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  50. package/lib/Signal/Group/sender-key-state.d.ts +17 -0
  51. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  52. package/lib/Signal/Group/sender-key-state.js +84 -0
  53. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  54. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  55. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  56. package/lib/Signal/Group/sender-message-key.js +26 -0
  57. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  58. package/lib/Signal/libsignal.d.ts +55 -0
  59. package/lib/Signal/libsignal.d.ts.map +1 -0
  60. package/lib/Signal/libsignal.js +403 -0
  61. package/lib/Signal/libsignal.js.map +1 -0
  62. package/lib/Signal/lid-mapping.d.ts +21 -0
  63. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  64. package/lib/Signal/lid-mapping.js +277 -0
  65. package/lib/Signal/lid-mapping.js.map +1 -0
  66. package/lib/Socket/Client/index.d.ts +3 -0
  67. package/lib/Socket/Client/index.d.ts.map +1 -0
  68. package/lib/Socket/Client/index.js +3 -0
  69. package/lib/Socket/Client/index.js.map +1 -0
  70. package/lib/Socket/Client/types.d.ts +6 -0
  71. package/lib/Socket/Client/types.d.ts.map +1 -0
  72. package/lib/Socket/Client/types.js +93 -0
  73. package/lib/Socket/Client/types.js.map +1 -0
  74. package/lib/Socket/Client/websocket.d.ts +13 -0
  75. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  76. package/lib/Socket/Client/websocket.js +57 -0
  77. package/lib/Socket/Client/websocket.js.map +1 -0
  78. package/lib/Socket/business.d.ts +428 -0
  79. package/lib/Socket/business.d.ts.map +1 -0
  80. package/lib/Socket/business.js +380 -0
  81. package/lib/Socket/business.js.map +1 -0
  82. package/lib/Socket/chats.d.ts +176 -0
  83. package/lib/Socket/chats.d.ts.map +1 -0
  84. package/lib/Socket/chats.js +1238 -0
  85. package/lib/Socket/chats.js.map +1 -0
  86. package/lib/Socket/communities.d.ts +595 -0
  87. package/lib/Socket/communities.d.ts.map +1 -0
  88. package/lib/Socket/communities.js +432 -0
  89. package/lib/Socket/communities.js.map +1 -0
  90. package/lib/Socket/graphql.js +908 -0
  91. package/lib/Socket/groups.d.ts +318 -0
  92. package/lib/Socket/groups.d.ts.map +1 -0
  93. package/lib/Socket/groups.js +364 -0
  94. package/lib/Socket/groups.js.map +1 -0
  95. package/lib/Socket/index.d.ts +947 -0
  96. package/lib/Socket/index.d.ts.map +1 -0
  97. package/lib/Socket/index.js +19 -0
  98. package/lib/Socket/index.js.map +1 -0
  99. package/lib/Socket/interop.js +562 -0
  100. package/lib/Socket/managed-account.js +210 -0
  101. package/lib/Socket/messages-recv.d.ts +367 -0
  102. package/lib/Socket/messages-recv.d.ts.map +1 -0
  103. package/lib/Socket/messages-recv.js +2199 -0
  104. package/lib/Socket/messages-recv.js.map +1 -0
  105. package/lib/Socket/messages-send.d.ts +364 -0
  106. package/lib/Socket/messages-send.d.ts.map +1 -0
  107. package/lib/Socket/messages-send.js +1631 -0
  108. package/lib/Socket/messages-send.js.map +1 -0
  109. package/lib/Socket/mex.d.ts +2 -0
  110. package/lib/Socket/mex.d.ts.map +1 -0
  111. package/lib/Socket/mex.js +42 -0
  112. package/lib/Socket/mex.js.map +1 -0
  113. package/lib/Socket/newsletter.d.ts +315 -0
  114. package/lib/Socket/newsletter.d.ts.map +1 -0
  115. package/lib/Socket/newsletter.js +235 -0
  116. package/lib/Socket/newsletter.js.map +1 -0
  117. package/lib/Socket/privacy.js +448 -0
  118. package/lib/Socket/registration.js +430 -0
  119. package/lib/Socket/socket.d.ts +99 -0
  120. package/lib/Socket/socket.d.ts.map +1 -0
  121. package/lib/Socket/socket.js +1290 -0
  122. package/lib/Socket/socket.js.map +1 -0
  123. package/lib/Store/index.d.ts +4 -0
  124. package/lib/Store/index.d.ts.map +1 -0
  125. package/lib/Store/index.js +4 -0
  126. package/lib/Store/index.js.map +1 -0
  127. package/lib/Store/make-in-memory-store.d.ts +63 -0
  128. package/lib/Store/make-in-memory-store.d.ts.map +1 -0
  129. package/lib/Store/make-in-memory-store.js +462 -0
  130. package/lib/Store/make-in-memory-store.js.map +1 -0
  131. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  132. package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
  133. package/lib/Store/make-ordered-dictionary.js +79 -0
  134. package/lib/Store/make-ordered-dictionary.js.map +1 -0
  135. package/lib/Store/object-repository.d.ts +11 -0
  136. package/lib/Store/object-repository.d.ts.map +1 -0
  137. package/lib/Store/object-repository.js +24 -0
  138. package/lib/Store/object-repository.js.map +1 -0
  139. package/lib/Types/Auth.d.ts +60 -0
  140. package/lib/Types/Auth.d.ts.map +1 -0
  141. package/lib/Types/Auth.js +2 -0
  142. package/lib/Types/Auth.js.map +1 -0
  143. package/lib/Types/Bussines.d.ts +9 -0
  144. package/lib/Types/Bussines.d.ts.map +1 -0
  145. package/lib/Types/Bussines.js +2 -0
  146. package/lib/Types/Bussines.js.map +1 -0
  147. package/lib/Types/Call.d.ts +22 -0
  148. package/lib/Types/Call.d.ts.map +1 -0
  149. package/lib/Types/Call.js +2 -0
  150. package/lib/Types/Call.js.map +1 -0
  151. package/lib/Types/Chat.d.ts +3 -0
  152. package/lib/Types/Chat.d.ts.map +1 -0
  153. package/lib/Types/Chat.js +8 -0
  154. package/lib/Types/Chat.js.map +1 -0
  155. package/lib/Types/Contact.d.ts +11 -0
  156. package/lib/Types/Contact.d.ts.map +1 -0
  157. package/lib/Types/Contact.js +2 -0
  158. package/lib/Types/Contact.js.map +1 -0
  159. package/lib/Types/Events.d.ts +41 -0
  160. package/lib/Types/Events.d.ts.map +1 -0
  161. package/lib/Types/Events.js +2 -0
  162. package/lib/Types/Events.js.map +1 -0
  163. package/lib/Types/GroupMetadata.d.ts +36 -0
  164. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  165. package/lib/Types/GroupMetadata.js +2 -0
  166. package/lib/Types/GroupMetadata.js.map +1 -0
  167. package/lib/Types/Label.d.ts +3 -0
  168. package/lib/Types/Label.d.ts.map +1 -0
  169. package/lib/Types/Label.js +25 -0
  170. package/lib/Types/Label.js.map +1 -0
  171. package/lib/Types/LabelAssociation.d.ts +3 -0
  172. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  173. package/lib/Types/LabelAssociation.js +7 -0
  174. package/lib/Types/LabelAssociation.js.map +1 -0
  175. package/lib/Types/Message.d.ts +22 -0
  176. package/lib/Types/Message.d.ts.map +1 -0
  177. package/lib/Types/Message.js +18 -0
  178. package/lib/Types/Message.js.map +1 -0
  179. package/lib/Types/Mex.d.ts +3 -0
  180. package/lib/Types/Mex.d.ts.map +1 -0
  181. package/lib/Types/Mex.js +49 -0
  182. package/lib/Types/Mex.js.map +1 -0
  183. package/lib/Types/Product.d.ts +5 -0
  184. package/lib/Types/Product.d.ts.map +1 -0
  185. package/lib/Types/Product.js +2 -0
  186. package/lib/Types/Product.js.map +1 -0
  187. package/lib/Types/RichType.d.ts +3 -0
  188. package/lib/Types/RichType.d.ts.map +1 -0
  189. package/lib/Types/RichType.js +23 -0
  190. package/lib/Types/RichType.js.map +1 -0
  191. package/lib/Types/Signal.d.ts +10 -0
  192. package/lib/Types/Signal.d.ts.map +1 -0
  193. package/lib/Types/Signal.js +2 -0
  194. package/lib/Types/Signal.js.map +1 -0
  195. package/lib/Types/Socket.d.ts +33 -0
  196. package/lib/Types/Socket.d.ts.map +1 -0
  197. package/lib/Types/Socket.js +2 -0
  198. package/lib/Types/Socket.js.map +1 -0
  199. package/lib/Types/State.d.ts +6 -0
  200. package/lib/Types/State.d.ts.map +1 -0
  201. package/lib/Types/State.js +56 -0
  202. package/lib/Types/State.js.map +1 -0
  203. package/lib/Types/USync.d.ts +9 -0
  204. package/lib/Types/USync.d.ts.map +1 -0
  205. package/lib/Types/USync.js +2 -0
  206. package/lib/Types/USync.js.map +1 -0
  207. package/lib/Types/index.d.ts +16 -0
  208. package/lib/Types/index.d.ts.map +1 -0
  209. package/lib/Types/index.js +26 -0
  210. package/lib/Types/index.js.map +1 -0
  211. package/lib/Utils/a2ui.d.ts +50 -0
  212. package/lib/Utils/a2ui.js +168 -0
  213. package/lib/Utils/anchor-guard.d.ts +71 -0
  214. package/lib/Utils/anchor-guard.js +404 -0
  215. package/lib/Utils/async-utils.js +7 -0
  216. package/lib/Utils/auth-utils.d.ts +59 -0
  217. package/lib/Utils/auth-utils.d.ts.map +1 -0
  218. package/lib/Utils/auth-utils.js +306 -0
  219. package/lib/Utils/auth-utils.js.map +1 -0
  220. package/lib/Utils/browser-utils.d.ts +10 -0
  221. package/lib/Utils/browser-utils.d.ts.map +1 -0
  222. package/lib/Utils/browser-utils.js +29 -0
  223. package/lib/Utils/browser-utils.js.map +1 -0
  224. package/lib/Utils/business.d.ts +50 -0
  225. package/lib/Utils/business.d.ts.map +1 -0
  226. package/lib/Utils/business.js +245 -0
  227. package/lib/Utils/business.js.map +1 -0
  228. package/lib/Utils/chat-utils.d.ts +409 -0
  229. package/lib/Utils/chat-utils.d.ts.map +1 -0
  230. package/lib/Utils/chat-utils.js +872 -0
  231. package/lib/Utils/chat-utils.js.map +1 -0
  232. package/lib/Utils/companion-reg-client-utils.d.ts +10 -0
  233. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  234. package/lib/Utils/companion-reg-client-utils.js +69 -0
  235. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  236. package/lib/Utils/crypto-worker.js +20 -0
  237. package/lib/Utils/crypto.d.ts +40 -0
  238. package/lib/Utils/crypto.d.ts.map +1 -0
  239. package/lib/Utils/crypto.js +118 -0
  240. package/lib/Utils/crypto.js.map +1 -0
  241. package/lib/Utils/decode-wa-message.d.ts +85 -0
  242. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  243. package/lib/Utils/decode-wa-message.js +467 -0
  244. package/lib/Utils/decode-wa-message.js.map +1 -0
  245. package/lib/Utils/event-buffer.d.ts +13 -0
  246. package/lib/Utils/event-buffer.d.ts.map +1 -0
  247. package/lib/Utils/event-buffer.js +651 -0
  248. package/lib/Utils/event-buffer.js.map +1 -0
  249. package/lib/Utils/generics.d.ts +64 -0
  250. package/lib/Utils/generics.d.ts.map +1 -0
  251. package/lib/Utils/generics.js +442 -0
  252. package/lib/Utils/generics.js.map +1 -0
  253. package/lib/Utils/history.d.ts +77 -0
  254. package/lib/Utils/history.d.ts.map +1 -0
  255. package/lib/Utils/history.js +188 -0
  256. package/lib/Utils/history.js.map +1 -0
  257. package/lib/Utils/identity-change-handler.d.ts +14 -0
  258. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  259. package/lib/Utils/identity-change-handler.js +50 -0
  260. package/lib/Utils/identity-change-handler.js.map +1 -0
  261. package/lib/Utils/ignore-key.d.ts +51 -0
  262. package/lib/Utils/ignore-key.js +174 -0
  263. package/lib/Utils/index.d.ts +29 -0
  264. package/lib/Utils/index.d.ts.map +1 -0
  265. package/lib/Utils/index.js +29 -0
  266. package/lib/Utils/index.js.map +1 -0
  267. package/lib/Utils/link-preview.d.ts +13 -0
  268. package/lib/Utils/link-preview.d.ts.map +1 -0
  269. package/lib/Utils/link-preview.js +85 -0
  270. package/lib/Utils/link-preview.js.map +1 -0
  271. package/lib/Utils/listener-guard.js +48 -0
  272. package/lib/Utils/logger.d.ts +3 -0
  273. package/lib/Utils/logger.d.ts.map +1 -0
  274. package/lib/Utils/logger.js +3 -0
  275. package/lib/Utils/logger.js.map +1 -0
  276. package/lib/Utils/lt-hash.d.ts +7 -0
  277. package/lib/Utils/lt-hash.d.ts.map +1 -0
  278. package/lib/Utils/lt-hash.js +8 -0
  279. package/lib/Utils/lt-hash.js.map +1 -0
  280. package/lib/Utils/make-mutex.d.ts +7 -0
  281. package/lib/Utils/make-mutex.d.ts.map +1 -0
  282. package/lib/Utils/make-mutex.js +33 -0
  283. package/lib/Utils/make-mutex.js.map +1 -0
  284. package/lib/Utils/message-retry-manager.d.ts +80 -0
  285. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  286. package/lib/Utils/message-retry-manager.js +285 -0
  287. package/lib/Utils/message-retry-manager.js.map +1 -0
  288. package/lib/Utils/messages-media.d.ts +166 -0
  289. package/lib/Utils/messages-media.d.ts.map +1 -0
  290. package/lib/Utils/messages-media.js +979 -0
  291. package/lib/Utils/messages-media.js.map +1 -0
  292. package/lib/Utils/messages.d.ts +47 -0
  293. package/lib/Utils/messages.d.ts.map +1 -0
  294. package/lib/Utils/messages.js +1959 -0
  295. package/lib/Utils/messages.js.map +1 -0
  296. package/lib/Utils/meta-ai-msmsg.d.ts +12 -0
  297. package/lib/Utils/meta-ai-msmsg.js +124 -0
  298. package/lib/Utils/noise-handler.d.ts +21 -0
  299. package/lib/Utils/noise-handler.d.ts.map +1 -0
  300. package/lib/Utils/noise-handler.js +206 -0
  301. package/lib/Utils/noise-handler.js.map +1 -0
  302. package/lib/Utils/offline-node-processor.d.ts +10 -0
  303. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  304. package/lib/Utils/offline-node-processor.js +40 -0
  305. package/lib/Utils/offline-node-processor.js.map +1 -0
  306. package/lib/Utils/pre-key-manager.d.ts +26 -0
  307. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  308. package/lib/Utils/pre-key-manager.js +106 -0
  309. package/lib/Utils/pre-key-manager.js.map +1 -0
  310. package/lib/Utils/process-message.d.ts +102 -0
  311. package/lib/Utils/process-message.d.ts.map +1 -0
  312. package/lib/Utils/process-message.js +798 -0
  313. package/lib/Utils/process-message.js.map +1 -0
  314. package/lib/Utils/reporting-utils.d.ts +13 -0
  315. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  316. package/lib/Utils/reporting-utils.js +258 -0
  317. package/lib/Utils/reporting-utils.js.map +1 -0
  318. package/lib/Utils/rich-message-utils.d.ts +49 -0
  319. package/lib/Utils/rich-message-utils.d.ts.map +1 -0
  320. package/lib/Utils/rich-message-utils.js +369 -0
  321. package/lib/Utils/rich-message-utils.js.map +1 -0
  322. package/lib/Utils/session-queue.js +33 -0
  323. package/lib/Utils/signal.d.ts +83 -0
  324. package/lib/Utils/signal.d.ts.map +1 -0
  325. package/lib/Utils/signal.js +201 -0
  326. package/lib/Utils/signal.js.map +1 -0
  327. package/lib/Utils/stanza-ack.d.ts +22 -0
  328. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  329. package/lib/Utils/stanza-ack.js +72 -0
  330. package/lib/Utils/stanza-ack.js.map +1 -0
  331. package/lib/Utils/sync-action-utils.d.ts +3 -0
  332. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  333. package/lib/Utils/sync-action-utils.js +49 -0
  334. package/lib/Utils/sync-action-utils.js.map +1 -0
  335. package/lib/Utils/tc-token-utils.d.ts +30 -0
  336. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  337. package/lib/Utils/tc-token-utils.js +164 -0
  338. package/lib/Utils/tc-token-utils.js.map +1 -0
  339. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  340. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  341. package/lib/Utils/use-multi-file-auth-state.js +196 -0
  342. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  343. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  344. package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
  345. package/lib/Utils/use-single-file-auth-state.js +118 -0
  346. package/lib/Utils/use-single-file-auth-state.js.map +1 -0
  347. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  348. package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
  349. package/lib/Utils/use-sqlite-auth-state.js +109 -0
  350. package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
  351. package/lib/Utils/validate-connection.d.ts +44 -0
  352. package/lib/Utils/validate-connection.d.ts.map +1 -0
  353. package/lib/Utils/validate-connection.js +210 -0
  354. package/lib/Utils/validate-connection.js.map +1 -0
  355. package/lib/Utils/worker-pool.js +73 -0
  356. package/lib/WABinary/constants.d.ts +62 -0
  357. package/lib/WABinary/constants.d.ts.map +1 -0
  358. package/lib/WABinary/constants.js +1467 -0
  359. package/lib/WABinary/constants.js.map +1 -0
  360. package/lib/WABinary/decode.d.ts +10 -0
  361. package/lib/WABinary/decode.d.ts.map +1 -0
  362. package/lib/WABinary/decode.js +262 -0
  363. package/lib/WABinary/decode.js.map +1 -0
  364. package/lib/WABinary/encode.d.ts +3 -0
  365. package/lib/WABinary/encode.d.ts.map +1 -0
  366. package/lib/WABinary/encode.js +220 -0
  367. package/lib/WABinary/encode.js.map +1 -0
  368. package/lib/WABinary/generic-utils.d.ts +77 -0
  369. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  370. package/lib/WABinary/generic-utils.js +226 -0
  371. package/lib/WABinary/generic-utils.js.map +1 -0
  372. package/lib/WABinary/index.d.ts +6 -0
  373. package/lib/WABinary/index.d.ts.map +1 -0
  374. package/lib/WABinary/index.js +6 -0
  375. package/lib/WABinary/index.js.map +1 -0
  376. package/lib/WABinary/jid-utils.d.ts +29 -0
  377. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  378. package/lib/WABinary/jid-utils.js +96 -0
  379. package/lib/WABinary/jid-utils.js.map +1 -0
  380. package/lib/WABinary/types.d.ts +6 -0
  381. package/lib/WABinary/types.d.ts.map +1 -0
  382. package/lib/WABinary/types.js +2 -0
  383. package/lib/WABinary/types.js.map +1 -0
  384. package/lib/WAM/BinaryInfo.d.ts +8 -0
  385. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  386. package/lib/WAM/BinaryInfo.js +10 -0
  387. package/lib/WAM/BinaryInfo.js.map +1 -0
  388. package/lib/WAM/constants.d.ts +34927 -0
  389. package/lib/WAM/constants.d.ts.map +1 -0
  390. package/lib/WAM/constants.js +22853 -0
  391. package/lib/WAM/constants.js.map +1 -0
  392. package/lib/WAM/encode.d.ts +2 -0
  393. package/lib/WAM/encode.d.ts.map +1 -0
  394. package/lib/WAM/encode.js +150 -0
  395. package/lib/WAM/encode.js.map +1 -0
  396. package/lib/WAM/index.d.ts +4 -0
  397. package/lib/WAM/index.d.ts.map +1 -0
  398. package/lib/WAM/index.js +4 -0
  399. package/lib/WAM/index.js.map +1 -0
  400. package/lib/WAUSync/Protocols/USyncBusinessProtocol.d.ts +8 -0
  401. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +99 -0
  402. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
  403. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  404. package/lib/WAUSync/Protocols/USyncContactProtocol.js +53 -0
  405. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  406. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  407. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  408. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  409. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  410. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  411. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  412. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  413. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  414. package/lib/WAUSync/Protocols/USyncFeatureProtocol.d.ts +9 -0
  415. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +70 -0
  416. package/lib/WAUSync/Protocols/USyncPictureProtocol.d.ts +12 -0
  417. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  418. package/lib/WAUSync/Protocols/USyncSidelistProtocol.d.ts +10 -0
  419. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +25 -0
  420. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  421. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  422. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  423. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  424. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.d.ts +11 -0
  425. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +34 -0
  426. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  427. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  428. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +31 -0
  429. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  430. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  431. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  432. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  433. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  434. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
  435. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  436. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  437. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  438. package/lib/WAUSync/Protocols/index.d.ts +11 -0
  439. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  440. package/lib/WAUSync/Protocols/index.js +11 -0
  441. package/lib/WAUSync/Protocols/index.js.map +1 -0
  442. package/lib/WAUSync/USyncQuery.d.ts +32 -0
  443. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  444. package/lib/WAUSync/USyncQuery.js +185 -0
  445. package/lib/WAUSync/USyncQuery.js.map +1 -0
  446. package/lib/WAUSync/USyncUser.d.ts +25 -0
  447. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  448. package/lib/WAUSync/USyncUser.js +48 -0
  449. package/lib/WAUSync/USyncUser.js.map +1 -0
  450. package/lib/WAUSync/index.d.ts +4 -0
  451. package/lib/WAUSync/index.d.ts.map +1 -0
  452. package/lib/WAUSync/index.js +4 -0
  453. package/lib/WAUSync/index.js.map +1 -0
  454. package/lib/index.d.ts +12 -0
  455. package/lib/index.d.ts.map +1 -0
  456. package/lib/index.js +12 -0
  457. package/lib/index.js.map +1 -0
  458. package/package.json +122 -5
@@ -0,0 +1,979 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { spawn } from 'child_process';
3
+ import * as Crypto from 'crypto';
4
+ import { once } from 'events';
5
+ import { createReadStream, createWriteStream, promises as fs, WriteStream } from 'fs';
6
+ import { tmpdir } from 'os';
7
+ import { join } from 'path';
8
+ import { Readable, Transform } from 'stream';
9
+ import { pipeline } from 'stream/promises';
10
+ import { URL } from 'url';
11
+ import { proto } from '../../WAProto/index.js';
12
+ import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP, NEWSLETTER_MEDIA_PATH_MAP } from '../Defaults/index.js';
13
+ import { getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary/index.js';
14
+ import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto.js';
15
+ import { generateMessageIDV2 } from './generics.js';
16
+ const getTmpFilesDirectory = () => tmpdir();
17
+ let imageProcessingLibrary;
18
+ export const getImageProcessingLibrary = async () => {
19
+ if (imageProcessingLibrary) {
20
+ return imageProcessingLibrary;
21
+ }
22
+ //@ts-ignore
23
+ const [sharp, image, jimp] = await Promise.all([
24
+ import('sharp').catch(() => { }),
25
+ import('@napi-rs/image').catch(() => { }),
26
+ import('jimp').catch(() => { })
27
+ ]);
28
+ if (sharp) {
29
+ imageProcessingLibrary = { sharp };
30
+ }
31
+ else if (image) {
32
+ imageProcessingLibrary = { image };
33
+ }
34
+ else if (jimp) {
35
+ imageProcessingLibrary = { jimp };
36
+ }
37
+ else {
38
+ throw new Boom('No image processing library available');
39
+ }
40
+ return imageProcessingLibrary;
41
+ };
42
+ export const hkdfInfoKey = (type) => {
43
+ const hkdfInfo = MEDIA_HKDF_KEY_MAPPING[type];
44
+ return `WhatsApp ${hkdfInfo} Keys`;
45
+ };
46
+ export const getRawMediaUploadData = async (media, mediaType, logger) => {
47
+ const { stream } = await getStream(media);
48
+ logger?.debug('got stream for raw upload');
49
+ const hasher = Crypto.createHash('sha256');
50
+ const filePath = join(tmpdir(), mediaType + generateMessageIDV2());
51
+ const fileWriteStream = createWriteStream(filePath);
52
+ let fileLength = 0;
53
+ try {
54
+ for await (const data of stream) {
55
+ fileLength += data.length;
56
+ hasher.update(data);
57
+ if (!fileWriteStream.write(data)) {
58
+ await once(fileWriteStream, 'drain');
59
+ }
60
+ }
61
+ fileWriteStream.end();
62
+ await once(fileWriteStream, 'finish');
63
+ stream.destroy();
64
+ const fileSha256 = hasher.digest();
65
+ logger?.debug('hashed data for raw upload');
66
+ return {
67
+ filePath: filePath,
68
+ fileSha256,
69
+ fileLength
70
+ };
71
+ }
72
+ catch (error) {
73
+ fileWriteStream.destroy();
74
+ stream.destroy();
75
+ try {
76
+ await fs.unlink(filePath);
77
+ }
78
+ catch {
79
+ //
80
+ }
81
+ throw error;
82
+ }
83
+ };
84
+ /** generates all the keys required to encrypt/decrypt & sign a media message */
85
+ export async function getMediaKeys(buffer, mediaType) {
86
+ if (!buffer) {
87
+ throw new Boom('Cannot derive from empty media key');
88
+ }
89
+ if (typeof buffer === 'string') {
90
+ buffer = Buffer.from(buffer.replace('data:;base64,', ''), 'base64');
91
+ }
92
+ // expand using HKDF to 112 bytes, also pass in the relevant app info
93
+ const expandedMediaKey = hkdf(buffer, 112, { info: hkdfInfoKey(mediaType) });
94
+ return {
95
+ iv: expandedMediaKey.slice(0, 16),
96
+ cipherKey: expandedMediaKey.slice(16, 48),
97
+ macKey: expandedMediaKey.slice(48, 80)
98
+ };
99
+ }
100
+ /** Extracts video thumb using FFMPEG */
101
+ export const extractVideoThumb = async (path, time, size) => {
102
+ const ffmpeg = spawn('ffmpeg', [
103
+ '-loglevel', 'error',
104
+ '-ss', String(time),
105
+ '-i', path,
106
+ '-an', '-sn', '-dn',
107
+ '-map_metadata', '-1',
108
+ '-vf', `scale=${size.width}:-1`,
109
+ '-frames:v', '1',
110
+ '-c:v', 'mjpeg',
111
+ '-f', 'image2pipe',
112
+ 'pipe:1'
113
+ ], {
114
+ stdio: ['ignore', 'pipe', 'pipe']
115
+ });
116
+ let buffer = Buffer.alloc(0);
117
+ const stderrChunks = [];
118
+ ffmpeg.stdout.on('data', (chunk) => {
119
+ buffer = Buffer.concat([buffer, chunk]);
120
+ });
121
+ ffmpeg.stderr.on('data', (chunk) => stderrChunks.push(chunk));
122
+ const [code] = await once(ffmpeg, 'close');
123
+ if (code !== 0) {
124
+ throw new Boom(`FFmpeg failed (code ${code}):\n` +
125
+ Buffer.concat(stderrChunks).toString('utf8'));
126
+ }
127
+ return buffer;
128
+ };
129
+ export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
130
+ // TODO: Move entirely to sharp, removing jimp as it supports readable streams
131
+ // This will have positive speed and performance impacts as well as minimizing RAM usage.
132
+ if (bufferOrFilePath instanceof Readable) {
133
+ bufferOrFilePath = await toBuffer(bufferOrFilePath);
134
+ }
135
+ const lib = await getImageProcessingLibrary();
136
+ if ('sharp' in lib && lib.sharp?.default) {
137
+ const img = lib.sharp.default(bufferOrFilePath);
138
+ const dimensions = await img.metadata();
139
+ const buffer = await img.resize(width).jpeg({ quality: 50 }).toBuffer();
140
+ return {
141
+ buffer,
142
+ original: {
143
+ width: dimensions.width,
144
+ height: dimensions.height
145
+ }
146
+ };
147
+ }
148
+ else if ('image' in lib && lib.image?.Transformer) {
149
+ if (!Buffer.isBuffer(bufferOrFilePath)) {
150
+ bufferOrFilePath = await fs.readFile(bufferOrFilePath);
151
+ }
152
+ const img = new lib.image.Transformer(bufferOrFilePath);
153
+ const dimensions = await img.metadata();
154
+ const buffer = await img.resize(width, undefined, 0).jpeg(50);
155
+ return {
156
+ buffer,
157
+ original: {
158
+ width: dimensions.width,
159
+ height: dimensions.height
160
+ }
161
+ };
162
+ }
163
+ else if ('jimp' in lib && lib.jimp?.Jimp) {
164
+ const jimp = await lib.jimp.Jimp.read(bufferOrFilePath);
165
+ const dimensions = {
166
+ width: jimp.width,
167
+ height: jimp.height
168
+ };
169
+ const buffer = await jimp
170
+ .resize({ w: width, mode: lib.jimp.ResizeStrategy.BILINEAR })
171
+ .getBuffer('image/jpeg', { quality: 50 });
172
+ return {
173
+ buffer,
174
+ original: dimensions
175
+ };
176
+ }
177
+ else {
178
+ throw new Boom('No image processing library available');
179
+ }
180
+ };
181
+ export const encodeBase64EncodedStringForUpload = (b64) => encodeURIComponent(b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, ''));
182
+ export const generateProfilePicture = async (mediaUpload, dimensions) => {
183
+ let buffer;
184
+ const { width: w = 720, height: h = 720 } = dimensions || {};
185
+ if (Buffer.isBuffer(mediaUpload)) {
186
+ buffer = mediaUpload;
187
+ }
188
+ else {
189
+ // Use getStream to handle all WAMediaUpload types (Buffer, Stream, URL)
190
+ const { stream } = await getStream(mediaUpload);
191
+ // Convert the resulting stream to a buffer
192
+ buffer = await toBuffer(stream);
193
+ }
194
+ const lib = await getImageProcessingLibrary();
195
+ let img;
196
+ if ('sharp' in lib && lib.sharp?.default) {
197
+ img = lib.sharp
198
+ .default(buffer)
199
+ .resize(w, h)
200
+ .jpeg({
201
+ quality: 80
202
+ })
203
+ .toBuffer();
204
+ }
205
+ else if ('image' in lib && lib.image?.Transformer) {
206
+ img = new lib.image
207
+ .Transformer(buffer)
208
+ .resize(w, h, 0)
209
+ .jpeg(80);
210
+ }
211
+ else if ('jimp' in lib && lib.jimp?.Jimp) {
212
+ const jimp = await lib.jimp.Jimp.read(buffer);
213
+ const min = Math.min(jimp.width, jimp.height);
214
+ const cropped = jimp.crop({ x: 0, y: 0, w: min, h: min });
215
+ img = cropped.resize({ w, h, mode: lib.jimp.ResizeStrategy.BILINEAR }).getBuffer('image/jpeg', { quality: 80 });
216
+ }
217
+ else {
218
+ throw new Boom('No image processing library available');
219
+ }
220
+ return {
221
+ img: await img
222
+ };
223
+ };
224
+ /** gets the SHA256 of the given media message */
225
+ export const mediaMessageSHA256B64 = (message) => {
226
+ const media = Object.values(message)[0];
227
+ return media?.fileSha256 && Buffer.from(media.fileSha256).toString('base64');
228
+ };
229
+ export async function getAudioDuration(buffer) {
230
+ const musicMetadata = await import('music-metadata');
231
+ let metadata;
232
+ const options = {
233
+ duration: true
234
+ };
235
+ if (Buffer.isBuffer(buffer)) {
236
+ metadata = await musicMetadata.parseBuffer(buffer, undefined, options);
237
+ }
238
+ else if (typeof buffer === 'string') {
239
+ metadata = await musicMetadata.parseFile(buffer, options);
240
+ }
241
+ else {
242
+ metadata = await musicMetadata.parseStream(buffer, undefined, options);
243
+ }
244
+ return metadata.format.duration;
245
+ }
246
+ /**
247
+ referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
248
+ */
249
+ export async function getAudioWaveform(buffer, logger) {
250
+ try {
251
+ // @ts-ignore
252
+ const { default: decoder } = await import('audio-decode');
253
+ let audioData;
254
+ if (Buffer.isBuffer(buffer)) {
255
+ audioData = buffer;
256
+ }
257
+ else if (typeof buffer === 'string') {
258
+ const rStream = createReadStream(buffer);
259
+ audioData = await toBuffer(rStream);
260
+ }
261
+ else {
262
+ audioData = await toBuffer(buffer);
263
+ }
264
+ const audioBuffer = await decoder(audioData);
265
+ const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
266
+ const samples = 64; // Number of samples we want to have in our final data set
267
+ const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
268
+ const filteredData = [];
269
+ for (let i = 0; i < samples; i++) {
270
+ const blockStart = blockSize * i; // the location of the first sample in the block
271
+ let sum = 0;
272
+ for (let j = 0; j < blockSize; j++) {
273
+ sum = sum + Math.abs(rawData[blockStart + j]); // find the sum of all the samples in the block
274
+ }
275
+ filteredData.push(sum / blockSize); // divide the sum by the block size to get the average
276
+ }
277
+ // This guarantees that the largest data point will be set to 1, and the rest of the data will scale proportionally.
278
+ const multiplier = Math.pow(Math.max(...filteredData), -1);
279
+ const normalizedData = filteredData.map(n => n * multiplier);
280
+ // Generate waveform like WhatsApp
281
+ const waveform = new Uint8Array(normalizedData.map(n => Math.floor(100 * n)));
282
+ return waveform;
283
+ }
284
+ catch (e) {
285
+ logger?.debug('Failed to generate waveform: ' + e);
286
+ }
287
+ }
288
+ export const toReadable = (buffer) => {
289
+ const readable = new Readable({ read: () => { } });
290
+ readable.push(buffer);
291
+ readable.push(null);
292
+ return readable;
293
+ };
294
+ export const toBuffer = async (stream) => {
295
+ const chunks = [];
296
+ for await (const chunk of stream) {
297
+ chunks.push(chunk);
298
+ }
299
+ stream.destroy();
300
+ return Buffer.concat(chunks);
301
+ };
302
+ export const getStream = async (item, opts) => {
303
+ if (Buffer.isBuffer(item)) {
304
+ return { stream: toReadable(item), type: 'buffer' };
305
+ }
306
+ // A bare path or URL string is accepted, and the reason is the error it used to produce. The
307
+ // contract below is `Buffer | { stream } | { url }`, so `'stream' in item` throws on a string —
308
+ // and it throws with the path interpolated:
309
+ //
310
+ // TypeError: Cannot use 'in' operator to search for 'stream' in /tmp/8cktb7o7x.webp
311
+ //
312
+ // Measured on a production fleet, 2026-10-10: five of those under [SEND_STICKER]. The message
313
+ // names a file, so it reads as a missing or unreadable one, while the real fault is the SHAPE of
314
+ // the argument — and the file was perfectly readable: `createReadStream(item.url)` at the end of
315
+ // this function handles exactly that string. Widening here costs nothing and removes the whole
316
+ // class, for every caller rather than the one that was caught.
317
+ if (typeof item === 'string') {
318
+ item = { url: item };
319
+ }
320
+ if (!item || typeof item !== 'object') {
321
+ throw new Boom(`media source must be a Buffer, a string, { stream } or { url }, got ${item === null ? 'null' : typeof item}`);
322
+ }
323
+ if ('stream' in item) {
324
+ return { stream: item.stream, type: 'readable' };
325
+ }
326
+ // Named rather than left to throw "Cannot read properties of undefined (reading 'toString')",
327
+ // which says nothing about which field is missing.
328
+ if (item.url === undefined || item.url === null) {
329
+ throw new Boom('media source object has neither `stream` nor `url`');
330
+ }
331
+ const urlStr = item.url.toString();
332
+ if (urlStr.startsWith('data:')) {
333
+ const buffer = Buffer.from(urlStr.split(',')[1], 'base64');
334
+ return { stream: toReadable(buffer), type: 'buffer' };
335
+ }
336
+ if (urlStr.startsWith('http://') || urlStr.startsWith('https://')) {
337
+ return { stream: await getHttpStream(item.url, opts), type: 'remote' };
338
+ }
339
+ return { stream: createReadStream(item.url), type: 'file' };
340
+ };
341
+ /** generates a thumbnail for a given media, if required */
342
+ export async function generateThumbnail(file, mediaType, options) {
343
+ let thumbnail;
344
+ let originalImageDimensions;
345
+ if (mediaType === 'image') {
346
+ const { buffer, original } = await extractImageThumb(file);
347
+ thumbnail = buffer.toString('base64');
348
+ if (original.width && original.height) {
349
+ originalImageDimensions = {
350
+ width: original.width,
351
+ height: original.height
352
+ };
353
+ }
354
+ }
355
+ else if (mediaType === 'video') {
356
+ try {
357
+ const buff = await extractVideoThumb(file, '00:00:00', { width: 32, height: 32 });
358
+ thumbnail = buff.toString('base64');
359
+ }
360
+ catch (err) {
361
+ options.logger?.debug('could not generate video thumb: ' + err);
362
+ }
363
+ }
364
+ return {
365
+ thumbnail,
366
+ originalImageDimensions
367
+ };
368
+ }
369
+ export const getHttpStream = async (url, options = {}) => {
370
+ const response = await fetch(url.toString(), {
371
+ dispatcher: options.dispatcher,
372
+ method: 'GET',
373
+ headers: options.headers,
374
+ signal: options.signal
375
+ });
376
+ if (!response.ok) {
377
+ if (response.body instanceof Readable) {
378
+ response.body.destroy();
379
+ }
380
+ else {
381
+ await response.body?.cancel().catch(() => { });
382
+ }
383
+ throw new Boom(`Failed to fetch stream from ${url}`, { statusCode: response.status, data: { url } });
384
+ }
385
+ // @ts-ignore Node18+ Readable.fromWeb exists
386
+ return response.body instanceof Readable ? response.body : Readable.fromWeb(response.body);
387
+ };
388
+ const SIDECAR_CHUNK_SIZE = 65536;
389
+ const SIDECAR_HMAC_SIZE = 10;
390
+ const SIDECAR_IV_SIZE = 16;
391
+ const CONTAINER_SCAN_MAX_BYTES = 1024;
392
+ const SIDECAR_MEDIA_TYPES = new Set(['video', 'audio', 'ptt', 'gif']);
393
+ const readU32 = (bytes, offset) => ((bytes[offset] << 24) | (bytes[offset + 1] << 16) | (bytes[offset + 2] << 8) | bytes[offset + 3]) >>> 0;
394
+ /**
395
+ * Walks the top-level ISO-BMFF boxes (mp4/mov/3gp/m4a) in the leading bytes. A file is
396
+ * streamable only when `moov` precedes `mdat`; advertising a non-faststart mp4 as seekable
397
+ * (by attaching a sidecar) makes the recipient's player fail instead of falling back to a
398
+ * plain download. Non-ISO-BMFF payloads (ogg/opus voice notes) are streamable.
399
+ * Returns true / false, or null while `head` is too short to decide.
400
+ */
401
+ export const scanStreamable = (head) => {
402
+ if (head.length < 8) {
403
+ return null;
404
+ }
405
+ if (readU32(head, 4) !== 0x66747970 /* ftyp */) {
406
+ return true;
407
+ }
408
+ let offset = 0;
409
+ while (offset + 8 <= head.length) {
410
+ const type = readU32(head, offset + 4);
411
+ if (type === 0x6d6f6f76 /* moov */) {
412
+ return true;
413
+ }
414
+ if (type === 0x6d646174 /* mdat */) {
415
+ return false;
416
+ }
417
+ let size = readU32(head, offset);
418
+ let headerSize = 8;
419
+ if (size === 1) {
420
+ if (offset + 16 > head.length) {
421
+ return null;
422
+ }
423
+ if (readU32(head, offset + 8) !== 0) {
424
+ return true;
425
+ }
426
+ size = readU32(head, offset + 12);
427
+ headerSize = 16;
428
+ }
429
+ else if (size === 0) {
430
+ return true;
431
+ }
432
+ if (size < headerSize) {
433
+ return true;
434
+ }
435
+ offset += size;
436
+ if (offset > CONTAINER_SCAN_MAX_BYTES) {
437
+ return true;
438
+ }
439
+ }
440
+ return offset > CONTAINER_SCAN_MAX_BYTES ? true : null;
441
+ };
442
+ /**
443
+ * Streaming sidecar as WhatsApp Web builds it: HMAC-SHA256(macKey) truncated to 10 bytes over
444
+ * each 64 KiB window of iv+ciphertext+mac, with the last 16 bytes of the previous window
445
+ * prepended, so the recipient can verify and play a range without the whole file.
446
+ */
447
+ class SidecarAccumulator {
448
+ constructor(macKey) {
449
+ this.macKey = macKey;
450
+ this.window = Buffer.alloc(SIDECAR_IV_SIZE + SIDECAR_CHUNK_SIZE);
451
+ this.windowOffset = 0;
452
+ this.totalPushed = 0;
453
+ this.nextChunkStart = 0;
454
+ this.digests = [];
455
+ }
456
+ push(data) {
457
+ let srcOffset = 0;
458
+ while (srcOffset < data.length) {
459
+ const windowEnd = this.nextChunkStart + SIDECAR_IV_SIZE + SIDECAR_CHUNK_SIZE;
460
+ const toCopy = Math.min(windowEnd - this.totalPushed, data.length - srcOffset);
461
+ this.window.set(data.subarray(srcOffset, srcOffset + toCopy), this.windowOffset);
462
+ this.windowOffset += toCopy;
463
+ this.totalPushed += toCopy;
464
+ srcOffset += toCopy;
465
+ if (this.totalPushed === windowEnd) {
466
+ this.flushChunk();
467
+ }
468
+ }
469
+ }
470
+ finish() {
471
+ if (this.windowOffset > 0) {
472
+ this.flushChunk();
473
+ }
474
+ return Buffer.concat(this.digests);
475
+ }
476
+ flushChunk() {
477
+ const digest = Crypto.createHmac('sha256', this.macKey).update(this.window.subarray(0, this.windowOffset)).digest();
478
+ this.digests.push(digest.subarray(0, SIDECAR_HMAC_SIZE));
479
+ this.nextChunkStart += SIDECAR_CHUNK_SIZE;
480
+ this.window.copyWithin(0, this.windowOffset - SIDECAR_IV_SIZE, this.windowOffset);
481
+ this.windowOffset = SIDECAR_IV_SIZE;
482
+ }
483
+ }
484
+ export const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
485
+ const { stream, type } = await getStream(media, opts);
486
+ logger?.debug('fetched media stream');
487
+ const mediaKey = Crypto.randomBytes(32);
488
+ const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType);
489
+ const encFilePath = join(getTmpFilesDirectory(), mediaType + generateMessageIDV2() + '-enc');
490
+ const encFileWriteStream = createWriteStream(encFilePath);
491
+ let originalFileStream;
492
+ let originalFilePath;
493
+ if (saveOriginalFileIfRequired) {
494
+ originalFilePath = join(getTmpFilesDirectory(), mediaType + generateMessageIDV2() + '-original');
495
+ originalFileStream = createWriteStream(originalFilePath);
496
+ }
497
+ let fileLength = 0;
498
+ const aes = Crypto.createCipheriv('aes-256-cbc', cipherKey, iv);
499
+ const hmac = Crypto.createHmac('sha256', macKey).update(iv);
500
+ const sha256Plain = Crypto.createHash('sha256');
501
+ const sha256Enc = Crypto.createHash('sha256');
502
+ const sidecar = SIDECAR_MEDIA_TYPES.has(mediaType) ? new SidecarAccumulator(macKey) : undefined;
503
+ sidecar?.push(iv);
504
+ let streamableVerdict = sidecar ? null : false;
505
+ let head = Buffer.alloc(0);
506
+ const onChunk = async (buff) => {
507
+ sha256Enc.update(buff);
508
+ hmac.update(buff);
509
+ sidecar?.push(buff);
510
+ // Handle backpressure: if write returns false, wait for drain
511
+ if (!encFileWriteStream.write(buff)) {
512
+ await once(encFileWriteStream, 'drain');
513
+ }
514
+ };
515
+ try {
516
+ for await (const data of stream) {
517
+ fileLength += data.length;
518
+ if (type === 'remote' &&
519
+ opts?.maxContentLength &&
520
+ fileLength > opts.maxContentLength) {
521
+ throw new Boom(`content length exceeded when encrypting "${type}"`, {
522
+ data: { media, type }
523
+ });
524
+ }
525
+ if (originalFileStream) {
526
+ if (!originalFileStream.write(data)) {
527
+ await once(originalFileStream, 'drain');
528
+ }
529
+ }
530
+ sha256Plain.update(data);
531
+ if (streamableVerdict === null) {
532
+ head = Buffer.concat([head, data]);
533
+ streamableVerdict = scanStreamable(head);
534
+ if (streamableVerdict === null && head.length > CONTAINER_SCAN_MAX_BYTES) {
535
+ streamableVerdict = true;
536
+ }
537
+ }
538
+ await onChunk(aes.update(data));
539
+ }
540
+ await onChunk(aes.final());
541
+ const mac = hmac.digest().slice(0, 10);
542
+ sha256Enc.update(mac);
543
+ sidecar?.push(mac);
544
+ // a non-faststart mp4 (mdat before moov) must not advertise seekability
545
+ const streamingSidecar = sidecar && streamableVerdict !== false ? sidecar.finish() : undefined;
546
+ const fileSha256 = sha256Plain.digest();
547
+ const fileEncSha256 = sha256Enc.digest();
548
+ encFileWriteStream.write(mac);
549
+ const encFinishPromise = once(encFileWriteStream, 'finish');
550
+ const originalFinishPromise = originalFileStream ? once(originalFileStream, 'finish') : Promise.resolve();
551
+ encFileWriteStream.end();
552
+ originalFileStream?.end?.();
553
+ stream.destroy();
554
+ // Wait for write streams to fully flush to disk
555
+ // This helps reduce memory pressure by allowing OS to release buffers
556
+ await encFinishPromise;
557
+ await originalFinishPromise;
558
+ logger?.debug('encrypted data successfully');
559
+ return {
560
+ mediaKey,
561
+ originalFilePath,
562
+ encFilePath,
563
+ mac,
564
+ fileEncSha256,
565
+ fileSha256,
566
+ fileLength,
567
+ streamingSidecar
568
+ };
569
+ }
570
+ catch (error) {
571
+ // destroy all streams with error
572
+ encFileWriteStream.destroy();
573
+ originalFileStream?.destroy?.();
574
+ aes.destroy();
575
+ hmac.destroy();
576
+ sha256Plain.destroy();
577
+ sha256Enc.destroy();
578
+ stream.destroy();
579
+ try {
580
+ await fs.unlink(encFilePath);
581
+ if (originalFilePath) {
582
+ await fs.unlink(originalFilePath);
583
+ }
584
+ }
585
+ catch (err) {
586
+ logger?.error({ err }, 'failed deleting tmp files');
587
+ }
588
+ throw error;
589
+ }
590
+ };
591
+ export const DEF_MEDIA_HOST = 'mmg.whatsapp.net';
592
+ const AES_CHUNK_SIZE = 16;
593
+ export const getUrlFromDirectPath = (directPath, host = DEF_MEDIA_HOST) => `https://${host}${directPath}`;
594
+ const extractHost = (url) => {
595
+ if (!url)
596
+ return undefined;
597
+ try {
598
+ return new URL(url).host;
599
+ }
600
+ catch {
601
+ return undefined;
602
+ }
603
+ };
604
+ export const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
605
+ // Fallback host: explicit opt > host parsed from `url` > DEF_MEDIA_HOST.
606
+ // Lets us honor a non-default host carried by the proto without forcing callers to thread it through.
607
+ const fallbackHost = opts.host ?? extractHost(url);
608
+ const downloadUrl = directPath ? getUrlFromDirectPath(directPath, fallbackHost) : url;
609
+ if (!downloadUrl) {
610
+ throw new Boom('No valid media URL or directPath present in message', { statusCode: 400 });
611
+ }
612
+ const keys = await getMediaKeys(mediaKey, type);
613
+ return downloadEncryptedContent(downloadUrl, keys, opts);
614
+ };
615
+ /**
616
+ * Authenticates the complete iv+ciphertext against its trailing 10-byte HMAC before
617
+ * returning plaintext. Downloads are spooled to a private temporary file, keeping
618
+ * memory bounded. Ranges use an inclusive startByte and exclusive endByte and are
619
+ * sliced after full authentication; they still download the complete media.
620
+ * Consume or destroy the returned stream to remove its temporary file.
621
+ * */
622
+ export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv, macKey }, { startByte = 0, endByte, options } = {}) => {
623
+ if (!macKey) {
624
+ throw new Boom('Media MAC key is required', { statusCode: 400 });
625
+ }
626
+ if (!Number.isSafeInteger(startByte) || startByte < 0 ||
627
+ (endByte !== undefined && (!Number.isSafeInteger(endByte) || endByte < startByte))) {
628
+ throw new Boom('Invalid media byte range', { statusCode: 400 });
629
+ }
630
+ const headers = new Headers(options?.headers);
631
+ headers.set('Origin', DEFAULT_ORIGIN);
632
+ // A caller-supplied Range would prevent verification of the full-file MAC.
633
+ headers.delete('Range');
634
+ let fetched;
635
+ let tempDirectory;
636
+ let filePath;
637
+ const cleanup = async () => {
638
+ if (filePath) {
639
+ await fs.rm(filePath, { force: true });
640
+ }
641
+ if (tempDirectory) {
642
+ await fs.rmdir(tempDirectory);
643
+ }
644
+ };
645
+ try {
646
+ tempDirectory = await fs.mkdtemp(join(getTmpFilesDirectory(), 'baileys-media-'));
647
+ filePath = join(tempDirectory, 'media');
648
+ fetched = await getHttpStream(downloadUrl, { ...options, headers });
649
+ const hmac = Crypto.createHmac('sha256', macKey).update(iv);
650
+ let trailingMac = Buffer.alloc(0);
651
+ let ciphertextLength = 0;
652
+ const authenticate = new Transform({
653
+ transform(chunk, _, callback) {
654
+ const data = Buffer.concat([trailingMac, chunk]);
655
+ const length = Math.max(data.length - 10, 0);
656
+ trailingMac = data.subarray(length);
657
+ const ciphertext = data.subarray(0, length);
658
+ ciphertextLength += length;
659
+ hmac.update(ciphertext);
660
+ callback(null, ciphertext);
661
+ },
662
+ flush(callback) {
663
+ if (trailingMac.length !== 10 || ciphertextLength === 0 || ciphertextLength % AES_CHUNK_SIZE !== 0) {
664
+ callback(new Boom('Invalid or truncated media payload', { statusCode: 400 }));
665
+ }
666
+ else if (!Crypto.timingSafeEqual(hmac.digest().subarray(0, 10), trailingMac)) {
667
+ callback(new Boom('Media MAC verification failed', { statusCode: 400 }));
668
+ }
669
+ else {
670
+ callback();
671
+ }
672
+ }
673
+ });
674
+ await pipeline(fetched, authenticate, Crypto.createDecipheriv('aes-256-cbc', cipherKey, iv),
675
+ createWriteStream(filePath, { flags: 'wx', mode: 0o600 }), { signal: options?.signal });
676
+ const { size } = await fs.stat(filePath);
677
+ const end = Math.min(endByte ?? size, size);
678
+ if (startByte >= end) {
679
+ await cleanup();
680
+ return Readable.from([]);
681
+ }
682
+ const output = createReadStream(filePath, { start: startByte, end: end - 1, signal: options?.signal });
683
+ output.once('close', () => {
684
+ void cleanup().catch(() => { });
685
+ });
686
+ return output;
687
+ }
688
+ catch (error) {
689
+ fetched?.destroy();
690
+ await cleanup().catch(() => { });
691
+ throw error;
692
+ }
693
+ };
694
+ export function extensionForMediaMessage(message) {
695
+ const getExtension = (mimetype) => mimetype.split(';')[0]?.split('/')[1];
696
+ const type = Object.keys(message)[0];
697
+ let extension;
698
+ if (type === 'locationMessage' || type === 'liveLocationMessage' || type === 'productMessage') {
699
+ extension = '.jpeg';
700
+ }
701
+ else {
702
+ const messageContent = message[type];
703
+ extension = getExtension(messageContent.mimetype);
704
+ }
705
+ return extension;
706
+ }
707
+ const isNodeRuntime = () => {
708
+ return (typeof process !== 'undefined' &&
709
+ process.versions?.node !== null &&
710
+ typeof process.versions.bun === 'undefined' &&
711
+ typeof globalThis.Deno === 'undefined');
712
+ };
713
+ export const uploadWithNodeHttp = async ({ url, filePath, headers, timeoutMs, agent }, redirectCount = 0) => {
714
+ if (redirectCount > 5) {
715
+ throw new Error('Too many redirects');
716
+ }
717
+ const parsedUrl = new URL(url);
718
+ const httpModule = parsedUrl.protocol === 'https:' ? await import('https') : await import('http');
719
+ // Get file size for Content-Length header (required for Node.js streaming)
720
+ const fileStats = await fs.stat(filePath);
721
+ const fileSize = fileStats.size;
722
+ return new Promise((resolve, reject) => {
723
+ const req = httpModule.request({
724
+ hostname: parsedUrl.hostname,
725
+ port: parsedUrl.port || (parsedUrl.protocol === 'https:' ? 443 : 80),
726
+ path: parsedUrl.pathname + parsedUrl.search,
727
+ method: 'POST',
728
+ headers: {
729
+ ...headers,
730
+ 'Content-Length': fileSize
731
+ },
732
+ agent,
733
+ timeout: timeoutMs
734
+ }, res => {
735
+ // Handle redirects (3xx)
736
+ if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
737
+ res.resume(); // Consume response to free resources
738
+ const newUrl = new URL(res.headers.location, url).toString();
739
+ resolve(uploadWithNodeHttp({
740
+ url: newUrl,
741
+ filePath,
742
+ headers,
743
+ timeoutMs,
744
+ agent
745
+ }, redirectCount + 1));
746
+ return;
747
+ }
748
+ let body = '';
749
+ res.on('data', chunk => (body += chunk));
750
+ res.on('end', () => {
751
+ try {
752
+ resolve(JSON.parse(body));
753
+ }
754
+ catch {
755
+ resolve(undefined);
756
+ }
757
+ });
758
+ });
759
+ req.on('error', reject);
760
+ req.on('timeout', () => {
761
+ req.destroy();
762
+ reject(new Error('Upload timeout'));
763
+ });
764
+ const stream = createReadStream(filePath);
765
+ stream.pipe(req);
766
+ stream.on('error', err => {
767
+ req.destroy();
768
+ reject(err);
769
+ });
770
+ });
771
+ };
772
+ const uploadWithFetch = async ({ url, filePath, headers, timeoutMs, agent }) => {
773
+ // Convert Node.js Readable to Web ReadableStream
774
+ const nodeStream = createReadStream(filePath);
775
+ const webStream = Readable.toWeb(nodeStream);
776
+ // Native fetch only accepts Undici-style dispatchers, not generic https Agents.
777
+ const dispatcher = typeof agent?.dispatch === 'function' ? agent : undefined;
778
+ const response = await fetch(url, {
779
+ ...(dispatcher ? { dispatcher } : {}),
780
+ method: 'POST',
781
+ body: webStream,
782
+ headers,
783
+ duplex: 'half',
784
+ signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined
785
+ });
786
+ try {
787
+ return (await response.json());
788
+ }
789
+ catch {
790
+ return undefined;
791
+ }
792
+ };
793
+ /**
794
+ * Uploads media to WhatsApp servers.
795
+ *
796
+ * ## Why we have two upload implementations:
797
+ *
798
+ * Node.js's native `fetch` (powered by undici) has a known bug where it buffers
799
+ * the entire request body in memory before sending, even when using streams.
800
+ * This causes memory issues with large files (e.g., 1GB file = 1GB+ memory usage).
801
+ * See: https://github.com/nodejs/undici/issues/4058
802
+ *
803
+ * Other runtimes (Bun, Deno, browsers) correctly stream the request body without
804
+ * buffering, so we can use the web-standard Fetch API there.
805
+ *
806
+ * ## Future considerations:
807
+ * Once the undici bug is fixed, we can simplify this to use only the Fetch API
808
+ * across all runtimes. Monitor the GitHub issue for updates.
809
+ */
810
+ const uploadMedia = async (params, logger) => {
811
+ if (isNodeRuntime()) {
812
+ logger?.debug('Using Node.js https module for upload (avoids undici buffering bug)');
813
+ return uploadWithNodeHttp(params);
814
+ }
815
+ else {
816
+ logger?.debug('Using web-standard Fetch API for upload');
817
+ return uploadWithFetch(params);
818
+ }
819
+ };
820
+ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
821
+ return async (filePath, { mediaType, fileEncSha256B64, timeoutMs, newsletter }) => {
822
+ // send a query JSON to obtain the url & auth token to upload our media
823
+ const MAX_UPLOAD_RETRIES = 3;
824
+ for (let attempt = 1; attempt <= MAX_UPLOAD_RETRIES; attempt++) {
825
+ let uploadInfo = await refreshMediaConn(false);
826
+ let urls;
827
+ const hosts = [...customUploadHosts, ...uploadInfo.hosts];
828
+ fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64);
829
+ const customHeaders = (() => {
830
+ const hdrs = options?.headers;
831
+ if (!hdrs)
832
+ return {};
833
+ return Array.isArray(hdrs) ? Object.fromEntries(hdrs) : hdrs;
834
+ })();
835
+ const headers = {
836
+ ...customHeaders,
837
+ 'Content-Type': 'application/octet-stream',
838
+ Origin: DEFAULT_ORIGIN
839
+ };
840
+ for (const { hostname } of hosts) {
841
+ logger.debug(`uploading to "${hostname}"`);
842
+ const auth = encodeURIComponent(uploadInfo.auth);
843
+ const mediaPathMap = newsletter ? NEWSLETTER_MEDIA_PATH_MAP : MEDIA_PATH_MAP;
844
+ const serverThumb = newsletter ? '&server_thumb_gen=1' : '';
845
+ const url = `https://${hostname}${mediaPathMap[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}${serverThumb}`;
846
+ let result;
847
+ try {
848
+ result = await uploadMedia({
849
+ url,
850
+ filePath,
851
+ headers,
852
+ timeoutMs,
853
+ agent: fetchAgent
854
+ }, logger);
855
+ if (result?.url || result?.direct_path) {
856
+ urls = {
857
+ mediaUrl: result.url,
858
+ directPath: result.direct_path,
859
+ meta_hmac: result.meta_hmac,
860
+ fbid: result.fbid,
861
+ ts: result.ts,
862
+ thumbnailDirectPath: result.thumbnail_info?.thumbnail_direct_path,
863
+ thumbnailSha256: result.thumbnail_info?.thumbnail_sha256
864
+ };
865
+ break;
866
+ }
867
+ else {
868
+ uploadInfo = await refreshMediaConn(true);
869
+ throw new Error(`upload failed, reason: ${JSON.stringify(result)}`);
870
+ }
871
+ }
872
+ catch (error) {
873
+ // hosts is customUploadHosts + uploadInfo.hosts, so indexing it by the length
874
+ // of uploadInfo.hosts alone named the wrong host as last.
875
+ const isLast = hostname === hosts[hosts.length - 1]?.hostname;
876
+ logger.warn({ trace: error?.stack, uploadResult: result }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`);
877
+ }
878
+ }
879
+ if (!urls) {
880
+ if (attempt < MAX_UPLOAD_RETRIES) {
881
+ logger.warn(`Media upload failed on all hosts, retrying (${attempt}/${MAX_UPLOAD_RETRIES})...`);
882
+ await new Promise(r => setTimeout(r, 2000));
883
+ continue;
884
+ }
885
+ logger.error(`Media upload failed on all hosts after ${MAX_UPLOAD_RETRIES} attempts`);
886
+ return null;
887
+ }
888
+ return urls;
889
+ }
890
+ };
891
+ };
892
+ const getMediaRetryKey = (mediaKey) => {
893
+ return hkdf(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' });
894
+ };
895
+ /**
896
+ * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
897
+ */
898
+ export const encryptMediaRetryRequest = (key, mediaKey, meId) => {
899
+ const recp = { stanzaId: key.id };
900
+ const recpBuffer = proto.ServerErrorReceipt.encode(recp).finish();
901
+ const iv = Crypto.randomBytes(12);
902
+ const retryKey = getMediaRetryKey(mediaKey);
903
+ const ciphertext = aesEncryptGCM(recpBuffer, retryKey, iv, Buffer.from(key.id));
904
+ const req = {
905
+ tag: 'receipt',
906
+ attrs: {
907
+ id: key.id,
908
+ to: jidNormalizedUser(meId),
909
+ type: 'server-error'
910
+ },
911
+ content: [
912
+ // this encrypt node is actually pretty useless
913
+ // the media is returned even without this node
914
+ // keeping it here to maintain parity with WA Web
915
+ {
916
+ tag: 'encrypt',
917
+ attrs: {},
918
+ content: [
919
+ { tag: 'enc_p', attrs: {}, content: ciphertext },
920
+ { tag: 'enc_iv', attrs: {}, content: iv }
921
+ ]
922
+ },
923
+ {
924
+ tag: 'rmr',
925
+ attrs: {
926
+ jid: key.remoteJid,
927
+ from_me: (!!key.fromMe).toString(),
928
+ // @ts-ignore
929
+ participant: key.participant || undefined
930
+ }
931
+ }
932
+ ]
933
+ };
934
+ return req;
935
+ };
936
+ export const decodeMediaRetryNode = (node) => {
937
+ const rmrNode = getBinaryNodeChild(node, 'rmr');
938
+ const event = {
939
+ key: {
940
+ id: node.attrs.id,
941
+ remoteJid: rmrNode.attrs.jid,
942
+ fromMe: rmrNode.attrs.from_me === 'true',
943
+ participant: rmrNode.attrs.participant
944
+ }
945
+ };
946
+ const errorNode = getBinaryNodeChild(node, 'error');
947
+ if (errorNode) {
948
+ const errorCode = +errorNode.attrs.code;
949
+ event.error = new Boom(`Failed to re-upload media (${errorCode})`, {
950
+ data: errorNode.attrs,
951
+ statusCode: getStatusCodeForMediaRetry(errorCode)
952
+ });
953
+ }
954
+ else {
955
+ const encryptedInfoNode = getBinaryNodeChild(node, 'encrypt');
956
+ const ciphertext = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_p');
957
+ const iv = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_iv');
958
+ if (ciphertext && iv) {
959
+ event.media = { ciphertext, iv };
960
+ }
961
+ else {
962
+ event.error = new Boom('Failed to re-upload media (missing ciphertext)', { statusCode: 404 });
963
+ }
964
+ }
965
+ return event;
966
+ };
967
+ export const decryptMediaRetryData = ({ ciphertext, iv }, mediaKey, msgId) => {
968
+ const retryKey = getMediaRetryKey(mediaKey);
969
+ const plaintext = aesDecryptGCM(ciphertext, retryKey, iv, Buffer.from(msgId));
970
+ return proto.MediaRetryNotification.decode(plaintext);
971
+ };
972
+ export const getStatusCodeForMediaRetry = (code) => MEDIA_RETRY_STATUS_MAP[code];
973
+ const MEDIA_RETRY_STATUS_MAP = {
974
+ [proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
975
+ [proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
976
+ [proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
977
+ [proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418
978
+ };
979
+ //# sourceMappingURL=messages-media.js.map