@vanzxysenpai/baileys 0.0.0-stage → 0.0.2

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 (431) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +25 -0
  3. package/NOTICE.md +158 -0
  4. package/README.md +5294 -2
  5. package/VanzxyBanner.js +134 -0
  6. package/WAProto/index.d.ts +13317 -0
  7. package/WAProto/index.js +147553 -0
  8. package/lib/Builders/A2UI.d.ts +131 -0
  9. package/lib/Builders/A2UI.js +343 -0
  10. package/lib/Builders/AIRich.d.ts +1021 -0
  11. package/lib/Builders/AIRich.js +2889 -0
  12. package/lib/Builders/Album.d.ts +51 -0
  13. package/lib/Builders/Album.js +99 -0
  14. package/lib/Builders/Button.d.ts +137449 -0
  15. package/lib/Builders/Button.js +1054 -0
  16. package/lib/Builders/ButtonV2.d.ts +43 -0
  17. package/lib/Builders/ButtonV2.js +175 -0
  18. package/lib/Builders/ButtonV3.d.ts +35 -0
  19. package/lib/Builders/ButtonV3.js +189 -0
  20. package/lib/Builders/Carousel.d.ts +68 -0
  21. package/lib/Builders/Carousel.js +161 -0
  22. package/lib/Builders/Event.d.ts +61 -0
  23. package/lib/Builders/Event.js +118 -0
  24. package/lib/Builders/Expiring.d.ts +17 -0
  25. package/lib/Builders/Expiring.js +27 -0
  26. package/lib/Builders/Poll.d.ts +63 -0
  27. package/lib/Builders/Poll.js +139 -0
  28. package/lib/Builders/VanzxyBaileys.d.ts +42 -0
  29. package/lib/Builders/VanzxyBaileys.js +110 -0
  30. package/lib/Builders/errors.d.ts +25 -0
  31. package/lib/Builders/errors.js +29 -0
  32. package/lib/Builders/index.d.ts +14 -0
  33. package/lib/Builders/index.js +23 -0
  34. package/lib/Builders/shared.d.ts +395 -0
  35. package/lib/Builders/shared.js +738 -0
  36. package/lib/Defaults/bot-jid.d.ts +1 -0
  37. package/lib/Defaults/bot-jid.js +1 -0
  38. package/lib/Defaults/index.d.ts +161 -0
  39. package/lib/Defaults/index.js +165 -0
  40. package/lib/Defaults/version.d.ts +1 -0
  41. package/lib/Defaults/version.js +1 -0
  42. package/lib/Framework/Bot.d.ts +865 -0
  43. package/lib/Framework/Bot.js +230 -0
  44. package/lib/Framework/Context.d.ts +17 -0
  45. package/lib/Framework/Context.js +90 -0
  46. package/lib/Framework/MediaManager.d.ts +15 -0
  47. package/lib/Framework/MediaManager.js +154 -0
  48. package/lib/Framework/SessionManager.d.ts +10 -0
  49. package/lib/Framework/SessionManager.js +34 -0
  50. package/lib/Framework/StatsManager.d.ts +20 -0
  51. package/lib/Framework/StatsManager.js +117 -0
  52. package/lib/Framework/Store/SQLiteStore.d.ts +13 -0
  53. package/lib/Framework/Store/SQLiteStore.js +68 -0
  54. package/lib/Framework/index.d.ts +6 -0
  55. package/lib/Framework/index.js +11 -0
  56. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  57. package/lib/Signal/Group/ciphertext-message.js +11 -0
  58. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  59. package/lib/Signal/Group/group-session-builder.js +29 -0
  60. package/lib/Signal/Group/group_cipher.d.ts +10 -0
  61. package/lib/Signal/Group/group_cipher.js +81 -0
  62. package/lib/Signal/Group/index.d.ts +11 -0
  63. package/lib/Signal/Group/index.js +11 -0
  64. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  65. package/lib/Signal/Group/keyhelper.js +17 -0
  66. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  67. package/lib/Signal/Group/sender-chain-key.js +25 -0
  68. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  69. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  70. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  71. package/lib/Signal/Group/sender-key-message.js +65 -0
  72. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  73. package/lib/Signal/Group/sender-key-name.js +47 -0
  74. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  75. package/lib/Signal/Group/sender-key-record.js +40 -0
  76. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  77. package/lib/Signal/Group/sender-key-state.js +83 -0
  78. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  79. package/lib/Signal/Group/sender-message-key.js +25 -0
  80. package/lib/Signal/libsignal.d.ts +58 -0
  81. package/lib/Signal/libsignal.js +436 -0
  82. package/lib/Signal/lid-mapping.d.ts +20 -0
  83. package/lib/Signal/lid-mapping.js +276 -0
  84. package/lib/Socket/Client/index.d.ts +2 -0
  85. package/lib/Socket/Client/index.js +2 -0
  86. package/lib/Socket/Client/types.d.ts +5 -0
  87. package/lib/Socket/Client/types.js +10 -0
  88. package/lib/Socket/Client/websocket.d.ts +12 -0
  89. package/lib/Socket/Client/websocket.js +53 -0
  90. package/lib/Socket/business.d.ts +674 -0
  91. package/lib/Socket/business.js +379 -0
  92. package/lib/Socket/chats.d.ts +137 -0
  93. package/lib/Socket/chats.js +1299 -0
  94. package/lib/Socket/communities.d.ts +805 -0
  95. package/lib/Socket/communities.js +454 -0
  96. package/lib/Socket/dugong.d.ts +118 -0
  97. package/lib/Socket/dugong.js +810 -0
  98. package/lib/Socket/groups.d.ts +287 -0
  99. package/lib/Socket/groups.js +386 -0
  100. package/lib/Socket/index.d.ts +826 -0
  101. package/lib/Socket/index.js +35 -0
  102. package/lib/Socket/messages-recv.d.ts +613 -0
  103. package/lib/Socket/messages-recv.js +1851 -0
  104. package/lib/Socket/messages-send.d.ts +608 -0
  105. package/lib/Socket/messages-send.js +1574 -0
  106. package/lib/Socket/mex-fallback.d.ts +51 -0
  107. package/lib/Socket/mex-fallback.js +97 -0
  108. package/lib/Socket/mex.d.ts +1 -0
  109. package/lib/Socket/mex.js +41 -0
  110. package/lib/Socket/newsletter-ext.d.ts +47 -0
  111. package/lib/Socket/newsletter-ext.js +262 -0
  112. package/lib/Socket/newsletter.d.ts +285 -0
  113. package/lib/Socket/newsletter.js +223 -0
  114. package/lib/Socket/socket.d.ts +60 -0
  115. package/lib/Socket/socket.js +1001 -0
  116. package/lib/Socket/username.d.ts +842 -0
  117. package/lib/Socket/username.js +156 -0
  118. package/lib/Store/index.d.ts +3 -0
  119. package/lib/Store/index.js +3 -0
  120. package/lib/Store/make-in-memory-store.d.ts +62 -0
  121. package/lib/Store/make-in-memory-store.js +425 -0
  122. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  123. package/lib/Store/make-ordered-dictionary.js +78 -0
  124. package/lib/Store/object-repository.d.ts +10 -0
  125. package/lib/Store/object-repository.js +23 -0
  126. package/lib/Types/Auth.d.ts +1 -0
  127. package/lib/Types/Auth.js +1 -0
  128. package/lib/Types/Bussines.d.ts +1 -0
  129. package/lib/Types/Bussines.js +1 -0
  130. package/lib/Types/Call.d.ts +1 -0
  131. package/lib/Types/Call.js +1 -0
  132. package/lib/Types/Chat.d.ts +1 -0
  133. package/lib/Types/Chat.js +7 -0
  134. package/lib/Types/Contact.d.ts +1 -0
  135. package/lib/Types/Contact.js +1 -0
  136. package/lib/Types/Events.d.ts +1 -0
  137. package/lib/Types/Events.js +1 -0
  138. package/lib/Types/GroupMetadata.d.ts +1 -0
  139. package/lib/Types/GroupMetadata.js +1 -0
  140. package/lib/Types/Label.d.ts +2 -0
  141. package/lib/Types/Label.js +24 -0
  142. package/lib/Types/LabelAssociation.d.ts +2 -0
  143. package/lib/Types/LabelAssociation.js +6 -0
  144. package/lib/Types/Message.d.ts +11 -0
  145. package/lib/Types/Message.js +17 -0
  146. package/lib/Types/Mex.d.ts +2 -0
  147. package/lib/Types/Mex.js +38 -0
  148. package/lib/Types/Product.d.ts +1 -0
  149. package/lib/Types/Product.js +1 -0
  150. package/lib/Types/RichType.d.ts +2 -0
  151. package/lib/Types/RichType.js +22 -0
  152. package/lib/Types/Signal.d.ts +1 -0
  153. package/lib/Types/Signal.js +1 -0
  154. package/lib/Types/Socket.d.ts +1 -0
  155. package/lib/Types/Socket.js +1 -0
  156. package/lib/Types/State.d.ts +5 -0
  157. package/lib/Types/State.js +55 -0
  158. package/lib/Types/USync.d.ts +1 -0
  159. package/lib/Types/USync.js +1 -0
  160. package/lib/Types/index.d.ts +15 -0
  161. package/lib/Types/index.js +27 -0
  162. package/lib/Utils/PersistentStore.d.ts +83 -0
  163. package/lib/Utils/PersistentStore.js +592 -0
  164. package/lib/Utils/anchor-guard.d.ts +31 -0
  165. package/lib/Utils/anchor-guard.js +329 -0
  166. package/lib/Utils/android-stanza-id.d.ts +4 -0
  167. package/lib/Utils/android-stanza-id.js +21 -0
  168. package/lib/Utils/anti-delete.d.ts +62 -0
  169. package/lib/Utils/anti-delete.js +212 -0
  170. package/lib/Utils/auth-secure.d.ts +180 -0
  171. package/lib/Utils/auth-secure.js +791 -0
  172. package/lib/Utils/auth-utils.d.ts +59 -0
  173. package/lib/Utils/auth-utils.js +326 -0
  174. package/lib/Utils/auto-reconnect.d.ts +8 -0
  175. package/lib/Utils/auto-reconnect.js +204 -0
  176. package/lib/Utils/auto-reply.d.ts +35 -0
  177. package/lib/Utils/auto-reply.js +152 -0
  178. package/lib/Utils/bad-mac-handler.d.ts +59 -0
  179. package/lib/Utils/bad-mac-handler.js +119 -0
  180. package/lib/Utils/baileys-event-stream.d.ts +5 -0
  181. package/lib/Utils/baileys-event-stream.js +62 -0
  182. package/lib/Utils/browser-utils.d.ts +9 -0
  183. package/lib/Utils/browser-utils.js +29 -0
  184. package/lib/Utils/business.d.ts +49 -0
  185. package/lib/Utils/business.js +236 -0
  186. package/lib/Utils/button-helper-utils.d.ts +59 -0
  187. package/lib/Utils/button-helper-utils.js +266 -0
  188. package/lib/Utils/button-sender.d.ts +164 -0
  189. package/lib/Utils/button-sender.js +845 -0
  190. package/lib/Utils/chat-control.d.ts +98 -0
  191. package/lib/Utils/chat-control.js +231 -0
  192. package/lib/Utils/chat-history-helpers.d.ts +4 -0
  193. package/lib/Utils/chat-history-helpers.js +70 -0
  194. package/lib/Utils/chat-utils.d.ts +408 -0
  195. package/lib/Utils/chat-utils.js +879 -0
  196. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  197. package/lib/Utils/companion-reg-client-utils.js +39 -0
  198. package/lib/Utils/connection-watchdog.d.ts +10 -0
  199. package/lib/Utils/connection-watchdog.js +74 -0
  200. package/lib/Utils/crypto.d.ts +41 -0
  201. package/lib/Utils/crypto.js +145 -0
  202. package/lib/Utils/decode-wa-message.d.ts +83 -0
  203. package/lib/Utils/decode-wa-message.js +315 -0
  204. package/lib/Utils/disconnect-reason.d.ts +13 -0
  205. package/lib/Utils/disconnect-reason.js +36 -0
  206. package/lib/Utils/event-buffer.d.ts +12 -0
  207. package/lib/Utils/event-buffer.js +640 -0
  208. package/lib/Utils/fetch-timeout.d.ts +4 -0
  209. package/lib/Utils/fetch-timeout.js +14 -0
  210. package/lib/Utils/ffmpeg-path.d.ts +5 -0
  211. package/lib/Utils/ffmpeg-path.js +130 -0
  212. package/lib/Utils/generics.d.ts +79 -0
  213. package/lib/Utils/generics.js +426 -0
  214. package/lib/Utils/group-metadata-cache.d.ts +3 -0
  215. package/lib/Utils/group-metadata-cache.js +25 -0
  216. package/lib/Utils/group-status-detection.d.ts +5 -0
  217. package/lib/Utils/group-status-detection.js +114 -0
  218. package/lib/Utils/history.d.ts +91 -0
  219. package/lib/Utils/history.js +144 -0
  220. package/lib/Utils/html-app.d.ts +14 -0
  221. package/lib/Utils/html-app.js +97 -0
  222. package/lib/Utils/html-multiplayer.d.ts +8 -0
  223. package/lib/Utils/html-multiplayer.js +90 -0
  224. package/lib/Utils/humanizer.d.ts +8 -0
  225. package/lib/Utils/humanizer.js +74 -0
  226. package/lib/Utils/identity-change-handler.d.ts +13 -0
  227. package/lib/Utils/identity-change-handler.js +49 -0
  228. package/lib/Utils/index.d.ts +88 -0
  229. package/lib/Utils/index.js +93 -0
  230. package/lib/Utils/jid-tools.d.ts +3 -0
  231. package/lib/Utils/jid-tools.js +78 -0
  232. package/lib/Utils/link-preview-metadata.d.ts +47 -0
  233. package/lib/Utils/link-preview-metadata.js +90 -0
  234. package/lib/Utils/link-preview.d.ts +12 -0
  235. package/lib/Utils/link-preview.js +84 -0
  236. package/lib/Utils/lock-manager.d.ts +5 -0
  237. package/lib/Utils/lock-manager.js +50 -0
  238. package/lib/Utils/logger.d.ts +2 -0
  239. package/lib/Utils/logger.js +2 -0
  240. package/lib/Utils/lt-hash.d.ts +12 -0
  241. package/lib/Utils/lt-hash.js +26 -0
  242. package/lib/Utils/make-mutex.d.ts +6 -0
  243. package/lib/Utils/make-mutex.js +32 -0
  244. package/lib/Utils/media-messages.d.ts +35 -0
  245. package/lib/Utils/media-messages.js +70 -0
  246. package/lib/Utils/media-processor.d.ts +6 -0
  247. package/lib/Utils/media-processor.js +174 -0
  248. package/lib/Utils/media-set.d.ts +6 -0
  249. package/lib/Utils/media-set.js +169 -0
  250. package/lib/Utils/message-kind.d.ts +26 -0
  251. package/lib/Utils/message-kind.js +138 -0
  252. package/lib/Utils/message-retry-manager.d.ts +79 -0
  253. package/lib/Utils/message-retry-manager.js +264 -0
  254. package/lib/Utils/message-search.d.ts +40 -0
  255. package/lib/Utils/message-search.js +181 -0
  256. package/lib/Utils/messages-media.d.ts +136 -0
  257. package/lib/Utils/messages-media.js +867 -0
  258. package/lib/Utils/messages.d.ts +66 -0
  259. package/lib/Utils/messages.js +2271 -0
  260. package/lib/Utils/meta-ai-msmsg.d.ts +3 -0
  261. package/lib/Utils/meta-ai-msmsg.js +132 -0
  262. package/lib/Utils/meta-ai.d.ts +4 -0
  263. package/lib/Utils/meta-ai.js +75 -0
  264. package/lib/Utils/migrate-auth-state.d.ts +23 -0
  265. package/lib/Utils/migrate-auth-state.js +126 -0
  266. package/lib/Utils/mini-app.d.ts +20 -0
  267. package/lib/Utils/mini-app.js +215 -0
  268. package/lib/Utils/mock-socket.d.ts +67 -0
  269. package/lib/Utils/mock-socket.js +254 -0
  270. package/lib/Utils/modern-messages.d.ts +64 -0
  271. package/lib/Utils/modern-messages.js +497 -0
  272. package/lib/Utils/native-flow.d.ts +19 -0
  273. package/lib/Utils/native-flow.js +112 -0
  274. package/lib/Utils/newsletter-status.d.ts +157 -0
  275. package/lib/Utils/newsletter-status.js +652 -0
  276. package/lib/Utils/noise-handler.d.ts +20 -0
  277. package/lib/Utils/noise-handler.js +200 -0
  278. package/lib/Utils/offline-node-processor.d.ts +9 -0
  279. package/lib/Utils/offline-node-processor.js +39 -0
  280. package/lib/Utils/pairing-utils.d.ts +5 -0
  281. package/lib/Utils/pairing-utils.js +29 -0
  282. package/lib/Utils/passkey.d.ts +4 -0
  283. package/lib/Utils/passkey.js +11 -0
  284. package/lib/Utils/past-participants.d.ts +2 -0
  285. package/lib/Utils/past-participants.js +40 -0
  286. package/lib/Utils/payment-detection.d.ts +40 -0
  287. package/lib/Utils/payment-detection.js +213 -0
  288. package/lib/Utils/payment-guard.d.ts +28 -0
  289. package/lib/Utils/payment-guard.js +143 -0
  290. package/lib/Utils/payment-messages.d.ts +42 -0
  291. package/lib/Utils/payment-messages.js +161 -0
  292. package/lib/Utils/payment-utils.d.ts +75 -0
  293. package/lib/Utils/payment-utils.js +145 -0
  294. package/lib/Utils/phone-utils.d.ts +3 -0
  295. package/lib/Utils/phone-utils.js +29 -0
  296. package/lib/Utils/pre-key-manager.d.ts +25 -0
  297. package/lib/Utils/pre-key-manager.js +105 -0
  298. package/lib/Utils/process-message.d.ts +103 -0
  299. package/lib/Utils/process-message.js +868 -0
  300. package/lib/Utils/qr-terminal.d.ts +1 -0
  301. package/lib/Utils/qr-terminal.js +16 -0
  302. package/lib/Utils/reconnect-backoff.d.ts +25 -0
  303. package/lib/Utils/reconnect-backoff.js +47 -0
  304. package/lib/Utils/reporting-utils.d.ts +12 -0
  305. package/lib/Utils/reporting-utils.js +257 -0
  306. package/lib/Utils/rich-message-utils.d.ts +54 -0
  307. package/lib/Utils/rich-message-utils.js +435 -0
  308. package/lib/Utils/rich-messages.d.ts +298 -0
  309. package/lib/Utils/rich-messages.js +1145 -0
  310. package/lib/Utils/scheduled-message.d.ts +81 -0
  311. package/lib/Utils/scheduled-message.js +101 -0
  312. package/lib/Utils/scheduling.d.ts +59 -0
  313. package/lib/Utils/scheduling.js +139 -0
  314. package/lib/Utils/signal.d.ts +82 -0
  315. package/lib/Utils/signal.js +200 -0
  316. package/lib/Utils/stanza-ack.d.ts +16 -0
  317. package/lib/Utils/stanza-ack.js +37 -0
  318. package/lib/Utils/status-stickers.d.ts +79 -0
  319. package/lib/Utils/status-stickers.js +261 -0
  320. package/lib/Utils/status.d.ts +107 -0
  321. package/lib/Utils/status.js +131 -0
  322. package/lib/Utils/sticker-pack-maker.d.ts +20 -0
  323. package/lib/Utils/sticker-pack-maker.js +112 -0
  324. package/lib/Utils/stickerpack.d.ts +18 -0
  325. package/lib/Utils/stickerpack.js +316 -0
  326. package/lib/Utils/sync-action-utils.d.ts +2 -0
  327. package/lib/Utils/sync-action-utils.js +48 -0
  328. package/lib/Utils/tag.d.ts +8 -0
  329. package/lib/Utils/tag.js +45 -0
  330. package/lib/Utils/tc-token-utils.d.ts +29 -0
  331. package/lib/Utils/tc-token-utils.js +162 -0
  332. package/lib/Utils/templates.d.ts +86 -0
  333. package/lib/Utils/templates.js +148 -0
  334. package/lib/Utils/text-format.d.ts +13 -0
  335. package/lib/Utils/text-format.js +81 -0
  336. package/lib/Utils/text-tools.d.ts +3 -0
  337. package/lib/Utils/text-tools.js +38 -0
  338. package/lib/Utils/ttl-cache.d.ts +29 -0
  339. package/lib/Utils/ttl-cache.js +123 -0
  340. package/lib/Utils/use-cache-manager-auth-state.d.ts +22 -0
  341. package/lib/Utils/use-cache-manager-auth-state.js +86 -0
  342. package/lib/Utils/use-multi-file-auth-state.d.ts +20 -0
  343. package/lib/Utils/use-multi-file-auth-state.js +201 -0
  344. package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
  345. package/lib/Utils/use-single-file-auth-state.js +111 -0
  346. package/lib/Utils/use-sqlite-auth-state.d.ts +13 -0
  347. package/lib/Utils/use-sqlite-auth-state.js +171 -0
  348. package/lib/Utils/username.d.ts +22 -0
  349. package/lib/Utils/username.js +59 -0
  350. package/lib/Utils/validate-connection.d.ts +43 -0
  351. package/lib/Utils/validate-connection.js +197 -0
  352. package/lib/Utils/vcard.d.ts +40 -0
  353. package/lib/Utils/vcard.js +92 -0
  354. package/lib/Utils/voice-note.d.ts +13 -0
  355. package/lib/Utils/voice-note.js +47 -0
  356. package/lib/VoIP/audio-feeder.d.ts +15 -0
  357. package/lib/VoIP/audio-feeder.js +132 -0
  358. package/lib/VoIP/index.d.ts +22 -0
  359. package/lib/VoIP/index.js +277 -0
  360. package/lib/VoIP/relay-transport.d.ts +16 -0
  361. package/lib/VoIP/relay-transport.js +559 -0
  362. package/lib/VoIP/signaling.d.ts +16 -0
  363. package/lib/VoIP/signaling.js +624 -0
  364. package/lib/VoIP/types.d.ts +11 -0
  365. package/lib/VoIP/types.js +17 -0
  366. package/lib/VoIP/wasm-engine.d.ts +28 -0
  367. package/lib/VoIP/wasm-engine.js +1214 -0
  368. package/lib/VoIP/worker-bootstrap.d.ts +1 -0
  369. package/lib/VoIP/worker-bootstrap.js +1042 -0
  370. package/lib/WABinary/constants.d.ts +61 -0
  371. package/lib/WABinary/constants.js +1466 -0
  372. package/lib/WABinary/decode.d.ts +9 -0
  373. package/lib/WABinary/decode.js +261 -0
  374. package/lib/WABinary/encode.d.ts +2 -0
  375. package/lib/WABinary/encode.js +219 -0
  376. package/lib/WABinary/generic-utils.d.ts +45 -0
  377. package/lib/WABinary/generic-utils.js +285 -0
  378. package/lib/WABinary/index.d.ts +5 -0
  379. package/lib/WABinary/index.js +5 -0
  380. package/lib/WABinary/jid-utils.d.ts +32 -0
  381. package/lib/WABinary/jid-utils.js +102 -0
  382. package/lib/WABinary/types.d.ts +1 -0
  383. package/lib/WABinary/types.js +1 -0
  384. package/lib/WAM/BinaryInfo.d.ts +7 -0
  385. package/lib/WAM/BinaryInfo.js +9 -0
  386. package/lib/WAM/constants.d.ts +34926 -0
  387. package/lib/WAM/constants.js +22852 -0
  388. package/lib/WAM/encode.d.ts +1 -0
  389. package/lib/WAM/encode.js +149 -0
  390. package/lib/WAM/index.d.ts +3 -0
  391. package/lib/WAM/index.js +3 -0
  392. package/lib/WAUSync/Protocols/USyncBusinessProtocol.d.ts +43 -0
  393. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +32 -0
  394. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  395. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  396. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
  397. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +60 -0
  398. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  399. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  400. package/lib/WAUSync/Protocols/USyncFeatureProtocol.d.ts +13 -0
  401. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +28 -0
  402. package/lib/WAUSync/Protocols/USyncPictureProtocol.d.ts +22 -0
  403. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
  404. package/lib/WAUSync/Protocols/USyncSidelistProtocol.d.ts +20 -0
  405. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +23 -0
  406. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  407. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  408. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.d.ts +14 -0
  409. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +24 -0
  410. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  411. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  412. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  413. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +49 -0
  414. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  415. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  416. package/lib/WAUSync/Protocols/index.d.ts +12 -0
  417. package/lib/WAUSync/Protocols/index.js +12 -0
  418. package/lib/WAUSync/USyncQuery.d.ts +25 -0
  419. package/lib/WAUSync/USyncQuery.js +140 -0
  420. package/lib/WAUSync/USyncUser.d.ts +24 -0
  421. package/lib/WAUSync/USyncUser.js +47 -0
  422. package/lib/WAUSync/index.d.ts +3 -0
  423. package/lib/WAUSync/index.js +3 -0
  424. package/lib/assets/wasm/loader.js +5 -0
  425. package/lib/assets/wasm/whatsapp.wasm +0 -0
  426. package/lib/assets/wasm/worker-modules.js +273 -0
  427. package/lib/exports-extra.d.ts +45 -0
  428. package/lib/exports-extra.js +47 -0
  429. package/lib/index.d.ts +16 -0
  430. package/lib/index.js +24 -0
  431. package/package.json +161 -4
