@d0v3riz/baileys 6.7.19 → 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.
Files changed (113) hide show
  1. package/README.md +1263 -4
  2. package/WAProto/GenerateStatics.sh +2 -0
  3. package/WAProto/WAProto.proto +4633 -0
  4. package/WAProto/index.d.ts +3212 -122
  5. package/WAProto/index.js +9635 -299
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +1 -1
  8. package/lib/Defaults/index.js +16 -16
  9. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  10. package/lib/Signal/Group/ciphertext-message.js +15 -0
  11. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  12. package/lib/Signal/Group/group-session-builder.js +64 -0
  13. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  14. package/lib/Signal/Group/group_cipher.js +96 -0
  15. package/lib/Signal/Group/index.d.ts +11 -0
  16. package/lib/Signal/Group/index.js +57 -0
  17. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  18. package/lib/Signal/Group/keyhelper.js +55 -0
  19. package/lib/Signal/Group/queue-job.d.ts +1 -0
  20. package/lib/Signal/Group/queue-job.js +57 -0
  21. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  22. package/lib/Signal/Group/sender-chain-key.js +34 -0
  23. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  24. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  25. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  26. package/lib/Signal/Group/sender-key-message.js +69 -0
  27. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  28. package/lib/Signal/Group/sender-key-name.js +51 -0
  29. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  30. package/lib/Signal/Group/sender-key-record.js +53 -0
  31. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  32. package/lib/Signal/Group/sender-key-state.js +99 -0
  33. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  34. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +29 -39
  35. package/lib/Signal/libsignal.js +33 -20
  36. package/lib/Socket/Client/websocket.js +1 -1
  37. package/lib/Socket/business.d.ts +5 -5
  38. package/lib/Socket/business.js +5 -5
  39. package/lib/Socket/chats.d.ts +4 -4
  40. package/lib/Socket/chats.js +70 -70
  41. package/lib/Socket/groups.d.ts +6 -6
  42. package/lib/Socket/groups.js +39 -24
  43. package/lib/Socket/index.d.ts +5 -5
  44. package/lib/Socket/index.js +2 -2
  45. package/lib/Socket/messages-recv.d.ts +5 -5
  46. package/lib/Socket/messages-recv.js +73 -56
  47. package/lib/Socket/messages-send.d.ts +5 -5
  48. package/lib/Socket/messages-send.js +53 -46
  49. package/lib/Socket/socket.d.ts +3 -3
  50. package/lib/Socket/socket.js +22 -29
  51. package/lib/Socket/usync.d.ts +3 -3
  52. package/lib/Socket/usync.js +10 -15
  53. package/lib/Types/Auth.d.ts +1 -1
  54. package/lib/Types/Chat.d.ts +1 -1
  55. package/lib/Types/Chat.js +7 -1
  56. package/lib/Types/Contact.d.ts +4 -0
  57. package/lib/Types/Events.d.ts +1 -1
  58. package/lib/Types/GroupMetadata.d.ts +7 -3
  59. package/lib/Types/Message.d.ts +6 -1
  60. package/lib/Types/Socket.d.ts +3 -3
  61. package/lib/Utils/auth-utils.js +8 -9
  62. package/lib/Utils/baileys-event-stream.js +1 -1
  63. package/lib/Utils/business.js +9 -11
  64. package/lib/Utils/chat-utils.d.ts +4 -4
  65. package/lib/Utils/chat-utils.js +64 -69
  66. package/lib/Utils/crypto.js +4 -10
  67. package/lib/Utils/decode-wa-message.js +6 -2
  68. package/lib/Utils/event-buffer.d.ts +2 -2
  69. package/lib/Utils/event-buffer.js +9 -13
  70. package/lib/Utils/generics.d.ts +1 -1
  71. package/lib/Utils/generics.js +28 -30
  72. package/lib/Utils/history.js +10 -5
  73. package/lib/Utils/link-preview.js +5 -9
  74. package/lib/Utils/lt-hash.js +2 -2
  75. package/lib/Utils/make-mutex.js +1 -1
  76. package/lib/Utils/messages-media.js +40 -55
  77. package/lib/Utils/messages.d.ts +1 -1
  78. package/lib/Utils/messages.js +71 -61
  79. package/lib/Utils/process-message.d.ts +1 -1
  80. package/lib/Utils/process-message.js +25 -30
  81. package/lib/Utils/signal.js +9 -7
  82. package/lib/Utils/use-multi-file-auth-state.js +2 -3
  83. package/lib/Utils/validate-connection.js +17 -22
  84. package/lib/WABinary/constants.d.ts +4 -4
  85. package/lib/WABinary/constants.js +1271 -8
  86. package/lib/WABinary/decode.js +2 -1
  87. package/lib/WABinary/encode.js +2 -2
  88. package/lib/WABinary/generic-utils.js +1 -1
  89. package/lib/WABinary/jid-utils.js +8 -11
  90. package/lib/WAM/constants.js +2252 -2359
  91. package/lib/WAM/encode.js +5 -7
  92. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  93. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
  94. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  95. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
  96. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  97. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
  98. package/lib/WAUSync/USyncQuery.js +17 -13
  99. package/package.json +11 -6
  100. package/WASignalGroup/GroupProtocol.js +0 -1697
  101. package/WASignalGroup/ciphertext_message.js +0 -16
  102. package/WASignalGroup/group_cipher.js +0 -120
  103. package/WASignalGroup/group_session_builder.js +0 -46
  104. package/WASignalGroup/index.js +0 -5
  105. package/WASignalGroup/keyhelper.js +0 -21
  106. package/WASignalGroup/protobufs.js +0 -3
  107. package/WASignalGroup/queue_job.js +0 -69
  108. package/WASignalGroup/sender_chain_key.js +0 -50
  109. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  110. package/WASignalGroup/sender_key_message.js +0 -92
  111. package/WASignalGroup/sender_key_name.js +0 -70
  112. package/WASignalGroup/sender_key_record.js +0 -56
  113. package/WASignalGroup/sender_key_state.js +0 -129
