@vinzsocket/baileys 2.8.10 → 2.8.30
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.
- package/lib/Defaults/index.js +75 -73
- package/lib/Signal/Group/ciphertext-message.js +9 -9
- package/lib/Signal/Group/group-session-builder.js +21 -21
- package/lib/Signal/Group/group_cipher.js +79 -81
- package/lib/Signal/Group/index.js +2 -2
- package/lib/Signal/Group/keyhelper.js +9 -9
- package/lib/Signal/Group/queue-job.js +43 -46
- package/lib/Signal/Group/sender-chain-key.js +24 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
- package/lib/Signal/Group/sender-key-message.js +55 -60
- package/lib/Signal/Group/sender-key-name.js +38 -39
- package/lib/Signal/Group/sender-key-record.js +39 -41
- package/lib/Signal/Group/sender-key-state.js +85 -89
- package/lib/Signal/Group/sender-message-key.js +22 -22
- package/lib/Signal/libsignal.js +387 -292
- package/lib/Signal/lid-mapping.js +98 -93
- package/lib/Socket/Client/types.js +6 -6
- package/lib/Socket/Client/websocket.js +44 -44
- package/lib/Socket/business.js +350 -365
- package/lib/Socket/chats.js +1019 -914
- package/lib/Socket/communities.js +454 -376
- package/lib/Socket/groups.js +378 -310
- package/lib/Socket/index.js +11 -11
- package/lib/Socket/messages-recv.js +1355 -1182
- package/lib/Socket/messages-send.js +1224 -1081
- package/lib/Socket/mex.js +40 -34
- package/lib/Socket/newsletter.js +212 -169
- package/lib/Socket/socket.js +896 -757
- package/lib/Store/index.js +1 -1
- package/lib/Store/make-cache-manager-store.js +75 -79
- package/lib/Store/make-in-memory-store.js +450 -389
- package/lib/Store/make-ordered-dictionary.js +73 -76
- package/lib/Store/object-repository.js +24 -22
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Label.js +20 -20
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +2 -2
- package/lib/Types/Newsletter.js +24 -24
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.js +8 -8
- package/lib/Types/index.js +10 -10
- package/lib/Utils/auth-utils.js +408 -401
- package/lib/Utils/baileys-event-stream.js +44 -35
- package/lib/Utils/business.js +200 -197
- package/lib/Utils/chat-utils.js +775 -708
- package/lib/Utils/crypto.js +97 -85
- package/lib/Utils/decode-wa-message.js +240 -227
- package/lib/Utils/event-buffer.js +547 -518
- package/lib/Utils/extended-messages.js +250 -203
- package/lib/Utils/generics.js +300 -289
- package/lib/Utils/history.js +76 -69
- package/lib/Utils/lid-resolver.js +47 -42
- package/lib/Utils/link-preview.js +75 -65
- package/lib/Utils/logger.js +3 -1
- package/lib/Utils/lt-hash.js +38 -34
- package/lib/Utils/make-mutex.js +32 -34
- package/lib/Utils/mention.js +79 -86
- package/lib/Utils/message-retry-manager.js +148 -136
- package/lib/Utils/messages-media.js +652 -562
- package/lib/Utils/messages.js +753 -707
- package/lib/Utils/noise-handler.js +156 -135
- package/lib/Utils/process-message.js +404 -341
- package/lib/Utils/signal.js +180 -118
- package/lib/Utils/use-multi-file-auth-state.js +87 -91
- package/lib/Utils/validate-connection.js +167 -142
- package/lib/WABinary/constants.js +28 -1293
- package/lib/WABinary/decode.js +220 -218
- package/lib/WABinary/encode.js +199 -201
- package/lib/WABinary/generic-utils.js +80 -77
- package/lib/WABinary/jid-utils.js +41 -35
- package/lib/WAM/BinaryInfo.js +7 -7
- package/lib/WAM/constants.js +1 -15241
- package/lib/WAM/encode.js +124 -131
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
- package/lib/WAUSync/USyncQuery.js +82 -84
- package/lib/WAUSync/USyncUser.js +20 -20
- package/package.json +4 -2
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
maxRetries: 3,
|
|
36
|
+
baseDelayMs: 100,
|
|
37
|
+
sessionRecordErrors: ['No session record', 'SessionError: No session record']
|
|
30
38
|
};
|
|
31
39
|
export const NACK_REASONS = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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 =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
263
|
-
|
|
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
|