@neelegirl/baileys 1.5.4 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (374) hide show
  1. package/README.md +10 -189
  2. package/index.js +38 -0
  3. package/package.json +11 -94
  4. package/LICENSE +0 -21
  5. package/WAProto/GenerateStatics.sh +0 -3
  6. package/WAProto/WAProto.proto +0 -4633
  7. package/WAProto/fix-imports.js +0 -29
  8. package/WAProto/index.d.ts +0 -11969
  9. package/WAProto/index.js +0 -84368
  10. package/engine-requirements.js +0 -10
  11. package/lib/Defaults/index.d.ts +0 -62
  12. package/lib/Defaults/index.d.ts.map +0 -1
  13. package/lib/Defaults/index.js +0 -115
  14. package/lib/Defaults/index.js.map +0 -1
  15. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  16. package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
  17. package/lib/Signal/Group/ciphertext-message.js +0 -12
  18. package/lib/Signal/Group/ciphertext-message.js.map +0 -1
  19. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  20. package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
  21. package/lib/Signal/Group/group-session-builder.js +0 -30
  22. package/lib/Signal/Group/group-session-builder.js.map +0 -1
  23. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  24. package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
  25. package/lib/Signal/Group/group_cipher.js +0 -82
  26. package/lib/Signal/Group/group_cipher.js.map +0 -1
  27. package/lib/Signal/Group/index.d.ts +0 -12
  28. package/lib/Signal/Group/index.d.ts.map +0 -1
  29. package/lib/Signal/Group/index.js +0 -12
  30. package/lib/Signal/Group/index.js.map +0 -1
  31. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  32. package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
  33. package/lib/Signal/Group/keyhelper.js +0 -18
  34. package/lib/Signal/Group/keyhelper.js.map +0 -1
  35. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  36. package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
  37. package/lib/Signal/Group/sender-chain-key.js +0 -26
  38. package/lib/Signal/Group/sender-chain-key.js.map +0 -1
  39. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  40. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
  41. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  42. package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
  43. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  44. package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
  45. package/lib/Signal/Group/sender-key-message.js +0 -66
  46. package/lib/Signal/Group/sender-key-message.js.map +0 -1
  47. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  48. package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
  49. package/lib/Signal/Group/sender-key-name.js +0 -48
  50. package/lib/Signal/Group/sender-key-name.js.map +0 -1
  51. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  52. package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
  53. package/lib/Signal/Group/sender-key-record.js +0 -41
  54. package/lib/Signal/Group/sender-key-record.js.map +0 -1
  55. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  56. package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
  57. package/lib/Signal/Group/sender-key-state.js +0 -84
  58. package/lib/Signal/Group/sender-key-state.js.map +0 -1
  59. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  60. package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
  61. package/lib/Signal/Group/sender-message-key.js +0 -26
  62. package/lib/Signal/Group/sender-message-key.js.map +0 -1
  63. package/lib/Signal/libsignal.d.ts +0 -5
  64. package/lib/Signal/libsignal.d.ts.map +0 -1
  65. package/lib/Signal/libsignal.js +0 -342
  66. package/lib/Signal/libsignal.js.map +0 -1
  67. package/lib/Signal/lid-mapping.d.ts +0 -23
  68. package/lib/Signal/lid-mapping.d.ts.map +0 -1
  69. package/lib/Signal/lid-mapping.js +0 -171
  70. package/lib/Signal/lid-mapping.js.map +0 -1
  71. package/lib/Socket/Client/index.d.ts +0 -3
  72. package/lib/Socket/Client/index.d.ts.map +0 -1
  73. package/lib/Socket/Client/index.js +0 -3
  74. package/lib/Socket/Client/index.js.map +0 -1
  75. package/lib/Socket/Client/types.d.ts +0 -16
  76. package/lib/Socket/Client/types.d.ts.map +0 -1
  77. package/lib/Socket/Client/types.js +0 -11
  78. package/lib/Socket/Client/types.js.map +0 -1
  79. package/lib/Socket/Client/websocket.d.ts +0 -13
  80. package/lib/Socket/Client/websocket.d.ts.map +0 -1
  81. package/lib/Socket/Client/websocket.js +0 -50
  82. package/lib/Socket/Client/websocket.js.map +0 -1
  83. package/lib/Socket/business.d.ts +0 -188
  84. package/lib/Socket/business.d.ts.map +0 -1
  85. package/lib/Socket/business.js +0 -376
  86. package/lib/Socket/business.js.map +0 -1
  87. package/lib/Socket/chats.d.ts +0 -98
  88. package/lib/Socket/chats.d.ts.map +0 -1
  89. package/lib/Socket/chats.js +0 -962
  90. package/lib/Socket/chats.js.map +0 -1
  91. package/lib/Socket/communities.d.ts +0 -244
  92. package/lib/Socket/communities.d.ts.map +0 -1
  93. package/lib/Socket/communities.js +0 -431
  94. package/lib/Socket/communities.js.map +0 -1
  95. package/lib/Socket/groups.d.ts +0 -137
  96. package/lib/Socket/groups.d.ts.map +0 -1
  97. package/lib/Socket/groups.js +0 -327
  98. package/lib/Socket/groups.js.map +0 -1
  99. package/lib/Socket/index.d.ts +0 -231
  100. package/lib/Socket/index.d.ts.map +0 -1
  101. package/lib/Socket/index.js +0 -18
  102. package/lib/Socket/index.js.map +0 -1
  103. package/lib/Socket/messages-recv.d.ts +0 -173
  104. package/lib/Socket/messages-recv.d.ts.map +0 -1
  105. package/lib/Socket/messages-recv.js +0 -1228
  106. package/lib/Socket/messages-recv.js.map +0 -1
  107. package/lib/Socket/messages-send.d.ts +0 -169
  108. package/lib/Socket/messages-send.d.ts.map +0 -1
  109. package/lib/Socket/messages-send.js +0 -953
  110. package/lib/Socket/messages-send.js.map +0 -1
  111. package/lib/Socket/mex.d.ts +0 -3
  112. package/lib/Socket/mex.d.ts.map +0 -1
  113. package/lib/Socket/mex.js +0 -42
  114. package/lib/Socket/mex.js.map +0 -1
  115. package/lib/Socket/newsletter.d.ts +0 -147
  116. package/lib/Socket/newsletter.d.ts.map +0 -1
  117. package/lib/Socket/newsletter.js +0 -181
  118. package/lib/Socket/newsletter.js.map +0 -1
  119. package/lib/Socket/socket.d.ts +0 -51
  120. package/lib/Socket/socket.d.ts.map +0 -1
  121. package/lib/Socket/socket.js +0 -864
  122. package/lib/Socket/socket.js.map +0 -1
  123. package/lib/Types/Auth.d.ts +0 -111
  124. package/lib/Types/Auth.d.ts.map +0 -1
  125. package/lib/Types/Auth.js +0 -2
  126. package/lib/Types/Auth.js.map +0 -1
  127. package/lib/Types/Bussines.d.ts +0 -25
  128. package/lib/Types/Bussines.d.ts.map +0 -1
  129. package/lib/Types/Bussines.js +0 -2
  130. package/lib/Types/Bussines.js.map +0 -1
  131. package/lib/Types/Call.d.ts +0 -14
  132. package/lib/Types/Call.d.ts.map +0 -1
  133. package/lib/Types/Call.js +0 -2
  134. package/lib/Types/Call.js.map +0 -1
  135. package/lib/Types/Chat.d.ts +0 -123
  136. package/lib/Types/Chat.d.ts.map +0 -1
  137. package/lib/Types/Chat.js +0 -8
  138. package/lib/Types/Chat.js.map +0 -1
  139. package/lib/Types/Contact.d.ts +0 -24
  140. package/lib/Types/Contact.d.ts.map +0 -1
  141. package/lib/Types/Contact.js +0 -2
  142. package/lib/Types/Contact.js.map +0 -1
  143. package/lib/Types/Events.d.ts +0 -202
  144. package/lib/Types/Events.d.ts.map +0 -1
  145. package/lib/Types/Events.js +0 -2
  146. package/lib/Types/Events.js.map +0 -1
  147. package/lib/Types/GroupMetadata.d.ts +0 -67
  148. package/lib/Types/GroupMetadata.d.ts.map +0 -1
  149. package/lib/Types/GroupMetadata.js +0 -2
  150. package/lib/Types/GroupMetadata.js.map +0 -1
  151. package/lib/Types/Label.d.ts +0 -47
  152. package/lib/Types/Label.d.ts.map +0 -1
  153. package/lib/Types/Label.js +0 -25
  154. package/lib/Types/Label.js.map +0 -1
  155. package/lib/Types/LabelAssociation.d.ts +0 -30
  156. package/lib/Types/LabelAssociation.d.ts.map +0 -1
  157. package/lib/Types/LabelAssociation.js +0 -7
  158. package/lib/Types/LabelAssociation.js.map +0 -1
  159. package/lib/Types/Message.d.ts +0 -303
  160. package/lib/Types/Message.d.ts.map +0 -1
  161. package/lib/Types/Message.js +0 -11
  162. package/lib/Types/Message.js.map +0 -1
  163. package/lib/Types/Newsletter.d.ts +0 -135
  164. package/lib/Types/Newsletter.d.ts.map +0 -1
  165. package/lib/Types/Newsletter.js +0 -31
  166. package/lib/Types/Newsletter.js.map +0 -1
  167. package/lib/Types/Product.d.ts +0 -79
  168. package/lib/Types/Product.d.ts.map +0 -1
  169. package/lib/Types/Product.js +0 -2
  170. package/lib/Types/Product.js.map +0 -1
  171. package/lib/Types/Signal.d.ts +0 -76
  172. package/lib/Types/Signal.d.ts.map +0 -1
  173. package/lib/Types/Signal.js +0 -2
  174. package/lib/Types/Signal.js.map +0 -1
  175. package/lib/Types/Socket.d.ts +0 -133
  176. package/lib/Types/Socket.d.ts.map +0 -1
  177. package/lib/Types/Socket.js +0 -3
  178. package/lib/Types/Socket.js.map +0 -1
  179. package/lib/Types/State.d.ts +0 -39
  180. package/lib/Types/State.d.ts.map +0 -1
  181. package/lib/Types/State.js +0 -13
  182. package/lib/Types/State.js.map +0 -1
  183. package/lib/Types/USync.d.ts +0 -26
  184. package/lib/Types/USync.d.ts.map +0 -1
  185. package/lib/Types/USync.js +0 -2
  186. package/lib/Types/USync.js.map +0 -1
  187. package/lib/Types/index.d.ts +0 -65
  188. package/lib/Types/index.d.ts.map +0 -1
  189. package/lib/Types/index.js +0 -26
  190. package/lib/Types/index.js.map +0 -1
  191. package/lib/Utils/auth-utils.d.ts +0 -19
  192. package/lib/Utils/auth-utils.d.ts.map +0 -1
  193. package/lib/Utils/auth-utils.js +0 -257
  194. package/lib/Utils/auth-utils.js.map +0 -1
  195. package/lib/Utils/baileys-event-stream.d.ts +0 -17
  196. package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
  197. package/lib/Utils/baileys-event-stream.js +0 -56
  198. package/lib/Utils/baileys-event-stream.js.map +0 -1
  199. package/lib/Utils/browser-utils.d.ts +0 -4
  200. package/lib/Utils/browser-utils.d.ts.map +0 -1
  201. package/lib/Utils/browser-utils.js +0 -28
  202. package/lib/Utils/browser-utils.js.map +0 -1
  203. package/lib/Utils/business.d.ts +0 -23
  204. package/lib/Utils/business.d.ts.map +0 -1
  205. package/lib/Utils/business.js +0 -231
  206. package/lib/Utils/business.js.map +0 -1
  207. package/lib/Utils/chat-utils.d.ts +0 -70
  208. package/lib/Utils/chat-utils.d.ts.map +0 -1
  209. package/lib/Utils/chat-utils.js +0 -763
  210. package/lib/Utils/chat-utils.js.map +0 -1
  211. package/lib/Utils/crypto.d.ts +0 -41
  212. package/lib/Utils/crypto.d.ts.map +0 -1
  213. package/lib/Utils/crypto.js +0 -142
  214. package/lib/Utils/crypto.js.map +0 -1
  215. package/lib/Utils/decode-wa-message.d.ts +0 -48
  216. package/lib/Utils/decode-wa-message.d.ts.map +0 -1
  217. package/lib/Utils/decode-wa-message.js +0 -279
  218. package/lib/Utils/decode-wa-message.js.map +0 -1
  219. package/lib/Utils/event-buffer.d.ts +0 -34
  220. package/lib/Utils/event-buffer.d.ts.map +0 -1
  221. package/lib/Utils/event-buffer.js +0 -548
  222. package/lib/Utils/event-buffer.js.map +0 -1
  223. package/lib/Utils/generics.d.ts +0 -90
  224. package/lib/Utils/generics.d.ts.map +0 -1
  225. package/lib/Utils/generics.js +0 -381
  226. package/lib/Utils/generics.js.map +0 -1
  227. package/lib/Utils/history.d.ts +0 -19
  228. package/lib/Utils/history.d.ts.map +0 -1
  229. package/lib/Utils/history.js +0 -84
  230. package/lib/Utils/history.js.map +0 -1
  231. package/lib/Utils/index.d.ts +0 -20
  232. package/lib/Utils/index.d.ts.map +0 -1
  233. package/lib/Utils/index.js +0 -19
  234. package/lib/Utils/index.js.map +0 -1
  235. package/lib/Utils/link-preview.d.ts +0 -21
  236. package/lib/Utils/link-preview.d.ts.map +0 -1
  237. package/lib/Utils/link-preview.js +0 -85
  238. package/lib/Utils/link-preview.js.map +0 -1
  239. package/lib/Utils/logger.d.ts +0 -12
  240. package/lib/Utils/logger.d.ts.map +0 -1
  241. package/lib/Utils/logger.js +0 -3
  242. package/lib/Utils/logger.js.map +0 -1
  243. package/lib/Utils/lt-hash.d.ts +0 -13
  244. package/lib/Utils/lt-hash.d.ts.map +0 -1
  245. package/lib/Utils/lt-hash.js +0 -48
  246. package/lib/Utils/lt-hash.js.map +0 -1
  247. package/lib/Utils/make-mutex.d.ts +0 -8
  248. package/lib/Utils/make-mutex.d.ts.map +0 -1
  249. package/lib/Utils/make-mutex.js +0 -40
  250. package/lib/Utils/make-mutex.js.map +0 -1
  251. package/lib/Utils/message-retry-manager.d.ts +0 -82
  252. package/lib/Utils/message-retry-manager.d.ts.map +0 -1
  253. package/lib/Utils/message-retry-manager.js +0 -149
  254. package/lib/Utils/message-retry-manager.js.map +0 -1
  255. package/lib/Utils/messages-media.d.ts +0 -114
  256. package/lib/Utils/messages-media.d.ts.map +0 -1
  257. package/lib/Utils/messages-media.js +0 -663
  258. package/lib/Utils/messages-media.js.map +0 -1
  259. package/lib/Utils/messages.d.ts +0 -76
  260. package/lib/Utils/messages.d.ts.map +0 -1
  261. package/lib/Utils/messages.js +0 -820
  262. package/lib/Utils/messages.js.map +0 -1
  263. package/lib/Utils/noise-handler.d.ts +0 -20
  264. package/lib/Utils/noise-handler.d.ts.map +0 -1
  265. package/lib/Utils/noise-handler.js +0 -147
  266. package/lib/Utils/noise-handler.js.map +0 -1
  267. package/lib/Utils/pre-key-manager.d.ts +0 -28
  268. package/lib/Utils/pre-key-manager.d.ts.map +0 -1
  269. package/lib/Utils/pre-key-manager.js +0 -106
  270. package/lib/Utils/pre-key-manager.js.map +0 -1
  271. package/lib/Utils/process-message.d.ts +0 -42
  272. package/lib/Utils/process-message.d.ts.map +0 -1
  273. package/lib/Utils/process-message.js +0 -413
  274. package/lib/Utils/process-message.js.map +0 -1
  275. package/lib/Utils/signal.d.ts +0 -34
  276. package/lib/Utils/signal.d.ts.map +0 -1
  277. package/lib/Utils/signal.js +0 -159
  278. package/lib/Utils/signal.js.map +0 -1
  279. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  280. package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
  281. package/lib/Utils/use-multi-file-auth-state.js +0 -121
  282. package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
  283. package/lib/Utils/validate-connection.d.ts +0 -11
  284. package/lib/Utils/validate-connection.d.ts.map +0 -1
  285. package/lib/Utils/validate-connection.js +0 -195
  286. package/lib/Utils/validate-connection.js.map +0 -1
  287. package/lib/WABinary/constants.d.ts +0 -28
  288. package/lib/WABinary/constants.d.ts.map +0 -1
  289. package/lib/WABinary/constants.js +0 -1301
  290. package/lib/WABinary/constants.js.map +0 -1
  291. package/lib/WABinary/decode.d.ts +0 -7
  292. package/lib/WABinary/decode.d.ts.map +0 -1
  293. package/lib/WABinary/decode.js +0 -238
  294. package/lib/WABinary/decode.js.map +0 -1
  295. package/lib/WABinary/encode.d.ts +0 -3
  296. package/lib/WABinary/encode.d.ts.map +0 -1
  297. package/lib/WABinary/encode.js +0 -216
  298. package/lib/WABinary/encode.js.map +0 -1
  299. package/lib/WABinary/generic-utils.d.ts +0 -15
  300. package/lib/WABinary/generic-utils.d.ts.map +0 -1
  301. package/lib/WABinary/generic-utils.js +0 -102
  302. package/lib/WABinary/generic-utils.js.map +0 -1
  303. package/lib/WABinary/index.d.ts +0 -6
  304. package/lib/WABinary/index.d.ts.map +0 -1
  305. package/lib/WABinary/index.js +0 -6
  306. package/lib/WABinary/index.js.map +0 -1
  307. package/lib/WABinary/jid-utils.d.ts +0 -48
  308. package/lib/WABinary/jid-utils.d.ts.map +0 -1
  309. package/lib/WABinary/jid-utils.js +0 -96
  310. package/lib/WABinary/jid-utils.js.map +0 -1
  311. package/lib/WABinary/types.d.ts +0 -19
  312. package/lib/WABinary/types.d.ts.map +0 -1
  313. package/lib/WABinary/types.js +0 -2
  314. package/lib/WABinary/types.js.map +0 -1
  315. package/lib/WAM/BinaryInfo.d.ts +0 -9
  316. package/lib/WAM/BinaryInfo.d.ts.map +0 -1
  317. package/lib/WAM/BinaryInfo.js +0 -10
  318. package/lib/WAM/BinaryInfo.js.map +0 -1
  319. package/lib/WAM/constants.d.ts +0 -40
  320. package/lib/WAM/constants.d.ts.map +0 -1
  321. package/lib/WAM/constants.js +0 -22853
  322. package/lib/WAM/constants.js.map +0 -1
  323. package/lib/WAM/encode.d.ts +0 -3
  324. package/lib/WAM/encode.d.ts.map +0 -1
  325. package/lib/WAM/encode.js +0 -150
  326. package/lib/WAM/encode.js.map +0 -1
  327. package/lib/WAM/index.d.ts +0 -4
  328. package/lib/WAM/index.d.ts.map +0 -1
  329. package/lib/WAM/index.js +0 -4
  330. package/lib/WAM/index.js.map +0 -1
  331. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  332. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
  333. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -29
  334. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
  335. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
  336. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
  337. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -54
  338. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
  339. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
  340. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
  341. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
  342. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
  343. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
  344. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
  345. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -38
  346. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
  347. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  348. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
  349. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  350. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
  351. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  352. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
  353. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
  354. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
  355. package/lib/WAUSync/Protocols/index.d.ts +0 -5
  356. package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
  357. package/lib/WAUSync/Protocols/index.js +0 -5
  358. package/lib/WAUSync/Protocols/index.js.map +0 -1
  359. package/lib/WAUSync/USyncQuery.d.ts +0 -29
  360. package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
  361. package/lib/WAUSync/USyncQuery.js +0 -94
  362. package/lib/WAUSync/USyncQuery.js.map +0 -1
  363. package/lib/WAUSync/USyncUser.d.ts +0 -13
  364. package/lib/WAUSync/USyncUser.d.ts.map +0 -1
  365. package/lib/WAUSync/USyncUser.js +0 -23
  366. package/lib/WAUSync/USyncUser.js.map +0 -1
  367. package/lib/WAUSync/index.d.ts +0 -4
  368. package/lib/WAUSync/index.d.ts.map +0 -1
  369. package/lib/WAUSync/index.js +0 -4
  370. package/lib/WAUSync/index.js.map +0 -1
  371. package/lib/index.d.ts +0 -12
  372. package/lib/index.d.ts.map +0 -1
  373. package/lib/index.js +0 -11
  374. package/lib/index.js.map +0 -1
