@queenanya/baileys 7.4.0 → 7.4.1

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 (63) hide show
  1. package/README.md +0 -10
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Defaults/index.d.ts +0 -231
  4. package/lib/Defaults/index.js +1 -17
  5. package/lib/Socket/Client/index.d.ts +2 -3
  6. package/lib/Socket/Client/index.js +2 -3
  7. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
  8. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
  9. package/lib/Socket/business.d.ts +1 -1
  10. package/lib/Socket/chats.d.ts +2 -2
  11. package/lib/Socket/chats.js +5 -6
  12. package/lib/Socket/groups.d.ts +1 -7
  13. package/lib/Socket/index.d.ts +10 -12
  14. package/lib/Socket/index.js +2 -2
  15. package/lib/Socket/messages-recv.d.ts +2 -2
  16. package/lib/Socket/messages-recv.js +3 -6
  17. package/lib/Socket/messages-send.d.ts +1 -1
  18. package/lib/Socket/messages-send.js +23 -8
  19. package/lib/Socket/newsletter.d.ts +1 -1
  20. package/lib/Socket/socket.d.ts +2 -1
  21. package/lib/Socket/socket.js +9 -14
  22. package/lib/Store/make-in-memory-store.js +8 -10
  23. package/lib/Store/make-ordered-dictionary.js +2 -2
  24. package/lib/Types/Auth.d.ts +0 -6
  25. package/lib/Types/Chat.d.ts +7 -7
  26. package/lib/Types/Contact.d.ts +1 -1
  27. package/lib/Types/Message.d.ts +4 -2
  28. package/lib/Types/Socket.d.ts +3 -3
  29. package/lib/Utils/auth-utils.js +1 -7
  30. package/lib/Utils/chat-utils.d.ts +4 -4
  31. package/lib/Utils/chat-utils.js +25 -20
  32. package/lib/Utils/decode-wa-message.js +14 -3
  33. package/lib/Utils/event-buffer.js +7 -7
  34. package/lib/Utils/generics.d.ts +8 -4
  35. package/lib/Utils/generics.js +33 -6
  36. package/lib/Utils/history.d.ts +2 -2
  37. package/lib/Utils/link-preview.js +24 -1
  38. package/lib/Utils/make-mutex.js +1 -0
  39. package/lib/Utils/messages-media.d.ts +1 -1
  40. package/lib/Utils/messages-media.js +9 -16
  41. package/lib/Utils/messages.js +7 -11
  42. package/lib/Utils/noise-handler.d.ts +1 -2
  43. package/lib/Utils/noise-handler.js +5 -10
  44. package/lib/Utils/process-message.js +1 -0
  45. package/lib/Utils/signal.js +2 -0
  46. package/lib/Utils/use-multi-file-auth-state.js +1 -0
  47. package/lib/Utils/validate-connection.d.ts +0 -1
  48. package/lib/Utils/validate-connection.js +10 -44
  49. package/lib/WABinary/constants.js +5 -5
  50. package/lib/WABinary/encode.js +7 -5
  51. package/lib/WABinary/jid-utils.d.ts +1 -1
  52. package/lib/WABinary/jid-utils.js +1 -1
  53. package/lib/WAM/BinaryInfo.d.ts +2 -2
  54. package/lib/WAM/constants.d.ts +3 -2
  55. package/lib/WAM/encode.js +2 -2
  56. package/package.json +4 -5
  57. package/lib/Defaults/phonenumber-mcc.json +0 -223
  58. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  59. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  60. package/lib/Socket/registration.d.ts +0 -271
  61. package/lib/Socket/registration.js +0 -166
  62. /package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +0 -0
  63. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -45,13 +45,11 @@ const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
