@mrlegendbot/baileys 1.2.3 → 1.2.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/README.upstream.md +1312 -0
- package/WAProto/WAProto.json +1 -0
- package/WAProto/WAProto.proto +6275 -0
- package/WAProto/compiler.js +550 -0
- package/WAProto/index.js +2 -97691
- package/lib/Defaults/index.js +89 -92
- package/lib/Signal/Group/ciphertext-message.js +9 -10
- package/lib/Signal/Group/group-session-builder.js +21 -22
- package/lib/Signal/Group/group_cipher.js +75 -69
- package/lib/Signal/Group/index.js +0 -1
- package/lib/Signal/Group/keyhelper.js +9 -10
- package/lib/Signal/Group/sender-chain-key.js +21 -22
- package/lib/Signal/Group/sender-key-distribution-message.js +51 -60
- package/lib/Signal/Group/sender-key-message.js +56 -62
- package/lib/Signal/Group/sender-key-name.js +38 -40
- package/lib/Signal/Group/sender-key-record.js +33 -34
- package/lib/Signal/Group/sender-key-state.js +72 -76
- package/lib/Signal/Group/sender-message-key.js +22 -23
- package/lib/Signal/libsignal.js +506 -405
- package/lib/Signal/lid-mapping.js +276 -258
- package/lib/Socket/Client/index.js +0 -1
- package/lib/Socket/Client/types.js +6 -7
- package/lib/Socket/Client/websocket.js +48 -49
- package/lib/Socket/business.js +349 -369
- package/lib/Socket/chats.js +1172 -1148
- package/lib/Socket/communities.js +473 -413
- package/lib/Socket/groups.js +387 -331
- package/lib/Socket/index.js +6 -8
- package/lib/Socket/messages-recv.js +1782 -1719
- package/lib/Socket/messages-send.js +1554 -2450
- package/lib/Socket/mex.js +40 -35
- package/lib/Socket/newsletter.js +239 -191
- package/lib/Socket/socket.js +992 -923
- package/lib/Store/index.js +8 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +70 -0
- package/lib/Store/make-in-memory-store.js +417 -0
- package/lib/Store/make-ordered-dictionary.js +69 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +0 -1
- package/lib/Types/Bussines.js +0 -1
- package/lib/Types/Call.js +0 -1
- package/lib/Types/Chat.js +1 -8
- package/lib/Types/Contact.js +0 -1
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +0 -1
- package/lib/Types/Label.js +20 -22
- package/lib/Types/LabelAssociation.js +2 -4
- package/lib/Types/Message.js +3 -5
- package/lib/Types/Mex.js +26 -31
- package/lib/Types/Product.js +0 -1
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +4 -52
- package/lib/Types/USync.js +0 -1
- package/lib/Types/index.js +10 -11
- package/lib/Utils/auth-utils.js +240 -277
- package/lib/Utils/browser-utils.js +20 -23
- package/lib/Utils/business.js +200 -204
- package/lib/Utils/chat-utils.js +836 -810
- package/lib/Utils/companion-reg-client-utils.js +23 -25
- package/lib/Utils/crypto.js +70 -86
- package/lib/Utils/decode-wa-message.js +277 -284
- package/lib/Utils/event-buffer.js +592 -595
- package/lib/Utils/generics.js +312 -335
- package/lib/Utils/history.js +123 -115
- package/lib/Utils/index.js +1 -2
- package/lib/Utils/link-preview.js +74 -73
- package/lib/Utils/logger.js +3 -2
- package/lib/Utils/lt-hash.js +0 -6
- package/lib/Utils/make-mutex.js +27 -27
- package/lib/Utils/message-retry-manager.js +213 -254
- package/lib/Utils/messages-media.js +741 -715
- package/lib/Utils/messages.js +791 -827
- package/lib/Utils/noise-handler.js +215 -187
- package/lib/Utils/pre-key-manager.js +69 -98
- package/lib/Utils/process-message.js +617 -586
- package/lib/Utils/reporting-utils.js +553 -234
- package/lib/Utils/signal.js +217 -170
- package/lib/Utils/stanza-ack.js +27 -35
- package/lib/Utils/sync-action-utils.js +37 -41
- package/lib/Utils/tc-token-utils.js +120 -141
- package/lib/Utils/use-multi-file-auth-state.js +87 -105
- package/lib/Utils/use-sqlite-auth-state.js +162 -0
- package/lib/Utils/validate-connection.js +190 -188
- package/lib/WABinary/constants.js +28 -1294
- package/lib/WABinary/decode.js +245 -249
- package/lib/WABinary/encode.js +201 -206
- package/lib/WABinary/generic-utils.js +86 -89
- package/lib/WABinary/index.js +0 -1
- package/lib/WABinary/jid-utils.js +68 -77
- package/lib/WABinary/types.js +0 -1
- package/lib/WAM/BinaryInfo.js +7 -8
- package/lib/WAM/constants.js +19892 -22853
- package/lib/WAM/encode.js +121 -132
- package/lib/WAM/index.js +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +46 -43
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +47 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -23
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -33
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -20
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -44
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
- package/lib/WAUSync/Protocols/index.js +0 -1
- package/lib/WAUSync/USyncQuery.js +79 -88
- package/lib/WAUSync/USyncUser.js +28 -29
- package/lib/WAUSync/index.js +0 -1
- package/lib/index.js +2 -2
- package/package.json +22 -86
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -85
- package/WAProto/index.d.ts +0 -14017
- package/lib/Defaults/index.d.ts +0 -75
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
- package/lib/Signal/Group/group-session-builder.d.ts +0 -15
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/index.d.ts +0 -12
- package/lib/Signal/Group/keyhelper.d.ts +0 -11
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -18
- package/lib/Signal/Group/sender-key-record.d.ts +0 -31
- package/lib/Signal/Group/sender-key-state.d.ts +0 -39
- package/lib/Signal/Group/sender-message-key.d.ts +0 -12
- package/lib/Signal/libsignal.d.ts +0 -5
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Socket/Client/index.d.ts +0 -3
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -217
- package/lib/Socket/chats.d.ts +0 -125
- package/lib/Socket/communities.d.ts +0 -273
- package/lib/Socket/groups.d.ts +0 -161
- package/lib/Socket/index.d.ts +0 -260
- package/lib/Socket/messages-recv.d.ts +0 -203
- package/lib/Socket/messages-send.d.ts +0 -199
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/newsletter.d.ts +0 -170
- package/lib/Socket/socket.d.ts +0 -59
- package/lib/Types/Auth.d.ts +0 -117
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Call.d.ts +0 -15
- package/lib/Types/Chat.d.ts +0 -124
- package/lib/Types/Contact.d.ts +0 -26
- package/lib/Types/Events.d.ts +0 -256
- package/lib/Types/GroupMetadata.d.ts +0 -71
- package/lib/Types/Label.d.ts +0 -47
- package/lib/Types/LabelAssociation.d.ts +0 -30
- package/lib/Types/Message.d.ts +0 -320
- package/lib/Types/Mex.d.ts +0 -141
- package/lib/Types/Product.d.ts +0 -79
- package/lib/Types/Signal.d.ts +0 -87
- package/lib/Types/Socket.d.ts +0 -136
- package/lib/Types/State.d.ts +0 -97
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -66
- package/lib/Utils/auth-utils.d.ts +0 -24
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/business.d.ts +0 -23
- package/lib/Utils/chat-utils.d.ts +0 -100
- package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/crypto.d.ts +0 -37
- package/lib/Utils/decode-wa-message.d.ts +0 -66
- package/lib/Utils/event-buffer.d.ts +0 -36
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/history.d.ts +0 -24
- package/lib/Utils/identity-change-handler.d.ts +0 -44
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/index.d.ts +0 -22
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -12
- package/lib/Utils/lt-hash.d.ts +0 -8
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -115
- package/lib/Utils/messages-media.d.ts +0 -133
- package/lib/Utils/messages.d.ts +0 -91
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/offline-node-processor.d.ts +0 -17
- package/lib/Utils/offline-node-processor.js +0 -40
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/process-message.d.ts +0 -60
- package/lib/Utils/reporting-utils.d.ts +0 -11
- package/lib/Utils/signal.d.ts +0 -47
- package/lib/Utils/stanza-ack.d.ts +0 -11
- package/lib/Utils/sync-action-utils.d.ts +0 -19
- package/lib/Utils/tc-token-utils.d.ts +0 -37
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -28
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -15
- package/lib/WABinary/index.d.ts +0 -6
- package/lib/WABinary/jid-utils.d.ts +0 -48
- package/lib/WABinary/types.d.ts +0 -19
- package/lib/WAM/BinaryInfo.d.ts +0 -9
- package/lib/WAM/constants.d.ts +0 -40
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -30
- package/lib/WAUSync/USyncUser.d.ts +0 -17
- package/lib/WAUSync/index.d.ts +0 -4
- package/lib/index.d.ts +0 -12
|
@@ -1,317 +1,310 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
|
-
import { proto } from '../../WAProto/
|
|
3
|
-
import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidGroup,
|
|
4
|
-
// transferDevice
|
|
5
|
-
} from '../WABinary/index.js';
|
|
2
|
+
import { proto } from '../../WAProto/compiler.js';
|
|
3
|
+
import { areJidsSameUser, isHostedLidUser, isHostedPnUser, isJidBroadcast, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser } from '../WABinary/index.js';
|
|
6
4
|
import { unpadRandomMax16 } from './generics.js';
|
|
7
5
|
export const getDecryptionJid = async (sender, repository) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
if (isLidUser(sender) || isHostedLidUser(sender)) {
|
|
7
|
+
return sender;
|
|
8
|
+
}
|
|
9
|
+
const mapped = await repository.lidMapping.getLIDForPN(sender);
|
|
10
|
+
return mapped || sender;
|
|
13
11
|
};
|
|
14
12
|
const storeMappingFromEnvelope = async (stanza, sender, repository, decryptionJid, logger) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
const {
|
|
14
|
+
senderAlt
|
|
15
|
+
} = extractAddressingContext(stanza);
|
|
16
|
+
if (senderAlt && isLidUser(senderAlt) && isPnUser(sender) && decryptionJid === sender) {
|
|
17
|
+
try {
|
|
18
|
+
await repository.lidMapping.storeLIDPNMappings([{
|
|
19
|
+
lid: senderAlt,
|
|
20
|
+
pn: sender
|
|
21
|
+
}]);
|
|
22
|
+
await repository.migrateSession(sender, senderAlt);
|
|
23
|
+
logger.debug({
|
|
24
|
+
sender,
|
|
25
|
+
senderAlt
|
|
26
|
+
}, 'Stored LID mapping from envelope');
|
|
27
|
+
} catch (error) {
|
|
28
|
+
logger.warn({
|
|
29
|
+
sender,
|
|
30
|
+
senderAlt,
|
|
31
|
+
error
|
|
32
|
+
}, 'Failed to store LID mapping');
|
|
26
33
|
}
|
|
34
|
+
}
|
|
27
35
|
};
|
|
28
36
|
export const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
29
37
|
export const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
|
30
38
|
export const ACCOUNT_RESTRICTED_TEXT = 'Your account has been restricted';
|
|
31
|
-
// Retry configuration for failed decryption
|
|
32
39
|
export const DECRYPTION_RETRY_CONFIG = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
maxRetries: 3,
|
|
41
|
+
baseDelayMs: 100,
|
|
42
|
+
sessionRecordErrors: ['No session record', 'SessionError: No session record']
|
|
36
43
|
};
|
|
37
|
-
/** NACK reason codes we send to the server (client → server) */
|
|
38
44
|
export const NACK_REASONS = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
SenderReachoutTimelocked: 463,
|
|
46
|
+
ParsingError: 487,
|
|
47
|
+
UnrecognizedStanza: 488,
|
|
48
|
+
UnrecognizedStanzaClass: 489,
|
|
49
|
+
UnrecognizedStanzaType: 490,
|
|
50
|
+
InvalidProtobuf: 491,
|
|
51
|
+
InvalidHostedCompanionStanza: 493,
|
|
52
|
+
MissingMessageSecret: 495,
|
|
53
|
+
SignalErrorOldCounter: 496,
|
|
54
|
+
MessageDeletedOnPeer: 499,
|
|
55
|
+
UnhandledError: 500,
|
|
56
|
+
UnsupportedAdminRevoke: 550,
|
|
57
|
+
UnsupportedLIDGroup: 551,
|
|
58
|
+
DBOperationFailed: 552
|
|
53
59
|
};
|
|
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
60
|
export const SERVER_ERROR_CODES = {
|
|
60
|
-
|
|
61
|
-
|
|
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'
|
|
61
|
+
MessageAccountRestriction: '463',
|
|
62
|
+
SmaxInvalid: '479'
|
|
68
63
|
};
|
|
69
|
-
export const extractAddressingContext =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
};
|
|
64
|
+
export const extractAddressingContext = stanza => {
|
|
65
|
+
let senderAlt;
|
|
66
|
+
let recipientAlt;
|
|
67
|
+
const sender = stanza.attrs.participant || stanza.attrs.from;
|
|
68
|
+
const addressingMode = stanza.attrs.addressing_mode || (sender?.endsWith('lid') ? 'lid' : 'pn');
|
|
69
|
+
if (addressingMode === 'lid') {
|
|
70
|
+
senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn;
|
|
71
|
+
recipientAlt = stanza.attrs.recipient_pn;
|
|
72
|
+
} else {
|
|
73
|
+
senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid;
|
|
74
|
+
recipientAlt = stanza.attrs.recipient_lid;
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
addressingMode,
|
|
78
|
+
senderAlt,
|
|
79
|
+
recipientAlt
|
|
80
|
+
};
|
|
95
81
|
};
|
|
96
|
-
/**
|
|
97
|
-
* Decode the received node as a message.
|
|
98
|
-
* @note this will only parse the message, not decrypt it
|
|
99
|
-
*/
|
|
100
82
|
export function decodeMessageNode(stanza, meId, meLid) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
83
|
+
let msgType;
|
|
84
|
+
let chatId;
|
|
85
|
+
let author;
|
|
86
|
+
let fromMe = false;
|
|
87
|
+
const msgId = stanza.attrs.id;
|
|
88
|
+
const from = stanza.attrs.from;
|
|
89
|
+
const participant = stanza.attrs.participant;
|
|
90
|
+
const recipient = stanza.attrs.recipient;
|
|
91
|
+
if (!msgId) {
|
|
92
|
+
throw new Boom('Invalid message stanza: missing id attribute', {
|
|
93
|
+
data: stanza
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (!from) {
|
|
97
|
+
throw new Boom('Invalid message stanza: missing from attribute', {
|
|
98
|
+
data: stanza
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const addressingContext = extractAddressingContext(stanza);
|
|
102
|
+
const isMe = jid => areJidsSameUser(jid, meId);
|
|
103
|
+
const isMeLid = jid => areJidsSameUser(jid, meLid);
|
|
104
|
+
if (isPnUser(from) || isLidUser(from) || isHostedLidUser(from) || isHostedPnUser(from)) {
|
|
105
|
+
if (recipient) {
|
|
106
|
+
if (!isMe(from) && !isMeLid(from)) {
|
|
107
|
+
throw new Boom('receipient present, but msg not from me', {
|
|
108
|
+
data: stanza
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (isMe(from) || isMeLid(from)) {
|
|
112
|
+
fromMe = true;
|
|
113
|
+
}
|
|
114
|
+
chatId = recipient;
|
|
115
|
+
} else {
|
|
116
|
+
if (isMe(from) || isMeLid(from)) {
|
|
117
|
+
fromMe = true;
|
|
118
|
+
}
|
|
119
|
+
chatId = from;
|
|
111
120
|
}
|
|
112
|
-
|
|
113
|
-
|
|
121
|
+
msgType = 'chat';
|
|
122
|
+
author = from;
|
|
123
|
+
} else if (isJidGroup(from)) {
|
|
124
|
+
if (!participant) {
|
|
125
|
+
throw new Boom('No participant in group message');
|
|
114
126
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const isMeLid = (jid) => areJidsSameUser(jid, meLid);
|
|
118
|
-
if (isPnUser(from) || isLidUser(from) || isHostedLidUser(from) || isHostedPnUser(from)) {
|
|
119
|
-
if (recipient && !isJidMetaAI(recipient)) {
|
|
120
|
-
if (!isMe(from) && !isMeLid(from)) {
|
|
121
|
-
throw new Boom('receipient present, but msg not from me', { data: stanza });
|
|
122
|
-
}
|
|
123
|
-
if (isMe(from) || isMeLid(from)) {
|
|
124
|
-
fromMe = true;
|
|
125
|
-
}
|
|
126
|
-
chatId = recipient;
|
|
127
|
-
}
|
|
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
|
-
}
|
|
135
|
-
chatId = from;
|
|
136
|
-
}
|
|
137
|
-
msgType = 'chat';
|
|
138
|
-
author = from;
|
|
127
|
+
if (isMe(participant) || isMeLid(participant)) {
|
|
128
|
+
fromMe = true;
|
|
139
129
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
msgType = 'group';
|
|
148
|
-
author = participant;
|
|
149
|
-
chatId = from;
|
|
130
|
+
msgType = 'group';
|
|
131
|
+
author = participant;
|
|
132
|
+
chatId = from;
|
|
133
|
+
} else if (isJidBroadcast(from)) {
|
|
134
|
+
if (!participant) {
|
|
135
|
+
throw new Boom('No participant in group message');
|
|
150
136
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (isJidStatusBroadcast(from)) {
|
|
157
|
-
msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
|
|
161
|
-
}
|
|
162
|
-
fromMe = isParticipantMe;
|
|
163
|
-
chatId = from;
|
|
164
|
-
author = participant;
|
|
137
|
+
const isParticipantMe = isMe(participant);
|
|
138
|
+
if (isJidStatusBroadcast(from)) {
|
|
139
|
+
msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
|
|
140
|
+
} else {
|
|
141
|
+
msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
|
|
165
142
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
143
|
+
fromMe = isParticipantMe;
|
|
144
|
+
chatId = from;
|
|
145
|
+
author = participant;
|
|
146
|
+
} else if (isJidNewsletter(from)) {
|
|
147
|
+
msgType = 'newsletter';
|
|
148
|
+
chatId = from;
|
|
149
|
+
author = from;
|
|
150
|
+
if (stanza.attrs.is_sender) {
|
|
151
|
+
fromMe = true;
|
|
173
152
|
}
|
|
174
|
-
|
|
175
|
-
|
|
153
|
+
if (isMe(from) || isMeLid(from)) {
|
|
154
|
+
fromMe = true;
|
|
176
155
|
}
|
|
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
|
-
|
|
156
|
+
} else {
|
|
157
|
+
throw new Boom('Unknown message type', {
|
|
158
|
+
data: stanza
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const pushname = stanza?.attrs?.notify;
|
|
162
|
+
const key = {
|
|
163
|
+
remoteJid: chatId,
|
|
164
|
+
remoteJidAlt: !isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
|
|
165
|
+
remoteJidUsername: !isJidGroup(chatId) ? stanza.attrs.peer_recipient_username || stanza.attrs.recipient_username : undefined,
|
|
166
|
+
fromMe,
|
|
167
|
+
id: msgId,
|
|
168
|
+
participant,
|
|
169
|
+
participantAlt: isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
|
|
170
|
+
participantUsername: stanza.attrs.participant ? stanza.attrs.participant_username : undefined,
|
|
171
|
+
addressingMode: addressingContext.addressingMode,
|
|
172
|
+
...(msgType === 'newsletter' && stanza.attrs.server_id ? {
|
|
173
|
+
server_id: stanza.attrs.server_id
|
|
174
|
+
} : {})
|
|
175
|
+
};
|
|
176
|
+
const fullMessage = {
|
|
177
|
+
key,
|
|
178
|
+
category: stanza.attrs.category,
|
|
179
|
+
messageTimestamp: +stanza.attrs.t,
|
|
180
|
+
pushName: pushname,
|
|
181
|
+
broadcast: isJidBroadcast(from)
|
|
182
|
+
};
|
|
183
|
+
if (key.fromMe) {
|
|
184
|
+
fullMessage.status = proto.WebMessageInfo.Status.SERVER_ACK;
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
fullMessage,
|
|
188
|
+
author,
|
|
189
|
+
sender: msgType === 'chat' ? author : chatId
|
|
190
|
+
};
|
|
207
191
|
}
|
|
208
192
|
export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
fullMessage.message = msg;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
catch (err) {
|
|
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()];
|
|
299
|
-
}
|
|
300
|
-
}
|
|
193
|
+
const {
|
|
194
|
+
fullMessage,
|
|
195
|
+
author,
|
|
196
|
+
sender
|
|
197
|
+
} = decodeMessageNode(stanza, meId, meLid);
|
|
198
|
+
return {
|
|
199
|
+
fullMessage,
|
|
200
|
+
category: stanza.attrs.category,
|
|
201
|
+
author,
|
|
202
|
+
async decrypt() {
|
|
203
|
+
let decryptables = 0;
|
|
204
|
+
if (Array.isArray(stanza.content)) {
|
|
205
|
+
for (const {
|
|
206
|
+
tag,
|
|
207
|
+
attrs,
|
|
208
|
+
content
|
|
209
|
+
} of stanza.content) {
|
|
210
|
+
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
211
|
+
const cert = proto.VerifiedNameCertificate.decode(content);
|
|
212
|
+
const details = proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
213
|
+
fullMessage.verifiedBizName = details.verifiedName;
|
|
214
|
+
}
|
|
215
|
+
if (tag === 'unavailable' && attrs.type === 'view_once') {
|
|
216
|
+
fullMessage.key.isViewOnce = true;
|
|
217
|
+
}
|
|
218
|
+
if (attrs.count && tag === 'enc') {
|
|
219
|
+
fullMessage.retryCount = Number(attrs.count);
|
|
220
|
+
}
|
|
221
|
+
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (!(content instanceof Uint8Array)) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
decryptables += 1;
|
|
228
|
+
let msgBuffer;
|
|
229
|
+
const decryptionJid = await getDecryptionJid(author, repository);
|
|
230
|
+
if (tag !== 'plaintext') {
|
|
231
|
+
await storeMappingFromEnvelope(stanza, author, repository, decryptionJid, logger);
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type;
|
|
235
|
+
switch (e2eType) {
|
|
236
|
+
case 'skmsg':
|
|
237
|
+
msgBuffer = await repository.decryptGroupMessage({
|
|
238
|
+
group: sender,
|
|
239
|
+
authorJid: author,
|
|
240
|
+
msg: content
|
|
241
|
+
});
|
|
242
|
+
break;
|
|
243
|
+
case 'pkmsg':
|
|
244
|
+
case 'msg':
|
|
245
|
+
msgBuffer = await repository.decryptMessage({
|
|
246
|
+
jid: decryptionJid,
|
|
247
|
+
type: e2eType,
|
|
248
|
+
ciphertext: content
|
|
249
|
+
});
|
|
250
|
+
break;
|
|
251
|
+
case 'plaintext':
|
|
252
|
+
msgBuffer = content;
|
|
253
|
+
break;
|
|
254
|
+
default:
|
|
255
|
+
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
256
|
+
}
|
|
257
|
+
if (!msgBuffer) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const msgToDecode = e2eType !== 'plaintext' ? unpadRandomMax16(msgBuffer) : msgBuffer;
|
|
261
|
+
let msg = proto.Message.decode(msgToDecode);
|
|
262
|
+
const outerMessageContextInfo = msg.messageContextInfo;
|
|
263
|
+
msg = msg.deviceSentMessage?.message || msg;
|
|
264
|
+
if (outerMessageContextInfo && !msg.messageContextInfo) {
|
|
265
|
+
msg.messageContextInfo = outerMessageContextInfo;
|
|
301
266
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
267
|
+
if (msg.senderKeyDistributionMessage) {
|
|
268
|
+
try {
|
|
269
|
+
await repository.processSenderKeyDistributionMessage({
|
|
270
|
+
authorJid: author,
|
|
271
|
+
item: msg.senderKeyDistributionMessage
|
|
272
|
+
});
|
|
273
|
+
} catch (err) {
|
|
274
|
+
logger.error({
|
|
275
|
+
key: fullMessage.key,
|
|
276
|
+
err
|
|
277
|
+
}, 'failed to process sender key distribution message');
|
|
278
|
+
}
|
|
306
279
|
}
|
|
280
|
+
if (fullMessage.message) {
|
|
281
|
+
Object.assign(fullMessage.message, msg);
|
|
282
|
+
} else {
|
|
283
|
+
fullMessage.message = msg;
|
|
284
|
+
}
|
|
285
|
+
} catch (err) {
|
|
286
|
+
const errorContext = {
|
|
287
|
+
key: fullMessage.key,
|
|
288
|
+
err,
|
|
289
|
+
messageType: tag === 'plaintext' ? 'plaintext' : attrs.type,
|
|
290
|
+
sender,
|
|
291
|
+
author,
|
|
292
|
+
isSessionRecordError: isSessionRecordError(err)
|
|
293
|
+
};
|
|
294
|
+
logger.error(errorContext, 'failed to decrypt message');
|
|
295
|
+
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
296
|
+
fullMessage.messageStubParameters = [err.message.toString()];
|
|
297
|
+
}
|
|
307
298
|
}
|
|
308
|
-
|
|
299
|
+
}
|
|
300
|
+
if (!decryptables && !fullMessage.key?.isViewOnce) {
|
|
301
|
+
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
302
|
+
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
309
306
|
};
|
|
310
|
-
/**
|
|
311
|
-
* Utility function to check if an error is related to missing session record
|
|
312
|
-
*/
|
|
313
307
|
function isSessionRecordError(error) {
|
|
314
|
-
|
|
315
|
-
|
|
308
|
+
const errorMessage = error?.message || error?.toString() || '';
|
|
309
|
+
return DECRYPTION_RETRY_CONFIG.sessionRecordErrors.some(errorPattern => errorMessage.includes(errorPattern));
|
|
316
310
|
}
|
|
317
|
-
//# sourceMappingURL=decode-wa-message.js.map
|