@vinzsocket/baileys 2.8.9 → 2.8.20

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 (83) hide show
  1. package/lib/Defaults/index.js +75 -73
  2. package/lib/Signal/Group/ciphertext-message.js +9 -9
  3. package/lib/Signal/Group/group-session-builder.js +21 -21
  4. package/lib/Signal/Group/group_cipher.js +79 -81
  5. package/lib/Signal/Group/index.js +2 -2
  6. package/lib/Signal/Group/keyhelper.js +9 -9
  7. package/lib/Signal/Group/queue-job.js +43 -46
  8. package/lib/Signal/Group/sender-chain-key.js +24 -25
  9. package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
  10. package/lib/Signal/Group/sender-key-message.js +55 -60
  11. package/lib/Signal/Group/sender-key-name.js +38 -39
  12. package/lib/Signal/Group/sender-key-record.js +39 -41
  13. package/lib/Signal/Group/sender-key-state.js +85 -89
  14. package/lib/Signal/Group/sender-message-key.js +22 -22
  15. package/lib/Signal/libsignal.js +387 -292
  16. package/lib/Signal/lid-mapping.js +98 -93
  17. package/lib/Socket/Client/types.js +6 -6
  18. package/lib/Socket/Client/websocket.js +44 -44
  19. package/lib/Socket/business.js +350 -365
  20. package/lib/Socket/chats.js +1019 -914
  21. package/lib/Socket/communities.js +454 -376
  22. package/lib/Socket/groups.js +378 -310
  23. package/lib/Socket/index.js +11 -11
  24. package/lib/Socket/messages-recv.js +1355 -1182
  25. package/lib/Socket/messages-send.js +1224 -1081
  26. package/lib/Socket/mex.js +40 -34
  27. package/lib/Socket/newsletter.js +212 -169
  28. package/lib/Socket/socket.js +896 -757
  29. package/lib/Store/index.js +1 -1
  30. package/lib/Store/make-cache-manager-store.js +75 -79
  31. package/lib/Store/make-in-memory-store.js +450 -389
  32. package/lib/Store/make-ordered-dictionary.js +73 -76
  33. package/lib/Store/object-repository.js +24 -22
  34. package/lib/Types/Chat.js +1 -7
  35. package/lib/Types/Label.js +20 -20
  36. package/lib/Types/LabelAssociation.js +2 -2
  37. package/lib/Types/Message.js +2 -2
  38. package/lib/Types/Newsletter.js +24 -24
  39. package/lib/Types/Socket.js +1 -1
  40. package/lib/Types/State.js +8 -8
  41. package/lib/Types/index.js +10 -10
  42. package/lib/Utils/auth-utils.js +408 -401
  43. package/lib/Utils/baileys-event-stream.js +44 -35
  44. package/lib/Utils/business.js +200 -197
  45. package/lib/Utils/chat-utils.js +775 -708
  46. package/lib/Utils/crypto.js +97 -85
  47. package/lib/Utils/decode-wa-message.js +240 -227
  48. package/lib/Utils/event-buffer.js +547 -518
  49. package/lib/Utils/extended-messages.js +250 -203
  50. package/lib/Utils/generics.js +300 -289
  51. package/lib/Utils/history.js +76 -69
  52. package/lib/Utils/lid-resolver.js +47 -42
  53. package/lib/Utils/link-preview.js +75 -65
  54. package/lib/Utils/logger.js +3 -1
  55. package/lib/Utils/lt-hash.js +38 -34
  56. package/lib/Utils/make-mutex.js +32 -34
  57. package/lib/Utils/mention.js +79 -86
  58. package/lib/Utils/message-retry-manager.js +148 -136
  59. package/lib/Utils/messages-media.js +652 -562
  60. package/lib/Utils/messages.js +753 -707
  61. package/lib/Utils/noise-handler.js +156 -135
  62. package/lib/Utils/process-message.js +404 -341
  63. package/lib/Utils/signal.js +180 -118
  64. package/lib/Utils/use-multi-file-auth-state.js +87 -91
  65. package/lib/Utils/validate-connection.js +167 -142
  66. package/lib/WABinary/constants.js +28 -1293
  67. package/lib/WABinary/decode.js +220 -218
  68. package/lib/WABinary/encode.js +199 -201
  69. package/lib/WABinary/generic-utils.js +80 -77
  70. package/lib/WABinary/jid-utils.js +41 -35
  71. package/lib/WAM/BinaryInfo.js +7 -7
  72. package/lib/WAM/constants.js +1 -15241
  73. package/lib/WAM/encode.js +124 -131
  74. package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
  75. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
  76. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
  77. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
  78. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
  79. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
  80. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
  81. package/lib/WAUSync/USyncQuery.js +82 -84
  82. package/lib/WAUSync/USyncUser.js +20 -20
  83. package/package.json +4 -1