45
45
  const getImageProcessingLibrary = async () => {
46
46
  const [_jimp, sharp] = await Promise.all([
47
47
  (async () => {
48
- const jimp = await (import('jimp')
49
- .catch(() => { }));
48
+ const jimp = await (Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { }));
50
49
  return jimp;
51
50
  })(),
52
51
  (async () => {
53
- const sharp = await (import('sharp')
54
- .catch(() => { }));
52
+ const sharp = await (Promise.resolve().then(() => __importStar(require('sharp'))).catch(() => { }));
55
53
  return sharp;
56
54
  })()
57
55
  ]);
@@ -262,7 +260,7 @@ const mediaMessageSHA256B64 = (message) => {
262
260
  };
263
261
  exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
264
262
  async function getAudioDuration(buffer) {
265
- const musicMetadata = await import('music-metadata');
263
+ const musicMetadata = await Promise.resolve().then(() => __importStar(require('music-metadata')));
266
264
  let metadata;
267
265
  if (Buffer.isBuffer(buffer)) {
268
266
  metadata = await musicMetadata.parseBuffer(buffer, undefined, { duration: true });
@@ -287,7 +285,7 @@ exports.getAudioDuration = getAudioDuration;
287
285
  */
288
286
  async function getAudioWaveform(buffer, logger) {
289
287
  try {
290
- const audioDecode = (buffer) => import('audio-decode').then(({ default: audioDecode }) => audioDecode(buffer));
288
+ const audioDecode = (buffer) => Promise.resolve().then(() => __importStar(require('audio-decode'))).then(({ default: audioDecode }) => audioDecode(buffer));
291
289
  let audioData;
292
290
  if (Buffer.isBuffer(buffer)) {
293
291
  audioData = buffer;
@@ -445,7 +443,7 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
445
443
  let writeStream;
446
444
  let didSaveToTmpPath = false;
447
445
  if (type === 'file') {
448
- bodyPath = media.url;
446
+ bodyPath = media.url.toString();
449
447
  }
450
448
  else if (saveOriginalFileIfRequired) {
451
449
  bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
@@ -468,10 +466,8 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
468
466
  });
469
467
  }
470
468
  sha256Plain = sha256Plain.update(data);
471
- if (writeStream) {
472
- if (!writeStream.write(data)) {
473
- await (0, events_1.once)(writeStream, 'drain');
474
- }
469
+ if (writeStream && !writeStream.write(data)) {
470
+ await (0, events_1.once)(writeStream, 'drain');
475
471
  }
476
472
  onChunk(aes.update(data));
477
473
  }
@@ -654,7 +650,8 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
654
650
  for (const { hostname } of hosts) {
655
651
  logger.debug(`uploading to "${hostname}"`);
656
652
  const auth = encodeURIComponent(uploadInfo.auth); // the auth token
657
- const url = `https://${hostname}${media}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
653
+ const url = `https://${hostname}${Defaults_1.MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`;
654
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
658
655
  let result;
659
656
  try {
660
657
  const body = await axios_1.default.post(url, stream, {
@@ -787,7 +784,3 @@ const MEDIA_RETRY_STATUS_MAP = {
787
784
  [WAProto_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
788
785
  [WAProto_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418,
789
786
  };
790
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
791
- function __importStar(arg0) {
792
- throw new Error('Function not implemented.');
793
- }
@@ -706,17 +706,13 @@ const downloadMediaMessage = async (message, type, options, ctx) => {
706
706
  const result = await downloadMsg()
707
707
  .catch(async (error) => {
708
708
  var _a;
709
- if (ctx) {
710
- if (axios_1.default.isAxiosError(error)) {
711
- // check if the message requires a reupload
712
- if (REUPLOAD_REQUIRED_STATUS.includes((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
713
- ctx.logger.info({ key: message.key }, 'sending reupload media request...');
714
- // request reupload
715
- message = await ctx.reuploadRequest(message);
716
- const result = await downloadMsg();
717
- return result;
718
- }
719
- }
709
+ if (ctx && axios_1.default.isAxiosError(error) && // check if the message requires a reupload
710
+ REUPLOAD_REQUIRED_STATUS.includes((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
711
+ ctx.logger.info({ key: message.key }, 'sending reupload media request...');
712
+ // request reupload
713
+ message = await ctx.reuploadRequest(message);
714
+ const result = await downloadMsg();
715
+ return result;
720
716
  }
721
717
  throw error;
722
718
  });
@@ -4,10 +4,9 @@ import { Logger } from 'pino';
4
4
  import { proto } from '../../WAProto';
5
5
  import { KeyPair } from '../Types';
6
6
  import { BinaryNode } from '../WABinary';
7
- export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }: {
7
+ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
8
8
  keyPair: KeyPair;
9
9
  NOISE_HEADER: Uint8Array;
10
- mobile: boolean;
11
10
  logger: Logger;
12
11
  routingInfo?: Buffer | undefined;
13
12
  }) => {
@@ -11,7 +11,7 @@ const generateIV = (counter) => {
11
11
  new DataView(iv).setUint32(8, counter);
12
12
  return new Uint8Array(iv);
13
13
  };
14
- const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }) => {
14
+ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
15
15
  logger = logger.child({ class: 'ns' });
16
16
  const authenticate = (data) => {
17
17
  if (!isFinished) {
@@ -83,15 +83,10 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
83
83
  const decStaticContent = decrypt(serverHello.static);
84
84
  mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent));
85
85
  const certDecoded = decrypt(serverHello.payload);
86
- if (mobile) {
87
- WAProto_1.proto.CertChain.NoiseCertificate.decode(certDecoded);
88
- }
89
- else {
90
- const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded);
91
- const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
92
- if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
93
- throw new boom_1.Boom('certification match failed', { statusCode: 400 });
94
- }
86
+ const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded);
87
+ const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
88
+ if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
89
+ throw new boom_1.Boom('certification match failed', { statusCode: 400 });
95
90
  }
96
91
  const keyEnc = encrypt(noiseKey.public);
97
92
  mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
@@ -200,6 +200,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
200
200
  const { peerDataOperationResult } = response;
201
201
  for (const result of peerDataOperationResult) {
202
202
  const { placeholderMessageResendResponse: retryResponse } = result;
203
+ //eslint-disable-next-line max-depth
203
204
  if (retryResponse) {
204
205
  const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
205
206
  // wait till another upsert event is available, don't want it to be part of the PDO response message
@@ -101,8 +101,10 @@ const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
101
101
  const devicesNode = (0, WABinary_1.getBinaryNodeChild)(item, 'devices');
102
102
  const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(devicesNode, 'device-list');
103
103
  if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
104
+ //eslint-disable-next-line max-depth
104
105
  for (const { tag, attrs } of deviceListNode.content) {
105
106
  const device = +attrs.id;
107
+ //eslint-disable-next-line max-depth
106
108
  if (tag === 'device' && // ensure the "device" tag
107
109
  (!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
108
110
  (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
@@ -24,6 +24,7 @@ const fileLock = new async_lock_1.default({ maxPending: Infinity });
24
24
  * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
25
25
  * */
26
26
  const useMultiFileAuthState = async (folder) => {
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
28
  const writeData = (data, file) => {
28
29
  const filePath = (0, path_1.join)(folder, fixFileName(file));
29
30
  return fileLock.acquire(filePath, () => (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer)));
@@ -1,7 +1,6 @@
1
1
  import { proto } from '../../WAProto';
2
2
  import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
3
3
  import { BinaryNode } from '../WABinary';
4
- export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload;
5
4
  export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
6
5
  export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
7
6
  export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = exports.generateMobileNode = void 0;
3
+ exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
4
4
  const boom_1 = require("@hapi/boom");
5
5
  const crypto_1 = require("crypto");
6
6
  const WAProto_1 = require("../../WAProto");
@@ -10,30 +10,19 @@ const crypto_2 = require("./crypto");
10
10
  const generics_1 = require("./generics");
11
11
  const signal_1 = require("./signal");
12
12
  const getUserAgent = (config) => {
13
- var _a, _b;
14
- const osVersion = config.mobile ? '15.3.1' : '0.1';
15
- const version = config.mobile ? [2, 24, 6] : config.version;
16
- const device = config.mobile ? 'iPhone_7' : 'Desktop';
17
- const manufacturer = config.mobile ? 'Apple' : '';
18
- const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
19
- const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
20
13
  return {
21
14
  appVersion: {
22
- primary: version[0],
23
- secondary: version[1],
24
- tertiary: version[2],
15
+ primary: config.version[0],
16
+ secondary: config.version[1],
17
+ tertiary: config.version[2],
25
18
  },
26
- platform,
19
+ platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
27
20
  releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
28
- mcc: ((_a = config.auth.creds.registration) === null || _a === void 0 ? void 0 : _a.phoneNumberMobileCountryCode) || '000',
29
- mnc: ((_b = config.auth.creds.registration) === null || _b === void 0 ? void 0 : _b.phoneNumberMobileNetworkCode) || '000',
30
- osVersion: osVersion,
31
- manufacturer,
32
- device,
33
- osBuildNumber: osVersion,
21
+ osVersion: '0.1',
22
+ device: 'Desktop',
23
+ osBuildNumber: '0.1',
34
24
  localeLanguageIso6391: 'en',
35
- localeCountryIso31661Alpha2: 'US',
36
- ...phoneId
25
+ localeCountryIso31661Alpha2: 'US'
37
26
  };
38
27
  };
39
28
  const PLATFORM_MAP = {
@@ -53,32 +42,9 @@ const getClientPayload = (config) => {
53
42
  connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
54
43
  userAgent: getUserAgent(config),
55
44
  };
56
- if (!config.mobile) {
57
- payload.webInfo = getWebInfo(config);
58
- }
45
+ payload.webInfo = getWebInfo(config);
59
46
  return payload;
60
47
  };
61
- const generateMobileNode = (config) => {
62
- if (!config.auth.creds) {
63
- throw new boom_1.Boom('No registration data found', { data: config });
64
- }
65
- const payload = {
66
- ...getClientPayload(config),
67
- sessionId: Math.floor(Math.random() * 999999999 + 1),
68
- shortConnect: true,
69
- connectAttemptCount: 0,
70
- device: 0,
71
- dnsSource: {
72
- appCached: false,
73
- dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
74
- },
75
- passive: false,
76
- pushName: 'test',
77
- username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
78
- };
79
- return WAProto_1.proto.ClientPayload.fromObject(payload);
80
- };
81
- exports.generateMobileNode = generateMobileNode;
82
48
  const generateLoginNode = (userJid, config) => {
83
49
  const { user, device } = (0, WABinary_1.jidDecode)(userJid);
84
50
  const payload = {
@@ -30,11 +30,11 @@ exports.SINGLE_BYTE_TOKENS = [
30
30
  '', 'xmlstreamstart', 'xmlstreamend', 's.whatsapp.net', 'type', 'participant', 'from', 'receipt', 'id', 'broadcast', 'status', 'message', 'notification', 'notify', 'to', 'jid', 'user', 'class', 'offline', 'g.us', 'result', 'mediatype', 'enc', 'skmsg', 'off_cnt', 'xmlns', 'presence', 'participants', 'ack', 't', 'iq', 'device_hash', 'read', 'value', 'media', 'picture', 'chatstate', 'unavailable', 'text', 'urn:xmpp:whatsapp:push', 'devices', 'verified_name', 'contact', 'composing', 'edge_routing', 'routing_info', 'item', 'image', 'verified_level', 'get', 'fallback_hostname', '2', 'media_conn', '1', 'v', 'handshake', 'fallback_class', 'count', 'config', 'offline_preview', 'download_buckets', 'w:profile:picture', 'set', 'creation', 'location', 'fallback_ip4', 'msg', 'urn:xmpp:ping', 'fallback_ip6', 'call-creator', 'relaylatency', 'success', 'subscribe', 'video', 'business_hours_config', 'platform', 'hostname', 'version', 'unknown', '0', 'ping', 'hash', 'edit', 'subject', 'max_buckets', 'download', 'delivery', 'props', 'sticker', 'name', 'last', 'contacts', 'business', 'primary', 'preview', 'w:p', 'pkmsg', 'call-id', 'retry', 'prop', 'call', 'auth_ttl', 'available', 'relay_id', 'last_id', 'day_of_week', 'w', 'host', 'seen', 'bits', 'list', 'atn', 'upload', 'is_new', 'w:stats', 'key', 'paused', 'specific_hours', 'multicast', 'stream:error', 'mmg.whatsapp.net', 'code', 'deny', 'played', 'profile', 'fna', 'device-list', 'close_time', 'latency', 'gcm', 'pop', 'audio', '26', 'w:web', 'open_time', 'error', 'auth', 'ip4', 'update', 'profile_options', 'config_value', 'category', 'catalog_not_created', '00', 'config_code', 'mode', 'catalog_status', 'ip6', 'blocklist', 'registration', '7', 'web', 'fail', 'w:m', 'cart_enabled', 'ttl', 'gif', '300', 'device_orientation', 'identity', 'query', '401', 'media-gig2-1.cdn.whatsapp.net', 'in', '3', 'te2', 'add', 'fallback', 'categories', 'ptt', 'encrypt', 'notice', 'thumbnail-document', 'item-not-found', '12', 'thumbnail-image', 'stage', 'thumbnail-link', 'usync', 'out', 'thumbnail-video', '8', '01', 'context', 'sidelist', 'thumbnail-gif', 'terminate', 'not-authorized', 'orientation', 'dhash', 'capability', 'side_list', 'md-app-state', 'description', 'serial', 'readreceipts', 'te', 'business_hours', 'md-msg-hist', 'tag', 'attribute_padding', 'document', 'open_24h', 'delete', 'expiration', 'active', 'prev_v_id', 'true', 'passive', 'index', '4', 'conflict', 'remove', 'w:gp2', 'config_expo_key', 'screen_height', 'replaced', '02', 'screen_width', 'uploadfieldstat', '2:47DEQpj8', 'media-bog1-1.cdn.whatsapp.net', 'encopt', 'url', 'catalog_exists', 'keygen', 'rate', 'offer', 'opus', 'media-mia3-1.cdn.whatsapp.net', 'privacy', 'media-mia3-2.cdn.whatsapp.net', 'signature', 'preaccept', 'token_id', 'media-eze1-1.cdn.whatsapp.net'
31
31
  ];
32
32
  exports.TOKEN_MAP = {};
33
- for (let i = 0; i < exports.SINGLE_BYTE_TOKENS.length; i++) {
34
- exports.TOKEN_MAP[exports.SINGLE_BYTE_TOKENS[i]] = { index: i };
33
+ for (const [i, SINGLE_BYTE_TOKEN] of exports.SINGLE_BYTE_TOKENS.entries()) {
34
+ exports.TOKEN_MAP[SINGLE_BYTE_TOKEN] = { index: i };
35
35
  }
36
- for (let i = 0; i < exports.DOUBLE_BYTE_TOKENS.length; i++) {
37
- for (let j = 0; j < exports.DOUBLE_BYTE_TOKENS[i].length; j++) {
38
- exports.TOKEN_MAP[exports.DOUBLE_BYTE_TOKENS[i][j]] = { dict: i, index: j };
36
+ for (const [i, DOUBLE_BYTE_TOKEN] of exports.DOUBLE_BYTE_TOKENS.entries()) {
37
+ for (const [j, element] of DOUBLE_BYTE_TOKEN.entries()) {
38
+ exports.TOKEN_MAP[element] = { dict: i, index: j };
39
39
  }
40
40
  }
@@ -35,7 +35,11 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
35
35
  buffer.push((value >> (curShift * 8)) & 0xff);
36
36
  }
37
37
  };
38
- const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
38
+ const pushBytes = (bytes) => {
39
+ for (const b of bytes) {
40
+ buffer.push(b);
41
+ }
42
+ };
39
43
  const pushInt16 = (value) => {
40
44
  pushBytes([(value >> 8) & 0xff, value & 0xff]);
41
45
  };
@@ -137,8 +141,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
137
141
  if (str.length > TAGS.PACKED_MAX) {
138
142
  return false;
139
143
  }
140
- for (let i = 0; i < str.length; i++) {
141
- const char = str[i];
144
+ for (const char of str) {
142
145
  const isInNibbleRange = char >= '0' && char <= '9';
143
146
  if (!isInNibbleRange && char !== '-' && char !== '.') {
144
147
  return false;
@@ -150,8 +153,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
150
153
  if (str.length > TAGS.PACKED_MAX) {
151
154
  return false;
152
155
  }
153
- for (let i = 0; i < str.length; i++) {
154
- const char = str[i];
156
+ for (const char of str) {
155
157
  const isInNibbleRange = char >= '0' && char <= '9';
156
158
  if (!isInNibbleRange && !(char >= 'A' && char <= 'F') && !(char >= 'a' && char <= 'f')) {
157
159
  return false;
@@ -9,7 +9,7 @@ export type JidWithDevice = {
9
9
  device?: number;
10
10
  };
11
11
  export type FullJid = JidWithDevice & {
12
- server: JidServer | string;
12
+ server: JidServer;
13
13
  domainType?: number;
14
14
  };
15
15
  export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
@@ -20,7 +20,7 @@ const jidDecode = (jid) => {
20
20
  const [userAgent, device] = userCombined.split(':');
21
21
  const user = userAgent.split('_')[0];
22
22
  return {
23
- server,
23
+ server: server,
24
24
  user,
25
25
  domainType: server === 'lid' ? 1 : 0,
26
26
  device: device ? +device : undefined
@@ -6,10 +6,10 @@ export declare class BinaryInfo {
6
6
  events: {
7
7
  [x: string]: {
8
8
  props: {
9
- [x: string]: any;
9
+ [x: string]: import("./constants").Value;
10
10
  };
11
11
  globals: {
12
- [x: string]: any;
12
+ [x: string]: import("./constants").Value;
13
13
  };
14
14
  };
15
15
  }[];
@@ -28,11 +28,12 @@ type EventByName<T extends Event['name']> = Extract<Event, {
28
28
  export type EventInputType = {
29
29
  [key in Event['name']]: {
30
30
  props: {
31
- [k in keyof EventByName<key>['props']]: any;
31
+ [k in keyof EventByName<key>['props']]: Value;
32
32
  };
33
33
  globals: {
34
- [x: string]: any;
34
+ [x: string]: Value;
35
35
  };
36
36
  };
37
37
  } & {};
38
+ export type Value = number | null | string;
38
39
  export {};
package/lib/WAM/encode.js CHANGED
@@ -13,10 +13,10 @@ const encodeWAM = (binaryInfo) => {
13
13
  .reduce((a, b) => a + b);
14
14
  const buffer = Buffer.alloc(totalSize);
15
15
  let offset = 0;
16
- binaryInfo.buffer.forEach((buffer_) => {
16
+ for (const buffer_ of binaryInfo.buffer) {
17
17
  buffer_.copy(buffer, offset);
18
18
  offset += buffer_.length;
19
- });
19
+ }
20
20
  return buffer;
21
21
  };
22
22
  exports.encodeWAM = encodeWAM;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@queenanya/baileys",
3
- "version": "7.4.0",
3
+ "version": "7.4.1",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -33,10 +33,9 @@
33
33
  "changelog:preview": "conventional-changelog -p angular -u",
34
34
  "changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
35
35
  "example": "node --inspect -r ts-node/register Example/example.ts",
36
- "example:mobile": "node --inspect -r ts-node/register Example/example.ts --mobile",
37
36
  "gen:protobuf": "sh WAProto/GenerateStatics.sh",
38
- "lint": "eslint src --ext .js,.ts,.jsx,.tsx",
39
- "lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
37
+ "lint": "eslint src --ext .js,.ts",
38
+ "lint:fix": "yarn lint --fix",
40
39
  "prepack": "tsc",
41
40
  "prepare": "tsc",
42
41
  "release": "release-it",
@@ -44,6 +43,7 @@
44
43
  },
45
44
  "dependencies": {
46
45
  "@adiwajshing/keyed-db": "^0.2.4",
46
+ "@queenanya/eslint-config": "github:whiskeysockets/eslint-config",
47
47
  "@hapi/boom": "^10.0.1",
48
48
  "async-lock": "^1.4.1",
49
49
  "audio-decode": "^2.2.0",
@@ -63,7 +63,6 @@
63
63
  "ws": "^8.18.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
67
66
  "@types/got": "^9.6.12",
68
67
  "@types/jest": "^29.5.12",
69
68
  "@types/node": "^20.14.10",
@@ -1,223 +0,0 @@
1
- {
2
- "93": 412,
3
- "355": 276,
4
- "213": 603,
5
- "1-684": 544,
6
- "376": 213,
7
- "244": 631,
8
- "1-264": 365,
9
- "1-268": 344,
10
- "54": 722,
11
- "374": 283,
12
- "297": 363,
13
- "61": 505,
14
- "43": 232,
15
- "994": 400,
16
- "1-242": 364,
17
- "973": 426,
18
- "880": 470,
19
- "1-246": 342,
20
- "375": 257,
21
- "32": 206,
22
- "501": 702,
23
- "229": 616,
24
- "1-441": 350,
25
- "975": 402,
26
- "591": 736,
27
- "387": 218,
28
- "267": 652,
29
- "55": 724,
30
- "1-284": 348,
31
- "673": 528,
32
- "359": 284,
33
- "226": 613,
34
- "257": 642,
35
- "855": 456,
36
- "237": 624,
37
- "238": 625,
38
- "1-345": 346,
39
- "236": 623,
40
- "235": 622,
41
- "56": 730,
42
- "86": 454,
43
- "57": 732,
44
- "269": 654,
45
- "682": 548,
46
- "506": 712,
47
- "385": 219,
48
- "53": 368,
49
- "357": 280,
50
- "420": 230,
51
- "243": 630,
52
- "45": 238,
53
- "253": 638,
54
- "1-767": 366,
55
- "1-809": 370,
56
- "1-849": 370,
57
- "1-829": 370,
58
- "593": 740,
59
- "20": 602,
60
- "503": 706,
61
- "240": 627,
62
- "291": 657,
63
- "372": 248,
64
- "251": 636,
65
- "500": 750,
66
- "298": 288,
67
- "679": 542,
68
- "358": 244,
69
- "33": 208,
70
- "689": 547,
71
- "241": 628,
72
- "220": 607,
73
- "995": 282,
74
- "49": 262,
75
- "233": 620,
76
- "350": 266,
77
- "30": 202,
78
- "299": 290,
79
- "1-473": 352,
80
- "1-671": 535,
81
- "502": 704,
82
- "224": 537,
83
- "592": 738,
84
- "509": 372,
85
- "504": 708,
86
- "852": 454,
87
- "36": 216,
88
- "354": 274,
89
- "91": 404,
90
- "62": 510,
91
- "98": 432,
92
- "964": 418,
93
- "353": 234,
94
- "972": 425,
95
- "39": 222,
96
- "225": 612,
97
- "1-876": 338,
98
- "81": 440,
99
- "962": 416,
100
- "254": 639,
101
- "686": 545,
102
- "383": 221,
103
- "965": 419,
104
- "371": 247,
105
- "961": 415,
106
- "266": 651,
107
- "231": 618,
108
- "218": 606,
109
- "423": 295,
110
- "370": 246,
111
- "352": 270,
112
- "389": 294,
113
- "261": 646,
114
- "265": 650,
115
- "60": 502,
116
- "960": 472,
117
- "223": 610,
118
- "356": 278,
119
- "692": 551,
120
- "222": 609,
121
- "230": 617,
122
- "52": 334,
123
- "691": 550,
124
- "373": 259,
125
- "377": 212,
126
- "976": 428,
127
- "382": 297,
128
- "1-664": 354,
129
- "212": 604,
130
- "258": 643,
131
- "95": 414,
132
- "264": 649,
133
- "674": 536,
134
- "977": 429,
135
- "31": 204,
136
- "687": 546,
137
- "64": 530,
138
- "505": 710,
139
- "227": 614,
140
- "234": 621,
141
- "683": 555,
142
- "1-670": 534,
143
- "47": 242,
144
- "968": 226,
145
- "92": 410,
146
- "680": 552,
147
- "970": 423,
148
- "507": 714,
149
- "675": 537,
150
- "595": 744,
151
- "51": 716,
152
- "63": 515,
153
- "48": 260,
154
- "351": 268,
155
- "1-787, 1-939": 330,
156
- "974": 427,
157
- "242": 630,
158
- "40": 226,
159
- "7": 250,
160
- "250": 635,
161
- "290": 658,
162
- "1-869": 356,
163
- "1-758": 358,
164
- "508": 308,
165
- "1-784": 360,
166
- "685": 544,
167
- "378": 292,
168
- "239": 626,
169
- "966": 420,
170
- "221": 608,
171
- "381": 220,
172
- "248": 633,
173
- "232": 619,
174
- "65": 525,
175
- "386": 293,
176
- "677": 540,
177
- "27": 655,
178
- "211": 659,
179
- "34": 214,
180
- "94": 413,
181
- "249": 634,
182
- "597": 746,
183
- "268": 653,
184
- "46": 240,
185
- "41": 228,
186
- "963": 417,
187
- "886": 466,
188
- "992": 436,
189
- "255": 640,
190
- "66": 520,
191
- "228": 615,
192
- "690": 554,
193
- "676": 539,
194
- "1-868": 374,
195
- "216": 605,
196
- "90": 286,
197
- "993": 438,
198
- "1-649": 376,
199
- "688": 553,
200
- "1-340": 332,
201
- "256": 641,
202
- "380": 255,
203
- "971": 424,
204
- "44": 234,
205
- "1": 310,
206
- "598": 748,
207
- "998": 434,
208
- "678": 541,
209
- "379": 225,
210
- "58": 734,
211
- "681": 543,
212
- "967": 421,
213
- "260": 645,
214
- "263": 648,
215
- "670": 514,
216
- "245": 632,
217
- "856": 457,
218
- "599": 362,
219
- "850": 467,
220
- "262": 647,
221
- "82": 450,
222
- "84": 452
223
- }
@@ -1,13 +0,0 @@
1
- /// <reference types="node" />
2
- import { Socket } from 'net';
3
- import { AbstractSocketClient } from './abstract-socket-client';
4
- export declare class MobileSocketClient extends AbstractSocketClient {
5
- protected socket: Socket | null;
6
- get isOpen(): boolean;
7
- get isClosed(): boolean;
8
- get isClosing(): boolean;
9
- get isConnecting(): boolean;
10
- connect(): Promise<void>;
11
- close(): Promise<void>;
12
- send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
13
- }