@d0v3riz/baileys 6.7.2 → 6.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +4 -3
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Socket/business.d.ts +2 -0
  4. package/lib/Socket/business.js +1 -0
  5. package/lib/Socket/chats.d.ts +5 -6
  6. package/lib/Socket/chats.js +7 -2
  7. package/lib/Socket/groups.d.ts +1 -0
  8. package/lib/Socket/groups.js +2 -1
  9. package/lib/Socket/index.d.ts +2 -0
  10. package/lib/Socket/messages-recv.d.ts +1 -0
  11. package/lib/Socket/messages-recv.js +32 -15
  12. package/lib/Socket/messages-send.d.ts +1 -0
  13. package/lib/Socket/messages-send.js +8 -3
  14. package/lib/Socket/registration.d.ts +2 -0
  15. package/lib/Socket/socket.js +16 -3
  16. package/lib/Store/make-in-memory-store.d.ts +2 -2
  17. package/lib/Store/make-in-memory-store.js +6 -43
  18. package/lib/Types/Auth.d.ts +1 -0
  19. package/lib/Types/Chat.d.ts +1 -0
  20. package/lib/Types/Events.d.ts +8 -1
  21. package/lib/Types/GroupMetadata.d.ts +3 -1
  22. package/lib/Types/index.d.ts +7 -0
  23. package/lib/Utils/auth-utils.js +1 -0
  24. package/lib/Utils/crypto.d.ts +1 -1
  25. package/lib/Utils/crypto.js +4 -2
  26. package/lib/Utils/generics.d.ts +4 -9
  27. package/lib/Utils/generics.js +34 -8
  28. package/lib/Utils/messages-media.d.ts +1 -0
  29. package/lib/Utils/messages-media.js +8 -14
  30. package/lib/Utils/messages.d.ts +2 -1
  31. package/lib/Utils/messages.js +9 -7
  32. package/lib/Utils/noise-handler.d.ts +3 -2
  33. package/lib/Utils/noise-handler.js +18 -5
  34. package/lib/Utils/process-message.js +15 -2
  35. package/lib/Utils/signal.js +26 -16
  36. package/lib/Utils/use-multi-file-auth-state.js +16 -3
  37. package/lib/WABinary/decode.d.ts +2 -2
  38. package/lib/WABinary/decode.js +6 -4
  39. package/lib/WABinary/encode.d.ts +1 -1
  40. package/lib/WABinary/encode.js +8 -4
  41. package/package.json +9 -7
package/README.md CHANGED
@@ -324,13 +324,13 @@ const sock = makeWASocket({ })
324
324
  // the store can listen from a new socket once the current socket outlives its lifetime
325
325
  store.bind(sock.ev)
326
326
 