@@ -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
- '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,
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) { // ignore if fails
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
- ('url' in uploadData.media) &&
87
+ 'url' in uploadData.media &&
87
88
  !!uploadData.media.url &&
88
- !!options.mediaCache && (
89
- // generate the key
90
- mediaType + ':' + uploadData.media.url.toString());
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,8 +107,7 @@ 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;
@@ -120,7 +120,11 @@ 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(encFilePath, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
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
  })(),
@@ -152,9 +156,8 @@ 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
- .finally(async () => {
159
+ })()
160
+ ]).finally(async () => {
158
161
  try {
159
162
  await fs_1.promises.unlink(encFilePath);
160
163
  if (originalFilePath) {
@@ -302,9 +305,11 @@ const generateWAMessageContent = async (message, options) => {
302
305
  m = (0, exports.generateForwardMessageContent)(message.forward, message.force);
303
306
  }
304
307
  else if ('disappearingMessagesInChat' in message) {
305
- const exp = typeof message.disappearingMessagesInChat === 'boolean' ?
306
- (message.disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
307
- message.disappearingMessagesInChat;
308
+ const exp = typeof message.disappearingMessagesInChat === 'boolean'
309
+ ? message.disappearingMessagesInChat
310
+ ? Defaults_1.WA_DEFAULT_EPHEMERAL
311
+ : 0
312
+ : message.disappearingMessagesInChat;
308
313
  m = (0, exports.prepareDisappearingMessageSettingContent)(exp);
309
314
  }
310
315
  else if ('groupInvite' in message) {
@@ -340,14 +345,14 @@ const generateWAMessageContent = async (message, options) => {
340
345
  m.templateButtonReplyMessage = {
341
346
  selectedDisplayText: message.buttonReply.displayText,
342
347
  selectedId: message.buttonReply.id,
343
- selectedIndex: message.buttonReply.index,
348
+ selectedIndex: message.buttonReply.index
344
349
  };
345
350
  break;
346
351
  case 'plain':
347
352
  m.buttonsResponseMessage = {
348
353
  selectedButtonId: message.buttonReply.id,
349
354
  selectedDisplayText: message.buttonReply.displayText,
350
- type: WAProto_1.proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT,
355
+ type: WAProto_1.proto.Message.ButtonsResponseMessage.Type.DISPLAY_TEXT
351
356
  };
352
357
  break;
353
358
  }
@@ -362,7 +367,7 @@ const generateWAMessageContent = async (message, options) => {
362
367
  ...message,
363
368
  product: {
364
369
  ...message.product,
365
- productImage: imageMessage,
370
+ productImage: imageMessage
366
371
  }
367
372
  });
368
373
  }
@@ -375,18 +380,19 @@ const generateWAMessageContent = async (message, options) => {
375
380
  if (!Array.isArray(message.poll.values)) {
376
381
  throw new boom_1.Boom('Invalid poll values', { statusCode: 400 });
377
382
  }
378
- if (message.poll.selectableCount < 0
379
- || message.poll.selectableCount > message.poll.values.length) {
380
- throw new boom_1.Boom(`poll.selectableCount in poll should be >= 0 and <= ${message.poll.values.length}`, { statusCode: 400 });
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
+ });
381
387
  }
382
388
  m.messageContextInfo = {
383
389
  // encKey
384
- messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32),
390
+ messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32)
385
391
  };
386
392
  const pollCreationMessage = {
387
393
  name: message.poll.name,
388
394
  selectableOptionsCount: message.poll.selectableCount,
389
- options: message.poll.values.map(optionName => ({ optionName })),
395
+ options: message.poll.values.map(optionName => ({ optionName }))
390
396
  };
391
397
  if (message.poll.toAnnouncementGroup) {
392
398
  // poll v2 is for community announcement groups (single select and multiple)
@@ -451,7 +457,9 @@ const generateWAMessageFromContent = (jid, message, options) => {
451
457
  const timestamp = (0, generics_1.unixTimestampSeconds)(options.timestamp);
452
458
  const { quoted, userJid, contextInfo } = options;
453
459
  if (quoted) {
454
- const participant = quoted.key.fromMe ? userJid : (quoted.participant || quoted.key.participant || quoted.key.remoteJid);
460
+ const participant = quoted.key.fromMe
461
+ ? userJid
462
+ : quoted.participant || quoted.key.participant || quoted.key.remoteJid;
455
463
  let quotedMsg = (0, exports.normalizeMessageContent)(quoted.message);
456
464
  const msgType = (0, exports.getContentType)(quotedMsg);
457
465
  // strip any redundant properties
@@ -486,7 +494,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
486
494
  key !== 'ephemeralMessage') {
487
495
  innerMessage[key].contextInfo = {
488
496
  ...(innerMessage[key].contextInfo || {}),
489
- expiration: options.ephemeralExpiration || Defaults_1.WA_DEFAULT_EPHEMERAL,
497
+ expiration: options.ephemeralExpiration || Defaults_1.WA_DEFAULT_EPHEMERAL
490
498
  //ephemeralSettingTimestamp: options.ephemeralOptions.eph_setting_ts?.toString()
491
499
  };
492
500
  }
@@ -495,7 +503,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
495
503
  key: {
496
504
  remoteJid: jid,
497
505
  fromMe: true,
498
- 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)()
499
507
  },
500
508
  message: message,
501
509
  messageTimestamp: timestamp,
@@ -542,12 +550,12 @@ const normalizeMessageContent = (content) => {
542
550
  }
543
551
  return content;
544
552
  function getFutureProofMessage(message) {
545
- return ((message === null || message === void 0 ? void 0 : message.ephemeralMessage)
546
- || (message === null || message === void 0 ? void 0 : message.viewOnceMessage)
547
- || (message === null || message === void 0 ? void 0 : message.documentWithCaptionMessage)
548
- || (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2)
549
- || (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension)
550
- || (message === null || message === void 0 ? void 0 : message.editedMessage));
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));
551
559
  }
