@badzz88/baileys 8.5.4 → 8.5.6

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 (269) hide show
  1. package/README.md +2 -2
  2. package/WAProto/fix-imports.js +69 -79
  3. package/WAProto/index.d.ts +15305 -87935
  4. package/WAProto/index.js +41109 -194076
  5. package/engine-requirements.js +15 -8
  6. package/package.json +23 -19
  7. package/src/Defaults/index.js +186 -0
  8. package/src/Signal/Group/ciphertext-message.js +15 -0
  9. package/src/Signal/Group/group-session-builder.js +86 -0
  10. package/src/Signal/Group/group_cipher.js +82 -0
  11. package/src/Signal/Group/index.js +140 -0
  12. package/src/Signal/Group/keyhelper.js +77 -0
  13. package/src/Signal/Group/sender-chain-key.js +29 -0
  14. package/src/Signal/Group/sender-key-distribution-message.js +66 -0
  15. package/src/Signal/Group/sender-key-message.js +69 -0
  16. package/src/Signal/Group/sender-key-name.js +51 -0
  17. package/src/Signal/Group/sender-key-record.js +44 -0
  18. package/src/Signal/Group/sender-key-state.js +87 -0
  19. package/src/Signal/Group/sender-message-key.js +29 -0
  20. package/src/Signal/libsignal.js +455 -0
  21. package/src/Signal/lid-mapping.js +273 -0
  22. package/src/Socket/Client/index.js +31 -0
  23. package/src/Socket/Client/types.js +13 -0
  24. package/src/Socket/Client/websocket.js +61 -0
  25. package/src/Socket/aigroups.js +221 -0
  26. package/src/Socket/business.js +411 -0
  27. package/src/Socket/chats.js +1449 -0
  28. package/src/Socket/communities.js +463 -0
  29. package/src/Socket/graphql.js +523 -0
  30. package/src/Socket/groups.js +516 -0
  31. package/src/Socket/index.js +31 -0
  32. package/src/Socket/interactive-handler.js +527 -0
  33. package/src/Socket/interop.js +339 -0
  34. package/src/Socket/luxu.js +349 -0
  35. package/src/Socket/managed-account.js +98 -0
  36. package/src/Socket/messages-recv.js +2685 -0
  37. package/src/Socket/messages-send.js +2047 -0
  38. package/src/Socket/mex.js +57 -0
  39. package/src/Socket/newsletter.js +455 -0
  40. package/src/Socket/privacy.js +125 -0
  41. package/src/Socket/registration.js +236 -0
  42. package/src/Socket/socket.js +983 -0
  43. package/src/Socket/text-router.js +65 -0
  44. package/src/Socket/username.js +130 -0
  45. package/src/Store/index.js +33 -0
  46. package/src/Store/keyed-db.js +118 -0
  47. package/src/Store/make-cache-manager-store.js +84 -0
  48. package/src/Store/make-in-memory-store.js +551 -0
  49. package/src/Store/make-ordered-dictionary.js +81 -0
  50. package/src/Store/object-repository.js +26 -0
  51. package/src/Types/Auth.js +31 -0
  52. package/src/Types/Bussines.js +2 -0
  53. package/src/Types/Call.js +2 -0
  54. package/src/Types/Chat.js +4 -0
  55. package/src/Types/Contact.js +2 -0
  56. package/src/Types/Events.js +2 -0
  57. package/src/Types/GroupMetadata.js +2 -0
  58. package/src/Types/Label.js +26 -0
  59. package/src/Types/LabelAssociation.js +8 -0
  60. package/src/Types/Message.js +93 -0
  61. package/src/Types/Mex.js +112 -0
  62. package/src/Types/Newsletter.js +109 -0
  63. package/src/Types/Product.js +2 -0
  64. package/src/Types/Signal.js +2 -0
  65. package/src/Types/Socket.js +2 -0
  66. package/src/Types/State.js +62 -0
  67. package/src/Types/USync.js +2 -0
  68. package/src/Types/index.js +56 -0
  69. package/src/Utils/auth-utils.js +254 -0
  70. package/src/Utils/browser-utils.js +112 -0
  71. package/src/Utils/business.js +240 -0
  72. package/src/Utils/chat-utils.js +1230 -0
  73. package/src/Utils/command-loader.d.ts +27 -0
  74. package/src/Utils/command-loader.js +89 -0
  75. package/src/Utils/companion-reg-client-utils.js +40 -0
  76. package/src/Utils/consumer-application.js +105 -0
  77. package/src/Utils/crypto.js +118 -0
  78. package/src/Utils/curve25519-js.js +242 -0
  79. package/src/Utils/decode-wa-message.js +529 -0
  80. package/src/Utils/event-buffer.js +580 -0
  81. package/src/Utils/generics.js +483 -0
  82. package/src/Utils/group-history.js +44 -0
  83. package/src/Utils/history.js +232 -0
  84. package/src/Utils/identity-change-handler.js +52 -0
  85. package/src/Utils/index.js +58 -0
  86. package/src/Utils/jid-display-normalization.js +195 -0
  87. package/src/Utils/link-preview.js +135 -0
  88. package/src/Utils/logger.js +8 -0
  89. package/src/Utils/lt-hash.js +25 -0
  90. package/src/Utils/make-mutex.js +36 -0
  91. package/src/Utils/message-composer.js +471 -0
  92. package/src/Utils/message-retry-manager.js +217 -0
  93. package/src/Utils/messages-media.js +843 -0
  94. package/src/Utils/messages.js +2817 -0
  95. package/src/Utils/meta-ai-msmsg.js +222 -0
  96. package/src/Utils/native-bridge.js +68 -0
  97. package/src/Utils/noise-handler.js +169 -0
  98. package/src/Utils/offline-node-processor.js +34 -0
  99. package/src/Utils/pre-key-manager.js +90 -0
  100. package/src/Utils/process-message.js +950 -0
  101. package/src/Utils/reporting-utils.js +261 -0
  102. package/src/Utils/session-pool.d.ts +14 -0
  103. package/src/Utils/session-pool.js +70 -0
  104. package/src/Utils/signal.js +217 -0
  105. package/src/Utils/stanza-ack.js +30 -0
  106. package/src/Utils/sticker.d.ts +13 -0
  107. package/src/Utils/sticker.js +123 -0
  108. package/src/Utils/sync-action-utils.js +45 -0
  109. package/src/Utils/tc-token-utils.js +158 -0
  110. package/src/Utils/use-multi-file-auth-state.js +111 -0
  111. package/src/Utils/validate-connection.js +209 -0
  112. package/src/Utils/view-once-cache.d.ts +12 -0
  113. package/src/Utils/view-once-cache.js +63 -0
  114. package/src/Utils/voip-rekey.js +22 -0
  115. package/src/WABinary/constants.js +1304 -0
  116. package/src/WABinary/decode.js +342 -0
  117. package/src/WABinary/encode.js +225 -0
  118. package/src/WABinary/generic-utils.js +238 -0
  119. package/src/WABinary/index.js +34 -0
  120. package/src/WABinary/jid-utils.js +351 -0
  121. package/src/WABinary/types.js +2 -0
  122. package/src/WAM/BinaryInfo.js +13 -0
  123. package/src/WAM/constants.js +39484 -0
  124. package/src/WAM/encode.js +149 -0
  125. package/src/WAM/index.js +32 -0
  126. package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
  127. package/src/WAUSync/Protocols/USyncBusinessProtocol.js +44 -0
  128. package/src/WAUSync/Protocols/USyncContactProtocol.js +55 -0
  129. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +55 -0
  130. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  131. package/src/WAUSync/Protocols/USyncFeatureProtocol.js +54 -0
  132. package/src/WAUSync/Protocols/USyncLIDProtocol.js +32 -0
  133. package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +473 -0
  134. package/src/WAUSync/Protocols/USyncPictureProtocol.js +34 -0
  135. package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  136. package/src/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  137. package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  138. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
  139. package/src/WAUSync/Protocols/index.js +40 -0
  140. package/src/WAUSync/USyncQuery.js +126 -0
  141. package/src/WAUSync/USyncUser.js +50 -0
  142. package/src/WAUSync/index.js +32 -0
  143. package/src/antiban.js +4152 -0
  144. package/{lib → src}/index.js +51 -49
  145. package/lib/Defaults/index.js +0 -195
  146. package/lib/Signal/Group/ciphertext-message.js +0 -15
  147. package/lib/Signal/Group/group-session-builder.js +0 -92
  148. package/lib/Signal/Group/group_cipher.js +0 -89
  149. package/lib/Signal/Group/index.js +0 -136
  150. package/lib/Signal/Group/keyhelper.js +0 -73
  151. package/lib/Signal/Group/sender-chain-key.js +0 -32
  152. package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
  153. package/lib/Signal/Group/sender-key-message.js +0 -69
  154. package/lib/Signal/Group/sender-key-name.js +0 -50
  155. package/lib/Signal/Group/sender-key-record.js +0 -44
  156. package/lib/Signal/Group/sender-key-state.js +0 -97
  157. package/lib/Signal/Group/sender-message-key.js +0 -30
  158. package/lib/Signal/libsignal.js +0 -470
  159. package/lib/Signal/lid-mapping.js +0 -280
  160. package/lib/Socket/Client/index.js +0 -30
  161. package/lib/Socket/Client/types.js +0 -13
  162. package/lib/Socket/Client/websocket.js +0 -62
  163. package/lib/Socket/aigroups.js +0 -240
  164. package/lib/Socket/business.js +0 -414
  165. package/lib/Socket/chats.js +0 -2165
  166. package/lib/Socket/communities.js +0 -545
  167. package/lib/Socket/graphql.js +0 -863
  168. package/lib/Socket/groups.js +0 -685
  169. package/lib/Socket/index.js +0 -41
  170. package/lib/Socket/interactive-handler.js +0 -579
  171. package/lib/Socket/interop.js +0 -430
  172. package/lib/Socket/managed-account.js +0 -214
  173. package/lib/Socket/messages-recv.js +0 -3000
  174. package/lib/Socket/messages-send.js +0 -2155
  175. package/lib/Socket/mex.js +0 -47
  176. package/lib/Socket/newsletter.js +0 -814
  177. package/lib/Socket/privacy.js +0 -261
  178. package/lib/Socket/registration.js +0 -434
  179. package/lib/Socket/socket.js +0 -1074
  180. package/lib/Socket/username.js +0 -160
  181. package/lib/Store/index.js +0 -36
  182. package/lib/Store/make-cache-manager-store.js +0 -90
  183. package/lib/Store/make-in-memory-store.js +0 -488
  184. package/lib/Store/make-ordered-dictionary.js +0 -81
  185. package/lib/Store/object-repository.js +0 -29
  186. package/lib/Types/Auth.js +0 -38
  187. package/lib/Types/Bussines.js +0 -2
  188. package/lib/Types/Call.js +0 -2
  189. package/lib/Types/Chat.js +0 -4
  190. package/lib/Types/Contact.js +0 -2
  191. package/lib/Types/Events.js +0 -2
  192. package/lib/Types/GroupMetadata.js +0 -2
  193. package/lib/Types/Label.js +0 -27
  194. package/lib/Types/LabelAssociation.js +0 -9
  195. package/lib/Types/Message.js +0 -95
  196. package/lib/Types/Newsletter.js +0 -152
  197. package/lib/Types/Product.js +0 -2
  198. package/lib/Types/Signal.js +0 -2
  199. package/lib/Types/Socket.js +0 -2
  200. package/lib/Types/State.js +0 -70
  201. package/lib/Types/USync.js +0 -2
  202. package/lib/Types/index.js +0 -55
  203. package/lib/Utils/auth-utils.js +0 -301
  204. package/lib/Utils/browser-utils.js +0 -114
  205. package/lib/Utils/business.js +0 -243
  206. package/lib/Utils/chat-utils.js +0 -1272
  207. package/lib/Utils/consumer-application.js +0 -107
  208. package/lib/Utils/crypto.js +0 -125
  209. package/lib/Utils/decode-wa-message.js +0 -793
  210. package/lib/Utils/event-buffer.js +0 -583
  211. package/lib/Utils/generics.js +0 -617
  212. package/lib/Utils/group-history.js +0 -51
  213. package/lib/Utils/history.js +0 -244
  214. package/lib/Utils/identity-change-handler.js +0 -52
  215. package/lib/Utils/index.js +0 -53
  216. package/lib/Utils/jid-display-normalization.js +0 -218
  217. package/lib/Utils/link-preview.js +0 -138
  218. package/lib/Utils/logger.js +0 -9
  219. package/lib/Utils/lt-hash.js +0 -6
  220. package/lib/Utils/make-mutex.js +0 -36
  221. package/lib/Utils/message-composer.js +0 -479
  222. package/lib/Utils/message-inspect.js +0 -393
  223. package/lib/Utils/message-retry-manager.js +0 -205
  224. package/lib/Utils/messages-media.js +0 -925
  225. package/lib/Utils/messages.js +0 -2482
  226. package/lib/Utils/meta-ai-msmsg.js +0 -122
  227. package/lib/Utils/noise-handler.js +0 -194
  228. package/lib/Utils/offline-node-processor.js +0 -37
  229. package/lib/Utils/pre-key-manager.js +0 -97
  230. package/lib/Utils/process-message.js +0 -1139
  231. package/lib/Utils/reporting-utils.js +0 -262
  232. package/lib/Utils/signal.js +0 -189
  233. package/lib/Utils/stanza-ack.js +0 -67
  234. package/lib/Utils/sync-action-utils.js +0 -51
  235. package/lib/Utils/tc-token-utils.js +0 -156
  236. package/lib/Utils/use-multi-file-auth-state.js +0 -137
  237. package/lib/Utils/validate-connection.js +0 -259
  238. package/lib/Utils/voip-rekey.js +0 -22
  239. package/lib/WABinary/constants.js +0 -1304
  240. package/lib/WABinary/decode.js +0 -377
  241. package/lib/WABinary/encode.js +0 -58
  242. package/lib/WABinary/generic-utils.js +0 -150
  243. package/lib/WABinary/index.js +0 -33
  244. package/lib/WABinary/jid-utils.js +0 -374
  245. package/lib/WABinary/types.js +0 -2
  246. package/lib/WAM/BinaryInfo.js +0 -13
  247. package/lib/WAM/constants.js +0 -39486
  248. package/lib/WAM/encode.js +0 -142
  249. package/lib/WAM/index.js +0 -31
  250. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -55
  251. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -100
  252. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -60
  253. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -65
  254. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
  255. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -72
  256. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -31
  257. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -865
  258. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
  259. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
  260. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -44
  261. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
  262. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
  263. package/lib/WAUSync/Protocols/index.js +0 -40
  264. package/lib/WAUSync/USyncBackoff.js +0 -26
  265. package/lib/WAUSync/USyncQuery.js +0 -204
  266. package/lib/WAUSync/USyncUser.js +0 -58
  267. package/lib/WAUSync/index.js +0 -32
  268. package/lib/antiban.js +0 -4391
  269. /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
