@deffa5556/bail 1.0.6 → 1.0.9

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 (316) hide show
  1. package/cjs/WAProto/index.cjs +106053 -0
  2. package/cjs/deffa/config.cjs +14 -0
  3. package/cjs/deffa/plugins/ai/deepseekr1.cjs +35 -0
  4. package/cjs/deffa/plugins/ai/gita.cjs +26 -0
  5. package/cjs/deffa/plugins/ai/glm47flash.cjs +35 -0
  6. package/cjs/deffa/plugins/ai/gptoss120b.cjs +35 -0
  7. package/cjs/deffa/plugins/ai/qwq32b.cjs +35 -0
  8. package/cjs/deffa/plugins/berita/antara.cjs +25 -0
  9. package/cjs/deffa/plugins/berita/cnbcindonesia.cjs +25 -0
  10. package/cjs/deffa/plugins/berita/cnn.cjs +25 -0
  11. package/cjs/deffa/plugins/berita/kompas.cjs +25 -0
  12. package/cjs/deffa/plugins/berita/liputan6.cjs +25 -0
  13. package/cjs/deffa/plugins/berita/merdeka.cjs +25 -0
  14. package/cjs/deffa/plugins/berita/sindonews.cjs +25 -0
  15. package/cjs/deffa/plugins/berita/tribunnews.cjs +25 -0
  16. package/cjs/deffa/plugins/downloader/douyin.cjs +30 -0
  17. package/cjs/deffa/plugins/downloader/facebook.cjs +30 -0
  18. package/cjs/deffa/plugins/downloader/github.cjs +35 -0
  19. package/cjs/deffa/plugins/downloader/lahelu.cjs +30 -0
  20. package/cjs/deffa/plugins/downloader/snackvideo.cjs +30 -0
  21. package/cjs/deffa/plugins/downloader/soundcloud.cjs +30 -0
  22. package/cjs/deffa/plugins/downloader/tiktok.cjs +30 -0
  23. package/cjs/deffa/plugins/downloader/tiktokhd.cjs +30 -0
  24. package/cjs/deffa/plugins/downloader/twitter.cjs +30 -0
  25. package/cjs/deffa/plugins/downloader/ummy.cjs +36 -0
  26. package/cjs/deffa/plugins/index.cjs +213 -0
  27. package/cjs/deffa/plugins/info/bmkg.cjs +34 -0
  28. package/cjs/deffa/plugins/info/cuaca.cjs +31 -0
  29. package/cjs/deffa/plugins/info/jadwaltv.cjs +29 -0
  30. package/cjs/deffa/plugins/maker/brat.cjs +45 -0
  31. package/cjs/deffa/plugins/maker/bratvid.cjs +52 -0
  32. package/cjs/deffa/plugins/search/8font.cjs +28 -0
  33. package/cjs/deffa/plugins/search/applemusic.cjs +28 -0
  34. package/cjs/deffa/plugins/search/bimg.cjs +30 -0
  35. package/cjs/deffa/plugins/search/brave.cjs +34 -0
  36. package/cjs/deffa/plugins/search/duckduckgo.cjs +28 -0
  37. package/cjs/deffa/plugins/search/lahelu.cjs +28 -0
  38. package/cjs/deffa/plugins/search/mangatoon.cjs +28 -0
  39. package/cjs/deffa/plugins/search/mcpedl.cjs +28 -0
  40. package/cjs/deffa/plugins/search/myinstants.cjs +28 -0
  41. package/cjs/deffa/plugins/search/otakotaku.cjs +28 -0
  42. package/cjs/deffa/plugins/search/pinterest.cjs +30 -0
  43. package/cjs/deffa/plugins/search/resep.cjs +28 -0
  44. package/cjs/deffa/plugins/search/seegore.cjs +30 -0
  45. package/cjs/deffa/plugins/search/soundcloud.cjs +28 -0
  46. package/cjs/deffa/plugins/search/youtube.cjs +28 -0
  47. package/cjs/deffa/plugins/stalk/github.cjs +38 -0
  48. package/cjs/deffa/plugins/stalk/pinterest.cjs +37 -0
  49. package/cjs/deffa/plugins/stalk/threads.cjs +34 -0
  50. package/cjs/deffa/plugins/stalk/tiktok.cjs +37 -0
  51. package/cjs/deffa/plugins/stalk/twitter.cjs +37 -0
  52. package/cjs/deffa/plugins/stalk/youtube.cjs +37 -0
  53. package/cjs/lib/Defaults/index.cjs +158 -0
  54. package/cjs/lib/Discord/Client.cjs +263 -0
  55. package/cjs/lib/Discord/Constants.cjs +1842 -0
  56. package/cjs/lib/Discord/connect-dc.cjs +11 -0
  57. package/cjs/lib/Discord/esm-bridge.cjs +136 -0
  58. package/cjs/lib/Discord/gateway/Dispatcher.cjs +93 -0
  59. package/cjs/lib/Discord/gateway/Shard.cjs +695 -0
  60. package/cjs/lib/Discord/gateway/ShardManager.cjs +344 -0
  61. package/cjs/lib/Discord/gateway/compression/base.cjs +13 -0
  62. package/cjs/lib/Discord/gateway/compression/config.cjs +47 -0
  63. package/cjs/lib/Discord/gateway/compression/pako.cjs +44 -0
  64. package/cjs/lib/Discord/gateway/compression/zlib-native.cjs +47 -0
  65. package/cjs/lib/Discord/gateway/compression/zlib-sync.cjs +31 -0
  66. package/cjs/lib/Discord/gateway/compression/zstd-napi.cjs +80 -0
  67. package/cjs/lib/Discord/gateway/compression/zstd-native.cjs +46 -0
  68. package/cjs/lib/Discord/gateway/events.cjs +956 -0
  69. package/cjs/lib/Discord/index.cjs +238 -0
  70. package/cjs/lib/Discord/rest/Bucket.cjs +69 -0
  71. package/cjs/lib/Discord/rest/DiscordHTTPError.cjs +63 -0
  72. package/cjs/lib/Discord/rest/DiscordRESTError.cjs +84 -0
  73. package/cjs/lib/Discord/rest/OAuthHelper.cjs +226 -0
  74. package/cjs/lib/Discord/rest/RESTManager.cjs +116 -0
  75. package/cjs/lib/Discord/rest/RequestHandler.cjs +320 -0
  76. package/cjs/lib/Discord/rest/SequentialBucket.cjs +69 -0
  77. package/cjs/lib/Discord/routes/Applications.cjs +625 -0
  78. package/cjs/lib/Discord/routes/Channels.cjs +1199 -0
  79. package/cjs/lib/Discord/routes/Guilds.cjs +1792 -0
  80. package/cjs/lib/Discord/routes/Interactions.cjs +212 -0
  81. package/cjs/lib/Discord/routes/Lobbies.cjs +197 -0
  82. package/cjs/lib/Discord/routes/Miscellaneous.cjs +120 -0
  83. package/cjs/lib/Discord/routes/OAuth.cjs +350 -0
  84. package/cjs/lib/Discord/routes/Users.cjs +107 -0
  85. package/cjs/lib/Discord/routes/Webhooks.cjs +308 -0
  86. package/cjs/lib/Discord/structures/AnnouncementChannel.cjs +46 -0
  87. package/cjs/lib/Discord/structures/AnnouncementThreadChannel.cjs +28 -0
  88. package/cjs/lib/Discord/structures/Application.cjs +345 -0
  89. package/cjs/lib/Discord/structures/ApplicationCommand.cjs +109 -0
  90. package/cjs/lib/Discord/structures/Attachment.cjs +46 -0
  91. package/cjs/lib/Discord/structures/AuditLogEntry.cjs +41 -0
  92. package/cjs/lib/Discord/structures/AutoModerationRule.cjs +117 -0
  93. package/cjs/lib/Discord/structures/AutocompleteInteraction.cjs +90 -0
  94. package/cjs/lib/Discord/structures/Base.cjs +56 -0
  95. package/cjs/lib/Discord/structures/BaseEntitlement.cjs +40 -0
  96. package/cjs/lib/Discord/structures/CategoryChannel.cjs +102 -0
  97. package/cjs/lib/Discord/structures/Channel.cjs +89 -0
  98. package/cjs/lib/Discord/structures/ClientApplication.cjs +269 -0
  99. package/cjs/lib/Discord/structures/CommandInteraction.cjs +294 -0
  100. package/cjs/lib/Discord/structures/ComponentInteraction.cjs +306 -0
  101. package/cjs/lib/Discord/structures/Entitlement.cjs +24 -0
  102. package/cjs/lib/Discord/structures/ExtendedUser.cjs +48 -0
  103. package/cjs/lib/Discord/structures/ForumChannel.cjs +20 -0
  104. package/cjs/lib/Discord/structures/GroupChannel.cjs +160 -0
  105. package/cjs/lib/Discord/structures/Guild.cjs +1289 -0
  106. package/cjs/lib/Discord/structures/GuildChannel.cjs +82 -0
  107. package/cjs/lib/Discord/structures/GuildPreview.cjs +141 -0
  108. package/cjs/lib/Discord/structures/GuildScheduledEvent.cjs +166 -0
  109. package/cjs/lib/Discord/structures/GuildTemplate.cjs +96 -0
  110. package/cjs/lib/Discord/structures/Integration.cjs +123 -0
  111. package/cjs/lib/Discord/structures/Interaction.cjs +78 -0
  112. package/cjs/lib/Discord/structures/InteractionResolvedChannel.cjs +36 -0
  113. package/cjs/lib/Discord/structures/Invite.cjs +196 -0
  114. package/cjs/lib/Discord/structures/InviteGuild.cjs +117 -0
  115. package/cjs/lib/Discord/structures/InviteRole.cjs +88 -0
  116. package/cjs/lib/Discord/structures/Lobby.cjs +84 -0
  117. package/cjs/lib/Discord/structures/LobbyMember.cjs +30 -0
  118. package/cjs/lib/Discord/structures/MediaChannel.cjs +20 -0
  119. package/cjs/lib/Discord/structures/Member.cjs +300 -0
  120. package/cjs/lib/Discord/structures/Message.cjs +553 -0
  121. package/cjs/lib/Discord/structures/ModalSubmitInteraction.cjs +263 -0
  122. package/cjs/lib/Discord/structures/OAuthApplication.cjs +203 -0
  123. package/cjs/lib/Discord/structures/OAuthGuild.cjs +98 -0
  124. package/cjs/lib/Discord/structures/PartialApplication.cjs +97 -0
  125. package/cjs/lib/Discord/structures/Permission.cjs +61 -0
  126. package/cjs/lib/Discord/structures/PermissionOverwrite.cjs +46 -0
  127. package/cjs/lib/Discord/structures/PingInteraction.cjs +27 -0
  128. package/cjs/lib/Discord/structures/Poll.cjs +69 -0
  129. package/cjs/lib/Discord/structures/PrimaryGuild.cjs +93 -0
  130. package/cjs/lib/Discord/structures/PrivateChannel.cjs +131 -0
  131. package/cjs/lib/Discord/structures/PrivateThreadChannel.cjs +28 -0
  132. package/cjs/lib/Discord/structures/PublicThreadChannel.cjs +36 -0
  133. package/cjs/lib/Discord/structures/Role.cjs +126 -0
  134. package/cjs/lib/Discord/structures/SKU.cjs +58 -0
  135. package/cjs/lib/Discord/structures/Soundboard.cjs +58 -0
  136. package/cjs/lib/Discord/structures/StageChannel.cjs +45 -0
  137. package/cjs/lib/Discord/structures/StageInstance.cjs +80 -0
  138. package/cjs/lib/Discord/structures/Subscription.cjs +21 -0
  139. package/cjs/lib/Discord/structures/Team.cjs +70 -0
  140. package/cjs/lib/Discord/structures/TestEntitlement.cjs +22 -0
  141. package/cjs/lib/Discord/structures/TextChannel.cjs +48 -0
  142. package/cjs/lib/Discord/structures/TextableChannel.cjs +265 -0
  143. package/cjs/lib/Discord/structures/TextableVoiceChannel.cjs +70 -0
  144. package/cjs/lib/Discord/structures/ThreadChannel.cjs +276 -0
  145. package/cjs/lib/Discord/structures/ThreadOnlyChannel.cjs +205 -0
  146. package/cjs/lib/Discord/structures/ThreadableChannel.cjs +57 -0
  147. package/cjs/lib/Discord/structures/UnavailableGuild.cjs +21 -0
  148. package/cjs/lib/Discord/structures/User.cjs +223 -0
  149. package/cjs/lib/Discord/structures/VoiceChannel.cjs +34 -0
  150. package/cjs/lib/Discord/structures/VoiceState.cjs +113 -0
  151. package/cjs/lib/Discord/structures/Webhook.cjs +224 -0
  152. package/cjs/lib/Discord/util/Collection.cjs +77 -0
  153. package/cjs/lib/Discord/util/Errors.cjs +81 -0
  154. package/cjs/lib/Discord/util/QueryBuilder.cjs +20 -0
  155. package/cjs/lib/Discord/util/Routes.cjs +293 -0
  156. package/cjs/lib/Discord/util/SimpleCollection.cjs +78 -0
  157. package/cjs/lib/Discord/util/Time.cjs +92 -0
  158. package/cjs/lib/Discord/util/TypedCollection.cjs +78 -0
  159. package/cjs/lib/Discord/util/TypedEmitter.cjs +20 -0
  160. package/cjs/lib/Discord/util/Util.cjs +906 -0
  161. package/cjs/lib/Discord/util/interactions/InteractionOptionsWrapper.cjs +207 -0
  162. package/cjs/lib/Discord/util/interactions/MessageInteractionResponse.cjs +26 -0
  163. package/cjs/lib/Discord/util/interactions/ModalSubmitInteractionComponentsWrapper.cjs +98 -0
  164. package/cjs/lib/Discord/util/interactions/SelectMenuValuesWrapper.cjs +77 -0
  165. package/cjs/lib/Discord/util/interactions/shared.cjs +20 -0
  166. package/cjs/lib/Discord/util/warning.cjs +34 -0
  167. package/cjs/lib/Signal/Group/ciphertext-message.cjs +16 -0
  168. package/cjs/lib/Signal/Group/group-session-builder.cjs +67 -0
  169. package/cjs/lib/Signal/Group/group_cipher.cjs +86 -0
  170. package/cjs/lib/Signal/Group/index.cjs +58 -0
  171. package/cjs/lib/Signal/Group/keyhelper.cjs +56 -0
  172. package/cjs/lib/Signal/Group/sender-chain-key.cjs +30 -0
  173. package/cjs/lib/Signal/Group/sender-key-distribution-message.cjs +67 -0
  174. package/cjs/lib/Signal/Group/sender-key-message.cjs +70 -0
  175. package/cjs/lib/Signal/Group/sender-key-name.cjs +52 -0
  176. package/cjs/lib/Signal/Group/sender-key-record.cjs +45 -0
  177. package/cjs/lib/Signal/Group/sender-key-state.cjs +88 -0
  178. package/cjs/lib/Signal/Group/sender-message-key.cjs +30 -0
  179. package/cjs/lib/Signal/libsignal.cjs +467 -0
  180. package/cjs/lib/Signal/lid-mapping.cjs +281 -0
  181. package/cjs/lib/Socket/Client/index.cjs +19 -0
  182. package/cjs/lib/Socket/Client/types.cjs +15 -0
  183. package/cjs/lib/Socket/Client/websocket.cjs +61 -0
  184. package/cjs/lib/Socket/business.cjs +384 -0
  185. package/cjs/lib/Socket/chats.cjs +1221 -0
  186. package/cjs/lib/Socket/communities.cjs +440 -0
  187. package/cjs/lib/Socket/groups.cjs +353 -0
  188. package/cjs/lib/Socket/index.cjs +14 -0
  189. package/cjs/lib/Socket/messages-recv.cjs +1772 -0
  190. package/cjs/lib/Socket/messages-send.cjs +1376 -0
  191. package/cjs/lib/Socket/mex.cjs +46 -0
  192. package/cjs/lib/Socket/newsletter.cjs +230 -0
  193. package/cjs/lib/Socket/socket.cjs +976 -0
  194. package/cjs/lib/Store/index.cjs +20 -0
  195. package/cjs/lib/Store/make-in-memory-store.cjs +470 -0
  196. package/cjs/lib/Store/make-ordered-dictionary.cjs +82 -0
  197. package/cjs/lib/Store/object-repository.cjs +28 -0
  198. package/cjs/lib/Telegram/button.cjs +147 -0
  199. package/cjs/lib/Telegram/composer.cjs +582 -0
  200. package/cjs/lib/Telegram/context.cjs +853 -0
  201. package/cjs/lib/Telegram/core/helpers/args.cjs +57 -0
  202. package/cjs/lib/Telegram/core/helpers/check.cjs +55 -0
  203. package/cjs/lib/Telegram/core/helpers/compact.cjs +16 -0
  204. package/cjs/lib/Telegram/core/helpers/deunionize.cjs +12 -0
  205. package/cjs/lib/Telegram/core/helpers/formatting.cjs +91 -0
  206. package/cjs/lib/Telegram/core/helpers/util.cjs +50 -0
  207. package/cjs/lib/Telegram/core/network/client.cjs +338 -0
  208. package/cjs/lib/Telegram/core/network/error.cjs +21 -0
  209. package/cjs/lib/Telegram/core/network/multipart-stream.cjs +79 -0
  210. package/cjs/lib/Telegram/core/network/polling.cjs +87 -0
  211. package/cjs/lib/Telegram/core/network/webhook.cjs +54 -0
  212. package/cjs/lib/Telegram/core/types/typegram.cjs +31 -0
  213. package/cjs/lib/Telegram/deffa-telegraf.cjs +264 -0
  214. package/cjs/lib/Telegram/esm-bridge.cjs +20 -0
  215. package/cjs/lib/Telegram/filters.cjs +69 -0
  216. package/cjs/lib/Telegram/format.cjs +58 -0
  217. package/cjs/lib/Telegram/future.cjs +140 -0
  218. package/cjs/lib/Telegram/index.cjs +67 -0
  219. package/cjs/lib/Telegram/input.cjs +61 -0
  220. package/cjs/lib/Telegram/markup.cjs +129 -0
  221. package/cjs/lib/Telegram/middleware.cjs +2 -0
  222. package/cjs/lib/Telegram/reactions.cjs +84 -0
  223. package/cjs/lib/Telegram/router.cjs +46 -0
  224. package/cjs/lib/Telegram/scenes/base.cjs +39 -0
  225. package/cjs/lib/Telegram/scenes/context.cjs +104 -0
  226. package/cjs/lib/Telegram/scenes/index.cjs +21 -0
  227. package/cjs/lib/Telegram/scenes/stage.cjs +49 -0
  228. package/cjs/lib/Telegram/scenes/wizard/context.cjs +31 -0
  229. package/cjs/lib/Telegram/scenes/wizard/index.cjs +45 -0
  230. package/cjs/lib/Telegram/scenes.cjs +21 -0
  231. package/cjs/lib/Telegram/session.cjs +166 -0
  232. package/cjs/lib/Telegram/telegram-types.cjs +6 -0
  233. package/cjs/lib/Telegram/telegram.cjs +945 -0
  234. package/cjs/lib/Telegram/types.cjs +2 -0
  235. package/cjs/lib/Telegram/utils.cjs +5 -0
  236. package/cjs/lib/Types/Auth.cjs +3 -0
  237. package/cjs/lib/Types/Bussines.cjs +3 -0
  238. package/cjs/lib/Types/Call.cjs +3 -0
  239. package/cjs/lib/Types/Chat.cjs +11 -0
  240. package/cjs/lib/Types/Contact.cjs +3 -0
  241. package/cjs/lib/Types/Events.cjs +4 -0
  242. package/cjs/lib/Types/GroupMetadata.cjs +3 -0
  243. package/cjs/lib/Types/Label.cjs +26 -0
  244. package/cjs/lib/Types/LabelAssociation.cjs +8 -0
  245. package/cjs/lib/Types/Message.cjs +19 -0
  246. package/cjs/lib/Types/Mex.cjs +40 -0
  247. package/cjs/lib/Types/Product.cjs +3 -0
  248. package/cjs/lib/Types/RichType.cjs +24 -0
  249. package/cjs/lib/Types/Signal.cjs +4 -0
  250. package/cjs/lib/Types/Socket.cjs +4 -0
  251. package/cjs/lib/Types/State.cjs +54 -0
  252. package/cjs/lib/Types/USync.cjs +4 -0
  253. package/cjs/lib/Types/index.cjs +42 -0
  254. package/cjs/lib/Utils/auth-utils.cjs +312 -0
  255. package/cjs/lib/Utils/browser-utils.cjs +39 -0
  256. package/cjs/lib/Utils/business.cjs +241 -0
  257. package/cjs/lib/Utils/chat-utils.cjs +890 -0
  258. package/cjs/lib/Utils/companion-reg-client-utils.cjs +51 -0
  259. package/cjs/lib/Utils/crypto.cjs +170 -0
  260. package/cjs/lib/Utils/decode-wa-message.cjs +330 -0
  261. package/cjs/lib/Utils/event-buffer.cjs +629 -0
  262. package/cjs/lib/Utils/generics.cjs +427 -0
  263. package/cjs/lib/Utils/history.cjs +141 -0
  264. package/cjs/lib/Utils/identity-change-handler.cjs +56 -0
  265. package/cjs/lib/Utils/index.cjs +43 -0
  266. package/cjs/lib/Utils/link-preview.cjs +122 -0
  267. package/cjs/lib/Utils/logger.cjs +8 -0
  268. package/cjs/lib/Utils/lt-hash.cjs +11 -0
  269. package/cjs/lib/Utils/make-mutex.cjs +38 -0
  270. package/cjs/lib/Utils/message-retry-manager.cjs +267 -0
  271. package/cjs/lib/Utils/messages-media.cjs +906 -0
  272. package/cjs/lib/Utils/messages.cjs +1909 -0
  273. package/cjs/lib/Utils/noise-handler.cjs +205 -0
  274. package/cjs/lib/Utils/offline-node-processor.cjs +43 -0
  275. package/cjs/lib/Utils/pre-key-manager.cjs +113 -0
  276. package/cjs/lib/Utils/process-message.cjs +755 -0
  277. package/cjs/lib/Utils/reporting-utils.cjs +263 -0
  278. package/cjs/lib/Utils/rich-message-utils.cjs +434 -0
  279. package/cjs/lib/Utils/session-guard.cjs +163 -0
  280. package/cjs/lib/Utils/signal.cjs +214 -0
  281. package/cjs/lib/Utils/stanza-ack.cjs +41 -0
  282. package/cjs/lib/Utils/sync-action-utils.cjs +54 -0
  283. package/cjs/lib/Utils/tc-token-utils.cjs +174 -0
  284. package/cjs/lib/Utils/text-sticker.cjs +174 -0
  285. package/cjs/lib/Utils/use-multi-file-auth-state.cjs +125 -0
  286. package/cjs/lib/Utils/use-single-file-auth-state.cjs +113 -0
  287. package/cjs/lib/Utils/use-sqlite-auth-state.cjs +145 -0
  288. package/cjs/lib/Utils/validate-connection.cjs +210 -0
  289. package/cjs/lib/WABinary/constants.cjs +1470 -0
  290. package/cjs/lib/WABinary/decode.cjs +301 -0
  291. package/cjs/lib/WABinary/encode.cjs +257 -0
  292. package/cjs/lib/WABinary/generic-utils.cjs +240 -0
  293. package/cjs/lib/WABinary/index.cjs +22 -0
  294. package/cjs/lib/WABinary/jid-utils.cjs +114 -0
  295. package/cjs/lib/WABinary/types.cjs +37 -0
  296. package/cjs/lib/WAM/BinaryInfo.cjs +14 -0
  297. package/cjs/lib/WAM/constants.cjs +22856 -0
  298. package/cjs/lib/WAM/encode.cjs +154 -0
  299. package/cjs/lib/WAM/index.cjs +20 -0
  300. package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.cjs +56 -0
  301. package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.cjs +58 -0
  302. package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.cjs +31 -0
  303. package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.cjs +42 -0
  304. package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.cjs +29 -0
  305. package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.cjs +55 -0
  306. package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.cjs +33 -0
  307. package/cjs/lib/WAUSync/Protocols/index.cjs +22 -0
  308. package/cjs/lib/WAUSync/USyncQuery.cjs +102 -0
  309. package/cjs/lib/WAUSync/USyncUser.cjs +35 -0
  310. package/cjs/lib/WAUSync/index.cjs +20 -0
  311. package/cjs/lib/index.cjs +372 -0
  312. package/cjs/lib/plugins/loader.cjs +117 -0
  313. package/lib/Defaults/index.js +1 -1
  314. package/lib/Socket/socket.js +3 -3
  315. package/lib/Telegram/esm-bridge.mjs +1 -1
  316. package/package.json +11 -6
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildPairingQRData = exports.getCompanionPlatformId = exports.getCompanionWebClientType = exports.CompanionWebClientType = void 0;
4
+ (function (CompanionWebClientType) {
5
+ CompanionWebClientType[CompanionWebClientType["UNKNOWN"] = 0] = "UNKNOWN";
6
+ CompanionWebClientType[CompanionWebClientType["CHROME"] = 1] = "CHROME";
7
+ CompanionWebClientType[CompanionWebClientType["EDGE"] = 2] = "EDGE";
8
+ CompanionWebClientType[CompanionWebClientType["FIREFOX"] = 3] = "FIREFOX";
9
+ CompanionWebClientType[CompanionWebClientType["IE"] = 4] = "IE";
10
+ CompanionWebClientType[CompanionWebClientType["OPERA"] = 5] = "OPERA";
11
+ CompanionWebClientType[CompanionWebClientType["SAFARI"] = 6] = "SAFARI";
12
+ CompanionWebClientType[CompanionWebClientType["ELECTRON"] = 7] = "ELECTRON";
13
+ CompanionWebClientType[CompanionWebClientType["UWP"] = 8] = "UWP";
14
+ CompanionWebClientType[CompanionWebClientType["OTHER_WEB_CLIENT"] = 9] = "OTHER_WEB_CLIENT";
15
+ })(exports.CompanionWebClientType || (exports.CompanionWebClientType = {}));
16
+ // Browser name → WA Companion type mapping
17
+ // Browser yang tidak dikenal WA (Kiwi, UC, Brave, dll) di-spoof sebagai Chrome (ID: 1)
18
+ // supaya pairing tetap stabil dan tidak kena reject server
19
+ const BROWSER_TO_COMPANION_WEB_CLIENT = {
20
+ Chrome: exports.CompanionWebClientType.CHROME,
21
+ Edge: exports.CompanionWebClientType.EDGE,
22
+ Firefox: exports.CompanionWebClientType.FIREFOX,
23
+ IE: exports.CompanionWebClientType.IE,
24
+ Opera: exports.CompanionWebClientType.OPERA,
25
+ Safari: exports.CompanionWebClientType.SAFARI
26
+ };
27
+ const getCompanionWebClientType = ([os, browserName]) => {
28
+ if (browserName === 'Desktop') {
29
+ return os === 'Windows' ? exports.CompanionWebClientType.UWP : exports.CompanionWebClientType.ELECTRON;
30
+ }
31
+ // Browser apapun yang tidak ada di mapping (Kiwi, UC, Brave, Vivaldi, Arc, dll)
32
+ // akan fallback ke CHROME (ID: 1) bukan OTHER_WEB_CLIENT (ID: 9)
33
+ // ini lebih aman karena WA server lebih toleran terhadap Chrome
34
+ return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] ?? exports.CompanionWebClientType.CHROME;
35
+ };
36
+ exports.getCompanionWebClientType = getCompanionWebClientType;
37
+ const getCompanionPlatformId = (browser) => {
38
+ return (0, exports.getCompanionWebClientType)(browser).toString();
39
+ };
40
+ exports.getCompanionPlatformId = getCompanionPlatformId;
41
+ const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
42
+ return 'https://wa.me/settings/linked_devices#' + [
43
+ ref,
44
+ noiseKeyB64,
45
+ identityKeyB64,
46
+ advB64,
47
+ (0, exports.getCompanionPlatformId)(browser)
48
+ ].join(',');
49
+ };
50
+ exports.buildPairingQRData = buildPairingQRData;
51
+ //# sourceMappingURL=companion-reg-client-utils.js.map
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = exports.hkdf = exports.md5 = void 0;
37
+ exports.aesEncryptGCM = aesEncryptGCM;
38
+ exports.aesDecryptGCM = aesDecryptGCM;
39
+ exports.aesEncryptCTR = aesEncryptCTR;
40
+ exports.aesDecryptCTR = aesDecryptCTR;
41
+ exports.aesDecrypt = aesDecrypt;
42
+ exports.aesDecryptWithIV = aesDecryptWithIV;
43
+ exports.aesEncrypt = aesEncrypt;
44
+ exports.aesEncrypWithIV = aesEncrypWithIV;
45
+ exports.hmacSign = hmacSign;
46
+ exports.sha256 = sha256;
47
+ exports.derivePairingCodeKey = derivePairingCodeKey;
48
+ const crypto_1 = require("crypto");
49
+ const curve = __importStar(require("libsignal/src/curve.js"));
50
+ const index_js_1 = require("../Defaults/index.cjs");
51
+ var whatsapp_rust_bridge_1 = require("whatsapp-rust-bridge");
52
+ Object.defineProperty(exports, "md5", { enumerable: true, get: function () { return whatsapp_rust_bridge_1.md5; } });
53
+ Object.defineProperty(exports, "hkdf", { enumerable: true, get: function () { return whatsapp_rust_bridge_1.hkdf; } });
54
+ // insure browser & node compatibility
55
+ // some Node 18 builds don't expose globalThis.crypto by default, so fall back to node:crypto's webcrypto
56
+ const { subtle } = globalThis.crypto ?? crypto_1.webcrypto;
57
+ /** prefix version byte to the pub keys, required for some curve crypto functions */
58
+ const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([index_js_1.KEY_BUNDLE_TYPE, pubKey]);
59
+ exports.generateSignalPubKey = generateSignalPubKey;
60
+ exports.Curve = {
61
+ generateKeyPair: () => {
62
+ const { pubKey, privKey } = curve.generateKeyPair();
63
+ return {
64
+ private: Buffer.from(privKey),
65
+ // remove version byte
66
+ public: Buffer.from(pubKey.slice(1))
67
+ };
68
+ },
69
+ sharedKey: (privateKey, publicKey) => {
70
+ const shared = curve.calculateAgreement((0, exports.generateSignalPubKey)(publicKey), privateKey);
71
+ return Buffer.from(shared);
72
+ },
73
+ sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
74
+ verify: (pubKey, message, signature) => {
75
+ try {
76
+ curve.verifySignature((0, exports.generateSignalPubKey)(pubKey), message, signature);
77
+ return true;
78
+ }
79
+ catch (error) {
80
+ return false;
81
+ }
82
+ }
83
+ };
84
+ const signedKeyPair = (identityKeyPair, keyId) => {
85
+ const preKey = exports.Curve.generateKeyPair();
86
+ const pubKey = (0, exports.generateSignalPubKey)(preKey.public);
87
+ const signature = exports.Curve.sign(identityKeyPair.private, pubKey);
88
+ return { keyPair: preKey, signature, keyId };
89
+ };
90
+ exports.signedKeyPair = signedKeyPair;
91
+ const GCM_TAG_LENGTH = 128 >> 3;
92
+ /**
93
+ * encrypt AES 256 GCM;
94
+ * where the tag tag is suffixed to the ciphertext
95
+ * */
96
+ function aesEncryptGCM(plaintext, key, iv, additionalData) {
97
+ const cipher = (0, crypto_1.createCipheriv)('aes-256-gcm', key, iv);
98
+ cipher.setAAD(additionalData);
99
+ return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
100
+ }
101
+ /**
102
+ * decrypt AES 256 GCM;
103
+ * where the auth tag is suffixed to the ciphertext
104
+ * */
105
+ function aesDecryptGCM(ciphertext, key, iv, additionalData) {
106
+ const decipher = (0, crypto_1.createDecipheriv)('aes-256-gcm', key, iv);
107
+ // decrypt additional adata
108
+ const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
109
+ const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
110
+ // set additional data
111
+ decipher.setAAD(additionalData);
112
+ decipher.setAuthTag(tag);
113
+ return Buffer.concat([decipher.update(enc), decipher.final()]);
114
+ }
115
+ function aesEncryptCTR(plaintext, key, iv) {
116
+ const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
117
+ return Buffer.concat([cipher.update(plaintext), cipher.final()]);
118
+ }
119
+ function aesDecryptCTR(ciphertext, key, iv) {
120
+ const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
121
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
122
+ }
123
+ /** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
124
+ function aesDecrypt(buffer, key) {
125
+ return aesDecryptWithIV(buffer.subarray(16), key, buffer.subarray(0, 16));
126
+ }
127
+ /** decrypt AES 256 CBC */
128
+ function aesDecryptWithIV(buffer, key, IV) {
129
+ const aes = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, IV);
130
+ return Buffer.concat([aes.update(buffer), aes.final()]);
131
+ }
132
+ // encrypt AES 256 CBC; where a random IV is prefixed to the buffer
133
+ function aesEncrypt(buffer, key) {
134
+ const IV = (0, crypto_1.randomBytes)(16);
135
+ const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
136
+ return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
137
+ }
138
+ // encrypt AES 256 CBC with a given IV
139
+ function aesEncrypWithIV(buffer, key, IV) {
140
+ const aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, IV);
141
+ return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
142
+ }
143
+ // sign HMAC using SHA 256
144
+ function hmacSign(buffer, key, variant = 'sha256') {
145
+ return (0, crypto_1.createHmac)(variant, key).update(buffer).digest();
146
+ }
147
+ function sha256(buffer) {
148
+ return (0, crypto_1.createHash)('sha256').update(buffer).digest();
149
+ }
150
+ async function derivePairingCodeKey(pairingCode, salt) {
151
+ // Convert inputs to formats Web Crypto API can work with
152
+ const encoder = new TextEncoder();
153
+ const pairingCodeBuffer = encoder.encode(pairingCode);
154
+ const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
155
+ // Import the pairing code as key material
156
+ const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, [
157
+ 'deriveBits'
158
+ ]);
159
+ // Derive bits using PBKDF2 with the same parameters
160
+ // 2 << 16 = 131,072 iterations
161
+ const derivedBits = await subtle.deriveBits({
162
+ name: 'PBKDF2',
163
+ salt: saltBuffer,
164
+ iterations: 2 << 16,
165
+ hash: 'SHA-256'
166
+ }, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
167
+ );
168
+ return Buffer.from(derivedBits);
169
+ }
170
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decryptMessageNode = exports.extractAddressingContext = exports.SERVER_ERROR_CODES = exports.NACK_REASONS = exports.DECRYPTION_RETRY_CONFIG = exports.ACCOUNT_RESTRICTED_TEXT = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = exports.getDecryptionJid = void 0;
4
+ exports.decodeMessageNode = decodeMessageNode;
5
+ const boom_1 = require("@hapi/boom");
6
+ const index_js_1 = require("../../WAProto/index.cjs");
7
+ const index_js_2 = require("../WABinary/index.cjs");
8
+ const generics_js_1 = require("./generics.cjs");
9
+ const getDecryptionJid = async (sender, repository) => {
10
+ if ((0, index_js_2.isLidUser)(sender) || (0, index_js_2.isHostedLidUser)(sender)) {
11
+ return sender;
12
+ }
13
+ const mapped = await repository.lidMapping.getLIDForPN(sender);
14
+ return mapped || sender;
15
+ };
16
+ exports.getDecryptionJid = getDecryptionJid;
17
+ const storeMappingFromEnvelope = async (stanza, sender, repository, decryptionJid, logger) => {
18
+ // TODO: Handle hosted IDs
19
+ const { senderAlt } = (0, exports.extractAddressingContext)(stanza);
20
+ if (senderAlt && (0, index_js_2.isLidUser)(senderAlt) && (0, index_js_2.isPnUser)(sender) && decryptionJid === sender) {
21
+ try {
22
+ await repository.lidMapping.storeLIDPNMappings([{ lid: senderAlt, pn: sender }]);
23
+ await repository.migrateSession(sender, senderAlt);
24
+ logger.debug({ sender, senderAlt }, 'Stored LID mapping from envelope');
25
+ }
26
+ catch (error) {
27
+ logger.warn({ sender, senderAlt, error }, 'Failed to store LID mapping');
28
+ }
29
+ }
30
+ };
31
+ exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
32
+ exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
33
+ exports.ACCOUNT_RESTRICTED_TEXT = 'Your account has been restricted';
34
+ // Retry configuration for failed decryption
35
+ exports.DECRYPTION_RETRY_CONFIG = {
36
+ maxRetries: 3,
37
+ baseDelayMs: 100,
38
+ sessionRecordErrors: ['No session record', 'SessionError: No session record']
39
+ };
40
+ /** NACK reason codes we send to the server (client → server) */
41
+ exports.NACK_REASONS = {
42
+ SenderReachoutTimelocked: 463,
43
+ ParsingError: 487,
44
+ UnrecognizedStanza: 488,
45
+ UnrecognizedStanzaClass: 489,
46
+ UnrecognizedStanzaType: 490,
47
+ InvalidProtobuf: 491,
48
+ InvalidHostedCompanionStanza: 493,
49
+ MissingMessageSecret: 495,
50
+ SignalErrorOldCounter: 496,
51
+ MessageDeletedOnPeer: 499,
52
+ UnhandledError: 500,
53
+ UnsupportedAdminRevoke: 550,
54
+ UnsupportedLIDGroup: 551,
55
+ DBOperationFailed: 552
56
+ };
57
+ /**
58
+ * Server-side error codes returned in ack stanzas (server → client) that we
59
+ * currently have dedicated handlers for. Extend as more handlers are added.
60
+ * Distinct from the client-side NackReason enum (WAWebCreateNackFromStanza).
61
+ */
62
+ exports.SERVER_ERROR_CODES = {
63
+ /**
64
+ * 1:1 message missing privacy token (tctoken). Usually means the account is
65
+ * restricted: WhatsApp blocks starting new chats but preserves existing ones,
66
+ * since established chats already carry a tctoken.
67
+ */
68
+ MessageAccountRestriction: '463',
69
+ /** Stanza validation failure (SMAX_INVALID) — likely stale device session */
70
+ SmaxInvalid: '479'
71
+ };
72
+ const extractAddressingContext = (stanza) => {
73
+ let senderAlt;
74
+ let recipientAlt;
75
+ const sender = stanza.attrs.participant || stanza.attrs.from;
76
+ const addressingMode = stanza.attrs.addressing_mode || (sender?.endsWith('lid') ? 'lid' : 'pn');
77
+ if (addressingMode === 'lid') {
78
+ // Message is LID-addressed: sender is LID, extract corresponding PN
79
+ // without device data
80
+ senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn;
81
+ recipientAlt = stanza.attrs.recipient_pn;
82
+ // with device data
83
+ //if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt)
84
+ }
85
+ else {
86
+ // Message is PN-addressed: sender is PN, extract corresponding LID
87
+ // without device data
88
+ senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid;
89
+ recipientAlt = stanza.attrs.recipient_lid;
90
+ //with device data
91
+ //if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt)
92
+ }
93
+ return {
94
+ addressingMode,
95
+ senderAlt,
96
+ recipientAlt
97
+ };
98
+ };
99
+ exports.extractAddressingContext = extractAddressingContext;
100
+ /**
101
+ * Decode the received node as a message.
102
+ * @note this will only parse the message, not decrypt it
103
+ */
104
+ function decodeMessageNode(stanza, meId, meLid) {
105
+ let msgType;
106
+ let chatId;
107
+ let author;
108
+ let fromMe = false;
109
+ const msgId = stanza.attrs.id;
110
+ const from = stanza.attrs.from;
111
+ const participant = stanza.attrs.participant;
112
+ const recipient = stanza.attrs.recipient;
113
+ if (!msgId) {
114
+ throw new boom_1.Boom('Invalid message stanza: missing id attribute', { data: stanza });
115
+ }
116
+ if (!from) {
117
+ throw new boom_1.Boom('Invalid message stanza: missing from attribute', { data: stanza });
118
+ }
119
+ const addressingContext = (0, exports.extractAddressingContext)(stanza);
120
+ const isMe = (jid) => (0, index_js_2.areJidsSameUser)(jid, meId);
121
+ const isMeLid = (jid) => (0, index_js_2.areJidsSameUser)(jid, meLid);
122
+ if ((0, index_js_2.isPnUser)(from) || (0, index_js_2.isLidUser)(from) || (0, index_js_2.isHostedLidUser)(from) || (0, index_js_2.isHostedPnUser)(from)) {
123
+ if (recipient && !(0, index_js_2.isJidMetaAI)(recipient)) {
124
+ if (!isMe(from) && !isMeLid(from)) {
125
+ throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
126
+ }
127
+ if (isMe(from) || isMeLid(from)) {
128
+ fromMe = true;
129
+ }
130
+ chatId = recipient;
131
+ }
132
+ else {
133
+ // Peer-routed self stanzas (history sync, app-state sync, etc.) arrive
134
+ // with `from` set to our own device but no `recipient` attribute —
135
+ // still mark as fromMe so self-only protocolMessage handlers run.
136
+ if (isMe(from) || isMeLid(from)) {
137
+ fromMe = true;
138
+ }
139
+ chatId = from;
140
+ }
141
+ msgType = 'chat';
142
+ author = from;
143
+ }
144
+ else if ((0, index_js_2.isJidGroup)(from)) {
145
+ if (!participant) {
146
+ throw new boom_1.Boom('No participant in group message');
147
+ }
148
+ if (isMe(participant) || isMeLid(participant)) {
149
+ fromMe = true;
150
+ }
151
+ msgType = 'group';
152
+ author = participant;
153
+ chatId = from;
154
+ }
155
+ else if ((0, index_js_2.isJidBroadcast)(from)) {
156
+ if (!participant) {
157
+ throw new boom_1.Boom('No participant in group message');
158
+ }
159
+ const isParticipantMe = isMe(participant);
160
+ if ((0, index_js_2.isJidStatusBroadcast)(from)) {
161
+ msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
162
+ }
163
+ else {
164
+ msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
165
+ }
166
+ fromMe = isParticipantMe;
167
+ chatId = from;
168
+ author = participant;
169
+ }
170
+ else if ((0, index_js_2.isJidNewsletter)(from)) {
171
+ msgType = 'newsletter';
172
+ chatId = from;
173
+ author = from;
174
+ if (isMe(from) || isMeLid(from)) {
175
+ fromMe = true;
176
+ }
177
+ }
178
+ else {
179
+ throw new boom_1.Boom('Unknown message type', { data: stanza });
180
+ }
181
+ const pushname = stanza?.attrs?.notify;
182
+ const key = {
183
+ remoteJid: chatId,
184
+ remoteJidAlt: !(0, index_js_2.isJidGroup)(chatId) ? addressingContext.senderAlt : undefined,
185
+ remoteJidUsername: !(0, index_js_2.isJidGroup)(chatId)
186
+ ? stanza.attrs.peer_recipient_username || stanza.attrs.recipient_username
187
+ : undefined,
188
+ fromMe,
189
+ id: msgId,
190
+ participant,
191
+ participantAlt: (0, index_js_2.isJidGroup)(chatId) ? addressingContext.senderAlt : undefined,
192
+ participantUsername: stanza.attrs.participant ? stanza.attrs.participant_username : undefined,
193
+ addressingMode: addressingContext.addressingMode,
194
+ ...(msgType === 'newsletter' && stanza.attrs.server_id ? { server_id: stanza.attrs.server_id } : {})
195
+ };
196
+ const fullMessage = {
197
+ key,
198
+ category: stanza.attrs.category,
199
+ messageTimestamp: +stanza.attrs.t,
200
+ pushName: pushname,
201
+ broadcast: (0, index_js_2.isJidBroadcast)(from)
202
+ };
203
+ if (key.fromMe) {
204
+ fullMessage.status = index_js_1.proto.WebMessageInfo.Status.SERVER_ACK;
205
+ }
206
+ return {
207
+ fullMessage,
208
+ author,
209
+ sender: msgType === 'chat' ? author : chatId
210
+ };
211
+ }
212
+ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
213
+ const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
214
+ return {
215
+ fullMessage,
216
+ category: stanza.attrs.category,
217
+ author,
218
+ async decrypt() {
219
+ let decryptables = 0;
220
+ if (Array.isArray(stanza.content)) {
221
+ for (const { tag, attrs, content } of stanza.content) {
222
+ if (tag === 'verified_name' && content instanceof Uint8Array) {
223
+ const cert = index_js_1.proto.VerifiedNameCertificate.decode(content);
224
+ const details = index_js_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
225
+ fullMessage.verifiedBizName = details.verifiedName;
226
+ }
227
+ if (tag === 'unavailable' && attrs.type === 'view_once') {
228
+ fullMessage.key.isViewOnce = true; // TODO: remove from here and add a STUB TYPE
229
+ }
230
+ if (attrs.count && tag === 'enc') {
231
+ fullMessage.retryCount = Number(attrs.count);
232
+ }
233
+ if (tag !== 'enc' && tag !== 'plaintext') {
234
+ continue;
235
+ }
236
+ if (!(content instanceof Uint8Array)) {
237
+ continue;
238
+ }
239
+ decryptables += 1;
240
+ let msgBuffer;
241
+ const decryptionJid = await (0, exports.getDecryptionJid)(author, repository);
242
+ if (tag !== 'plaintext') {
243
+ // TODO: Handle hosted devices
244
+ await storeMappingFromEnvelope(stanza, author, repository, decryptionJid, logger);
245
+ }
246
+ try {
247
+ const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
248
+ switch (e2eType) {
249
+ case 'skmsg':
250
+ msgBuffer = await repository.decryptGroupMessage({
251
+ group: sender,
252
+ authorJid: author,
253
+ msg: content
254
+ });
255
+ break;
256
+ case 'pkmsg':
257
+ case 'msg':
258
+ msgBuffer = await repository.decryptMessage({
259
+ jid: decryptionJid,
260
+ type: e2eType,
261
+ ciphertext: content
262
+ });
263
+ break;
264
+ case 'plaintext':
265
+ case 'msmsg':
266
+ // 'msmsg' (message-secret message) carries a plain proto.Message
267
+ // envelope (pollUpdateMessage / encEventResponseMessage /
268
+ // secretEncryptedMessage) that is NOT Signal-encrypted at this
269
+ // layer — only specific inner fields are encrypted using a
270
+ // per-message `messageSecret`-derived key, decrypted later in
271
+ // process-message.js once the original message is looked up.
272
+ msgBuffer = content;
273
+ break;
274
+ default:
275
+ throw new Error(`Unknown e2e type: ${e2eType}`);
276
+ }
277
+ const isUnpadded = e2eType === 'plaintext' || e2eType === 'msmsg';
278
+ let msg = index_js_1.proto.Message.decode(isUnpadded ? msgBuffer : (0, generics_js_1.unpadRandomMax16)(msgBuffer));
279
+ msg = msg.deviceSentMessage?.message || msg;
280
+ if (msg.senderKeyDistributionMessage) {
281
+ //eslint-disable-next-line max-depth
282
+ try {
283
+ await repository.processSenderKeyDistributionMessage({
284
+ authorJid: author,
285
+ item: msg.senderKeyDistributionMessage
286
+ });
287
+ }
288
+ catch (err) {
289
+ logger.error({ key: fullMessage.key, err }, 'failed to process sender key distribution message');
290
+ }
291
+ }
292
+ if (fullMessage.message) {
293
+ Object.assign(fullMessage.message, msg);
294
+ }
295
+ else {
296
+ fullMessage.message = msg;
297
+ }
298
+ }
299
+ catch (err) {
300
+ const errorContext = {
301
+ key: fullMessage.key,
302
+ err,
303
+ messageType: tag === 'plaintext' ? 'plaintext' : attrs.type,
304
+ sender,
305
+ author,
306
+ isSessionRecordError: isSessionRecordError(err)
307
+ };
308
+ logger.error(errorContext, 'failed to decrypt message');
309
+ fullMessage.messageStubType = index_js_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
310
+ fullMessage.messageStubParameters = [err.message.toString()];
311
+ }
312
+ }
313
+ }
314
+ // if nothing was found to decrypt
315
+ if (!decryptables && !fullMessage.key?.isViewOnce) {
316
+ fullMessage.messageStubType = index_js_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
317
+ fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT];
318
+ }
319
+ }
320
+ };
321
+ };
322
+ exports.decryptMessageNode = decryptMessageNode;
323
+ /**
324
+ * Utility function to check if an error is related to missing session record
325
+ */
326
+ function isSessionRecordError(error) {
327
+ const errorMessage = error?.message || error?.toString() || '';
328
+ return exports.DECRYPTION_RETRY_CONFIG.sessionRecordErrors.some(errorPattern => errorMessage.includes(errorPattern));
329
+ }
330
+ //# sourceMappingURL=decode-wa-message.js.map