@ubedsockets/baileys 1.6.3 → 1.6.5
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/WAProto/GenerateStatics.sh +3 -4
- package/WAProto/WAProto.proto +1215 -511
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +65475 -137445
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -18
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +4 -6
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +21 -78
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +162 -43
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +124 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +571 -249
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +114 -99
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +260 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +11 -9
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1277 -559
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +199 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +674 -669
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +149 -286
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +239 -136
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +380 -238
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +56 -127
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +173 -63
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +174 -70
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +159 -207
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +93 -53
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +22 -33
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +17 -58
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +3 -46
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +24 -34
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +483 -744
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +411 -621
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +149 -99
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +459 -150
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +112 -73
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +23 -27
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +74 -104
- package/lib/Utils/validate-connection.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,14 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidGroup, isJidMetaAI, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser
|
|
4
|
+
// transferDevice
|
|
5
|
+
} from '../WABinary/index.js';
|
|
6
|
+
import { unpadRandomMax16 } from './generics.js';
|
|
7
|
+
export const getDecryptionJid = async (sender, repository) => {
|
|
8
|
+
if (isLidUser(sender) || isHostedLidUser(sender)) {
|
|
9
|
+
return sender;
|
|
10
|
+
}
|
|
11
|
+
const mapped = await repository.lidMapping.getLIDForPN(sender);
|
|
12
|
+
return mapped || sender;
|
|
13
|
+
};
|
|
14
|
+
const storeMappingFromEnvelope = async (stanza, sender, repository, decryptionJid, logger) => {
|
|
15
|
+
// TODO: Handle hosted IDs
|
|
16
|
+
const { senderAlt } = extractAddressingContext(stanza);
|
|
17
|
+
if (senderAlt && isLidUser(senderAlt) && isPnUser(sender) && decryptionJid === sender) {
|
|
18
|
+
try {
|
|
19
|
+
await repository.lidMapping.storeLIDPNMappings([{ lid: senderAlt, pn: sender }]);
|
|
20
|
+
await repository.migrateSession(sender, senderAlt);
|
|
21
|
+
logger.debug({ sender, senderAlt }, 'Stored LID mapping from envelope');
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
logger.warn({ sender, senderAlt, error }, 'Failed to store LID mapping');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
29
|
+
export const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
|
30
|
+
export const ACCOUNT_RESTRICTED_TEXT = 'Your account has been restricted';
|
|
31
|
+
// Retry configuration for failed decryption
|
|
32
|
+
export const DECRYPTION_RETRY_CONFIG = {
|
|
33
|
+
maxRetries: 3,
|
|
34
|
+
baseDelayMs: 100,
|
|
35
|
+
sessionRecordErrors: ['No session record', 'SessionError: No session record']
|
|
36
|
+
};
|
|
37
|
+
/** NACK reason codes we send to the server (client → server) */
|
|
38
|
+
export const NACK_REASONS = {
|
|
39
|
+
SenderReachoutTimelocked: 463,
|
|
12
40
|
ParsingError: 487,
|
|
13
41
|
UnrecognizedStanza: 488,
|
|
14
42
|
UnrecognizedStanzaClass: 489,
|
|
@@ -23,90 +51,153 @@ exports.NACK_REASONS = {
|
|
|
23
51
|
UnsupportedLIDGroup: 551,
|
|
24
52
|
DBOperationFailed: 552
|
|
25
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Server-side error codes returned in ack stanzas (server → client) that we
|
|
56
|
+
* currently have dedicated handlers for. Extend as more handlers are added.
|
|
57
|
+
* Distinct from the client-side NackReason enum (WAWebCreateNackFromStanza).
|
|
58
|
+
*/
|
|
59
|
+
export const SERVER_ERROR_CODES = {
|
|
60
|
+
/**
|
|
61
|
+
* 1:1 message missing privacy token (tctoken). Usually means the account is
|
|
62
|
+
* restricted: WhatsApp blocks starting new chats but preserves existing ones,
|
|
63
|
+
* since established chats already carry a tctoken.
|
|
64
|
+
*/
|
|
65
|
+
MessageAccountRestriction: '463',
|
|
66
|
+
/** Stanza validation failure (SMAX_INVALID) — likely stale device session */
|
|
67
|
+
SmaxInvalid: '479'
|
|
68
|
+
};
|
|
69
|
+
export const extractAddressingContext = (stanza) => {
|
|
70
|
+
let senderAlt;
|
|
71
|
+
let recipientAlt;
|
|
72
|
+
const sender = stanza.attrs.participant || stanza.attrs.from;
|
|
73
|
+
const addressingMode = stanza.attrs.addressing_mode || (sender?.endsWith('lid') ? 'lid' : 'pn');
|
|
74
|
+
if (addressingMode === 'lid') {
|
|
75
|
+
// Message is LID-addressed: sender is LID, extract corresponding PN
|
|
76
|
+
// without device data
|
|
77
|
+
senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn;
|
|
78
|
+
recipientAlt = stanza.attrs.recipient_pn;
|
|
79
|
+
// with device data
|
|
80
|
+
//if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt)
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Message is PN-addressed: sender is PN, extract corresponding LID
|
|
84
|
+
// without device data
|
|
85
|
+
senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid;
|
|
86
|
+
recipientAlt = stanza.attrs.recipient_lid;
|
|
87
|
+
//with device data
|
|
88
|
+
//if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt)
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
addressingMode,
|
|
92
|
+
senderAlt,
|
|
93
|
+
recipientAlt
|
|
94
|
+
};
|
|
95
|
+
};
|
|
26
96
|
/**
|
|
27
97
|
* Decode the received node as a message.
|
|
28
98
|
* @note this will only parse the message, not decrypt it
|
|
29
99
|
*/
|
|
30
|
-
function decodeMessageNode(stanza, meId, meLid) {
|
|
31
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
100
|
+
export function decodeMessageNode(stanza, meId, meLid) {
|
|
32
101
|
let msgType;
|
|
33
102
|
let chatId;
|
|
34
103
|
let author;
|
|
104
|
+
let fromMe = false;
|
|
35
105
|
const msgId = stanza.attrs.id;
|
|
36
106
|
const from = stanza.attrs.from;
|
|
37
|
-
const senderPn = (_a = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _a === void 0 ? void 0 : _a.sender_pn;
|
|
38
|
-
const senderLid = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid;
|
|
39
107
|
const participant = stanza.attrs.participant;
|
|
40
|
-
const participantLid = (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.participant_lid;
|
|
41
108
|
const recipient = stanza.attrs.recipient;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
109
|
+
if (!msgId) {
|
|
110
|
+
throw new Boom('Invalid message stanza: missing id attribute', { data: stanza });
|
|
111
|
+
}
|
|
112
|
+
if (!from) {
|
|
113
|
+
throw new Boom('Invalid message stanza: missing from attribute', { data: stanza });
|
|
114
|
+
}
|
|
115
|
+
const addressingContext = extractAddressingContext(stanza);
|
|
116
|
+
const isMe = (jid) => areJidsSameUser(jid, meId);
|
|
117
|
+
const isMeLid = (jid) => areJidsSameUser(jid, meLid);
|
|
118
|
+
if (isPnUser(from) || isLidUser(from) || isHostedLidUser(from) || isHostedPnUser(from)) {
|
|
119
|
+
if (recipient && !isJidMetaAI(recipient)) {
|
|
46
120
|
if (!isMe(from) && !isMeLid(from)) {
|
|
47
|
-
throw new
|
|
121
|
+
throw new Boom('receipient present, but msg not from me', { data: stanza });
|
|
122
|
+
}
|
|
123
|
+
if (isMe(from) || isMeLid(from)) {
|
|
124
|
+
fromMe = true;
|
|
48
125
|
}
|
|
49
126
|
chatId = recipient;
|
|
50
127
|
}
|
|
51
128
|
else {
|
|
129
|
+
// Peer-routed self stanzas (history sync, app-state sync, etc.) arrive
|
|
130
|
+
// with `from` set to our own device but no `recipient` attribute —
|
|
131
|
+
// still mark as fromMe so self-only protocolMessage handlers run.
|
|
132
|
+
if (isMe(from) || isMeLid(from)) {
|
|
133
|
+
fromMe = true;
|
|
134
|
+
}
|
|
52
135
|
chatId = from;
|
|
53
136
|
}
|
|
54
137
|
msgType = 'chat';
|
|
55
138
|
author = from;
|
|
56
139
|
}
|
|
57
|
-
else if (
|
|
140
|
+
else if (isJidGroup(from)) {
|
|
58
141
|
if (!participant) {
|
|
59
|
-
throw new
|
|
142
|
+
throw new Boom('No participant in group message');
|
|
143
|
+
}
|
|
144
|
+
if (isMe(participant) || isMeLid(participant)) {
|
|
145
|
+
fromMe = true;
|
|
60
146
|
}
|
|
61
147
|
msgType = 'group';
|
|
62
148
|
author = participant;
|
|
63
149
|
chatId = from;
|
|
64
150
|
}
|
|
65
|
-
else if ((
|
|
66
|
-
msgType = 'newsletter';
|
|
67
|
-
author = from;
|
|
68
|
-
chatId = from;
|
|
69
|
-
}
|
|
70
|
-
else if ((0, WABinary_1.isJidBroadcast)(from)) {
|
|
151
|
+
else if (isJidBroadcast(from)) {
|
|
71
152
|
if (!participant) {
|
|
72
|
-
throw new
|
|
153
|
+
throw new Boom('No participant in group message');
|
|
73
154
|
}
|
|
74
155
|
const isParticipantMe = isMe(participant);
|
|
75
|
-
if (
|
|
156
|
+
if (isJidStatusBroadcast(from)) {
|
|
76
157
|
msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
|
|
77
158
|
}
|
|
78
159
|
else {
|
|
79
160
|
msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
|
|
80
161
|
}
|
|
162
|
+
fromMe = isParticipantMe;
|
|
81
163
|
chatId = from;
|
|
82
164
|
author = participant;
|
|
83
165
|
}
|
|
166
|
+
else if (isJidNewsletter(from)) {
|
|
167
|
+
msgType = 'newsletter';
|
|
168
|
+
chatId = from;
|
|
169
|
+
author = from;
|
|
170
|
+
if (isMe(from) || isMeLid(from)) {
|
|
171
|
+
fromMe = true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
84
174
|
else {
|
|
85
|
-
throw new
|
|
175
|
+
throw new Boom('Unknown message type', { data: stanza });
|
|
86
176
|
}
|
|
87
|
-
const
|
|
88
|
-
const pushname = (_e = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _e === void 0 ? void 0 : _e.notify;
|
|
177
|
+
const pushname = stanza?.attrs?.notify;
|
|
89
178
|
const key = {
|
|
90
179
|
remoteJid: chatId,
|
|
180
|
+
remoteJidAlt: !isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
|
|
181
|
+
remoteJidUsername: !isJidGroup(chatId)
|
|
182
|
+
? stanza.attrs.peer_recipient_username || stanza.attrs.recipient_username
|
|
183
|
+
: undefined,
|
|
91
184
|
fromMe,
|
|
92
185
|
id: msgId,
|
|
93
|
-
senderPn,
|
|
94
|
-
senderLid,
|
|
95
186
|
participant,
|
|
96
|
-
|
|
97
|
-
|
|
187
|
+
participantAlt: isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
|
|
188
|
+
participantUsername: stanza.attrs.participant ? stanza.attrs.participant_username : undefined,
|
|
189
|
+
addressingMode: addressingContext.addressingMode,
|
|
190
|
+
...(msgType === 'newsletter' && stanza.attrs.server_id ? { server_id: stanza.attrs.server_id } : {})
|
|
98
191
|
};
|
|
99
192
|
const fullMessage = {
|
|
100
193
|
key,
|
|
194
|
+
category: stanza.attrs.category,
|
|
101
195
|
messageTimestamp: +stanza.attrs.t,
|
|
102
196
|
pushName: pushname,
|
|
103
|
-
broadcast:
|
|
197
|
+
broadcast: isJidBroadcast(from)
|
|
104
198
|
};
|
|
105
|
-
if (msgType === 'newsletter') {
|
|
106
|
-
fullMessage.newsletterServerId = +((_g = stanza.attrs) === null || _g === void 0 ? void 0 : _g.server_id);
|
|
107
|
-
}
|
|
108
199
|
if (key.fromMe) {
|
|
109
|
-
fullMessage.status =
|
|
200
|
+
fullMessage.status = proto.WebMessageInfo.Status.SERVER_ACK;
|
|
110
201
|
}
|
|
111
202
|
return {
|
|
112
203
|
fullMessage,
|
|
@@ -114,24 +205,26 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
114
205
|
sender: msgType === 'chat' ? author : chatId
|
|
115
206
|
};
|
|
116
207
|
}
|
|
117
|
-
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
208
|
+
export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
118
209
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
|
119
210
|
return {
|
|
120
211
|
fullMessage,
|
|
121
212
|
category: stanza.attrs.category,
|
|
122
213
|
author,
|
|
123
214
|
async decrypt() {
|
|
124
|
-
var _a;
|
|
125
215
|
let decryptables = 0;
|
|
126
216
|
if (Array.isArray(stanza.content)) {
|
|
127
217
|
for (const { tag, attrs, content } of stanza.content) {
|
|
128
218
|
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
129
|
-
const cert =
|
|
130
|
-
const details =
|
|
219
|
+
const cert = proto.VerifiedNameCertificate.decode(content);
|
|
220
|
+
const details = proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
131
221
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
132
222
|
}
|
|
133
223
|
if (tag === 'unavailable' && attrs.type === 'view_once') {
|
|
134
|
-
fullMessage.key.isViewOnce = true;
|
|
224
|
+
fullMessage.key.isViewOnce = true; // TODO: remove from here and add a STUB TYPE
|
|
225
|
+
}
|
|
226
|
+
if (attrs.count && tag === 'enc') {
|
|
227
|
+
fullMessage.retryCount = Number(attrs.count);
|
|
135
228
|
}
|
|
136
229
|
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
137
230
|
continue;
|
|
@@ -141,6 +234,11 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
141
234
|
}
|
|
142
235
|
decryptables += 1;
|
|
143
236
|
let msgBuffer;
|
|
237
|
+
const decryptionJid = await getDecryptionJid(author, repository);
|
|
238
|
+
if (tag !== 'plaintext') {
|
|
239
|
+
// TODO: Handle hosted devices
|
|
240
|
+
await storeMappingFromEnvelope(stanza, author, repository, decryptionJid, logger);
|
|
241
|
+
}
|
|
144
242
|
try {
|
|
145
243
|
const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
|
|
146
244
|
switch (e2eType) {
|
|
@@ -153,9 +251,8 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
153
251
|
break;
|
|
154
252
|
case 'pkmsg':
|
|
155
253
|
case 'msg':
|
|
156
|
-
const user = (0, WABinary_1.isJidUser)(sender) ? sender : author;
|
|
157
254
|
msgBuffer = await repository.decryptMessage({
|
|
158
|
-
jid:
|
|
255
|
+
jid: decryptionJid,
|
|
159
256
|
type: e2eType,
|
|
160
257
|
ciphertext: content
|
|
161
258
|
});
|
|
@@ -163,15 +260,13 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
163
260
|
case 'plaintext':
|
|
164
261
|
msgBuffer = content;
|
|
165
262
|
break;
|
|
166
|
-
case undefined:
|
|
167
|
-
msgBuffer = content;
|
|
168
|
-
break;
|
|
169
263
|
default:
|
|
170
264
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
171
265
|
}
|
|
172
|
-
let msg =
|
|
173
|
-
msg =
|
|
266
|
+
let msg = proto.Message.decode(e2eType !== 'plaintext' ? unpadRandomMax16(msgBuffer) : msgBuffer);
|
|
267
|
+
msg = msg.deviceSentMessage?.message || msg;
|
|
174
268
|
if (msg.senderKeyDistributionMessage) {
|
|
269
|
+
//eslint-disable-next-line max-depth
|
|
175
270
|
try {
|
|
176
271
|
await repository.processSenderKeyDistributionMessage({
|
|
177
272
|
authorJid: author,
|
|
@@ -179,7 +274,7 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
179
274
|
});
|
|
180
275
|
}
|
|
181
276
|
catch (err) {
|
|
182
|
-
logger.error({ key: fullMessage.key, err }, 'failed to
|
|
277
|
+
logger.error({ key: fullMessage.key, err }, 'failed to process sender key distribution message');
|
|
183
278
|
}
|
|
184
279
|
}
|
|
185
280
|
if (fullMessage.message) {
|
|
@@ -190,18 +285,33 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
190
285
|
}
|
|
191
286
|
}
|
|
192
287
|
catch (err) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
288
|
+
const errorContext = {
|
|
289
|
+
key: fullMessage.key,
|
|
290
|
+
err,
|
|
291
|
+
messageType: tag === 'plaintext' ? 'plaintext' : attrs.type,
|
|
292
|
+
sender,
|
|
293
|
+
author,
|
|
294
|
+
isSessionRecordError: isSessionRecordError(err)
|
|
295
|
+
};
|
|
296
|
+
logger.error(errorContext, 'failed to decrypt message');
|
|
297
|
+
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
298
|
+
fullMessage.messageStubParameters = [err.message.toString()];
|
|
196
299
|
}
|
|
197
300
|
}
|
|
198
301
|
}
|
|
199
302
|
// if nothing was found to decrypt
|
|
200
|
-
if (!decryptables) {
|
|
201
|
-
fullMessage.messageStubType =
|
|
202
|
-
fullMessage.messageStubParameters = [
|
|
303
|
+
if (!decryptables && !fullMessage.key?.isViewOnce) {
|
|
304
|
+
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
305
|
+
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT];
|
|
203
306
|
}
|
|
204
307
|
}
|
|
205
308
|
};
|
|
206
309
|
};
|
|
207
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Utility function to check if an error is related to missing session record
|
|
312
|
+
*/
|
|
313
|
+
function isSessionRecordError(error) {
|
|
314
|
+
const errorMessage = error?.message || error?.toString() || '';
|
|
315
|
+
return DECRYPTION_RETRY_CONFIG.sessionRecordErrors.some(errorPattern => errorMessage.includes(errorPattern));
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=decode-wa-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-wa-message.js","sourceRoot":"","sources":["../../src/Utils/decode-wa-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAG9C,OAAO,EACN,eAAe,EAEf,eAAe,EACf,cAAc,EACd,cAAc,EACd,UAAU,EACV,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,SAAS,EACT,QAAQ;AACR,iBAAiB;EACjB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAG7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,MAAc,EAAE,UAAwC,EAAmB,EAAE;IACnH,IAAI,SAAS,CAAC,MAAM,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,OAAO,MAAM,CAAA;IACd,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAC9D,OAAO,MAAM,IAAI,MAAM,CAAA;AACxB,CAAC,CAAA;AAED,MAAM,wBAAwB,GAAG,KAAK,EACrC,MAAkB,EAClB,MAAc,EACd,UAAwC,EACxC,aAAqB,EACrB,MAAe,EACC,EAAE;IAClB,0BAA0B;IAC1B,MAAM,EAAE,SAAS,EAAE,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAA;IAEtD,IAAI,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,aAAa,KAAK,MAAM,EAAE,CAAC;QACvF,IAAI,CAAC;YACJ,MAAM,UAAU,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE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1
|
+
import type { BaileysEventEmitter, BaileysEventMap } from '../Types/index.js';
|
|
2
|
+
import type { ILogger } from './logger.js';
|
|
3
|
+
/**
|
|
4
|
+
* A map that contains a list of all events that have been triggered
|
|
5
|
+
*
|
|
6
|
+
* Note, this can contain different type of events
|
|
7
|
+
* this can make processing events extremely efficient -- since everything
|
|
8
|
+
* can be done in a single transaction
|
|
9
|
+
*/
|
|
10
|
+
type BaileysEventData = Partial<BaileysEventMap>;
|
|
11
|
+
type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
12
|
+
/** Use to process events in a batch */
|
|
13
|
+
process(handler: (events: BaileysEventData) => void | Promise<void>): () => void;
|
|
14
|
+
/**
|
|
15
|
+
* starts buffering events, call flush() to release them
|
|
16
|
+
* */
|
|
17
|
+
buffer(): void;
|
|
18
|
+
/** buffers all events till the promise completes */
|
|
19
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* flushes all buffered events
|
|
22
|
+
* @returns returns true if the flush actually happened, otherwise false
|
|
23
|
+
*/
|
|
24
|
+
flush(): boolean;
|
|
25
|
+
/** is there an ongoing buffer */
|
|
26
|
+
isBuffering(): boolean;
|
|
27
|
+
/** destroy the event buffer, clearing all resources */
|
|
28
|
+
destroy(): void;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The event buffer logically consolidates different events into a single event
|
|
32
|
+
* making the data processing more efficient.
|
|
33
|
+
*/
|
|
34
|
+
export declare const makeEventBuffer: (logger: ILogger) => BaileysBufferableEventEmitter;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=event-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-buffer.d.ts","sourceRoot":"","sources":["../../src/Utils/event-buffer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEX,mBAAmB,EACnB,eAAe,EAOf,MAAM,UAAU,CAAA;AAGjB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAqBvC;;;;;;GAMG;AACH,KAAK,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AAIhD,KAAK,6BAA6B,GAAG,mBAAmB,GAAG;IAC1D,uCAAuC;IACvC,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAA;IAChF;;SAEK;IACL,MAAM,IAAI,IAAI,CAAA;IACd,oDAAoD;IAEpD,sBAAsB,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;IACxG;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAA;IAChB,iCAAiC;IACjC,WAAW,IAAI,OAAO,CAAA;IACtB,uDAAuD;IACvD,OAAO,IAAI,IAAI,CAAA;CACf,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,OAAO,KAAG,6BA8LjD,CAAA"}
|