@eduh_dev021/baileys 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (504) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +495 -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/http-error.d.ts +18 -0
  9. package/cjs/lib/Addon/http-error.js +66 -0
  10. package/cjs/lib/Addon/index.d.ts +3 -0
  11. package/cjs/lib/Addon/index.js +50 -0
  12. package/cjs/lib/Addon/keyed-db.d.ts +14 -0
  13. package/cjs/lib/Addon/keyed-db.js +264 -0
  14. package/cjs/lib/Addon/link-preview.d.ts +15 -0
  15. package/cjs/lib/Addon/link-preview.js +104 -0
  16. package/cjs/lib/Defaults/index.d.ts +184 -0
  17. package/cjs/lib/Defaults/index.js +292 -0
  18. package/cjs/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  19. package/cjs/lib/Signal/Group/ciphertext-message.js +37 -0
  20. package/cjs/lib/Signal/Group/group-cipher.d.ts +10 -0
  21. package/cjs/lib/Signal/Group/group-cipher.js +105 -0
  22. package/cjs/lib/Signal/Group/group-session-builder.d.ts +7 -0
  23. package/cjs/lib/Signal/Group/group-session-builder.js +65 -0
  24. package/cjs/lib/Signal/Group/index.d.ts +11 -0
  25. package/cjs/lib/Signal/Group/index.js +67 -0
  26. package/cjs/lib/Signal/Group/keyhelper.d.ts +6 -0
  27. package/cjs/lib/Signal/Group/keyhelper.js +47 -0
  28. package/cjs/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  29. package/cjs/lib/Signal/Group/sender-chain-key.js +51 -0
  30. package/cjs/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  31. package/cjs/lib/Signal/Group/sender-key-distribution-message.js +80 -0
  32. package/cjs/lib/Signal/Group/sender-key-message.d.ts +18 -0
  33. package/cjs/lib/Signal/Group/sender-key-message.js +87 -0
  34. package/cjs/lib/Signal/Group/sender-key-name.d.ts +11 -0
  35. package/cjs/lib/Signal/Group/sender-key-name.js +73 -0
  36. package/cjs/lib/Signal/Group/sender-key-record.d.ts +12 -0
  37. package/cjs/lib/Signal/Group/sender-key-record.js +66 -0
  38. package/cjs/lib/Signal/Group/sender-key-state.d.ts +16 -0
  39. package/cjs/lib/Signal/Group/sender-key-state.js +106 -0
  40. package/cjs/lib/Signal/Group/sender-message-key.d.ts +11 -0
  41. package/cjs/lib/Signal/Group/sender-message-key.js +51 -0
  42. package/cjs/lib/Signal/libsignal.d.ts +54 -0
  43. package/cjs/lib/Signal/libsignal.js +421 -0
  44. package/cjs/lib/Signal/lid-mapping.d.ts +20 -0
  45. package/cjs/lib/Signal/lid-mapping.js +292 -0
  46. package/cjs/lib/Socket/Client/index.d.ts +2 -0
  47. package/cjs/lib/Socket/Client/index.js +23 -0
  48. package/cjs/lib/Socket/Client/types.d.ts +5 -0
  49. package/cjs/lib/Socket/Client/types.js +36 -0
  50. package/cjs/lib/Socket/Client/websocket.d.ts +12 -0
  51. package/cjs/lib/Socket/Client/websocket.js +143 -0
  52. package/cjs/lib/Socket/business.d.ts +387 -0
  53. package/cjs/lib/Socket/business.js +402 -0
  54. package/cjs/lib/Socket/chats.d.ts +144 -0
  55. package/cjs/lib/Socket/chats.js +1118 -0
  56. package/cjs/lib/Socket/communities.d.ts +554 -0
  57. package/cjs/lib/Socket/communities.js +456 -0
  58. package/cjs/lib/Socket/groups.d.ts +286 -0
  59. package/cjs/lib/Socket/groups.js +366 -0
  60. package/cjs/lib/Socket/index.d.ts +522 -0
  61. package/cjs/lib/Socket/index.js +32 -0
  62. package/cjs/lib/Socket/messages-recv.d.ts +326 -0
  63. package/cjs/lib/Socket/messages-recv.js +1670 -0
  64. package/cjs/lib/Socket/messages-send.d.ts +321 -0
  65. package/cjs/lib/Socket/messages-send.js +1252 -0
  66. package/cjs/lib/Socket/mex.d.ts +1 -0
  67. package/cjs/lib/Socket/mex.js +65 -0
  68. package/cjs/lib/Socket/newsletter.d.ts +283 -0
  69. package/cjs/lib/Socket/newsletter.js +243 -0
  70. package/cjs/lib/Socket/socket.d.ts +61 -0
  71. package/cjs/lib/Socket/socket.js +908 -0
  72. package/cjs/lib/Store/index.d.ts +3 -0
  73. package/cjs/lib/Store/index.js +25 -0
  74. package/cjs/lib/Store/make-in-memory-store.d.ts +63 -0
  75. package/cjs/lib/Store/make-in-memory-store.js +431 -0
  76. package/cjs/lib/Store/make-ordered-dictionary.d.ts +12 -0
  77. package/cjs/lib/Store/make-ordered-dictionary.js +101 -0
  78. package/cjs/lib/Store/object-repository.d.ts +10 -0
  79. package/cjs/lib/Store/object-repository.js +49 -0
  80. package/cjs/lib/Transport/crypto.d.ts +6 -0
  81. package/cjs/lib/Transport/crypto.js +107 -0
  82. package/cjs/lib/Transport/curve.d.ts +8 -0
  83. package/cjs/lib/Transport/curve.js +94 -0
  84. package/cjs/lib/Transport/index.d.ts +16 -0
  85. package/cjs/lib/Transport/index.js +67 -0
  86. package/cjs/lib/Transport/internals.d.ts +57 -0
  87. package/cjs/lib/Transport/internals.js +203 -0
  88. package/cjs/lib/Transport/session-builder.d.ts +40 -0
  89. package/cjs/lib/Transport/session-builder.js +169 -0
  90. package/cjs/lib/Transport/session-cipher.d.ts +26 -0
  91. package/cjs/lib/Transport/session-cipher.js +328 -0
  92. package/cjs/lib/Transport/session-record.d.ts +55 -0
  93. package/cjs/lib/Transport/session-record.js +289 -0
  94. package/cjs/lib/Types/Auth.d.ts +1 -0
  95. package/cjs/lib/Types/Auth.js +15 -0
  96. package/cjs/lib/Types/Bussines.d.ts +1 -0
  97. package/cjs/lib/Types/Bussines.js +15 -0
  98. package/cjs/lib/Types/Call.d.ts +1 -0
  99. package/cjs/lib/Types/Call.js +15 -0
  100. package/cjs/lib/Types/Chat.d.ts +1 -0
  101. package/cjs/lib/Types/Chat.js +33 -0
  102. package/cjs/lib/Types/Contact.d.ts +1 -0
  103. package/cjs/lib/Types/Contact.js +15 -0
  104. package/cjs/lib/Types/Events.d.ts +1 -0
  105. package/cjs/lib/Types/Events.js +1 -0
  106. package/cjs/lib/Types/GroupMetadata.d.ts +1 -0
  107. package/cjs/lib/Types/GroupMetadata.js +15 -0
  108. package/cjs/lib/Types/Label.d.ts +2 -0
  109. package/cjs/lib/Types/Label.js +49 -0
  110. package/cjs/lib/Types/LabelAssociation.d.ts +2 -0
  111. package/cjs/lib/Types/LabelAssociation.js +31 -0
  112. package/cjs/lib/Types/Message.d.ts +11 -0
  113. package/cjs/lib/Types/Message.js +58 -0
  114. package/cjs/lib/Types/Mex.d.ts +2 -0
  115. package/cjs/lib/Types/Mex.js +66 -0
  116. package/cjs/lib/Types/Product.d.ts +1 -0
  117. package/cjs/lib/Types/Product.js +15 -0
  118. package/cjs/lib/Types/RichType.d.ts +2 -0
  119. package/cjs/lib/Types/RichType.js +50 -0
  120. package/cjs/lib/Types/Signal.d.ts +1 -0
  121. package/cjs/lib/Types/Signal.js +1 -0
  122. package/cjs/lib/Types/Socket.d.ts +1 -0
  123. package/cjs/lib/Types/Socket.js +1 -0
  124. package/cjs/lib/Types/State.d.ts +5 -0
  125. package/cjs/lib/Types/State.js +83 -0
  126. package/cjs/lib/Types/USync.d.ts +1 -0
  127. package/cjs/lib/Types/USync.js +1 -0
  128. package/cjs/lib/Types/index.d.ts +13 -0
  129. package/cjs/lib/Types/index.js +64 -0
  130. package/cjs/lib/Utils/auth-utils.d.ts +58 -0
  131. package/cjs/lib/Utils/auth-utils.js +275 -0
  132. package/cjs/lib/Utils/browser-utils.d.ts +9 -0
  133. package/cjs/lib/Utils/browser-utils.js +56 -0
  134. package/cjs/lib/Utils/business.d.ts +49 -0
  135. package/cjs/lib/Utils/business.js +259 -0
  136. package/cjs/lib/Utils/chat-utils.d.ts +408 -0
  137. package/cjs/lib/Utils/chat-utils.js +821 -0
  138. package/cjs/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  139. package/cjs/lib/Utils/companion-reg-client-utils.js +71 -0
  140. package/cjs/lib/Utils/crypto.d.ts +39 -0
  141. package/cjs/lib/Utils/crypto.js +155 -0
  142. package/cjs/lib/Utils/decode-wa-message.d.ts +83 -0
  143. package/cjs/lib/Utils/decode-wa-message.js +316 -0
  144. package/cjs/lib/Utils/event-buffer.d.ts +12 -0
  145. package/cjs/lib/Utils/event-buffer.js +605 -0
  146. package/cjs/lib/Utils/generics.d.ts +63 -0
  147. package/cjs/lib/Utils/generics.js +440 -0
  148. package/cjs/lib/Utils/history.d.ts +75 -0
  149. package/cjs/lib/Utils/history.js +153 -0
  150. package/cjs/lib/Utils/identity-change-handler.d.ts +13 -0
  151. package/cjs/lib/Utils/identity-change-handler.js +73 -0
  152. package/cjs/lib/Utils/index.d.ts +24 -0
  153. package/cjs/lib/Utils/index.js +67 -0
  154. package/cjs/lib/Utils/link-preview.d.ts +13 -0
  155. package/cjs/lib/Utils/link-preview.js +87 -0
  156. package/cjs/lib/Utils/logger.d.ts +12 -0
  157. package/cjs/lib/Utils/logger.js +40 -0
  158. package/cjs/lib/Utils/lt-hash.d.ts +6 -0
  159. package/cjs/lib/Utils/lt-hash.js +28 -0
  160. package/cjs/lib/Utils/make-mutex.d.ts +6 -0
  161. package/cjs/lib/Utils/make-mutex.js +58 -0
  162. package/cjs/lib/Utils/message-retry-manager.d.ts +79 -0
  163. package/cjs/lib/Utils/message-retry-manager.js +274 -0
  164. package/cjs/lib/Utils/messages-media.d.ts +134 -0
  165. package/cjs/lib/Utils/messages-media.js +799 -0
  166. package/cjs/lib/Utils/messages.d.ts +47 -0
  167. package/cjs/lib/Utils/messages.js +1667 -0
  168. package/cjs/lib/Utils/noise-handler.d.ts +20 -0
  169. package/cjs/lib/Utils/noise-handler.js +223 -0
  170. package/cjs/lib/Utils/offline-node-processor.d.ts +10 -0
  171. package/cjs/lib/Utils/offline-node-processor.js +60 -0
  172. package/cjs/lib/Utils/pre-key-manager.d.ts +25 -0
  173. package/cjs/lib/Utils/pre-key-manager.js +116 -0
  174. package/cjs/lib/Utils/process-message.d.ts +83 -0
  175. package/cjs/lib/Utils/process-message.js +607 -0
  176. package/cjs/lib/Utils/reporting-utils.d.ts +12 -0
  177. package/cjs/lib/Utils/reporting-utils.js +282 -0
  178. package/cjs/lib/Utils/rich-message-utils.d.ts +48 -0
  179. package/cjs/lib/Utils/rich-message-utils.js +381 -0
  180. package/cjs/lib/Utils/signal.d.ts +82 -0
  181. package/cjs/lib/Utils/signal.js +232 -0
  182. package/cjs/lib/Utils/stanza-ack.d.ts +16 -0
  183. package/cjs/lib/Utils/stanza-ack.js +53 -0
  184. package/cjs/lib/Utils/sync-action-utils.d.ts +2 -0
  185. package/cjs/lib/Utils/sync-action-utils.js +68 -0
  186. package/cjs/lib/Utils/tc-token-utils.d.ts +29 -0
  187. package/cjs/lib/Utils/tc-token-utils.js +182 -0
  188. package/cjs/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  189. package/cjs/lib/Utils/use-multi-file-auth-state.js +135 -0
  190. package/cjs/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  191. package/cjs/lib/Utils/use-single-file-auth-state.js +115 -0
  192. package/cjs/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  193. package/cjs/lib/Utils/use-sqlite-auth-state.js +140 -0
  194. package/cjs/lib/Utils/validate-connection.d.ts +44 -0
  195. package/cjs/lib/Utils/validate-connection.js +229 -0
  196. package/cjs/lib/WABinary/constants.d.ts +61 -0
  197. package/cjs/lib/WABinary/constants.js +1992 -0
  198. package/cjs/lib/WABinary/decode.d.ts +9 -0
  199. package/cjs/lib/WABinary/decode.js +292 -0
  200. package/cjs/lib/WABinary/encode.d.ts +2 -0
  201. package/cjs/lib/WABinary/encode.js +240 -0
  202. package/cjs/lib/WABinary/generic-utils.d.ts +79 -0
  203. package/cjs/lib/WABinary/generic-utils.js +252 -0
  204. package/cjs/lib/WABinary/index.d.ts +5 -0
  205. package/cjs/lib/WABinary/index.js +29 -0
  206. package/cjs/lib/WABinary/jid-utils.d.ts +28 -0
  207. package/cjs/lib/WABinary/jid-utils.js +151 -0
  208. package/cjs/lib/WABinary/types.d.ts +1 -0
  209. package/cjs/lib/WABinary/types.js +23 -0
  210. package/cjs/lib/WACrypto/appstate-keys.js +39 -0
  211. package/cjs/lib/WACrypto/curves/constants.js +37 -0
  212. package/cjs/lib/WACrypto/hkdf.js +38 -0
  213. package/cjs/lib/WACrypto/index.js +51 -0
  214. package/cjs/lib/WACrypto/lthash.js +59 -0
  215. package/cjs/lib/WACrypto/math/constants.js +53 -0
  216. package/cjs/lib/WACrypto/math/edwards.js +206 -0
  217. package/cjs/lib/WACrypto/math/fe.js +449 -0
  218. package/cjs/lib/WACrypto/math/le.js +44 -0
  219. package/cjs/lib/WACrypto/math/mod.js +36 -0
  220. package/cjs/lib/WACrypto/util/bytes.js +348 -0
  221. package/cjs/lib/WACrypto/x25519.js +157 -0
  222. package/cjs/lib/WACrypto/xeddsa.js +134 -0
  223. package/cjs/lib/WAM/BinaryInfo.d.ts +7 -0
  224. package/cjs/lib/WAM/BinaryInfo.js +35 -0
  225. package/cjs/lib/WAM/constants.d.ts +34926 -0
  226. package/cjs/lib/WAM/constants.js +22890 -0
  227. package/cjs/lib/WAM/encode.d.ts +1 -0
  228. package/cjs/lib/WAM/encode.js +162 -0
  229. package/cjs/lib/WAM/index.d.ts +3 -0
  230. package/cjs/lib/WAM/index.js +25 -0
  231. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  232. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +77 -0
  233. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  234. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +76 -0
  235. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  236. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +52 -0
  237. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  238. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +61 -0
  239. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  240. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +50 -0
  241. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  242. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +76 -0
  243. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  244. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +53 -0
  245. package/cjs/lib/WAUSync/Protocols/index.d.ts +5 -0
  246. package/cjs/lib/WAUSync/Protocols/index.js +29 -0
  247. package/cjs/lib/WAUSync/USyncQuery.d.ts +20 -0
  248. package/cjs/lib/WAUSync/USyncQuery.js +113 -0
  249. package/cjs/lib/WAUSync/USyncUser.d.ts +16 -0
  250. package/cjs/lib/WAUSync/USyncUser.js +56 -0
  251. package/cjs/lib/WAUSync/index.d.ts +3 -0
  252. package/cjs/lib/WAUSync/index.js +25 -0
  253. package/cjs/lib/index.d.ts +11 -0
  254. package/cjs/lib/index.js +56 -0
  255. package/cjs/package.json +3 -0
  256. package/engine-requirements.js +12 -0
  257. package/lib/Addon/http-error.d.ts +18 -0
  258. package/lib/Addon/http-error.js +40 -0
  259. package/lib/Addon/index.d.ts +3 -0
  260. package/lib/Addon/index.js +4 -0
  261. package/lib/Addon/keyed-db.d.ts +14 -0
  262. package/lib/Addon/keyed-db.js +241 -0
  263. package/lib/Addon/link-preview.d.ts +15 -0
  264. package/lib/Addon/link-preview.js +79 -0
  265. package/lib/Defaults/index.d.ts +184 -0
  266. package/lib/Defaults/index.js +181 -0
  267. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  268. package/lib/Signal/Group/ciphertext-message.js +11 -0
  269. package/lib/Signal/Group/group-cipher.d.ts +10 -0
  270. package/lib/Signal/Group/group-cipher.js +81 -0
  271. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  272. package/lib/Signal/Group/group-session-builder.js +29 -0
  273. package/lib/Signal/Group/index.d.ts +11 -0
  274. package/lib/Signal/Group/index.js +11 -0
  275. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  276. package/lib/Signal/Group/keyhelper.js +17 -0
  277. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  278. package/lib/Signal/Group/sender-chain-key.js +25 -0
  279. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  280. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  281. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  282. package/lib/Signal/Group/sender-key-message.js +65 -0
  283. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  284. package/lib/Signal/Group/sender-key-name.js +47 -0
  285. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  286. package/lib/Signal/Group/sender-key-record.js +40 -0
  287. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  288. package/lib/Signal/Group/sender-key-state.js +83 -0
  289. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  290. package/lib/Signal/Group/sender-message-key.js +25 -0
  291. package/lib/Signal/libsignal.d.ts +54 -0
  292. package/lib/Signal/libsignal.js +426 -0
  293. package/lib/Signal/lid-mapping.d.ts +20 -0
  294. package/lib/Signal/lid-mapping.js +274 -0
  295. package/lib/Socket/Client/index.d.ts +2 -0
  296. package/lib/Socket/Client/index.js +2 -0
  297. package/lib/Socket/Client/types.d.ts +5 -0
  298. package/lib/Socket/Client/types.js +10 -0
  299. package/lib/Socket/Client/websocket.d.ts +12 -0
  300. package/lib/Socket/Client/websocket.js +119 -0
  301. package/lib/Socket/business.d.ts +387 -0
  302. package/lib/Socket/business.js +379 -0
  303. package/lib/Socket/chats.d.ts +144 -0
  304. package/lib/Socket/chats.js +1216 -0
  305. package/lib/Socket/communities.d.ts +554 -0
  306. package/lib/Socket/communities.js +431 -0
  307. package/lib/Socket/groups.d.ts +286 -0
  308. package/lib/Socket/groups.js +347 -0
  309. package/lib/Socket/index.d.ts +522 -0
  310. package/lib/Socket/index.js +11 -0
  311. package/lib/Socket/messages-recv.d.ts +326 -0
  312. package/lib/Socket/messages-recv.js +1822 -0
  313. package/lib/Socket/messages-send.d.ts +321 -0
  314. package/lib/Socket/messages-send.js +1378 -0
  315. package/lib/Socket/mex.d.ts +1 -0
  316. package/lib/Socket/mex.js +41 -0
  317. package/lib/Socket/newsletter.d.ts +283 -0
  318. package/lib/Socket/newsletter.js +225 -0
  319. package/lib/Socket/socket.d.ts +61 -0
  320. package/lib/Socket/socket.js +992 -0
  321. package/lib/Store/index.d.ts +3 -0
  322. package/lib/Store/index.js +3 -0
  323. package/lib/Store/make-in-memory-store.d.ts +63 -0
  324. package/lib/Store/make-in-memory-store.js +419 -0
  325. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  326. package/lib/Store/make-ordered-dictionary.js +78 -0
  327. package/lib/Store/object-repository.d.ts +10 -0
  328. package/lib/Store/object-repository.js +23 -0
  329. package/lib/Transport/crypto.d.ts +6 -0
  330. package/lib/Transport/crypto.js +61 -0
  331. package/lib/Transport/curve.d.ts +8 -0
  332. package/lib/Transport/curve.js +66 -0
  333. package/lib/Transport/index.d.ts +16 -0
  334. package/lib/Transport/index.js +9 -0
  335. package/lib/Transport/internals.d.ts +57 -0
  336. package/lib/Transport/internals.js +155 -0
  337. package/lib/Transport/session-builder.d.ts +40 -0
  338. package/lib/Transport/session-builder.js +143 -0
  339. package/lib/Transport/session-cipher.d.ts +26 -0
  340. package/lib/Transport/session-cipher.js +301 -0
  341. package/lib/Transport/session-record.d.ts +55 -0
  342. package/lib/Transport/session-record.js +272 -0
  343. package/lib/Types/Auth.d.ts +1 -0
  344. package/lib/Types/Auth.js +1 -0
  345. package/lib/Types/Bussines.d.ts +1 -0
  346. package/lib/Types/Bussines.js +1 -0
  347. package/lib/Types/Call.d.ts +1 -0
  348. package/lib/Types/Call.js +1 -0
  349. package/lib/Types/Chat.d.ts +1 -0
  350. package/lib/Types/Chat.js +7 -0
  351. package/lib/Types/Contact.d.ts +1 -0
  352. package/lib/Types/Contact.js +1 -0
  353. package/lib/Types/Events.d.ts +1 -0
  354. package/lib/Types/Events.js +1 -0
  355. package/lib/Types/GroupMetadata.d.ts +1 -0
  356. package/lib/Types/GroupMetadata.js +1 -0
  357. package/lib/Types/Label.d.ts +2 -0
  358. package/lib/Types/Label.js +24 -0
  359. package/lib/Types/LabelAssociation.d.ts +2 -0
  360. package/lib/Types/LabelAssociation.js +6 -0
  361. package/lib/Types/Message.d.ts +11 -0
  362. package/lib/Types/Message.js +17 -0
  363. package/lib/Types/Mex.d.ts +2 -0
  364. package/lib/Types/Mex.js +38 -0
  365. package/lib/Types/Product.d.ts +1 -0
  366. package/lib/Types/Product.js +1 -0
  367. package/lib/Types/RichType.d.ts +2 -0
  368. package/lib/Types/RichType.js +22 -0
  369. package/lib/Types/Signal.d.ts +1 -0
  370. package/lib/Types/Signal.js +1 -0
  371. package/lib/Types/Socket.d.ts +1 -0
  372. package/lib/Types/Socket.js +1 -0
  373. package/lib/Types/State.d.ts +5 -0
  374. package/lib/Types/State.js +54 -0
  375. package/lib/Types/USync.d.ts +1 -0
  376. package/lib/Types/USync.js +1 -0
  377. package/lib/Types/index.d.ts +13 -0
  378. package/lib/Types/index.js +25 -0
  379. package/lib/Utils/auth-utils.d.ts +58 -0
  380. package/lib/Utils/auth-utils.js +316 -0
  381. package/lib/Utils/browser-utils.d.ts +9 -0
  382. package/lib/Utils/browser-utils.js +28 -0
  383. package/lib/Utils/business.d.ts +49 -0
  384. package/lib/Utils/business.js +230 -0
  385. package/lib/Utils/chat-utils.d.ts +408 -0
  386. package/lib/Utils/chat-utils.js +871 -0
  387. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  388. package/lib/Utils/companion-reg-client-utils.js +39 -0
  389. package/lib/Utils/crypto.d.ts +39 -0
  390. package/lib/Utils/crypto.js +117 -0
  391. package/lib/Utils/decode-wa-message.d.ts +83 -0
  392. package/lib/Utils/decode-wa-message.js +316 -0
  393. package/lib/Utils/event-buffer.d.ts +12 -0
  394. package/lib/Utils/event-buffer.js +621 -0
  395. package/lib/Utils/generics.d.ts +63 -0
  396. package/lib/Utils/generics.js +394 -0
  397. package/lib/Utils/history.d.ts +75 -0
  398. package/lib/Utils/history.js +133 -0
  399. package/lib/Utils/identity-change-handler.d.ts +13 -0
  400. package/lib/Utils/identity-change-handler.js +48 -0
  401. package/lib/Utils/index.d.ts +24 -0
  402. package/lib/Utils/index.js +24 -0
  403. package/lib/Utils/link-preview.d.ts +13 -0
  404. package/lib/Utils/link-preview.js +73 -0
  405. package/lib/Utils/logger.d.ts +12 -0
  406. package/lib/Utils/logger.js +12 -0
  407. package/lib/Utils/lt-hash.d.ts +6 -0
  408. package/lib/Utils/lt-hash.js +7 -0
  409. package/lib/Utils/make-mutex.d.ts +6 -0
  410. package/lib/Utils/make-mutex.js +32 -0
  411. package/lib/Utils/message-retry-manager.d.ts +79 -0
  412. package/lib/Utils/message-retry-manager.js +259 -0
  413. package/lib/Utils/messages-media.d.ts +134 -0
  414. package/lib/Utils/messages-media.js +802 -0
  415. package/lib/Utils/messages.d.ts +47 -0
  416. package/lib/Utils/messages.js +1911 -0
  417. package/lib/Utils/noise-handler.d.ts +20 -0
  418. package/lib/Utils/noise-handler.js +200 -0
  419. package/lib/Utils/offline-node-processor.d.ts +10 -0
  420. package/lib/Utils/offline-node-processor.js +40 -0
  421. package/lib/Utils/pre-key-manager.d.ts +25 -0
  422. package/lib/Utils/pre-key-manager.js +105 -0
  423. package/lib/Utils/process-message.d.ts +83 -0
  424. package/lib/Utils/process-message.js +748 -0
  425. package/lib/Utils/reporting-utils.d.ts +12 -0
  426. package/lib/Utils/reporting-utils.js +257 -0
  427. package/lib/Utils/rich-message-utils.d.ts +48 -0
  428. package/lib/Utils/rich-message-utils.js +369 -0
  429. package/lib/Utils/signal.d.ts +82 -0
  430. package/lib/Utils/signal.js +200 -0
  431. package/lib/Utils/stanza-ack.d.ts +16 -0
  432. package/lib/Utils/stanza-ack.js +37 -0
  433. package/lib/Utils/sync-action-utils.d.ts +2 -0
  434. package/lib/Utils/sync-action-utils.js +48 -0
  435. package/lib/Utils/tc-token-utils.d.ts +29 -0
  436. package/lib/Utils/tc-token-utils.js +163 -0
  437. package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  438. package/lib/Utils/use-multi-file-auth-state.js +116 -0
  439. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  440. package/lib/Utils/use-single-file-auth-state.js +94 -0
  441. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  442. package/lib/Utils/use-sqlite-auth-state.js +109 -0
  443. package/lib/Utils/validate-connection.d.ts +44 -0
  444. package/lib/Utils/validate-connection.js +210 -0
  445. package/lib/WABinary/constants.d.ts +61 -0
  446. package/lib/WABinary/constants.js +1466 -0
  447. package/lib/WABinary/decode.d.ts +9 -0
  448. package/lib/WABinary/decode.js +261 -0
  449. package/lib/WABinary/encode.d.ts +2 -0
  450. package/lib/WABinary/encode.js +219 -0
  451. package/lib/WABinary/generic-utils.d.ts +79 -0
  452. package/lib/WABinary/generic-utils.js +228 -0
  453. package/lib/WABinary/index.d.ts +5 -0
  454. package/lib/WABinary/index.js +5 -0
  455. package/lib/WABinary/jid-utils.d.ts +28 -0
  456. package/lib/WABinary/jid-utils.js +95 -0
  457. package/lib/WABinary/types.d.ts +1 -0
  458. package/lib/WABinary/types.js +1 -0
  459. package/lib/WACrypto/appstate-keys.js +26 -0
  460. package/lib/WACrypto/curves/constants.js +12 -0
  461. package/lib/WACrypto/hkdf.js +27 -0
  462. package/lib/WACrypto/index.js +20 -0
  463. package/lib/WACrypto/lthash.js +54 -0
  464. package/lib/WACrypto/math/constants.js +24 -0
  465. package/lib/WACrypto/math/edwards.js +194 -0
  466. package/lib/WACrypto/math/fe.js +698 -0
  467. package/lib/WACrypto/math/le.js +23 -0
  468. package/lib/WACrypto/math/mod.js +15 -0
  469. package/lib/WACrypto/util/bytes.js +339 -0
  470. package/lib/WACrypto/x25519.js +145 -0
  471. package/lib/WACrypto/xeddsa.js +92 -0
  472. package/lib/WAM/BinaryInfo.d.ts +7 -0
  473. package/lib/WAM/BinaryInfo.js +9 -0
  474. package/lib/WAM/constants.d.ts +34926 -0
  475. package/lib/WAM/constants.js +22852 -0
  476. package/lib/WAM/encode.d.ts +1 -0
  477. package/lib/WAM/encode.js +149 -0
  478. package/lib/WAM/index.d.ts +3 -0
  479. package/lib/WAM/index.js +3 -0
  480. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  481. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  482. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  483. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  484. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  485. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  486. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  487. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  488. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  489. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  490. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  491. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  492. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  493. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  494. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  495. package/lib/WAUSync/Protocols/index.js +5 -0
  496. package/lib/WAUSync/USyncQuery.d.ts +20 -0
  497. package/lib/WAUSync/USyncQuery.js +97 -0
  498. package/lib/WAUSync/USyncUser.d.ts +16 -0
  499. package/lib/WAUSync/USyncUser.js +30 -0
  500. package/lib/WAUSync/index.d.ts +3 -0
  501. package/lib/WAUSync/index.js +3 -0
  502. package/lib/index.d.ts +11 -0
  503. package/lib/index.js +11 -0
  504. package/package.json +79 -5