552
560
  };
553
561
  exports.normalizeMessageContent = normalizeMessageContent;
@@ -572,9 +580,7 @@ const extractMessageContent = (content) => {
572
580
  }
573
581
  else {
574
582
  return {
575
- conversation: 'contentText' in msg
576
- ? msg.contentText
577
- : ('hydratedContentText' in msg ? msg.hydratedContentText : '')
583
+ conversation: 'contentText' in msg ? msg.contentText : 'hydratedContentText' in msg ? msg.hydratedContentText : ''
578
584
  };
579
585
  }
580
586
  };
@@ -597,11 +603,15 @@ exports.extractMessageContent = extractMessageContent;
597
603
  /**
598
604
  * Returns the device predicted by message ID
599
605
  */
600
- const getDevice = (id) => /^3A.{18}$/.test(id) ? 'ios' :
601
- /^3E.{20}$/.test(id) ? 'web' :
602
- /^(.{21}|.{32})$/.test(id) ? 'android' :
603
- /^(3F|.{18}$)/.test(id) ? 'desktop' :
604
- 'unknown';
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';
605
615
  exports.getDevice = getDevice;
606
616
  /** Upserts a receipt in the message */
607
617
  const updateMessageWithReceipt = (msg, receipt) => {
@@ -618,11 +628,9 @@ exports.updateMessageWithReceipt = updateMessageWithReceipt;
618
628
  /** Update the message with a new reaction */
619
629
  const updateMessageWithReaction = (msg, reaction) => {
620
630
  const authorID = (0, generics_1.getKeyAuthor)(reaction.key);
621
- const reactions = (msg.reactions || [])
622
- .filter(r => (0, generics_1.getKeyAuthor)(r.key) !== authorID);
623
- if (reaction.text) {
624
- reactions.push(reaction);
625
- }
631
+ const reactions = (msg.reactions || []).filter(r => (0, generics_1.getKeyAuthor)(r.key) !== authorID);
632
+ reaction.text = reaction.text || '';
633
+ reactions.push(reaction);
626
634
  msg.reactions = reactions;
627
635
  };
628
636
  exports.updateMessageWithReaction = updateMessageWithReaction;
@@ -630,8 +638,7 @@ exports.updateMessageWithReaction = updateMessageWithReaction;
630
638
  const updateMessageWithPollUpdate = (msg, update) => {
631
639
  var _a, _b;
632
640
  const authorID = (0, generics_1.getKeyAuthor)(update.pollUpdateMessageKey);
633
- const reactions = (msg.pollUpdates || [])
634
- .filter(r => (0, generics_1.getKeyAuthor)(r.pollUpdateMessageKey) !== authorID);
641
+ const reactions = (msg.pollUpdates || []).filter(r => (0, generics_1.getKeyAuthor)(r.pollUpdateMessageKey) !== authorID);
635
642
  if ((_b = (_a = update.vote) === null || _a === void 0 ? void 0 : _a.selectedOptions) === null || _b === void 0 ? void 0 : _b.length) {
636
643
  reactions.push(update);
637
644
  }
@@ -646,7 +653,10 @@ exports.updateMessageWithPollUpdate = updateMessageWithPollUpdate;
646
653
  */
647
654
  function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
648
655
  var _a, _b, _c;
649
- const opts = ((_a = message === null || message === void 0 ? void 0 : message.pollCreationMessage) === null || _a === void 0 ? void 0 : _a.options) || ((_b = message === null || message === void 0 ? void 0 : message.pollCreationMessageV2) === null || _b === void 0 ? void 0 : _b.options) || ((_c = message === null || message === void 0 ? void 0 : message.pollCreationMessageV3) === null || _c === void 0 ? void 0 : _c.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
+ [];
650
660
  const voteHashMap = opts.reduce((acc, opt) => {
651
661
  const hash = (0, crypto_2.sha256)(Buffer.from(opt.optionName || '')).toString();
652
662
  acc[hash] = {
@@ -699,10 +709,10 @@ const REUPLOAD_REQUIRED_STATUS = [410, 404];
699
709
  * Downloads the given message. Throws an error if it's not a media message
700
710
  */
701
711
  const downloadMediaMessage = async (message, type, options, ctx) => {
702
- const result = await downloadMsg()
703
- .catch(async (error) => {
712
+ const result = await downloadMsg().catch(async (error) => {
704
713
  var _a;
705
- if (ctx && axios_1.default.isAxiosError(error) && // check if the message requires a reupload
714
+ if (ctx &&
715
+ axios_1.default.isAxiosError(error) && // check if the message requires a reupload
706
716
  REUPLOAD_REQUIRED_STATUS.includes((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
707
717
  ctx.logger.info({ key: message.key }, 'sending reupload media request...');
708
718
  // request reupload
@@ -750,11 +760,11 @@ exports.downloadMediaMessage = downloadMediaMessage;
750
760
  /** Checks whether the given message is a media message; if it is returns the inner content */
751
761
  const assertMediaContent = (content) => {
752
762
  content = (0, exports.extractMessageContent)(content);
753
- const mediaContent = (content === null || content === void 0 ? void 0 : content.documentMessage)
754
- || (content === null || content === void 0 ? void 0 : content.imageMessage)
755
- || (content === null || content === void 0 ? void 0 : content.videoMessage)
756
- || (content === null || content === void 0 ? void 0 : content.audioMessage)
757
- || (content === null || content === void 0 ? void 0 : content.stickerMessage);
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);
758
768
  if (!mediaContent) {
759
769
  throw new boom_1.Boom('given message is not a media message', { statusCode: 400, data: content });
760
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, }: PollContext): proto.Message.PollVoteMessage;
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
- // fromMe automatically becomes false
44
- : false;
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
- || REAL_MSG_STUB_TYPES.has(message.messageStubType)
59
- || (REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)
60
- && ((_a = message.messageStubParameters) === null || _a === void 0 ? void 0 : _a.some(p => (0, WABinary_1.areJidsSameUser)(meId, p)))))
61
- && hasSomeContent
62
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.protocolMessage)
63
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.reactionMessage)
64
- && !(normalizedContent === null || normalizedContent === void 0 ? void 0 : normalizedContent.pollUpdateMessage);
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) => (!message.key.fromMe && !message.messageStubType);
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) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, 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 }]);
@@ -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) => (key ? ({
62
- keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
63
- publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
64
- signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature'),
65
- }) : undefined);
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
- 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
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
- // check HMAC matches
110
- const advSign = (0, crypto_2.hmacSign)(details, Buffer.from(advSecretKey, 'base64'));
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
- // sign the details with our identity key
122
- const deviceMsg = Buffer.concat([Buffer.from([6, 1]), deviceDetails, signedIdentityKey.public, accountSignatureKey]);
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;