@d0v3riz/baileys 6.7.18 → 6.7.20
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.md +1263 -4
- package/WAProto/GenerateStatics.sh +2 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/index.d.ts +3212 -122
- package/WAProto/index.js +9635 -299
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +1 -1
- package/lib/Defaults/index.js +16 -16
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +29 -39
- package/lib/Signal/libsignal.js +33 -20
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/business.d.ts +5 -5
- package/lib/Socket/business.js +5 -5
- package/lib/Socket/chats.d.ts +4 -4
- package/lib/Socket/chats.js +70 -70
- package/lib/Socket/groups.d.ts +6 -6
- package/lib/Socket/groups.js +39 -24
- package/lib/Socket/index.d.ts +5 -5
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +5 -5
- package/lib/Socket/messages-recv.js +73 -56
- package/lib/Socket/messages-send.d.ts +5 -5
- package/lib/Socket/messages-send.js +53 -46
- package/lib/Socket/socket.d.ts +3 -3
- package/lib/Socket/socket.js +22 -29
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Socket/usync.js +10 -15
- package/lib/Types/Auth.d.ts +1 -1
- package/lib/Types/Chat.d.ts +1 -1
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +4 -0
- package/lib/Types/Events.d.ts +1 -1
- package/lib/Types/GroupMetadata.d.ts +7 -3
- package/lib/Types/Message.d.ts +7 -2
- package/lib/Types/Socket.d.ts +3 -3
- package/lib/Utils/auth-utils.js +8 -9
- package/lib/Utils/baileys-event-stream.js +1 -1
- package/lib/Utils/business.js +17 -11
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/chat-utils.js +64 -69
- package/lib/Utils/crypto.js +4 -10
- package/lib/Utils/decode-wa-message.js +6 -2
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +9 -13
- package/lib/Utils/generics.d.ts +1 -1
- package/lib/Utils/generics.js +28 -30
- package/lib/Utils/history.js +10 -5
- package/lib/Utils/link-preview.js +5 -9
- package/lib/Utils/lt-hash.js +2 -2
- package/lib/Utils/make-mutex.js +1 -1
- package/lib/Utils/messages-media.d.ts +2 -3
- package/lib/Utils/messages-media.js +80 -95
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +83 -75
- package/lib/Utils/process-message.d.ts +1 -1
- package/lib/Utils/process-message.js +25 -30
- package/lib/Utils/signal.js +9 -7
- package/lib/Utils/use-multi-file-auth-state.js +2 -3
- package/lib/Utils/validate-connection.js +17 -22
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +1271 -8
- package/lib/WABinary/decode.js +2 -1
- package/lib/WABinary/encode.js +2 -2
- package/lib/WABinary/generic-utils.js +1 -1
- package/lib/WABinary/jid-utils.js +8 -11
- package/lib/WAM/constants.js +2252 -2359
- package/lib/WAM/encode.js +5 -7
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
- package/lib/WAUSync/USyncQuery.js +17 -13
- package/package.json +11 -6
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
package/lib/Utils/messages.js
CHANGED
|
@@ -22,14 +22,14 @@ const MIMETYPE_MAP = {
|
|
|
22
22
|
document: 'application/pdf',
|
|
23
23
|
audio: 'audio/ogg; codecs=opus',
|
|
24
24
|
sticker: 'image/webp',
|
|
25
|
-
'product-catalog-image': 'image/jpeg'
|
|
25
|
+
'product-catalog-image': 'image/jpeg'
|
|
26
26
|
};
|
|
27
27
|
const MessageTypeProto = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
image: Types_1.WAProto.Message.ImageMessage,
|
|
29
|
+
video: Types_1.WAProto.Message.VideoMessage,
|
|
30
|
+
audio: Types_1.WAProto.Message.AudioMessage,
|
|
31
|
+
sticker: Types_1.WAProto.Message.StickerMessage,
|
|
32
|
+
document: Types_1.WAProto.Message.DocumentMessage
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* Uses a regex to test whether the string contains a URL, and returns the URL if it does.
|
|
@@ -45,7 +45,8 @@ const generateLinkPreviewIfRequired = async (text, getUrlInfo, logger) => {
|
|
|
45
45
|
const urlInfo = await getUrlInfo(url);
|
|
46
46
|
return urlInfo;
|
|
47
47
|
}
|
|
48
|
-
catch (error) {
|
|
48
|
+
catch (error) {
|
|
49
|
+
// ignore if fails
|
|
49
50
|
logger === null || logger === void 0 ? void 0 : logger.warn({ trace: error.stack }, 'url generation failed');
|
|
50
51
|
}
|
|
51
52
|
}
|
|
@@ -83,11 +84,11 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
83
84
|
delete uploadData[mediaType];
|
|
84
85
|
// check if cacheable + generate cache key
|
|
85
86
|
const cacheableKey = typeof uploadData.media === 'object' &&
|
|
86
|
-
|
|
87
|
+
'url' in uploadData.media &&
|
|
87
88
|
!!uploadData.media.url &&
|
|
88
|
-
!!options.mediaCache &&
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
!!options.mediaCache &&
|
|
90
|
+
// generate the key
|
|
91
|
+
mediaType + ':' + uploadData.media.url.toString();
|
|
91
92
|
if (mediaType === 'document' && !uploadData.fileName) {
|
|
92
93
|
uploadData.fileName = 'file';
|
|
93
94
|
}
|
|
@@ -106,12 +107,11 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
109
|
-
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
|
|
110
|
-
(typeof uploadData['jpegThumbnail'] === 'undefined');
|
|
110
|
+
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData['jpegThumbnail'] === 'undefined';
|
|
111
111
|
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
|
|
112
112
|
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
113
113
|
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
114
|
-
const { mediaKey,
|
|
114
|
+
const { mediaKey, encFilePath, originalFilePath, fileEncSha256, fileSha256, fileLength } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
115
115
|
logger,
|
|
116
116
|
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
117
117
|
opts: options.options
|
|
@@ -120,14 +120,18 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
120
120
|
const fileEncSha256B64 = fileEncSha256.toString('base64');
|
|
121
121
|
const [{ mediaUrl, directPath }] = await Promise.all([
|
|
122
122
|
(async () => {
|
|
123
|
-
const result = await options.upload(
|
|
123
|
+
const result = await options.upload(encFilePath, {
|
|
124
|
+
fileEncSha256B64,
|
|
125
|
+
mediaType,
|
|
126
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
127
|
+
});
|
|
124
128
|
logger === null || logger === void 0 ? void 0 : logger.debug({ mediaType, cacheableKey }, 'uploaded media');
|
|
125
129
|
return result;
|
|
126
130
|
})(),
|
|
127
131
|
(async () => {
|
|
128
132
|
try {
|
|
129
133
|
if (requiresThumbnailComputation) {
|
|
130
|
-
const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(
|
|
134
|
+
const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(originalFilePath, mediaType, options);
|
|
131
135
|
uploadData.jpegThumbnail = thumbnail;
|
|
132
136
|
if (!uploadData.width && originalImageDimensions) {
|
|
133
137
|
uploadData.width = originalImageDimensions.width;
|
|
@@ -137,11 +141,11 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
137
141
|
logger === null || logger === void 0 ? void 0 : logger.debug('generated thumbnail');
|
|
138
142
|
}
|
|
139
143
|
if (requiresDurationComputation) {
|
|
140
|
-
uploadData.seconds = await (0, messages_media_1.getAudioDuration)(
|
|
144
|
+
uploadData.seconds = await (0, messages_media_1.getAudioDuration)(originalFilePath);
|
|
141
145
|
logger === null || logger === void 0 ? void 0 : logger.debug('computed audio duration');
|
|
142
146
|
}
|
|
143
147
|
if (requiresWaveformProcessing) {
|
|
144
|
-
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(
|
|
148
|
+
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(originalFilePath, logger);
|
|
145
149
|
logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
|
|
146
150
|
}
|
|
147
151
|
if (requiresAudioBackground) {
|
|
@@ -152,20 +156,17 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
152
156
|
catch (error) {
|
|
153
157
|
logger === null || logger === void 0 ? void 0 : logger.warn({ trace: error.stack }, 'failed to obtain extra info');
|
|
154
158
|
}
|
|
155
|
-
})()
|
|
156
|
-
])
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
await fs_1.promises.access(bodyPath);
|
|
163
|
-
await fs_1.promises.unlink(bodyPath);
|
|
164
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp file');
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
|
|
159
|
+
})()
|
|
160
|
+
]).finally(async () => {
|
|
161
|
+
try {
|
|
162
|
+
await fs_1.promises.unlink(encFilePath);
|
|
163
|
+
if (originalFilePath) {
|
|
164
|
+
await fs_1.promises.unlink(originalFilePath);
|
|
168
165
|
}
|
|
166
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp files');
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
|
|
169
170
|
}
|
|
170
171
|
});
|
|
171
172
|
const obj = Types_1.WAProto.Message.fromObject({
|
|
@@ -304,9 +305,11 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
304
305
|
m = (0, exports.generateForwardMessageContent)(message.forward, message.force);
|
|
305
306
|
}
|
|
306
307
|
else if ('disappearingMessagesInChat' in message) {
|
|
307
|
-
const exp = typeof message.disappearingMessagesInChat === 'boolean'
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
const exp = typeof message.disappearingMessagesInChat === 'boolean'
|
|
309
|
+
? message.disappearingMessagesInChat
|
|
310
|
+
? Defaults_1.WA_DEFAULT_EPHEMERAL
|
|
311
|
+
: 0
|
|
312
|
+
: message.disappearingMessagesInChat;
|
|
310
313
|
m = (0, exports.prepareDisappearingMessageSettingContent)(exp);
|
|
311
314
|
}
|
|
312
315
|
else if ('groupInvite' in message) {
|
|
@@ -342,14 +345,14 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
342
345
|
m.templateButtonReplyMessage = {
|
|
343
346
|
selectedDisplayText: message.buttonReply.displayText,
|
|
344
347
|
selectedId: message.buttonReply.id,
|
|
345
|
-
selectedIndex: message.buttonReply.index
|
|
348
|
+
selectedIndex: message.buttonReply.index
|
|
346
349
|
};
|
|
347
350
|
break;
|
|
348
351
|
case 'plain':
|
|
349
352
|
m.buttonsResponseMessage = {
|
|
350
353
|
selectedButtonId: message.buttonReply.id,
|
|
351
354
|
selectedDisplayText: message.buttonReply.displayText,
|
|
352
|
-
type: WAProto_1.proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT
|
|
355
|
+
type: WAProto_1.proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT
|
|
353
356
|
};
|
|
354
357
|
break;
|
|
355
358
|
}
|
|
@@ -364,7 +367,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
364
367
|
...message,
|
|
365
368
|
product: {
|
|
366
369
|
...message.product,
|
|
367
|
-
productImage: imageMessage
|
|
370
|
+
productImage: imageMessage
|
|
368
371
|
}
|
|
369
372
|
});
|
|
370
373
|
}
|
|
@@ -377,18 +380,19 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
377
380
|
if (!Array.isArray(message.poll.values)) {
|
|
378
381
|
throw new boom_1.Boom('Invalid poll values', { statusCode: 400 });
|
|
379
382
|
}
|
|
380
|
-
if (message.poll.selectableCount < 0
|
|
381
|
-
|
|
382
|
-
|
|
383
|
+
if (message.poll.selectableCount < 0 || message.poll.selectableCount > message.poll.values.length) {
|
|
384
|
+
throw new boom_1.Boom(`poll.selectableCount in poll should be >= 0 and <= ${message.poll.values.length}`, {
|
|
385
|
+
statusCode: 400
|
|
386
|
+
});
|
|
383
387
|
}
|
|
384
388
|
m.messageContextInfo = {
|
|
385
389
|
// encKey
|
|
386
|
-
messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32)
|
|
390
|
+
messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32)
|
|
387
391
|
};
|
|
388
392
|
const pollCreationMessage = {
|
|
389
393
|
name: message.poll.name,
|
|
390
394
|
selectableOptionsCount: message.poll.selectableCount,
|
|
391
|
-
options: message.poll.values.map(optionName => ({ optionName }))
|
|
395
|
+
options: message.poll.values.map(optionName => ({ optionName }))
|
|
392
396
|
};
|
|
393
397
|
if (message.poll.toAnnouncementGroup) {
|
|
394
398
|
// poll v2 is for community announcement groups (single select and multiple)
|
|
@@ -453,7 +457,9 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
453
457
|
const timestamp = (0, generics_1.unixTimestampSeconds)(options.timestamp);
|
|
454
458
|
const { quoted, userJid, contextInfo } = options;
|
|
455
459
|
if (quoted) {
|
|
456
|
-
const participant = quoted.key.fromMe
|
|
460
|
+
const participant = quoted.key.fromMe
|
|
461
|
+
? userJid
|
|
462
|
+
: quoted.participant || quoted.key.participant || quoted.key.remoteJid;
|
|
457
463
|
let quotedMsg = (0, exports.normalizeMessageContent)(quoted.message);
|
|
458
464
|
const msgType = (0, exports.getContentType)(quotedMsg);
|
|
459
465
|
// strip any redundant properties
|
|
@@ -488,7 +494,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
488
494
|
key !== 'ephemeralMessage') {
|
|
489
495
|
innerMessage[key].contextInfo = {
|
|
490
496
|
...(innerMessage[key].contextInfo || {}),
|
|
491
|
-
expiration: options.ephemeralExpiration || Defaults_1.WA_DEFAULT_EPHEMERAL
|
|
497
|
+
expiration: options.ephemeralExpiration || Defaults_1.WA_DEFAULT_EPHEMERAL
|
|
492
498
|
//ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
|
|
493
499
|
};
|
|
494
500
|
}
|
|
@@ -497,7 +503,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
497
503
|
key: {
|
|
498
504
|
remoteJid: jid,
|
|
499
505
|
fromMe: true,
|
|
500
|
-
id: (options === null || options === void 0 ? void 0 : options.messageId) || (0, generics_1.generateMessageIDV2)()
|
|
506
|
+
id: (options === null || options === void 0 ? void 0 : options.messageId) || (0, generics_1.generateMessageIDV2)()
|
|
501
507
|
},
|
|
502
508
|
message: message,
|
|
503
509
|
messageTimestamp: timestamp,
|
|
@@ -544,12 +550,12 @@ const normalizeMessageContent = (content) => {
|
|
|
544
550
|
}
|
|
545
551
|
return content;
|
|
546
552
|
function getFutureProofMessage(message) {
|
|
547
|
-
return ((message === null || message === void 0 ? void 0 : message.ephemeralMessage)
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
+
return ((message === null || message === void 0 ? void 0 : message.ephemeralMessage) ||
|
|
554
|
+
(message === null || message === void 0 ? void 0 : message.viewOnceMessage) ||
|
|
555
|
+
(message === null || message === void 0 ? void 0 : message.documentWithCaptionMessage) ||
|
|
556
|
+
(message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) ||
|
|
557
|
+
(message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) ||
|
|
558
|
+
(message === null || message === void 0 ? void 0 : message.editedMessage));
|
|
553
559
|
}
|
|
554
560
|
};
|
|
555
561
|
exports.normalizeMessageContent = normalizeMessageContent;
|
|
@@ -574,9 +580,7 @@ const extractMessageContent = (content) => {
|
|
|
574
580
|
}
|
|
575
581
|
else {
|
|
576
582
|
return {
|
|
577
|
-
conversation: 'contentText' in msg
|
|
578
|
-
? msg.contentText
|
|
579
|
-
: ('hydratedContentText' in msg ? msg.hydratedContentText : '')
|
|
583
|
+
conversation: 'contentText' in msg ? msg.contentText : 'hydratedContentText' in msg ? msg.hydratedContentText : ''
|
|
580
584
|
};
|
|
581
585
|
}
|
|
582
586
|
};
|
|
@@ -599,11 +603,15 @@ exports.extractMessageContent = extractMessageContent;
|
|
|
599
603
|
/**
|
|
600
604
|
* Returns the device predicted by message ID
|
|
601
605
|
*/
|
|
602
|
-
const getDevice = (id) => /^3A.{18}$/.test(id)
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
606
|
+
const getDevice = (id) => /^3A.{18}$/.test(id)
|
|
607
|
+
? 'ios'
|
|
608
|
+
: /^3E.{20}$/.test(id)
|
|
609
|
+
? 'web'
|
|
610
|
+
: /^(.{21}|.{32})$/.test(id)
|
|
611
|
+
? 'android'
|
|
612
|
+
: /^(3F|.{18}$)/.test(id)
|
|
613
|
+
? 'desktop'
|
|
614
|
+
: 'unknown';
|
|
607
615
|
exports.getDevice = getDevice;
|
|
608
616
|
/** Upserts a receipt in the message */
|
|
609
617
|
const updateMessageWithReceipt = (msg, receipt) => {
|
|
@@ -620,11 +628,9 @@ exports.updateMessageWithReceipt = updateMessageWithReceipt;
|
|
|
620
628
|
/** Update the message with a new reaction */
|
|
621
629
|
const updateMessageWithReaction = (msg, reaction) => {
|
|
622
630
|
const authorID = (0, generics_1.getKeyAuthor)(reaction.key);
|
|
623
|
-
const reactions = (msg.reactions || [])
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
reactions.push(reaction);
|
|
627
|
-
}
|
|
631
|
+
const reactions = (msg.reactions || []).filter(r => (0, generics_1.getKeyAuthor)(r.key) !== authorID);
|
|
632
|
+
reaction.text = reaction.text || '';
|
|
633
|
+
reactions.push(reaction);
|
|
628
634
|
msg.reactions = reactions;
|
|
629
635
|
};
|
|
630
636
|
exports.updateMessageWithReaction = updateMessageWithReaction;
|
|
@@ -632,8 +638,7 @@ exports.updateMessageWithReaction = updateMessageWithReaction;
|
|
|
632
638
|
const updateMessageWithPollUpdate = (msg, update) => {
|
|
633
639
|
var _a, _b;
|
|
634
640
|
const authorID = (0, generics_1.getKeyAuthor)(update.pollUpdateMessageKey);
|
|
635
|
-
const reactions = (msg.pollUpdates || [])
|
|
636
|
-
.filter(r => (0, generics_1.getKeyAuthor)(r.pollUpdateMessageKey) !== authorID);
|
|
641
|
+
const reactions = (msg.pollUpdates || []).filter(r => (0, generics_1.getKeyAuthor)(r.pollUpdateMessageKey) !== authorID);
|
|
637
642
|
if ((_b = (_a = update.vote) === null || _a === void 0 ? void 0 : _a.selectedOptions) === null || _b === void 0 ? void 0 : _b.length) {
|
|
638
643
|
reactions.push(update);
|
|
639
644
|
}
|
|
@@ -648,7 +653,10 @@ exports.updateMessageWithPollUpdate = updateMessageWithPollUpdate;
|
|
|
648
653
|
*/
|
|
649
654
|
function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
|
|
650
655
|
var _a, _b, _c;
|
|
651
|
-
const opts = ((_a = message === null || message === void 0 ? void 0 : message.pollCreationMessage) === null || _a === void 0 ? void 0 : _a.options) ||
|
|
656
|
+
const opts = ((_a = message === null || message === void 0 ? void 0 : message.pollCreationMessage) === null || _a === void 0 ? void 0 : _a.options) ||
|
|
657
|
+
((_b = message === null || message === void 0 ? void 0 : message.pollCreationMessageV2) === null || _b === void 0 ? void 0 : _b.options) ||
|
|
658
|
+
((_c = message === null || message === void 0 ? void 0 : message.pollCreationMessageV3) === null || _c === void 0 ? void 0 : _c.options) ||
|
|
659
|
+
[];
|
|
652
660
|
const voteHashMap = opts.reduce((acc, opt) => {
|
|
653
661
|
const hash = (0, crypto_2.sha256)(Buffer.from(opt.optionName || '')).toString();
|
|
654
662
|
acc[hash] = {
|
|
@@ -701,10 +709,10 @@ const REUPLOAD_REQUIRED_STATUS = [410, 404];
|
|
|
701
709
|
* Downloads the given message. Throws an error if it's not a media message
|
|
702
710
|
*/
|
|
703
711
|
const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
704
|
-
const result = await downloadMsg()
|
|
705
|
-
.catch(async (error) => {
|
|
712
|
+
const result = await downloadMsg().catch(async (error) => {
|
|
706
713
|
var _a;
|
|
707
|
-
if (ctx &&
|
|
714
|
+
if (ctx &&
|
|
715
|
+
axios_1.default.isAxiosError(error) && // check if the message requires a reupload
|
|
708
716
|
REUPLOAD_REQUIRED_STATUS.includes((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
|
|
709
717
|
ctx.logger.info({ key: message.key }, 'sending reupload media request...');
|
|
710
718
|
// request reupload
|
|
@@ -752,11 +760,11 @@ exports.downloadMediaMessage = downloadMediaMessage;
|
|
|
752
760
|
/** Checks whether the given message is a media message; if it is returns the inner content */
|
|
753
761
|
const assertMediaContent = (content) => {
|
|
754
762
|
content = (0, exports.extractMessageContent)(content);
|
|
755
|
-
const mediaContent = (content === null || content === void 0 ? void 0 : content.documentMessage)
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
763
|
+
const mediaContent = (content === null || content === void 0 ? void 0 : content.documentMessage) ||
|
|
764
|
+
(content === null || content === void 0 ? void 0 : content.imageMessage) ||
|
|
765
|
+
(content === null || content === void 0 ? void 0 : content.videoMessage) ||
|
|
766
|
+
(content === null || content === void 0 ? void 0 : content.audioMessage) ||
|
|
767
|
+
(content === null || content === void 0 ? void 0 : content.stickerMessage);
|
|
760
768
|
if (!mediaContent) {
|
|
761
769
|
throw new boom_1.Boom('given message is not a media message', { statusCode: 400, data: content });
|
|
762
770
|
}
|
|
@@ -36,6 +36,6 @@ type PollContext = {
|
|
|
36
36
|
* @param ctx additional info about the poll required for decryption
|
|
37
37
|
* @returns list of SHA256 options
|
|
38
38
|
*/
|
|
39
|
-
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid
|
|
39
|
+
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }: PollContext): proto.Message.PollVoteMessage;
|
|
40
40
|
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options }: ProcessMessageContext) => Promise<void>;
|
|
41
41
|
export default processMessage;
|
|
@@ -15,9 +15,7 @@ const REAL_MSG_STUB_TYPES = new Set([
|
|
|
15
15
|
Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
|
|
16
16
|
Types_1.WAMessageStubType.CALL_MISSED_VOICE
|
|
17
17
|
]);
|
|
18
|
-
const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
|
|
19
|
-
Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
|
|
20
|
-
]);
|
|
18
|
+
const REAL_MSG_REQ_ME_STUB_TYPES = new Set([Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD]);
|
|
21
19
|
/** Cleans a received message to further processing */
|
|
22
20
|
const cleanMessage = (message, meId) => {
|
|
23
21
|
// ensure remoteJid and participant doesn't have device or agent in it
|
|
@@ -39,9 +37,9 @@ const cleanMessage = (message, meId) => {
|
|
|
39
37
|
// we've to correct the key to be from them, or some other participant
|
|
40
38
|
msgKey.fromMe = !msgKey.fromMe
|
|
41
39
|
? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId)
|
|
42
|
-
// if the message being reacted to, was from them
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
: // if the message being reacted to, was from them
|
|
41
|
+
// fromMe automatically becomes false
|
|
42
|
+
false;
|
|
45
43
|
// set the remoteJid to being the same as the chat the message came from
|
|
46
44
|
msgKey.remoteJid = message.key.remoteJid;
|
|
47
45
|
// set participant of the message
|
|
@@ -54,26 +52,24 @@ const isRealMessage = (message, meId) => {
|
|
|
54
52
|
var _a;
|
|
55
53
|
const normalizedContent = (0, messages_1.normalizeMessageContent)(message.message);
|
|
56
54
|
const hasSomeContent = !!(0, messages_1.getContentType)(normalizedContent);
|
|
57
|
-
return (!!normalizedContent
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
&&
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
return ((!!normalizedContent ||
|
|
56
|
+
REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
|
|
57
|
+
(REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType) &&
|
|
58
|
+
((_a = message.messageStubParameters) === null || _a === void 0 ? void 0 : _a.some(p => (0, WABinary_1.areJidsSameUser)(meId, p))))) &&
|
|
59
|
+
hasSomeContent &&
|
|
60
|
+
!(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage) &&
|
|
61
|
+
!(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.reactionMessage) &&
|
|
62
|
+
!(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.pollUpdateMessage));
|
|
65
63
|
};
|
|
66
64
|
exports.isRealMessage = isRealMessage;
|
|
67
|
-
const shouldIncrementChatUnread = (message) =>
|
|
65
|
+
const shouldIncrementChatUnread = (message) => !message.key.fromMe && !message.messageStubType;
|
|
68
66
|
exports.shouldIncrementChatUnread = shouldIncrementChatUnread;
|
|
69
67
|
/**
|
|
70
68
|
* Get the ID of the chat from the given key.
|
|
71
69
|
* Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
|
|
72
70
|
*/
|
|
73
71
|
const getChatId = ({ remoteJid, participant, fromMe }) => {
|
|
74
|
-
if ((0, WABinary_1.isJidBroadcast)(remoteJid)
|
|
75
|
-
&& !(0, WABinary_1.isJidStatusBroadcast)(remoteJid)
|
|
76
|
-
&& !fromMe) {
|
|
72
|
+
if ((0, WABinary_1.isJidBroadcast)(remoteJid) && !(0, WABinary_1.isJidStatusBroadcast)(remoteJid) && !fromMe) {
|
|
77
73
|
return participant;
|
|
78
74
|
}
|
|
79
75
|
return remoteJid;
|
|
@@ -85,7 +81,7 @@ exports.getChatId = getChatId;
|
|
|
85
81
|
* @param ctx additional info about the poll required for decryption
|
|
86
82
|
* @returns list of SHA256 options
|
|
87
83
|
*/
|
|
88
|
-
function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid
|
|
84
|
+
function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
|
|
89
85
|
const sign = Buffer.concat([
|
|
90
86
|
toBinary(pollMsgId),
|
|
91
87
|
toBinary(pollCreatorJid),
|
|
@@ -119,8 +115,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
119
115
|
const content = (0, messages_1.normalizeMessageContent)(message.message);
|
|
120
116
|
// unarchive chat if it's a real message, or someone reacted to our message
|
|
121
117
|
// and we've the unarchive chats setting on
|
|
122
|
-
if ((isRealMsg || ((_b = (_a = content === null || content === void 0 ? void 0 : content.reactionMessage) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.fromMe))
|
|
123
|
-
&& (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
|
|
118
|
+
if ((isRealMsg || ((_b = (_a = content === null || content === void 0 ? void 0 : content.reactionMessage) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.fromMe)) && (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
|
|
124
119
|
chat.archived = false;
|
|
125
120
|
chat.readOnly = false;
|
|
126
121
|
}
|
|
@@ -135,7 +130,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
135
130
|
histNotification,
|
|
136
131
|
process,
|
|
137
132
|
id: message.key.id,
|
|
138
|
-
isLatest
|
|
133
|
+
isLatest
|
|
139
134
|
}, 'got history notification');
|
|
140
135
|
if (process) {
|
|
141
136
|
if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
|
@@ -149,9 +144,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
149
144
|
const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
150
145
|
ev.emit('messaging-history.set', {
|
|
151
146
|
...data,
|
|
152
|
-
isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
|
|
153
|
-
? isLatest
|
|
154
|
-
: undefined,
|
|
147
|
+
isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND ? isLatest : undefined,
|
|
155
148
|
peerDataRequestSessionId: histNotification.peerDataRequestSessionId
|
|
156
149
|
});
|
|
157
150
|
}
|
|
@@ -238,18 +231,20 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
238
231
|
else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
|
|
239
232
|
const reaction = {
|
|
240
233
|
...content.reactionMessage,
|
|
241
|
-
key: message.key
|
|
234
|
+
key: message.key
|
|
242
235
|
};
|
|
243
|
-
ev.emit('messages.reaction', [
|
|
236
|
+
ev.emit('messages.reaction', [
|
|
237
|
+
{
|
|
244
238
|
reaction,
|
|
245
|
-
key: (_e = content.reactionMessage) === null || _e === void 0 ? void 0 : _e.key
|
|
246
|
-
}
|
|
239
|
+
key: (_e = content.reactionMessage) === null || _e === void 0 ? void 0 : _e.key
|
|
240
|
+
}
|
|
241
|
+
]);
|
|
247
242
|
}
|
|
248
243
|
else if (message.messageStubType) {
|
|
249
244
|
const jid = (_f = message.key) === null || _f === void 0 ? void 0 : _f.remoteJid;
|
|
250
245
|
//let actor = whatsappID (message.participant)
|
|
251
246
|
let participants;
|
|
252
|
-
const emitParticipantsUpdate = (action) =>
|
|
247
|
+
const emitParticipantsUpdate = (action) => ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action });
|
|
253
248
|
const emitGroupUpdate = (update) => {
|
|
254
249
|
var _a;
|
|
255
250
|
ev.emit('groups.update', [{ id: jid, ...update, author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined }]);
|
package/lib/Utils/signal.js
CHANGED
|
@@ -34,7 +34,7 @@ const generateOrGetPreKeys = (creds, range) => {
|
|
|
34
34
|
return {
|
|
35
35
|
newPreKeys,
|
|
36
36
|
lastPreKeyId,
|
|
37
|
-
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
37
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
exports.generateOrGetPreKeys = generateOrGetPreKeys;
|
|
@@ -58,11 +58,13 @@ const xmppPreKey = (pair, id) => ({
|
|
|
58
58
|
});
|
|
59
59
|
exports.xmppPreKey = xmppPreKey;
|
|
60
60
|
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
61
|
-
const extractKey = (key) =>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
const extractKey = (key) => key
|
|
62
|
+
? {
|
|
63
|
+
keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
|
|
64
|
+
publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
|
|
65
|
+
signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature')
|
|
66
|
+
}
|
|
67
|
+
: undefined;
|
|
66
68
|
const nodes = (0, WABinary_1.getBinaryNodeChildren)((0, WABinary_1.getBinaryNodeChild)(node, 'list'), 'user');
|
|
67
69
|
for (const node of nodes) {
|
|
68
70
|
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
@@ -138,7 +140,7 @@ const getNextPreKeysNode = async (state, count) => {
|
|
|
138
140
|
attrs: {
|
|
139
141
|
xmlns: 'encrypt',
|
|
140
142
|
type: 'set',
|
|
141
|
-
to: WABinary_1.S_WHATSAPP_NET
|
|
143
|
+
to: WABinary_1.S_WHATSAPP_NET
|
|
142
144
|
},
|
|
143
145
|
content: [
|
|
144
146
|
{ tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
|
|
@@ -75,8 +75,7 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
catch (_a) {
|
|
79
|
-
}
|
|
78
|
+
catch (_a) { }
|
|
80
79
|
};
|
|
81
80
|
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
82
81
|
if (folderInfo) {
|
|
@@ -88,7 +87,7 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
88
87
|
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
89
88
|
}
|
|
90
89
|
const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
|
|
91
|
-
const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
|
|
90
|
+
const creds = (await readData('creds.json')) || (0, auth_utils_1.initAuthCreds)();
|
|
92
91
|
return {
|
|
93
92
|
state: {
|
|
94
93
|
creds,
|
|
@@ -14,7 +14,7 @@ const getUserAgent = (config) => {
|
|
|
14
14
|
appVersion: {
|
|
15
15
|
primary: config.version[0],
|
|
16
16
|
secondary: config.version[1],
|
|
17
|
-
tertiary: config.version[2]
|
|
17
|
+
tertiary: config.version[2]
|
|
18
18
|
},
|
|
19
19
|
platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
20
20
|
releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
@@ -24,12 +24,12 @@ const getUserAgent = (config) => {
|
|
|
24
24
|
localeLanguageIso6391: 'en',
|
|
25
25
|
mnc: '000',
|
|
26
26
|
mcc: '000',
|
|
27
|
-
localeCountryIso31661Alpha2: config.countryCode
|
|
27
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
const PLATFORM_MAP = {
|
|
31
31
|
'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
32
|
-
|
|
32
|
+
Windows: WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
33
33
|
};
|
|
34
34
|
const getWebInfo = (config) => {
|
|
35
35
|
let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
@@ -42,7 +42,7 @@ const getClientPayload = (config) => {
|
|
|
42
42
|
const payload = {
|
|
43
43
|
connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
44
44
|
connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
45
|
-
userAgent: getUserAgent(config)
|
|
45
|
+
userAgent: getUserAgent(config)
|
|
46
46
|
};
|
|
47
47
|
payload.webInfo = getWebInfo(config);
|
|
48
48
|
return payload;
|
|
@@ -54,7 +54,7 @@ const generateLoginNode = (userJid, config) => {
|
|
|
54
54
|
passive: false,
|
|
55
55
|
pull: true,
|
|
56
56
|
username: +user,
|
|
57
|
-
device: device
|
|
57
|
+
device: device
|
|
58
58
|
};
|
|
59
59
|
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
60
60
|
};
|
|
@@ -72,7 +72,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
72
72
|
const companion = {
|
|
73
73
|
os: config.browser[0],
|
|
74
74
|
platformType: getPlatformType(config.browser[1]),
|
|
75
|
-
requireFullSync: config.syncFullHistory
|
|
75
|
+
requireFullSync: config.syncFullHistory
|
|
76
76
|
};
|
|
77
77
|
const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
|
|
78
78
|
const registerPayload = {
|
|
@@ -87,8 +87,8 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
87
87
|
eIdent: signedIdentityKey.public,
|
|
88
88
|
eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
|
|
89
89
|
eSkeyVal: signedPreKey.keyPair.public,
|
|
90
|
-
eSkeySig: signedPreKey.signature
|
|
91
|
-
}
|
|
90
|
+
eSkeySig: signedPreKey.signature
|
|
91
|
+
}
|
|
92
92
|
};
|
|
93
93
|
return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
|
|
94
94
|
};
|
|
@@ -105,21 +105,21 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
105
105
|
}
|
|
106
106
|
const bizName = businessNode === null || businessNode === void 0 ? void 0 : businessNode.attrs.name;
|
|
107
107
|
const jid = deviceNode.attrs.jid;
|
|
108
|
-
const { details, hmac } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
109
|
-
|
|
110
|
-
const
|
|
108
|
+
const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
109
|
+
const isHostedAccount = accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED;
|
|
110
|
+
const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0);
|
|
111
|
+
const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
111
112
|
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
112
113
|
throw new boom_1.Boom('Invalid account signature');
|
|
113
114
|
}
|
|
114
115
|
const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
|
|
115
116
|
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
116
|
-
// verify the device signature matches
|
|
117
117
|
const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public]);
|
|
118
118
|
if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
119
119
|
throw new boom_1.Boom('Failed to verify account signature');
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
const deviceMsg = Buffer.concat([
|
|
121
|
+
const devicePrefix = isHostedAccount ? Buffer.from([6, 6]) : Buffer.from([6, 1]);
|
|
122
|
+
const deviceMsg = Buffer.concat([devicePrefix, deviceDetails, signedIdentityKey.public, accountSignatureKey]);
|
|
123
123
|
account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
124
124
|
const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
|
|
125
125
|
const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
|
|
@@ -129,7 +129,7 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
129
129
|
attrs: {
|
|
130
130
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
131
131
|
type: 'result',
|
|
132
|
-
id: msgId
|
|
132
|
+
id: msgId
|
|
133
133
|
},
|
|
134
134
|
content: [
|
|
135
135
|
{
|
|
@@ -148,10 +148,7 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
148
148
|
const authUpdate = {
|
|
149
149
|
account,
|
|
150
150
|
me: { id: jid, name: bizName },
|
|
151
|
-
signalIdentities: [
|
|
152
|
-
...(signalIdentities || []),
|
|
153
|
-
identity
|
|
154
|
-
],
|
|
151
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
155
152
|
platform: platformNode === null || platformNode === void 0 ? void 0 : platformNode.attrs.name
|
|
156
153
|
};
|
|
157
154
|
return {
|
|
@@ -168,8 +165,6 @@ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
|
168
165
|
if (!includeSignatureKey || !((_a = account.accountSignatureKey) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
169
166
|
account.accountSignatureKey = null;
|
|
170
167
|
}
|
|
171
|
-
return WAProto_1.proto.ADVSignedDeviceIdentity
|
|
172
|
-
.encode(account)
|
|
173
|
-
.finish();
|
|
168
|
+
return WAProto_1.proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
174
169
|
};
|
|
175
170
|
exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
|