@@ -0,0 +1,282 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var reporting_utils_exports = {};
19
+ __export(reporting_utils_exports, {
20
+ getMessageReportingToken: () => getMessageReportingToken,
21
+ shouldIncludeReportingToken: () => shouldIncludeReportingToken
22
+ });
23
+ module.exports = __toCommonJS(reporting_utils_exports);
24
+ var import_node_crypto = require("node:crypto");
25
+ var import_WAProto = require("../../WAProto/index.js");
26
+ var import_crypto = require("./crypto.js");
27
+ const reportingFields = [
28
+ { f: 1 },
29
+ {
30
+ f: 3,
31
+ s: [{ f: 2 }, { f: 3 }, { f: 8 }, { f: 11 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 25 }]
32
+ },
33
+ { f: 4, s: [{ f: 1 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
34
+ { f: 5, s: [{ f: 3 }, { f: 4 }, { f: 5 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
35
+ { f: 6, s: [{ f: 1 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 30 }] },
36
+ { f: 7, s: [{ f: 2 }, { f: 7 }, { f: 10 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
37
+ { f: 8, s: [{ f: 2 }, { f: 7 }, { f: 9 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 21 }] },
38
+ { f: 9, s: [{ f: 2 }, { f: 6 }, { f: 7 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
39
+ { f: 12, s: [{ f: 1 }, { f: 2 }, { f: 14, m: true }, { f: 15 }] },
40
+ { f: 18, s: [{ f: 6 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
41
+ { f: 26, s: [{ f: 4 }, { f: 5 }, { f: 8 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
42
+ { f: 28, s: [{ f: 1 }, { f: 2 }, { f: 4 }, { f: 5 }, { f: 6 }, { f: 7, s: [{ f: 21 }, { f: 22 }] }] },
43
+ { f: 37, s: [{ f: 1, m: true }] },
44
+ {
45
+ f: 49,
46
+ s: [
47
+ { f: 2 },
48
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
49
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
50
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
51
+ ]
52
+ },
53
+ { f: 53, s: [{ f: 1, m: true }] },
54
+ { f: 55, s: [{ f: 1, m: true }] },
55
+ { f: 58, s: [{ f: 1, m: true }] },
56
+ { f: 59, s: [{ f: 1, m: true }] },
57
+ {
58
+ f: 60,
59
+ s: [
60
+ { f: 2 },
61
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
62
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
63
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
64
+ ]
65
+ },
66
+ {
67
+ f: 64,
68
+ s: [
69
+ { f: 2 },
70
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
71
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
72
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
73
+ ]
74
+ },
75
+ { f: 66, s: [{ f: 2 }, { f: 6 }, { f: 7 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
76
+ { f: 74, s: [{ f: 1, m: true }] },
77
+ { f: 87, s: [{ f: 1, m: true }] },
78
+ { f: 88, s: [{ f: 1 }, { f: 2, s: [{ f: 1 }] }, { f: 3, s: [{ f: 21 }, { f: 22 }] }] },
79
+ { f: 92, s: [{ f: 1, m: true }] },
80
+ { f: 93, s: [{ f: 1, m: true }] },
81
+ { f: 94, s: [{ f: 1, m: true }] }
82
+ ];
83
+ const compileReportingFields = (fields) => {
84
+ const map = /* @__PURE__ */ new Map();
85
+ for (const f of fields) {
86
+ map.set(f.f, {
87
+ m: f.m,
88
+ children: f.s ? compileReportingFields(f.s) : void 0
89
+ });
90
+ }
91
+ return map;
92
+ };
93
+ const compiledReportingFields = compileReportingFields(reportingFields);
94
+ const EMPTY_MAP = /* @__PURE__ */ new Map();
95
+ const ENC_SECRET_REPORT_TOKEN = "Report Token";
96
+ const WIRE = {
97
+ VARINT: 0,
98
+ FIXED64: 1,
99
+ BYTES: 2,
100
+ FIXED32: 5
101
+ };
102
+ const shouldIncludeReportingToken = (message) => !message.reactionMessage && !message.encReactionMessage && !message.encEventResponseMessage && !message.pollUpdateMessage;
103
+ const generateMsgSecretKey = (modificationType, origMsgId, origMsgSender, modificationSender, origMsgSecret) => {
104
+ const useCaseSecret = Buffer.concat([
105
+ Buffer.from(origMsgId, "utf8"),
106
+ Buffer.from(origMsgSender, "utf8"),
107
+ Buffer.from(modificationSender, "utf8"),
108
+ Buffer.from(modificationType, "utf8")
109
+ ]);
110
+ return (0, import_crypto.hkdf)(origMsgSecret, 32, { info: useCaseSecret.toString("latin1") });
111
+ };
112
+ const extractReportingTokenContent = (data, cfg) => {
113
+ const out = [];
114
+ let i = 0;
115
+ while (i < data.length) {
116
+ const tag = decodeVarint(data, i);
117
+ if (!tag.ok) {
118
+ return null;
119
+ }
120
+ const fieldNum = tag.value >> 3;
121
+ const wireType = tag.value & 7;
122
+ const fieldStart = i;
123
+ i += tag.bytes;
124
+ const fieldCfg = cfg.get(fieldNum);
125
+ const pushSlice = (end) => {
126
+ if (end > data.length) {
127
+ return false;
128
+ }
129
+ out.push({ num: fieldNum, bytes: data.subarray(fieldStart, end) });
130
+ i = end;
131
+ return true;
132
+ };
133
+ const skip = (end) => {
134
+ if (end > data.length) {
135
+ return false;
136
+ }
137
+ i = end;
138
+ return true;
139
+ };
140
+ if (wireType === WIRE.VARINT) {
141
+ const v = decodeVarint(data, i);
142
+ if (!v.ok) {
143
+ return null;
144
+ }
145
+ const end = i + v.bytes;
146
+ if (!fieldCfg) {
147
+ if (!skip(end)) {
148
+ return null;
149
+ }
150
+ continue;
151
+ }
152
+ if (!pushSlice(end)) {
153
+ return null;
154
+ }
155
+ continue;
156
+ }
157
+ if (wireType === WIRE.FIXED64) {
158
+ const end = i + 8;
159
+ if (!fieldCfg) {
160
+ if (!skip(end)) {
161
+ return null;
162
+ }
163
+ continue;
164
+ }
165
+ if (!pushSlice(end)) {
166
+ return null;
167
+ }
168
+ continue;
169
+ }
170
+ if (wireType === WIRE.FIXED32) {
171
+ const end = i + 4;
172
+ if (!fieldCfg) {
173
+ if (!skip(end)) {
174
+ return null;
175
+ }
176
+ continue;
177
+ }
178
+ if (!pushSlice(end)) {
179
+ return null;
180
+ }
181
+ continue;
182
+ }
183
+ if (wireType === WIRE.BYTES) {
184
+ const len = decodeVarint(data, i);
185
+ if (!len.ok) {
186
+ return null;
187
+ }
188
+ const valStart = i + len.bytes;
189
+ const valEnd = valStart + len.value;
190
+ if (valEnd > data.length) {
191
+ return null;
192
+ }
193
+ if (!fieldCfg) {
194
+ i = valEnd;
195
+ continue;
196
+ }
197
+ if (fieldCfg.m || fieldCfg.children) {
198
+ const sub = extractReportingTokenContent(data.subarray(valStart, valEnd), fieldCfg.children ?? EMPTY_MAP);
199
+ if (sub === null) {
200
+ return null;
201
+ }
202
+ if (sub.length > 0) {
203
+ const newTag = encodeVarint(tag.value);
204
+ const newLen = encodeVarint(sub.length);
205
+ out.push({
206
+ num: fieldNum,
207
+ bytes: Buffer.concat([newTag, newLen, sub])
208
+ });
209
+ }
210
+ i = valEnd;
211
+ continue;
212
+ }
213
+ out.push({ num: fieldNum, bytes: data.subarray(fieldStart, valEnd) });
214
+ i = valEnd;
215
+ continue;
216
+ }
217
+ return null;
218
+ }
219
+ if (out.length === 0) {
220
+ return Buffer.alloc(0);
221
+ }
222
+ out.sort((a, b) => a.num - b.num);
223
+ return Buffer.concat(out.map((f) => f.bytes));
224
+ };
225
+ const decodeVarint = (buffer, offset) => {
226
+ let value = 0;
227
+ let bytes = 0;
228
+ let shift = 0;
229
+ while (offset + bytes < buffer.length) {
230
+ const current = buffer[offset + bytes];
231
+ value |= (current & 127) << shift;
232
+ bytes++;
233
+ if ((current & 128) === 0) {
234
+ return { value, bytes, ok: true };
235
+ }
236
+ shift += 7;
237
+ if (shift > 35) {
238
+ return { value: 0, bytes: 0, ok: false };
239
+ }
240
+ }
241
+ return { value: 0, bytes: 0, ok: false };
242
+ };
243
+ const encodeVarint = (value) => {
244
+ const parts = [];
245
+ let remaining = value >>> 0;
246
+ while (remaining > 127) {
247
+ parts.push(remaining & 127 | 128);
248
+ remaining >>>= 7;
249
+ }
250
+ parts.push(remaining);
251
+ return Buffer.from(parts);
252
+ };
253
+ const getMessageReportingToken = async (msgProtobuf, message, key) => {
254
+ const msgSecret = message.messageContextInfo?.messageSecret;
255
+ if (!msgSecret || !key.id) {
256
+ return null;
257
+ }
258
+ const from = key.fromMe ? key.remoteJid : key.participant || key.remoteJid;
259
+ const to = key.fromMe ? key.participant || key.remoteJid : key.remoteJid;
260
+ const reportingSecret = generateMsgSecretKey(ENC_SECRET_REPORT_TOKEN, key.id, from, to, msgSecret);
261
+ const content = extractReportingTokenContent(msgProtobuf, compiledReportingFields);
262
+ if (!content || content.length === 0) {
263
+ return null;
264
+ }
265
+ const reportingToken = (0, import_node_crypto.createHmac)("sha256", reportingSecret).update(content).digest().subarray(0, 16);
266
+ return {
267
+ tag: "reporting",
268
+ attrs: {},
269
+ content: [
270
+ {
271
+ tag: "reporting_token",
272
+ attrs: { v: "2" },
273
+ content: reportingToken
274
+ }
275
+ ]
276
+ };
277
+ };
278
+ // Annotate the CommonJS export names for ESM import in node:
279
+ 0 && (module.exports = {
280
+ getMessageReportingToken,
281
+ shouldIncludeReportingToken
282
+ });
@@ -0,0 +1,48 @@
1
+ export function tokenizeCode(code: any, language?: string): {
2
+ highlightType: any;
3
+ codeContent: string | undefined;
4
+ }[];
5
+ export function toUnified(submessages: any, uuid: any): {
6
+ response_id: any;
7
+ sections: any;
8
+ };
9
+ export function prepareRichResponseMessage(content: any): {
10
+ messageContextInfo: {
11
+ botMetadata: {
12
+ verificationMetadata: {
13
+ proofs: {
14
+ certificateChain: Uint8Array<ArrayBuffer>[];
15
+ version: number;
16
+ useCase: number;
17
+ signature: Uint8Array<ArrayBuffer>;
18
+ }[];
19
+ };
20
+ };
21
+ };
22
+ botForwardedMessage: {
23
+ message: {
24
+ richResponseMessage: any;
25
+ };
26
+ };
27
+ };
28
+ export function botMetadataSignature(): Uint8Array<ArrayBuffer>;
29
+ export function botMetadataCertificate(length?: number): Uint8Array<ArrayBuffer>;
30
+ export function wrapToBotForwardedMessage(richResponseMessage: any): {
31
+ messageContextInfo: {
32
+ botMetadata: {
33
+ verificationMetadata: {
34
+ proofs: {
35
+ certificateChain: Uint8Array<ArrayBuffer>[];
36
+ version: number;
37
+ useCase: number;
38
+ signature: Uint8Array<ArrayBuffer>;
39
+ }[];
40
+ };
41
+ };
42
+ };
43
+ botForwardedMessage: {
44
+ message: {
45
+ richResponseMessage: any;
46
+ };
47
+ };
48
+ };
@@ -0,0 +1,381 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var rich_message_utils_exports = {};
19
+ __export(rich_message_utils_exports, {
20
+ botMetadataCertificate: () => botMetadataCertificate,
21
+ botMetadataSignature: () => botMetadataSignature,
22
+ prepareRichResponseMessage: () => prepareRichResponseMessage,
23
+ toUnified: () => toUnified,
24
+ tokenizeCode: () => tokenizeCode,
25
+ wrapToBotForwardedMessage: () => wrapToBotForwardedMessage
26
+ });
27
+ module.exports = __toCommonJS(rich_message_utils_exports);
28
+ var import_node_crypto = require("node:crypto");
29
+ var import_Defaults = require("../Defaults/index.js");
30
+ var import_constants = require("../WABinary/constants.js");
31
+ var import_RichType = require("../Types/RichType.js");
32
+ var import_WAProto = require("../../WAProto/index.js");
33
+ var import_generics = require("./generics.js");
34
+ const NOOP = /* @__PURE__ */ new Set([]);
35
+ const tokenizeCode = (code, language = "javascript") => {
36
+ const keywords = import_constants.LANGUAGE_KEYWORDS[language] || NOOP;
37
+ const blocks = [];
38
+ import_Defaults.LEXER_REGEX.lastIndex = 0;
39
+ let match;
40
+ while ((match = import_Defaults.LEXER_REGEX.exec(code)) !== null) {
41
+ if (match[1]) {
42
+ blocks.push({ highlightType: import_RichType.CodeHighlightType.COMMENT, codeContent: match[1] });
43
+ } else if (match[2]) {
44
+ blocks.push({ highlightType: import_RichType.CodeHighlightType.STRING, codeContent: match[2] });
45
+ } else if (match[3]) {
46
+ blocks.push({
47
+ highlightType: keywords.has(match[3]) ? import_RichType.CodeHighlightType.KEYWORD : import_RichType.CodeHighlightType.METHOD,
48
+ codeContent: match[3]
49
+ });
50
+ } else if (match[4]) {
51
+ blocks.push({
52
+ highlightType: keywords.has(match[4]) ? import_RichType.CodeHighlightType.KEYWORD : import_RichType.CodeHighlightType.DEFAULT,
53
+ codeContent: match[4]
54
+ });
55
+ } else if (match[5]) {
56
+ blocks.push({ highlightType: import_RichType.CodeHighlightType.NUMBER, codeContent: match[5] });
57
+ } else {
58
+ blocks.push({ highlightType: import_RichType.CodeHighlightType.DEFAULT, codeContent: match[6] });
59
+ }
60
+ }
61
+ return blocks;
62
+ };
63
+ const toUnified = (submessages, uuid) => ({
64
+ response_id: uuid || (0, import_node_crypto.randomUUID)(),
65
+ sections: submessages.map((submessage, index) => {
66
+ switch (submessage.messageType) {
67
+ case import_RichType.RichSubMessageType.CODE:
68
+ const codeMetadata = submessage.codeMetadata;
69
+ return {
70
+ view_model: {
71
+ primitive: {
72
+ language: codeMetadata.codeLanguage,
73
+ code_blocks: codeMetadata.codeBlocks.map((block) => ({ content: block.codeContent, type: import_RichType.CodeHighlightType[block.highlightType] })),
74
+ __typename: "GenAICodeUXPrimitive"
75
+ },
76
+ __typename: "GenAISingleLayoutViewModel"
77
+ }
78
+ };
79
+ case import_RichType.RichSubMessageType.CONTENT_ITEMS:
80
+ return {};
81
+ case import_RichType.RichSubMessageType.INLINE_IMAGE:
82
+ return {};
83
+ case import_RichType.RichSubMessageType.LATEX:
84
+ return {};
85
+ case import_RichType.RichSubMessageType.TABLE:
86
+ const tableMetadata = submessage.tableMetadata;
87
+ return {
88
+ view_model: {
89
+ primitive: {
90
+ title: tableMetadata.title,
91
+ rows: tableMetadata.rows.map((row) => ({
92
+ is_header: row.isHeading,
93
+ cells: row.items,
94
+ markdown_cells: row.items.map((item) => ({ text: item }))
95
+ })),
96
+ __typename: "GenATableUXPrimitive"
97
+ },
98
+ __typename: "GenAISingleLayoutViewModel"
99
+ }
100
+ };
101
+ case import_RichType.RichSubMessageType.TEXT:
102
+ return {
103
+ view_model: {
104
+ primitive: {
105
+ text: submessage.messageText,
106
+ inline_entities: submessage.inlineEntities || [],
107
+ __typename: "GenAIMarkdownTextUXPrimitive"
108
+ },
109
+ __typename: "GenAISingleLayoutViewModel"
110
+ }
111
+ };
112
+ }
113
+ return submessage;
114
+ })
115
+ });
116
+ const prepareRichResponseMessage = (content) => {
117
+ let { alignment, code, contentText, disclaimerText, footerText, headerText, imageText, inlineImage, inlineVideo, items, language, latex, links, noHeading, posts, products, suggested, richResponse, table, tapLinkUrl, title } = content;
118
+ let submessages = [];
119
+ if (Array.isArray(richResponse)) {
120
+ submessages = richResponse.map((submessage) => {
121
+ if (submessage.text) {
122
+ return {
123
+ messageType: import_RichType.RichSubMessageType.TEXT,
124
+ messageText: submessage.text,
125
+ inlineEntities: submessage.inlineEntities
126
+ };
127
+ } else if (submessage.code) {
128
+ return {
129
+ messageType: import_RichType.RichSubMessageType.CODE,
130
+ codeMetadata: {
131
+ codeLanguage: submessage.language,
132
+ codeBlocks: submessage.code
133
+ }
134
+ };
135
+ } else if (submessage.items) {
136
+ return {
137
+ messageType: import_RichType.RichSubMessageType.CONTENT_ITEMS,
138
+ contentItemsMetadata: {
139
+ itemsMetadata: submessage.items,
140
+ contentType: import_WAProto.proto.AIRichResponseContentItemsMetadata.ContentType.CAROUSEL
141
+ }
142
+ };
143
+ } else if (submessage.inlineImage) {
144
+ return {
145
+ messageType: import_RichType.RichSubMessageType.INLINE_IMAGE,
146
+ imageMetadata: {
147
+ imageUrl: submessage.inlineImage,
148
+ imageText: submessage.imageText,
149
+ alignment: submessage.alignment,
150
+ tapLinkUrl: submessage.tapLinkUrl
151
+ }
152
+ };
153
+ } else if (submessage.inlineVideo) {
154
+ return {
155
+ messageType: import_RichType.RichSubMessageType.TEXT,
156
+ messageText: "INLINE_VIDEO"
157
+ };
158
+ } else if (submessage.latex) {
159
+ return {
160
+ messageType: import_RichType.RichSubMessageType.LATEX,
161
+ latexMetadata: {
162
+ text: submessage.text,
163
+ expressions: submessage.latex
164
+ }
165
+ };
166
+ } else if (submessage.posts) {
167
+ return {
168
+ messageType: import_RichType.RichSubMessageType.TEXT,
169
+ messageText: "POSTS"
170
+ };
171
+ } else if (submessage.products) {
172
+ return {
173
+ messageType: import_RichType.RichSubMessageType.TEXT,
174
+ messageText: "PRODUCTS"
175
+ };
176
+ } else if (submessage.suggested) {
177
+ return {
178
+ messageType: import_RichType.RichSubMessageType.TEXT,
179
+ messageText: "SUGGESTED_PROMPT"
180
+ };
181
+ } else if (submessage.table) {
182
+ return {
183
+ messageType: import_RichType.RichSubMessageType.TABLE,
184
+ tableMetadata: {
185
+ title: submessage.title,
186
+ rows: submessage.table
187
+ }
188
+ };
189
+ }
190
+ return submessage;
191
+ });
192
+ } else {
193
+ if (headerText) {
194
+ submessages.push({
195
+ messageType: import_RichType.RichSubMessageType.TEXT,
196
+ messageText: headerText
197
+ });
198
+ }
199
+ if (contentText) {
200
+ submessages.push({
201
+ messageType: import_RichType.RichSubMessageType.TEXT,
202
+ messageText: contentText
203
+ });
204
+ }
205
+ if (code) {
206
+ language || (language = "javascript");
207
+ submessages.push({
208
+ messageType: import_RichType.RichSubMessageType.CODE,
209
+ codeMetadata: {
210
+ codeLanguage: language,
211
+ codeBlocks: tokenizeCode(code, language)
212
+ }
213
+ });
214
+ }
215
+ if (items) {
216
+ submessages.push({
217
+ messageType: import_RichType.RichSubMessageType.CONTENT_ITEMS,
218
+ contentItemsMetadata: {
219
+ itemsMetadata: items,
220
+ contentType: import_WAProto.proto.AIRichResponseContentItemsMetadata.ContentType.CAROUSEL
221
+ }
222
+ });
223
+ }
224
+ if (inlineImage) {
225
+ submessages.push({
226
+ messageType: import_RichType.RichSubMessageType.INLINE_IMAGE,
227
+ imageMetadata: {
228
+ imageUrl: inlineImage,
229
+ imageText,
230
+ alignment,
231
+ tapLinkUrl
232
+ }
233
+ });
234
+ }
235
+ if (inlineVideo) {
236
+ submessages.push({
237
+ messageType: import_RichType.RichSubMessageType.TEXT,
238
+ messageText: "INLINE_VIDEO"
239
+ });
240
+ }
241
+ if (latex) {
242
+ submessages.push({
243
+ messageType: import_RichType.RichSubMessageType.LATEX,
244
+ latexMetadata: {
245
+ text,
246
+ expressions: latex
247
+ }
248
+ });
249
+ }
250
+ if (links) {
251
+ links.forEach((linkField, index) => {
252
+ const prefix = "SS_" + index;
253
+ const url = linkField.url || import_Defaults.DONATE_URL;
254
+ const sources = linkField.sources?.map((sourceField) => ({
255
+ source_type: "THIRD_PARTY",
256
+ source_display_name: sourceField.displayName || "Donate",
257
+ source_subtitle: sourceField.subtitle || "Saweria",
258
+ source_url: sourceField.url || url
259
+ }));
260
+ submessages.push({
261
+ messageType: import_RichType.RichSubMessageType.TEXT,
262
+ messageText: linkField.text + ` {{${prefix}}}\xB9{{/${prefix}}} `,
263
+ inlineEntities: [{
264
+ key: prefix,
265
+ metadata: {
266
+ reference_id: index + 1,
267
+ reference_url: url,
268
+ reference_title: linkField.title || "For Donation via Saweria",
269
+ reference_display_name: linkField.displayName || "Donation",
270
+ sources: sources || [],
271
+ __typename: "GenAISearchCitationItem"
272
+ }
273
+ }]
274
+ });
275
+ });
276
+ }
277
+ if (posts) {
278
+ submessages.push({
279
+ messageType: import_RichType.RichSubMessageType.TEXT,
280
+ messageText: "POSTS"
281
+ });
282
+ }
283
+ if (products) {
284
+ submessages.push({
285
+ messageType: import_RichType.RichSubMessageType.TEXT,
286
+ messageText: "PRODUCTS"
287
+ });
288
+ }
289
+ if (suggested) {
290
+ submessages.push({
291
+ messageType: import_RichType.RichSubMessageType.TEXT,
292
+ messageText: "SUGGESTED_PROMPT"
293
+ });
294
+ }
295
+ if (table) {
296
+ submessages.push({
297
+ messageType: import_RichType.RichSubMessageType.TABLE,
298
+ tableMetadata: {
299
+ title,
300
+ rows: table.map((items2, index) => ({
301
+ isHeading: !noHeading && index == 0,
302
+ items: items2
303
+ }))
304
+ }
305
+ });
306
+ }
307
+ if (footerText) {
308
+ submessages.push({
309
+ messageType: import_RichType.RichSubMessageType.TEXT,
310
+ messageText: footerText
311
+ });
312
+ }
313
+ }
314
+ const uuid = (0, import_node_crypto.randomUUID)();
315
+ const unified = toUnified(submessages, uuid);
316
+ const richResponseMessage = import_WAProto.proto.AIRichResponseMessage.create({
317
+ submessages,
318
+ messageType: import_WAProto.proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
319
+ unifiedResponse: {
320
+ data: import_Defaults.TEXT_ENCODER.encode(JSON.stringify(unified))
321
+ // Lia@Note 25-04-26 --- Expects "ArrayBufferLike"
322
+ },
323
+ contextInfo: {
324
+ isForwarded: true,
325
+ forwardingScore: 1,
326
+ forwardedAiBotMessageInfo: { botJid: "867051314767696@bot" },
327
+ forwardOrigin: 4
328
+ }
329
+ });
330
+ const message = wrapToBotForwardedMessage(richResponseMessage);
331
+ const botMetadata = message.messageContextInfo.botMetadata;
332
+ if (disclaimerText) {
333
+ botMetadata.messageDisclaimerText = disclaimerText;
334
+ }
335
+ botMetadata.botResponseId = uuid;
336
+ return message;
337
+ };
338
+ const botMetadataSignature = () => {
339
+ const signature = new Uint8Array(64);
340
+ (0, import_node_crypto.getRandomValues)(signature);
341
+ return signature;
342
+ };
343
+ const botMetadataCertificate = (length = 685) => {
344
+ const certificate = new Uint8Array(length);
345
+ certificate[0] = 48;
346
+ certificate[1] = 130;
347
+ (0, import_node_crypto.getRandomValues)(certificate.subarray(2));
348
+ return certificate;
349
+ };
350
+ const wrapToBotForwardedMessage = (richResponseMessage) => ({
351
+ messageContextInfo: {
352
+ botMetadata: {
353
+ // Lia@Note 09-04-26 --- TODO: Fill verificationMetadata field
354
+ verificationMetadata: {
355
+ proofs: [
356
+ {
357
+ certificateChain: [
358
+ botMetadataCertificate(),
359
+ botMetadataCertificate(892)
360
+ ],
361
+ version: 1,
362
+ useCase: 1,
363
+ signature: botMetadataSignature()
364
+ }
365
+ ]
366
+ }
367
+ }
368
+ },
369
+ botForwardedMessage: {
370
+ message: { richResponseMessage }
371
+ }
372
+ });
373
+ // Annotate the CommonJS export names for ESM import in node:
374
+ 0 && (module.exports = {
375
+ botMetadataCertificate,
376
+ botMetadataSignature,
377
+ prepareRichResponseMessage,
378
+ toUnified,
379
+ tokenizeCode,
380
+ wrapToBotForwardedMessage
381
+ });