supunmd-bail 2.0.2 → 2.1.3
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/LICENSE +1 -1
- package/README.md +2 -2
- package/WAProto/index.js +130529 -45236
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +9 -18
- package/lib/Defaults/index.js +136 -104
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
- package/lib/Signal/Group/ciphertext-message.js +5 -2
- package/lib/Signal/Group/group-session-builder.d.ts +3 -4
- package/lib/Signal/Group/group-session-builder.js +41 -7
- package/lib/Signal/Group/group_cipher.d.ts +4 -4
- package/lib/Signal/Group/group_cipher.js +51 -37
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +57 -12
- package/lib/Signal/Group/keyhelper.d.ts +1 -2
- package/lib/Signal/Group/keyhelper.js +44 -7
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +5 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +2 -3
- package/lib/Signal/Group/sender-chain-key.js +15 -7
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
- package/lib/Signal/Group/sender-key-message.d.ts +1 -2
- package/lib/Signal/Group/sender-key-message.js +12 -9
- package/lib/Signal/Group/sender-key-name.d.ts +0 -1
- package/lib/Signal/Group/sender-key-name.js +5 -2
- package/lib/Signal/Group/sender-key-record.d.ts +2 -3
- package/lib/Signal/Group/sender-key-record.js +21 -9
- package/lib/Signal/Group/sender-key-state.d.ts +6 -7
- package/lib/Signal/Group/sender-key-state.js +42 -27
- package/lib/Signal/Group/sender-message-key.d.ts +0 -1
- package/lib/Signal/Group/sender-message-key.js +7 -4
- package/lib/Signal/libsignal.d.ts +3 -5
- package/lib/Signal/libsignal.js +90 -258
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -2
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +108 -125
- package/lib/Socket/business.js +43 -159
- package/lib/Socket/chats.d.ts +239 -70
- package/lib/Socket/chats.js +384 -363
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +56 -78
- package/lib/Socket/groups.js +96 -106
- package/lib/Socket/index.d.ts +115 -173
- package/lib/Socket/index.js +10 -17
- package/lib/Socket/messages-recv.d.ts +79 -91
- package/lib/Socket/messages-recv.js +521 -639
- package/lib/Socket/messages-send.d.ts +91 -111
- package/lib/Socket/messages-send.js +438 -599
- package/lib/Socket/newsletter.d.ts +84 -97
- package/lib/Socket/newsletter.js +1 -181
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +18 -26
- package/lib/Socket/socket.js +230 -448
- package/lib/Socket/usync.d.ts +16 -17
- package/lib/Socket/usync.js +26 -19
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +427 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +12 -13
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +1 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +13 -34
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.d.ts +1 -6
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +15 -60
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +5 -17
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -12
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +54 -84
- package/lib/Types/Message.js +9 -11
- package/lib/Types/Newsletter.d.ts +98 -130
- package/lib/Types/Newsletter.js +38 -31
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +1 -20
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +25 -47
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -14
- package/lib/Types/State.js +2 -13
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +14 -22
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +6 -7
- package/lib/Utils/auth-utils.js +148 -199
- package/lib/Utils/baileys-event-stream.d.ts +1 -2
- package/lib/Utils/baileys-event-stream.js +22 -15
- package/lib/Utils/business.d.ts +2 -3
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/chat-utils.d.ts +22 -21
- package/lib/Utils/chat-utils.js +226 -260
- package/lib/Utils/crypto.d.ts +19 -19
- package/lib/Utils/crypto.js +86 -77
- package/lib/Utils/decode-wa-message.d.ts +8 -37
- package/lib/Utils/decode-wa-message.js +83 -164
- package/lib/Utils/event-buffer.d.ts +8 -7
- package/lib/Utils/event-buffer.js +76 -110
- package/lib/Utils/generics.d.ts +29 -27
- package/lib/Utils/generics.js +210 -168
- package/lib/Utils/history.d.ts +8 -12
- package/lib/Utils/history.js +46 -34
- package/lib/Utils/index.d.ts +17 -20
- package/lib/Utils/index.js +33 -20
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +22 -14
- package/lib/Utils/logger.d.ts +3 -11
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +8 -9
- package/lib/Utils/lt-hash.js +28 -25
- package/lib/Utils/make-mutex.d.ts +2 -3
- package/lib/Utils/make-mutex.js +10 -7
- package/lib/Utils/messages-media.d.ts +44 -42
- package/lib/Utils/messages-media.js +475 -319
- package/lib/Utils/messages.d.ts +18 -17
- package/lib/Utils/messages.js +259 -383
- package/lib/Utils/noise-handler.d.ts +15 -14
- package/lib/Utils/noise-handler.js +38 -30
- package/lib/Utils/process-message.d.ts +13 -14
- package/lib/Utils/process-message.js +147 -239
- package/lib/Utils/signal.d.ts +5 -7
- package/lib/Utils/signal.js +72 -78
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +27 -29
- package/lib/Utils/validate-connection.d.ts +7 -7
- package/lib/Utils/validate-connection.js +106 -72
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.d.ts +5 -5
- package/lib/WABinary/decode.js +42 -28
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +154 -105
- package/lib/WABinary/generic-utils.d.ts +7 -5
- package/lib/WABinary/generic-utils.js +63 -56
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +8 -25
- package/lib/WABinary/jid-utils.js +40 -74
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +11 -3
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +3 -5
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.d.ts +4 -5
- package/lib/WAUSync/Protocols/index.js +20 -5
- package/lib/WAUSync/USyncQuery.d.ts +4 -5
- package/lib/WAUSync/USyncQuery.js +35 -40
- package/lib/WAUSync/USyncUser.d.ts +5 -6
- package/lib/WAUSync/USyncUser.js +5 -2
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.d.ts +9 -19
- package/lib/index.js +1 -36
- package/package.json +109 -103
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -5519
- package/WAProto/fix-imports.js +0 -29
- package/WAProto/index.d.ts +0 -11969
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.js +0 -171
- package/lib/Socket/Client/types.js +0 -11
- package/lib/Socket/Client/websocket.js +0 -50
- package/lib/Socket/communities.d.ts +0 -244
- package/lib/Socket/communities.js +0 -431
- package/lib/Socket/mex.d.ts +0 -3
- package/lib/Socket/mex.js +0 -42
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.js +0 -2
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.js +0 -28
- package/lib/Utils/message-retry-manager.d.ts +0 -82
- package/lib/Utils/message-retry-manager.js +0 -149
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/pre-key-manager.js +0 -106
- /package/lib/{supun → supunmd} +0 -0
|
@@ -1,103 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
// Retry configuration for failed decryption
|
|
31
|
-
export const DECRYPTION_RETRY_CONFIG = {
|
|
32
|
-
maxRetries: 3,
|
|
33
|
-
baseDelayMs: 100,
|
|
34
|
-
sessionRecordErrors: ['No session record', 'SessionError: No session record']
|
|
35
|
-
};
|
|
36
|
-
export const NACK_REASONS = {
|
|
37
|
-
ParsingError: 487,
|
|
38
|
-
UnrecognizedStanza: 488,
|
|
39
|
-
UnrecognizedStanzaClass: 489,
|
|
40
|
-
UnrecognizedStanzaType: 490,
|
|
41
|
-
InvalidProtobuf: 491,
|
|
42
|
-
InvalidHostedCompanionStanza: 493,
|
|
43
|
-
MissingMessageSecret: 495,
|
|
44
|
-
SignalErrorOldCounter: 496,
|
|
45
|
-
MessageDeletedOnPeer: 499,
|
|
46
|
-
UnhandledError: 500,
|
|
47
|
-
UnsupportedAdminRevoke: 550,
|
|
48
|
-
UnsupportedLIDGroup: 551,
|
|
49
|
-
DBOperationFailed: 552
|
|
50
|
-
};
|
|
51
|
-
export const extractAddressingContext = (stanza) => {
|
|
52
|
-
let senderAlt;
|
|
53
|
-
let recipientAlt;
|
|
54
|
-
const sender = stanza.attrs.participant || stanza.attrs.from;
|
|
55
|
-
const addressingMode = stanza.attrs.addressing_mode || (sender?.endsWith('lid') ? 'lid' : 'pn');
|
|
56
|
-
if (addressingMode === 'lid') {
|
|
57
|
-
// Message is LID-addressed: sender is LID, extract corresponding PN
|
|
58
|
-
// without device data
|
|
59
|
-
senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn;
|
|
60
|
-
recipientAlt = stanza.attrs.recipient_pn;
|
|
61
|
-
// with device data
|
|
62
|
-
//if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt)
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
// Message is PN-addressed: sender is PN, extract corresponding LID
|
|
66
|
-
// without device data
|
|
67
|
-
senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid;
|
|
68
|
-
recipientAlt = stanza.attrs.recipient_lid;
|
|
69
|
-
//with device data
|
|
70
|
-
//if (sender && senderAlt) senderAlt = transferDevice(sender, senderAlt)
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
addressingMode,
|
|
74
|
-
senderAlt,
|
|
75
|
-
recipientAlt
|
|
76
|
-
};
|
|
77
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decryptMessageNode = exports.decodeMessageNode = void 0;
|
|
4
|
+
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const WAProto_1 = require("../../WAProto");
|
|
6
|
+
const WABinary_1 = require("../WABinary");
|
|
7
|
+
const generics_1 = require("./generics");
|
|
8
|
+
const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
78
9
|
/**
|
|
79
10
|
* Decode the received node as a message.
|
|
80
11
|
* @note this will only parse the message, not decrypt it
|
|
81
12
|
*/
|
|
82
|
-
|
|
13
|
+
function decodeMessageNode(stanza, meId, meLid) {
|
|
14
|
+
var _a, _b;
|
|
83
15
|
let msgType;
|
|
84
16
|
let chatId;
|
|
85
17
|
let author;
|
|
86
|
-
let fromMe = false;
|
|
87
18
|
const msgId = stanza.attrs.id;
|
|
88
19
|
const from = stanza.attrs.from;
|
|
89
20
|
const participant = stanza.attrs.participant;
|
|
90
21
|
const recipient = stanza.attrs.recipient;
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
throw new Boom('receipient present, but msg not from me', { data: stanza });
|
|
22
|
+
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
|
23
|
+
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
24
|
+
if ((0, WABinary_1.isJidUser)(from)) {
|
|
25
|
+
if (recipient) {
|
|
26
|
+
if (!isMe(from)) {
|
|
27
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
98
28
|
}
|
|
99
|
-
|
|
100
|
-
|
|
29
|
+
chatId = recipient;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
chatId = from;
|
|
33
|
+
}
|
|
34
|
+
msgType = 'chat';
|
|
35
|
+
author = from;
|
|
36
|
+
}
|
|
37
|
+
else if ((0, WABinary_1.isLidUser)(from)) {
|
|
38
|
+
if (recipient) {
|
|
39
|
+
if (!isMeLid(from)) {
|
|
40
|
+
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
101
41
|
}
|
|
102
42
|
chatId = recipient;
|
|
103
43
|
}
|
|
@@ -107,62 +47,55 @@ export function decodeMessageNode(stanza, meId, meLid) {
|
|
|
107
47
|
msgType = 'chat';
|
|
108
48
|
author = from;
|
|
109
49
|
}
|
|
110
|
-
else if (isJidGroup(from)) {
|
|
50
|
+
else if ((0, WABinary_1.isJidGroup)(from)) {
|
|
111
51
|
if (!participant) {
|
|
112
|
-
throw new Boom('No participant in group message');
|
|
113
|
-
}
|
|
114
|
-
if (isMe(participant) || isMeLid(participant)) {
|
|
115
|
-
fromMe = true;
|
|
52
|
+
throw new boom_1.Boom('No participant in group message');
|
|
116
53
|
}
|
|
117
54
|
msgType = 'group';
|
|
118
55
|
author = participant;
|
|
119
56
|
chatId = from;
|
|
120
57
|
}
|
|
121
|
-
else if (isJidBroadcast(from)) {
|
|
58
|
+
else if ((0, WABinary_1.isJidBroadcast)(from)) {
|
|
122
59
|
if (!participant) {
|
|
123
|
-
throw new Boom('No participant in group message');
|
|
60
|
+
throw new boom_1.Boom('No participant in group message');
|
|
124
61
|
}
|
|
125
62
|
const isParticipantMe = isMe(participant);
|
|
126
|
-
if (isJidStatusBroadcast(from)) {
|
|
63
|
+
if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
|
|
127
64
|
msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
|
|
128
65
|
}
|
|
129
66
|
else {
|
|
130
67
|
msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
|
|
131
68
|
}
|
|
132
|
-
fromMe = isParticipantMe;
|
|
133
69
|
chatId = from;
|
|
134
70
|
author = participant;
|
|
135
71
|
}
|
|
136
|
-
else if (
|
|
72
|
+
else if ((0, WABinary_1.isJidNewsLetter)(from)) {
|
|
137
73
|
msgType = 'newsletter';
|
|
138
|
-
chatId = from;
|
|
139
74
|
author = from;
|
|
140
|
-
|
|
141
|
-
fromMe = true;
|
|
142
|
-
}
|
|
75
|
+
chatId = from;
|
|
143
76
|
}
|
|
144
77
|
else {
|
|
145
|
-
throw new Boom('Unknown message type', { data: stanza });
|
|
78
|
+
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
146
79
|
}
|
|
147
|
-
const
|
|
80
|
+
const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
|
81
|
+
const pushname = stanza.attrs.notify;
|
|
148
82
|
const key = {
|
|
149
83
|
remoteJid: chatId,
|
|
150
|
-
remoteJidAlt: !isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
|
|
151
84
|
fromMe,
|
|
152
85
|
id: msgId,
|
|
153
|
-
participant
|
|
154
|
-
participantAlt: isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
|
|
155
|
-
addressingMode: addressingContext.addressingMode,
|
|
156
|
-
...(msgType === 'newsletter' && stanza.attrs.server_id ? { server_id: stanza.attrs.server_id } : {})
|
|
86
|
+
participant
|
|
157
87
|
};
|
|
158
88
|
const fullMessage = {
|
|
159
89
|
key,
|
|
160
90
|
messageTimestamp: +stanza.attrs.t,
|
|
161
91
|
pushName: pushname,
|
|
162
|
-
broadcast: isJidBroadcast(from)
|
|
92
|
+
broadcast: (0, WABinary_1.isJidBroadcast)(from)
|
|
163
93
|
};
|
|
94
|
+
if (msgType === 'newsletter') {
|
|
95
|
+
fullMessage.newsletterServerId = +((_b = stanza.attrs) === null || _b === void 0 ? void 0 : _b.server_id);
|
|
96
|
+
}
|
|
164
97
|
if (key.fromMe) {
|
|
165
|
-
fullMessage.status = proto.WebMessageInfo.Status.SERVER_ACK;
|
|
98
|
+
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
|
|
166
99
|
}
|
|
167
100
|
return {
|
|
168
101
|
fullMessage,
|
|
@@ -170,25 +103,44 @@ export function decodeMessageNode(stanza, meId, meLid) {
|
|
|
170
103
|
sender: msgType === 'chat' ? author : chatId
|
|
171
104
|
};
|
|
172
105
|
}
|
|
173
|
-
|
|
106
|
+
exports.decodeMessageNode = decodeMessageNode;
|
|
107
|
+
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
174
108
|
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
|
175
109
|
return {
|
|
176
110
|
fullMessage,
|
|
177
111
|
category: stanza.attrs.category,
|
|
178
112
|
author,
|
|
179
113
|
async decrypt() {
|
|
114
|
+
var _a;
|
|
180
115
|
let decryptables = 0;
|
|
181
|
-
|
|
116
|
+
async function processSenderKeyDistribution(msg) {
|
|
117
|
+
if (msg.senderKeyDistributionMessage) {
|
|
118
|
+
try {
|
|
119
|
+
await repository.processSenderKeyDistributionMessage({
|
|
120
|
+
authorJid: author,
|
|
121
|
+
item: msg.senderKeyDistributionMessage
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
|
|
130
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
|
131
|
+
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
|
132
|
+
await processSenderKeyDistribution(msg);
|
|
133
|
+
fullMessage.message = msg;
|
|
134
|
+
decryptables += 1;
|
|
135
|
+
}
|
|
136
|
+
else if (Array.isArray(stanza.content)) {
|
|
182
137
|
for (const { tag, attrs, content } of stanza.content) {
|
|
183
138
|
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
184
|
-
const cert = proto.VerifiedNameCertificate.decode(content);
|
|
185
|
-
const details = proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
139
|
+
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
|
|
140
|
+
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
186
141
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
187
142
|
}
|
|
188
|
-
if (tag
|
|
189
|
-
fullMessage.key.isViewOnce = true; // TODO: remove from here and add a STUB TYPE
|
|
190
|
-
}
|
|
191
|
-
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
143
|
+
if (tag !== 'enc') {
|
|
192
144
|
continue;
|
|
193
145
|
}
|
|
194
146
|
if (!(content instanceof Uint8Array)) {
|
|
@@ -196,13 +148,8 @@ export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
196
148
|
}
|
|
197
149
|
decryptables += 1;
|
|
198
150
|
let msgBuffer;
|
|
199
|
-
const decryptionJid = await getDecryptionJid(author, repository);
|
|
200
|
-
if (tag !== 'plaintext') {
|
|
201
|
-
// TODO: Handle hosted devices
|
|
202
|
-
await storeMappingFromEnvelope(stanza, author, repository, decryptionJid, logger);
|
|
203
|
-
}
|
|
204
151
|
try {
|
|
205
|
-
const e2eType =
|
|
152
|
+
const e2eType = attrs.type;
|
|
206
153
|
switch (e2eType) {
|
|
207
154
|
case 'skmsg':
|
|
208
155
|
msgBuffer = await repository.decryptGroupMessage({
|
|
@@ -213,32 +160,19 @@ export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
213
160
|
break;
|
|
214
161
|
case 'pkmsg':
|
|
215
162
|
case 'msg':
|
|
163
|
+
const user = (0, WABinary_1.isJidUser)(sender) ? sender : author;
|
|
216
164
|
msgBuffer = await repository.decryptMessage({
|
|
217
|
-
jid:
|
|
165
|
+
jid: user,
|
|
218
166
|
type: e2eType,
|
|
219
167
|
ciphertext: content
|
|
220
168
|
});
|
|
221
169
|
break;
|
|
222
|
-
case 'plaintext':
|
|
223
|
-
msgBuffer = content;
|
|
224
|
-
break;
|
|
225
170
|
default:
|
|
226
171
|
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
227
172
|
}
|
|
228
|
-
let msg = proto.Message.decode(
|
|
229
|
-
msg = msg.deviceSentMessage
|
|
230
|
-
|
|
231
|
-
//eslint-disable-next-line max-depth
|
|
232
|
-
try {
|
|
233
|
-
await repository.processSenderKeyDistributionMessage({
|
|
234
|
-
authorJid: author,
|
|
235
|
-
item: msg.senderKeyDistributionMessage
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
catch (err) {
|
|
239
|
-
logger.error({ key: fullMessage.key, err }, 'failed to process sender key distribution message');
|
|
240
|
-
}
|
|
241
|
-
}
|
|
173
|
+
let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
|
|
174
|
+
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
175
|
+
await processSenderKeyDistribution(msg);
|
|
242
176
|
if (fullMessage.message) {
|
|
243
177
|
Object.assign(fullMessage.message, msg);
|
|
244
178
|
}
|
|
@@ -247,33 +181,18 @@ export const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
247
181
|
}
|
|
248
182
|
}
|
|
249
183
|
catch (err) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
messageType: tag === 'plaintext' ? 'plaintext' : attrs.type,
|
|
254
|
-
sender,
|
|
255
|
-
author,
|
|
256
|
-
isSessionRecordError: isSessionRecordError(err)
|
|
257
|
-
};
|
|
258
|
-
logger.error(errorContext, 'failed to decrypt message');
|
|
259
|
-
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
260
|
-
fullMessage.messageStubParameters = [err.message.toString()];
|
|
184
|
+
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
185
|
+
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
186
|
+
fullMessage.messageStubParameters = [err.message];
|
|
261
187
|
}
|
|
262
188
|
}
|
|
263
189
|
}
|
|
264
190
|
// if nothing was found to decrypt
|
|
265
191
|
if (!decryptables) {
|
|
266
|
-
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
267
|
-
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT];
|
|
192
|
+
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
193
|
+
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
|
|
268
194
|
}
|
|
269
195
|
}
|
|
270
196
|
};
|
|
271
197
|
};
|
|
272
|
-
|
|
273
|
-
* Utility function to check if an error is related to missing session record
|
|
274
|
-
*/
|
|
275
|
-
function isSessionRecordError(error) {
|
|
276
|
-
const errorMessage = error?.message || error?.toString() || '';
|
|
277
|
-
return DECRYPTION_RETRY_CONFIG.sessionRecordErrors.some(errorPattern => errorMessage.includes(errorPattern));
|
|
278
|
-
}
|
|
279
|
-
//# sourceMappingURL=decode-wa-message.js.map
|
|
198
|
+
exports.decryptMessageNode = decryptMessageNode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Logger } from 'pino';
|
|
2
|
+
import { BaileysEventEmitter, BaileysEventMap } from '../Types';
|
|
3
3
|
/**
|
|
4
4
|
* A map that contains a list of all events that have been triggered
|
|
5
5
|
*
|
|
@@ -10,25 +10,26 @@ import type { ILogger } from './logger.js';
|
|
|
10
10
|
type BaileysEventData = Partial<BaileysEventMap>;
|
|
11
11
|
type BaileysBufferableEventEmitter = BaileysEventEmitter & {
|
|
12
12
|
/** Use to process events in a batch */
|
|
13
|
-
process(handler: (events: BaileysEventData) => void | Promise<void>): () => void;
|
|
13
|
+
process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void);
|
|
14
14
|
/**
|
|
15
15
|
* starts buffering events, call flush() to release them
|
|
16
16
|
* */
|
|
17
17
|
buffer(): void;
|
|
18
18
|
/** buffers all events till the promise completes */
|
|
19
|
-
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T
|
|
19
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
20
20
|
/**
|
|
21
21
|
* flushes all buffered events
|
|
22
|
+
* @param force if true, will flush all data regardless of any pending buffers
|
|
22
23
|
* @returns returns true if the flush actually happened, otherwise false
|
|
23
24
|
*/
|
|
24
|
-
flush(): boolean;
|
|
25
|
+
flush(force?: boolean): boolean;
|
|
25
26
|
/** is there an ongoing buffer */
|
|
26
27
|
isBuffering(): boolean;
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
30
|
* The event buffer logically consolidates different events into a single event
|
|
30
31
|
* making the data processing more efficient.
|
|
32
|
+
* @param ev the baileys event emitter
|
|
31
33
|
*/
|
|
32
|
-
export declare const makeEventBuffer: (logger:
|
|
34
|
+
export declare const makeEventBuffer: (logger: Logger) => BaileysBufferableEventEmitter;
|
|
33
35
|
export {};
|
|
34
|
-
//# sourceMappingURL=event-buffer.d.ts.map
|