@vinzsocket/baileys 2.8.30 → 3.0.0
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/fix-imports.js +7 -16
- package/WAProto/index.js +1 -37306
- package/lib/Defaults/index.js +37 -33
- package/lib/Signal/Group/ciphertext-message.js +6 -2
- package/lib/Signal/Group/group-session-builder.js +12 -7
- package/lib/Signal/Group/group_cipher.js +18 -13
- package/lib/Signal/Group/index.js +77 -12
- package/lib/Signal/Group/keyhelper.js +15 -8
- package/lib/Signal/Group/queue-job.js +7 -2
- package/lib/Signal/Group/sender-chain-key.js +11 -6
- package/lib/Signal/Group/sender-key-distribution-message.js +10 -6
- package/lib/Signal/Group/sender-key-message.js +14 -9
- package/lib/Signal/Group/sender-key-name.js +6 -2
- package/lib/Signal/Group/sender-key-record.js +13 -9
- package/lib/Signal/Group/sender-key-state.js +10 -6
- package/lib/Signal/Group/sender-message-key.js +9 -4
- package/lib/Signal/libsignal.js +34 -28
- package/lib/Signal/lid-mapping.js +24 -19
- package/lib/Socket/Client/index.js +25 -3
- package/lib/Socket/Client/types.js +8 -4
- package/lib/Socket/Client/websocket.js +16 -11
- package/lib/Socket/business.js +38 -34
- package/lib/Socket/chats.js +100 -95
- package/lib/Socket/communities.js +55 -49
- package/lib/Socket/groups.js +56 -51
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.js +150 -145
- package/lib/Socket/messages-send.js +109 -104
- package/lib/Socket/mex.js +12 -8
- package/lib/Socket/newsletter.js +27 -23
- package/lib/Socket/socket.js +111 -107
- package/lib/Store/index.js +47 -4
- package/lib/Store/make-cache-manager-store.js +17 -11
- package/lib/Store/make-in-memory-store.js +31 -29
- package/lib/Store/make-ordered-dictionary.js +7 -2
- package/lib/Store/object-repository.js +7 -2
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.js +5 -2
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.js +1 -2
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.js +6 -3
- package/lib/Types/LabelAssociation.js +6 -3
- package/lib/Types/Message.js +16 -7
- package/lib/Types/Newsletter.js +8 -5
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.js +1 -2
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +7 -4
- package/lib/Types/USync.js +1 -2
- package/lib/Types/index.js +153 -15
- package/lib/Utils/auth-utils.js +32 -25
- package/lib/Utils/baileys-event-stream.js +21 -15
- package/lib/Utils/business.js +71 -61
- package/lib/Utils/chat-utils.js +91 -77
- package/lib/Utils/crypto.js +54 -32
- package/lib/Utils/decode-wa-message.js +46 -39
- package/lib/Utils/event-buffer.js +24 -19
- package/lib/Utils/extended-messages.js +14 -9
- package/lib/Utils/generics.js +100 -64
- package/lib/Utils/history.js +30 -23
- package/lib/Utils/index.js +234 -22
- package/lib/Utils/lid-resolver.js +12 -5
- package/lib/Utils/link-preview.js +11 -7
- package/lib/Utils/logger.js +8 -4
- package/lib/Utils/lt-hash.js +8 -5
- package/lib/Utils/make-mutex.js +8 -3
- package/lib/Utils/mention.js +12 -4
- package/lib/Utils/message-retry-manager.js +10 -6
- package/lib/Utils/messages-media.js +127 -95
- package/lib/Utils/messages.js +122 -98
- package/lib/Utils/noise-handler.js +25 -21
- package/lib/Utils/process-message.js +72 -63
- package/lib/Utils/signal.js +45 -33
- package/lib/Utils/use-multi-file-auth-state.js +24 -20
- package/lib/Utils/validate-connection.js +54 -47
- package/lib/WABinary/constants.js +9 -6
- package/lib/WABinary/decode.js +17 -10
- package/lib/WABinary/encode.js +11 -6
- package/lib/WABinary/generic-utils.js +31 -17
- package/lib/WABinary/index.js +58 -6
- package/lib/WABinary/jid-utils.js +36 -20
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +6 -2
- package/lib/WAM/constants.js +1 -1
- package/lib/WAM/encode.js +16 -12
- package/lib/WAM/index.js +36 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +9 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -6
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +8 -4
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +9 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +23 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -2
- package/lib/WAUSync/Protocols/index.js +58 -6
- package/lib/WAUSync/USyncQuery.js +21 -17
- package/lib/WAUSync/USyncUser.js +6 -2
- package/lib/WAUSync/index.js +36 -4
- package/lib/index.js +112 -12
- package/package.json +8 -6
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", {
|
|
2
|
+
value: true
|
|
3
|
+
});
|
|
4
|
+
exports.makeMessagesRecvSocket = void 0;
|
|
5
|
+
var _nodeCache = _interopRequireDefault(require("@cacheable/node-cache"));
|
|
6
|
+
var _boom = require("@hapi/boom");
|
|
7
|
+
var _crypto = require("crypto");
|
|
8
|
+
var _long = _interopRequireDefault(require("long"));
|
|
9
|
+
var _index = require("../../WAProto/index.js");
|
|
10
|
+
var _index2 = require("../Defaults/index.js");
|
|
11
|
+
var _index3 = require("../Types/index.js");
|
|
12
|
+
var _index4 = require("../Utils/index.js");
|
|
13
|
+
var _makeMutex = require("../Utils/make-mutex.js");
|
|
14
|
+
var _index5 = require("../WABinary/index.js");
|
|
15
|
+
var _groups = require("./groups.js");
|
|
16
|
+
var _messagesSend = require("./messages-send.js");
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
const makeMessagesRecvSocket = config => {
|
|
14
19
|
const {
|
|
15
20
|
logger,
|
|
16
21
|
retryRequestDelayMs,
|
|
@@ -19,7 +24,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
19
24
|
shouldIgnoreJid,
|
|
20
25
|
enableAutoSessionRecreation
|
|
21
26
|
} = config;
|
|
22
|
-
const sock = makeMessagesSocket(config);
|
|
27
|
+
const sock = (0, _messagesSend.makeMessagesSocket)(config);
|
|
23
28
|
const {
|
|
24
29
|
ev,
|
|
25
30
|
authState,
|
|
@@ -39,26 +44,26 @@ export const makeMessagesRecvSocket = config => {
|
|
|
39
44
|
messageRetryManager
|
|
40
45
|
} = sock;
|
|
41
46
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
|
42
|
-
const retryMutex = makeMutex();
|
|
43
|
-
const msgRetryCache = config.msgRetryCounterCache || new
|
|
44
|
-
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
47
|
+
const retryMutex = (0, _makeMutex.makeMutex)();
|
|
48
|
+
const msgRetryCache = config.msgRetryCounterCache || new _nodeCache.default({
|
|
49
|
+
stdTTL: _index2.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
45
50
|
// 1 hour
|
|
46
51
|
useClones: false
|
|
47
52
|
});
|
|
48
|
-
const callOfferCache = config.callOfferCache || new
|
|
49
|
-
stdTTL: DEFAULT_CACHE_TTLS.CALL_OFFER,
|
|
53
|
+
const callOfferCache = config.callOfferCache || new _nodeCache.default({
|
|
54
|
+
stdTTL: _index2.DEFAULT_CACHE_TTLS.CALL_OFFER,
|
|
50
55
|
// 5 mins
|
|
51
56
|
useClones: false
|
|
52
57
|
});
|
|
53
|
-
const placeholderResendCache = config.placeholderResendCache || new
|
|
54
|
-
stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
58
|
+
const placeholderResendCache = config.placeholderResendCache || new _nodeCache.default({
|
|
59
|
+
stdTTL: _index2.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
55
60
|
// 1 hour
|
|
56
61
|
useClones: false
|
|
57
62
|
});
|
|
58
63
|
let sendActiveReceipts = false;
|
|
59
64
|
const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
|
|
60
65
|
if (!authState.creds.me?.id) {
|
|
61
|
-
throw new Boom('Not authenticated');
|
|
66
|
+
throw new _boom.Boom('Not authenticated');
|
|
62
67
|
}
|
|
63
68
|
const pdoMessage = {
|
|
64
69
|
historySyncOnDemandRequest: {
|
|
@@ -68,13 +73,13 @@ export const makeMessagesRecvSocket = config => {
|
|
|
68
73
|
oldestMsgTimestampMs: oldestMsgTimestamp,
|
|
69
74
|
onDemandMsgCount: count
|
|
70
75
|
},
|
|
71
|
-
peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
|
|
76
|
+
peerDataOperationRequestType: _index.proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND
|
|
72
77
|
};
|
|
73
78
|
return sendPeerDataOperationMessage(pdoMessage);
|
|
74
79
|
};
|
|
75
80
|
const requestPlaceholderResend = async messageKey => {
|
|
76
81
|
if (!authState.creds.me?.id) {
|
|
77
|
-
throw new Boom('Not authenticated');
|
|
82
|
+
throw new _boom.Boom('Not authenticated');
|
|
78
83
|
}
|
|
79
84
|
if (placeholderResendCache.get(messageKey?.id)) {
|
|
80
85
|
logger.debug({
|
|
@@ -84,7 +89,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
84
89
|
} else {
|
|
85
90
|
placeholderResendCache.set(messageKey?.id, true);
|
|
86
91
|
}
|
|
87
|
-
await delay(5000);
|
|
92
|
+
await (0, _index4.delay)(5000);
|
|
88
93
|
if (!placeholderResendCache.get(messageKey?.id)) {
|
|
89
94
|
logger.debug({
|
|
90
95
|
messageKey
|
|
@@ -95,7 +100,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
95
100
|
placeholderMessageResendRequest: [{
|
|
96
101
|
messageKey
|
|
97
102
|
}],
|
|
98
|
-
peerDataOperationRequestType: proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
|
|
103
|
+
peerDataOperationRequestType: _index.proto.Message.PeerDataOperationRequestType.PLACEHOLDER_MESSAGE_RESEND
|
|
99
104
|
};
|
|
100
105
|
setTimeout(() => {
|
|
101
106
|
if (placeholderResendCache.get(messageKey?.id)) {
|
|
@@ -109,7 +114,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
109
114
|
};
|
|
110
115
|
// Handles mex newsletter notifications
|
|
111
116
|
const handleMexNewsletterNotification = async node => {
|
|
112
|
-
const mexNode = getBinaryNodeChild(node, 'mex');
|
|
117
|
+
const mexNode = (0, _index5.getBinaryNodeChild)(node, 'mex');
|
|
113
118
|
if (!mexNode?.content) {
|
|
114
119
|
logger.warn({
|
|
115
120
|
node
|
|
@@ -173,7 +178,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
173
178
|
// Handles newsletter notifications
|
|
174
179
|
const handleNewsletterNotification = async node => {
|
|
175
180
|
const from = node.attrs.from;
|
|
176
|
-
const child = getAllBinaryNodeChildren(node)[0];
|
|
181
|
+
const child = (0, _index5.getAllBinaryNodeChildren)(node)[0];
|
|
177
182
|
const author = node.attrs.participant;
|
|
178
183
|
logger.info({
|
|
179
184
|
from,
|
|
@@ -185,7 +190,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
185
190
|
id: from,
|
|
186
191
|
server_id: child.attrs.message_id,
|
|
187
192
|
reaction: {
|
|
188
|
-
code: getBinaryNodeChildString(child, 'reaction'),
|
|
193
|
+
code: (0, _index5.getBinaryNodeChildString)(child, 'reaction'),
|
|
189
194
|
count: 1
|
|
190
195
|
}
|
|
191
196
|
};
|
|
@@ -210,12 +215,12 @@ export const makeMessagesRecvSocket = config => {
|
|
|
210
215
|
ev.emit('newsletter-participants.update', participantUpdate);
|
|
211
216
|
break;
|
|
212
217
|
case 'update':
|
|
213
|
-
const settingsNode = getBinaryNodeChild(child, 'settings');
|
|
218
|
+
const settingsNode = (0, _index5.getBinaryNodeChild)(child, 'settings');
|
|
214
219
|
if (settingsNode) {
|
|
215
220
|
const update = {};
|
|
216
|
-
const nameNode = getBinaryNodeChild(settingsNode, 'name');
|
|
221
|
+
const nameNode = (0, _index5.getBinaryNodeChild)(settingsNode, 'name');
|
|
217
222
|
if (nameNode?.content) update.name = nameNode.content.toString();
|
|
218
|
-
const descriptionNode = getBinaryNodeChild(settingsNode, 'description');
|
|
223
|
+
const descriptionNode = (0, _index5.getBinaryNodeChild)(settingsNode, 'description');
|
|
219
224
|
if (descriptionNode?.content) update.description = descriptionNode.content.toString();
|
|
220
225
|
ev.emit('newsletter-settings.update', {
|
|
221
226
|
id: from,
|
|
@@ -224,12 +229,12 @@ export const makeMessagesRecvSocket = config => {
|
|
|
224
229
|
}
|
|
225
230
|
break;
|
|
226
231
|
case 'message':
|
|
227
|
-
const plaintextNode = getBinaryNodeChild(child, 'plaintext');
|
|
232
|
+
const plaintextNode = (0, _index5.getBinaryNodeChild)(child, 'plaintext');
|
|
228
233
|
if (plaintextNode?.content) {
|
|
229
234
|
try {
|
|
230
235
|
const contentBuf = typeof plaintextNode.content === 'string' ? Buffer.from(plaintextNode.content, 'binary') : Buffer.from(plaintextNode.content);
|
|
231
|
-
const messageProto = proto.Message.decode(contentBuf);
|
|
232
|
-
const fullMessage = proto.WebMessageInfo.create({
|
|
236
|
+
const messageProto = _index.proto.Message.decode(contentBuf);
|
|
237
|
+
const fullMessage = _index.proto.WebMessageInfo.create({
|
|
233
238
|
key: {
|
|
234
239
|
remoteJid: from,
|
|
235
240
|
id: child.attrs.message_id || child.attrs.server_id,
|
|
@@ -276,14 +281,14 @@ export const makeMessagesRecvSocket = config => {
|
|
|
276
281
|
if (!!attrs.recipient) {
|
|
277
282
|
stanza.attrs.recipient = attrs.recipient;
|
|
278
283
|
}
|
|
279
|
-
if (!!attrs.type && (tag !== 'message' || getBinaryNodeChild({
|
|
284
|
+
if (!!attrs.type && (tag !== 'message' || (0, _index5.getBinaryNodeChild)({
|
|
280
285
|
tag,
|
|
281
286
|
attrs,
|
|
282
287
|
content
|
|
283
288
|
}, 'unavailable') || errorCode !== 0)) {
|
|
284
289
|
stanza.attrs.type = attrs.type;
|
|
285
290
|
}
|
|
286
|
-
if (tag === 'message' && getBinaryNodeChild({
|
|
291
|
+
if (tag === 'message' && (0, _index5.getBinaryNodeChild)({
|
|
287
292
|
tag,
|
|
288
293
|
attrs,
|
|
289
294
|
content
|
|
@@ -321,7 +326,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
321
326
|
const sendRetryRequest = async (node, forceIncludeKeys = false) => {
|
|
322
327
|
const {
|
|
323
328
|
fullMessage
|
|
324
|
-
} = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '');
|
|
329
|
+
} = (0, _index4.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '');
|
|
325
330
|
const {
|
|
326
331
|
key: msgKey
|
|
327
332
|
} = fullMessage;
|
|
@@ -416,7 +421,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
416
421
|
logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
|
|
417
422
|
}
|
|
418
423
|
}
|
|
419
|
-
const deviceIdentity = encodeSignedDeviceIdentity(account, true);
|
|
424
|
+
const deviceIdentity = (0, _index4.encodeSignedDeviceIdentity)(account, true);
|
|
420
425
|
await authState.keys.transaction(async () => {
|
|
421
426
|
const receipt = {
|
|
422
427
|
tag: 'receipt',
|
|
@@ -436,7 +441,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
436
441
|
}, {
|
|
437
442
|
tag: 'registration',
|
|
438
443
|
attrs: {},
|
|
439
|
-
content: encodeBigEndian(authState.creds.registrationId)
|
|
444
|
+
content: (0, _index4.encodeBigEndian)(authState.creds.registrationId)
|
|
440
445
|
}]
|
|
441
446
|
};
|
|
442
447
|
if (node.attrs.recipient) {
|
|
@@ -449,7 +454,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
449
454
|
const {
|
|
450
455
|
update,
|
|
451
456
|
preKeys
|
|
452
|
-
} = await getNextPreKeys(authState, 1);
|
|
457
|
+
} = await (0, _index4.getNextPreKeys)(authState, 1);
|
|
453
458
|
const [keyId] = Object.keys(preKeys);
|
|
454
459
|
const key = preKeys[+keyId];
|
|
455
460
|
const content = receipt.content;
|
|
@@ -459,12 +464,12 @@ export const makeMessagesRecvSocket = config => {
|
|
|
459
464
|
content: [{
|
|
460
465
|
tag: 'type',
|
|
461
466
|
attrs: {},
|
|
462
|
-
content: Buffer.from(KEY_BUNDLE_TYPE)
|
|
467
|
+
content: Buffer.from(_index2.KEY_BUNDLE_TYPE)
|
|
463
468
|
}, {
|
|
464
469
|
tag: 'identity',
|
|
465
470
|
attrs: {},
|
|
466
471
|
content: identityKey.public
|
|
467
|
-
}, xmppPreKey(key, +keyId), xmppSignedPreKey(signedPreKey), {
|
|
472
|
+
}, (0, _index4.xmppPreKey)(key, +keyId), (0, _index4.xmppSignedPreKey)(signedPreKey), {
|
|
468
473
|
tag: 'device-identity',
|
|
469
474
|
attrs: {},
|
|
470
475
|
content: deviceIdentity
|
|
@@ -481,10 +486,10 @@ export const makeMessagesRecvSocket = config => {
|
|
|
481
486
|
};
|
|
482
487
|
const handleEncryptNotification = async node => {
|
|
483
488
|
const from = node.attrs.from;
|
|
484
|
-
if (from === S_WHATSAPP_NET) {
|
|
485
|
-
const countChild = getBinaryNodeChild(node, 'count');
|
|
489
|
+
if (from === _index5.S_WHATSAPP_NET) {
|
|
490
|
+
const countChild = (0, _index5.getBinaryNodeChild)(node, 'count');
|
|
486
491
|
const count = +countChild.attrs.value;
|
|
487
|
-
const shouldUploadMorePreKeys = count < MIN_PREKEY_COUNT;
|
|
492
|
+
const shouldUploadMorePreKeys = count < _index2.MIN_PREKEY_COUNT;
|
|
488
493
|
logger.debug({
|
|
489
494
|
count,
|
|
490
495
|
shouldUploadMorePreKeys
|
|
@@ -493,7 +498,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
493
498
|
await uploadPreKeys();
|
|
494
499
|
}
|
|
495
500
|
} else {
|
|
496
|
-
const identityNode = getBinaryNodeChild(node, 'identity');
|
|
501
|
+
const identityNode = (0, _index5.getBinaryNodeChild)(node, 'identity');
|
|
497
502
|
if (identityNode) {
|
|
498
503
|
logger.info({
|
|
499
504
|
jid: from
|
|
@@ -508,12 +513,12 @@ export const makeMessagesRecvSocket = config => {
|
|
|
508
513
|
}
|
|
509
514
|
};
|
|
510
515
|
const handleGroupNotification = (participant, child, msg) => {
|
|
511
|
-
const participantJid = getBinaryNodeChild(child, 'participant')?.attrs?.jid || participant;
|
|
516
|
+
const participantJid = (0, _index5.getBinaryNodeChild)(child, 'participant')?.attrs?.jid || participant;
|
|
512
517
|
// TODO: Add participant LID
|
|
513
518
|
switch (child?.tag) {
|
|
514
519
|
case 'create':
|
|
515
|
-
const metadata = extractGroupMetadata(child);
|
|
516
|
-
msg.messageStubType = WAMessageStubType.GROUP_CREATE;
|
|
520
|
+
const metadata = (0, _groups.extractGroupMetadata)(child);
|
|
521
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_CREATE;
|
|
517
522
|
msg.messageStubParameters = [metadata.subject];
|
|
518
523
|
msg.key = {
|
|
519
524
|
participant: metadata.owner
|
|
@@ -532,15 +537,15 @@ export const makeMessagesRecvSocket = config => {
|
|
|
532
537
|
case 'not_ephemeral':
|
|
533
538
|
msg.message = {
|
|
534
539
|
protocolMessage: {
|
|
535
|
-
type: proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
540
|
+
type: _index.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
536
541
|
ephemeralExpiration: +(child.attrs.expiration || 0)
|
|
537
542
|
}
|
|
538
543
|
};
|
|
539
544
|
break;
|
|
540
545
|
case 'modify':
|
|
541
|
-
const oldNumber = getBinaryNodeChildren(child, 'participant').map(p => p.attrs.jid);
|
|
546
|
+
const oldNumber = (0, _index5.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
|
|
542
547
|
msg.messageStubParameters = oldNumber || [];
|
|
543
|
-
msg.messageStubType = WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
|
|
548
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
|
|
544
549
|
break;
|
|
545
550
|
case 'promote':
|
|
546
551
|
case 'demote':
|
|
@@ -548,72 +553,72 @@ export const makeMessagesRecvSocket = config => {
|
|
|
548
553
|
case 'add':
|
|
549
554
|
case 'leave':
|
|
550
555
|
const stubType = `GROUP_PARTICIPANT_${child.tag.toUpperCase()}`;
|
|
551
|
-
msg.messageStubType = WAMessageStubType[stubType];
|
|
552
|
-
const participants = getBinaryNodeChildren(child, 'participant').map(p => p.attrs.jid);
|
|
556
|
+
msg.messageStubType = _index3.WAMessageStubType[stubType];
|
|
557
|
+
const participants = (0, _index5.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
|
|
553
558
|
if (participants.length === 1 &&
|
|
554
559
|
// if recv. "remove" message and sender removed themselves
|
|
555
560
|
// mark as left
|
|
556
|
-
areJidsSameUser(participants[0], participant) && child.tag === 'remove') {
|
|
557
|
-
msg.messageStubType = WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
|
|
561
|
+
(0, _index5.areJidsSameUser)(participants[0], participant) && child.tag === 'remove') {
|
|
562
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
|
|
558
563
|
}
|
|
559
564
|
msg.messageStubParameters = participants;
|
|
560
565
|
break;
|
|
561
566
|
case 'subject':
|
|
562
|
-
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_SUBJECT;
|
|
567
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_CHANGE_SUBJECT;
|
|
563
568
|
msg.messageStubParameters = [child.attrs.subject];
|
|
564
569
|
break;
|
|
565
570
|
case 'description':
|
|
566
|
-
const description = getBinaryNodeChild(child, 'body')?.content?.toString();
|
|
567
|
-
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
|
|
571
|
+
const description = (0, _index5.getBinaryNodeChild)(child, 'body')?.content?.toString();
|
|
572
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
|
|
568
573
|
msg.messageStubParameters = description ? [description] : undefined;
|
|
569
574
|
break;
|
|
570
575
|
case 'announcement':
|
|
571
576
|
case 'not_announcement':
|
|
572
|
-
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
|
|
577
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
|
|
573
578
|
msg.messageStubParameters = [child.tag === 'announcement' ? 'on' : 'off'];
|
|
574
579
|
break;
|
|
575
580
|
case 'locked':
|
|
576
581
|
case 'unlocked':
|
|
577
|
-
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_RESTRICT;
|
|
582
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_CHANGE_RESTRICT;
|
|
578
583
|
msg.messageStubParameters = [child.tag === 'locked' ? 'on' : 'off'];
|
|
579
584
|
break;
|
|
580
585
|
case 'invite':
|
|
581
|
-
msg.messageStubType = WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
|
|
586
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_CHANGE_INVITE_LINK;
|
|
582
587
|
msg.messageStubParameters = [child.attrs.code];
|
|
583
588
|
break;
|
|
584
589
|
case 'member_add_mode':
|
|
585
590
|
const addMode = child.content;
|
|
586
591
|
if (addMode) {
|
|
587
|
-
msg.messageStubType = WAMessageStubType.GROUP_MEMBER_ADD_MODE;
|
|
592
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_MEMBER_ADD_MODE;
|
|
588
593
|
msg.messageStubParameters = [addMode.toString()];
|
|
589
594
|
}
|
|
590
595
|
break;
|
|
591
596
|
case 'membership_approval_mode':
|
|
592
|
-
const approvalMode = getBinaryNodeChild(child, 'group_join');
|
|
597
|
+
const approvalMode = (0, _index5.getBinaryNodeChild)(child, 'group_join');
|
|
593
598
|
if (approvalMode) {
|
|
594
|
-
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
|
|
599
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE;
|
|
595
600
|
msg.messageStubParameters = [approvalMode.attrs.state];
|
|
596
601
|
}
|
|
597
602
|
break;
|
|
598
603
|
case 'created_membership_requests':
|
|
599
|
-
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
604
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
600
605
|
msg.messageStubParameters = [participantJid, 'created', child.attrs.request_method];
|
|
601
606
|
break;
|
|
602
607
|
case 'revoked_membership_requests':
|
|
603
|
-
const isDenied = areJidsSameUser(participantJid, participant);
|
|
604
|
-
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
608
|
+
const isDenied = (0, _index5.areJidsSameUser)(participantJid, participant);
|
|
609
|
+
msg.messageStubType = _index3.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
605
610
|
msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
|
|
606
611
|
break;
|
|
607
612
|
}
|
|
608
613
|
};
|
|
609
614
|
const processNotification = async node => {
|
|
610
615
|
const result = {};
|
|
611
|
-
const [child] = getAllBinaryNodeChildren(node);
|
|
616
|
+
const [child] = (0, _index5.getAllBinaryNodeChildren)(node);
|
|
612
617
|
const nodeType = node.attrs.type;
|
|
613
|
-
const from = jidNormalizedUser(node.attrs.from);
|
|
618
|
+
const from = (0, _index5.jidNormalizedUser)(node.attrs.from);
|
|
614
619
|
switch (nodeType) {
|
|
615
620
|
case 'privacy_token':
|
|
616
|
-
const tokenList = getBinaryNodeChildren(child, 'token');
|
|
621
|
+
const tokenList = (0, _index5.getBinaryNodeChildren)(child, 'token');
|
|
617
622
|
for (const {
|
|
618
623
|
attrs,
|
|
619
624
|
content
|
|
@@ -638,15 +643,15 @@ export const makeMessagesRecvSocket = config => {
|
|
|
638
643
|
handleGroupNotification(node.attrs.participant, child, result);
|
|
639
644
|
break;
|
|
640
645
|
case 'mediaretry':
|
|
641
|
-
const event = decodeMediaRetryNode(node);
|
|
646
|
+
const event = (0, _index4.decodeMediaRetryNode)(node);
|
|
642
647
|
ev.emit('messages.media-update', [event]);
|
|
643
648
|
break;
|
|
644
649
|
case 'encrypt':
|
|
645
650
|
await handleEncryptNotification(node);
|
|
646
651
|
break;
|
|
647
652
|
case 'devices':
|
|
648
|
-
const devices = getBinaryNodeChildren(child, 'device');
|
|
649
|
-
if (areJidsSameUser(child.attrs.jid, authState.creds.me.id) || areJidsSameUser(child.attrs.lid, authState.creds.me.lid)) {
|
|
653
|
+
const devices = (0, _index5.getBinaryNodeChildren)(child, 'device');
|
|
654
|
+
if ((0, _index5.areJidsSameUser)(child.attrs.jid, authState.creds.me.id) || (0, _index5.areJidsSameUser)(child.attrs.lid, authState.creds.me.lid)) {
|
|
650
655
|
const deviceData = devices.map(d => ({
|
|
651
656
|
id: d.attrs.jid,
|
|
652
657
|
lid: d.attrs.lid
|
|
@@ -658,22 +663,22 @@ export const makeMessagesRecvSocket = config => {
|
|
|
658
663
|
//TODO: drop a new event, add hashes
|
|
659
664
|
break;
|
|
660
665
|
case 'server_sync':
|
|
661
|
-
const update = getBinaryNodeChild(node, 'collection');
|
|
666
|
+
const update = (0, _index5.getBinaryNodeChild)(node, 'collection');
|
|
662
667
|
if (update) {
|
|
663
668
|
const name = update.attrs.name;
|
|
664
669
|
await resyncAppState([name], false);
|
|
665
670
|
}
|
|
666
671
|
break;
|
|
667
672
|
case 'picture':
|
|
668
|
-
const setPicture = getBinaryNodeChild(node, 'set');
|
|
669
|
-
const delPicture = getBinaryNodeChild(node, 'delete');
|
|
673
|
+
const setPicture = (0, _index5.getBinaryNodeChild)(node, 'set');
|
|
674
|
+
const delPicture = (0, _index5.getBinaryNodeChild)(node, 'delete');
|
|
670
675
|
ev.emit('contacts.update', [{
|
|
671
|
-
id: jidNormalizedUser(node?.attrs?.from) || (setPicture || delPicture)?.attrs?.hash || '',
|
|
676
|
+
id: (0, _index5.jidNormalizedUser)(node?.attrs?.from) || (setPicture || delPicture)?.attrs?.hash || '',
|
|
672
677
|
imgUrl: setPicture ? 'changed' : 'removed'
|
|
673
678
|
}]);
|
|
674
|
-
if (isJidGroup(from)) {
|
|
679
|
+
if ((0, _index5.isJidGroup)(from)) {
|
|
675
680
|
const node = setPicture || delPicture;
|
|
676
|
-
result.messageStubType = WAMessageStubType.GROUP_CHANGE_ICON;
|
|
681
|
+
result.messageStubType = _index3.WAMessageStubType.GROUP_CHANGE_ICON;
|
|
677
682
|
if (setPicture) {
|
|
678
683
|
result.messageStubParameters = [setPicture.attrs.id];
|
|
679
684
|
}
|
|
@@ -701,7 +706,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
701
706
|
}
|
|
702
707
|
});
|
|
703
708
|
} else if (child.tag === 'blocklist') {
|
|
704
|
-
const blocklists = getBinaryNodeChildren(child, 'item');
|
|
709
|
+
const blocklists = (0, _index5.getBinaryNodeChildren)(child, 'item');
|
|
705
710
|
for (const {
|
|
706
711
|
attrs
|
|
707
712
|
} of blocklists) {
|
|
@@ -715,31 +720,31 @@ export const makeMessagesRecvSocket = config => {
|
|
|
715
720
|
}
|
|
716
721
|
break;
|
|
717
722
|
case 'link_code_companion_reg':
|
|
718
|
-
const linkCodeCompanionReg = getBinaryNodeChild(node, 'link_code_companion_reg');
|
|
719
|
-
const ref = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_ref'));
|
|
720
|
-
const primaryIdentityPublicKey = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'primary_identity_pub'));
|
|
721
|
-
const primaryEphemeralPublicKeyWrapped = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
|
|
723
|
+
const linkCodeCompanionReg = (0, _index5.getBinaryNodeChild)(node, 'link_code_companion_reg');
|
|
724
|
+
const ref = toRequiredBuffer((0, _index5.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_ref'));
|
|
725
|
+
const primaryIdentityPublicKey = toRequiredBuffer((0, _index5.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'primary_identity_pub'));
|
|
726
|
+
const primaryEphemeralPublicKeyWrapped = toRequiredBuffer((0, _index5.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
|
|
722
727
|
const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
|
|
723
|
-
const companionSharedKey = Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
|
|
724
|
-
const random = randomBytes(32);
|
|
725
|
-
const linkCodeSalt = randomBytes(32);
|
|
726
|
-
const linkCodePairingExpanded = await hkdf(companionSharedKey, 32, {
|
|
728
|
+
const companionSharedKey = _index4.Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
|
|
729
|
+
const random = (0, _crypto.randomBytes)(32);
|
|
730
|
+
const linkCodeSalt = (0, _crypto.randomBytes)(32);
|
|
731
|
+
const linkCodePairingExpanded = await (0, _index4.hkdf)(companionSharedKey, 32, {
|
|
727
732
|
salt: linkCodeSalt,
|
|
728
733
|
info: 'link_code_pairing_key_bundle_encryption_key'
|
|
729
734
|
});
|
|
730
735
|
const encryptPayload = Buffer.concat([Buffer.from(authState.creds.signedIdentityKey.public), primaryIdentityPublicKey, random]);
|
|
731
|
-
const encryptIv = randomBytes(12);
|
|
732
|
-
const encrypted = aesEncryptGCM(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
|
|
736
|
+
const encryptIv = (0, _crypto.randomBytes)(12);
|
|
737
|
+
const encrypted = (0, _index4.aesEncryptGCM)(encryptPayload, linkCodePairingExpanded, encryptIv, Buffer.alloc(0));
|
|
733
738
|
const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
|
|
734
|
-
const identitySharedKey = Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
|
|
739
|
+
const identitySharedKey = _index4.Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
|
|
735
740
|
const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
|
|
736
|
-
authState.creds.advSecretKey = (await hkdf(identityPayload, 32, {
|
|
741
|
+
authState.creds.advSecretKey = (await (0, _index4.hkdf)(identityPayload, 32, {
|
|
737
742
|
info: 'adv_secret'
|
|
738
743
|
})).toString('base64');
|
|
739
744
|
await query({
|
|
740
745
|
tag: 'iq',
|
|
741
746
|
attrs: {
|
|
742
|
-
to: S_WHATSAPP_NET,
|
|
747
|
+
to: _index5.S_WHATSAPP_NET,
|
|
743
748
|
type: 'set',
|
|
744
749
|
id: sock.generateMessageTag(),
|
|
745
750
|
xmlns: 'md'
|
|
@@ -775,14 +780,14 @@ export const makeMessagesRecvSocket = config => {
|
|
|
775
780
|
async function decipherLinkPublicKey(data) {
|
|
776
781
|
const buffer = toRequiredBuffer(data);
|
|
777
782
|
const salt = buffer.slice(0, 32);
|
|
778
|
-
const secretKey = await derivePairingCodeKey(authState.creds.pairingCode, salt);
|
|
783
|
+
const secretKey = await (0, _index4.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
779
784
|
const iv = buffer.slice(32, 48);
|
|
780
785
|
const payload = buffer.slice(48, 80);
|
|
781
|
-
return aesDecryptCTR(payload, secretKey, iv);
|
|
786
|
+
return (0, _index4.aesDecryptCTR)(payload, secretKey, iv);
|
|
782
787
|
}
|
|
783
788
|
function toRequiredBuffer(data) {
|
|
784
789
|
if (data === undefined) {
|
|
785
|
-
throw new Boom('Invalid buffer', {
|
|
790
|
+
throw new _boom.Boom('Invalid buffer', {
|
|
786
791
|
statusCode: 400
|
|
787
792
|
});
|
|
788
793
|
}
|
|
@@ -841,7 +846,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
841
846
|
// if it's the primary jid sending the request
|
|
842
847
|
// just re-send the message to everyone
|
|
843
848
|
// prevents the first message decryption failure
|
|
844
|
-
const sendToAll = !jidDecode(participant)?.device;
|
|
849
|
+
const sendToAll = !(0, _index5.jidDecode)(participant)?.device;
|
|
845
850
|
// Check if we should recreate session for this retry
|
|
846
851
|
let shouldRecreateSession = false;
|
|
847
852
|
let recreateReason = '';
|
|
@@ -872,7 +877,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
872
877
|
}
|
|
873
878
|
}
|
|
874
879
|
await assertSessions([participant], shouldRecreateSession);
|
|
875
|
-
if (isJidGroup(remoteJid)) {
|
|
880
|
+
if ((0, _index5.isJidGroup)(remoteJid)) {
|
|
876
881
|
await authState.keys.set({
|
|
877
882
|
'sender-key-memory': {
|
|
878
883
|
[remoteJid]: null
|
|
@@ -915,8 +920,8 @@ export const makeMessagesRecvSocket = config => {
|
|
|
915
920
|
content
|
|
916
921
|
} = node;
|
|
917
922
|
const isLid = attrs.from.includes('lid');
|
|
918
|
-
const isNodeFromMe = areJidsSameUser(attrs.participant || attrs.from, isLid ? authState.creds.me?.lid : authState.creds.me?.id);
|
|
919
|
-
const remoteJid = !isNodeFromMe || isJidGroup(attrs.from) ? attrs.from : attrs.recipient;
|
|
923
|
+
const isNodeFromMe = (0, _index5.areJidsSameUser)(attrs.participant || attrs.from, isLid ? authState.creds.me?.lid : authState.creds.me?.id);
|
|
924
|
+
const remoteJid = !isNodeFromMe || (0, _index5.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
|
|
920
925
|
const fromMe = !attrs.recipient || (attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe;
|
|
921
926
|
const key = {
|
|
922
927
|
remoteJid,
|
|
@@ -933,26 +938,26 @@ export const makeMessagesRecvSocket = config => {
|
|
|
933
938
|
}
|
|
934
939
|
const ids = [attrs.id];
|
|
935
940
|
if (Array.isArray(content)) {
|
|
936
|
-
const items = getBinaryNodeChildren(content[0], 'item');
|
|
941
|
+
const items = (0, _index5.getBinaryNodeChildren)(content[0], 'item');
|
|
937
942
|
ids.push(...items.map(i => i.attrs.id));
|
|
938
943
|
}
|
|
939
944
|
try {
|
|
940
945
|
await Promise.all([processingMutex.mutex(async () => {
|
|
941
|
-
const status = getStatusFromReceiptType(attrs.type);
|
|
946
|
+
const status = (0, _index4.getStatusFromReceiptType)(attrs.type);
|
|
942
947
|
if (typeof status !== 'undefined' && (
|
|
943
948
|
// basically, we only want to know when a message from us has been delivered to/read by the other person
|
|
944
949
|
// or another device of ours has read some messages
|
|
945
|
-
status >= proto.WebMessageInfo.Status.SERVER_ACK || !isNodeFromMe)) {
|
|
946
|
-
if (isJidGroup(remoteJid) || isJidStatusBroadcast(remoteJid)) {
|
|
950
|
+
status >= _index.proto.WebMessageInfo.Status.SERVER_ACK || !isNodeFromMe)) {
|
|
951
|
+
if ((0, _index5.isJidGroup)(remoteJid) || (0, _index5.isJidStatusBroadcast)(remoteJid)) {
|
|
947
952
|
if (attrs.participant) {
|
|
948
|
-
const updateKey = status === proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
|
|
953
|
+
const updateKey = status === _index.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
|
|
949
954
|
ev.emit('message-receipt.update', ids.map(id => ({
|
|
950
955
|
key: {
|
|
951
956
|
...key,
|
|
952
957
|
id
|
|
953
958
|
},
|
|
954
959
|
receipt: {
|
|
955
|
-
userJid: jidNormalizedUser(attrs.participant),
|
|
960
|
+
userJid: (0, _index5.jidNormalizedUser)(attrs.participant),
|
|
956
961
|
[updateKey]: +attrs.t
|
|
957
962
|
}
|
|
958
963
|
})));
|
|
@@ -972,7 +977,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
972
977
|
if (attrs.type === 'retry') {
|
|
973
978
|
// correctly set who is asking for the retry
|
|
974
979
|
key.participant = key.participant || attrs.from;
|
|
975
|
-
const retryNode = getBinaryNodeChild(node, 'retry');
|
|
980
|
+
const retryNode = (0, _index5.getBinaryNodeChild)(node, 'retry');
|
|
976
981
|
if (ids[0] && key.participant && willSendMessageAgain(ids[0], key.participant)) {
|
|
977
982
|
if (key.fromMe) {
|
|
978
983
|
try {
|
|
@@ -1021,7 +1026,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1021
1026
|
await Promise.all([processingMutex.mutex(async () => {
|
|
1022
1027
|
const msg = await processNotification(node);
|
|
1023
1028
|
if (msg) {
|
|
1024
|
-
const fromMe = areJidsSameUser(node.attrs.participant || remoteJid, authState.creds.me.id);
|
|
1029
|
+
const fromMe = (0, _index5.areJidsSameUser)(node.attrs.participant || remoteJid, authState.creds.me.id);
|
|
1025
1030
|
msg.key = {
|
|
1026
1031
|
remoteJid,
|
|
1027
1032
|
fromMe,
|
|
@@ -1031,7 +1036,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1031
1036
|
};
|
|
1032
1037
|
msg.participant ?? (msg.participant = node.attrs.participant);
|
|
1033
1038
|
msg.messageTimestamp = +node.attrs.t;
|
|
1034
|
-
const fullMsg = proto.WebMessageInfo.create(msg);
|
|
1039
|
+
const fullMsg = _index.proto.WebMessageInfo.create(msg);
|
|
1035
1040
|
await upsertMessage(fullMsg, 'append');
|
|
1036
1041
|
}
|
|
1037
1042
|
})]);
|
|
@@ -1047,21 +1052,21 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1047
1052
|
await sendMessageAck(node);
|
|
1048
1053
|
return;
|
|
1049
1054
|
}
|
|
1050
|
-
const encNode = getBinaryNodeChild(node, 'enc');
|
|
1055
|
+
const encNode = (0, _index5.getBinaryNodeChild)(node, 'enc');
|
|
1051
1056
|
// TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
|
|
1052
1057
|
if (encNode && encNode.attrs.type === 'msmsg') {
|
|
1053
1058
|
logger.debug({
|
|
1054
1059
|
key: node.attrs.key
|
|
1055
1060
|
}, 'ignored msmsg');
|
|
1056
|
-
await sendMessageAck(node, NACK_REASONS.MissingMessageSecret);
|
|
1061
|
+
await sendMessageAck(node, _index4.NACK_REASONS.MissingMessageSecret);
|
|
1057
1062
|
return;
|
|
1058
1063
|
}
|
|
1059
1064
|
let response;
|
|
1060
|
-
if (getBinaryNodeChild(node, 'unavailable') && !encNode) {
|
|
1065
|
+
if ((0, _index5.getBinaryNodeChild)(node, 'unavailable') && !encNode) {
|
|
1061
1066
|
await sendMessageAck(node);
|
|
1062
1067
|
const {
|
|
1063
1068
|
key
|
|
1064
|
-
} = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
|
|
1069
|
+
} = (0, _index4.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
|
|
1065
1070
|
response = await requestPlaceholderResend(key);
|
|
1066
1071
|
if (response === 'RESOLVED') {
|
|
1067
1072
|
return;
|
|
@@ -1077,13 +1082,13 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1077
1082
|
category,
|
|
1078
1083
|
author,
|
|
1079
1084
|
decrypt
|
|
1080
|
-
} = decryptMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
|
|
1081
|
-
if (response && msg?.messageStubParameters?.[0] === NO_MESSAGE_FOUND_ERROR_TEXT) {
|
|
1082
|
-
msg.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, response];
|
|
1085
|
+
} = (0, _index4.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
|
|
1086
|
+
if (response && msg?.messageStubParameters?.[0] === _index4.NO_MESSAGE_FOUND_ERROR_TEXT) {
|
|
1087
|
+
msg.messageStubParameters = [_index4.NO_MESSAGE_FOUND_ERROR_TEXT, response];
|
|
1083
1088
|
}
|
|
1084
|
-
if (msg.message?.protocolMessage?.type === proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER && node.attrs.sender_pn) {
|
|
1085
|
-
const lid = jidNormalizedUser(node.attrs.from),
|
|
1086
|
-
pn = jidNormalizedUser(node.attrs.sender_pn);
|
|
1089
|
+
if (msg.message?.protocolMessage?.type === _index.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER && node.attrs.sender_pn) {
|
|
1090
|
+
const lid = (0, _index5.jidNormalizedUser)(node.attrs.from),
|
|
1091
|
+
pn = (0, _index5.jidNormalizedUser)(node.attrs.sender_pn);
|
|
1087
1092
|
ev.emit('lid-mapping.update', {
|
|
1088
1093
|
lid,
|
|
1089
1094
|
pn
|
|
@@ -1093,7 +1098,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1093
1098
|
const alt = msg.key.participantAlt || msg.key.remoteJidAlt;
|
|
1094
1099
|
// store new mappings we didn't have before
|
|
1095
1100
|
if (!!alt) {
|
|
1096
|
-
const altServer = jidDecode(alt)?.server;
|
|
1101
|
+
const altServer = (0, _index5.jidDecode)(alt)?.server;
|
|
1097
1102
|
const lidMapping = signalRepository.getLIDMappingStore();
|
|
1098
1103
|
if (altServer === 'lid') {
|
|
1099
1104
|
if (!(await lidMapping.getPNForLID(alt))) {
|
|
@@ -1116,9 +1121,9 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1116
1121
|
await Promise.all([processingMutex.mutex(async () => {
|
|
1117
1122
|
await decrypt();
|
|
1118
1123
|
// message failed to decrypt
|
|
1119
|
-
if (msg.messageStubType === proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
1120
|
-
if (msg?.messageStubParameters?.[0] === MISSING_KEYS_ERROR_TEXT) {
|
|
1121
|
-
return sendMessageAck(node, NACK_REASONS.ParsingError);
|
|
1124
|
+
if (msg.messageStubType === _index.proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
1125
|
+
if (msg?.messageStubParameters?.[0] === _index4.MISSING_KEYS_ERROR_TEXT) {
|
|
1126
|
+
return sendMessageAck(node, _index4.NACK_REASONS.ParsingError);
|
|
1122
1127
|
}
|
|
1123
1128
|
const errorMessage = msg?.messageStubParameters?.[0] || '';
|
|
1124
1129
|
const isPreKeyError = errorMessage.includes('PreKey');
|
|
@@ -1132,7 +1137,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1132
1137
|
}, 'Connection closed, skipping retry');
|
|
1133
1138
|
return;
|
|
1134
1139
|
}
|
|
1135
|
-
if (getBinaryNodeChild(node, 'unavailable')) {
|
|
1140
|
+
if ((0, _index5.getBinaryNodeChild)(node, 'unavailable')) {
|
|
1136
1141
|
logger.debug('Message unavailable, skipping retry');
|
|
1137
1142
|
return;
|
|
1138
1143
|
}
|
|
@@ -1145,17 +1150,17 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1145
1150
|
logger.debug('Uploading pre-keys for error recovery');
|
|
1146
1151
|
await uploadPreKeys(5);
|
|
1147
1152
|
logger.debug('Waiting for server to process new pre-keys');
|
|
1148
|
-
await delay(1000);
|
|
1153
|
+
await (0, _index4.delay)(1000);
|
|
1149
1154
|
} catch (uploadErr) {
|
|
1150
1155
|
logger.error({
|
|
1151
1156
|
uploadErr
|
|
1152
1157
|
}, 'Pre-key upload failed, proceeding with retry anyway');
|
|
1153
1158
|
}
|
|
1154
1159
|
}
|
|
1155
|
-
const encNode = getBinaryNodeChild(node, 'enc');
|
|
1160
|
+
const encNode = (0, _index5.getBinaryNodeChild)(node, 'enc');
|
|
1156
1161
|
await sendRetryRequest(node, !encNode);
|
|
1157
1162
|
if (retryRequestDelayMs) {
|
|
1158
|
-
await delay(retryRequestDelayMs);
|
|
1163
|
+
await (0, _index4.delay)(retryRequestDelayMs);
|
|
1159
1164
|
}
|
|
1160
1165
|
} catch (err) {
|
|
1161
1166
|
logger.error({
|
|
@@ -1164,7 +1169,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1164
1169
|
}, 'Failed to handle retry, attempting basic retry');
|
|
1165
1170
|
// Still attempt retry even if pre-key upload failed
|
|
1166
1171
|
try {
|
|
1167
|
-
const encNode = getBinaryNodeChild(node, 'enc');
|
|
1172
|
+
const encNode = (0, _index5.getBinaryNodeChild)(node, 'enc');
|
|
1168
1173
|
await sendRetryRequest(node, !encNode);
|
|
1169
1174
|
} catch (retryErr) {
|
|
1170
1175
|
logger.error({
|
|
@@ -1184,7 +1189,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1184
1189
|
// message was sent by us from a different device
|
|
1185
1190
|
type = 'sender';
|
|
1186
1191
|
// need to specially handle this case
|
|
1187
|
-
if (isLidUser(msg.key.remoteJid) || isLidUser(msg.key.remoteJidAlt)) {
|
|
1192
|
+
if ((0, _index5.isLidUser)(msg.key.remoteJid) || (0, _index5.isLidUser)(msg.key.remoteJidAlt)) {
|
|
1188
1193
|
participant = author; // TODO: investigate sending receipts to LIDs and not PNs
|
|
1189
1194
|
}
|
|
1190
1195
|
} else if (!sendActiveReceipts) {
|
|
@@ -1192,13 +1197,13 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1192
1197
|
}
|
|
1193
1198
|
await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
|
|
1194
1199
|
// send ack for history message
|
|
1195
|
-
const isAnyHistoryMsg = getHistoryMsg(msg.message);
|
|
1200
|
+
const isAnyHistoryMsg = (0, _index4.getHistoryMsg)(msg.message);
|
|
1196
1201
|
if (isAnyHistoryMsg) {
|
|
1197
|
-
const jid = jidNormalizedUser(msg.key.remoteJid);
|
|
1202
|
+
const jid = (0, _index5.jidNormalizedUser)(msg.key.remoteJid);
|
|
1198
1203
|
await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
|
|
1199
1204
|
}
|
|
1200
1205
|
}
|
|
1201
|
-
cleanMessage(msg, authState.creds.me.id);
|
|
1206
|
+
(0, _index4.cleanMessage)(msg, authState.creds.me.id);
|
|
1202
1207
|
await sendMessageAck(node);
|
|
1203
1208
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
1204
1209
|
})]);
|
|
@@ -1214,14 +1219,14 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1214
1219
|
const {
|
|
1215
1220
|
attrs
|
|
1216
1221
|
} = node;
|
|
1217
|
-
const [infoChild] = getAllBinaryNodeChildren(node);
|
|
1222
|
+
const [infoChild] = (0, _index5.getAllBinaryNodeChildren)(node);
|
|
1218
1223
|
if (!infoChild) {
|
|
1219
|
-
throw new Boom('Missing call info in call node');
|
|
1224
|
+
throw new _boom.Boom('Missing call info in call node');
|
|
1220
1225
|
}
|
|
1221
1226
|
const callId = infoChild.attrs['call-id'];
|
|
1222
1227
|
const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
|
|
1223
|
-
status = getCallStatusFromNode(infoChild);
|
|
1224
|
-
if (isLidUser(from) && infoChild.tag === 'relaylatency') {
|
|
1228
|
+
status = (0, _index4.getCallStatusFromNode)(infoChild);
|
|
1229
|
+
if ((0, _index5.isLidUser)(from) && infoChild.tag === 'relaylatency') {
|
|
1225
1230
|
const verify = callOfferCache.get(callId);
|
|
1226
1231
|
if (!verify) {
|
|
1227
1232
|
status = 'offer';
|
|
@@ -1245,7 +1250,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1245
1250
|
status
|
|
1246
1251
|
};
|
|
1247
1252
|
if (status === 'offer') {
|
|
1248
|
-
call.isVideo = !!getBinaryNodeChild(infoChild, 'video');
|
|
1253
|
+
call.isVideo = !!(0, _index5.getBinaryNodeChild)(infoChild, 'video');
|
|
1249
1254
|
call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
|
|
1250
1255
|
call.groupJid = infoChild.attrs['group-jid'];
|
|
1251
1256
|
callOfferCache.set(call.id, call);
|
|
@@ -1293,7 +1298,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1293
1298
|
ev.emit('messages.update', [{
|
|
1294
1299
|
key,
|
|
1295
1300
|
update: {
|
|
1296
|
-
status: WAMessageStatus.ERROR,
|
|
1301
|
+
status: _index3.WAMessageStatus.ERROR,
|
|
1297
1302
|
messageStubParameters: [attrs.error]
|
|
1298
1303
|
}
|
|
1299
1304
|
}]);
|
|
@@ -1380,13 +1385,13 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1380
1385
|
id: call.id,
|
|
1381
1386
|
fromMe: false
|
|
1382
1387
|
},
|
|
1383
|
-
messageTimestamp: unixTimestampSeconds(call.date)
|
|
1388
|
+
messageTimestamp: (0, _index4.unixTimestampSeconds)(call.date)
|
|
1384
1389
|
};
|
|
1385
1390
|
if (call.status === 'timeout') {
|
|
1386
1391
|
if (call.isGroup) {
|
|
1387
|
-
msg.messageStubType = call.isVideo ? WAMessageStubType.CALL_MISSED_GROUP_VIDEO : WAMessageStubType.CALL_MISSED_GROUP_VOICE;
|
|
1392
|
+
msg.messageStubType = call.isVideo ? _index3.WAMessageStubType.CALL_MISSED_GROUP_VIDEO : _index3.WAMessageStubType.CALL_MISSED_GROUP_VOICE;
|
|
1388
1393
|
} else {
|
|
1389
|
-
msg.messageStubType = call.isVideo ? WAMessageStubType.CALL_MISSED_VIDEO : WAMessageStubType.CALL_MISSED_VOICE;
|
|
1394
|
+
msg.messageStubType = call.isVideo ? _index3.WAMessageStubType.CALL_MISSED_VIDEO : _index3.WAMessageStubType.CALL_MISSED_VOICE;
|
|
1390
1395
|
}
|
|
1391
1396
|
} else {
|
|
1392
1397
|
msg.message = {
|
|
@@ -1395,7 +1400,7 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1395
1400
|
}
|
|
1396
1401
|
};
|
|
1397
1402
|
}
|
|
1398
|
-
const protoMsg = proto.WebMessageInfo.create(msg);
|
|
1403
|
+
const protoMsg = _index.proto.WebMessageInfo.create(msg);
|
|
1399
1404
|
upsertMessage(protoMsg, call.offline ? 'append' : 'notify');
|
|
1400
1405
|
}
|
|
1401
1406
|
});
|
|
@@ -1417,4 +1422,4 @@ export const makeMessagesRecvSocket = config => {
|
|
|
1417
1422
|
messageRetryManager
|
|
1418
1423
|
};
|
|
1419
1424
|
};
|
|
1420
|
-
|
|
1425
|
+
exports.makeMessagesRecvSocket = makeMessagesRecvSocket;
|