327
- sock.ev.on('chats.set', () => {
327
+ sock.ev.on('chats.upsert', () => {
328
328
  // can use "store.chats" however you want, even after the socket dies out
329
329
  // "chats" => a KeyedDB instance
330
330
  console.log('got chats', store.chats.all())
331
331
  })
332
332
 
333
- sock.ev.on('contacts.set', () => {
333
+ sock.ev.on('contacts.upsert', () => {
334
334
  console.log('got contacts', Object.values(store.contacts))
335
335
  })
336
336
 
@@ -422,7 +422,8 @@ await sock.sendMessage(
422
422
  {
423
423
  video: "./Media/ma_gif.mp4",
424
424
  caption: "hello!",
425
- gifPlayback: true
425
+ gifPlayback: true,
426
+ ptv: false // if set to true, will send as a `video note`
426
427
  }
427
428
  )
428
429
 
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 2403, 2]
2
+ "version": [2, 2413, 1]
3
3
  }
@@ -2,6 +2,7 @@
2
2
  import { GetCatalogOptions, ProductCreate, ProductUpdate, SocketConfig } from '../Types';
3
3
  import { BinaryNode } from '../WABinary';
4
4
  export declare const makeBusinessSocket: (config: SocketConfig) => {
5
+ logger: import("pino").Logger<import("pino").LoggerOptions>;
5
6
  getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
6
7
  getCatalog: ({ jid, limit, cursor }: GetCatalogOptions) => Promise<{
7
8
  products: import("../Types").Product[];
@@ -85,6 +86,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
85
86
  updateProfileStatus: (status: string) => Promise<void>;
86
87
  updateProfileName: (name: string) => Promise<void>;
87
88
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
89
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
88
90
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
89
91
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
90
92
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
@@ -248,6 +248,7 @@ const makeBusinessSocket = (config) => {
248
248
  };
249
249
  return {
250
250
  ...sock,
251
+ logger: config.logger,
251
252
  getOrderDetails,
252
253
  getCatalog,
253
254
  getCollections,
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Boom } from '@hapi/boom';
3
3
  import { proto } from '../../WAProto';
4
- import { ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
4
+ import { ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
5
5
  import { BinaryNode } from '../WABinary';
6
6
  export declare const makeChatsSocket: (config: SocketConfig) => {
7
7
  processingMutex: {
@@ -29,6 +29,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
29
29
  updateProfileStatus: (status: string) => Promise<void>;
30
30
  updateProfileName: (name: string) => Promise<void>;
31
31
  updateBlockStatus: (jid: string, action: 'block' | 'unblock') => Promise<void>;
32
+ updateCallPrivacy: (value: WAPrivacyCallValue) => Promise<void>;
32
33
  updateLastSeenPrivacy: (value: WAPrivacyValue) => Promise<void>;
33
34
  updateOnlinePrivacy: (value: WAPrivacyOnlineValue) => Promise<void>;
34
35
  updateProfilePicturePrivacy: (value: WAPrivacyValue) => Promise<void>;
@@ -66,16 +67,14 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
66
67
  generateMessageTag: () => string;
67
68
  query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
68
69
  waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
70
+ /**
71
+ * Star or Unstar a message
72
+ */
69
73
  waitForSocketOpen: () => Promise<void>;
70
74
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
71
75
  sendNode: (frame: BinaryNode) => Promise<void>;
72
76
  logout: (msg?: string | undefined) => Promise<void>;
73
77
  end: (error: Error | undefined) => void;
74
- /**
75
- * modify a chat -- mark unread, read etc.
76
- * lastMessages must be sorted in reverse chronologically
77
- * requires the last messages till the last message received; required for archive & unread
78
- */
79
78
  onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
80
79
  uploadPreKeys: (count?: number) => Promise<void>;
81
80
  uploadPreKeysToServerIfRequired: () => Promise<void>;
@@ -66,6 +66,9 @@ const makeChatsSocket = (config) => {
66
66
  }]
67
67
  });
68
68
  };
69
+ const updateCallPrivacy = async (value) => {
70
+ await privacyQuery('calladd', value);
71
+ };
69
72
  const updateLastSeenPrivacy = async (value) => {
70
73
  await privacyQuery('last', value);
71
74
  };
@@ -442,7 +445,8 @@ const makeChatsSocket = (config) => {
442
445
  const result = await query({
443
446
  tag: 'iq',
444
447
  attrs: {
445
- to: jid,
448
+ target: jid,
449
+ to: WABinary_1.S_WHATSAPP_NET,
446
450
  type: 'get',
447
451
  xmlns: 'w:profile:picture'
448
452
  },
@@ -511,7 +515,7 @@ const makeChatsSocket = (config) => {
511
515
  let presence;
512
516
  const jid = attrs.from;
513
517
  const participant = attrs.participant || attrs.from;
514
- if (shouldIgnoreJid(jid)) {
518
+ if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
515
519
  return;
516
520
  }
517
521
  if (tag === 'presence') {
@@ -817,6 +821,7 @@ const makeChatsSocket = (config) => {
817
821
  updateProfileStatus,
818
822
  updateProfileName,
819
823
  updateBlockStatus,
824
+ updateCallPrivacy,
820
825
  updateLastSeenPrivacy,
821
826
  updateOnlinePrivacy,
822
827
  updateProfilePicturePrivacy,
@@ -62,6 +62,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
62
62
  updateProfileStatus: (status: string) => Promise<void>;
63
63
  updateProfileName: (name: string) => Promise<void>;
64
64
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
65
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
65
66
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
66
67
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
67
68
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
@@ -193,6 +193,7 @@ const makeGroupsSocket = (config) => {
193
193
  * @param inviteMessage the message to accept
194
194
  */
195
195
  groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
196
+ var _a;
196
197
  key = typeof key === 'string' ? { remoteJid: key } : key;
197
198
  const results = await groupQuery(inviteMessage.groupJid, 'set', [{
198
199
  tag: 'accept',
@@ -224,7 +225,7 @@ const makeGroupsSocket = (config) => {
224
225
  await upsertMessage({
225
226
  key: {
226
227
  remoteJid: inviteMessage.groupJid,
227
- id: (0, Utils_1.generateMessageID)(),
228
+ id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
228
229
  fromMe: false,
229
230
  participant: key.remoteJid,
230
231
  },
@@ -3,6 +3,7 @@ import { UserFacingSocketConfig } from '../Types';
3
3
  declare const makeWASocket: (config: UserFacingSocketConfig) => {
4
4
  register: (code: string) => Promise<import("./registration").ExistsResponse>;
5
5
  requestRegistrationCode: (registrationOptions?: import("./registration").RegistrationOptions | undefined) => Promise<import("./registration").ExistsResponse>;
6
+ logger: import("pino").Logger<import("pino").LoggerOptions>;
6
7
  getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
7
8
  getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
8
9
  products: import("../Types").Product[];
@@ -86,6 +87,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
86
87
  updateProfileStatus: (status: string) => Promise<void>;
87
88
  updateProfileName: (name: string) => Promise<void>;
88
89
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
90
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
89
91
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
90
92
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
91
93
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
@@ -74,6 +74,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
74
74
  updateProfileStatus: (status: string) => Promise<void>;
75
75
  updateProfileName: (name: string) => Promise<void>;
76
76
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
77
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
77
78
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
78
79
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
79
80
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
@@ -75,15 +75,16 @@ const makeMessagesRecvSocket = (config) => {
75
75
  await query(stanza);
76
76
  };
77
77
  const sendRetryRequest = async (node, forceIncludeKeys = false) => {
78
- const msgId = node.attrs.id;
79
- let retryCount = msgRetryCache.get(msgId) || 0;
78
+ const { id: msgId, participant } = node.attrs;
79
+ const key = `${msgId}:${participant}`;
80
+ let retryCount = msgRetryCache.get(key) || 0;
80
81
  if (retryCount >= maxMsgRetryCount) {
81
82
  logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
82
- msgRetryCache.del(msgId);
83
+ msgRetryCache.del(key);
83
84
  return;
84
85
  }
85
86
  retryCount += 1;
86
- msgRetryCache.set(msgId, retryCount);
87
+ msgRetryCache.set(key, retryCount);
87
88
  const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds;
88
89
  const deviceIdentity = (0, Utils_1.encodeSignedDeviceIdentity)(account, true);
89
90
  await authState.keys.transaction(async () => {
@@ -163,6 +164,8 @@ const makeMessagesRecvSocket = (config) => {
163
164
  }
164
165
  };
165
166
  const handleGroupNotification = (participant, child, msg) => {
167
+ var _a, _b;
168
+ const participantJid = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(child, 'participant')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.jid) || participant;
166
169
  switch (child === null || child === void 0 ? void 0 : child.tag) {
167
170
  case 'create':
168
171
  const metadata = (0, groups_1.extractGroupMetadata)(child);
@@ -188,6 +191,11 @@ const makeMessagesRecvSocket = (config) => {
188
191
  }
189
192
  };
190
193
  break;
194
+ case 'modify':
195
+ const oldNumber = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
196
+ msg.messageStubParameters = oldNumber || [];
197
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
198
+ break;
191
199
  case 'promote':
192
200
  case 'demote':
193
201
  case 'remove':
@@ -237,6 +245,15 @@ const makeMessagesRecvSocket = (config) => {
237
245
  msg.messageStubParameters = [approvalMode.attrs.state];
238
246
  }
239
247
  break;
248
+ case 'created_membership_requests':
249
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
250
+ msg.messageStubParameters = [participantJid, 'created', child.attrs.request_method];
251
+ break;
252
+ case 'revoked_membership_requests':
253
+ const isDenied = (0, WABinary_1.areJidsSameUser)(participantJid, participant);
254
+ msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
255
+ msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
256
+ break;
240
257
  }
241
258
  };
242
259
  const processNotification = async (node) => {
@@ -332,7 +349,7 @@ const makeMessagesRecvSocket = (config) => {
332
349
  const ref = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_ref'));
333
350
  const primaryIdentityPublicKey = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'primary_identity_pub'));
334
351
  const primaryEphemeralPublicKeyWrapped = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
335
- const codePairingPublicKey = decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
352
+ const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
336
353
  const companionSharedKey = Utils_1.Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
337
354
  const random = (0, crypto_1.randomBytes)(32);
338
355
  const linkCodeSalt = (0, crypto_1.randomBytes)(32);
@@ -389,10 +406,10 @@ const makeMessagesRecvSocket = (config) => {
389
406
  return result;
390
407
  }
391
408
  };
392
- function decipherLinkPublicKey(data) {
409
+ async function decipherLinkPublicKey(data) {
393
410
  const buffer = toRequiredBuffer(data);
394
411
  const salt = buffer.slice(0, 32);
395
- const secretKey = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
412
+ const secretKey = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
396
413
  const iv = buffer.slice(32, 48);
397
414
  const payload = buffer.slice(48, 80);
398
415
  return (0, Utils_1.aesDecryptCTR)(payload, secretKey, iv);
@@ -461,7 +478,7 @@ const makeMessagesRecvSocket = (config) => {
461
478
  fromMe,
462
479
  participant: attrs.participant
463
480
  };
464
- if (shouldIgnoreJid(remoteJid)) {
481
+ if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
465
482
  logger.debug({ remoteJid }, 'ignoring receipt from jid');
466
483
  await sendMessageAck(node);
467
484
  return;
@@ -480,7 +497,7 @@ const makeMessagesRecvSocket = (config) => {
480
497
  // or another device of ours has read some messages
481
498
  status > WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ||
482
499
  !isNodeFromMe)) {
483
- if ((0, WABinary_1.isJidGroup)(remoteJid)) {
500
+ if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
484
501
  if (attrs.participant) {
485
502
  const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
486
503
  ev.emit('message-receipt.update', ids.map(id => ({
@@ -527,7 +544,7 @@ const makeMessagesRecvSocket = (config) => {
527
544
  };
528
545
  const handleNotification = async (node) => {
529
546
  const remoteJid = node.attrs.from;
530
- if (shouldIgnoreJid(remoteJid)) {
547
+ if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
531
548
  logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification');
532
549
  await sendMessageAck(node);
533
550
  return;
@@ -556,17 +573,17 @@ const makeMessagesRecvSocket = (config) => {
556
573
  };
557
574
  const handleMessage = async (node) => {
558
575
  var _a, _b;
576
+ if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
577
+ logger.debug({ key: node.attrs.key }, 'ignored message');
578
+ await sendMessageAck(node);
579
+ return;
580
+ }
559
581
  const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
560
582
  if (((_b = (_a = msg.message) === null || _a === void 0 ? void 0 : _a.protocolMessage) === null || _b === void 0 ? void 0 : _b.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) {
561
583
  if (node.attrs.sender_pn) {
562
584
  ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
563
585
  }
564
586
  }
565
- if (shouldIgnoreJid(msg.key.remoteJid)) {
566
- logger.debug({ key: msg.key }, 'ignored message');
567
- await sendMessageAck(node);
568
- return;
569
- }
570
587
  await Promise.all([
571
588
  processingMutex.mutex(async () => {
572
589
  await decrypt();
@@ -69,6 +69,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
69
69
  updateProfileStatus: (status: string) => Promise<void>;
70
70
  updateProfileName: (name: string) => Promise<void>;
71
71
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
72
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
72
73
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
73
74
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
74
75
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
@@ -130,6 +130,9 @@ const makeMessagesSocket = (config) => {
130
130
  users.push({ tag: 'user', attrs: { jid } });
131
131
  }
132
132
  }
133
+ if (!users.length) {
134
+ return deviceResults;
135
+ }
133
136
  const iq = {
134
137
  tag: 'iq',
135
138
  attrs: {
@@ -247,6 +250,7 @@ const makeMessagesSocket = (config) => {
247
250
  return { nodes, shouldIncludeDeviceIdentity };
248
251
  };
249
252
  const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }) => {
253
+ var _a;
250
254
  const meId = authState.creds.me.id;
251
255
  let shouldIncludeDeviceIdentity = false;
252
256
  const { user, server } = (0, WABinary_1.jidDecode)(jid);
@@ -254,7 +258,7 @@ const makeMessagesSocket = (config) => {
254
258
  const isGroup = server === 'g.us';
255
259
  const isStatus = jid === statusJid;
256
260
  const isLid = server === 'lid';
257
- msgId = msgId || (0, Utils_1.generateMessageID)();
261
+ msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
258
262
  useUserDevicesCache = useUserDevicesCache !== false;
259
263
  const participants = [];
260
264
  const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid;
@@ -601,7 +605,7 @@ const makeMessagesSocket = (config) => {
601
605
  return message;
602
606
  },
603
607
  sendMessage: async (jid, content, options = {}) => {
604
- var _a, _b;
608
+ var _a, _b, _c;
605
609
  const userJid = authState.creds.me.id;
606
610
  if (typeof content === 'object' &&
607
611
  'disappearingMessagesInChat' in content &&
@@ -631,6 +635,7 @@ const makeMessagesSocket = (config) => {
631
635
  upload: waUploadToServer,
632
636
  mediaCache: config.mediaCache,
633
637
  options: config.options,
638
+ messageId: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
634
639
  ...options,
635
640
  });
636
641
  const isDeleteMsg = 'delete' in content && !!content.delete;
@@ -639,7 +644,7 @@ const makeMessagesSocket = (config) => {
639
644
  // required for delete
640
645
  if (isDeleteMsg) {
641
646
  // if the chat is a group, and I am not the author, then delete the message as an admin
642
- if ((0, WABinary_1.isJidGroup)((_a = content.delete) === null || _a === void 0 ? void 0 : _a.remoteJid) && !((_b = content.delete) === null || _b === void 0 ? void 0 : _b.fromMe)) {
647
+ if ((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) {
643
648
  additionalAttributes.edit = '8';
644
649
  }
645
650
  else {
@@ -4,6 +4,7 @@ import { KeyPair, SignedKeyPair, SocketConfig } from '../Types';
4
4
  export declare const makeRegistrationSocket: (config: SocketConfig) => {
5
5
  register: (code: string) => Promise<ExistsResponse>;
6
6
  requestRegistrationCode: (registrationOptions?: RegistrationOptions) => Promise<ExistsResponse>;
7
+ logger: import("pino").Logger<import("pino").LoggerOptions>;
7
8
  getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
8
9
  getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
9
10
  products: import("../Types").Product[];
@@ -87,6 +88,7 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
87
88
  updateProfileStatus: (status: string) => Promise<void>;
88
89
  updateProfileName: (name: string) => Promise<void>;
89
90
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
91
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
90
92
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
91
93
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
92
94
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
@@ -18,12 +18,16 @@ const Client_1 = require("./Client");
18
18
  * - query phone connection
19
19
  */
20
20
  const makeSocket = (config) => {
21
+ var _a, _b;
21
22
  const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
22
23
  let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
23
24
  config.mobile = config.mobile || url.protocol === 'tcp:';
24
25
  if (config.mobile && url.protocol !== 'tcp:') {
25
26
  url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
26
27
  }
28
+ if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
29
+ url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
30
+ }
27
31
  const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
28
32
  ws.connect();
29
33
  const ev = (0, Utils_1.makeEventBuffer)(logger);
@@ -34,7 +38,8 @@ const makeSocket = (config) => {
34
38
  keyPair: ephemeralKeyPair,
35
39
  NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
36
40
  mobile: config.mobile,
37
- logger
41
+ logger,
42
+ routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
38
43
  });
39
44
  const { creds } = authState;
40
45
  // add transaction capability
@@ -398,7 +403,7 @@ const makeSocket = (config) => {
398
403
  {
399
404
  tag: 'companion_platform_id',
400
405
  attrs: {},
401
- content: '49' // Chrome
406
+ content: (0, Utils_1.getPlatformId)(browser[1])
402
407
  },
403
408
  {
404
409
  tag: 'companion_platform_display',
@@ -419,7 +424,7 @@ const makeSocket = (config) => {
419
424
  async function generatePairingKey() {
420
425
  const salt = (0, crypto_1.randomBytes)(32);
421
426
  const randomIv = (0, crypto_1.randomBytes)(16);
422
- const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
427
+ const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
423
428
  const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
424
429
  return Buffer.concat([salt, randomIv, ciphered]);
425
430
  }
@@ -526,6 +531,14 @@ const makeSocket = (config) => {
526
531
  ws.on('CB:ib,,downgrade_webclient', () => {
527
532
  end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
528
533
  });
534
+ ws.on('CB:ib,,edge_routing', (node) => {
535
+ const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
536
+ const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
537
+ if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
538
+ authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
539
+ ev.emit('creds.update', authState.creds);
540
+ }
541
+ });
529
542
  let didStartBuffer = false;
530
543
  process.nextTick(() => {
531
544
  var _a;
@@ -17,10 +17,10 @@ export declare const waLabelAssociationKey: Comparable<LabelAssociation, string>
17
17
  export type BaileysInMemoryStoreConfig = {
18
18
  chatKey?: Comparable<Chat, string>;
19
19
  labelAssociationKey?: Comparable<LabelAssociation, string>;
20
- logger: Logger;
20
+ logger?: Logger;
21
21
  socket?: WASocket;
22
22
  };
23
- declare const _default: ({ logger, chatKey, labelAssociationKey, socket }: BaileysInMemoryStoreConfig) => {
23
+ declare const _default: (config: BaileysInMemoryStoreConfig) => {
24
24
  chats: KeyedDB<Chat, string>;
25
25
  contacts: {
26
26
  [_: string]: Contact;
@@ -23,48 +23,11 @@ exports.waLabelAssociationKey = {
23
23
  compare: (k1, k2) => k2.localeCompare(k1)
24
24
  };
25
25
  const makeMessagesDictionary = () => (0, make_ordered_dictionary_1.default)(exports.waMessageID);
26
- const predefinedLabels = Object.freeze({
27
- '1': {
28
- id: '1',
29
- name: 'New customer',
30
- predefinedId: '1',
31
- color: 1,
32
- deleted: false
33
- },
34
- '2': {
35
- id: '2',
36
- name: 'New order',
37
- predefinedId: '2',
38
- color: 2,
39
- deleted: false
40
- },
41
- '3': {
42
- id: '3',
43
- name: 'Pending payment',
44
- predefinedId: '3',
45
- color: 3,
46
- deleted: false
47
- },
48
- '4': {
49
- id: '4',
50
- name: 'Paid',
51
- predefinedId: '4',
52
- color: 4,
53
- deleted: false
54
- },
55
- '5': {
56
- id: '5',
57
- name: 'Order completed',
58
- predefinedId: '5',
59
- color: 5,
60
- deleted: false
61
- }
62
- });
63
- exports.default = ({ logger, chatKey, labelAssociationKey, socket }) => {
64
- // const logger = _logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' })
65
- chatKey = chatKey || (0, exports.waChatKey)(true);
66
- labelAssociationKey = labelAssociationKey || exports.waLabelAssociationKey;
67
- logger = logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
26
+ exports.default = (config) => {
27
+ const socket = config.socket;
28
+ const chatKey = config.chatKey || (0, exports.waChatKey)(true);
29
+ const labelAssociationKey = config.labelAssociationKey || exports.waLabelAssociationKey;
30
+ const logger = config.logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
68
31
  const KeyedDB = require('@adiwajshing/keyed-db').default;
69
32
  const chats = new KeyedDB(chatKey, c => c.id);
70
33
  const messages = {};
@@ -72,7 +35,7 @@ exports.default = ({ logger, chatKey, labelAssociationKey, socket }) => {
72
35
  const groupMetadata = {};
73
36
  const presences = {};
74
37
  const state = { connection: 'close' };
75
- const labels = new object_repository_1.ObjectRepository(predefinedLabels);
38
+ const labels = new object_repository_1.ObjectRepository();
76
39
  const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
77
40
  const assertMessageList = (jid) => {
78
41
  if (!messages[jid]) {
@@ -65,6 +65,7 @@ export type AuthenticationCreds = SignalCreds & {
65
65
  registration: RegistrationOptions;
66
66
  pairingCode: string | undefined;
67
67
  lastPropHash: string | undefined;
68
+ routingInfo: Buffer | undefined;
68
69
  };
69
70
  export type SignalDataTypeMap = {
70
71
  'pre-key': KeyPair;
@@ -8,6 +8,7 @@ import type { MinimalMessage } from './Message';
8
8
  export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
9
9
  export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
10
10
  export type WAReadReceiptsValue = 'all' | 'none';
11
+ export type WAPrivacyCallValue = 'all' | 'known';
11
12
  /** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
12
13
  export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
13
14
  export declare const ALL_WA_PATCH_NAMES: readonly ["critical_block", "critical_unblock_low", "regular_high", "regular_low", "regular"];
@@ -4,7 +4,7 @@ import { AuthenticationCreds } from './Auth';
4
4
  import { WACallEvent } from './Call';
5
5
  import { Chat, ChatUpdate, PresenceData } from './Chat';
6
6
  import { Contact } from './Contact';
7
- import { GroupMetadata, ParticipantAction } from './GroupMetadata';
7
+ import { GroupMetadata, ParticipantAction, RequestJoinAction, RequestJoinMethod } from './GroupMetadata';
8
8
  import { Label } from './Label';
9
9
  import { LabelAssociation } from './LabelAssociation';
10
10
  import { MessageUpsertType, MessageUserReceiptUpdate, WAMessage, WAMessageKey, WAMessageUpdate } from './Message';
@@ -78,6 +78,13 @@ export type BaileysEventMap = {
78
78
  participants: string[];
79
79
  action: ParticipantAction;
80
80
  };
81
+ 'group.join-request': {
82
+ id: string;
83
+ author: string;
84
+ participant: string;
85
+ action: RequestJoinAction;
86
+ method: RequestJoinMethod;
87
+ };
81
88
  'blocklist.set': {
82
89
  blocklist: string[];
83
90
  };
@@ -4,7 +4,9 @@ export type GroupParticipant = (Contact & {
4
4
  isSuperAdmin?: boolean;
5
5
  admin?: 'admin' | 'superadmin' | null;
6
6
  });
7
- export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote';
7
+ export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote' | 'modify';
8
+ export type RequestJoinAction = 'created' | 'revoked' | 'rejected';
9
+ export type RequestJoinMethod = 'invite_link' | 'linked_group_join' | 'non_admin_add' | undefined;
8
10
  export interface GroupMetadata {
9
11
  id: string;
10
12
  owner: string | undefined;
@@ -14,6 +14,13 @@ import { SocketConfig } from './Socket';
14
14
  export type UserFacingSocketConfig = Partial<SocketConfig> & {
15
15
  auth: AuthenticationState;
16
16
  };
17
+ export type BrowsersMap = {
18
+ ubuntu(browser: string): [string, string, string];
19
+ macOS(browser: string): [string, string, string];
20
+ baileys(browser: string): [string, string, string];
21
+ windows(browser: string): [string, string, string];
22
+ appropriate(browser: string): [string, string, string];
23
+ };
17
24
  export declare enum DisconnectReason {
18
25
  connectionClosed = 428,
19
26
  connectionLost = 408,
@@ -200,6 +200,7 @@ const initAuthCreds = () => {
200
200
  registration: {},
201
201
  pairingCode: undefined,
202
202
  lastPropHash: undefined,
203
+ routingInfo: undefined,
203
204
  };
204
205
  };
205
206
  exports.initAuthCreds = initAuthCreds;
@@ -38,4 +38,4 @@ export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number
38
38
  salt?: Buffer;
39
39
  info?: string;
40
40
  }): Buffer;
41
- export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer;
41
+ export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
@@ -30,7 +30,9 @@ exports.derivePairingCodeKey = exports.hkdf = exports.md5 = exports.sha256 = exp
30
30
  const crypto_1 = require("crypto");
31
31
  const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
32
32
  const libsignal = __importStar(require("libsignal"));
33
+ const util_1 = require("util");
33
34
  const Defaults_1 = require("../Defaults");
35
+ const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
34
36
  /** prefix version byte to the pub keys, required for some curve crypto functions */
35
37
  const generateSignalPubKey = (pubKey) => (pubKey.length === 33
36
38
  ? pubKey
@@ -145,7 +147,7 @@ function hkdf(buffer, expandedLength, info) {
145
147
  return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
146
148
  }
147
149
  exports.hkdf = hkdf;
148
- function derivePairingCodeKey(pairingCode, salt) {
149
- return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
150
+ async function derivePairingCodeKey(pairingCode, salt) {
151
+ return await pbkdf2Promise(pairingCode, salt, 2 << 16, 32, 'sha256');
150
152
  }
151
153
  exports.derivePairingCodeKey = derivePairingCodeKey;