@queenanya/baileys 7.0.1 → 7.0.2

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.
@@ -86,6 +86,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
86
86
  updateProfileStatus: (status: string) => Promise<void>;
87
87
  updateProfileName: (name: string) => Promise<void>;
88
88
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
89
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
89
90
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
90
91
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
91
92
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
@@ -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,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
  };
@@ -817,6 +820,7 @@ const makeChatsSocket = (config) => {
817
820
  updateProfileStatus,
818
821
  updateProfileName,
819
822
  updateBlockStatus,
823
+ updateCallPrivacy,
820
824
  updateLastSeenPrivacy,
821
825
  updateOnlinePrivacy,
822
826
  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>;
@@ -87,6 +87,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
87
87
  updateProfileStatus: (status: string) => Promise<void>;
88
88
  updateProfileName: (name: string) => Promise<void>;
89
89
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
90
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
90
91
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
91
92
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
92
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 () => {
@@ -190,6 +191,11 @@ const makeMessagesRecvSocket = (config) => {
190
191
  }
191
192
  };
192
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;
193
199
  case 'promote':
194
200
  case 'demote':
195
201
  case 'remove':
@@ -343,7 +349,7 @@ const makeMessagesRecvSocket = (config) => {
343
349
  const ref = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_ref'));
344
350
  const primaryIdentityPublicKey = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'primary_identity_pub'));
345
351
  const primaryEphemeralPublicKeyWrapped = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
346
- const codePairingPublicKey = decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
352
+ const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
347
353
  const companionSharedKey = Utils_1.Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
348
354
  const random = (0, crypto_1.randomBytes)(32);
349
355
  const linkCodeSalt = (0, crypto_1.randomBytes)(32);
@@ -400,10 +406,10 @@ const makeMessagesRecvSocket = (config) => {
400
406
  return result;
401
407
  }
402
408
  };
