@eduh_dev021/baileys 0.0.0-stage → 1.1.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 (526) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +1843 -2
  3. package/WAProto/index.d.ts +22220 -0
  4. package/WAProto/index.js +5 -0
  5. package/cjs/WAProto/index.d.ts +22220 -0
  6. package/cjs/WAProto/index.js +60125 -0
  7. package/cjs/engine-requirements.js +12 -0
  8. package/cjs/lib/Addon/cache.js +179 -0
  9. package/cjs/lib/Addon/crc32.js +41 -0
  10. package/cjs/lib/Addon/file-type.js +217 -0
  11. package/cjs/lib/Addon/get-file.js +99 -0
  12. package/cjs/lib/Addon/http-error.d.ts +18 -0
  13. package/cjs/lib/Addon/http-error.js +66 -0
  14. package/cjs/lib/Addon/index.d.ts +96 -0
  15. package/cjs/lib/Addon/index.js +58 -0
  16. package/cjs/lib/Addon/keyed-db.d.ts +14 -0
  17. package/cjs/lib/Addon/keyed-db.js +264 -0
  18. package/cjs/lib/Addon/link-preview.d.ts +15 -0
  19. package/cjs/lib/Addon/link-preview.js +104 -0
  20. package/cjs/lib/Addon/media-info.js +98 -0
  21. package/cjs/lib/Addon/mutex.js +78 -0
  22. package/cjs/lib/Addon/qr.js +464 -0
  23. package/cjs/lib/Addon/queue.js +54 -0
  24. package/cjs/lib/Addon/waveform.js +130 -0
  25. package/cjs/lib/Addon/zip.js +136 -0
  26. package/cjs/lib/Defaults/index.d.ts +184 -0
  27. package/cjs/lib/Defaults/index.js +292 -0
  28. package/cjs/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  29. package/cjs/lib/Signal/Group/ciphertext-message.js +37 -0
  30. package/cjs/lib/Signal/Group/group-cipher.d.ts +10 -0
  31. package/cjs/lib/Signal/Group/group-cipher.js +105 -0
  32. package/cjs/lib/Signal/Group/group-session-builder.d.ts +7 -0
  33. package/cjs/lib/Signal/Group/group-session-builder.js +65 -0
  34. package/cjs/lib/Signal/Group/index.d.ts +11 -0
  35. package/cjs/lib/Signal/Group/index.js +67 -0
  36. package/cjs/lib/Signal/Group/keyhelper.d.ts +6 -0
  37. package/cjs/lib/Signal/Group/keyhelper.js +47 -0
  38. package/cjs/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  39. package/cjs/lib/Signal/Group/sender-chain-key.js +51 -0
  40. package/cjs/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  41. package/cjs/lib/Signal/Group/sender-key-distribution-message.js +80 -0
  42. package/cjs/lib/Signal/Group/sender-key-message.d.ts +18 -0
  43. package/cjs/lib/Signal/Group/sender-key-message.js +87 -0
  44. package/cjs/lib/Signal/Group/sender-key-name.d.ts +11 -0
  45. package/cjs/lib/Signal/Group/sender-key-name.js +73 -0
  46. package/cjs/lib/Signal/Group/sender-key-record.d.ts +12 -0
  47. package/cjs/lib/Signal/Group/sender-key-record.js +66 -0
  48. package/cjs/lib/Signal/Group/sender-key-state.d.ts +16 -0
  49. package/cjs/lib/Signal/Group/sender-key-state.js +106 -0
  50. package/cjs/lib/Signal/Group/sender-message-key.d.ts +11 -0
  51. package/cjs/lib/Signal/Group/sender-message-key.js +51 -0
  52. package/cjs/lib/Signal/libsignal.d.ts +54 -0
  53. package/cjs/lib/Signal/libsignal.js +421 -0
  54. package/cjs/lib/Signal/lid-mapping.d.ts +20 -0
  55. package/cjs/lib/Signal/lid-mapping.js +292 -0
  56. package/cjs/lib/Socket/Client/index.d.ts +2 -0
  57. package/cjs/lib/Socket/Client/index.js +23 -0
  58. package/cjs/lib/Socket/Client/types.d.ts +5 -0
  59. package/cjs/lib/Socket/Client/types.js +36 -0
  60. package/cjs/lib/Socket/Client/websocket.d.ts +12 -0
  61. package/cjs/lib/Socket/Client/websocket.js +143 -0
  62. package/cjs/lib/Socket/business.d.ts +387 -0
  63. package/cjs/lib/Socket/business.js +402 -0
  64. package/cjs/lib/Socket/chats.d.ts +144 -0
  65. package/cjs/lib/Socket/chats.js +1118 -0
  66. package/cjs/lib/Socket/communities.d.ts +554 -0
  67. package/cjs/lib/Socket/communities.js +456 -0
  68. package/cjs/lib/Socket/groups.d.ts +286 -0
  69. package/cjs/lib/Socket/groups.js +366 -0
  70. package/cjs/lib/Socket/index.d.ts +522 -0
  71. package/cjs/lib/Socket/index.js +32 -0
  72. package/cjs/lib/Socket/messages-recv.d.ts +326 -0
  73. package/cjs/lib/Socket/messages-recv.js +1670 -0
  74. package/cjs/lib/Socket/messages-send.d.ts +321 -0
  75. package/cjs/lib/Socket/messages-send.js +1252 -0
  76. package/cjs/lib/Socket/mex.d.ts +1 -0
  77. package/cjs/lib/Socket/mex.js +65 -0
  78. package/cjs/lib/Socket/newsletter.d.ts +283 -0
  79. package/cjs/lib/Socket/newsletter.js +243 -0
  80. package/cjs/lib/Socket/socket.d.ts +61 -0
  81. package/cjs/lib/Socket/socket.js +908 -0
  82. package/cjs/lib/Store/index.d.ts +3 -0
  83. package/cjs/lib/Store/index.js +25 -0
  84. package/cjs/lib/Store/make-in-memory-store.d.ts +63 -0
  85. package/cjs/lib/Store/make-in-memory-store.js +431 -0
  86. package/cjs/lib/Store/make-ordered-dictionary.d.ts +12 -0
  87. package/cjs/lib/Store/make-ordered-dictionary.js +101 -0
  88. package/cjs/lib/Store/object-repository.d.ts +10 -0
  89. package/cjs/lib/Store/object-repository.js +49 -0
  90. package/cjs/lib/Transport/crypto.d.ts +6 -0
  91. package/cjs/lib/Transport/crypto.js +107 -0
  92. package/cjs/lib/Transport/curve.d.ts +8 -0
  93. package/cjs/lib/Transport/curve.js +94 -0
  94. package/cjs/lib/Transport/index.d.ts +16 -0
  95. package/cjs/lib/Transport/index.js +67 -0
  96. package/cjs/lib/Transport/internals.d.ts +57 -0
  97. package/cjs/lib/Transport/internals.js +203 -0
  98. package/cjs/lib/Transport/session-builder.d.ts +40 -0
  99. package/cjs/lib/Transport/session-builder.js +169 -0
  100. package/cjs/lib/Transport/session-cipher.d.ts +26 -0
  101. package/cjs/lib/Transport/session-cipher.js +328 -0
  102. package/cjs/lib/Transport/session-record.d.ts +55 -0
  103. package/cjs/lib/Transport/session-record.js +289 -0
  104. package/cjs/lib/Types/Auth.d.ts +1 -0
  105. package/cjs/lib/Types/Auth.js +15 -0
  106. package/cjs/lib/Types/Bussines.d.ts +1 -0
  107. package/cjs/lib/Types/Bussines.js +15 -0
  108. package/cjs/lib/Types/Call.d.ts +1 -0
  109. package/cjs/lib/Types/Call.js +15 -0
  110. package/cjs/lib/Types/Chat.d.ts +1 -0
  111. package/cjs/lib/Types/Chat.js +33 -0
  112. package/cjs/lib/Types/Contact.d.ts +1 -0
  113. package/cjs/lib/Types/Contact.js +15 -0
  114. package/cjs/lib/Types/Events.d.ts +1 -0
  115. package/cjs/lib/Types/Events.js +1 -0
  116. package/cjs/lib/Types/GroupMetadata.d.ts +1 -0
  117. package/cjs/lib/Types/GroupMetadata.js +15 -0
  118. package/cjs/lib/Types/Label.d.ts +2 -0
  119. package/cjs/lib/Types/Label.js +49 -0
  120. package/cjs/lib/Types/LabelAssociation.d.ts +2 -0
  121. package/cjs/lib/Types/LabelAssociation.js +31 -0
  122. package/cjs/lib/Types/Message.d.ts +11 -0
  123. package/cjs/lib/Types/Message.js +58 -0
  124. package/cjs/lib/Types/Mex.d.ts +2 -0
  125. package/cjs/lib/Types/Mex.js +66 -0
  126. package/cjs/lib/Types/Product.d.ts +1 -0
  127. package/cjs/lib/Types/Product.js +15 -0
  128. package/cjs/lib/Types/RichType.d.ts +2 -0
  129. package/cjs/lib/Types/RichType.js +50 -0
  130. package/cjs/lib/Types/Signal.d.ts +1 -0
  131. package/cjs/lib/Types/Signal.js +1 -0
  132. package/cjs/lib/Types/Socket.d.ts +1 -0
  133. package/cjs/lib/Types/Socket.js +1 -0
  134. package/cjs/lib/Types/State.d.ts +5 -0
  135. package/cjs/lib/Types/State.js +83 -0
  136. package/cjs/lib/Types/USync.d.ts +1 -0
  137. package/cjs/lib/Types/USync.js +1 -0
  138. package/cjs/lib/Types/index.d.ts +13 -0
  139. package/cjs/lib/Types/index.js +64 -0
  140. package/cjs/lib/Utils/auth-utils.d.ts +58 -0
  141. package/cjs/lib/Utils/auth-utils.js +275 -0
  142. package/cjs/lib/Utils/browser-utils.d.ts +9 -0
  143. package/cjs/lib/Utils/browser-utils.js +56 -0
  144. package/cjs/lib/Utils/business.d.ts +49 -0
  145. package/cjs/lib/Utils/business.js +259 -0
  146. package/cjs/lib/Utils/chat-utils.d.ts +408 -0
  147. package/cjs/lib/Utils/chat-utils.js +821 -0
  148. package/cjs/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  149. package/cjs/lib/Utils/companion-reg-client-utils.js +71 -0
  150. package/cjs/lib/Utils/crypto.d.ts +39 -0
  151. package/cjs/lib/Utils/crypto.js +155 -0
  152. package/cjs/lib/Utils/decode-wa-message.d.ts +83 -0
  153. package/cjs/lib/Utils/decode-wa-message.js +316 -0
  154. package/cjs/lib/Utils/event-buffer.d.ts +12 -0
  155. package/cjs/lib/Utils/event-buffer.js +605 -0
  156. package/cjs/lib/Utils/generics.d.ts +63 -0
  157. package/cjs/lib/Utils/generics.js +440 -0
  158. package/cjs/lib/Utils/history.d.ts +75 -0
  159. package/cjs/lib/Utils/history.js +153 -0
  160. package/cjs/lib/Utils/identity-change-handler.d.ts +13 -0
  161. package/cjs/lib/Utils/identity-change-handler.js +73 -0
  162. package/cjs/lib/Utils/index.d.ts +24 -0
  163. package/cjs/lib/Utils/index.js +67 -0
  164. package/cjs/lib/Utils/link-preview.d.ts +13 -0
  165. package/cjs/lib/Utils/link-preview.js +87 -0
  166. package/cjs/lib/Utils/logger.d.ts +12 -0
  167. package/cjs/lib/Utils/logger.js +40 -0
  168. package/cjs/lib/Utils/lt-hash.d.ts +6 -0
  169. package/cjs/lib/Utils/lt-hash.js +28 -0
  170. package/cjs/lib/Utils/make-mutex.d.ts +6 -0
  171. package/cjs/lib/Utils/make-mutex.js +58 -0
  172. package/cjs/lib/Utils/message-retry-manager.d.ts +79 -0
  173. package/cjs/lib/Utils/message-retry-manager.js +274 -0
  174. package/cjs/lib/Utils/messages-media.d.ts +134 -0
  175. package/cjs/lib/Utils/messages-media.js +799 -0
  176. package/cjs/lib/Utils/messages.d.ts +47 -0
  177. package/cjs/lib/Utils/messages.js +1667 -0
  178. package/cjs/lib/Utils/noise-handler.d.ts +20 -0
  179. package/cjs/lib/Utils/noise-handler.js +223 -0
  180. package/cjs/lib/Utils/offline-node-processor.d.ts +10 -0
  181. package/cjs/lib/Utils/offline-node-processor.js +60 -0
  182. package/cjs/lib/Utils/pre-key-manager.d.ts +25 -0
  183. package/cjs/lib/Utils/pre-key-manager.js +116 -0
  184. package/cjs/lib/Utils/process-message.d.ts +83 -0
  185. package/cjs/lib/Utils/process-message.js +607 -0
  186. package/cjs/lib/Utils/reporting-utils.d.ts +12 -0
  187. package/cjs/lib/Utils/reporting-utils.js +282 -0
  188. package/cjs/lib/Utils/rich-message-utils.d.ts +48 -0
  189. package/cjs/lib/Utils/rich-message-utils.js +381 -0
  190. package/cjs/lib/Utils/signal.d.ts +82 -0
  191. package/cjs/lib/Utils/signal.js +232 -0
  192. package/cjs/lib/Utils/stanza-ack.d.ts +16 -0
  193. package/cjs/lib/Utils/stanza-ack.js +53 -0
  194. package/cjs/lib/Utils/sync-action-utils.d.ts +2 -0
  195. package/cjs/lib/Utils/sync-action-utils.js +68 -0
  196. package/cjs/lib/Utils/tc-token-utils.d.ts +29 -0
  197. package/cjs/lib/Utils/tc-token-utils.js +182 -0
  198. package/cjs/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  199. package/cjs/lib/Utils/use-multi-file-auth-state.js +135 -0
  200. package/cjs/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  201. package/cjs/lib/Utils/use-single-file-auth-state.js +115 -0
  202. package/cjs/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  203. package/cjs/lib/Utils/use-sqlite-auth-state.js +140 -0
  204. package/cjs/lib/Utils/validate-connection.d.ts +44 -0
  205. package/cjs/lib/Utils/validate-connection.js +229 -0
  206. package/cjs/lib/WABinary/constants.d.ts +61 -0
  207. package/cjs/lib/WABinary/constants.js +1992 -0
  208. package/cjs/lib/WABinary/decode.d.ts +9 -0
  209. package/cjs/lib/WABinary/decode.js +292 -0
  210. package/cjs/lib/WABinary/encode.d.ts +2 -0
  211. package/cjs/lib/WABinary/encode.js +240 -0
  212. package/cjs/lib/WABinary/generic-utils.d.ts +79 -0
  213. package/cjs/lib/WABinary/generic-utils.js +252 -0
  214. package/cjs/lib/WABinary/index.d.ts +5 -0
  215. package/cjs/lib/WABinary/index.js +29 -0
  216. package/cjs/lib/WABinary/jid-utils.d.ts +28 -0
  217. package/cjs/lib/WABinary/jid-utils.js +151 -0
  218. package/cjs/lib/WABinary/types.d.ts +1 -0
  219. package/cjs/lib/WABinary/types.js +23 -0
  220. package/cjs/lib/WACrypto/appstate-keys.js +39 -0
  221. package/cjs/lib/WACrypto/curves/constants.js +37 -0
  222. package/cjs/lib/WACrypto/hkdf.js +38 -0
  223. package/cjs/lib/WACrypto/index.js +51 -0
  224. package/cjs/lib/WACrypto/lthash.js +59 -0
  225. package/cjs/lib/WACrypto/math/constants.js +53 -0
  226. package/cjs/lib/WACrypto/math/edwards.js +206 -0
  227. package/cjs/lib/WACrypto/math/fe.js +449 -0
  228. package/cjs/lib/WACrypto/math/le.js +44 -0
  229. package/cjs/lib/WACrypto/math/mod.js +36 -0
  230. package/cjs/lib/WACrypto/util/bytes.js +348 -0
  231. package/cjs/lib/WACrypto/x25519.js +157 -0
  232. package/cjs/lib/WACrypto/xeddsa.js +134 -0
  233. package/cjs/lib/WAM/BinaryInfo.d.ts +7 -0
  234. package/cjs/lib/WAM/BinaryInfo.js +35 -0
  235. package/cjs/lib/WAM/constants.d.ts +34926 -0
  236. package/cjs/lib/WAM/constants.js +22890 -0
  237. package/cjs/lib/WAM/encode.d.ts +1 -0
  238. package/cjs/lib/WAM/encode.js +162 -0
  239. package/cjs/lib/WAM/index.d.ts +3 -0
  240. package/cjs/lib/WAM/index.js +25 -0
  241. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  242. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +77 -0
  243. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  244. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +76 -0
  245. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  246. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +52 -0
  247. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  248. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +61 -0
  249. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  250. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +50 -0
  251. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  252. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +76 -0
  253. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  254. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +53 -0
  255. package/cjs/lib/WAUSync/Protocols/index.d.ts +5 -0
  256. package/cjs/lib/WAUSync/Protocols/index.js +29 -0
  257. package/cjs/lib/WAUSync/USyncQuery.d.ts +20 -0
  258. package/cjs/lib/WAUSync/USyncQuery.js +113 -0
  259. package/cjs/lib/WAUSync/USyncUser.d.ts +16 -0
  260. package/cjs/lib/WAUSync/USyncUser.js +56 -0
  261. package/cjs/lib/WAUSync/index.d.ts +3 -0
  262. package/cjs/lib/WAUSync/index.js +25 -0
  263. package/cjs/lib/index.d.ts +11 -0
  264. package/cjs/lib/index.js +56 -0
  265. package/cjs/package.json +3 -0
  266. package/engine-requirements.js +12 -0
  267. package/lib/Addon/cache.js +201 -0
  268. package/lib/Addon/crc32.js +21 -0
  269. package/lib/Addon/file-type.js +198 -0
  270. package/lib/Addon/get-file.js +98 -0
  271. package/lib/Addon/http-error.d.ts +18 -0
  272. package/lib/Addon/http-error.js +40 -0
  273. package/lib/Addon/index.d.ts +96 -0
  274. package/lib/Addon/index.js +26 -0
  275. package/lib/Addon/keyed-db.d.ts +14 -0
  276. package/lib/Addon/keyed-db.js +241 -0
  277. package/lib/Addon/link-preview.d.ts +15 -0
  278. package/lib/Addon/link-preview.js +79 -0
  279. package/lib/Addon/media-info.js +96 -0
  280. package/lib/Addon/mutex.js +76 -0
  281. package/lib/Addon/qr.js +531 -0
  282. package/lib/Addon/queue.js +44 -0
  283. package/lib/Addon/waveform.js +135 -0
  284. package/lib/Addon/zip.js +144 -0
  285. package/lib/Defaults/index.d.ts +184 -0
  286. package/lib/Defaults/index.js +181 -0
  287. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  288. package/lib/Signal/Group/ciphertext-message.js +11 -0
  289. package/lib/Signal/Group/group-cipher.d.ts +10 -0
  290. package/lib/Signal/Group/group-cipher.js +81 -0
  291. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  292. package/lib/Signal/Group/group-session-builder.js +29 -0
  293. package/lib/Signal/Group/index.d.ts +11 -0
  294. package/lib/Signal/Group/index.js +11 -0
  295. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  296. package/lib/Signal/Group/keyhelper.js +17 -0
  297. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  298. package/lib/Signal/Group/sender-chain-key.js +25 -0
  299. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  300. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  301. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  302. package/lib/Signal/Group/sender-key-message.js +65 -0
  303. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  304. package/lib/Signal/Group/sender-key-name.js +47 -0
  305. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  306. package/lib/Signal/Group/sender-key-record.js +40 -0
  307. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  308. package/lib/Signal/Group/sender-key-state.js +83 -0
  309. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  310. package/lib/Signal/Group/sender-message-key.js +25 -0
  311. package/lib/Signal/libsignal.d.ts +54 -0
  312. package/lib/Signal/libsignal.js +426 -0
  313. package/lib/Signal/lid-mapping.d.ts +20 -0
  314. package/lib/Signal/lid-mapping.js +274 -0
  315. package/lib/Socket/Client/index.d.ts +2 -0
  316. package/lib/Socket/Client/index.js +2 -0
  317. package/lib/Socket/Client/types.d.ts +5 -0
  318. package/lib/Socket/Client/types.js +10 -0
  319. package/lib/Socket/Client/websocket.d.ts +12 -0
  320. package/lib/Socket/Client/websocket.js +119 -0
  321. package/lib/Socket/business.d.ts +387 -0
  322. package/lib/Socket/business.js +379 -0
  323. package/lib/Socket/chats.d.ts +144 -0
  324. package/lib/Socket/chats.js +1216 -0
  325. package/lib/Socket/communities.d.ts +554 -0
  326. package/lib/Socket/communities.js +431 -0
  327. package/lib/Socket/groups.d.ts +286 -0
  328. package/lib/Socket/groups.js +347 -0
  329. package/lib/Socket/index.d.ts +522 -0
  330. package/lib/Socket/index.js +11 -0
  331. package/lib/Socket/messages-recv.d.ts +326 -0
  332. package/lib/Socket/messages-recv.js +1822 -0
  333. package/lib/Socket/messages-send.d.ts +321 -0
  334. package/lib/Socket/messages-send.js +1378 -0
  335. package/lib/Socket/mex.d.ts +1 -0
  336. package/lib/Socket/mex.js +41 -0
  337. package/lib/Socket/newsletter.d.ts +283 -0
  338. package/lib/Socket/newsletter.js +225 -0
  339. package/lib/Socket/socket.d.ts +61 -0
  340. package/lib/Socket/socket.js +992 -0
  341. package/lib/Store/index.d.ts +3 -0
  342. package/lib/Store/index.js +3 -0
  343. package/lib/Store/make-in-memory-store.d.ts +63 -0
  344. package/lib/Store/make-in-memory-store.js +419 -0
  345. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  346. package/lib/Store/make-ordered-dictionary.js +78 -0
  347. package/lib/Store/object-repository.d.ts +10 -0
  348. package/lib/Store/object-repository.js +23 -0
  349. package/lib/Transport/crypto.d.ts +6 -0
  350. package/lib/Transport/crypto.js +61 -0
  351. package/lib/Transport/curve.d.ts +8 -0
  352. package/lib/Transport/curve.js +66 -0
  353. package/lib/Transport/index.d.ts +16 -0
  354. package/lib/Transport/index.js +9 -0
  355. package/lib/Transport/internals.d.ts +57 -0
  356. package/lib/Transport/internals.js +155 -0
  357. package/lib/Transport/session-builder.d.ts +40 -0
  358. package/lib/Transport/session-builder.js +143 -0
  359. package/lib/Transport/session-cipher.d.ts +26 -0
  360. package/lib/Transport/session-cipher.js +301 -0
  361. package/lib/Transport/session-record.d.ts +55 -0
  362. package/lib/Transport/session-record.js +272 -0
  363. package/lib/Types/Auth.d.ts +1 -0
  364. package/lib/Types/Auth.js +1 -0
  365. package/lib/Types/Bussines.d.ts +1 -0
  366. package/lib/Types/Bussines.js +1 -0
  367. package/lib/Types/Call.d.ts +1 -0
  368. package/lib/Types/Call.js +1 -0
  369. package/lib/Types/Chat.d.ts +1 -0
  370. package/lib/Types/Chat.js +7 -0
  371. package/lib/Types/Contact.d.ts +1 -0
  372. package/lib/Types/Contact.js +1 -0
  373. package/lib/Types/Events.d.ts +1 -0
  374. package/lib/Types/Events.js +1 -0
  375. package/lib/Types/GroupMetadata.d.ts +1 -0
  376. package/lib/Types/GroupMetadata.js +1 -0
  377. package/lib/Types/Label.d.ts +2 -0
  378. package/lib/Types/Label.js +24 -0
  379. package/lib/Types/LabelAssociation.d.ts +2 -0
  380. package/lib/Types/LabelAssociation.js +6 -0
  381. package/lib/Types/Message.d.ts +11 -0
  382. package/lib/Types/Message.js +17 -0
  383. package/lib/Types/Mex.d.ts +2 -0
  384. package/lib/Types/Mex.js +38 -0
  385. package/lib/Types/Product.d.ts +1 -0
  386. package/lib/Types/Product.js +1 -0
  387. package/lib/Types/RichType.d.ts +2 -0
  388. package/lib/Types/RichType.js +22 -0
  389. package/lib/Types/Signal.d.ts +1 -0
  390. package/lib/Types/Signal.js +1 -0
  391. package/lib/Types/Socket.d.ts +1 -0
  392. package/lib/Types/Socket.js +1 -0
  393. package/lib/Types/State.d.ts +5 -0
  394. package/lib/Types/State.js +54 -0
  395. package/lib/Types/USync.d.ts +1 -0
  396. package/lib/Types/USync.js +1 -0
  397. package/lib/Types/index.d.ts +13 -0
  398. package/lib/Types/index.js +25 -0
  399. package/lib/Utils/auth-utils.d.ts +58 -0
  400. package/lib/Utils/auth-utils.js +316 -0
  401. package/lib/Utils/browser-utils.d.ts +9 -0
  402. package/lib/Utils/browser-utils.js +28 -0
  403. package/lib/Utils/business.d.ts +49 -0
  404. package/lib/Utils/business.js +230 -0
  405. package/lib/Utils/chat-utils.d.ts +408 -0
  406. package/lib/Utils/chat-utils.js +871 -0
  407. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  408. package/lib/Utils/companion-reg-client-utils.js +39 -0
  409. package/lib/Utils/crypto.d.ts +39 -0
  410. package/lib/Utils/crypto.js +117 -0
  411. package/lib/Utils/decode-wa-message.d.ts +83 -0
  412. package/lib/Utils/decode-wa-message.js +316 -0
  413. package/lib/Utils/event-buffer.d.ts +12 -0
  414. package/lib/Utils/event-buffer.js +621 -0
  415. package/lib/Utils/generics.d.ts +63 -0
  416. package/lib/Utils/generics.js +394 -0
  417. package/lib/Utils/history.d.ts +75 -0
  418. package/lib/Utils/history.js +133 -0
  419. package/lib/Utils/identity-change-handler.d.ts +13 -0
  420. package/lib/Utils/identity-change-handler.js +48 -0
  421. package/lib/Utils/index.d.ts +24 -0
  422. package/lib/Utils/index.js +24 -0
  423. package/lib/Utils/link-preview.d.ts +13 -0
  424. package/lib/Utils/link-preview.js +73 -0
  425. package/lib/Utils/logger.d.ts +12 -0
  426. package/lib/Utils/logger.js +12 -0
  427. package/lib/Utils/lt-hash.d.ts +6 -0
  428. package/lib/Utils/lt-hash.js +7 -0
  429. package/lib/Utils/make-mutex.d.ts +6 -0
  430. package/lib/Utils/make-mutex.js +32 -0
  431. package/lib/Utils/message-retry-manager.d.ts +79 -0
  432. package/lib/Utils/message-retry-manager.js +259 -0
  433. package/lib/Utils/messages-media.d.ts +134 -0
  434. package/lib/Utils/messages-media.js +802 -0
  435. package/lib/Utils/messages.d.ts +47 -0
  436. package/lib/Utils/messages.js +1907 -0
  437. package/lib/Utils/noise-handler.d.ts +20 -0
  438. package/lib/Utils/noise-handler.js +200 -0
  439. package/lib/Utils/offline-node-processor.d.ts +10 -0
  440. package/lib/Utils/offline-node-processor.js +40 -0
  441. package/lib/Utils/pre-key-manager.d.ts +25 -0
  442. package/lib/Utils/pre-key-manager.js +105 -0
  443. package/lib/Utils/process-message.d.ts +83 -0
  444. package/lib/Utils/process-message.js +748 -0
  445. package/lib/Utils/reporting-utils.d.ts +12 -0
  446. package/lib/Utils/reporting-utils.js +257 -0
  447. package/lib/Utils/rich-message-utils.d.ts +48 -0
  448. package/lib/Utils/rich-message-utils.js +366 -0
  449. package/lib/Utils/signal.d.ts +82 -0
  450. package/lib/Utils/signal.js +200 -0
  451. package/lib/Utils/stanza-ack.d.ts +16 -0
  452. package/lib/Utils/stanza-ack.js +37 -0
  453. package/lib/Utils/sync-action-utils.d.ts +2 -0
  454. package/lib/Utils/sync-action-utils.js +48 -0
  455. package/lib/Utils/tc-token-utils.d.ts +29 -0
  456. package/lib/Utils/tc-token-utils.js +163 -0
  457. package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  458. package/lib/Utils/use-multi-file-auth-state.js +116 -0
  459. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  460. package/lib/Utils/use-single-file-auth-state.js +94 -0
  461. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  462. package/lib/Utils/use-sqlite-auth-state.js +109 -0
  463. package/lib/Utils/validate-connection.d.ts +44 -0
  464. package/lib/Utils/validate-connection.js +210 -0
  465. package/lib/WABinary/constants.d.ts +61 -0
  466. package/lib/WABinary/constants.js +1466 -0
  467. package/lib/WABinary/decode.d.ts +9 -0
  468. package/lib/WABinary/decode.js +261 -0
  469. package/lib/WABinary/encode.d.ts +2 -0
  470. package/lib/WABinary/encode.js +219 -0
  471. package/lib/WABinary/generic-utils.d.ts +79 -0
  472. package/lib/WABinary/generic-utils.js +226 -0
  473. package/lib/WABinary/index.d.ts +5 -0
  474. package/lib/WABinary/index.js +5 -0
  475. package/lib/WABinary/jid-utils.d.ts +28 -0
  476. package/lib/WABinary/jid-utils.js +95 -0
  477. package/lib/WABinary/types.d.ts +1 -0
  478. package/lib/WABinary/types.js +1 -0
  479. package/lib/WACrypto/appstate-keys.js +26 -0
  480. package/lib/WACrypto/curves/constants.js +12 -0
  481. package/lib/WACrypto/hkdf.js +27 -0
  482. package/lib/WACrypto/index.js +20 -0
  483. package/lib/WACrypto/lthash.js +54 -0
  484. package/lib/WACrypto/math/constants.js +24 -0
  485. package/lib/WACrypto/math/edwards.js +194 -0
  486. package/lib/WACrypto/math/fe.js +698 -0
  487. package/lib/WACrypto/math/le.js +23 -0
  488. package/lib/WACrypto/math/mod.js +15 -0
  489. package/lib/WACrypto/util/bytes.js +339 -0
  490. package/lib/WACrypto/x25519.js +145 -0
  491. package/lib/WACrypto/xeddsa.js +92 -0
  492. package/lib/WAM/BinaryInfo.d.ts +7 -0
  493. package/lib/WAM/BinaryInfo.js +9 -0
  494. package/lib/WAM/constants.d.ts +34926 -0
  495. package/lib/WAM/constants.js +22852 -0
  496. package/lib/WAM/encode.d.ts +1 -0
  497. package/lib/WAM/encode.js +149 -0
  498. package/lib/WAM/index.d.ts +3 -0
  499. package/lib/WAM/index.js +3 -0
  500. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  501. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  502. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  503. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  504. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  505. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  506. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  507. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  508. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  509. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  510. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  511. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  512. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  513. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  514. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  515. package/lib/WAUSync/Protocols/index.js +5 -0
  516. package/lib/WAUSync/USyncQuery.d.ts +20 -0
  517. package/lib/WAUSync/USyncQuery.js +97 -0
  518. package/lib/WAUSync/USyncUser.d.ts +16 -0
  519. package/lib/WAUSync/USyncUser.js +30 -0
  520. package/lib/WAUSync/index.d.ts +3 -0
  521. package/lib/WAUSync/index.js +3 -0
  522. package/lib/index.d.ts +11 -0
  523. package/lib/index.js +11 -0
  524. package/package.json +74 -5
  525. package/tests/addon-test.mjs +162 -0
  526. package/tests/differential-test.mjs +90 -0