@@ -1,663 +0,0 @@
1
- import { Boom } from '@hapi/boom';
2
- import { exec } 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 { URL } from 'url';
10
- import { proto } from '../../WAProto/index.js';
11
- import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP } from '../Defaults/index.js';
12
- import { getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary/index.js';
13
- import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto.js';
14
- import { generateMessageIDV2 } from './generics.js';
15
- const getTmpFilesDirectory = () => tmpdir();
16
- const getImageProcessingLibrary = async () => {
17
- //@ts-ignore
18
- const [jimp, sharp] = await Promise.all([import('jimp').catch(() => { }), import('sharp').catch(() => { })]);
19
- if (sharp) {
20
- return { sharp };
21
- }
22
- if (jimp) {
23
- return { jimp };
24
- }
25
- throw new Boom('No image processing library available');
26
- };
27
- export const hkdfInfoKey = (type) => {
28
- const hkdfInfo = MEDIA_HKDF_KEY_MAPPING[type];
29
- return `WhatsApp ${hkdfInfo} Keys`;
30
- };
31
- export const getRawMediaUploadData = async (media, mediaType, logger) => {
32
- const { stream } = await getStream(media);
33
- logger?.debug('got stream for raw upload');
34
- const hasher = Crypto.createHash('sha256');
35
- const filePath = join(tmpdir(), mediaType + generateMessageIDV2());
36
- const fileWriteStream = createWriteStream(filePath);
37
- let fileLength = 0;
38
- try {
39
- for await (const data of stream) {
40
- fileLength += data.length;
41
- hasher.update(data);
42
- if (!fileWriteStream.write(data)) {
43
- await once(fileWriteStream, 'drain');
44
- }
45
- }
46
- fileWriteStream.end();
47
- await once(fileWriteStream, 'finish');
48
- stream.destroy();
49
- const fileSha256 = hasher.digest();
50
- logger?.debug('hashed data for raw upload');
51
- return {
52
- filePath: filePath,
53
- fileSha256,
54
- fileLength
55
- };
56
- }
57
- catch (error) {
58
- fileWriteStream.destroy();
59
- stream.destroy();
60
- try {
61
- await fs.unlink(filePath);
62
- }
63
- catch {
64
- //
65
- }
66
- throw error;
67
- }
68
- };
69
- /** generates all the keys required to encrypt/decrypt & sign a media message */
70
- export async function getMediaKeys(buffer, mediaType) {
71
- if (!buffer) {
72
- throw new Boom('Cannot derive from empty media key');
73
- }
74
- if (typeof buffer === 'string') {
75
- buffer = Buffer.from(buffer.replace('data:;base64,', ''), 'base64');
76
- }
77
- // expand using HKDF to 112 bytes, also pass in the relevant app info
78
- const expandedMediaKey = await hkdf(buffer, 112, { info: hkdfInfoKey(mediaType) });
79
- return {
80
- iv: expandedMediaKey.slice(0, 16),
81
- cipherKey: expandedMediaKey.slice(16, 48),
82
- macKey: expandedMediaKey.slice(48, 80)
83
- };
84
- }
85
- /** Extracts video thumb using FFMPEG */
86
- const extractVideoThumb = async (path, destPath, time, size) => new Promise((resolve, reject) => {
87
- const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`;
88
- exec(cmd, err => {
89
- if (err) {
90
- reject(err);
91
- }
92
- else {
93
- resolve();
94
- }
95
- });
96
- });
97
- export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
98
- // TODO: Move entirely to sharp, removing jimp as it supports readable streams
99
- // This will have positive speed and performance impacts as well as minimizing RAM usage.
100
- if (bufferOrFilePath instanceof Readable) {
101
- bufferOrFilePath = await toBuffer(bufferOrFilePath);
102
- }
103
- const lib = await getImageProcessingLibrary();
104
- if ('sharp' in lib && typeof lib.sharp?.default === 'function') {
105
- const img = lib.sharp.default(bufferOrFilePath);
106
- const dimensions = await img.metadata();
107
- const buffer = await img.resize(width).jpeg({ quality: 50 }).toBuffer();
108
- return {
109
- buffer,
110
- original: {
111
- width: dimensions.width,
112
- height: dimensions.height
113
- }
114
- };
115
- }
116
- else if ('jimp' in lib && typeof lib.jimp?.Jimp === 'object') {
117
- const jimp = await lib.jimp.Jimp.read(bufferOrFilePath);
118
- const dimensions = {
119
- width: jimp.width,
120
- height: jimp.height
121
- };
122
- const buffer = await jimp
123
- .resize({ w: width, mode: lib.jimp.ResizeStrategy.BILINEAR })
124
- .getBuffer('image/jpeg', { quality: 50 });
125
- return {
126
- buffer,
127
- original: dimensions
128
- };
129
- }
130
- else {
131
- throw new Boom('No image processing library available');
132
- }
133
- };
134
- export const encodeBase64EncodedStringForUpload = (b64) => encodeURIComponent(b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, ''));
135
- export const generateProfilePicture = async (mediaUpload, dimensions) => {
136
- let buffer;
137
- const { width: w = 640, height: h = 640 } = dimensions || {};
138
- if (Buffer.isBuffer(mediaUpload)) {
139
- buffer = mediaUpload;
140
- }
141
- else {
142
- // Use getStream to handle all WAMediaUpload types (Buffer, Stream, URL)
143
- const { stream } = await getStream(mediaUpload);
144
- // Convert the resulting stream to a buffer
145
- buffer = await toBuffer(stream);
146
- }
147
- const lib = await getImageProcessingLibrary();
148
- let img;
149
- if ('sharp' in lib && typeof lib.sharp?.default === 'function') {
150
- img = lib.sharp
151
- .default(buffer)
152
- .resize(w, h)
153
- .jpeg({
154
- quality: 50
155
- })
156
- .toBuffer();
157
- }
158
- else if ('jimp' in lib && typeof lib.jimp?.Jimp === 'object') {
159
- const jimp = await lib.jimp.Jimp.read(buffer);
160
- const min = Math.min(jimp.width, jimp.height);
161
- const cropped = jimp.crop({ x: 0, y: 0, w: min, h: min });
162
- img = cropped.resize({ w, h, mode: lib.jimp.ResizeStrategy.BILINEAR }).getBuffer('image/jpeg', { quality: 50 });
163
- }
164
- else {
165
- throw new Boom('No image processing library available');
166
- }
167
- return {
168
- img: await img
169
- };
170
- };
171
- /** gets the SHA256 of the given media message */
172
- export const mediaMessageSHA256B64 = (message) => {
173
- const media = Object.values(message)[0];
174
- return media?.fileSha256 && Buffer.from(media.fileSha256).toString('base64');
175
- };
176
- export async function getAudioDuration(buffer) {
177
- const musicMetadata = await import('music-metadata');
178
- let metadata;
179
- const options = {
180
- duration: true
181
- };
182
- if (Buffer.isBuffer(buffer)) {
183
- metadata = await musicMetadata.parseBuffer(buffer, undefined, options);
184
- }
185
- else if (typeof buffer === 'string') {
186
- metadata = await musicMetadata.parseFile(buffer, options);
187
- }
188
- else {
189
- metadata = await musicMetadata.parseStream(buffer, undefined, options);
190
- }
191
- return metadata.format.duration;
192
- }
193
- /**
194
- referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
195
- */
196
- export async function getAudioWaveform(buffer, logger) {
197
- try {
198
- // @ts-ignore
199
- const { default: decoder } = await import('audio-decode');
200
- let audioData;
201
- if (Buffer.isBuffer(buffer)) {
202
- audioData = buffer;
203
- }
204
- else if (typeof buffer === 'string') {
205
- const rStream = createReadStream(buffer);
206
- audioData = await toBuffer(rStream);
207
- }
208
- else {
209
- audioData = await toBuffer(buffer);
210
- }
211
- const audioBuffer = await decoder(audioData);
212
- const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
213
- const samples = 64; // Number of samples we want to have in our final data set
214
- const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
215
- const filteredData = [];
216
- for (let i = 0; i < samples; i++) {
217
- const blockStart = blockSize * i; // the location of the first sample in the block
218
- let sum = 0;
219
- for (let j = 0; j < blockSize; j++) {
220
- sum = sum + Math.abs(rawData[blockStart + j]); // find the sum of all the samples in the block
221
- }
222
- filteredData.push(sum / blockSize); // divide the sum by the block size to get the average
223
- }
224
- // This guarantees that the largest data point will be set to 1, and the rest of the data will scale proportionally.
225
- const multiplier = Math.pow(Math.max(...filteredData), -1);
226
- const normalizedData = filteredData.map(n => n * multiplier);
227
- // Generate waveform like WhatsApp
228
- const waveform = new Uint8Array(normalizedData.map(n => Math.floor(100 * n)));
229
- return waveform;
230
- }
231
- catch (e) {
232
- logger?.debug('Failed to generate waveform: ' + e);
233
- }
234
- }
235
- export const toReadable = (buffer) => {
236
- const readable = new Readable({ read: () => { } });
237
- readable.push(buffer);
238
- readable.push(null);
239
- return readable;
240
- };
241
- export const toBuffer = async (stream) => {
242
- const chunks = [];
243
- for await (const chunk of stream) {
244
- chunks.push(chunk);
245
- }
246
- stream.destroy();
247
- return Buffer.concat(chunks);
248
- };
249
- export const getStream = async (item, opts) => {
250
- if (Buffer.isBuffer(item)) {
251
- return { stream: toReadable(item), type: 'buffer' };
252
- }
253
- if ('stream' in item) {
254
- return { stream: item.stream, type: 'readable' };
255
- }
256
- const urlStr = item.url.toString();
257
- if (urlStr.startsWith('data:')) {
258
- const buffer = Buffer.from(urlStr.split(',')[1], 'base64');
259
- return { stream: toReadable(buffer), type: 'buffer' };
260
- }
261
- if (urlStr.startsWith('http://') || urlStr.startsWith('https://')) {
262
- return { stream: await getHttpStream(item.url, opts), type: 'remote' };
263
- }
264
- return { stream: createReadStream(item.url), type: 'file' };
265
- };
266
- /** generates a thumbnail for a given media, if required */
267
- export async function generateThumbnail(file, mediaType, options) {
268
- let thumbnail;
269
- let originalImageDimensions;
270
- if (mediaType === 'image') {
271
- const { buffer, original } = await extractImageThumb(file);
272
- thumbnail = buffer.toString('base64');
273
- if (original.width && original.height) {
274
- originalImageDimensions = {
275
- width: original.width,
276
- height: original.height
277
- };
278
- }
279
- }
280
- else if (mediaType === 'video') {
281
- const imgFilename = join(getTmpFilesDirectory(), generateMessageIDV2() + '.jpg');
282
- try {
283
- await extractVideoThumb(file, imgFilename, '00:00:00', { width: 32, height: 32 });
284
- const buff = await fs.readFile(imgFilename);
285
- thumbnail = buff.toString('base64');
286
- await fs.unlink(imgFilename);
287
- }
288
- catch (err) {
289
- options.logger?.debug('could not generate video thumb: ' + err);
290
- }
291
- }
292
- return {
293
- thumbnail,
294
- originalImageDimensions
295
- };
296
- }
297
- export const getHttpStream = async (url, options = {}) => {
298
- const response = await fetch(url.toString(), {
299
- dispatcher: options.dispatcher,
300
- method: 'GET',
301
- headers: options.headers
302
- });
303
- if (!response.ok) {
304
- throw new Boom(`Failed to fetch stream from ${url}`, { statusCode: response.status, data: { url } });
305
- }
306
- // @ts-ignore Node18+ Readable.fromWeb exists
307
- return Readable.fromWeb(response.body);
308
- };
309
- export const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
310
- const { stream, type } = await getStream(media, opts);
311
- logger?.debug('fetched media stream');
312
- const mediaKey = Crypto.randomBytes(32);
313
- const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType);
314
- const encFilePath = join(getTmpFilesDirectory(), mediaType + generateMessageIDV2() + '-enc');
315
- const encFileWriteStream = createWriteStream(encFilePath);
316
- let originalFileStream;
317
- let originalFilePath;
318
- if (saveOriginalFileIfRequired) {
319
- originalFilePath = join(getTmpFilesDirectory(), mediaType + generateMessageIDV2() + '-original');
320
- originalFileStream = createWriteStream(originalFilePath);
321
- }
322
- let fileLength = 0;
323
- const aes = Crypto.createCipheriv('aes-256-cbc', cipherKey, iv);
324
- const hmac = Crypto.createHmac('sha256', macKey).update(iv);
325
- const sha256Plain = Crypto.createHash('sha256');
326
- const sha256Enc = Crypto.createHash('sha256');
327
- const onChunk = (buff) => {
328
- sha256Enc.update(buff);
329
- hmac.update(buff);
330
- encFileWriteStream.write(buff);
331
- };
332
- try {
333
- for await (const data of stream) {
334
- fileLength += data.length;
335
- if (type === 'remote' &&
336
- opts?.maxContentLength &&
337
- fileLength + data.length > opts.maxContentLength) {
338
- throw new Boom(`content length exceeded when encrypting "${type}"`, {
339
- data: { media, type }
340
- });
341
- }
342
- if (originalFileStream) {
343
- if (!originalFileStream.write(data)) {
344
- await once(originalFileStream, 'drain');
345
- }
346
- }
347
- sha256Plain.update(data);
348
- onChunk(aes.update(data));
349
- }
350
- onChunk(aes.final());
351
- const mac = hmac.digest().slice(0, 10);
352
- sha256Enc.update(mac);
353
- const fileSha256 = sha256Plain.digest();
354
- const fileEncSha256 = sha256Enc.digest();
355
- encFileWriteStream.write(mac);
356
- encFileWriteStream.end();
357
- originalFileStream?.end?.();
358
- stream.destroy();
359
- logger?.debug('encrypted data successfully');
360
- return {
361
- mediaKey,
362
- originalFilePath,
363
- encFilePath,
364
- mac,
365
- fileEncSha256,
366
- fileSha256,
367
- fileLength
368
- };
369
- }
370
- catch (error) {
371
- // destroy all streams with error
372
- encFileWriteStream.destroy();
373
- originalFileStream?.destroy?.();
374
- aes.destroy();
375
- hmac.destroy();
376
- sha256Plain.destroy();
377
- sha256Enc.destroy();
378
- stream.destroy();
379
- try {
380
- await fs.unlink(encFilePath);
381
- if (originalFilePath) {
382
- await fs.unlink(originalFilePath);
383
- }
384
- }
385
- catch (err) {
386
- logger?.error({ err }, 'failed deleting tmp files');
387
- }
388
- throw error;
389
- }
390
- };
391
- const DEF_HOST = 'mmg.whatsapp.net';
392
- const AES_CHUNK_SIZE = 16;
393
- const toSmallestChunkSize = (num) => {
394
- return Math.floor(num / AES_CHUNK_SIZE) * AES_CHUNK_SIZE;
395
- };
396
- export const getUrlFromDirectPath = (directPath) => `https://${DEF_HOST}${directPath}`;
397
- export const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
398
- const isValidMediaUrl = url?.startsWith('https://mmg.whatsapp.net/');
399
- const downloadUrl = isValidMediaUrl ? url : getUrlFromDirectPath(directPath);
400
- if (!downloadUrl) {
401
- throw new Boom('No valid media URL or directPath present in message', { statusCode: 400 });
402
- }
403
- const keys = await getMediaKeys(mediaKey, type);
404
- return downloadEncryptedContent(downloadUrl, keys, opts);
405
- };
406
- /**
407
- * Decrypts and downloads an AES256-CBC encrypted file given the keys.
408
- * Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
409
- * */
410
- export const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startByte, endByte, options } = {}) => {
411
- let bytesFetched = 0;
412
- let startChunk = 0;
413
- let firstBlockIsIV = false;
414
- // if a start byte is specified -- then we need to fetch the previous chunk as that will form the IV
415
- if (startByte) {
416
- const chunk = toSmallestChunkSize(startByte || 0);
417
- if (chunk) {
418
- startChunk = chunk - AES_CHUNK_SIZE;
419
- bytesFetched = chunk;
420
- firstBlockIsIV = true;
421
- }
422
- }
423
- const endChunk = endByte ? toSmallestChunkSize(endByte || 0) + AES_CHUNK_SIZE : undefined;
424
- const headersInit = options?.headers ? options.headers : undefined;
425
- const headers = {
426
- ...(headersInit
427
- ? Array.isArray(headersInit)
428
- ? Object.fromEntries(headersInit)
429
- : headersInit
430
- : {}),
431
- Origin: DEFAULT_ORIGIN
432
- };
433
- if (startChunk || endChunk) {
434
- headers.Range = `bytes=${startChunk}-`;
435
- if (endChunk) {
436
- headers.Range += endChunk;
437
- }
438
- }
439
- // download the message
440
- const fetched = await getHttpStream(downloadUrl, {
441
- ...(options || {}),
442
- headers
443
- });
444
- let remainingBytes = Buffer.from([]);
445
- let aes;
446
- const pushBytes = (bytes, push) => {
447
- if (startByte || endByte) {
448
- const start = bytesFetched >= startByte ? undefined : Math.max(startByte - bytesFetched, 0);
449
- const end = bytesFetched + bytes.length < endByte ? undefined : Math.max(endByte - bytesFetched, 0);
450
- push(bytes.slice(start, end));
451
- bytesFetched += bytes.length;
452
- }
453
- else {
454
- push(bytes);
455
- }
456
- };
457
- const output = new Transform({
458
- transform(chunk, _, callback) {
459
- let data = Buffer.concat([remainingBytes, chunk]);
460
- const decryptLength = toSmallestChunkSize(data.length);
461
- remainingBytes = data.slice(decryptLength);
462
- data = data.slice(0, decryptLength);
463
- if (!aes) {
464
- let ivValue = iv;
465
- if (firstBlockIsIV) {
466
- ivValue = data.slice(0, AES_CHUNK_SIZE);
467
- data = data.slice(AES_CHUNK_SIZE);
468
- }
469
- aes = Crypto.createDecipheriv('aes-256-cbc', cipherKey, ivValue);
470
- // if an end byte that is not EOF is specified
471
- // stop auto padding (PKCS7) -- otherwise throws an error for decryption
472
- if (endByte) {
473
- aes.setAutoPadding(false);
474
- }
475
- }
476
- try {
477
- pushBytes(aes.update(data), b => this.push(b));
478
- callback();
479
- }
480
- catch (error) {
481
- callback(error);
482
- }
483
- },
484
- final(callback) {
485
- try {
486
- pushBytes(aes.final(), b => this.push(b));
487
- callback();
488
- }
489
- catch (error) {
490
- callback(error);
491
- }
492
- }
493
- });
494
- return fetched.pipe(output, { end: true });
495
- };
496
- export function extensionForMediaMessage(message) {
497
- const getExtension = (mimetype) => mimetype.split(';')[0]?.split('/')[1];
498
- const type = Object.keys(message)[0];
499
- let extension;
500
- if (type === 'locationMessage' || type === 'liveLocationMessage' || type === 'productMessage') {
501
- extension = '.jpeg';
502
- }
503
- else {
504
- const messageContent = message[type];
505
- extension = getExtension(messageContent.mimetype);
506
- }
507
- return extension;
508
- }
509
- export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
510
- return async (filePath, { mediaType, fileEncSha256B64, timeoutMs }) => {
511
- // send a query JSON to obtain the url & auth token to upload our media
512
- let uploadInfo = await refreshMediaConn(false);
513
- let urls;
514
- const hosts = [...customUploadHosts, ...uploadInfo.hosts];
515
- fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64);
516
- for (const { hostname } of hosts) {
517
- logger.debug(`uploading to "${hostname}"`);
518
- const auth = encodeURIComponent(uploadInfo.auth); // the auth token
519
- const url = `https://${hostname}${MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
520
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
521
- let result;
522
- try {
523
- const stream = createReadStream(filePath);
524
- const response = await fetch(url, {
525
- dispatcher: fetchAgent,
526
- method: 'POST',
527
- body: stream,
528
- headers: {
529
- ...(() => {
530
- const hdrs = options?.headers;
531
- if (!hdrs)
532
- return {};
533
- return Array.isArray(hdrs) ? Object.fromEntries(hdrs) : hdrs;
534
- })(),
535
- 'Content-Type': 'application/octet-stream',
536
- Origin: DEFAULT_ORIGIN
537
- },
538
- duplex: 'half',
539
- // Note: custom agents/proxy require undici Agent; omitted here.
540
- signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined
541
- });
542
- let parsed = undefined;
543
- try {
544
- parsed = await response.json();
545
- }
546
- catch {
547
- parsed = undefined;
548
- }
549
- result = parsed;
550
- if (result?.url || result?.directPath) {
551
- urls = {
552
- mediaUrl: result.url,
553
- directPath: result.direct_path,
554
- meta_hmac: result.meta_hmac,
555
- fbid: result.fbid,
556
- ts: result.ts
557
- };
558
- break;
559
- }
560
- else {
561
- uploadInfo = await refreshMediaConn(true);
562
- throw new Error(`upload failed, reason: ${JSON.stringify(result)}`);
563
- }
564
- }
565
- catch (error) {
566
- const isLast = hostname === hosts[uploadInfo.hosts.length - 1]?.hostname;
567
- logger.warn({ trace: error?.stack, uploadResult: result }, `Error in uploading to ${hostname} ${isLast ? '' : ', retrying...'}`);
568
- }
569
- }
570
- if (!urls) {
571
- throw new Boom('Media upload failed on all hosts', { statusCode: 500 });
572
- }
573
- return urls;
574
- };
575
- };
576
- const getMediaRetryKey = (mediaKey) => {
577
- return hkdf(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' });
578
- };
579
- /**
580
- * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
581
- */
582
- export const encryptMediaRetryRequest = async (key, mediaKey, meId) => {
583
- const recp = { stanzaId: key.id };
584
- const recpBuffer = proto.ServerErrorReceipt.encode(recp).finish();
585
- const iv = Crypto.randomBytes(12);
586
- const retryKey = await getMediaRetryKey(mediaKey);
587
- const ciphertext = aesEncryptGCM(recpBuffer, retryKey, iv, Buffer.from(key.id));
588
- const req = {
589
- tag: 'receipt',
590
- attrs: {
591
- id: key.id,
592
- to: jidNormalizedUser(meId),
593
- type: 'server-error'
594
- },
595
- content: [
596
- // this encrypt node is actually pretty useless
597
- // the media is returned even without this node
598
- // keeping it here to maintain parity with WA Web
599
- {
600
- tag: 'encrypt',
601
- attrs: {},
602
- content: [
603
- { tag: 'enc_p', attrs: {}, content: ciphertext },
604
- { tag: 'enc_iv', attrs: {}, content: iv }
605
- ]
606
- },
607
- {
608
- tag: 'rmr',
609
- attrs: {
610
- jid: key.remoteJid,
611
- from_me: (!!key.fromMe).toString(),
612
- // @ts-ignore
613
- participant: key.participant || undefined
614
- }
615
- }
616
- ]
617
- };
618
- return req;
619
- };
620
- export const decodeMediaRetryNode = (node) => {
621
- const rmrNode = getBinaryNodeChild(node, 'rmr');
622
- const event = {
623
- key: {
624
- id: node.attrs.id,
625
- remoteJid: rmrNode.attrs.jid,
626
- fromMe: rmrNode.attrs.from_me === 'true',
627
- participant: rmrNode.attrs.participant
628
- }
629
- };
630
- const errorNode = getBinaryNodeChild(node, 'error');
631
- if (errorNode) {
632
- const errorCode = +errorNode.attrs.code;
633
- event.error = new Boom(`Failed to re-upload media (${errorCode})`, {
634
- data: errorNode.attrs,
635
- statusCode: getStatusCodeForMediaRetry(errorCode)
636
- });
637
- }
638
- else {
639
- const encryptedInfoNode = getBinaryNodeChild(node, 'encrypt');
640
- const ciphertext = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_p');
641
- const iv = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_iv');
642
- if (ciphertext && iv) {
643
- event.media = { ciphertext, iv };
644
- }
645
- else {
646
- event.error = new Boom('Failed to re-upload media (missing ciphertext)', { statusCode: 404 });
647
- }
648
- }
649
- return event;
650
- };
651
- export const decryptMediaRetryData = async ({ ciphertext, iv }, mediaKey, msgId) => {
652
- const retryKey = await getMediaRetryKey(mediaKey);
653
- const plaintext = aesDecryptGCM(ciphertext, retryKey, iv, Buffer.from(msgId));
654
- return proto.MediaRetryNotification.decode(plaintext);
655
- };
656
- export const getStatusCodeForMediaRetry = (code) => MEDIA_RETRY_STATUS_MAP[code];
657
- const MEDIA_RETRY_STATUS_MAP = {
658
- [proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
659
- [proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
660
- [proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
661
- [proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418
662
- };
663
- //# sourceMappingURL=messages-media.js.map