403
- function decipherLinkPublicKey(data) {
409
+ async function decipherLinkPublicKey(data) {
404
410
  const buffer = toRequiredBuffer(data);
405
411
  const salt = buffer.slice(0, 32);
406
- const secretKey = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
412
+ const secretKey = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
407
413
  const iv = buffer.slice(32, 48);
408
414
  const payload = buffer.slice(48, 80);
409
415
  return (0, Utils_1.aesDecryptCTR)(payload, secretKey, iv);
@@ -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>;
@@ -88,6 +88,7 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
88
88
  updateProfileStatus: (status: string) => Promise<void>;
89
89
  updateProfileName: (name: string) => Promise<void>;
90
90
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
91
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
91
92
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
92
93
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
93
94
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
@@ -424,7 +424,7 @@ const makeSocket = (config) => {
424
424
  async function generatePairingKey() {
425
425
  const salt = (0, crypto_1.randomBytes)(32);
426
426
  const randomIv = (0, crypto_1.randomBytes)(16);
427
- const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
427
+ const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
428
428
  const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
429
429
  return Buffer.concat([salt, randomIv, ciphered]);
430
430
  }
@@ -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 @@ 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
8
  export type RequestJoinAction = 'created' | 'revoked' | 'rejected';
9
9
  export type RequestJoinMethod = 'invite_link' | 'linked_group_join' | 'non_admin_add' | undefined;
10
10
  export interface GroupMetadata {
@@ -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;
@@ -41,7 +41,7 @@ exports.Browsers = {
41
41
  };
42
42
  const getPlatformId = (browser) => {
43
43
  const platformType = WAProto_1.proto.DeviceProps.PlatformType[browser.toUpperCase()];
44
- return platformType ? platformType.toString().charCodeAt(0) : '51'; // Firefox
44
+ return platformType ? platformType.toString().charCodeAt(0).toString() : '51'; // Firefox
45
45
  };
46
46
  exports.getPlatformId = getPlatformId;
47
47
  exports.BufferJSON = {
@@ -17,5 +17,5 @@ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public
17
17
  finishInit: () => void;
18
18
  processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Buffer;
19
19
  encodeFrame: (data: Buffer | Uint8Array) => Buffer;
20
- decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => void;
20
+ decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void>;
21
21
  };
@@ -125,7 +125,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
125
125
  frame.set(data, introSize + 3);
126
126
  return frame;
127
127
  },
128
- decodeFrame: (newData, onFrame) => {
128
+ decodeFrame: async (newData, onFrame) => {
129
129
  var _a;
130
130
  // the binary protocol uses its own framing mechanism
131
131
  // on top of the WS frames
@@ -143,7 +143,7 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
143
143
  inBytes = inBytes.slice(size + 3);
144
144
  if (isFinished) {
145
145
  const result = decrypt(frame);
146
- frame = (0, WABinary_1.decodeBinaryNode)(result);
146
+ frame = await (0, WABinary_1.decodeBinaryNode)(result);
147
147
  }
148
148
  logger.trace({ msg: (_a = frame === null || frame === void 0 ? void 0 : frame.attrs) === null || _a === void 0 ? void 0 : _a.id }, 'recv frame');
149
149
  onFrame(frame);
@@ -225,6 +225,10 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
225
225
  };
226
226
  const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
227
227
  switch (message.messageStubType) {
228
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
229
+ participants = message.messageStubParameters || [];
230
+ emitParticipantsUpdate('modify');
231
+ break;
228
232
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
229
233
  case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
230
234
  participants = message.messageStubParameters || [];
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
- export declare const decompressingIfRequired: (buffer: Buffer) => Buffer;
3
+ export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer>;
4
4
  export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
5
5
  index: number;
6
6
  }) => BinaryNode;
7
- export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode;
7
+ export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
@@ -24,12 +24,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
27
+ const util_1 = require("util");
27
28
  const zlib_1 = require("zlib");
28
29
  const constants = __importStar(require("./constants"));
29
30
  const jid_utils_1 = require("./jid-utils");
30
- const decompressingIfRequired = (buffer) => {
31
+ const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
32
+ const decompressingIfRequired = async (buffer) => {
31
33
  if (2 & buffer.readUInt8()) {
32
- buffer = (0, zlib_1.inflateSync)(buffer.slice(1));
34
+ buffer = await inflatePromise(buffer.slice(1));
33
35
  }
34
36
  else { // nodes with no compression have a 0x00 prefix, we remove that
35
37
  buffer = buffer.slice(1);
@@ -245,8 +247,8 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
245
247
  };
246
248
  };
247
249
  exports.decodeDecompressedBinaryNode = decodeDecompressedBinaryNode;
248
- const decodeBinaryNode = (buff) => {
249
- const decompBuff = (0, exports.decompressingIfRequired)(buff);
250
+ const decodeBinaryNode = async (buff) => {
251
+ const decompBuff = await (0, exports.decompressingIfRequired)(buff);
250
252
  return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
251
253
  };
252
254
  exports.decodeBinaryNode = decodeBinaryNode;
@@ -1,3 +1,3 @@
1
1
  /// <reference types="node" />
2
2
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
- export declare const encodeBinaryNode: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => Buffer;
3
+ export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => Buffer;
@@ -26,7 +26,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.encodeBinaryNode = void 0;
27
27
  const constants = __importStar(require("./constants"));
28
28
  const jid_utils_1 = require("./jid-utils");
29
- const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0]) => {
29
+ const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
30
+ const encoded = encodeBinaryNodeInner(node, opts, buffer);
31
+ return Buffer.from(encoded);
32
+ };
33
+ exports.encodeBinaryNode = encodeBinaryNode;
34
+ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
30
35
  const { TAGS, TOKEN_MAP } = opts;
31
36
  const pushByte = (value) => buffer.push(value & 0xff);
32
37
  const pushInt = (value, n, littleEndian = false) => {
@@ -214,7 +219,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
214
219
  else if (Array.isArray(content)) {
215
220
  writeListStart(content.length);
216
221
  for (const item of content) {
217
- (0, exports.encodeBinaryNode)(item, opts, buffer);
222
+ encodeBinaryNodeInner(item, opts, buffer);
218
223
  }
219
224
  }
220
225
  else if (typeof content === 'undefined') {
@@ -223,6 +228,5 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
223
228
  else {
224
229
  throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
225
230
  }
226
- return Buffer.from(buffer);
231
+ return buffer;
227
232
  };
228
- exports.encodeBinaryNode = encodeBinaryNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@queenanya/baileys",
3
- "version": "7.0.1",
3
+ "version": "7.0.2",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -44,7 +44,6 @@
44
44
  "dependencies": {
45
45
  "@adiwajshing/keyed-db": "^0.2.4",
46
46
  "@hapi/boom": "^9.1.3",
47
- "@queenanya/invite": "latest",
48
47
  "async-lock": "^1.4.1",
49
48
  "audio-decode": "^2.1.3",
50
49
  "axios": "^1.6.0",