@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,117 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { jidNormalizedUser } from '../WABinary/index.js';
3
+
4
+ // Vanz@Port (from @queenanya/baileys Framework, originally Baileys PR #2710
5
+ // by LuferOS) --- group activity tracking: message counts, sticker counts,
6
+ // leaderboards, ghost (inactive member) detection.
7
+ //
8
+ // Kept from upstream's P0-P3 pass:
9
+ // - all participant JIDs normalized via jidNormalizedUser() before storing/
10
+ // querying, so PN/LID/device (:0, :42) variants resolve to the same row
11
+ // - getTopUsers/getTopStickers guard limit to a positive integer
12
+ // - getGhosts throws Boom(503) instead of a bare Error when the socket
13
+ // isn't connected, so callers can branch on statusCode
14
+ //
15
+ async function loadBetterSqlite3() {
16
+ try {
17
+ const mod = (await import('better-sqlite3'));
18
+ return mod.default ?? mod;
19
+ }
20
+ catch (err) {
21
+ const helpful = new Error('`better-sqlite3` is required for the Framework StatsManager. Install it as a peer dependency: `npm install better-sqlite3` (or `yarn add better-sqlite3`).');
22
+ helpful.cause = err;
23
+ throw helpful;
24
+ }
25
+ }
26
+
27
+ export class StatsManager {
28
+ constructor(db, groupMetaFn) {
29
+ this.db = db;
30
+ this.groupMetaFn = groupMetaFn;
31
+ this.db.exec(`
32
+ CREATE TABLE IF NOT EXISTS group_stats (
33
+ group_jid TEXT NOT NULL,
34
+ user_jid TEXT NOT NULL,
35
+ msg_count INTEGER NOT NULL DEFAULT 0,
36
+ sticker_count INTEGER NOT NULL DEFAULT 0,
37
+ last_active INTEGER NOT NULL,
38
+ PRIMARY KEY (group_jid, user_jid)
39
+ )
40
+ `);
41
+ this.insertStmt = this.db.prepare(`
42
+ INSERT INTO group_stats (group_jid, user_jid, msg_count, sticker_count, last_active)
43
+ VALUES (?, ?, ?, ?, ?)
44
+ ON CONFLICT(group_jid, user_jid) DO UPDATE SET
45
+ msg_count = msg_count + excluded.msg_count,
46
+ sticker_count = sticker_count + excluded.sticker_count,
47
+ last_active = excluded.last_active
48
+ `);
49
+ this.getStatsStmt = this.db.prepare('SELECT user_jid, msg_count, sticker_count, last_active FROM group_stats WHERE group_jid = ?');
50
+ this.getTopMsgStmt = (limit) => this.db.prepare(`SELECT user_jid AS jid, msg_count AS count FROM group_stats WHERE group_jid = ? ORDER BY msg_count DESC LIMIT ${limit}`);
51
+ this.getTopStickerStmt = (limit) => this.db.prepare(`SELECT user_jid AS jid, sticker_count AS count FROM group_stats WHERE group_jid = ? ORDER BY sticker_count DESC LIMIT ${limit}`);
52
+ }
53
+
54
+ /** Vanz@Port: replaces the old synchronous `new StatsManager(dbPath, groupMetaFn)`. */
55
+ static async create(dbPath, groupMetaFn) {
56
+ const Database = await loadBetterSqlite3();
57
+ return new StatsManager(new Database(dbPath), groupMetaFn);
58
+ }
59
+
60
+ /** Record a message observation for stats. Normalizes both JIDs before storing. */
61
+ observeMessage(groupJid, userJid, isSticker) {
62
+ const normalizedGroupJid = jidNormalizedUser(groupJid);
63
+ const normalizedUserJid = jidNormalizedUser(userJid);
64
+ const msgCount = 1;
65
+ const stickerCount = isSticker ? 1 : 0;
66
+ const now = Date.now();
67
+ this.insertStmt.run(normalizedGroupJid, normalizedUserJid, msgCount, stickerCount, now);
68
+ }
69
+
70
+ /** Top message senders for a group. */
71
+ getTopUsers(groupJid, limit = 10) {
72
+ const safeLimit = Math.max(1, Math.floor(limit));
73
+ const normalizedGroupJid = jidNormalizedUser(groupJid);
74
+ return this.getTopMsgStmt(safeLimit).all(normalizedGroupJid);
75
+ }
76
+
77
+ /** Top sticker senders for a group. */
78
+ getTopStickers(groupJid, limit = 10) {
79
+ const safeLimit = Math.max(1, Math.floor(limit));
80
+ const normalizedGroupJid = jidNormalizedUser(groupJid);
81
+ return this.getTopStickerStmt(safeLimit).all(normalizedGroupJid);
82
+ }
83
+
84
+ /** Detect inactive members ("ghosts") in a group. */
85
+ async getGhosts(groupJid, socketConnected, inactiveDays = 30) {
86
+ if (!socketConnected) {
87
+ throw new Boom('Socket not connected — cannot fetch group metadata for ghost detection', {
88
+ statusCode: 503
89
+ });
90
+ }
91
+ const normalizedGroupJid = jidNormalizedUser(groupJid);
92
+ const cutoff = Date.now() - inactiveDays * 24 * 60 * 60 * 1000;
93
+ const rows = this.getStatsStmt.all(normalizedGroupJid);
94
+ const statsMap = new Map();
95
+ for (const row of rows) {
96
+ statsMap.set(jidNormalizedUser(row.user_jid), row.last_active);
97
+ }
98
+ const groupMeta = await this.groupMetaFn(groupJid);
99
+ return groupMeta.participants
100
+ .map(p => {
101
+ const normalizedJid = jidNormalizedUser(p.id);
102
+ const lastActive = statsMap.get(normalizedJid);
103
+ if (!lastActive) {
104
+ return { jid: normalizedJid, isTotalGhost: true };
105
+ }
106
+ if (lastActive < cutoff) {
107
+ return { jid: normalizedJid, isTotalGhost: false, lastActive };
108
+ }
109
+ return null;
110
+ })
111
+ .filter((g) => g !== null);
112
+ }
113
+
114
+ close() {
115
+ this.db.close();
116
+ }
117
+ }
@@ -0,0 +1,13 @@
1
+ export class SQLiteStore {
2
+ /** Vanz@Port: replaces the old synchronous `new SQLiteStore(dbPath)` — await this instead. */
3
+ static create(dbPath: any): Promise<SQLiteStore>;
4
+ constructor(db: any);
5
+ db: any;
6
+ getStmt: any;
7
+ setStmt: any;
8
+ delStmt: any;
9
+ get(key: any): any;
10
+ set(key: any, value: any): void;
11
+ del(key: any): void;
12
+ close(): void;
13
+ }
@@ -0,0 +1,68 @@
1
+ // Vanz@Port (from @queenanya/baileys Framework, originally Baileys PR #2710
2
+ // by LuferOS) --- generic key-value store backed by better-sqlite3. Used by
3
+ // SessionManager to persist per-JID session state to disk instead of RAM.
4
+ //
5
+ async function loadBetterSqlite3() {
6
+ try {
7
+ const mod = (await import('better-sqlite3'));
8
+ return mod.default ?? mod;
9
+ }
10
+ catch (err) {
11
+ const helpful = new Error('`better-sqlite3` is required for the Framework SQLiteStore. Install it as a peer dependency: `npm install better-sqlite3` (or `yarn add better-sqlite3`).');
12
+ helpful.cause = err;
13
+ throw helpful;
14
+ }
15
+ }
16
+
17
+ export class SQLiteStore {
18
+ constructor(db) {
19
+ this.db = db;
20
+ this.db.exec(`
21
+ CREATE TABLE IF NOT EXISTS kv_store (
22
+ key TEXT PRIMARY KEY,
23
+ value TEXT NOT NULL
24
+ )
25
+ `);
26
+ this.getStmt = this.db.prepare('SELECT value FROM kv_store WHERE key = ?');
27
+ this.setStmt = this.db.prepare('INSERT INTO kv_store (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value');
28
+ this.delStmt = this.db.prepare('DELETE FROM kv_store WHERE key = ?');
29
+ }
30
+
31
+ /** Vanz@Port: replaces the old synchronous `new SQLiteStore(dbPath)` — await this instead. */
32
+ static async create(dbPath) {
33
+ const Database = await loadBetterSqlite3();
34
+ return new SQLiteStore(new Database(dbPath));
35
+ }
36
+
37
+ get(key) {
38
+ const row = this.getStmt.get(key);
39
+ if (!row)
40
+ return undefined;
41
+ try {
42
+ return JSON.parse(row.value);
43
+ }
44
+ catch {
45
+ // Fallback for legacy non-JSON rows (migration safety)
46
+ return row.value;
47
+ }
48
+ }
49
+
50
+ set(key, value) {
51
+ // guard undefined/null — delegate to del so callers don't need to check
52
+ if (value === undefined || value === null) {
53
+ this.del(key);
54
+ return;
55
+ }
56
+ // always JSON.stringify — raw string storage breaks round-trip for
57
+ // values that are valid JSON (numbers, booleans, JSON objects serialized as strings)
58
+ this.setStmt.run(key, JSON.stringify(value));
59
+ }
60
+
61
+ del(key) {
62
+ this.delStmt.run(key);
63
+ }
64
+
65
+ close() {
66
+ this.db.close();
67
+ }
68
+ }
@@ -0,0 +1,6 @@
1
+ export { Context } from "./Context.js";
2
+ export { MediaManager } from "./MediaManager.js";
3
+ export { SessionManager } from "./SessionManager.js";
4
+ export { StatsManager } from "./StatsManager.js";
5
+ export { SQLiteStore } from "./Store/SQLiteStore.js";
6
+ export { Bot, resolveSocketVersionConfig } from "./Bot.js";
@@ -0,0 +1,11 @@
1
+ // Vanz@Port --- Enterprise Bot Framework exports.
2
+ // Source: WhiskeySockets/Baileys PR #2710 (LuferOS), via @queenanya/baileys.
3
+ // Adapted for this fork: SQLiteStore/StatsManager are lazy-loaded (see
4
+ // Store/SQLiteStore.js and StatsManager.js), MediaManager spawns the system
5
+ // `ffmpeg` binary instead of bundling fluent-ffmpeg/ffmpeg-static.
6
+ export { Bot, resolveSocketVersionConfig } from './Bot.js';
7
+ export { Context } from './Context.js';
8
+ export { MediaManager } from './MediaManager.js';
9
+ export { SessionManager } from './SessionManager.js';
10
+ export { StatsManager } from './StatsManager.js';
11
+ export { SQLiteStore } from './Store/SQLiteStore.js';
@@ -0,0 +1,9 @@
1
+ export class CiphertextMessage {
2
+ UNSUPPORTED_VERSION: number;
3
+ CURRENT_VERSION: number;
4
+ WHISPER_TYPE: number;
5
+ PREKEY_TYPE: number;
6
+ SENDERKEY_TYPE: number;
7
+ SENDERKEY_DISTRIBUTION_TYPE: number;
8
+ ENCRYPTED_MESSAGE_OVERHEAD: number;
9
+ }
@@ -0,0 +1,11 @@
1
+ export class CiphertextMessage {
2
+ constructor() {
3
+ this.UNSUPPORTED_VERSION = 1;
4
+ this.CURRENT_VERSION = 3;
5
+ this.WHISPER_TYPE = 2;
6
+ this.PREKEY_TYPE = 3;
7
+ this.SENDERKEY_TYPE = 4;
8
+ this.SENDERKEY_DISTRIBUTION_TYPE = 5;
9
+ this.ENCRYPTED_MESSAGE_OVERHEAD = 53;
10
+ }
11
+ }
@@ -0,0 +1,7 @@
1
+ export class GroupSessionBuilder {
2
+ constructor(senderKeyStore: any);
3
+ senderKeyStore: any;
4
+ process(senderKeyName: any, senderKeyDistributionMessage: any): Promise<void>;
5
+ create(senderKeyName: any): Promise<SenderKeyDistributionMessage>;
6
+ }
7
+ import { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
@@ -0,0 +1,29 @@
1
+ import * as keyhelper from './keyhelper.js';
2
+ import { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
3
+ import { SenderKeyName } from './sender-key-name.js';
4
+ import { SenderKeyRecord } from './sender-key-record.js';
5
+ export class GroupSessionBuilder {
6
+ constructor(senderKeyStore) {
7
+ this.senderKeyStore = senderKeyStore;
8
+ }
9
+ async process(senderKeyName, senderKeyDistributionMessage) {
10
+ const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
11
+ senderKeyRecord.addSenderKeyState(senderKeyDistributionMessage.getId(), senderKeyDistributionMessage.getIteration(), senderKeyDistributionMessage.getChainKey(), senderKeyDistributionMessage.getSignatureKey());
12
+ await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
13
+ }
14
+ async create(senderKeyName) {
15
+ const senderKeyRecord = await this.senderKeyStore.loadSenderKey(senderKeyName);
16
+ if (senderKeyRecord.isEmpty()) {
17
+ const keyId = keyhelper.generateSenderKeyId();
18
+ const senderKey = keyhelper.generateSenderKey();
19
+ const signingKey = keyhelper.generateSenderSigningKey();
20
+ senderKeyRecord.setSenderKeyState(keyId, 0, senderKey, signingKey);
21
+ await this.senderKeyStore.storeSenderKey(senderKeyName, senderKeyRecord);
22
+ }
23
+ const state = senderKeyRecord.getSenderKeyState();
24
+ if (!state) {
25
+ throw new Error('No session state available');
26
+ }
27
+ return new SenderKeyDistributionMessage(state.getKeyId(), state.getSenderChainKey().getIteration(), state.getSenderChainKey().getSeed(), state.getSigningKeyPublic());
28
+ }
29
+ }
@@ -0,0 +1,10 @@
1
+ export class GroupCipher {
2
+ constructor(senderKeyStore: any, senderKeyName: any);
3
+ senderKeyStore: any;
4
+ senderKeyName: any;
5
+ encrypt(paddedPlaintext: any): Promise<any>;
6
+ decrypt(senderKeyMessageBytes: any): Promise<any>;
7
+ getSenderKey(senderKeyState: any, iteration: any): any;
8
+ getPlainText(iv: any, key: any, ciphertext: any): Promise<any>;
9
+ getCipherText(iv: any, key: any, plaintext: any): Promise<any>;
10
+ }
@@ -0,0 +1,81 @@
1
+ import { decrypt, encrypt } from 'libsignal/src/crypto.js';
2
+ import { SenderKeyMessage } from './sender-key-message.js';
3
+ import { SenderKeyName } from './sender-key-name.js';
4
+ import { SenderKeyRecord } from './sender-key-record.js';
5
+ import { SenderKeyState } from './sender-key-state.js';
6
+ export class GroupCipher {
7
+ constructor(senderKeyStore, senderKeyName) {
8
+ this.senderKeyStore = senderKeyStore;
9
+ this.senderKeyName = senderKeyName;
10
+ }
11
+ async encrypt(paddedPlaintext) {
12
+ const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
13
+ if (!record) {
14
+ throw new Error('No SenderKeyRecord found for encryption');
15
+ }
16
+ const senderKeyState = record.getSenderKeyState();
17
+ if (!senderKeyState) {
18
+ throw new Error('No session to encrypt message');
19
+ }
20
+ const iteration = senderKeyState.getSenderChainKey().getIteration();
21
+ const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
22
+ const ciphertext = await this.getCipherText(senderKey.getIv(), senderKey.getCipherKey(), paddedPlaintext);
23
+ const senderKeyMessage = new SenderKeyMessage(senderKeyState.getKeyId(), senderKey.getIteration(), ciphertext, senderKeyState.getSigningKeyPrivate());
24
+ await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
25
+ return senderKeyMessage.serialize();
26
+ }
27
+ async decrypt(senderKeyMessageBytes) {
28
+ const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
29
+ if (!record) {
30
+ throw new Error('No SenderKeyRecord found for decryption');
31
+ }
32
+ const senderKeyMessage = new SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
33
+ const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
34
+ if (!senderKeyState) {
35
+ throw new Error('No session found to decrypt message');
36
+ }
37
+ senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
38
+ const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration());
39
+ const plaintext = await this.getPlainText(senderKey.getIv(), senderKey.getCipherKey(), senderKeyMessage.getCipherText());
40
+ await this.senderKeyStore.storeSenderKey(this.senderKeyName, record);
41
+ return plaintext;
42
+ }
43
+ getSenderKey(senderKeyState, iteration) {
44
+ let senderChainKey = senderKeyState.getSenderChainKey();
45
+ if (senderChainKey.getIteration() > iteration) {
46
+ if (senderKeyState.hasSenderMessageKey(iteration)) {
47
+ const messageKey = senderKeyState.removeSenderMessageKey(iteration);
48
+ if (!messageKey) {
49
+ throw new Error('No sender message key found for iteration');
50
+ }
51
+ return messageKey;
52
+ }
53
+ throw new Error(`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`);
54
+ }
55
+ if (iteration - senderChainKey.getIteration() > 2000) {
56
+ throw new Error('Over 2000 messages into the future!');
57
+ }
58
+ while (senderChainKey.getIteration() < iteration) {
59
+ senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey());
60
+ senderChainKey = senderChainKey.getNext();
61
+ }
62
+ senderKeyState.setSenderChainKey(senderChainKey.getNext());
63
+ return senderChainKey.getSenderMessageKey();
64
+ }
65
+ async getPlainText(iv, key, ciphertext) {
66
+ try {
67
+ return decrypt(key, ciphertext, iv);
68
+ }
69
+ catch (e) {
70
+ throw new Error('InvalidMessageException');
71
+ }
72
+ }
73
+ async getCipherText(iv, key, plaintext) {
74
+ try {
75
+ return encrypt(key, plaintext, iv);
76
+ }
77
+ catch (e) {
78
+ throw new Error('InvalidMessageException');
79
+ }
80
+ }
81
+ }
@@ -0,0 +1,11 @@
1
+ export { GroupSessionBuilder } from "./group-session-builder.js";
2
+ export { SenderKeyDistributionMessage } from "./sender-key-distribution-message.js";
3
+ export { SenderKeyRecord } from "./sender-key-record.js";
4
+ export { SenderKeyName } from "./sender-key-name.js";
5
+ export { GroupCipher } from "./group_cipher.js";
6
+ export { SenderKeyState } from "./sender-key-state.js";
7
+ export { SenderKeyMessage } from "./sender-key-message.js";
8
+ export { SenderMessageKey } from "./sender-message-key.js";
9
+ export { SenderChainKey } from "./sender-chain-key.js";
10
+ export { CiphertextMessage } from "./ciphertext-message.js";
11
+ export * as keyhelper from "./keyhelper.js";
@@ -0,0 +1,11 @@
1
+ export { GroupSessionBuilder } from './group-session-builder.js';
2
+ export { SenderKeyDistributionMessage } from './sender-key-distribution-message.js';
3
+ export { SenderKeyRecord } from './sender-key-record.js';
4
+ export { SenderKeyName } from './sender-key-name.js';
5
+ export { GroupCipher } from './group_cipher.js';
6
+ export { SenderKeyState } from './sender-key-state.js';
7
+ export { SenderKeyMessage } from './sender-key-message.js';
8
+ export { SenderMessageKey } from './sender-message-key.js';
9
+ export { SenderChainKey } from './sender-chain-key.js';
10
+ export { CiphertextMessage } from './ciphertext-message.js';
11
+ export * as keyhelper from './keyhelper.js';
@@ -0,0 +1,6 @@
1
+ export function generateSenderKey(): any;
2
+ export function generateSenderKeyId(): any;
3
+ export function generateSenderSigningKey(key: any): {
4
+ public: any;
5
+ private: any;
6
+ };
@@ -0,0 +1,17 @@
1
+ import * as nodeCrypto from 'crypto';
2
+ import { generateKeyPair } from 'libsignal/src/curve.js';
3
+ export function generateSenderKey() {
4
+ return nodeCrypto.randomBytes(32);
5
+ }
6
+ export function generateSenderKeyId() {
7
+ return nodeCrypto.randomInt(2147483647);
8
+ }
9
+ export function generateSenderSigningKey(key) {
10
+ if (!key) {
11
+ key = generateKeyPair();
12
+ }
13
+ return {
14
+ public: Buffer.from(key.pubKey),
15
+ private: Buffer.from(key.privKey)
16
+ };
17
+ }
@@ -0,0 +1,13 @@
1
+ export class SenderChainKey {
2
+ constructor(iteration: any, chainKey: any);
3
+ MESSAGE_KEY_SEED: any;
4
+ CHAIN_KEY_SEED: any;
5
+ iteration: any;
6
+ chainKey: any;
7
+ getIteration(): any;
8
+ getSenderMessageKey(): SenderMessageKey;
9
+ getNext(): SenderChainKey;
10
+ getSeed(): any;
11
+ getDerivative(seed: any, key: any): any;
12
+ }
13
+ import { SenderMessageKey } from './sender-message-key.js';
@@ -0,0 +1,25 @@
1
+ import { calculateMAC } from 'libsignal/src/crypto.js';
2
+ import { SenderMessageKey } from './sender-message-key.js';
3
+ export class SenderChainKey {
4
+ constructor(iteration, chainKey) {
5
+ this.MESSAGE_KEY_SEED = Buffer.from([0x01]);
6
+ this.CHAIN_KEY_SEED = Buffer.from([0x02]);
7
+ this.iteration = iteration;
8
+ this.chainKey = Buffer.from(chainKey);
9
+ }
10
+ getIteration() {
11
+ return this.iteration;
12
+ }
13
+ getSenderMessageKey() {
14
+ return new SenderMessageKey(this.iteration, this.getDerivative(this.MESSAGE_KEY_SEED, this.chainKey));
15
+ }
16
+ getNext() {
17
+ return new SenderChainKey(this.iteration + 1, this.getDerivative(this.CHAIN_KEY_SEED, this.chainKey));
18
+ }
19
+ getSeed() {
20
+ return this.chainKey;
21
+ }
22
+ getDerivative(seed, key) {
23
+ return calculateMAC(key, seed);
24
+ }
25
+ }
@@ -0,0 +1,16 @@
1
+ export class SenderKeyDistributionMessage extends CiphertextMessage {
2
+ constructor(id: any, iteration: any, chainKey: any, signatureKey: any, serialized: any);
3
+ serialized: any;
4
+ id: any;
5
+ iteration: any;
6
+ chainKey: any;
7
+ signatureKey: any;
8
+ intsToByteHighAndLow(highValue: any, lowValue: any): number;
9
+ serialize(): any;
10
+ getType(): number;
11
+ getIteration(): any;
12
+ getChainKey(): any;
13
+ getSignatureKey(): any;
14
+ getId(): any;
15
+ }
16
+ import { CiphertextMessage } from './ciphertext-message.js';
@@ -0,0 +1,62 @@
1
+ import { proto } from '../../../WAProto/index.js';
2
+ import { CiphertextMessage } from './ciphertext-message.js';
3
+ export class SenderKeyDistributionMessage extends CiphertextMessage {
4
+ constructor(id, iteration, chainKey, signatureKey, serialized) {
5
+ super();
6
+ if (serialized) {
7
+ try {
8
+ const message = serialized.slice(1);
9
+ const distributionMessage = proto.SenderKeyDistributionMessage.decode(message).toJSON();
10
+ this.serialized = serialized;
11
+ this.id = distributionMessage.id;
12
+ this.iteration = distributionMessage.iteration;
13
+ this.chainKey =
14
+ typeof distributionMessage.chainKey === 'string'
15
+ ? Buffer.from(distributionMessage.chainKey, 'base64')
16
+ : distributionMessage.chainKey;
17
+ this.signatureKey =
18
+ typeof distributionMessage.signingKey === 'string'
19
+ ? Buffer.from(distributionMessage.signingKey, 'base64')
20
+ : distributionMessage.signingKey;
21
+ }
22
+ catch (e) {
23
+ throw new Error(String(e));
24
+ }
25
+ }
26
+ else {
27
+ const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION);
28
+ this.id = id;
29
+ this.iteration = iteration;
30
+ this.chainKey = chainKey;
31
+ this.signatureKey = signatureKey;
32
+ const message = proto.SenderKeyDistributionMessage.encode(proto.SenderKeyDistributionMessage.create({
33
+ id,
34
+ iteration,
35
+ chainKey,
36
+ signingKey: this.signatureKey
37
+ })).finish();
38
+ this.serialized = Buffer.concat([Buffer.from([version]), message]);
39
+ }
40
+ }
41
+ intsToByteHighAndLow(highValue, lowValue) {
42
+ return (((highValue << 4) | lowValue) & 0xff) % 256;
43
+ }
44
+ serialize() {
45
+ return this.serialized;
46
+ }
47
+ getType() {
48
+ return this.SENDERKEY_DISTRIBUTION_TYPE;
49
+ }
50
+ getIteration() {
51
+ return this.iteration;
52
+ }
53
+ getChainKey() {
54
+ return this.chainKey;
55
+ }
56
+ getSignatureKey() {
57
+ return this.signatureKey;
58
+ }
59
+ getId() {
60
+ return this.id;
61
+ }
62
+ }
@@ -0,0 +1,18 @@
1
+ export class SenderKeyMessage extends CiphertextMessage {
2
+ constructor(keyId: any, iteration: any, ciphertext: any, signatureKey: any, serialized: any);
3
+ SIGNATURE_LENGTH: number;
4
+ serialized: any;
5
+ messageVersion: number;
6
+ keyId: any;
7
+ iteration: any;
8
+ ciphertext: any;
9
+ signature: any;
10
+ getKeyId(): any;
11
+ getIteration(): any;
12
+ getCipherText(): any;
13
+ verifySignature(signatureKey: any): void;
14
+ getSignature(signatureKey: any, serialized: any): any;
15
+ serialize(): any;
16
+ getType(): number;
17
+ }
18
+ import { CiphertextMessage } from './ciphertext-message.js';
@@ -0,0 +1,65 @@
1
+ import { calculateSignature, verifySignature } from 'libsignal/src/curve.js';
2
+ import { proto } from '../../../WAProto/index.js';
3
+ import { CiphertextMessage } from './ciphertext-message.js';
4
+ export class SenderKeyMessage extends CiphertextMessage {
5
+ constructor(keyId, iteration, ciphertext, signatureKey, serialized) {
6
+ super();
7
+ this.SIGNATURE_LENGTH = 64;
8
+ if (serialized) {
9
+ const version = serialized[0];
10
+ const message = serialized.slice(1, serialized.length - this.SIGNATURE_LENGTH);
11
+ const signature = serialized.slice(-1 * this.SIGNATURE_LENGTH);
12
+ const senderKeyMessage = proto.SenderKeyMessage.decode(message).toJSON();
13
+ this.serialized = serialized;
14
+ this.messageVersion = (version & 0xff) >> 4;
15
+ this.keyId = senderKeyMessage.id;
16
+ this.iteration = senderKeyMessage.iteration;
17
+ this.ciphertext =
18
+ typeof senderKeyMessage.ciphertext === 'string'
19
+ ? Buffer.from(senderKeyMessage.ciphertext, 'base64')
20
+ : senderKeyMessage.ciphertext;
21
+ this.signature = signature;
22
+ }
23
+ else {
24
+ const version = (((this.CURRENT_VERSION << 4) | this.CURRENT_VERSION) & 0xff) % 256;
25
+ const ciphertextBuffer = Buffer.from(ciphertext);
26
+ const message = proto.SenderKeyMessage.encode(proto.SenderKeyMessage.create({
27
+ id: keyId,
28
+ iteration: iteration,
29
+ ciphertext: ciphertextBuffer
30
+ })).finish();
31
+ const signature = this.getSignature(signatureKey, Buffer.concat([Buffer.from([version]), message]));
32
+ this.serialized = Buffer.concat([Buffer.from([version]), message, Buffer.from(signature)]);
33
+ this.messageVersion = this.CURRENT_VERSION;
34
+ this.keyId = keyId;
35
+ this.iteration = iteration;
36
+ this.ciphertext = ciphertextBuffer;
37
+ this.signature = signature;
38
+ }
39
+ }
40
+ getKeyId() {
41
+ return this.keyId;
42
+ }
43
+ getIteration() {
44
+ return this.iteration;
45
+ }
46
+ getCipherText() {
47
+ return this.ciphertext;
48
+ }
49
+ verifySignature(signatureKey) {
50
+ const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
51
+ const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
52
+ const res = verifySignature(signatureKey, part1, part2);
53
+ if (!res)
54
+ throw new Error('Invalid signature!');
55
+ }
56
+ getSignature(signatureKey, serialized) {
57
+ return Buffer.from(calculateSignature(signatureKey, serialized));
58
+ }
59
+ serialize() {
60
+ return this.serialized;
61
+ }
62
+ getType() {
63
+ return 4;
64
+ }
65
+ }
@@ -0,0 +1,11 @@
1
+ export class SenderKeyName {
2
+ constructor(groupId: any, sender: any);
3
+ groupId: any;
4
+ sender: any;
5
+ getGroupId(): any;
6
+ getSender(): any;
7
+ serialize(): string;
8
+ toString(): string;
9
+ equals(other: any): boolean;
10
+ hashCode(): number;
11
+ }