@@ -0,0 +1,624 @@
1
+ import { decodeBinaryNode } from '../WABinary/decode.js';
2
+ import { encodeBinaryNode } from '../WABinary/encode.js';
3
+ import { getBinaryNodeChild, getAllBinaryNodeChildren } from '../WABinary/generic-utils.js';
4
+ import { jidDecode, jidEncode, jidNormalizedUser } from '../WABinary/jid-utils.js';
5
+ import { encodeWAMessage, unpadRandomMax16 } from '../Utils/generics.js';
6
+ import { parseAndInjectE2ESessions } from '../Utils/signal.js';
7
+ import { encodeSignedDeviceIdentity } from '../Utils/validate-connection.js';
8
+ import { proto } from '../../WAProto/index.js';
9
+
10
+ const S_WHATSAPP_NET = "@s.whatsapp.net";
11
+ const TC_TOKEN_REQUEST_TIMEOUT_MS = 3500;
12
+ const SESSION_CACHE_TTL_MS = 5 * 60_000;
13
+ const ACK_TIMEOUT_MS = 15_000;
14
+
15
+ const getNodeChildren = (node) =>
16
+ Array.isArray(node.content) ? node.content : [];
17
+
18
+ const setNodeChildren = (node, children) => {
19
+ node.content = children.length ? children : undefined;
20
+ };
21
+
22
+ const replaceNodeChild = (node, tag, nextChild) => {
23
+ const children = getNodeChildren(node);
24
+ const index = children.findIndex((c) => c.tag === tag);
25
+ if (index >= 0) children[index] = nextChild;
26
+ else children.push(nextChild);
27
+ setNodeChildren(node, children);
28
+ };
29
+
30
+ const removeNodeChildrenByTag = (node, tag) => {
31
+ setNodeChildren(node, getNodeChildren(node).filter((c) => c.tag !== tag));
32
+ };
33
+
34
+ const parseCountAttr = (value, fallback = 0) => {
35
+ const parsed = Number(value);
36
+ return Number.isFinite(parsed) ? parsed : fallback;
37
+ };
38
+
39
+ export class SignalingBridge {
40
+ #sock;
41
+ #voip = null;
42
+ #observedTcTokens = new Map();
43
+ #pendingTcTokenWaiters = new Map();
44
+ #ensuredSignalSessions = new Map();
45
+ #remoteDevicePeerByCallId = new Map();
46
+ #remoteObfuscatedPeerByCallId = new Map();
47
+ #remoteXmppRoutePeerByCallId = new Map();
48
+ #incomingCallPeerById = new Map();
49
+ #outgoingSignalingQueue = Promise.resolve(undefined);
50
+ #incomingSignalingQueue = Promise.resolve(undefined);
51
+
52
+ constructor(config) {
53
+ this.#sock = config.sock;
54
+ }
55
+
56
+ attachEngine = (voip) => {
57
+ this.#voip = voip;
58
+ };
59
+
60
+ // Vanz@Add --- ourin-baileys's socket exposed a `getPrivacyTokens(jids)` helper for
61
+ // fetching `trusted_contact` tokens; the base socket here doesn't (it only has
62
+ // `issuePrivacyTokens`, which *issues* tokens rather than *requesting* someone else's).
63
+ // Self-contained so this module doesn't require patching Socket/messages-send.js.
64
+ #getPrivacyTokens = async (jids) => {
65
+ const t = Math.floor(Date.now() / 1000).toString();
66
+ return this.#sock.query({
67
+ tag: "iq",
68
+ attrs: {
69
+ to: S_WHATSAPP_NET,
70
+ type: "set",
71
+ xmlns: "privacy",
72
+ },
73
+ content: [
74
+ {
75
+ tag: "tokens",
76
+ attrs: {},
77
+ content: jids.map((jid) => ({
78
+ tag: "token",
79
+ attrs: {
80
+ jid: jidNormalizedUser(jid),
81
+ t,
82
+ type: "trusted_contact",
83
+ },
84
+ })),
85
+ },
86
+ ],
87
+ });
88
+ };
89
+
90
+ init = async () => {
91
+ const originalKeysSet = this.#sock.authState.keys.set.bind(this.#sock.authState.keys);
92
+ this.#sock.authState.keys.set = async (data) => {
93
+ const result = await originalKeysSet(data);
94
+ for (const [jid, entry] of Object.entries(data?.tctoken ?? {})) {
95
+ if (entry?.token instanceof Uint8Array && entry.token.length > 0) {
96
+ this.#rememberTcToken(jid, entry.token, entry.timestamp);
97
+ }
98
+ }
99
+ return result;
100
+ };
101
+ };
102
+
103
+ sendSignaling = (peerJid, callId, xmlPayload) => {
104
+ this.#outgoingSignalingQueue = this.#outgoingSignalingQueue
105
+ .then(() => this.#doSendSignaling(peerJid, callId, xmlPayload))
106
+ .catch(() => {});
107
+ };
108
+
109
+ processIncomingCall = (node, voip, activeCallId) => {
110
+ this.#incomingSignalingQueue = this.#incomingSignalingQueue
111
+ .then(() => this.#doProcessIncomingCall(node, voip, activeCallId))
112
+ .catch(() => {});
113
+ };
114
+
115
+ processIncomingReceipt = (node, voip, activeCallId) => {
116
+ this.#incomingSignalingQueue = this.#incomingSignalingQueue
117
+ .then(() => this.#doProcessIncomingReceipt(node, voip, activeCallId))
118
+ .catch(() => {});
119
+ };
120
+
121
+ requestTcToken = async (jid) => {
122
+ const userJid = this.#toBareJid(jid);
123
+ const cached = await this.#getTcToken(userJid);
124
+ if (cached?.length) return cached;
125
+
126
+ try {
127
+ const response = await this.#getPrivacyTokens([userJid]);
128
+ const tokensNode =
129
+ getBinaryNodeChild(response, "tokens") ??
130
+ getBinaryNodeChild(getBinaryNodeChild(response, "iq"), "tokens");
131
+ const tokenNodes = tokensNode
132
+ ? getAllBinaryNodeChildren(tokensNode).filter((c) => c.tag === "token")
133
+ : [];
134
+
135
+ for (const tokenNode of tokenNodes) {
136
+ const tokenJid = String(tokenNode.attrs.jid ?? "");
137
+ if (jidNormalizedUser(tokenJid) !== jidNormalizedUser(userJid)) continue;
138
+ const content = tokenNode.content;
139
+ if (content instanceof Uint8Array && content.length > 0) {
140
+ const token = Buffer.from(content);
141
+ await this.#sock.authState.keys.set({
142
+ tctoken: { [userJid]: { token, timestamp: String(tokenNode.attrs.t ?? "") } },
143
+ });
144
+ return token;
145
+ }
146
+ }
147
+ } catch {}
148
+
149
+ return this.#getTcToken(userJid);
150
+ };
151
+
152
+ ensureTcToken = async (...jids) => {
153
+ const uniqueJids = [
154
+ ...new Set(jids.map((j) => this.#toBareJid(String(j ?? "").trim())).filter(Boolean)),
155
+ ];
156
+ for (const jid of uniqueJids) {
157
+ const cached = await this.#getTcToken(jid);
158
+ if (cached?.length) return cached;
159
+ }
160
+ for (const jid of uniqueJids) {
161
+ const fetched = await Promise.race([
162
+ this.requestTcToken(jid),
163
+ new Promise((r) => setTimeout(() => r(undefined), TC_TOKEN_REQUEST_TIMEOUT_MS)),
164
+ ]);
165
+ if (fetched?.length) return fetched;
166
+ }
167
+ return undefined;
168
+ };
169
+
170
+ discoverPeerDevices = async (peerLidJid) => {
171
+ const devices = await this.#sock.getUSyncDevices([peerLidJid], true, false);
172
+ return this.#normalizeStartCallPeerList(devices.map((d) => d.jid).filter(Boolean));
173
+ };
174
+
175
+ ensureSessionsForPeers = async (jids) => {
176
+ const targets = this.#expandSignalSessionTargets(jids);
177
+ if (targets.length) await this.#ensureSignalSessions(targets, true);
178
+ };
179
+
180
+ resolveLid = async (pnJid) =>
181
+ this.#sock.signalRepository.lidMapping?.getLIDForPN(pnJid);
182
+
183
+ issueTcToken = async (jid) => {
184
+ const userJid = this.#toBareJid(jid);
185
+ const issuedAt = Math.floor(Date.now() / 1000);
186
+ try {
187
+ await this.#sock.query({
188
+ tag: "iq",
189
+ attrs: {
190
+ to: S_WHATSAPP_NET, type: "set", xmlns: "privacy",
191
+ id: this.#sock.generateMessageTag(),
192
+ },
193
+ content: [{
194
+ tag: "tokens", attrs: {},
195
+ content: [{
196
+ tag: "token",
197
+ attrs: { jid: userJid, t: String(issuedAt), type: "trusted_contact" },
198
+ }],
199
+ }],
200
+ });
201
+ return true;
202
+ } catch {
203
+ return false;
204
+ }
205
+ };
206
+
207
+ getRemoteDeviceJid = (callId) =>
208
+ this.#remoteDevicePeerByCallId.get(callId);
209
+
210
+ #doSendSignaling = async (peerJid, callId, xmlPayload) => {
211
+ const rawPayload = Buffer.from(xmlPayload);
212
+ let voipNode;
213
+ try {
214
+ voipNode = await decodeBinaryNode(Buffer.concat([Buffer.from([0]), rawPayload]));
215
+ } catch {
216
+ voipNode = await decodeBinaryNode(rawPayload);
217
+ }
218
+
219
+ const signalingTag = String(voipNode.tag);
220
+ const effectivePeerJid = this.#resolveOutboundPeerJid(callId, peerJid);
221
+
222
+ if (signalingTag === "offer" && !voipNode.attrs["call-creator"]) {
223
+ const selfLid = this.#sock.authState.creds.me?.lid;
224
+ if (selfLid) voipNode.attrs["call-creator"] = selfLid;
225
+ }
226
+
227
+ const destination = getBinaryNodeChild(voipNode, "destination");
228
+ if (destination) {
229
+ const destinations = getNodeChildren(destination);
230
+ const destinationJids = destinations
231
+ .map((n) => String(n.attrs.jid ?? "").trim())
232
+ .filter(Boolean);
233
+ const sessionTargets = this.#expandSignalSessionTargets(destinationJids);
234
+ if (sessionTargets.length) await this.#ensureSignalSessions(sessionTargets, signalingTag === "offer");
235
+
236
+ const rootEnc = getBinaryNodeChild(voipNode, "enc");
237
+ const encCount = parseCountAttr(rootEnc?.attrs.count);
238
+ let includeDeviceIdentity = false;
239
+
240
+ for (const destNode of destinations) {
241
+ const targetJid = String(destNode.attrs.jid ?? "").trim();
242
+ const destEnc = getBinaryNodeChild(destNode, "enc");
243
+ if (!targetJid || !destEnc || !(destEnc.content instanceof Uint8Array)) continue;
244
+ try {
245
+ const encrypted = await this.#encryptCallKey(targetJid, destEnc.content, encCount);
246
+ includeDeviceIdentity = includeDeviceIdentity || encrypted.shouldIncludeDeviceIdentity;
247
+ setNodeChildren(destNode, [encrypted.encNode]);
248
+ } catch {
249
+ for (const d of destinations) removeNodeChildrenByTag(d, "enc");
250
+ break;
251
+ }
252
+ }
253
+ if (includeDeviceIdentity) this.#appendDeviceIdentity(voipNode);
254
+
255
+ await this.#sendCallStanza(this.#toBareJid(peerJid), voipNode, signalingTag, effectivePeerJid, peerJid);
256
+ return;
257
+ }
258
+
259
+ if (signalingTag === "offer" || signalingTag === "enc_rekey") {
260
+ const enc = getBinaryNodeChild(voipNode, "enc");
261
+ if (enc && enc.content instanceof Uint8Array) {
262
+ const targetJid = this.#toCallDeviceJid(effectivePeerJid);
263
+ const encrypted = await this.#encryptCallKey(targetJid, enc.content, parseCountAttr(enc.attrs.count));
264
+ replaceNodeChild(voipNode, "enc", encrypted.encNode);
265
+ if (encrypted.shouldIncludeDeviceIdentity) this.#appendDeviceIdentity(voipNode);
266
+
267
+ await this.#sendCallStanza(targetJid, voipNode, signalingTag, effectivePeerJid, peerJid);
268
+ return;
269
+ }
270
+ }
271
+
272
+ const routeTo = signalingTag !== "offer" && signalingTag !== "enc_rekey"
273
+ ? this.#toBareJid(effectivePeerJid)
274
+ : this.#toCallDeviceJid(effectivePeerJid);
275
+ await this.#sendCallStanza(routeTo, voipNode, signalingTag, effectivePeerJid, peerJid);
276
+ };
277
+
278
+ #sendCallStanza = async (routeTo, voipNode, signalingTag, effectivePeerJid, callbackPeerJid) => {
279
+ const stanzaId = this.#sock.generateMessageTag();
280
+ await this.#sock.sendNode({
281
+ tag: "call",
282
+ attrs: { to: routeTo, id: stanzaId },
283
+ content: [voipNode],
284
+ });
285
+
286
+ void (async () => {
287
+ try {
288
+ const ackNode = await this.#sock.waitForMessage(stanzaId, ACK_TIMEOUT_MS);
289
+ if (!ackNode || !this.#voip) return;
290
+ const ackPayload = Buffer.from(encodeBinaryNode(ackNode)).toString("base64");
291
+ const tcToken = await this.ensureTcToken(effectivePeerJid, callbackPeerJid);
292
+ try {
293
+ this.#voip.handleSignalingAck({
294
+ payload: ackPayload,
295
+ ackError: ackNode.attrs?.error ?? "0",
296
+ msgType: ackNode.attrs?.type ?? signalingTag,
297
+ peerJid: effectivePeerJid,
298
+ extraData: tcToken,
299
+ });
300
+ } catch {}
301
+ } catch {}
302
+ })();
303
+ };
304
+
305
+ #doProcessIncomingCall = async (node, voip, activeCallId) => {
306
+ const voipChild = getAllBinaryNodeChildren(node)[0];
307
+ if (!voipChild) return;
308
+
309
+ const incomingCallId = String(voipChild.attrs["call-id"] ?? voipChild.attrs.call_id ?? "");
310
+ const callIdForRouting = incomingCallId || activeCallId;
311
+ if (activeCallId && incomingCallId && incomingCallId !== activeCallId) return;
312
+
313
+ const senderDeviceJid =
314
+ String(voipChild.attrs.participant ?? "") ||
315
+ String(node.attrs.participant ?? "") ||
316
+ String(node.attrs.from ?? "") ||
317
+ String(voipChild.attrs["call-creator"] ?? "");
318
+ const callbackPeerJid = String(node.attrs.from ?? "") || senderDeviceJid;
319
+ const platform = voipChild.attrs.platform ?? node.attrs.platform ?? "";
320
+ const appVersion = voipChild.attrs.version ?? node.attrs.version ?? "";
321
+ const epochId = voipChild.attrs.e ?? node.attrs.e ?? "0";
322
+ const timestamp = voipChild.attrs.t ?? node.attrs.t ?? "0";
323
+ const offline = !!(voipChild.attrs.offline ?? node.attrs.offline);
324
+
325
+ let usableNode = voipChild;
326
+ if (getBinaryNodeChild(voipChild, "enc")) {
327
+ usableNode = await this.#maybeDecryptEnc(voipChild, senderDeviceJid);
328
+ }
329
+
330
+ const b64 = Buffer.from(encodeBinaryNode(usableNode)).toString("base64");
331
+
332
+ const storedPeerJid = callIdForRouting ? this.#incomingCallPeerById.get(callIdForRouting) : undefined;
333
+ let mappedRemoteDeviceJid = callIdForRouting ? this.#remoteDevicePeerByCallId.get(callIdForRouting) : undefined;
334
+
335
+ if (callIdForRouting && (callbackPeerJid || senderDeviceJid)) {
336
+ this.#remoteXmppRoutePeerByCallId.set(callIdForRouting, callbackPeerJid || senderDeviceJid);
337
+ const hinted = this.#pickConcreteRouteHint(senderDeviceJid, callbackPeerJid);
338
+ if (hinted && hinted !== mappedRemoteDeviceJid) {
339
+ mappedRemoteDeviceJid = hinted;
340
+ this.#remoteDevicePeerByCallId.set(callIdForRouting, hinted);
341
+ }
342
+ }
343
+
344
+ const routedPeerJid = usableNode.tag === "offer"
345
+ ? this.#preferDeviceRouteJid(senderDeviceJid, callbackPeerJid, storedPeerJid)
346
+ : this.#preferOrderedRouteJid(mappedRemoteDeviceJid, storedPeerJid, senderDeviceJid, callbackPeerJid);
347
+
348
+ if (callIdForRouting && routedPeerJid) {
349
+ this.#incomingCallPeerById.set(callIdForRouting, routedPeerJid);
350
+ }
351
+
352
+ const tcToken = await this.ensureTcToken(routedPeerJid, callbackPeerJid);
353
+
354
+ switch (usableNode.tag) {
355
+ case "offer":
356
+ voip.handleSignalingOffer({
357
+ payload: b64,
358
+ peerPlatform: Number(platform || 0),
359
+ peerAppVersion: appVersion,
360
+ epochId, timestamp,
361
+ isOffline: offline,
362
+ isOfferNotContact: false,
363
+ peerJid: routedPeerJid,
364
+ tcToken,
365
+ });
366
+ break;
367
+ case "ack":
368
+ voip.handleSignalingAck({
369
+ payload: b64,
370
+ ackError: usableNode.attrs.error ?? "0",
371
+ msgType: usableNode.attrs.type ?? "",
372
+ peerJid: routedPeerJid,
373
+ extraData: tcToken,
374
+ });
375
+ break;
376
+ default:
377
+ voip.handleSignalingMessage({
378
+ payload: b64,
379
+ peerPlatform: platform,
380
+ peerAppVersion: appVersion,
381
+ epochId, timestamp,
382
+ isOffline: offline,
383
+ peerJid: routedPeerJid,
384
+ tcToken,
385
+ });
386
+ if (callIdForRouting && (usableNode.tag === "terminate" || usableNode.tag === "reject")) {
387
+ this.#incomingCallPeerById.delete(callIdForRouting);
388
+ this.#remoteDevicePeerByCallId.delete(callIdForRouting);
389
+ this.#remoteObfuscatedPeerByCallId.delete(callIdForRouting);
390
+ this.#remoteXmppRoutePeerByCallId.delete(callIdForRouting);
391
+ }
392
+ break;
393
+ }
394
+ };
395
+
396
+ #doProcessIncomingReceipt = async (node, voip, activeCallId) => {
397
+ const receiptChild = getAllBinaryNodeChildren(node)[0];
398
+ if (!receiptChild) return;
399
+
400
+ const incomingCallId = String(receiptChild.attrs["call-id"] ?? receiptChild.attrs.call_id ?? "");
401
+ const callIdForRouting = incomingCallId || activeCallId;
402
+ if (activeCallId && incomingCallId && incomingCallId !== activeCallId) return;
403
+
404
+ const callbackPeerJid = String(node.attrs.from ?? receiptChild.attrs["call-creator"] ?? "");
405
+ const storedPeerJid = callIdForRouting ? this.#incomingCallPeerById.get(callIdForRouting) : undefined;
406
+ const routedPeerJid = this.#preferOrderedRouteJid(storedPeerJid, callbackPeerJid);
407
+ if (callIdForRouting && routedPeerJid) this.#incomingCallPeerById.set(callIdForRouting, routedPeerJid);
408
+
409
+ const tcToken = await this.ensureTcToken(routedPeerJid, callbackPeerJid);
410
+ voip.handleSignalingReceipt({
411
+ payload: Buffer.from(encodeBinaryNode(node)).toString("base64"),
412
+ peerJid: routedPeerJid,
413
+ tcToken,
414
+ });
415
+ };
416
+
417
+ #maybeDecryptEnc = async (voipNode, peerJid) => {
418
+ const enc = getBinaryNodeChild(voipNode, "enc");
419
+ if (!enc || !(enc.content instanceof Uint8Array)) return voipNode;
420
+ const type = enc.attrs.type;
421
+ if (type !== "pkmsg" && type !== "msg") return voipNode;
422
+
423
+ const candidates = [...new Set([peerJid, this.#toCallDeviceJid(peerJid)])].filter(Boolean);
424
+ let lastErr;
425
+ for (const jid of candidates) {
426
+ try {
427
+ const decrypted = await this.#sock.signalRepository.decryptMessage({
428
+ jid, type, ciphertext: enc.content,
429
+ });
430
+ const parsed = proto.Message.decode(unpadRandomMax16(decrypted));
431
+ const callKey = parsed.call?.callKey;
432
+ if (!callKey || callKey.length === 0) {
433
+ throw new Error("decrypted signaling has no call.callKey");
434
+ }
435
+ enc.content = callKey;
436
+ return voipNode;
437
+ } catch (err) {
438
+ lastErr = err;
439
+ }
440
+ }
441
+ throw lastErr;
442
+ };
443
+
444
+ #encryptCallKey = async (targetJid, rawCallKey, count) => {
445
+ const primaryDeviceJid = this.#toPrimaryDeviceJid(targetJid);
446
+ const sessionTargets = primaryDeviceJid && primaryDeviceJid !== targetJid
447
+ ? [primaryDeviceJid, targetJid]
448
+ : [targetJid];
449
+ await this.#ensureSignalSessions(sessionTargets, false);
450
+
451
+ const { type, ciphertext } = await this.#sock.signalRepository.encryptMessage({
452
+ jid: targetJid,
453
+ data: encodeWAMessage({ call: { callKey: Buffer.from(rawCallKey) } }),
454
+ });
455
+
456
+ return {
457
+ encNode: {
458
+ tag: "enc",
459
+ attrs: { v: "2", type, count: String(count) },
460
+ content: Buffer.from(ciphertext),
461
+ },
462
+ shouldIncludeDeviceIdentity: type === "pkmsg",
463
+ };
464
+ };
465
+
466
+ #ensureSignalSessions = async (jids, refresh) => {
467
+ const missing = [];
468
+ for (const jid of [...new Set(jids.filter(Boolean))]) {
469
+ const signalId = this.#sock.signalRepository.jidToSignalProtocolAddress(jid);
470
+ const cachedAt = this.#ensuredSignalSessions.get(signalId);
471
+ if (!refresh && cachedAt && Date.now() - cachedAt < SESSION_CACHE_TTL_MS) continue;
472
+ if (!refresh) {
473
+ const validation = await this.#sock.signalRepository.validateSession(jid);
474
+ if (validation.exists) {
475
+ this.#ensuredSignalSessions.set(signalId, Date.now());
476
+ continue;
477
+ }
478
+ }
479
+ missing.push(jid);
480
+ }
481
+ if (!missing.length) return;
482
+
483
+ const sessionNode = await this.#sock.query({
484
+ tag: "iq",
485
+ attrs: { xmlns: "encrypt", type: "get", to: S_WHATSAPP_NET },
486
+ content: [{
487
+ tag: "key", attrs: {},
488
+ content: missing.map((jid) => ({ tag: "user", attrs: { jid } })),
489
+ }],
490
+ });
491
+ await parseAndInjectE2ESessions(sessionNode, this.#sock.signalRepository);
492
+ for (const jid of missing) {
493
+ this.#ensuredSignalSessions.set(
494
+ this.#sock.signalRepository.jidToSignalProtocolAddress(jid),
495
+ Date.now(),
496
+ );
497
+ }
498
+ };
499
+
500
+ #appendDeviceIdentity = (voipNode) => {
501
+ if (getBinaryNodeChild(voipNode, "device-identity")) return;
502
+ const account = this.#sock.authState.creds.account;
503
+ if (!account) return;
504
+ const children = getNodeChildren(voipNode);
505
+ children.push({
506
+ tag: "device-identity",
507
+ attrs: {},
508
+ content: encodeSignedDeviceIdentity(account, true),
509
+ });
510
+ setNodeChildren(voipNode, children);
511
+ };
512
+
513
+ #toBareJid = (jid) => {
514
+ const decoded = jidDecode(jid);
515
+ if (!decoded?.user) return jid;
516
+ const server = jid.endsWith("@lid") ? "lid" : "s.whatsapp.net";
517
+ return jidEncode(decoded.user, server);
518
+ };
519
+
520
+ #toCallDeviceJid = (jid) => {
521
+ const decoded = jidDecode(jid);
522
+ if (!decoded?.user) return jid;
523
+ const server = jid.endsWith("@lid") ? "lid" : "s.whatsapp.net";
524
+ if (decoded.device == null) return jidEncode(decoded.user, server);
525
+ return `${decoded.user}:${decoded.device}@${server}`;
526
+ };
527
+
528
+ #toPrimaryDeviceJid = (jid) => {
529
+ const decoded = jidDecode(jid);
530
+ if (!decoded?.user) return undefined;
531
+ const device = decoded.device;
532
+ if (device == null || device === 0) return undefined;
533
+ const server = jid.endsWith("@lid") ? "lid" : "s.whatsapp.net";
534
+ return jidEncode(decoded.user, server);
535
+ };
536
+
537
+ #hasConcreteDevice = (jid) => {
538
+ const decoded = jidDecode(jid);
539
+ return !!decoded?.user && decoded.device != null;
540
+ };
541
+
542
+ #preferDeviceRouteJid = (...candidates) => {
543
+ for (const c of candidates) {
544
+ const jid = String(c ?? "").trim();
545
+ if (jid && this.#hasConcreteDevice(jid)) return jid;
546
+ }
547
+ for (const c of candidates) {
548
+ const jid = String(c ?? "").trim();
549
+ if (jid) return this.#toCallDeviceJid(jid);
550
+ }
551
+ return "";
552
+ };
553
+
554
+ #preferOrderedRouteJid = (...candidates) => {
555
+ for (const c of candidates) {
556
+ const jid = String(c ?? "").trim();
557
+ if (jid) return this.#toCallDeviceJid(jid);
558
+ }
559
+ return "";
560
+ };
561
+
562
+ #pickConcreteRouteHint = (...candidates) => {
563
+ for (const c of candidates) {
564
+ const jid = String(c ?? "").trim();
565
+ if (jid && this.#hasConcreteDevice(jid)) return jid;
566
+ }
567
+ return "";
568
+ };
569
+
570
+ #resolveOutboundPeerJid = (callId, wasmPeerJid) => {
571
+ const peerJid = String(wasmPeerJid ?? "").trim();
572
+ if (!peerJid || !callId) return peerJid;
573
+ return this.#remoteDevicePeerByCallId.get(callId) ?? peerJid;
574
+ };
575
+
576
+ #expandSignalSessionTargets = (jids) =>
577
+ [...new Set(jids.flatMap((jid) => {
578
+ const primary = this.#toPrimaryDeviceJid(jid);
579
+ return primary && primary !== jid ? [primary, jid] : [jid];
580
+ }))];
581
+
582
+ #normalizeStartCallPeerList = (jids) => {
583
+ const result = new Set();
584
+ for (const jid of jids) {
585
+ const decoded = jidDecode(jid);
586
+ if (!decoded?.user) {
587
+ result.add(jid);
588
+ continue;
589
+ }
590
+ const server = jid.endsWith("@lid") ? "lid" : "s.whatsapp.net";
591
+ result.add(jidEncode(decoded.user, server));
592
+ if (decoded.device != null) {
593
+ result.add(`${decoded.user}:${decoded.device}@${server}`);
594
+ }
595
+ }
596
+ return [...result].slice(0, 5);
597
+ };
598
+
599
+ #rememberTcToken = (jid, token, timestamp = "") => {
600
+ const bareJid = this.#toBareJid(jid);
601
+ if (!token.length) return;
602
+ this.#observedTcTokens.set(bareJid, { token: Buffer.from(token), timestamp });
603
+ const waiters = this.#pendingTcTokenWaiters.get(bareJid);
604
+ if (waiters?.length) {
605
+ this.#pendingTcTokenWaiters.delete(bareJid);
606
+ for (const w of waiters) w(Buffer.from(token));
607
+ }
608
+ };
609
+
610
+ #getTcToken = async (jid) => {
611
+ const userJid = this.#toBareJid(jid);
612
+ const observed = this.#observedTcTokens.get(userJid)?.token;
613
+ if (observed?.length) return Buffer.from(observed);
614
+ try {
615
+ const data = await this.#sock.authState.keys.get("tctoken", [userJid]);
616
+ const token = data[userJid]?.token;
617
+ if (token && token.length > 0) {
618
+ this.#rememberTcToken(userJid, token, data[userJid]?.timestamp);
619
+ return token;
620
+ }
621
+ } catch {}
622
+ return undefined;
623
+ };
624
+ }
@@ -0,0 +1,11 @@
1
+ export namespace CallState {
2
+ let Idle: number;
3
+ let Calling: number;
4
+ let PreacceptReceived: number;
5
+ let ReceivedCall: number;
6
+ let AcceptSent: number;
7
+ let AcceptReceived: number;
8
+ let Active: number;
9
+ let ActiveElsewhere: number;
10
+ let Ending: number;
11
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Shared type definitions for baileys-caller.
3
+ *
4
+ * @author ShellTear
5
+ */
6
+ /** Mirrors the WhatsApp WASM `CallState` enum. */
7
+ export const CallState = {
8
+ Idle: 0,
9
+ Calling: 1,
10
+ PreacceptReceived: 2,
11
+ ReceivedCall: 3,
12
+ AcceptSent: 4,
13
+ AcceptReceived: 5,
14
+ Active: 6,
15
+ ActiveElsewhere: 7,
16
+ Ending: 13,
17
+ };
@@ -0,0 +1,28 @@
1
+ export class WasmEngine {
2
+ static #globalCallbackListeners: Map<any, any>;
3
+ static #globalCallbacksRegistered: boolean;
4
+ static registerGlobalCallbackListener: (callbackName: any, handler: any) => void;
5
+ static notifyGlobalCallbackListeners: (callbackName: any, data: any) => void;
6
+ constructor(config?: {});
7
+ initialize: () => Promise<void>;
8
+ isInitialized: () => boolean;
9
+ destroy: () => void;
10
+ initVoipStack: (selfJid: any, meUserJid: any, selfLid: any) => void;
11
+ waitForVoipStackReady: () => Promise<void>;
12
+ isVoipStackReady: () => boolean;
13
+ startCall: (options: any) => any;
14
+ endCall: (reason?: number, sendTerminate?: boolean) => void;
15
+ setMute: (muted: any) => any;
16
+ updateNetworkMedium: (networkMedium: any, networkMtu?: number) => void;
17
+ handleSignalingOffer: (msg: any) => void;
18
+ handleSignalingMessage: (msg: any) => void;
19
+ handleSignalingAck: (msg: any) => void;
20
+ handleSignalingReceipt: (msg: any) => void;
21
+ handleOnTransportMessage: (data: any, ip: any, port: any) => void;
22
+ updateIceRtt: (rttMs: any, relayIp: any, relayPort: any) => void;
23
+ sendAudioData: (data: any, ptr: any) => void;
24
+ malloc: (size: any) => any;
25
+ free: (ptr: any) => void;
26
+ #private;
27
+ }
28
+ export default WasmEngine;