@@ -3,263 +3,276 @@ import { proto } from '../../WAProto/index.js';
3
3
  import { areJidsSameUser, isJidBroadcast, isJidGroup, isJidMetaAI, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser, transferDevice } from '../WABinary/index.js';
4
4
  import { unpadRandomMax16 } from './generics.js';
5
5
  const getDecryptionJid = async (sender, repository) => {
6
- if (!sender.includes('@s.whatsapp.net')) {
7
- return sender;
8
- }
9
- return (await repository.getLIDMappingStore().getLIDForPN(sender));
6
+ if (!sender.includes('@s.whatsapp.net')) {
7
+ return sender;
8
+ }
9
+ return await repository.getLIDMappingStore().getLIDForPN(sender);
10
10
  };
11
11
  const storeMappingFromEnvelope = async (stanza, sender, decryptionJid, repository, logger) => {
12
- const { senderAlt } = extractAddressingContext(stanza);
13
- if (senderAlt && isLidUser(senderAlt) && isPnUser(sender) && decryptionJid === sender) {
14
- try {
15
- await repository.storeLIDPNMapping(senderAlt, sender);
16
- logger.debug({ sender, senderAlt }, 'Stored LID mapping from envelope');
17
- }
18
- catch (error) {
19
- logger.warn({ sender, senderAlt, error }, 'Failed to store LID mapping');
20
- }
12
+ const {
13
+ senderAlt
14
+ } = extractAddressingContext(stanza);
15
+ if (senderAlt && isLidUser(senderAlt) && isPnUser(sender) && decryptionJid === sender) {
16
+ try {
17
+ await repository.storeLIDPNMapping(senderAlt, sender);
18
+ logger.debug({
19
+ sender,
20
+ senderAlt
21
+ }, 'Stored LID mapping from envelope');
22
+ } catch (error) {
23
+ logger.warn({
24
+ sender,
25
+ senderAlt,
26
+ error
27
+ }, 'Failed to store LID mapping');
21
28
  }
29
+ }
22
30
  };
23
31
  export const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
24
32
  export const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
25
33
  // Retry configuration for failed decryption
26
34
  export const DECRYPTION_RETRY_CONFIG = {
27
- maxRetries: 3,
28
- baseDelayMs: 100,
29
- sessionRecordErrors: ['No session record', 'SessionError: No session record']
35
+ maxRetries: 3,
36
+ baseDelayMs: 100,
37
+ sessionRecordErrors: ['No session record', 'SessionError: No session record']
30
38
  };
31
39
  export const NACK_REASONS = {
32
- ParsingError: 487,
33
- UnrecognizedStanza: 488,
34
- UnrecognizedStanzaClass: 489,
35
- UnrecognizedStanzaType: 490,
36
- InvalidProtobuf: 491,
37
- InvalidHostedCompanionStanza: 493,
38
- MissingMessageSecret: 495,
39
- SignalErrorOldCounter: 496,
40
- MessageDeletedOnPeer: 499,
41
- UnhandledError: 500,
42
- UnsupportedAdminRevoke: 550,
43
- UnsupportedLIDGroup: 551,
44
- DBOperationFailed: 552
40
+ ParsingError: 487,
41
+ UnrecognizedStanza: 488,
42
+ UnrecognizedStanzaClass: 489,
43
+ UnrecognizedStanzaType: 490,
44
+ InvalidProtobuf: 491,
45
+ InvalidHostedCompanionStanza: 493,
46
+ MissingMessageSecret: 495,
47
+ SignalErrorOldCounter: 496,
48
+ MessageDeletedOnPeer: 499,
49
+ UnhandledError: 500,
50
+ UnsupportedAdminRevoke: 550,
51
+ UnsupportedLIDGroup: 551,
52
+ DBOperationFailed: 552
45
53
  };
46
- export const extractAddressingContext = (stanza) => {
47
- const addressingMode = stanza.attrs.addressing_mode || 'pn';
48
- let senderAlt;
49
- let recipientAlt;
50
- const sender = stanza.attrs.participant || stanza.attrs.from;
51
- if (addressingMode === 'lid') {
52
- // Message is LID-addressed: sender is LID, extract corresponding PN
53
- // without device data
54
- senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn;
55
- recipientAlt = stanza.attrs.recipient_pn;
56
- // with device data
57
- if (sender && senderAlt)
58
- senderAlt = transferDevice(sender, senderAlt);
59
- }
60
- else {
61
- // Message is PN-addressed: sender is PN, extract corresponding LID
62
- // without device data
63
- senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid;
64
- recipientAlt = stanza.attrs.recipient_lid;
65
- //with device data
66
- if (sender && senderAlt)
67
- senderAlt = transferDevice(sender, senderAlt);
68
- }
69
- return {
70
- addressingMode,
71
- senderAlt,
72
- recipientAlt
73
- };
54
+ export const extractAddressingContext = stanza => {
55
+ const addressingMode = stanza.attrs.addressing_mode || 'pn';
56
+ let senderAlt;
57
+ let recipientAlt;
58
+ const sender = stanza.attrs.participant || stanza.attrs.from;
59
+ if (addressingMode === 'lid') {
60
+ // Message is LID-addressed: sender is LID, extract corresponding PN
61
+ // without device data
62
+ senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn;
63
+ recipientAlt = stanza.attrs.recipient_pn;
64
+ // with device data
65
+ if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt);
66
+ } else {
67
+ // Message is PN-addressed: sender is PN, extract corresponding LID
68
+ // without device data
69
+ senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid;
70
+ recipientAlt = stanza.attrs.recipient_lid;
71
+ //with device data
72
+ if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt);
73
+ }
74
+ return {
75
+ addressingMode,
76
+ senderAlt,
77
+ recipientAlt
78
+ };
74
79
  };
