@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,3 @@
1
+ export * from "./make-in-memory-store.js";
2
+ export * from "./make-ordered-dictionary.js";
3
+ export * from "./object-repository.js";
@@ -0,0 +1,3 @@
1
+ export * from './make-in-memory-store.js';
2
+ export * from './make-ordered-dictionary.js';
3
+ export * from './object-repository.js';
@@ -0,0 +1,63 @@
1
+ export function waChatKey(pin: any): {
2
+ key: (c: any) => string;
3
+ compare: (k1: any, k2: any) => any;
4
+ };
5
+ export function waMessageID(m: any): any;
6
+ export namespace waLabelAssociationKey {
7
+ function key(la: any): any;
8
+ function compare(k1: any, k2: any): any;
9
+ }
10
+ export function makeInMemoryStore(config?: {}): {
11
+ chats: KeyedDB;
12
+ contacts: {};
13
+ messages: {};
14
+ groupMetadata: {};
15
+ state: {
16
+ connection: string;
17
+ };
18
+ presences: {};
19
+ labels: ObjectRepository;
20
+ labelAssociations: KeyedDB;
21
+ bind: (ev: any) => void;
22
+ /** loads messages from the store, if not found -- uses the legacy connection */
23
+ loadMessages: (jid: any, count: any, cursor: any) => Promise<any>;
24
+ /**
25
+ * Get all available labels for profile
26
+ *
27
+ * Keep in mind that the list is formed from predefined tags and tags
28
+ * that were "caught" during their editing.
29
+ */
30
+ getLabels: () => ObjectRepository;
31
+ /**
32
+ * Get labels for chat
33
+ *
34
+ * @returns Label IDs
35
+ **/
36
+ getChatLabels: (chatId: any) => any[];
37
+ /**
38
+ * Get labels for message
39
+ *
40
+ * @returns Label IDs
41
+ **/
42
+ getMessageLabels: (messageId: any) => any[];
43
+ loadMessage: (jid: any, id: any) => Promise<any>;
44
+ mostRecentMessage: (jid: any) => Promise<any>;
45
+ fetchImageUrl: (jid: any, sock: any) => Promise<any>;
46
+ fetchGroupMetadata: (jid: any, sock: any) => Promise<any>;
47
+ fetchMessageReceipts: ({ remoteJid, id }: {
48
+ remoteJid: any;
49
+ id: any;
50
+ }) => Promise<any>;
51
+ toJSON: () => {
52
+ chats: KeyedDB;
53
+ contacts: {};
54
+ messages: {};
55
+ labels: ObjectRepository;
56
+ labelAssociations: KeyedDB;
57
+ };
58
+ fromJSON: (json: any) => void;
59
+ writeToFile: (path: any) => void;
60
+ readFromFile: (path: any) => void;
61
+ };
62
+ import { KeyedDB } from '../Addon/index.js';
63
+ import { ObjectRepository } from './object-repository.js';
@@ -0,0 +1,419 @@
1
+ /**
2
+ * [WIP]
3
+ * Manually converted to ESM and modified by me
4
+ * Originally based on @whiskeysockets/baileys v6.7.16
5
+ * Minor adjustments for compatibility with baileys v7 (⁠つ⁠≧⁠▽⁠≦⁠)⁠つ
6
+ */
7
+ import { writeFileSync, readFileSync, existsSync } from 'node:fs';
8
+ import { KeyedDB } from '../Addon/index.js';
9
+ import { WAProto } from '../Types/index.js';
10
+ import { LabelAssociationType } from '../Types/LabelAssociation.js';
11
+ import { DEFAULT_CONNECTION_CONFIG } from '../Defaults/index.js';
12
+ import { md5, toNumber, updateMessageWithReceipt, updateMessageWithReaction } from '../Utils/index.js';
13
+ import { jidDecode, jidNormalizedUser } from '../WABinary/index.js';
14
+ import { makeOrderedDictionary } from './make-ordered-dictionary.js';
15
+ import { ObjectRepository } from './object-repository.js';
16
+ export const waChatKey = (pin) => ({
17
+ key: (c) => (pin ? (c.pinned ? '1' : '0') : '') + (c.archived ? '0' : '1') + (c.conversationTimestamp ? c.conversationTimestamp.toString(16).padStart(8, '0') : '') + c.id,
18
+ compare: (k1, k2) => k2.localeCompare(k1)
19
+ });
20
+ export const waMessageID = (m) => m.key.id || '';
21
+ export const waLabelAssociationKey = {
22
+ key: (la) => (la.type === LabelAssociationType.Chat ? la.chatId + la.labelId : la.chatId + la.messageId + la.labelId),
23
+ compare: (k1, k2) => k2.localeCompare(k1)
24
+ };
25
+ const makeMessagesDictionary = () => makeOrderedDictionary(waMessageID);
26
+ export const makeInMemoryStore = (config = {}) => {
27
+ const socket = config.socket;
28
+ const chatKey = config.chatKey || waChatKey(true);
29
+ const labelAssociationKey = config.labelAssociationKey || waLabelAssociationKey;
30
+ const logger = config.logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
31
+ const chats = new KeyedDB(chatKey, c => c.id);
32
+ const messages = {};
33
+ const contacts = {};
34
+ const groupMetadata = {};
35
+ const presences = {};
36
+ const state = { connection: 'close' };
37
+ const labels = new ObjectRepository();
38
+ const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
39
+ const assertMessageList = (jid) => {
40
+ if (!messages[jid]) {
41
+ messages[jid] = makeMessagesDictionary();
42
+ }
43
+ return messages[jid];
44
+ };
45
+ const contactsUpsert = (newContacts) => {
46
+ const oldContacts = new Set(Object.keys(contacts));
47
+ for (const contact of newContacts) {
48
+ oldContacts.delete(contact.id);
49
+ contacts[contact.id] = Object.assign(contacts[contact.id] || {}, contact);
50
+ }
51
+ return oldContacts;
52
+ };
53
+ const labelsUpsert = (newLabels) => {
54
+ for (const label of newLabels) {
55
+ labels.upsertById(label.id, label);
56
+ }
57
+ };
58
+ /**
59
+ * binds to a BaileysEventEmitter.
60
+ * It listens to all events and constructs a state that you can query accurate data from.
61
+ * Eg. can use the store to fetch chats, contacts, messages etc.
62
+ * @param ev typically the event emitter from the socket connection
63
+ */
64
+ const bind = (ev) => {
65
+ ev.on('connection.update', update => {
66
+ Object.assign(state, update);
67
+ });
68
+ ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
69
+ if (syncType === WAProto.HistorySync.HistorySyncType.ON_DEMAND) {
70
+ return; // FOR NOW,
71
+ //TODO: HANDLE
72
+ }
73
+ if (isLatest) {
74
+ chats.clear();
75
+ for (const id in messages) {
76
+ delete messages[id];
77
+ }
78
+ }
79
+ const chatsAdded = chats.insertIfAbsent(...newChats).length;
80
+ logger.debug({ chatsAdded }, 'synced chats');
81
+ const oldContacts = contactsUpsert(newContacts);
82
+ if (isLatest) {
83
+ for (const jid of oldContacts) {
84
+ delete contacts[jid];
85
+ }
86
+ }
87
+ logger.debug({ deletedContacts: isLatest ? oldContacts.size : 0, newContacts }, 'synced contacts');
88
+ for (const msg of newMessages) {
89
+ const jid = msg.key.remoteJidAlt || msg.key.remoteJid;
90
+ const list = assertMessageList(jid);
91
+ list.upsert(msg, 'prepend');
92
+ }
93
+ logger.debug({ messages: newMessages.length }, 'synced messages');
94
+ });
95
+ ev.on('contacts.upsert', contacts => {
96
+ contactsUpsert(contacts);
97
+ });
98
+ ev.on('contacts.update', async (updates) => {
99
+ var _a;
100
+ for (const update of updates) {
101
+ let contact;
102
+ if (contacts[update.id]) {
103
+ contact = contacts[update.id];
104
+ }
105
+ else {
106
+ const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
107
+ const { user } = jidDecode(contactId);
108
+ return [contactId, (await md5(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
109
+ }));
110
+ contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
111
+ }
112
+ if (contact) {
113
+ if (update.imgUrl === 'changed') {
114
+ contact.imgUrl = socket ? await (socket === null || socket === void 0 ? void 0 : socket.profilePictureUrl(contact.id)) : undefined;
115
+ }
116
+ else if (update.imgUrl === 'removed') {
117
+ delete contact.imgUrl;
118
+ }
119
+ }
120
+ else {
121
+ return logger.debug({ update }, 'got update for non-existant contact');
122
+ }
123
+ Object.assign(contacts[contact.id], contact);
124
+ }
125
+ });
126
+ ev.on('chats.upsert', newChats => {
127
+ chats.upsert(...newChats);
128
+ });
129
+ ev.on('chats.update', updates => {
130
+ for (let update of updates) {
131
+ const result = chats.update(update.id, chat => {
132
+ if (update.unreadCount > 0) {
133
+ update = { ...update };
134
+ update.unreadCount = (chat.unreadCount || 0) + update.unreadCount;
135
+ }
136
+ Object.assign(chat, update);
137
+ });
138
+ if (!result) {
139
+ logger.debug({ update }, 'got update for non-existant chat');
140
+ }
141
+ }
142
+ });
143
+ ev.on('labels.edit', (label) => {
144
+ if (label.deleted) {
145
+ return labels.deleteById(label.id);
146
+ }
147
+ // WhatsApp can store only up to 20 labels
148
+ if (labels.count() < 20) {
149
+ return labels.upsertById(label.id, label);
150
+ }
151
+ logger.error('Labels count exceed');
152
+ });
153
+ ev.on('labels.association', ({ type, association }) => {
154
+ switch (type) {
155
+ case 'add':
156
+ labelAssociations.upsert(association);
157
+ break;
158
+ case 'remove':
159
+ labelAssociations.delete(association);
160
+ break;
161
+ default:
162
+ console.error(`unknown operation type [${type}]`);
163
+ }
164
+ });
165
+ ev.on('presence.update', ({ id, presences: update }) => {
166
+ presences[id] = presences[id] || {};
167
+ Object.assign(presences[id], update);
168
+ });
169
+ ev.on('chats.delete', deletions => {
170
+ for (const item of deletions) {
171
+ if (chats.get(item)) {
172
+ chats.deleteById(item);
173
+ }
174
+ }
175
+ });
176
+ ev.on('messages.upsert', ({ messages: newMessages, type }) => {
177
+ switch (type) {
178
+ case 'append':
179
+ case 'notify':
180
+ for (const msg of newMessages) {
181
+ const jid = jidNormalizedUser(msg.key.remoteJidAlt || msg.key.remoteJid);
182
+ const list = assertMessageList(jid);
183
+ list.upsert(msg, 'append');
184
+ if (type === 'notify' && !chats.get(jid)) {
185
+ ev.emit('chats.upsert', [
186
+ {
187
+ id: jid,
188
+ conversationTimestamp: toNumber(msg.messageTimestamp),
189
+ unreadCount: 1
190
+ }
191
+ ]);
192
+ }
193
+ }
194
+ break;
195
+ }
196
+ });
197
+ ev.on('messages.update', updates => {
198
+ var _a;
199
+ for (const { update, key } of updates) {
200
+ const list = assertMessageList(jidNormalizedUser(key.remoteJid));
201
+ if (update === null || update === void 0 ? void 0 : update.status) {
202
+ const listStatus = (_a = list.get(key.id)) === null || _a === void 0 ? void 0 : _a.status;
203
+ if (listStatus && (update === null || update === void 0 ? void 0 : update.status) <= listStatus) {
204
+ logger.debug({ update, storedStatus: listStatus }, 'status stored newer then update');
205
+ delete update.status;
206
+ logger.debug({ update }, 'new update object');
207
+ }
208
+ }
209
+ const result = list.updateAssign(key.id, update);
210
+ if (!result) {
211
+ logger.debug({ update }, 'got update for non-existent message');
212
+ }
213
+ }
214
+ });
215
+ ev.on('messages.delete', item => {
216
+ if ('all' in item) {
217
+ const list = messages[item.jid];
218
+ list === null || list === void 0 ? void 0 : list.clear();
219
+ }
220
+ else {
221
+ const jid = item.keys[0].remoteJidAlt || item.keys[0].remoteJid;
222
+ const list = messages[jid];
223
+ if (list) {
224
+ const idSet = new Set(item.keys.map(k => k.id));
225
+ list.filter(m => !idSet.has(m.key.id));
226
+ }
227
+ }
228
+ });
229
+ ev.on('groups.update', updates => {
230
+ for (const update of updates) {
231
+ const id = update.id;
232
+ if (groupMetadata[id]) {
233
+ Object.assign(groupMetadata[id], update);
234
+ }
235
+ else {
236
+ logger.debug({ update }, 'got update for non-existant group metadata');
237
+ }
238
+ }
239
+ });
240
+ ev.on('group-participants.update', ({ id, participants, action }) => {
241
+ const metadata = groupMetadata[id];
242
+ if (metadata) {
243
+ switch (action) {
244
+ case 'add':
245
+ metadata.participants.push(...participants.map(participant => ({ id: participant.id, phoneNumber: participant.phoneNumber, admin: participant.admin })));
246
+ break;
247
+ case 'demote':
248
+ case 'promote':
249
+ for (const participant of metadata.participants) {
250
+ for (const participantData of participants) {
251
+ if (participantData.id === participant.id || participantData.phoneNumber === participant.phoneNumber) {
252
+ participant.admin = action === 'promote' && 'admin';
253
+ }
254
+ }
255
+ }
256
+ break;
257
+ case 'remove':
258
+ const removeSet = new Set();
259
+ for (const p of participants) {
260
+ if (p.id)
261
+ removeSet.add(p.id);
262
+ if (p.phoneNumber)
263
+ removeSet.add(p.phoneNumber);
264
+ }
265
+ metadata.participants = metadata.participants.reduce((acc, p) => {
266
+ if (!removeSet.has(p.id) && !removeSet.has(p.phoneNumber))
267
+ acc.push(p);
268
+ return acc;
269
+ }, []);
270
+ break;
271
+ }
272
+ }
273
+ });
274
+ ev.on('message-receipt.update', updates => {
275
+ for (const { key, receipt } of updates) {
276
+ const obj = messages[key.remoteJidAlt || key.remoteJid];
277
+ const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
278
+ if (msg) {
279
+ updateMessageWithReceipt(msg, receipt);
280
+ }
281
+ }
282
+ });
283
+ ev.on('messages.reaction', (reactions) => {
284
+ for (const { key, reaction } of reactions) {
285
+ const obj = messages[key.remoteJidAlt || key.remoteJid];
286
+ const msg = obj === null || obj === void 0 ? void 0 : obj.get(key.id);
287
+ if (msg) {
288
+ updateMessageWithReaction(msg, reaction);
289
+ }
290
+ }
291
+ });
292
+ };
293
+ const toJSON = () => ({
294
+ chats,
295
+ contacts,
296
+ messages,
297
+ labels,
298
+ labelAssociations
299
+ });
300
+ const fromJSON = (json) => {
301
+ chats.upsert(...json.chats);
302
+ labelAssociations.upsert(...json.labelAssociations || []);
303
+ contactsUpsert(Object.values(json.contacts));
304
+ labelsUpsert(Object.values(json.labels || {}));
305
+ for (const jid in json.messages) {
306
+ const list = assertMessageList(jid);
307
+ for (const msg of json.messages[jid]) {
308
+ list.upsert(WAProto.WebMessageInfo.fromObject(msg), 'append');
309
+ }
310
+ }
311
+ };
312
+ return {
313
+ chats,
314
+ contacts,
315
+ messages,
316
+ groupMetadata,
317
+ state,
318
+ presences,
319
+ labels,
320
+ labelAssociations,
321
+ bind,
322
+ /** loads messages from the store, if not found -- uses the legacy connection */
323
+ loadMessages: async (jid, count, cursor) => {
324
+ const list = assertMessageList(jid);
325
+ const mode = !cursor || 'before' in cursor ? 'before' : 'after';
326
+ const cursorKey = !!cursor ? ('before' in cursor ? cursor.before : cursor.after) : undefined;
327
+ const cursorValue = cursorKey ? list.get(cursorKey.id) : undefined;
328
+ let messages;
329
+ if (list && mode === 'before' && (!cursorKey || cursorValue)) {
330
+ if (cursorValue) {
331
+ const msgIdx = list.array.findIndex(m => m.key.id === (cursorKey === null || cursorKey === void 0 ? void 0 : cursorKey.id));
332
+ messages = list.array.slice(0, msgIdx);
333
+ }
334
+ else {
335
+ messages = list.array;
336
+ }
337
+ const diff = count - messages.length;
338
+ if (diff < 0) {
339
+ messages = messages.slice(-count); // get the last X messages
340
+ }
341
+ }
342
+ else {
343
+ messages = [];
344
+ }
345
+ return messages;
346
+ },
347
+ /**
348
+ * Get all available labels for profile
349
+ *
350
+ * Keep in mind that the list is formed from predefined tags and tags
351
+ * that were "caught" during their editing.
352
+ */
353
+ getLabels: () => {
354
+ return labels;
355
+ },
356
+ /**
357
+ * Get labels for chat
358
+ *
359
+ * @returns Label IDs
360
+ **/
361
+ getChatLabels: (chatId) => {
362
+ return labelAssociations.filter((la) => la.chatId === chatId).all();
363
+ },
364
+ /**
365
+ * Get labels for message
366
+ *
367
+ * @returns Label IDs
368
+ **/
369
+ getMessageLabels: (messageId) => {
370
+ const associations = labelAssociations
371
+ .filter((la) => la.messageId === messageId)
372
+ .all();
373
+ return associations.map(({ labelId }) => labelId);
374
+ },
375
+ loadMessage: async (jid, id) => { var _a; return (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.get(id); },
376
+ mostRecentMessage: async (jid) => {
377
+ var _a;
378
+ const message = (_a = messages[jid]) === null || _a === void 0 ? void 0 : _a.array.slice(-1)[0];
379
+ return message;
380
+ },
381
+ fetchImageUrl: async (jid, sock) => {
382
+ const contact = contacts[jid];
383
+ if (!contact) {
384
+ return sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid);
385
+ }
386
+ if (typeof contact.imgUrl === 'undefined') {
387
+ contact.imgUrl = await (sock === null || sock === void 0 ? void 0 : sock.profilePictureUrl(jid));
388
+ }
389
+ return contact.imgUrl;
390
+ },
391
+ fetchGroupMetadata: async (jid, sock) => {
392
+ if (!groupMetadata[jid]) {
393
+ const metadata = await (sock === null || sock === void 0 ? void 0 : sock.groupMetadata(jid));
394
+ if (metadata) {
395
+ groupMetadata[jid] = metadata;
396
+ }
397
+ }
398
+ return groupMetadata[jid];
399
+ },
400
+ fetchMessageReceipts: async ({ remoteJid, id }) => {
401
+ const list = messages[remoteJid];
402
+ const msg = list === null || list === void 0 ? void 0 : list.get(id);
403
+ return msg === null || msg === void 0 ? void 0 : msg.userReceipt;
404
+ },
405
+ toJSON,
406
+ fromJSON,
407
+ writeToFile: (path) => {
408
+ writeFileSync(path, JSON.stringify(toJSON()));
409
+ },
410
+ readFromFile: (path) => {
411
+ if (existsSync(path)) {
412
+ logger.debug({ path }, 'reading from file');
413
+ const jsonStr = readFileSync(path, { encoding: 'utf-8' });
414
+ const json = JSON.parse(jsonStr);
415
+ fromJSON(json);
416
+ }
417
+ }
418
+ };
419
+ };
@@ -0,0 +1,12 @@
1
+ export function makeOrderedDictionary(idGetter: any): {
2
+ array: any[];
3
+ get: (id: any) => any;
4
+ upsert: (item: any, mode: any) => void;
5
+ update: (item: any) => boolean;
6
+ remove: (item: any) => boolean;
7
+ updateAssign: (id: any, update: any) => boolean;
8
+ clear: () => void;
9
+ filter: (contain: any) => void;
10
+ toJSON: () => any[];
11
+ fromJSON: (newItems: any) => void;
12
+ };
@@ -0,0 +1,78 @@
1
+ export function makeOrderedDictionary(idGetter) {
2
+ const array = [];
3
+ const dict = {};
4
+ const get = (id) => dict[id];
5
+ const update = (item) => {
6
+ const id = idGetter(item);
7
+ const idx = array.findIndex(i => idGetter(i) === id);
8
+ if (idx >= 0) {
9
+ array[idx] = item;
10
+ dict[id] = item;
11
+ }
12
+ return false;
13
+ };
14
+ const upsert = (item, mode) => {
15
+ const id = idGetter(item);
16
+ if (get(id)) {
17
+ update(item);
18
+ }
19
+ else {
20
+ if (mode === 'append') {
21
+ array.push(item);
22
+ }
23
+ else {
24
+ array.splice(0, 0, item);
25
+ }
26
+ dict[id] = item;
27
+ }
28
+ };
29
+ const remove = (item) => {
30
+ const id = idGetter(item);
31
+ const idx = array.findIndex(i => idGetter(i) === id);
32
+ if (idx >= 0) {
33
+ array.splice(idx, 1);
34
+ delete dict[id];
35
+ return true;
36
+ }
37
+ return false;
38
+ };
39
+ return {
40
+ array,
41
+ get,
42
+ upsert,
43
+ update,
44
+ remove,
45
+ updateAssign: (id, update) => {
46
+ const item = get(id);
47
+ if (item) {
48
+ Object.assign(item, update);
49
+ delete dict[id];
50
+ dict[idGetter(item)] = item;
51
+ return true;
52
+ }
53
+ return false;
54
+ },
55
+ clear: () => {
56
+ array.splice(0, array.length);
57
+ for (const key of Object.keys(dict)) {
58
+ delete dict[key];
59
+ }
60
+ },
61
+ filter: (contain) => {
62
+ let i = 0;
63
+ while (i < array.length) {
64
+ if (!contain(array[i])) {
65
+ delete dict[idGetter(array[i])];
66
+ array.splice(i, 1);
67
+ }
68
+ else {
69
+ i += 1;
70
+ }
71
+ }
72
+ },
73
+ toJSON: () => array,
74
+ fromJSON: (newItems) => {
75
+ array.splice(0, array.length, ...newItems);
76
+ }
77
+ };
78
+ }
@@ -0,0 +1,10 @@
1
+ export class ObjectRepository {
2
+ constructor(entities?: {});
3
+ entityMap: Map<string, any>;
4
+ findById(id: any): any;
5
+ findAll(): any[];
6
+ upsertById(id: any, entity: any): Map<string, any>;
7
+ deleteById(id: any): boolean;
8
+ count(): number;
9
+ toJSON(): any[];
10
+ }
@@ -0,0 +1,23 @@
1
+ export class ObjectRepository {
2
+ constructor(entities = {}) {
3
+ this.entityMap = new Map(Object.entries(entities));
4
+ }
5
+ findById(id) {
6
+ return this.entityMap.get(id);
7
+ }
8
+ findAll() {
9
+ return Array.from(this.entityMap.values());
10
+ }
11
+ upsertById(id, entity) {
12
+ return this.entityMap.set(id, { ...entity });
13
+ }
14
+ deleteById(id) {
15
+ return this.entityMap.delete(id);
16
+ }
17
+ count() {
18
+ return this.entityMap.size;
19
+ }
20
+ toJSON() {
21
+ return this.findAll();
22
+ }
23
+ }
@@ -0,0 +1,6 @@
1
+ export function encrypt(key: any, data: any, iv: any): any;
2
+ export function decrypt(key: any, data: any, iv: any): any;
3
+ export function calculateMAC(key: any, data: any): any;
4
+ export function hash(data: any): any;
5
+ export function deriveSecrets(input: any, salt: any, info: any, chunks: any): any[];
6
+ export function verifyMAC(data: any, key: any, mac: any, length: any): void;
@@ -0,0 +1,61 @@
1
+ import { createCipheriv, createDecipheriv, createHmac, createHash } from 'node:crypto';
2
+ import assert from 'node:assert/strict';
3
+ import { hkdf } from '../WACrypto/index.js';
4
+ function assertBuffer(value) {
5
+ if (!Buffer.isBuffer(value)) {
6
+ throw TypeError(`Expected Buffer instead of: ${value.constructor.name}`);
7
+ }
8
+ return value;
9
+ }
10
+ export function encrypt(key, data, iv) {
11
+ assertBuffer(key);
12
+ assertBuffer(data);
13
+ assertBuffer(iv);
14
+ const cipher = createCipheriv('aes-256-cbc', key, iv);
15
+ return Buffer.concat([cipher.update(data), cipher.final()]);
16
+ }
17
+ export function decrypt(key, data, iv) {
18
+ assertBuffer(key);
19
+ assertBuffer(data);
20
+ assertBuffer(iv);
21
+ const decipher = createDecipheriv('aes-256-cbc', key, iv);
22
+ return Buffer.concat([decipher.update(data), decipher.final()]);
23
+ }
24
+ export function calculateMAC(key, data) {
25
+ assertBuffer(key);
26
+ assertBuffer(data);
27
+ const hmac = createHmac('sha256', key);
28
+ hmac.update(data);
29
+ return Buffer.from(hmac.digest());
30
+ }
31
+ export function hash(data) {
32
+ assertBuffer(data);
33
+ const sha512 = createHash('sha512');
34
+ sha512.update(data);
35
+ return sha512.digest();
36
+ }
37
+ export function deriveSecrets(input, salt, info, chunks) {
38
+ assertBuffer(input);
39
+ assertBuffer(salt);
40
+ assertBuffer(info);
41
+ if (salt.byteLength != 32) {
42
+ throw new Error('Got salt of incorrect length');
43
+ }
44
+ chunks = chunks || 3;
45
+ assert(chunks >= 1 && chunks <= 3);
46
+ const result = hkdf(input, chunks * 32, { salt, info: info.toString('utf8') });
47
+ const output = new Array(chunks);
48
+ for (let i = 0; i < chunks; i++) {
49
+ output[i] = Buffer.from(result.buffer, result.byteOffset + (i * 32), 32);
50
+ }
51
+ return output;
52
+ }
53
+ export function verifyMAC(data, key, mac, length) {
54
+ const calculatedMac = calculateMAC(key, data).slice(0, length);
55
+ if (mac.length !== length || calculatedMac.length !== length) {
56
+ throw new Error('Bad MAC length');
57
+ }
58
+ if (!mac.equals(calculatedMac)) {
59
+ throw new Error('Bad MAC');
60
+ }
61
+ }