@@ -0,0 +1,24 @@
1
+ export * from './generics.js';
2
+ export * from './decode-wa-message.js';
3
+ export * from './messages.js';
4
+ export * from './messages-media.js';
5
+ export * from './validate-connection.js';
6
+ export * from './crypto.js';
7
+ export * from './signal.js';
8
+ export * from './noise-handler.js';
9
+ export * from './history.js';
10
+ export * from './chat-utils.js';
11
+ export * from './lt-hash.js';
12
+ export * from './auth-utils.js';
13
+ export * from './use-multi-file-auth-state.js';
14
+ export * from './use-single-file-auth-state.js';
15
+ export * from './use-sqlite-auth-state.js';
16
+ export * from './link-preview.js';
17
+ export * from './event-buffer.js';
18
+ export * from './process-message.js';
19
+ export * from './rich-message-utils.js';
20
+ export * from './message-retry-manager.js';
21
+ export * from './browser-utils.js';
22
+ export * from './companion-reg-client-utils.js';
23
+ export * from './identity-change-handler.js';
24
+ export * from './stanza-ack.js';
@@ -0,0 +1,13 @@
1
+ export function getUrlInfo(text: any, opts?: {
2
+ thumbnailWidth: number;
3
+ fetchOpts: {
4
+ timeout: number;
5
+ };
6
+ }): Promise<{
7
+ 'canonical-url': string;
8
+ 'matched-text': any;
9
+ title: any;
10
+ description: any;
11
+ originalThumbnailUrl: any;
12
+ 'preview-type': number;
13
+ } | undefined>;
@@ -0,0 +1,73 @@
1
+ import { getLinkPreview } from '../Addon/index.js';
2
+ import { prepareWAMessageMedia } from './messages.js';
3
+ import { extractImageThumb, getHttpStream } from './messages-media.js';
4
+ const URL_PROTOCOL_REGEX = /^https?:\/\//;
5
+ const THUMBNAIL_WIDTH_PX = 192;
6
+ /** Fetches an image and generates a thumbnail for it */
7
+ const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
8
+ const stream = await getHttpStream(url, fetchOpts);
9
+ const result = await extractImageThumb(stream, thumbnailWidth);
10
+ return result;
11
+ };
12
+ /**
13
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
14
+ * Return undefined if the fetch failed or no URL was found
15
+ * @param text first matched URL in text
16
+ * @returns the URL info required to generate link preview
17
+ */
18
+ export const getUrlInfo = async (text, opts = {
19
+ thumbnailWidth: THUMBNAIL_WIDTH_PX,
20
+ fetchOpts: { timeout: 3000 }
21
+ }) => {
22
+ try {
23
+ const previewLink = URL_PROTOCOL_REGEX.test(text) ? text : 'https://' + text;
24
+ const info = await getLinkPreview(previewLink, opts.fetchOpts.timeout);
25
+ if (info?.title) {
26
+ const urlInfo = {
27
+ 'canonical-url': info.url,
28
+ 'matched-text': text,
29
+ title: info.title,
30
+ description: info.description,
31
+ originalThumbnailUrl: info.image,
32
+ 'preview-type': info.video ? 1 : 0
33
+ };
34
+ if (opts.uploadImage) {
35
+ await Promise.all([
36
+ (async () => {
37
+ const { imageMessage } = await prepareWAMessageMedia({ image: { url: info.image } }, {
38
+ upload: opts.uploadImage,
39
+ mediaTypeOverride: 'thumbnail-link',
40
+ options: opts.fetchOpts
41
+ });
42
+ urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
43
+ urlInfo.highQualityThumbnail = imageMessage;
44
+ })(),
45
+ info.favicon
46
+ ? (async () => {
47
+ const { imageMessage } = await prepareWAMessageMedia({ image: { url: info.favicon } }, {
48
+ upload: opts.uploadImage,
49
+ mediaTypeOverride: 'thumbnail-link',
50
+ options: opts.fetchOpts
51
+ });
52
+ urlInfo.favicon = imageMessage;
53
+ })()
54
+ : Promise.resolve()
55
+ ]);
56
+ }
57
+ else {
58
+ try {
59
+ urlInfo.jpegThumbnail = info.image ? (await getCompressedJpegThumbnail(info.image, opts)).buffer : undefined;
60
+ }
61
+ catch (error) {
62
+ opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
63
+ }
64
+ }
65
+ return urlInfo;
66
+ }
67
+ }
68
+ catch (error) {
69
+ if (!error.message.includes('receive a valid')) {
70
+ throw error;
71
+ }
72
+ }
73
+ };
@@ -0,0 +1,12 @@
1
+ export default SILENT_LOGGER;
2
+ declare const SILENT_LOGGER: Readonly<{
3
+ level: "silent";
4
+ debug: () => void;
5
+ info: () => void;
6
+ warn: () => void;
7
+ error: () => void;
8
+ fatal: () => void;
9
+ trace: () => void;
10
+ child: () => Readonly</*elided*/ any>;
11
+ isLevelEnabled: () => false;
12
+ }>;
@@ -0,0 +1,12 @@
1
+ const SILENT_LOGGER = Object.freeze({
2
+ level: 'silent',
3
+ debug: () => { },
4
+ info: () => { },
5
+ warn: () => { },
6
+ error: () => { },
7
+ fatal: () => { },
8
+ trace: () => { },
9
+ child: () => SILENT_LOGGER,
10
+ isLevelEnabled: () => false
11
+ });
12
+ export default SILENT_LOGGER;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
3
+ * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
4
+ * if the same series of mutations was made sequentially.
5
+ */
6
+ export const LT_HASH_ANTI_TAMPERING: any;
@@ -0,0 +1,7 @@
1
+ import { LTHashAntiTampering } from '../WACrypto/index.js';
2
+ /**
3
+ * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
4
+ * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
5
+ * if the same series of mutations was made sequentially.
6
+ */
7
+ export const LT_HASH_ANTI_TAMPERING = new LTHashAntiTampering();
@@ -0,0 +1,6 @@
1
+ export function makeMutex(): {
2
+ mutex(code: any): any;
3
+ };
4
+ export function makeKeyedMutex(): {
5
+ mutex(key: any, task: any): Promise<any>;
6
+ };
@@ -0,0 +1,32 @@
1
+ import { createMutex } from '../Addon/index.js';
2
+ export const makeMutex = () => {
3
+ const mutex = createMutex();
4
+ return {
5
+ mutex(code) {
6
+ return mutex.runExclusive(code);
7
+ }
8
+ };
9
+ };
10
+ export const makeKeyedMutex = () => {
11
+ const map = new Map();
12
+ return {
13
+ async mutex(key, task) {
14
+ let entry = map.get(key);
15
+ if (!entry) {
16
+ entry = { mutex: createMutex(), refCount: 0 };
17
+ map.set(key, entry);
18
+ }
19
+ entry.refCount++;
20
+ try {
21
+ return await entry.mutex.runExclusive(task);
22
+ }
23
+ finally {
24
+ entry.refCount--;
25
+ // only delete it if this is still the current entry
26
+ if (entry.refCount === 0 && map.get(key) === entry) {
27
+ map.delete(key);
28
+ }
29
+ }
30
+ }
31
+ };
32
+ };
@@ -0,0 +1,79 @@
1
+ export const RetryReason: any;
2
+ export class MessageRetryManager {
3
+ constructor(logger: any, maxMsgRetryCount: any);
4
+ logger: any;
5
+ recentMessagesMap: any;
6
+ messageKeyIndex: Map<any, any>;
7
+ sessionRecreateHistory: any;
8
+ retryCounters: any;
9
+ baseKeys: any;
10
+ pendingPhoneRequests: {};
11
+ maxMsgRetryCount: any;
12
+ statistics: {
13
+ totalRetries: number;
14
+ successfulRetries: number;
15
+ failedRetries: number;
16
+ mediaRetries: number;
17
+ sessionRecreations: number;
18
+ phoneRequests: number;
19
+ };
20
+ /**
21
+ * Add a recent message to the cache for retry handling
22
+ */
23
+ addRecentMessage(to: any, id: any, message: any): void;
24
+ /**
25
+ * Get a recent message from the cache
26
+ */
27
+ getRecentMessage(to: any, id: any): any;
28
+ /**
29
+ * Check if a session should be recreated based on retry count, history, and error code.
30
+ * MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
31
+ */
32
+ shouldRecreateSession(jid: any, hasSession: any, errorCode: any): {
33
+ reason: string;
34
+ recreate: boolean;
35
+ };
36
+ /**
37
+ * Parse error code from retry receipt's retry node.
38
+ * Returns undefined if no error code is present.
39
+ */
40
+ parseRetryErrorCode(errorAttr: any): any;
41
+ /**
42
+ * Check if an error code indicates a MAC failure
43
+ */
44
+ isMacError(errorCode: any): boolean;
45
+ /**
46
+ * Increment retry counter for a message
47
+ */
48
+ incrementRetryCount(messageId: any): any;
49
+ /**
50
+ * Get retry count for a message
51
+ */
52
+ getRetryCount(messageId: any): any;
53
+ /**
54
+ * Check if message has exceeded maximum retry attempts
55
+ */
56
+ hasExceededMaxRetries(messageId: any): boolean;
57
+ /**
58
+ * Mark retry as successful
59
+ */
60
+ markRetrySuccess(messageId: any): void;
61
+ /**
62
+ * Mark retry as failed
63
+ */
64
+ markRetryFailed(messageId: any): void;
65
+ /**
66
+ * Schedule a phone request with delay
67
+ */
68
+ schedulePhoneRequest(messageId: any, callback: any, delay?: number): void;
69
+ /**
70
+ * Cancel pending phone request
71
+ */
72
+ cancelPendingPhoneRequest(messageId: any): void;
73
+ clear(): void;
74
+ saveBaseKey(addr: any, msgId: any, baseKey: any): void;
75
+ hasSameBaseKey(addr: any, msgId: any, baseKey: any): boolean;
76
+ deleteBaseKey(addr: any, msgId: any): void;
77
+ keyToString(key: any): string;
78
+ removeRecentMessage(messageId: any): void;
79
+ }
@@ -0,0 +1,259 @@
1
+ import { createCache } from '../Addon/index.js';
2
+ /** Number of sent messages to cache in memory for handling retry receipts */
3
+ const RECENT_MESSAGES_SIZE = 1024;
4
+ const MESSAGE_KEY_SEPARATOR = '\u0000';
5
+ /** Timeout for session recreation - 1 hour */
6
+ const RECREATE_SESSION_TIMEOUT = 60 * 60; // 1 hour in milliseconds
7
+ const PHONE_REQUEST_DELAY = 3000;
8
+ // Retry reason codes matching WhatsApp Web's Signal error codes.
9
+ export var RetryReason;
10
+ (function (RetryReason) {
11
+ RetryReason[RetryReason["UnknownError"] = 0] = "UnknownError";
12
+ RetryReason[RetryReason["SignalErrorNoSession"] = 1] = "SignalErrorNoSession";
13
+ RetryReason[RetryReason["SignalErrorInvalidKey"] = 2] = "SignalErrorInvalidKey";
14
+ RetryReason[RetryReason["SignalErrorInvalidKeyId"] = 3] = "SignalErrorInvalidKeyId";
15
+ /** MAC verification failed - most common cause of decryption failures */
16
+ RetryReason[RetryReason["SignalErrorInvalidMessage"] = 4] = "SignalErrorInvalidMessage";
17
+ RetryReason[RetryReason["SignalErrorInvalidSignature"] = 5] = "SignalErrorInvalidSignature";
18
+ RetryReason[RetryReason["SignalErrorFutureMessage"] = 6] = "SignalErrorFutureMessage";
19
+ /** Explicit MAC failure - session is definitely out of sync */
20
+ RetryReason[RetryReason["SignalErrorBadMac"] = 7] = "SignalErrorBadMac";
21
+ RetryReason[RetryReason["SignalErrorInvalidSession"] = 8] = "SignalErrorInvalidSession";
22
+ RetryReason[RetryReason["SignalErrorInvalidMsgKey"] = 9] = "SignalErrorInvalidMsgKey";
23
+ RetryReason[RetryReason["BadBroadcastEphemeralSetting"] = 10] = "BadBroadcastEphemeralSetting";
24
+ RetryReason[RetryReason["UnknownCompanionNoPrekey"] = 11] = "UnknownCompanionNoPrekey";
25
+ RetryReason[RetryReason["AdvFailure"] = 12] = "AdvFailure";
26
+ RetryReason[RetryReason["StatusRevokeDelay"] = 13] = "StatusRevokeDelay";
27
+ })(RetryReason || (RetryReason = {}));
28
+ /** Error codes that indicate a MAC failure and require immediate session recreation */
29
+ const MAC_ERROR_CODES = new Set([RetryReason.SignalErrorInvalidMessage, RetryReason.SignalErrorBadMac]);
30
+ export class MessageRetryManager {
31
+ constructor(logger, maxMsgRetryCount) {
32
+ this.logger = logger;
33
+ this.recentMessagesMap = createCache({
34
+ max: RECENT_MESSAGES_SIZE,
35
+ ttl: 5 * 60,
36
+ dispose: (_value, key) => {
37
+ const separatorIndex = key.lastIndexOf(MESSAGE_KEY_SEPARATOR);
38
+ if (separatorIndex > -1) {
39
+ const messageId = key.slice(separatorIndex + MESSAGE_KEY_SEPARATOR.length);
40
+ this.messageKeyIndex.delete(messageId);
41
+ }
42
+ }
43
+ });
44
+ this.messageKeyIndex = new Map();
45
+ this.sessionRecreateHistory = createCache({
46
+ ttl: RECREATE_SESSION_TIMEOUT * 2
47
+ });
48
+ this.retryCounters = createCache({
49
+ ttl: 15 * 60
50
+ }); // 15 minutes TTL
51
+ this.baseKeys = createCache({
52
+ max: 1024,
53
+ ttl: 15 * 60
54
+ });
55
+ this.pendingPhoneRequests = {};
56
+ this.maxMsgRetryCount = 5;
57
+ this.statistics = {
58
+ totalRetries: 0,
59
+ successfulRetries: 0,
60
+ failedRetries: 0,
61
+ mediaRetries: 0,
62
+ sessionRecreations: 0,
63
+ phoneRequests: 0
64
+ };
65
+ this.maxMsgRetryCount = maxMsgRetryCount;
66
+ }
67
+ /**
68
+ * Add a recent message to the cache for retry handling
69
+ */
70
+ addRecentMessage(to, id, message) {
71
+ const key = { to, id };
72
+ const keyStr = this.keyToString(key);
73
+ // Add new message
74
+ this.recentMessagesMap.set(keyStr, {
75
+ message,
76
+ timestamp: Date.now()
77
+ });
78
+ this.messageKeyIndex.set(id, keyStr);
79
+ this.logger.debug(`Added message to retry cache: ${to}/${id}`);
80
+ }
81
+ /**
82
+ * Get a recent message from the cache
83
+ */
84
+ getRecentMessage(to, id) {
85
+ const key = { to, id };
86
+ const keyStr = this.keyToString(key);
87
+ return this.recentMessagesMap.get(keyStr);
88
+ }
89
+ /**
90
+ * Check if a session should be recreated based on retry count, history, and error code.
91
+ * MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
92
+ */
93
+ shouldRecreateSession(jid, hasSession, errorCode) {
94
+ // If we don't have a session, always recreate
95
+ if (!hasSession) {
96
+ this.sessionRecreateHistory.set(jid, Date.now());
97
+ this.statistics.sessionRecreations++;
98
+ return {
99
+ reason: "we don't have a Signal session with them",
100
+ recreate: true
101
+ };
102
+ }
103
+ // IMMEDIATE recreation for MAC errors - session is definitely out of sync
104
+ if (errorCode !== undefined && MAC_ERROR_CODES.has(errorCode)) {
105
+ this.sessionRecreateHistory.set(jid, Date.now());
106
+ this.statistics.sessionRecreations++;
107
+ this.logger.warn({ jid, errorCode: RetryReason[errorCode] }, 'MAC error detected, forcing immediate session recreation');
108
+ return {
109
+ reason: `MAC error (code ${errorCode}: ${RetryReason[errorCode]}), immediate session recreation`,
110
+ recreate: true
111
+ };
112
+ }
113
+ const now = Date.now();
114
+ const prevTime = this.sessionRecreateHistory.get(jid);
115
+ // If no previous recreation or it's been more than an hour
116
+ if (!prevTime || now - prevTime > RECREATE_SESSION_TIMEOUT) {
117
+ this.sessionRecreateHistory.set(jid, now);
118
+ this.statistics.sessionRecreations++;
119
+ return {
120
+ reason: 'retry count > 1 and over an hour since last recreation',
121
+ recreate: true
122
+ };
123
+ }
124
+ return { reason: '', recreate: false };
125
+ }
126
+ /**
127
+ * Parse error code from retry receipt's retry node.
128
+ * Returns undefined if no error code is present.
129
+ */
130
+ parseRetryErrorCode(errorAttr) {
131
+ if (errorAttr === undefined || errorAttr === '') {
132
+ return undefined;
133
+ }
134
+ const code = parseInt(errorAttr, 10);
135
+ if (Number.isNaN(code)) {
136
+ return undefined;
137
+ }
138
+ // Validate it's a known RetryReason
139
+ if (code >= RetryReason.UnknownError && code <= RetryReason.StatusRevokeDelay) {
140
+ return code;
141
+ }
142
+ return RetryReason.UnknownError;
143
+ }
144
+ /**
145
+ * Check if an error code indicates a MAC failure
146
+ */
147
+ isMacError(errorCode) {
148
+ return errorCode !== undefined && MAC_ERROR_CODES.has(errorCode);
149
+ }
150
+ /**
151
+ * Increment retry counter for a message
152
+ */
153
+ incrementRetryCount(messageId) {
154
+ this.retryCounters.set(messageId, (this.retryCounters.get(messageId) || 0) + 1);
155
+ this.statistics.totalRetries++;
156
+ return this.retryCounters.get(messageId);
157
+ }
158
+ /**
159
+ * Get retry count for a message
160
+ */
161
+ getRetryCount(messageId) {
162
+ return this.retryCounters.get(messageId) || 0;
163
+ }
164
+ /**
165
+ * Check if message has exceeded maximum retry attempts
166
+ */
167
+ hasExceededMaxRetries(messageId) {
168
+ return this.getRetryCount(messageId) >= this.maxMsgRetryCount;
169
+ }
170
+ /**
171
+ * Mark retry as successful
172
+ */
173
+ markRetrySuccess(messageId) {
174
+ this.statistics.successfulRetries++;
175
+ // Clean up retry counter for successful message
176
+ this.retryCounters.del(messageId);
177
+ this.cancelPendingPhoneRequest(messageId);
178
+ this.removeRecentMessage(messageId);
179
+ }
180
+ /**
181
+ * Mark retry as failed
182
+ */
183
+ markRetryFailed(messageId) {
184
+ this.statistics.failedRetries++;
185
+ this.retryCounters.del(messageId);
186
+ this.cancelPendingPhoneRequest(messageId);
187
+ this.removeRecentMessage(messageId);
188
+ }
189
+ /**
190
+ * Schedule a phone request with delay
191
+ */
192
+ schedulePhoneRequest(messageId, callback, delay = PHONE_REQUEST_DELAY) {
193
+ // Cancel any existing request for this message
194
+ this.cancelPendingPhoneRequest(messageId);
195
+ this.pendingPhoneRequests[messageId] = setTimeout(() => {
196
+ delete this.pendingPhoneRequests[messageId];
197
+ this.statistics.phoneRequests++;
198
+ callback();
199
+ }, delay);
200
+ this.logger.debug(`Scheduled phone request for message ${messageId} with ${delay}ms delay`);
201
+ }
202
+ /**
203
+ * Cancel pending phone request
204
+ */
205
+ cancelPendingPhoneRequest(messageId) {
206
+ const timeout = this.pendingPhoneRequests[messageId];
207
+ if (timeout) {
208
+ clearTimeout(timeout);
209
+ delete this.pendingPhoneRequests[messageId];
210
+ this.logger.debug(`Cancelled pending phone request for message ${messageId}`);
211
+ }
212
+ }
213
+ clear() {
214
+ this.recentMessagesMap.flushAll();
215
+ this.messageKeyIndex.clear();
216
+ this.sessionRecreateHistory.flushAll();
217
+ this.retryCounters.flushAll();
218
+ this.baseKeys.flushAll();
219
+ for (const messageId of Object.keys(this.pendingPhoneRequests)) {
220
+ this.cancelPendingPhoneRequest(messageId);
221
+ }
222
+ this.statistics = {
223
+ totalRetries: 0,
224
+ successfulRetries: 0,
225
+ failedRetries: 0,
226
+ mediaRetries: 0,
227
+ sessionRecreations: 0,
228
+ phoneRequests: 0
229
+ };
230
+ }
231
+ saveBaseKey(addr, msgId, baseKey) {
232
+ this.baseKeys.set(`${addr}:${msgId}`, baseKey);
233
+ }
234
+ hasSameBaseKey(addr, msgId, baseKey) {
235
+ const stored = this.baseKeys.get(`${addr}:${msgId}`);
236
+ if (!stored || stored.length !== baseKey.length) {
237
+ return false;
238
+ }
239
+ for (let i = 0; i < stored.length; i++) {
240
+ if (stored[i] !== baseKey[i])
241
+ return false;
242
+ }
243
+ return true;
244
+ }
245
+ deleteBaseKey(addr, msgId) {
246
+ this.baseKeys.del(`${addr}:${msgId}`);
247
+ }
248
+ keyToString(key) {
249
+ return `${key.to}${MESSAGE_KEY_SEPARATOR}${key.id}`;
250
+ }
251
+ removeRecentMessage(messageId) {
252
+ const keyStr = this.messageKeyIndex.get(messageId);
253
+ if (!keyStr) {
254
+ return;
255
+ }
256
+ this.recentMessagesMap.del(keyStr);
257
+ this.messageKeyIndex.delete(messageId);
258
+ }
259
+ }
@@ -0,0 +1,134 @@
1
+ /** generates all the keys required to encrypt/decrypt & sign a media message */
2
+ export function getMediaKeys(buffer: any, mediaType: any): Promise<{
3
+ iv: any;
4
+ cipherKey: any;
5
+ macKey: any;
6
+ }>;
7
+ export function getAudioData(buffer: any, logger: any): Promise<any>;
8
+ /** generates a thumbnail for a given media, if required */
9
+ export function generateThumbnail(file: any, mediaType: any, options: any): Promise<{
10
+ thumbnail: any;
11
+ originalImageDimensions: {
12
+ width: any;
13
+ height: any;
14
+ } | undefined;
15
+ }>;
16
+ export function extensionForMediaMessage(message: any): any;
17
+ export function getImageProcessingLibrary(): Promise<any>;
18
+ export function hkdfInfoKey(type: any): string;
19
+ export function getRawMediaUploadData(media: any, mediaType: any, logger: any): Promise<{
20
+ filePath: any;
21
+ fileSha256: any;
22
+ fileLength: number;
23
+ }>;
24
+ export function extractVideoThumb(path: any, time: any, size: any): Promise<any>;
25
+ export function extractImageThumb(bufferOrFilePath: any, width?: number): Promise<{
26
+ buffer: any;
27
+ original: {
28
+ width: any;
29
+ height: any;
30
+ };
31
+ }>;
32
+ export function encodeBase64EncodedStringForUpload(b64: any): string;
33
+ export function generateProfilePicture(mediaUpload: any, dimensions: any): Promise<{
34
+ img: any;
35
+ }>;
36
+ export function mediaMessageSHA256B64(message: any): any;
37
+ export function toReadable(buffer: any): any;
38
+ export function toBuffer(stream: any): Promise<any>;
39
+ export function getStream(item: any, opts: any): Promise<{
40
+ stream: any;
41
+ type: string;
42
+ }>;
43
+ export function getHttpStream(url: any, options?: {}): Promise<any>;
44
+ export function encryptedStream(media: any, mediaType: any, { logger, saveOriginalFileIfRequired, mediaKey, opts }?: {
45
+ mediaKey?: any;
46
+ }): Promise<{
47
+ mediaKey: any;
48
+ originalFilePath: any;
49
+ encFilePath: any;
50
+ mac: any;
51
+ fileEncSha256: any;
52
+ fileSha256: any;
53
+ fileLength: number;
54
+ }>;
55
+ export const DEF_MEDIA_HOST: "mmg.whatsapp.net";
56
+ export function getUrlFromDirectPath(directPath: any, host?: string): string;
57
+ export function downloadContentFromMessage({ mediaKey, directPath, url }: {
58
+ mediaKey: any;
59
+ directPath: any;
60
+ url: any;
61
+ }, type: any, opts?: {}): Promise<any>;
62
+ export function downloadEncryptedContent(downloadUrl: any, { cipherKey, iv }: {
63
+ cipherKey: any;
64
+ iv: any;
65
+ }, { startByte, endByte, options }?: {}): Promise<any>;
66
+ export function uploadWithNodeHttp({ url, filePath, headers, timeoutMs, agent }: {
67
+ url: any;
68
+ filePath: any;
69
+ headers: any;
70
+ timeoutMs: any;
71
+ agent: any;
72
+ }, redirectCount?: number): Promise<any>;
73
+ export function getWAUploadToServer({ customUploadHosts, fetchAgent, logger, options }: {
74
+ customUploadHosts: any;
75
+ fetchAgent: any;
76
+ logger: any;
77
+ options: any;
78
+ }, refreshMediaConn: any): (filePath: any, { mediaType, fileEncSha256B64, timeoutMs, newsletter }: {
79
+ mediaType: any;
80
+ fileEncSha256B64: any;
81
+ timeoutMs: any;
82
+ newsletter: any;
83
+ }) => Promise<{
84
+ mediaUrl: any;
85
+ directPath: any;
86
+ meta_hmac: any;
87
+ fbid: any;
88
+ ts: any;
89
+ thumbnailDirectPath: any;
90
+ thumbnailSha256: any;
91
+ }>;
92
+ export function encryptMediaRetryRequest(key: any, mediaKey: any, meId: any): {
93
+ tag: string;
94
+ attrs: {
95
+ id: any;
96
+ to: string;
97
+ type: string;
98
+ };
99
+ content: ({
100
+ tag: string;
101
+ attrs: {
102
+ jid?: undefined;
103
+ from_me?: undefined;
104
+ participant?: undefined;
105
+ };
106
+ content: {
107
+ tag: string;
108
+ attrs: {};
109
+ content: any;
110
+ }[];
111
+ } | {
112
+ tag: string;
113
+ attrs: {
114
+ jid: any;
115
+ from_me: string;
116
+ participant: any;
117
+ };
118
+ content?: undefined;
119
+ })[];
120
+ };
121
+ export function decodeMediaRetryNode(node: any): {
122
+ key: {
123
+ id: any;
124
+ remoteJid: any;
125
+ fromMe: boolean;
126
+ participant: any;
127
+ };
128
+ };
129
+ export function decryptMediaRetryData({ ciphertext, iv }: {
130
+ ciphertext: any;
131
+ iv: any;
132
+ }, mediaKey: any, msgId: any): proto.MediaRetryNotification & proto.MediaRetryNotification.$Properties;
133
+ export function getStatusCodeForMediaRetry(code: any): any;
134
+ import { proto } from '../../WAProto/index.js';