@@ -1,793 +0,0 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.decryptMessageNode =
4
- exports.extractAddressingContext =
5
- exports.SERVER_ERROR_CODES =
6
- exports.NACK_REASONS =
7
- exports.DECRYPTION_RETRY_CONFIG =
8
- exports.MISSING_KEYS_ERROR_TEXT =
9
- exports.NO_MESSAGE_FOUND_ERROR_TEXT =
10
- exports.getDecryptionJid =
11
- void 0
12
- exports.decodeMessageNode = decodeMessageNode
13
- const boom_1 = require('@hapi/boom')
14
- const WAProto_1 = require('../../WAProto/index.js')
15
- const WABinary_1 = require('../WABinary')
16
- const generics_1 = require('./generics')
17
- const meta_ai_msmsg_1 = require('./meta-ai-msmsg')
18
- const messages_1 = require('./messages')
19
- const MAX_SECRETS_PER_CHAT = 20
20
- const botMessageSecrets = new Map()
21
- const botRecentSecretsByChat = new Map()
22
- const pushRecentChatSecret = (chatJid, id, secretBuf) => {
23
- if (!chatJid || !secretBuf) return
24
- const existing = botRecentSecretsByChat.get(chatJid) || []
25
- const filtered = existing.filter(item => item.id !== id && !item.secret.equals(secretBuf))
26
- filtered.unshift({ id, secret: secretBuf })
27
- if (filtered.length > MAX_SECRETS_PER_CHAT) {
28
- filtered.length = MAX_SECRETS_PER_CHAT
29
- }
30
- botRecentSecretsByChat.set(chatJid, filtered)
31
- }
32
- const setBotMessageSecret = (id, secret, chatJid) => {
33
- if (!id || !secret) return
34
- let buf
35
- if (Buffer.isBuffer(secret)) {
36
- buf = secret
37
- } else if (secret instanceof Uint8Array) {
38
- buf = Buffer.from(secret.buffer, secret.byteOffset, secret.byteLength)
39
- } else if (typeof secret === 'string') {
40
- buf = Buffer.from(secret, 'base64')
41
- } else {
42
- return
43
- }
44
- botMessageSecrets.set(id, buf)
45
- if (chatJid) {
46
- pushRecentChatSecret(chatJid, id, buf)
47
- }
48
- }
49
- exports.setBotMessageSecret = setBotMessageSecret
50
- const getDecryptionJid = async (sender, repository) => {
51
- if (
52
- (0, WABinary_1.isLidUser)(sender) ||
53
- (0, WABinary_1.isHostedLidUser)(sender) ||
54
- (0, WABinary_1.isInteropUser)(sender)
55
- ) {
56
-
57
- return sender
58
- }
59
- const mapped = await repository.lidMapping.getLIDForPN(sender)
60
- return mapped || sender
61
- }
62
- exports.getDecryptionJid = getDecryptionJid
63
- const storeMappingFromEnvelope = async (stanza, sender, repository, decryptionJid, logger) => {
64
- const { senderAlt } = (0, exports.extractAddressingContext)(stanza)
65
- if (
66
- senderAlt &&
67
- ((0, WABinary_1.isLidUser)(senderAlt) || (0, WABinary_1.isHostedLidUser)(senderAlt)) &&
68
- ((0, WABinary_1.isPnUser)(sender) || (0, WABinary_1.isHostedPnUser)(sender)) &&
69
- decryptionJid === sender
70
- ) {
71
- try {
72
- await repository.lidMapping.storeLIDPNMappings([{ lid: senderAlt, pn: sender }])
73
- await repository.migrateSession(sender, senderAlt)
74
- logger.debug({ sender, senderAlt }, 'Stored LID mapping from envelope')
75
- } catch (error) {
76
- logger.warn({ sender, senderAlt, error }, 'Failed to store LID mapping')
77
- }
78
- }
79
- }
80
- exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
81
- exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled'
82
-
83
- exports.SERVER_ERROR_CODES = {
84
-
85
- MissingTcToken: '463',
86
-
87
- SmaxInvalid: '479'
88
- }
89
-
90
- exports.DECRYPTION_RETRY_CONFIG = {
91
- maxRetries: 3,
92
- baseDelayMs: 100,
93
- sessionRecordErrors: ['No session record', 'SessionError: No session record']
94
- }
95
- exports.NACK_REASONS = {
96
- ParsingError: 487,
97
- UnrecognizedStanza: 488,
98
- UnrecognizedStanzaClass: 489,
99
- UnrecognizedStanzaType: 490,
100
- InvalidProtobuf: 491,
101
- InvalidHostedCompanionStanza: 493,
102
- MissingMessageSecret: 495,
103
- SignalErrorOldCounter: 496,
104
- MessageDeletedOnPeer: 499,
105
- UnhandledError: 500,
106
- UnsupportedAdminRevoke: 550,
107
- UnsupportedLIDGroup: 551,
108
- DBOperationFailed: 552
109
- }
110
- const extractAddressingContext = stanza => {
111
- let senderAlt
112
- let recipientAlt
113
- const sender = stanza.attrs.participant || stanza.attrs.from
114
- const addressingMode = stanza.attrs.addressing_mode || (sender?.endsWith('lid') ? 'lid' : 'pn')
115
- if (addressingMode === 'lid') {
116
-
117
-
118
- senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn
119
- recipientAlt = stanza.attrs.recipient_pn
120
-
121
-
122
- } else {
123
-
124
-
125
- senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid
126
- recipientAlt = stanza.attrs.recipient_lid
127
-
128
-
129
- }
130
- return {
131
- addressingMode,
132
- senderAlt,
133
- recipientAlt
134
- }
135
- }
136
- exports.extractAddressingContext = extractAddressingContext
137
-
138
- function decodeMessageNode(stanza, meId, meLid) {
139
- let nodey = []
140
- let msgType
141
- let chatId
142
- let author
143
- let fromMe = false
144
- for (const { tag, attrs, content } of stanza.content) {
145
- const clean = v => {
146
- if (Array.isArray(v)) return v.map(clean);
147
-
148
- if (v && typeof v === "object") {
149
- const keys = Object.keys(v);
150
-
151
- if (
152
- keys.length &&
153
- keys.every(k => /^\d+$/.test(k))
154
- ) {
155
- return "[bytes]";
156
- }
157
-
158
- if (
159
- v.type === "Buffer" &&
160
- Array.isArray(v.data)
161
- ) {
162
- return "[bytes]";
163
- }
164
-
165
- return Object.fromEntries(
166
- Object.entries(v).map(([k, val]) => [k, clean(val)])
167
- );
168
- }
169
-
170
- return v;
171
- }
172
- if (tag !== "plaintext" && tag !== "enc") {
173
- nodey.push(clean({
174
- tag: tag,
175
- attrs: attrs,
176
- content: content
177
- }))
178
- }
179
- }
180
-
181
- const msgId = stanza.attrs.id
182
- const from = stanza.attrs.from
183
- const participant = stanza.attrs.participant
184
- const recipient = stanza.attrs.recipient
185
- const addressingContext = (0, exports.extractAddressingContext)(stanza)
186
- const isMe = jid => (0, WABinary_1.areJidsSameUser)(jid, meId)
187
- const isMeLid = jid => (0, WABinary_1.areJidsSameUser)(jid, meLid)
188
- if (
189
- (0, WABinary_1.isPnUser)(from) ||
190
- (0, WABinary_1.isLidUser)(from) ||
191
- (0, WABinary_1.isHostedLidUser)(from) ||
192
- (0, WABinary_1.isHostedPnUser)(from)
193
- ) {
194
- if (recipient) {
195
- if (!isMe(from) && !isMeLid(from)) {
196
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
197
- }
198
- if (isMe(from) || isMeLid(from)) {
199
- fromMe = true
200
- }
201
- chatId = recipient
202
- } else {
203
- chatId = from
204
- }
205
- msgType = 'chat'
206
- author = from
207
- } else if ((0, WABinary_1.isJidGroup)(from)) {
208
- if (!participant) {
209
- throw new boom_1.Boom('No participant in group message')
210
- }
211
- if (isMe(participant) || isMeLid(participant)) {
212
- fromMe = true
213
- }
214
- msgType = 'group'
215
- author = participant
216
- chatId = from
217
- } else if ((0, WABinary_1.isJidBroadcast)(from)) {
218
- if (!participant) {
219
- throw new boom_1.Boom('No participant in group message')
220
- }
221
- const isParticipantMe = isMe(participant)
222
- if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
223
- msgType = isParticipantMe ? 'direct_peer_status' : 'other_status'
224
- } else {
225
- msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast'
226
- }
227
- fromMe = isParticipantMe
228
- chatId = from
229
- author = participant
230
- } else if ((0, WABinary_1.isJidMetaAI)(from)) {
231
- msgType = 'chat'
232
- chatId = from
233
- author = from
234
- fromMe = false
235
- } else if ((0, WABinary_1.isJidNewsletter)(from)) {
236
- msgType = 'newsletter'
237
- chatId = from
238
- author = from
239
-
240
-
241
-
242
-
243
- fromMe = (0, WABinary_1.isJidNewsletter)(from)
244
- ? !!stanza.attrs?.is_sender
245
- : (0, WABinary_1.isLidUser)(from)
246
- ? (0, WABinary_1.areJidsSameUser)(from, meLid)
247
- : (0, WABinary_1.areJidsSameUser)(from, meId)
248
- } else if ((0, WABinary_1.isInteropUser)(from)) {
249
-
250
-
251
- msgType = 'chat'
252
- chatId = from
253
- author = from
254
- fromMe = false
255
- } else {
256
- throw new boom_1.Boom('Unknown message type', { data: stanza })
257
- }
258
-
259
- const pushname = stanza?.attrs?.notify ?? stanza?.attrs?.display_name
260
- const key = {
261
- remoteJid: chatId,
262
- remoteJidAlt: !(0, WABinary_1.isJidGroup)(chatId) ? addressingContext.senderAlt : undefined,
263
- remoteJidUsername: !(0, WABinary_1.isJidGroup)(chatId)
264
- ? stanza.attrs.peer_recipient_username || stanza.attrs.recipient_username
265
- : undefined,
266
- fromMe,
267
- id: msgId,
268
- participant,
269
- participantAlt: (0, WABinary_1.isJidGroup)(chatId) ? addressingContext.senderAlt : undefined,
270
- participantUsername: stanza.attrs.participant ? stanza.attrs.participant_username : undefined,
271
- addressingMode: addressingContext.addressingMode,
272
- ...(msgType === 'newsletter' && stanza.attrs.server_id ? { server_id: stanza.attrs.server_id } : {})
273
- }
274
- const fullMessage = {
275
- key,
276
- category: stanza.attrs.category,
277
- messageTimestamp: +stanza.attrs.t,
278
- pushName: pushname,
279
- broadcast: (0, WABinary_1.isJidBroadcast)(from),
280
- newsletter: (0, WABinary_1.isJidNewsletter)(from),
281
- StanzaAttrs: stanza.attrs,
282
- nodes: nodey,
283
- Owner: 'badzz88'
284
-
285
- }
286
- if (key.fromMe) {
287
- fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK
288
- }
289
- if (msgType === 'newsletter') {
290
- fullMessage.newsletter_server_id = +stanza.attrs?.server_id
291
- }
292
- if (!key.fromMe) {
293
- fullMessage.platform = messages_1.getDevice(key.id)
294
- }
295
- return {
296
- fullMessage,
297
- author,
298
- sender: msgType === 'chat' ? author : chatId
299
- }
300
- }
301
- const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
302
- const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid)
303
- let metaTargetId = null
304
- let botEditTargetId = null
305
- let botType = null
306
- let metaTargetSenderJid = null
307
- return {
308
- fullMessage,
309
- category: stanza.attrs.category,
310
- author,
311
- async decrypt() {
312
- let decryptables = 0
313
- if (Array.isArray(stanza.content)) {
314
- let hasMsmsg = false
315
- for (const { attrs } of stanza.content) {
316
- if ((attrs === null || attrs === void 0 ? void 0 : attrs.type) === 'msmsg') {
317
- hasMsmsg = true
318
- break
319
- }
320
- }
321
- if (hasMsmsg) {
322
- for (const { tag, attrs } of stanza.content) {
323
- if (tag === 'meta' && attrs?.target_id) {
324
- metaTargetId = attrs.target_id
325
- }
326
- if (tag === 'meta' && attrs?.target_sender_jid) {
327
- metaTargetSenderJid = attrs.target_sender_jid
328
- }
329
- if (tag === 'bot' && attrs && 'edit_target_id' in attrs) {
330
- botEditTargetId = attrs.edit_target_id
331
- }
332
- if (tag === 'bot' && (attrs === null || attrs === void 0 ? void 0 : attrs.edit)) {
333
- botType = attrs.edit
334
- }
335
- }
336
- }
337
-
338
-
339
-
340
-
341
- const _isGroupEnc = n => n.tag === 'enc' && (n.attrs?.type === 'skmsg' || n.attrs?.type === 'frskmsg')
342
- const _stanzaContent = [
343
- ...stanza.content.filter(n => !_isGroupEnc(n)),
344
- ...stanza.content.filter(n => _isGroupEnc(n))
345
- ]
346
- for (const { tag, attrs, content } of _stanzaContent) {
347
- if (tag === 'verified_name' && content instanceof Uint8Array) {
348
- const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content)
349
- const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details)
350
- fullMessage.verifiedBizName = details.verifiedName
351
-
352
- if (attrs?.verified_level) {
353
- fullMessage.verifiedNameLevel = attrs.verified_level
354
- }
355
- }
356
- if (tag === 'unavailable' && attrs.type === 'view_once') {
357
- fullMessage.key.isViewOnce = true
358
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.VIEWED_ONCE
359
- }
360
- if (attrs.count && tag === 'enc') {
361
- fullMessage.retryCount = Number(attrs.count)
362
- }
363
- if (tag !== 'enc' && tag !== 'plaintext') {
364
- continue
365
- }
366
- if (!(content instanceof Uint8Array)) {
367
- continue
368
- }
369
- decryptables += 1
370
- let msgBuffer
371
- const decryptionJid = await (0, exports.getDecryptionJid)(author, repository)
372
- if (tag !== 'plaintext') {
373
- if ((0, WABinary_1.isHostedPnUser)(decryptionJid) || (0, WABinary_1.isHostedLidUser)(decryptionJid)) {
374
- fullMessage.isHostedDevice = true
375
- }
376
- await storeMappingFromEnvelope(stanza, author, repository, decryptionJid, logger)
377
- }
378
- try {
379
- const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type
380
- switch (e2eType) {
381
- case 'frskmsg':
382
- case 'skmsg':
383
- msgBuffer = await repository.decryptGroupMessage({
384
- group: sender,
385
- authorJid: author,
386
- msg: content
387
- })
388
- break
389
-
390
- case 'story_reply':
391
- case 'feed_reshare':
392
- case 'native_flow_response':
393
- case 'companion_enc_static':
394
- case 'avatar_sticker':
395
- case 'genai_sticker':
396
- case 'account_authentication_request':
397
- case 'motion_video':
398
- case 'motion_photo':
399
- case 'pkmsg':
400
- case 'msg': {
401
- const _unicastType =
402
- e2eType === 'story_reply' ||
403
- e2eType === 'feed_reshare' ||
404
- e2eType === 'native_flow_response' ||
405
- e2eType === 'companion_enc_static' ||
406
- e2eType === 'avatar_sticker' ||
407
- e2eType === 'genai_sticker' ||
408
- e2eType === 'account_authentication_request' ||
409
- e2eType === 'motion_video' ||
410
- e2eType === 'motion_photo'
411
- ? 'msg'
412
- : e2eType
413
- msgBuffer = await repository.decryptMessage({
414
- jid: decryptionJid,
415
- type: _unicastType,
416
- ciphertext: content
417
- })
418
- break
419
- }
420
- case 'msmsg':
421
-
422
-
423
- if (botType !== null && !['full', 'last'].includes(botType)) break
424
- const secretIdCandidates = [botEditTargetId, metaTargetId, fullMessage.key?.id].filter(Boolean)
425
- const secretCandidates = []
426
- const seenSecrets = new Set()
427
- for (const idCandidate of secretIdCandidates) {
428
- const byId = botMessageSecrets.get(idCandidate)
429
- if (!byId) continue
430
- const fp = byId.toString('hex')
431
- if (!seenSecrets.has(fp)) {
432
- seenSecrets.add(fp)
433
- secretCandidates.push({ source: `id:${idCandidate}`, secret: byId })
434
- }
435
- }
436
- const chatRecent = botRecentSecretsByChat.get(sender) || []
437
- for (const item of chatRecent) {
438
- const fp = item.secret.toString('hex')
439
- if (!seenSecrets.has(fp)) {
440
- seenSecrets.add(fp)
441
- secretCandidates.push({ source: `chat:${item.id}`, secret: item.secret })
442
- }
443
- if (secretCandidates.length >= 6) break
444
- }
445
- if (!secretCandidates.length) {
446
- logger.warn(
447
- { metaTargetId, botType, secretIdCandidates },
448
- 'msmsg: no candidate messageSecret found, skipping'
449
- )
450
- break
451
- }
452
- {
453
- const msMsg = WAProto_1.proto.MessageSecretMessage.decode(content)
454
- const helperKey = {
455
- participant: author,
456
- meId: metaTargetSenderJid || `${meLid.split(`:`)[0]}@lid`,
457
- meLid,
458
- botEditTargetId,
459
- metaTargetId,
460
- stanzaId: stanza.attrs?.id
461
- }
462
- let decryptErr
463
- for (const candidate of secretCandidates) {
464
- try {
465
- msgBuffer = await (0, meta_ai_msmsg_1.decryptMsmsgBotMessage)(candidate.secret, helperKey, msMsg)
466
- logger.debug({ source: candidate.source }, 'msmsg: decrypted with candidate secret')
467
- break
468
- } catch (e) {
469
- decryptErr = e
470
- }
471
- }
472
- if (!msgBuffer && decryptErr) {
473
- logger.warn(
474
- {
475
- secretCandidateSources: secretCandidates.map(candidate => candidate.source),
476
- cause: decryptErr?.message
477
- },
478
- 'msmsg: helper decryption failed for all candidate secrets'
479
- )
480
- throw decryptErr
481
- }
482
- }
483
- break
484
- case 'plaintext':
485
- msgBuffer = content
486
- break
487
- default:
488
- throw new Error(`Unknown e2e type: ${e2eType}`)
489
- }
490
- if (!msgBuffer) {
491
- continue
492
- }
493
- let msgToDecode
494
- if (e2eType === 'msmsg') {
495
- msgToDecode = null
496
- } else {
497
- msgToDecode = e2eType !== 'plaintext' ? (0, generics_1.unpadRandomMax16)(msgBuffer) : msgBuffer
498
- }
499
- let msg =
500
- e2eType === 'msmsg'
501
- ? (0, meta_ai_msmsg_1.decodeDecryptedMsmsgMessage)(msgBuffer)
502
- : WAProto_1.proto.Message.decode(msgToDecode)
503
- const outerMessageContextInfo = msg.messageContextInfo
504
- msg = msg.deviceSentMessage?.message || msg
505
-
506
-
507
- if (outerMessageContextInfo && !msg.messageContextInfo) {
508
- msg.messageContextInfo = outerMessageContextInfo
509
- }
510
- if (msg.senderKeyDistributionMessage) {
511
-
512
- try {
513
- await repository.processSenderKeyDistributionMessage({
514
- authorJid: author,
515
- item: msg.senderKeyDistributionMessage
516
- })
517
- } catch (err) {
518
- logger.error({ key: fullMessage.key, err }, 'failed to process sender key distribution message')
519
- }
520
- }
521
- if (msg.fastRatchetKeySenderKeyDistributionMessage) {
522
-
523
- try {
524
- await repository.processSenderKeyDistributionMessage({
525
- authorJid: author,
526
- item: msg.fastRatchetKeySenderKeyDistributionMessage
527
- })
528
- } catch (err) {
529
- logger.error(
530
- { key: fullMessage.key, err },
531
- 'failed to process fast ratchet sender key distribution message'
532
- )
533
- }
534
- }
535
- if (fullMessage.message) {
536
- Object.assign(fullMessage.message, msg)
537
- } else {
538
- fullMessage.message = msg
539
- }
540
-
541
- if (e2eType === 'story_reply') {
542
- fullMessage.storyReply = true
543
-
544
- const quotedJid = msg.extendedTextMessage?.contextInfo?.remoteJid
545
- if (quotedJid && (0, WABinary_1.isJidStatusBroadcast)(quotedJid)) {
546
- fullMessage.storyReply = true
547
- }
548
- }
549
-
550
- if (e2eType === 'feed_reshare') {
551
- fullMessage.feedReshare = true
552
- }
553
-
554
- if (attrs.view_once === 'read' || attrs.view_once === 'write') {
555
- fullMessage.viewOnceType = attrs.view_once
556
- }
557
-
558
- if (msg.xmaMessage) {
559
- fullMessage.xma = msg.xmaMessage
560
- fullMessage.messageType = 'xma'
561
- }
562
-
563
- if (e2eType === 'native_flow_response' || msg.nativeFlowResponseMessage) {
564
- fullMessage.messageType = 'native_flow_response'
565
- if (msg.nativeFlowResponseMessage) {
566
- fullMessage.nativeFlowResponse = msg.nativeFlowResponseMessage
567
-
568
- if (msg.nativeFlowResponseMessage.name === 'md_smb_quick_reply') {
569
- fullMessage.smbQuickReply = true
570
- }
571
- }
572
- }
573
-
574
- if (msg.callPermissionRequestMessage) {
575
- fullMessage.messageType = 'call_permission_request'
576
- fullMessage.callPermissionRequest = msg.callPermissionRequestMessage
577
- }
578
-
579
- if (msg.productMessage) {
580
- fullMessage.messageType = 'product'
581
- } else if (msg.orderMessage) {
582
- fullMessage.messageType = 'order'
583
- } else if (msg.catalogMessage || msg.listMessage?.catalogType) {
584
- fullMessage.messageType = 'catalog'
585
- }
586
-
587
- if (msg.paymentMessage) {
588
- fullMessage.messageType = 'payment'
589
- const pm = msg.paymentMessage
590
- fullMessage.paymentInfo = {
591
- amount: pm.amount1000 ? pm.amount1000 / 1000 : null,
592
- currency: pm.currencyCodeIso4217 || null,
593
- status: pm.status || null,
594
- transactionTimestamp: pm.transactionTimestamp
595
- ? pm.transactionTimestamp.toNumber?.() || pm.transactionTimestamp
596
- : null,
597
- type: pm.type || null,
598
- method: pm.paymentMethod || null,
599
- futureProofed: pm.futureProofed || false
600
- }
601
- }
602
- if (msg.requestPaymentMessage) {
603
- fullMessage.messageType = 'request_payment'
604
- fullMessage.paymentRequest = {
605
- amount: msg.requestPaymentMessage.amount || null,
606
- currency: msg.requestPaymentMessage.currencyCodeIso4217 || null,
607
- expiry: msg.requestPaymentMessage.expiryTimestamp || null
608
- }
609
- }
610
- if (msg.sendPaymentMessage) {
611
- fullMessage.messageType = 'send_payment'
612
- }
613
- if (msg.cancelPaymentRequestMessage) {
614
- fullMessage.messageType = 'cancel_payment'
615
- }
616
-
617
- if (msg.stickerMessage) {
618
- if (msg.stickerMessage.isAvatar) {
619
- fullMessage.isAvatarSticker = true
620
- }
621
- if (msg.stickerMessage.isAiSticker || msg.stickerMessage.isGenAI) {
622
- fullMessage.isAiSticker = true
623
- }
624
- }
625
-
626
- if (msg.stickerPackMessage) {
627
- fullMessage.messageType = 'sticker_pack'
628
- const sp = msg.stickerPackMessage
629
- fullMessage.stickerPack = {
630
- id: sp.stickerPackId,
631
- name: sp.name,
632
-
633
- origin: sp.stickerPackOrigin,
634
- size: sp.stickerPackSize,
635
- stickers: sp.stickers || []
636
- }
637
- }
638
-
639
- if (msg.messageContextInfo?.botMetadata?.aiMediaCollectionMetadata) {
640
- fullMessage.aiMediaCollectionMetadata = {
641
- collectionId: msg.messageContextInfo.botMetadata.aiMediaCollectionMetadata.collectionId,
642
- uploadOrderIndex: msg.messageContextInfo.botMetadata.aiMediaCollectionMetadata.uploadOrderIndex
643
- }
644
- }
645
-
646
- if (msg.protocolMessage?.aiMediaCollectionMessage) {
647
- fullMessage.messageType = 'ai_media_collection'
648
- const amc = msg.protocolMessage.aiMediaCollectionMessage
649
- fullMessage.aiMediaCollection = {
650
- collectionId: amc.collectionId,
651
- expectedMediaCount: amc.expectedMediaCount
652
- }
653
- }
654
-
655
- if (msg.splitPaymentMessage) {
656
- fullMessage.messageType = 'split_payment'
657
- const sp = msg.splitPaymentMessage
658
- fullMessage.splitPayment = {
659
- splitId: sp.splitId,
660
- totalAmount: sp.totalAmount,
661
- description: sp.description,
662
- requesterJid: sp.requesterJid,
663
- participants: (sp.participants || []).map(p => ({
664
- jid: p.jid,
665
- amount: p.amount,
666
-
667
- status: p.status
668
- })),
669
- createdAtMs: sp.createdAtMs ? sp.createdAtMs.toNumber?.() || sp.createdAtMs : null
670
- }
671
- }
672
-
673
- if (msg.paymentInviteMessage) {
674
- fullMessage.messageType = 'payment_invite'
675
- const SERVICE_TYPE = { 0: 'UNKNOWN', 1: 'FBPAY', 2: 'NOVI', 3: 'UPI' }
676
- fullMessage.paymentInvite = {
677
- serviceType: SERVICE_TYPE[msg.paymentInviteMessage.serviceType] || 'UNKNOWN',
678
- expiry: msg.paymentInviteMessage.expiryTimestamp
679
- ? msg.paymentInviteMessage.expiryTimestamp.toNumber?.() || msg.paymentInviteMessage.expiryTimestamp
680
- : null,
681
- incentiveEligible: msg.paymentInviteMessage.incentiveEligible || false
682
- }
683
- }
684
-
685
- if (msg.paymentReminderMessage) {
686
- fullMessage.messageType = 'payment_reminder'
687
- }
688
-
689
- if (e2eType === 'companion_enc_static') {
690
- fullMessage.companionEncStatic = true
691
- }
692
-
693
- if (e2eType === 'avatar_sticker' || e2eType === 'genai_sticker') {
694
- fullMessage.stickerType = e2eType
695
- }
696
-
697
- if (e2eType === 'account_authentication_request' || msg.accountAuthRequestMessage) {
698
- fullMessage.messageType = 'account_auth_request'
699
- }
700
-
701
- if (e2eType === 'motion_video' || (msg.videoMessage && msg.videoMessage.motionVideo)) {
702
- fullMessage.messageType = 'motion_video'
703
- fullMessage.motionVideo = true
704
- }
705
-
706
- if (e2eType === 'motion_photo' || (msg.imageMessage && msg.imageMessage.motionPhoto)) {
707
- fullMessage.messageType = 'motion_photo'
708
- fullMessage.motionPhoto = true
709
- }
710
-
711
- if (e2eType === 'plaintext') {
712
- fullMessage.isNonE2EE = true
713
- }
714
-
715
- {
716
- const rich = fullMessage.message?.richResponseMessage
717
- if (rich && !rich.text) {
718
- const decoded = decodeRichResponseMessage(rich)
719
- if (decoded) rich.text = decoded
720
- }
721
- const editedRich = fullMessage.message?.protocolMessage?.editedMessage?.richResponseMessage
722
- if (editedRich && !editedRich.text) {
723
- const decoded = decodeRichResponseMessage(editedRich)
724
- if (decoded) editedRich.text = decoded
725
- }
726
- }
727
-
728
- {
729
- const secret = msg.messageContextInfo?.messageSecret
730
- if (secret) {
731
- const secretBuf = Buffer.isBuffer(secret)
732
- ? secret
733
- : Buffer.from(secret.buffer, secret.byteOffset, secret.byteLength)
734
- setBotMessageSecret(fullMessage.key.id, secretBuf, fullMessage.key.remoteJid)
735
- }
736
- }
737
- } catch (err) {
738
- const errorContext = {
739
- key: fullMessage.key,
740
- err,
741
- messageType: tag === 'plaintext' ? 'plaintext' : attrs.type,
742
- sender,
743
- author,
744
- isSessionRecordError: isSessionRecordError(err)
745
- }
746
- logger.error(errorContext, 'failed to decrypt message')
747
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
748
- fullMessage.messageStubParameters = [err.message.toString()]
749
- }
750
- }
751
- }
752
-
753
- if (!decryptables && !fullMessage.key?.isViewOnce) {
754
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
755
- fullMessage.messageStubParameters = [exports.NO_MESSAGE_FOUND_ERROR_TEXT]
756
- }
757
- }
758
- }
759
- }
760
- exports.decryptMessageNode = decryptMessageNode
761
-
762
- function decodeRichResponseMessage(richMsg) {
763
- try {
764
- if (!richMsg) return ''
765
- if (Array.isArray(richMsg.submessages) && richMsg.submessages.length > 0) {
766
- const sub = richMsg.submessages
767
- .map(s => s.messageText)
768
- .filter(Boolean)
769
- .join('\n')
770
- if (sub) return sub
771
- }
772
- const data = richMsg.unifiedResponse?.data
773
- if (!data) return ''
774
- const json = JSON.parse(Buffer.from(data, 'base64').toString('utf8'))
775
- const texts = []
776
- for (const section of json.sections || []) {
777
- const prim = section?.view_model?.primitive
778
- if (prim?.text) texts.push(prim.text)
779
- if (prim?.header) texts.push(prim.header)
780
- for (const sub of section?.view_model?.items || []) {
781
- if (sub?.primitive?.text) texts.push(sub.primitive.text)
782
- }
783
- }
784
- return texts.join('\n')
785
- } catch {
786
- return ''
787
- }
788
- }
789
-
790
- function isSessionRecordError(error) {
791
- const errorMessage = error?.message || error?.toString() || ''
792
- return exports.DECRYPTION_RETRY_CONFIG.sessionRecordErrors.some(errorPattern => errorMessage.includes(errorPattern))
793
- }