@d0v3riz/baileys 6.7.4 → 6.7.6

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 (43) hide show
  1. package/README.md +5 -4
  2. package/lib/Defaults/index.js +3 -1
  3. package/lib/Socket/business.d.ts +8 -5
  4. package/lib/Socket/chats.d.ts +3 -8
  5. package/lib/Socket/chats.js +15 -1
  6. package/lib/Socket/groups.d.ts +9 -1
  7. package/lib/Socket/groups.js +12 -1
  8. package/lib/Socket/index.d.ts +8 -5
  9. package/lib/Socket/messages-recv.d.ts +8 -6
  10. package/lib/Socket/messages-recv.js +105 -12
  11. package/lib/Socket/messages-send.d.ts +5 -3
  12. package/lib/Socket/messages-send.js +83 -71
  13. package/lib/Socket/registration.d.ts +8 -5
  14. package/lib/Socket/socket.js +2 -2
  15. package/lib/Store/make-in-memory-store.js +5 -1
  16. package/lib/Types/Chat.d.ts +2 -0
  17. package/lib/Types/Events.d.ts +5 -1
  18. package/lib/Types/GroupMetadata.d.ts +1 -1
  19. package/lib/Types/Message.d.ts +27 -24
  20. package/lib/Types/Socket.d.ts +5 -0
  21. package/lib/Types/index.d.ts +7 -0
  22. package/lib/Utils/crypto.d.ts +1 -1
  23. package/lib/Utils/crypto.js +4 -2
  24. package/lib/Utils/decode-wa-message.d.ts +1 -0
  25. package/lib/Utils/decode-wa-message.js +16 -7
  26. package/lib/Utils/generics.d.ts +4 -9
  27. package/lib/Utils/generics.js +34 -8
  28. package/lib/Utils/history.d.ts +4 -0
  29. package/lib/Utils/history.js +3 -0
  30. package/lib/Utils/messages-media.js +8 -14
  31. package/lib/Utils/messages.js +48 -58
  32. package/lib/Utils/noise-handler.d.ts +1 -1
  33. package/lib/Utils/noise-handler.js +2 -2
  34. package/lib/Utils/process-message.d.ts +3 -2
  35. package/lib/Utils/process-message.js +47 -24
  36. package/lib/Utils/signal.js +26 -16
  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/lib/WABinary/jid-utils.d.ts +2 -0
  42. package/lib/WABinary/jid-utils.js +4 -1
  43. package/package.json +6 -5
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
4
+ const lodash_1 = require("lodash");
4
5
  const Defaults_1 = require("../Defaults");
5
6
  const WABinary_1 = require("../WABinary");
6
7
  const crypto_1 = require("./crypto");
@@ -66,22 +67,31 @@ const parseAndInjectE2ESessions = async (node, repository) => {
66
67
  for (const node of nodes) {
67
68
  (0, WABinary_1.assertNodeErrorFree)(node);
68
69
  }
69
- await Promise.all(nodes.map(async (node) => {
70
- const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
71
- const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
72
- const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
73
- const jid = node.attrs.jid;
74
- const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
75
- await repository.injectE2ESession({
76
- jid,
77
- session: {
78
- registrationId: registrationId,
79
- identityKey: (0, crypto_1.generateSignalPubKey)(identity),
80
- signedPreKey: extractKey(signedKey),
81
- preKey: extractKey(key)
82
- }
83
- });
84
- }));
70
+ // Most of the work in repository.injectE2ESession is CPU intensive, not IO
71
+ // So Promise.all doesn't really help here,
72
+ // but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
73
+ // This way we chunk it in smaller parts and between those parts we can yield to the event loop
74
+ // It's rare case when you need to E2E sessions for so many users, but it's possible
75
+ const chunkSize = 100;
76
+ const chunks = (0, lodash_1.chunk)(nodes, chunkSize);
77
+ for (const nodesChunk of chunks) {
78
+ await Promise.all(nodesChunk.map(async (node) => {
79
+ const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
80
+ const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
81
+ const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
82
+ const jid = node.attrs.jid;
83
+ const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
84
+ await repository.injectE2ESession({
85
+ jid,
86
+ session: {
87
+ registrationId: registrationId,
88
+ identityKey: (0, crypto_1.generateSignalPubKey)(identity),
89
+ signedPreKey: extractKey(signedKey),
90
+ preKey: extractKey(key)
91
+ }
92
+ });
93
+ }));
94
+ }
85
95
  };
86
96
  exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
87
97
  const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
@@ -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;
@@ -26,4 +26,6 @@ export declare const isJidBroadcast: (jid: string | undefined) => boolean | unde
26
26
  export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
27
27
  /** is the jid the status broadcast */
28
28
  export declare const isJidStatusBroadcast: (jid: string) => boolean;
29
+ /** is the jid a newsletter */
30
+ export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
29
31
  export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
3
+ exports.jidNormalizedUser = exports.isJidNewsletter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
4
  exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
5
  exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
6
  exports.SERVER_JID = 'server@c.us';
@@ -48,6 +48,9 @@ exports.isJidGroup = isJidGroup;
48
48
  /** is the jid the status broadcast */
49
49
  const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
50
50
  exports.isJidStatusBroadcast = isJidStatusBroadcast;
51
+ /** is the jid a newsletter */
52
+ const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
53
+ exports.isJidNewsletter = isJidNewsletter;
51
54
  const jidNormalizedUser = (jid) => {
52
55
  const result = (0, exports.jidDecode)(jid);
53
56
  if (!result) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d0v3riz/baileys",
3
- "version": "6.7.4",
3
+ "version": "6.7.6",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -48,16 +48,17 @@
48
48
  "@hapi/boom": "^9.1.3",
49
49
  "async-lock": "^1.4.1",
50
50
  "audio-decode": "^2.1.3",
51
- "axios": "^1.3.3",
51
+ "axios": "^1.6.0",
52
52
  "cache-manager": "4.0.1",
53
53
  "futoin-hkdf": "^1.5.1",
54
54
  "libphonenumber-js": "^1.10.20",
55
55
  "libsignal": "https://github.com/d0v3riz/libsignal-node.git",
56
+ "lodash": "^4.17.21",
56
57
  "music-metadata": "^7.12.3",
57
58
  "node-cache": "^5.1.2",
58
59
  "pino": "^7.0.0",
59
60
  "protobufjs": "^7.2.4",
60
- "uuid": "^9.0.0",
61
+ "uuid": "^10.0.0",
61
62
  "ws": "^8.13.0"
62
63
  },
63
64
  "devDependencies": {
@@ -76,7 +77,7 @@
76
77
  "open": "^8.4.2",
77
78
  "qrcode-terminal": "^0.12.0",
78
79
  "release-it": "^15.10.3",
79
- "sharp": "^0.30.5",
80
+ "sharp": "^0.32.6",
80
81
  "ts-jest": "^27.0.3",
81
82
  "ts-node": "^10.8.1",
82
83
  "typedoc": "^0.24.7",
@@ -86,7 +87,7 @@
86
87
  "jimp": "^0.16.1",
87
88
  "link-preview-js": "^3.0.0",
88
89
  "qrcode-terminal": "^0.12.0",
89
- "sharp": "^0.32.2"
90
+ "sharp": "^0.32.6"
90
91
  },
91
92
  "peerDependenciesMeta": {
92
93
  "jimp": {