@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,4 @@
1
+ export const CompanionWebClientType: any;
2
+ export function getCompanionWebClientType([os, browserName]: [any, any]): any;
3
+ export function getCompanionPlatformId(browser: any): any;
4
+ export function buildPairingQRData(ref: any, noiseKeyB64: any, identityKeyB64: any, advB64: any, browser: any): string;
@@ -0,0 +1,71 @@
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 companion_reg_client_utils_exports = {};
19
+ __export(companion_reg_client_utils_exports, {
20
+ CompanionWebClientType: () => CompanionWebClientType,
21
+ buildPairingQRData: () => buildPairingQRData,
22
+ getCompanionPlatformId: () => getCompanionPlatformId,
23
+ getCompanionWebClientType: () => getCompanionWebClientType
24
+ });
25
+ module.exports = __toCommonJS(companion_reg_client_utils_exports);
26
+ var CompanionWebClientType;
27
+ (function(CompanionWebClientType2) {
28
+ CompanionWebClientType2[CompanionWebClientType2["UNKNOWN"] = 0] = "UNKNOWN";
29
+ CompanionWebClientType2[CompanionWebClientType2["CHROME"] = 1] = "CHROME";
30
+ CompanionWebClientType2[CompanionWebClientType2["EDGE"] = 2] = "EDGE";
31
+ CompanionWebClientType2[CompanionWebClientType2["FIREFOX"] = 3] = "FIREFOX";
32
+ CompanionWebClientType2[CompanionWebClientType2["IE"] = 4] = "IE";
33
+ CompanionWebClientType2[CompanionWebClientType2["OPERA"] = 5] = "OPERA";
34
+ CompanionWebClientType2[CompanionWebClientType2["SAFARI"] = 6] = "SAFARI";
35
+ CompanionWebClientType2[CompanionWebClientType2["ELECTRON"] = 7] = "ELECTRON";
36
+ CompanionWebClientType2[CompanionWebClientType2["UWP"] = 8] = "UWP";
37
+ CompanionWebClientType2[CompanionWebClientType2["OTHER_WEB_CLIENT"] = 9] = "OTHER_WEB_CLIENT";
38
+ })(CompanionWebClientType || (CompanionWebClientType = {}));
39
+ const BROWSER_TO_COMPANION_WEB_CLIENT = {
40
+ Chrome: CompanionWebClientType.CHROME,
41
+ Edge: CompanionWebClientType.EDGE,
42
+ Firefox: CompanionWebClientType.FIREFOX,
43
+ IE: CompanionWebClientType.IE,
44
+ Opera: CompanionWebClientType.OPERA,
45
+ Safari: CompanionWebClientType.SAFARI
46
+ };
47
+ const getCompanionWebClientType = ([os, browserName]) => {
48
+ if (browserName === "Desktop") {
49
+ return os === "Windows" ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON;
50
+ }
51
+ return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT;
52
+ };
53
+ const getCompanionPlatformId = (browser) => {
54
+ return getCompanionWebClientType(browser).toString();
55
+ };
56
+ const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
57
+ return "https://wa.me/settings/linked_devices#" + [
58
+ ref,
59
+ noiseKeyB64,
60
+ identityKeyB64,
61
+ advB64,
62
+ getCompanionPlatformId(browser)
63
+ ].join(",");
64
+ };
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ CompanionWebClientType,
68
+ buildPairingQRData,
69
+ getCompanionPlatformId,
70
+ getCompanionWebClientType
71
+ });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * encrypt AES 256 GCM;
3
+ * where the tag tag is suffixed to the ciphertext
4
+ * */
5
+ export function aesEncryptGCM(plaintext: any, key: any, iv: any, additionalData: any): any;
6
+ /**
7
+ * decrypt AES 256 GCM;
8
+ * where the auth tag is suffixed to the ciphertext
9
+ * */
10
+ export function aesDecryptGCM(ciphertext: any, key: any, iv: any, additionalData: any): any;
11
+ export function aesEncryptCTR(plaintext: any, key: any, iv: any): any;
12
+ export function aesDecryptCTR(ciphertext: any, key: any, iv: any): any;
13
+ /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
14
+ export function aesDecrypt(buffer: any, key: any): any;
15
+ /** decrypt AES 256 CBC */
16
+ export function aesDecryptWithIV(buffer: any, key: any, IV: any): any;
17
+ export function aesEncrypt(buffer: any, key: any): any;
18
+ export function aesEncrypWithIV(buffer: any, key: any, IV: any): any;
19
+ export function hmacSign(buffer: any, key: any, variant?: string): any;
20
+ export function sha256(buffer: any): any;
21
+ export function derivePairingCodeKey(pairingCode: any, salt: any): Promise<any>;
22
+ export function generateSignalPubKey(pubKey: any): any;
23
+ export namespace Curve {
24
+ function generateKeyPair(): {
25
+ private: any;
26
+ public: any;
27
+ };
28
+ function sharedKey(privateKey: any, publicKey: any): any;
29
+ function sign(privateKey: any, buf: any): any;
30
+ function verify(pubKey: any, message: any, signature: any): boolean;
31
+ }
32
+ export function signedKeyPair(identityKeyPair: any, keyId: any): {
33
+ keyPair: {
34
+ private: any;
35
+ public: any;
36
+ };
37
+ signature: any;
38
+ keyId: any;
39
+ };
@@ -0,0 +1,155 @@
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 crypto_exports = {};
19
+ __export(crypto_exports, {
20
+ Curve: () => Curve,
21
+ aesDecrypt: () => aesDecrypt,
22
+ aesDecryptCTR: () => aesDecryptCTR,
23
+ aesDecryptGCM: () => aesDecryptGCM,
24
+ aesDecryptWithIV: () => aesDecryptWithIV,
25
+ aesEncrypWithIV: () => aesEncrypWithIV,
26
+ aesEncrypt: () => aesEncrypt,
27
+ aesEncryptCTR: () => aesEncryptCTR,
28
+ aesEncryptGCM: () => aesEncryptGCM,
29
+ derivePairingCodeKey: () => derivePairingCodeKey,
30
+ generateSignalPubKey: () => generateSignalPubKey,
31
+ hkdf: () => import_WACrypto.hkdf,
32
+ hmacSign: () => hmacSign,
33
+ md5: () => import_WACrypto.md5,
34
+ sha256: () => sha256,
35
+ signedKeyPair: () => signedKeyPair
36
+ });
37
+ module.exports = __toCommonJS(crypto_exports);
38
+ var import_node_crypto = require("node:crypto");
39
+ var import_Defaults = require("../Defaults/index.js");
40
+ var import_Transport = require("../Transport/index.js");
41
+ var import_WACrypto = require("../WACrypto/index.js");
42
+ const { subtle } = globalThis.crypto;
43
+ const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([import_Defaults.KEY_BUNDLE_TYPE, pubKey]);
44
+ const Curve = {
45
+ generateKeyPair: () => {
46
+ const { pubKey, privKey } = import_Transport.curve.generateKeyPair();
47
+ return {
48
+ private: Buffer.from(privKey),
49
+ // remove version byte
50
+ public: Buffer.from(pubKey.slice(1))
51
+ };
52
+ },
53
+ sharedKey: (privateKey, publicKey) => {
54
+ const shared = import_Transport.curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
55
+ return Buffer.from(shared);
56
+ },
57
+ sign: (privateKey, buf) => import_Transport.curve.calculateSignature(privateKey, buf),
58
+ verify: (pubKey, message, signature) => {
59
+ try {
60
+ import_Transport.curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
61
+ return true;
62
+ } catch (error) {
63
+ return false;
64
+ }
65
+ }
66
+ };
67
+ const signedKeyPair = (identityKeyPair, keyId) => {
68
+ const preKey = Curve.generateKeyPair();
69
+ const pubKey = generateSignalPubKey(preKey.public);
70
+ const signature = Curve.sign(identityKeyPair.private, pubKey);
71
+ return { keyPair: preKey, signature, keyId };
72
+ };
73
+ const GCM_TAG_LENGTH = 128 >> 3;
74
+ function aesEncryptGCM(plaintext, key, iv, additionalData) {
75
+ const cipher = (0, import_node_crypto.createCipheriv)("aes-256-gcm", key, iv);
76
+ cipher.setAAD(additionalData);
77
+ return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
78
+ }
79
+ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
80
+ const decipher = (0, import_node_crypto.createDecipheriv)("aes-256-gcm", key, iv);
81
+ const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
82
+ const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
83
+ decipher.setAAD(additionalData);
84
+ decipher.setAuthTag(tag);
85
+ return Buffer.concat([decipher.update(enc), decipher.final()]);
86
+ }
87
+ function aesEncryptCTR(plaintext, key, iv) {
88
+ const cipher = (0, import_node_crypto.createCipheriv)("aes-256-ctr", key, iv);
89
+ return Buffer.concat([cipher.update(plaintext), cipher.final()]);
90
+ }
91
+ function aesDecryptCTR(ciphertext, key, iv) {
92
+ const decipher = (0, import_node_crypto.createDecipheriv)("aes-256-ctr", key, iv);
93
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
94
+ }
95
+ function aesDecrypt(buffer, key) {
96
+ return aesDecryptWithIV(buffer.subarray(16), key, buffer.subarray(0, 16));
97
+ }
98
+ function aesDecryptWithIV(buffer, key, IV) {
99
+ const aes = (0, import_node_crypto.createDecipheriv)("aes-256-cbc", key, IV);
100
+ return Buffer.concat([aes.update(buffer), aes.final()]);
101
+ }
102
+ function aesEncrypt(buffer, key) {
103
+ const IV = (0, import_node_crypto.randomBytes)(16);
104
+ const aes = (0, import_node_crypto.createCipheriv)("aes-256-cbc", key, IV);
105
+ return Buffer.concat([IV, aes.update(buffer), aes.final()]);
106
+ }
107
+ function aesEncrypWithIV(buffer, key, IV) {
108
+ const aes = (0, import_node_crypto.createCipheriv)("aes-256-cbc", key, IV);
109
+ return Buffer.concat([aes.update(buffer), aes.final()]);
110
+ }
111
+ function hmacSign(buffer, key, variant = "sha256") {
112
+ return (0, import_node_crypto.createHmac)(variant, key).update(buffer).digest();
113
+ }
114
+ function sha256(buffer) {
115
+ return (0, import_node_crypto.createHash)("sha256").update(buffer).digest();
116
+ }
117
+ async function derivePairingCodeKey(pairingCode, salt) {
118
+ const encoder = new TextEncoder();
119
+ const pairingCodeBuffer = encoder.encode(pairingCode);
120
+ const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
121
+ const keyMaterial = await subtle.importKey("raw", pairingCodeBuffer, { name: "PBKDF2" }, false, [
122
+ "deriveBits"
123
+ ]);
124
+ const derivedBits = await subtle.deriveBits(
125
+ {
126
+ name: "PBKDF2",
127
+ salt: saltBuffer,
128
+ iterations: 2 << 16,
129
+ hash: "SHA-256"
130
+ },
131
+ keyMaterial,
132
+ 32 * 8
133
+ // 32 bytes * 8 = 256 bits
134
+ );
135
+ return Buffer.from(derivedBits);
136
+ }
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ Curve,
140
+ aesDecrypt,
141
+ aesDecryptCTR,
142
+ aesDecryptGCM,
143
+ aesDecryptWithIV,
144
+ aesEncrypWithIV,
145
+ aesEncrypt,
146
+ aesEncryptCTR,
147
+ aesEncryptGCM,
148
+ derivePairingCodeKey,
149
+ generateSignalPubKey,
150
+ hkdf,
151
+ hmacSign,
152
+ md5,
153
+ sha256,
154
+ signedKeyPair
155
+ });
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Decode the received node as a message.
3
+ * @note this will only parse the message, not decrypt it
4
+ */
5
+ export function decodeMessageNode(stanza: any, meId: any, meLid: any): {
6
+ fullMessage: {
7
+ key: {
8
+ server_id?: any;
9
+ remoteJid: any;
10
+ remoteJidAlt: any;
11
+ remoteJidUsername: any;
12
+ fromMe: boolean;
13
+ id: any;
14
+ participant: any;
15
+ participantAlt: any;
16
+ participantUsername: any;
17
+ addressingMode: any;
18
+ };
19
+ category: any;
20
+ messageTimestamp: number;
21
+ pushName: any;
22
+ broadcast: any;
23
+ };
24
+ author: any;
25
+ sender: any;
26
+ };
27
+ export function getDecryptionJid(sender: any, repository: any): Promise<any>;
28
+ export const NO_MESSAGE_FOUND_ERROR_TEXT: "Message absent from node";
29
+ export const MISSING_KEYS_ERROR_TEXT: "Key used already or never filled";
30
+ export const ACCOUNT_RESTRICTED_TEXT: "Your account has been restricted";
31
+ export namespace DECRYPTION_RETRY_CONFIG {
32
+ let maxRetries: number;
33
+ let baseDelayMs: number;
34
+ let sessionRecordErrors: string[];
35
+ }
36
+ export namespace NACK_REASONS {
37
+ let SenderReachoutTimelocked: number;
38
+ let ParsingError: number;
39
+ let UnrecognizedStanza: number;
40
+ let UnrecognizedStanzaClass: number;
41
+ let UnrecognizedStanzaType: number;
42
+ let InvalidProtobuf: number;
43
+ let InvalidHostedCompanionStanza: number;
44
+ let MissingMessageSecret: number;
45
+ let SignalErrorOldCounter: number;
46
+ let MessageDeletedOnPeer: number;
47
+ let UnhandledError: number;
48
+ let UnsupportedAdminRevoke: number;
49
+ let UnsupportedLIDGroup: number;
50
+ let DBOperationFailed: number;
51
+ }
52
+ export namespace SERVER_ERROR_CODES {
53
+ let MessageAccountRestriction: string;
54
+ let SmaxInvalid: string;
55
+ }
56
+ export function extractAddressingContext(stanza: any): {
57
+ addressingMode: any;
58
+ senderAlt: any;
59
+ recipientAlt: any;
60
+ };
61
+ export function decryptMessageNode(stanza: any, meId: any, meLid: any, repository: any, logger: any): {
62
+ fullMessage: {
63
+ key: {
64
+ server_id?: any;
65
+ remoteJid: any;
66
+ remoteJidAlt: any;
67
+ remoteJidUsername: any;
68
+ fromMe: boolean;
69
+ id: any;
70
+ participant: any;
71
+ participantAlt: any;
72
+ participantUsername: any;
73
+ addressingMode: any;
74
+ };
75
+ category: any;
76
+ messageTimestamp: number;
77
+ pushName: any;
78
+ broadcast: any;
79
+ };
80
+ category: any;
81
+ author: any;
82
+ decrypt(): Promise<void>;
83
+ };
@@ -0,0 +1,316 @@
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 decode_wa_message_exports = {};
19
+ __export(decode_wa_message_exports, {
20
+ ACCOUNT_RESTRICTED_TEXT: () => ACCOUNT_RESTRICTED_TEXT,
21
+ DECRYPTION_RETRY_CONFIG: () => DECRYPTION_RETRY_CONFIG,
22
+ MISSING_KEYS_ERROR_TEXT: () => MISSING_KEYS_ERROR_TEXT,
23
+ NACK_REASONS: () => NACK_REASONS,
24
+ NO_MESSAGE_FOUND_ERROR_TEXT: () => NO_MESSAGE_FOUND_ERROR_TEXT,
25
+ SERVER_ERROR_CODES: () => SERVER_ERROR_CODES,
26
+ decodeMessageNode: () => decodeMessageNode,
27
+ decryptMessageNode: () => decryptMessageNode,
28
+ extractAddressingContext: () => extractAddressingContext,
29
+ getDecryptionJid: () => getDecryptionJid
30
+ });
31
+ module.exports = __toCommonJS(decode_wa_message_exports);
32
+ var import_WAProto = require("../../WAProto/index.js");
33
+ var import_Addon = require("../Addon/index.js");
34
+ var import_WABinary = require("../WABinary/index.js");
35
+ var import_generics = require("./generics.js");
36
+ const getDecryptionJid = async (sender, repository) => {
37
+ if ((0, import_WABinary.isLidUser)(sender) || (0, import_WABinary.isHostedLidUser)(sender)) {
38
+ return sender;
39
+ }
40
+ const mapped = await repository.lidMapping.getLIDForPN(sender);
41
+ return mapped || sender;
42
+ };
43
+ const storeMappingFromEnvelope = async (stanza, sender, repository, decryptionJid, logger) => {
44
+ const { senderAlt } = extractAddressingContext(stanza);
45
+ if (senderAlt && (0, import_WABinary.isLidUser)(senderAlt) && (0, import_WABinary.isPnUser)(sender) && decryptionJid === sender) {
46
+ try {
47
+ await repository.lidMapping.storeLIDPNMappings([{ lid: senderAlt, pn: sender }]);
48
+ await repository.migrateSession(sender, senderAlt);
49
+ logger.debug({ sender, senderAlt }, "Stored LID mapping from envelope");
50
+ } catch (error) {
51
+ logger.warn({ sender, senderAlt, error }, "Failed to store LID mapping");
52
+ }
53
+ }
54
+ };
55
+ const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
56
+ const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
57
+ const ACCOUNT_RESTRICTED_TEXT = "Your account has been restricted";
58
+ const DECRYPTION_RETRY_CONFIG = {
59
+ maxRetries: 3,
60
+ baseDelayMs: 100,
61
+ sessionRecordErrors: ["No session record", "SessionError: No session record"]
62
+ };
63
+ const NACK_REASONS = {
64
+ SenderReachoutTimelocked: 463,
65
+ ParsingError: 487,
66
+ UnrecognizedStanza: 488,
67
+ UnrecognizedStanzaClass: 489,
68
+ UnrecognizedStanzaType: 490,
69
+ InvalidProtobuf: 491,
70
+ InvalidHostedCompanionStanza: 493,
71
+ MissingMessageSecret: 495,
72
+ SignalErrorOldCounter: 496,
73
+ MessageDeletedOnPeer: 499,
74
+ UnhandledError: 500,
75
+ UnsupportedAdminRevoke: 550,
76
+ UnsupportedLIDGroup: 551,
77
+ DBOperationFailed: 552
78
+ };
79
+ const SERVER_ERROR_CODES = {
80
+ /**
81
+ * 1:1 message missing privacy token (tctoken). Usually means the account is
82
+ * restricted: WhatsApp blocks starting new chats but preserves existing ones,
83
+ * since established chats already carry a tctoken.
84
+ */
85
+ MessageAccountRestriction: "463",
86
+ /** Stanza validation failure (SMAX_INVALID) — likely stale device session */
87
+ SmaxInvalid: "479"
88
+ };
89
+ const extractAddressingContext = (stanza) => {
90
+ let senderAlt;
91
+ let recipientAlt;
92
+ const sender = stanza.attrs.participant || stanza.attrs.from;
93
+ const addressingMode = stanza.attrs.addressing_mode || (sender?.endsWith("lid") ? "lid" : "pn");
94
+ if (addressingMode === "lid") {
95
+ senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn;
96
+ recipientAlt = stanza.attrs.recipient_pn;
97
+ } else {
98
+ senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid;
99
+ recipientAlt = stanza.attrs.recipient_lid;
100
+ }
101
+ return {
102
+ addressingMode,
103
+ senderAlt,
104
+ recipientAlt
105
+ };
106
+ };
107
+ function decodeMessageNode(stanza, meId, meLid) {
108
+ let msgType;
109
+ let chatId;
110
+ let author;
111
+ let fromMe = false;
112
+ const msgId = stanza.attrs.id;
113
+ const from = stanza.attrs.from;
114
+ const participant = stanza.attrs.participant;
115
+ const recipient = stanza.attrs.recipient;
116
+ if (!msgId) {
117
+ throw new import_Addon.HttpError("Invalid message stanza: missing id attribute", { data: stanza });
118
+ }
119
+ if (!from) {
120
+ throw new import_Addon.HttpError("Invalid message stanza: missing from attribute", { data: stanza });
121
+ }
122
+ const addressingContext = extractAddressingContext(stanza);
123
+ const isMe = (jid) => (0, import_WABinary.areJidsSameUser)(jid, meId);
124
+ const isMeLid = (jid) => (0, import_WABinary.areJidsSameUser)(jid, meLid);
125
+ if ((0, import_WABinary.isPnUser)(from) || (0, import_WABinary.isLidUser)(from) || (0, import_WABinary.isHostedLidUser)(from) || (0, import_WABinary.isHostedPnUser)(from)) {
126
+ if (recipient && !(0, import_WABinary.isJidMetaAI)(recipient)) {
127
+ if (!isMe(from) && !isMeLid(from)) {
128
+ throw new import_Addon.HttpError("receipient present, but msg not from me", { data: stanza });
129
+ }
130
+ if (isMe(from) || isMeLid(from)) {
131
+ fromMe = true;
132
+ }
133
+ chatId = recipient;
134
+ } else {
135
+ if (isMe(from) || isMeLid(from)) {
136
+ fromMe = true;
137
+ }
138
+ chatId = from;
139
+ }
140
+ msgType = "chat";
141
+ author = from;
142
+ } else if ((0, import_WABinary.isJidGroup)(from)) {
143
+ if (!participant) {
144
+ throw new import_Addon.HttpError("No participant in group message");
145
+ }
146
+ if (isMe(participant) || isMeLid(participant)) {
147
+ fromMe = true;
148
+ }
149
+ msgType = "group";
150
+ author = participant;
151
+ chatId = from;
152
+ } else if ((0, import_WABinary.isJidBroadcast)(from)) {
153
+ if (!participant) {
154
+ throw new import_Addon.HttpError("No participant in group message");
155
+ }
156
+ const isParticipantMe = isMe(participant);
157
+ if ((0, import_WABinary.isJidStatusBroadcast)(from)) {
158
+ msgType = isParticipantMe ? "direct_peer_status" : "other_status";
159
+ } else {
160
+ msgType = isParticipantMe ? "peer_broadcast" : "other_broadcast";
161
+ }
162
+ fromMe = isParticipantMe;
163
+ chatId = from;
164
+ author = participant;
165
+ } else if ((0, import_WABinary.isJidNewsletter)(from)) {
166
+ msgType = "newsletter";
167
+ chatId = from;
168
+ author = from;
169
+ if (isMe(from) || isMeLid(from)) {
170
+ fromMe = true;
171
+ }
172
+ } else {
173
+ throw new import_Addon.HttpError("Unknown message type", { data: stanza });
174
+ }
175
+ const pushname = stanza?.attrs?.notify;
176
+ const key = {
177
+ remoteJid: chatId,
178
+ remoteJidAlt: !(0, import_WABinary.isJidGroup)(chatId) ? addressingContext.senderAlt : void 0,
179
+ remoteJidUsername: !(0, import_WABinary.isJidGroup)(chatId) ? stanza.attrs.peer_recipient_username || stanza.attrs.recipient_username : void 0,
180
+ fromMe,
181
+ id: msgId,
182
+ participant,
183
+ participantAlt: (0, import_WABinary.isJidGroup)(chatId) ? addressingContext.senderAlt : void 0,
184
+ participantUsername: stanza.attrs.participant ? stanza.attrs.participant_username : void 0,
185
+ addressingMode: addressingContext.addressingMode,
186
+ ...msgType === "newsletter" && stanza.attrs.server_id ? { server_id: stanza.attrs.server_id } : {}
187
+ };
188
+ const fullMessage = {
189
+ key,
190
+ category: stanza.attrs.category,
191
+ messageTimestamp: +stanza.attrs.t,
192
+ pushName: pushname,
193
+ broadcast: (0, import_WABinary.isJidBroadcast)(from)
194
+ };
195
+ if (key.fromMe) {
196
+ fullMessage.status = import_WAProto.proto.WebMessageInfo.Status.SERVER_ACK;
197
+ }
198
+ return {
199
+ fullMessage,
200
+ author,
201
+ sender: msgType === "chat" ? author : chatId
202
+ };
203
+ }
204
+ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
205
+ const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
206
+ return {
207
+ fullMessage,
208
+ category: stanza.attrs.category,
209
+ author,
210
+ async decrypt() {
211
+ let decryptables = 0;
212
+ if (Array.isArray(stanza.content)) {
213
+ for (const { tag, attrs, content } of stanza.content) {
214
+ if (tag === "verified_name" && content instanceof Uint8Array) {
215
+ const cert = import_WAProto.proto.VerifiedNameCertificate.decode(content);
216
+ const details = import_WAProto.proto.VerifiedNameCertificate.Details.decode(cert.details);
217
+ fullMessage.verifiedBizName = details.verifiedName;
218
+ }
219
+ if (tag === "unavailable" && attrs.type === "view_once") {
220
+ fullMessage.key.isViewOnce = true;
221
+ }
222
+ if (attrs.count && tag === "enc") {
223
+ fullMessage.retryCount = Number(attrs.count);
224
+ }
225
+ if (tag !== "enc" && tag !== "plaintext") {
226
+ continue;
227
+ }
228
+ if (!(content instanceof Uint8Array)) {
229
+ continue;
230
+ }
231
+ decryptables += 1;
232
+ let msgBuffer;
233
+ const decryptionJid = await getDecryptionJid(author, repository);
234
+ if (tag !== "plaintext") {
235
+ await storeMappingFromEnvelope(stanza, author, repository, decryptionJid, logger);
236
+ }
237
+ try {
238
+ const e2eType = tag === "plaintext" ? "plaintext" : attrs.type;
239
+ switch (e2eType) {
240
+ case "skmsg":
241
+ msgBuffer = await repository.decryptGroupMessage({
242
+ group: sender,
243
+ authorJid: author,
244
+ msg: content
245
+ });
246
+ break;
247
+ case "pkmsg":
248
+ case "msg":
249
+ msgBuffer = await repository.decryptMessage({
250
+ jid: decryptionJid,
251
+ type: e2eType,
252
+ ciphertext: content
253
+ });
254
+ break;
255
+ case "plaintext":
256
+ msgBuffer = content;
257
+ break;
258
+ default:
259
+ throw new Error(`Unknown e2e type: ${e2eType}`);
260
+ }
261
+ let msg = import_WAProto.proto.Message.decode(e2eType !== "plaintext" ? (0, import_generics.unpadRandomMax16)(msgBuffer) : msgBuffer);
262
+ msg = msg.deviceSentMessage?.message || msg;
263
+ if (msg.senderKeyDistributionMessage) {
264
+ try {
265
+ await repository.processSenderKeyDistributionMessage({
266
+ authorJid: author,
267
+ item: msg.senderKeyDistributionMessage
268
+ });
269
+ } catch (err) {
270
+ logger.error({ key: fullMessage.key, err }, "failed to process sender key distribution message");
271
+ }
272
+ }
273
+ if (fullMessage.message) {
274
+ Object.assign(fullMessage.message, msg);
275
+ } else {
276
+ fullMessage.message = msg;
277
+ }
278
+ } catch (err) {
279
+ const errorContext = {
280
+ key: fullMessage.key,
281
+ err,
282
+ messageType: tag === "plaintext" ? "plaintext" : attrs.type,
283
+ sender,
284
+ author,
285
+ isSessionRecordError: isSessionRecordError(err)
286
+ };
287
+ logger.error(errorContext, "failed to decrypt message");
288
+ fullMessage.messageStubType = import_WAProto.proto.WebMessageInfo.StubType.CIPHERTEXT;
289
+ fullMessage.messageStubParameters = [err.message.toString()];
290
+ }
291
+ }
292
+ }
293
+ if (!decryptables && !fullMessage.key?.isViewOnce) {
294
+ fullMessage.messageStubType = import_WAProto.proto.WebMessageInfo.StubType.CIPHERTEXT;
295
+ fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT];
296
+ }
297
+ }
298
+ };
299
+ };
300
+ function isSessionRecordError(error) {
301
+ const errorMessage = error?.message || error?.toString() || "";
302
+ return DECRYPTION_RETRY_CONFIG.sessionRecordErrors.some((errorPattern) => errorMessage.includes(errorPattern));
303
+ }
304
+ // Annotate the CommonJS export names for ESM import in node:
305
+ 0 && (module.exports = {
306
+ ACCOUNT_RESTRICTED_TEXT,
307
+ DECRYPTION_RETRY_CONFIG,
308
+ MISSING_KEYS_ERROR_TEXT,
309
+ NACK_REASONS,
310
+ NO_MESSAGE_FOUND_ERROR_TEXT,
311
+ SERVER_ERROR_CODES,
312
+ decodeMessageNode,
313
+ decryptMessageNode,
314
+ extractAddressingContext,
315
+ getDecryptionJid
316
+ });
@@ -0,0 +1,12 @@
1
+ export function makeEventBuffer(logger: any): {
2
+ process(handler: any): () => void;
3
+ emit(event: any, evData: any): any;
4
+ isBuffering(): boolean;
5
+ buffer: () => void;
6
+ flush: () => boolean;
7
+ createBufferedFunction(work: any): (...args: any[]) => Promise<any>;
8
+ on: (...args: any[]) => any;
9
+ off: (...args: any[]) => any;
10
+ removeAllListeners: (...args: any[]) => any;
11
+ destroy(): void;
12
+ };