75
80
  /**
76
81
  * Decode the received node as a message.
77
82
  * @note this will only parse the message, not decrypt it
78
83
  */
79
84
  export function decodeMessageNode(stanza, meId, meLid) {
80
- let msgType;
81
- let chatId;
82
- let author;
83
- const msgId = stanza.attrs.id;
84
- const from = stanza.attrs.from;
85
- const participant = stanza.attrs.participant;
86
- const recipient = stanza.attrs.recipient;
87
- const addressingContext = extractAddressingContext(stanza);
88
- const isMe = (jid) => areJidsSameUser(jid, meId);
89
- const isMeLid = (jid) => areJidsSameUser(jid, meLid);
90
- if (isPnUser(from) || isLidUser(from)) {
91
- if (recipient && !isJidMetaAI(recipient)) {
92
- if (!isMe(from) && !isMeLid(from)) {
93
- throw new Boom('receipient present, but msg not from me', { data: stanza });
94
- }
95
- chatId = recipient;
96
- }
97
- else {
98
- chatId = from;
99
- }
100
- msgType = 'chat';
101
- author = from;
85
+ let msgType;
86
+ let chatId;
87
+ let author;
88
+ const msgId = stanza.attrs.id;
89
+ const from = stanza.attrs.from;
90
+ const participant = stanza.attrs.participant;
91
+ const recipient = stanza.attrs.recipient;
92
+ const addressingContext = extractAddressingContext(stanza);
93
+ const isMe = jid => areJidsSameUser(jid, meId);
94
+ const isMeLid = jid => areJidsSameUser(jid, meLid);
95
+ if (isPnUser(from) || isLidUser(from)) {
96
+ if (recipient && !isJidMetaAI(recipient)) {
97
+ if (!isMe(from) && !isMeLid(from)) {
98
+ throw new Boom('receipient present, but msg not from me', {
99
+ data: stanza
100
+ });
101
+ }
102
+ chatId = recipient;
103
+ } else {
104
+ chatId = from;
102
105
  }
103
- else if (isJidGroup(from)) {
104
- if (!participant) {
105
- throw new Boom('No participant in group message');
106
- }
107
- msgType = 'group';
108
- author = participant;
109
- chatId = from;
106
+ msgType = 'chat';
107
+ author = from;
108
+ } else if (isJidGroup(from)) {
109
+ if (!participant) {
110
+ throw new Boom('No participant in group message');
110
111
  }
111
- else if (isJidBroadcast(from)) {
112
- if (!participant) {
113
- throw new Boom('No participant in group message');
114
- }
115
- const isParticipantMe = isMe(participant);
116
- if (isJidStatusBroadcast(from)) {
117
- msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
118
- }
119
- else {
120
- msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
121
- }
122
- chatId = from;
123
- author = participant;
112
+ msgType = 'group';
113
+ author = participant;
114
+ chatId = from;
115
+ } else if (isJidBroadcast(from)) {
116
+ if (!participant) {
117
+ throw new Boom('No participant in group message');
124
118
  }
125
- else if (isJidNewsletter(from)) {
126
- msgType = 'newsletter';
127
- chatId = from;
128
- author = from;
119
+ const isParticipantMe = isMe(participant);
120
+ if (isJidStatusBroadcast(from)) {
121
+ msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
122
+ } else {
123
+ msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
129
124
  }
130
- else {
131
- throw new Boom('Unknown message type', { data: stanza });
132
- }
133
- const fromMe = (isLidUser(from) ? isMeLid : isMe)((stanza.attrs.participant || stanza.attrs.from));
134
- const pushname = stanza?.attrs?.notify;
135
- const key = {
136
- remoteJid: chatId,
137
- remoteJidAlt: !isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
138
- fromMe,
139
- id: msgId,
140
- participant,
141
- participantAlt: isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
142
- ...(msgType === 'newsletter' && stanza.attrs.server_id ? { server_id: stanza.attrs.server_id } : {})
143
- };
144
- const fullMessage = {
145
- key,
146
- messageTimestamp: +stanza.attrs.t,
147
- pushName: pushname,
148
- broadcast: isJidBroadcast(from)
149
- };
150
- if (key.fromMe) {
151
- fullMessage.status = proto.WebMessageInfo.Status.SERVER_ACK;
152
- }
153
- return {
154
- fullMessage,
155
- author,
156
- sender: msgType === 'chat' ? author : chatId
157
- };
125
+ chatId = from;
126
+ author = participant;
127
+ } else if (isJidNewsletter(from)) {
128
+ msgType = 'newsletter';
129
+ chatId = from;
130
+ author = from;
131
+ } else {
132
+ throw new Boom('Unknown message type', {
133
+ data: stanza
134
+ });
135
+ }
136
+ const fromMe = (isLidUser(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
137
+ const pushname = stanza?.attrs?.notify;
138
+ const key = {
139
+ remoteJid: chatId,
140
+ remoteJidAlt: !isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
141
+ fromMe,
142
+ id: msgId,
143
+ participant,
144
+ participantAlt: isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
145
+ ...(msgType === 'newsletter' && stanza.attrs.server_id ? {
146
+ server_id: stanza.attrs.server_id
147
+ } : {})
148
+ };
149
+ const fullMessage = {
150
+ key,
151
+ messageTimestamp: +stanza.attrs.t,
152
+ pushName: pushname,
153
+ broadcast: isJidBroadcast(from)
154
+ };
155
+ if (key.fromMe) {
156
+ fullMessage.status = proto.WebMessageInfo.Status.SERVER_ACK;
157
+ }
158
+ return {
159
+ fullMessage,
160
+ author,
161
+ sender: msgType === 'chat' ? author : chatId
162
+ };
158
163
  }
159
164
  export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
160
- const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
161
- return {
162
- fullMessage,
163
- category: stanza.attrs.category,
164
- author,
165
- async decrypt() {
166
- let decryptables = 0;
167
- if (Array.isArray(stanza.content)) {
168
- for (const { tag, attrs, content } of stanza.content) {
169
- if (tag === 'verified_name' && content instanceof Uint8Array) {
170
- const cert = proto.VerifiedNameCertificate.decode(content);
171
- const details = proto.VerifiedNameCertificate.Details.decode(cert.details);
172
- fullMessage.verifiedBizName = details.verifiedName;
173
- }
174
- if (tag === 'unavailable' && attrs.type === 'view_once') {
175
- fullMessage.key.isViewOnce = true; // TODO: remove from here and add a STUB TYPE
176
- }
177
- if (tag !== 'enc' && tag !== 'plaintext') {
178
- continue;
179
- }
180
- if (!(content instanceof Uint8Array)) {
181
- continue;
182
- }
183
- decryptables += 1;
184
- let msgBuffer;
185
- const user = isPnUser(sender) ? sender : author; // TODO: flaky logic
186
- const decryptionJid = await getDecryptionJid(user, repository);
187
- if (tag !== 'plaintext') {
188
- await storeMappingFromEnvelope(stanza, user, decryptionJid, repository, logger);
189
- }
190
- try {
191
- const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
192
- switch (e2eType) {
193
- case 'skmsg':
194
- msgBuffer = await repository.decryptGroupMessage({
195
- group: sender,
196
- authorJid: author,
197
- msg: content
198
- });
199
- break;
200
- case 'pkmsg':
201
- case 'msg':
202
- msgBuffer = await repository.decryptMessage({
203
- jid: decryptionJid,
204
- type: e2eType,
205
- ciphertext: content
206
- });
207
- break;
208
- case 'plaintext':
209
- msgBuffer = content;
210
- break;
211
- default:
212
- throw new Error(`Unknown e2e type: ${e2eType}`);
213
- }
214
- let msg = proto.Message.decode(e2eType !== 'plaintext' ? unpadRandomMax16(msgBuffer) : msgBuffer);
215
- msg = msg.deviceSentMessage?.message || msg;
216
- if (msg.senderKeyDistributionMessage) {
217
- //eslint-disable-next-line max-depth
218
- try {
219
- await repository.processSenderKeyDistributionMessage({
220
- authorJid: author,
221
- item: msg.senderKeyDistributionMessage
222
- });
223
- }
224
- catch (err) {
225
- logger.error({ key: fullMessage.key, err }, 'failed to process sender key distribution message');
226
- }
227
- }
228
- if (fullMessage.message) {
229
- Object.assign(fullMessage.message, msg);
230
- }
231
- else {
232
- fullMessage.message = msg;
233
- }
234
- }
235
- catch (err) {
236
- const errorContext = {
237
- key: fullMessage.key,
238
- err,
239
- messageType: tag === 'plaintext' ? 'plaintext' : attrs.type,
240
- sender,
241
- author,
242
- isSessionRecordError: isSessionRecordError(err)
243
- };
244
- logger.error(errorContext, 'failed to decrypt message');
245
- fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
246
- fullMessage.messageStubParameters = [err.message.toString()];
247
- }
248
- }
165
+ const {
166
+ fullMessage,
167
+ author,
168
+ sender
169
+ } = decodeMessageNode(stanza, meId, meLid);
170
+ return {
171
+ fullMessage,
172
+ category: stanza.attrs.category,
173
+ author,
174
+ async decrypt() {
175
+ let decryptables = 0;
176
+ if (Array.isArray(stanza.content)) {
177
+ for (const {
178
+ tag,
179
+ attrs,
180
+ content
181
+ } of stanza.content) {
182
+ if (tag === 'verified_name' && content instanceof Uint8Array) {
183
+ const cert = proto.VerifiedNameCertificate.decode(content);
184
+ const details = proto.VerifiedNameCertificate.Details.decode(cert.details);
185
+ fullMessage.verifiedBizName = details.verifiedName;
186
+ }
187
+ if (tag === 'unavailable' && attrs.type === 'view_once') {
188
+ fullMessage.key.isViewOnce = true; // TODO: remove from here and add a STUB TYPE
189
+ }
190
+ if (tag !== 'enc' && tag !== 'plaintext') {
191
+ continue;
192
+ }
193
+ if (!(content instanceof Uint8Array)) {
194
+ continue;
195
+ }
196
+ decryptables += 1;
197
+ let msgBuffer;
198
+ const user = isPnUser(sender) ? sender : author; // TODO: flaky logic
199
+ const decryptionJid = await getDecryptionJid(user, repository);
200
+ if (tag !== 'plaintext') {
201
+ await storeMappingFromEnvelope(stanza, user, decryptionJid, repository, logger);
202
+ }
203
+ try {
204
+ const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
205
+ switch (e2eType) {
206
+ case 'skmsg':
207
+ msgBuffer = await repository.decryptGroupMessage({
208
+ group: sender,
209
+ authorJid: author,
210
+ msg: content
211
+ });
212
+ break;
213
+ case 'pkmsg':
214
+ case 'msg':
215
+ msgBuffer = await repository.decryptMessage({
216
+ jid: decryptionJid,
217
+ type: e2eType,
218
+ ciphertext: content
219
+ });
220
+ break;
221
+ case 'plaintext':
222
+ msgBuffer = content;
223
+ break;
224
+ default:
225
+ throw new Error(`Unknown e2e type: ${e2eType}`);
249
226
  }
250
- // if nothing was found to decrypt
251
- if (!decryptables) {
252
- fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
253
- fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT];
227
+ let msg = proto.Message.decode(e2eType !== 'plaintext' ? unpadRandomMax16(msgBuffer) : msgBuffer);
228
+ msg = msg.deviceSentMessage?.message || msg;
229
+ if (msg.senderKeyDistributionMessage) {
230
+ //eslint-disable-next-line max-depth
231
+ try {
232
+ await repository.processSenderKeyDistributionMessage({
233
+ authorJid: author,
234
+ item: msg.senderKeyDistributionMessage
235
+ });
236
+ } catch (err) {
237
+ logger.error({
238
+ key: fullMessage.key,
239
+ err
240
+ }, 'failed to process sender key distribution message');
241
+ }
254
242
  }
243
+ if (fullMessage.message) {
244
+ Object.assign(fullMessage.message, msg);
245
+ } else {
246
+ fullMessage.message = msg;
247
+ }
248
+ } catch (err) {
249
+ const errorContext = {
250
+ key: fullMessage.key,
251
+ err,
252
+ messageType: tag === 'plaintext' ? 'plaintext' : attrs.type,
253
+ sender,
254
+ author,
255
+ isSessionRecordError: isSessionRecordError(err)
256
+ };
257
+ logger.error(errorContext, 'failed to decrypt message');
258
+ fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
259
+ fullMessage.messageStubParameters = [err.message.toString()];
260
+ }
255
261
  }
256
- };
262
+ }
263
+ // if nothing was found to decrypt
264
+ if (!decryptables) {
265
+ fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
266
+ fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT];
267
+ }
268
+ }
269
+ };
257
270
  };
258
271
  /**
259
272
  * Utility function to check if an error is related to missing session record
260
273
  */
261
274
  function isSessionRecordError(error) {
262
- const errorMessage = error?.message || error?.toString() || '';
263
- return DECRYPTION_RETRY_CONFIG.sessionRecordErrors.some(errorPattern => errorMessage.includes(errorPattern));
275
+ const errorMessage = error?.message || error?.toString() || '';
276
+ return DECRYPTION_RETRY_CONFIG.sessionRecordErrors.some(errorPattern => errorMessage.includes(errorPattern));
264
277
  }
265
278
  //# sourceMappingURL=decode-wa-message.js.map