@genuxofficial/baileys 2.0.0 → 3.0.0

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 (76) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/WAProto.proto +4633 -0
  3. package/engine-requirements.js +1 -1
  4. package/lib/Defaults/index.d.ts +5 -3
  5. package/lib/Defaults/index.js +7 -7
  6. package/lib/Signal/libsignal.js +9 -18
  7. package/lib/Socket/Client/types.d.ts +2 -0
  8. package/lib/Socket/Client/websocket.js +1 -1
  9. package/lib/Socket/business.d.ts +40 -38
  10. package/lib/Socket/chats.d.ts +17 -20
  11. package/lib/Socket/chats.js +1 -85
  12. package/lib/Socket/groups.d.ts +25 -28
  13. package/lib/Socket/groups.js +9 -10
  14. package/lib/Socket/index.d.ts +46 -44
  15. package/lib/Socket/messages-recv.d.ts +37 -36
  16. package/lib/Socket/messages-recv.js +14 -26
  17. package/lib/Socket/messages-send.d.ts +35 -33
  18. package/lib/Socket/messages-send.js +10 -8
  19. package/lib/Socket/newsletter.d.ts +28 -31
  20. package/lib/Socket/newsletter.js +21 -17
  21. package/lib/Socket/socket.d.ts +7 -5
  22. package/lib/Socket/socket.js +1 -1
  23. package/lib/Socket/usync.d.ts +11 -9
  24. package/lib/Socket/usync.js +15 -10
  25. package/lib/Store/make-in-memory-store.d.ts +1 -1
  26. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  27. package/lib/Types/Auth.d.ts +2 -0
  28. package/lib/Types/Chat.d.ts +2 -8
  29. package/lib/Types/Contact.d.ts +0 -5
  30. package/lib/Types/GroupMetadata.d.ts +4 -5
  31. package/lib/Types/Label.d.ts +0 -11
  32. package/lib/Types/Label.js +1 -1
  33. package/lib/Types/LabelAssociation.js +1 -1
  34. package/lib/Types/Message.d.ts +27 -2
  35. package/lib/Types/Newsletter.js +2 -2
  36. package/lib/Types/Socket.d.ts +2 -0
  37. package/lib/Types/index.js +1 -1
  38. package/lib/Utils/auth-utils.js +3 -3
  39. package/lib/Utils/business.js +17 -5
  40. package/lib/Utils/chat-utils.d.ts +10 -8
  41. package/lib/Utils/chat-utils.js +0 -27
  42. package/lib/Utils/crypto.d.ts +16 -14
  43. package/lib/Utils/crypto.js +22 -34
  44. package/lib/Utils/decode-wa-message.d.ts +1 -1
  45. package/lib/Utils/decode-wa-message.js +16 -31
  46. package/lib/Utils/generics.d.ts +8 -33
  47. package/lib/Utils/generics.js +12 -98
  48. package/lib/Utils/link-preview.js +1 -34
  49. package/lib/Utils/make-mutex.d.ts +2 -2
  50. package/lib/Utils/messages-media.d.ts +19 -29
  51. package/lib/Utils/messages-media.js +87 -151
  52. package/lib/Utils/messages.d.ts +8 -5
  53. package/lib/Utils/messages.js +20 -28
  54. package/lib/Utils/noise-handler.d.ts +6 -4
  55. package/lib/Utils/process-message.js +2 -2
  56. package/lib/Utils/validate-connection.d.ts +2 -2
  57. package/lib/WABinary/decode.d.ts +4 -2
  58. package/lib/WABinary/decode.js +7 -17
  59. package/lib/WABinary/encode.d.ts +3 -1
  60. package/lib/WABinary/encode.js +7 -17
  61. package/lib/WABinary/generic-utils.d.ts +6 -6
  62. package/lib/WABinary/generic-utils.js +36 -21
  63. package/lib/WABinary/jid-utils.d.ts +6 -2
  64. package/lib/WABinary/jid-utils.js +5 -1
  65. package/lib/WAM/BinaryInfo.d.ts +12 -2
  66. package/lib/WAM/encode.d.ts +3 -1
  67. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  68. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +23 -14
  69. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  70. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  71. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  72. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -1
  73. package/lib/WAUSync/USyncQuery.js +13 -17
  74. package/package.json +59 -53
  75. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  76. package/lib/Store/make-cache-manager-store.js +0 -83
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.assertMediaContent = exports.downloadMediaMessage = exports.aggregateMessageKeysNotFromMe = exports.updateMessageWithPollUpdate = exports.updateMessageWithReaction = exports.updateMessageWithReceipt = exports.getDevice = exports.extractMessageContent = exports.normalizeMessageContent = exports.getContentType = exports.generateWAMessage = exports.generateWAMessageFromContent = exports.generateWAMessageContent = exports.generateForwardMessageContent = exports.prepareDisappearingMessageSettingContent = exports.prepareWAMessageMedia = exports.generateLinkPreviewIfRequired = exports.extractUrlFromText = void 0;
7
- exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage;
6
+ exports.assertMediaContent = exports.downloadMediaMessage = exports.aggregateMessageKeysNotFromMe = exports.getAggregateVotesInPollMessage = exports.updateMessageWithPollUpdate = exports.updateMessageWithReaction = exports.updateMessageWithReceipt = exports.getDevice = exports.extractMessageContent = exports.normalizeMessageContent = exports.getContentType = exports.generateWAMessage = exports.generateWAMessageFromContent = exports.generateWAMessageContent = exports.generateForwardMessageContent = exports.prepareDisappearingMessageSettingContent = exports.prepareWAMessageMedia = exports.generateLinkPreviewIfRequired = exports.extractUrlFromText = void 0;
8
7
  const boom_1 = require("@hapi/boom");
9
8
  const axios_1 = __importDefault(require("axios"));
10
9
  const crypto_1 = require("crypto");
@@ -82,20 +81,17 @@ const prepareWAMessageMedia = async (message, options) => {
82
81
  media: message[mediaType]
83
82
  };
84
83
  delete uploadData[mediaType];
85
- // check if cacheable + generate cache key
86
84
  const cacheableKey = typeof uploadData.media === 'object' &&
87
- ('url' in uploadData.media) &&
85
+ 'url' in uploadData.media &&
88
86
  !!uploadData.media.url &&
89
- !!options.mediaCache && (
90
- // generate the key
91
- mediaType + ':' + uploadData.media.url.toString());
87
+ !!options.mediaCache &&
88
+ (mediaType + ':' + uploadData.media.url.toString());
92
89
  if (mediaType === 'document' && !uploadData.fileName) {
93
90
  uploadData.fileName = 'file';
94
91
  }
95
92
  if (!uploadData.mimetype) {
96
93
  uploadData.mimetype = MIMETYPE_MAP[mediaType];
97
94
  }
98
- // check for cache hit
99
95
  if (cacheableKey) {
100
96
  const mediaBuff = options.mediaCache.get(cacheableKey);
101
97
  if (mediaBuff) {
@@ -107,28 +103,26 @@ const prepareWAMessageMedia = async (message, options) => {
107
103
  }
108
104
  }
109
105
  const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
110
- const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
111
- (typeof uploadData['jpegThumbnail'] === 'undefined');
106
+ const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData['jpegThumbnail'] === 'undefined';
112
107
  const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
113
108
  const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
114
109
  const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
115
- const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (options.newsletter ? messages_media_1.prepareStream : messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
110
+ const { mediaKey, encFilePath, originalFilePath, fileEncSha256, fileSha256, fileLength } = await (options.newsletter ? messages_media_1.prepareStream : messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
116
111
  logger,
117
112
  saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
118
113
  opts: options.options
119
114
  });
120
- // url safe Base64 encode the SHA256 hash of the body
121
115
  const fileEncSha256B64 = (options.newsletter ? fileSha256 : fileEncSha256 !== null && fileEncSha256 !== void 0 ? fileEncSha256 : fileSha256).toString('base64');
122
116
  const [{ mediaUrl, directPath, handle }] = await Promise.all([
123
117
  (async () => {
124
- const result = await options.upload(encWriteStream, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
118
+ const result = await options.upload(encFilePath, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
125
119
  logger === null || logger === void 0 ? void 0 : logger.debug({ mediaType, cacheableKey }, 'uploaded media');
126
120
  return result;
127
121
  })(),
128
122
  (async () => {
129
123
  try {
130
124
  if (requiresThumbnailComputation) {
131
- const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(bodyPath, mediaType, options);
125
+ const { thumbnail, originalImageDimensions } = await (0, messages_media_1.generateThumbnail)(originalFilePath, mediaType, options);
132
126
  uploadData.jpegThumbnail = thumbnail;
133
127
  if (!uploadData.width && originalImageDimensions) {
134
128
  uploadData.width = originalImageDimensions.width;
@@ -138,11 +132,11 @@ const prepareWAMessageMedia = async (message, options) => {
138
132
  logger === null || logger === void 0 ? void 0 : logger.debug('generated thumbnail');
139
133
  }
140
134
  if (requiresDurationComputation) {
141
- uploadData.seconds = await (0, messages_media_1.getAudioDuration)(bodyPath);
135
+ uploadData.seconds = await (0, messages_media_1.getAudioDuration)(originalFilePath);
142
136
  logger === null || logger === void 0 ? void 0 : logger.debug('computed audio duration');
143
137
  }
144
138
  if (requiresWaveformProcessing) {
145
- uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
139
+ uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(originalFilePath, logger);
146
140
  logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
147
141
  }
148
142
  if (requiresAudioBackground) {
@@ -156,19 +150,15 @@ const prepareWAMessageMedia = async (message, options) => {
156
150
  })(),
157
151
  ])
158
152
  .finally(async () => {
159
- if (!Buffer.isBuffer(encWriteStream)) {
160
- encWriteStream.destroy();
161
- }
162
- // remove tmp files
163
- if (didSaveToTmpPath && bodyPath) {
164
- try {
165
- await fs_1.promises.access(bodyPath);
166
- await fs_1.promises.unlink(bodyPath);
167
- logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp file');
168
- }
169
- catch (error) {
170
- logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
153
+ try {
154
+ await fs_1.promises.unlink(encFilePath);
155
+ if (originalFilePath) {
156
+ await fs_1.promises.unlink(originalFilePath);
171
157
  }
158
+ logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp files');
159
+ }
160
+ catch (error) {
161
+ logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
172
162
  }
173
163
  });
174
164
  const obj = Types_1.WAProto.Message.fromObject({
@@ -275,6 +265,7 @@ const generateWAMessageContent = async (message, options) => {
275
265
  extContent.font = options.font;
276
266
  }
277
267
  m.extendedTextMessage = extContent;
268
+ //WhatsApp always sends secretMessage along with the text message
278
269
  m.messageContextInfo = {
279
270
  messageSecret: (0, crypto_1.randomBytes)(32)
280
271
  };
@@ -932,6 +923,7 @@ function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
932
923
  }
933
924
  return Object.values(voteHashMap);
934
925
  }
926
+ exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage;
935
927
  /** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
936
928
  const aggregateMessageKeysNotFromMe = (keys) => {
937
929
  const keyMap = {};
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { ILogger } from './logger';
2
4
  import { proto } from '../../WAProto';
3
5
  import { KeyPair } from '../Types';
@@ -8,12 +10,12 @@ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public
8
10
  logger: ILogger;
9
11
  routingInfo?: Buffer | undefined;
10
12
  }) => {
11
- encrypt: (plaintext: Uint8Array) => Buffer<ArrayBuffer>;
12
- decrypt: (ciphertext: Uint8Array) => Buffer<ArrayBuffer>;
13
+ encrypt: (plaintext: Uint8Array) => Buffer;
14
+ decrypt: (ciphertext: Uint8Array) => Buffer;
13
15
  authenticate: (data: Uint8Array) => void;
14
16
  mixIntoKey: (data: Uint8Array) => Promise<void>;
15
17
  finishInit: () => Promise<void>;
16
- processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Promise<Buffer<ArrayBuffer>>;
17
- encodeFrame: (data: Buffer | Uint8Array) => Buffer<ArrayBuffer>;
18
+ processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Promise<Buffer>;
19
+ encodeFrame: (data: Buffer | Uint8Array) => Buffer;
18
20
  decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void>;
19
21
  };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
4
- exports.decryptPollVote = decryptPollVote;
3
+ exports.decryptPollVote = exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
5
4
  const WAProto_1 = require("../../WAProto");
6
5
  const Types_1 = require("../Types");
7
6
  const messages_1 = require("../Utils/messages");
@@ -102,6 +101,7 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
102
101
  return Buffer.from(txt);
103
102
  }
104
103
  }
104
+ exports.decryptPollVote = decryptPollVote;
105
105
  const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
106
106
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
107
107
  const meId = creds.me.id;
@@ -3,8 +3,8 @@ import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
3
3
  import { BinaryNode } from '../WABinary';
4
4
  export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
5
5
  export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
6
- export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, "advSecretKey" | "signedIdentityKey" | "signalIdentities">) => {
6
+ export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
7
7
  creds: Partial<AuthenticationCreds>;
8
8
  reply: BinaryNode;
9
9
  };
10
- export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array<ArrayBufferLike>;
10
+ export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;
@@ -1,6 +1,8 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
2
- export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer<ArrayBufferLike>>;
3
- export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, "DOUBLE_BYTE_TOKENS" | "SINGLE_BYTE_TOKENS" | "TAGS">, indexRef?: {
4
+ export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer>;
5
+ export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
4
6
  index: number;
5
7
  }) => BinaryNode;
6
8
  export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
@@ -15,23 +15,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
35
25
  Object.defineProperty(exports, "__esModule", { value: true });
36
26
  exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
37
27
  const util_1 = require("util");
@@ -1,2 +1,4 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
2
- export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, "TAGS" | "TOKEN_MAP">, buffer?: number[]) => Buffer;
4
+ export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => Buffer;
@@ -15,23 +15,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
35
25
  Object.defineProperty(exports, "__esModule", { value: true });
36
26
  exports.encodeBinaryNode = void 0;
37
27
  const constants = __importStar(require("./constants"));
@@ -1,14 +1,14 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { proto } from '../../WAProto';
2
4
  import { BinaryNode } from './types';
3
5
  export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
4
6
  export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
5
7
  export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
6
- export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | undefined;
8
+ export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
7
9
  export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
8
- export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
10
+ export declare const getBinaryNodeChildUInt: (node: BinaryNode | undefined, childTag: string, length: number) => number | undefined;
9
11
  export declare const assertNodeErrorFree: (node: BinaryNode) => void;
10
- export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => {
11
- [_: string]: string;
12
- };
12
+ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => Record<string, string>;
13
13
  export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
14
- export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): any;
14
+ export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'] | undefined, i?: number): string | undefined;
@@ -1,28 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getBinaryNodeChild = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChildren = void 0;
4
- exports.binaryNodeToString = binaryNodeToString;
3
+ exports.binaryNodeToString = exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getBinaryNodeChild = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChildren = void 0;
5
4
  const boom_1 = require("@hapi/boom");
6
5
  const WAProto_1 = require("../../WAProto");
7
6
  // some extra useful utilities
8
7
  const getBinaryNodeChildren = (node, childTag) => {
9
- if (Array.isArray(node === null || node === void 0 ? void 0 : node.content)) {
10
- return node.content.filter(item => item.tag === childTag);
8
+ if (!node || !Array.isArray(node.content)) {
9
+ return [];
11
10
  }
12
- return [];
11
+ return node.content.filter((item) => item.tag === childTag);
13
12
  };
14
13
  exports.getBinaryNodeChildren = getBinaryNodeChildren;
15
14
  const getAllBinaryNodeChildren = ({ content }) => {
16
- if (Array.isArray(content)) {
17
- return content;
18
- }
19
- return [];
15
+ return Array.isArray(content) ? content : [];
20
16
  };
21
17
  exports.getAllBinaryNodeChildren = getAllBinaryNodeChildren;
22
18
  const getBinaryNodeChild = (node, childTag) => {
23
- if (Array.isArray(node === null || node === void 0 ? void 0 : node.content)) {
24
- return node === null || node === void 0 ? void 0 : node.content.find(item => item.tag === childTag);
19
+ if (!node || !Array.isArray(node.content)) {
20
+ return undefined;
25
21
  }
22
+ return node.content.find(item => item.tag === childTag);
26
23
  };
27
24
  exports.getBinaryNodeChild = getBinaryNodeChild;
28
25
  const getBinaryNodeChildBuffer = (node, childTag) => {
@@ -31,6 +28,7 @@ const getBinaryNodeChildBuffer = (node, childTag) => {
31
28
  if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
32
29
  return child;
33
30
  }
31
+ return undefined;
34
32
  };
35
33
  exports.getBinaryNodeChildBuffer = getBinaryNodeChildBuffer;
36
34
  const getBinaryNodeChildString = (node, childTag) => {
@@ -42,6 +40,7 @@ const getBinaryNodeChildString = (node, childTag) => {
42
40
  else if (typeof child === 'string') {
43
41
  return child;
44
42
  }
43
+ return undefined;
45
44
  };
46
45
  exports.getBinaryNodeChildString = getBinaryNodeChildString;
47
46
  const getBinaryNodeChildUInt = (node, childTag, length) => {
@@ -49,31 +48,45 @@ const getBinaryNodeChildUInt = (node, childTag, length) => {
49
48
  if (buff) {
50
49
  return bufferToUInt(buff, length);
51
50
  }
51
+ return undefined;
52
52
  };
53
53
  exports.getBinaryNodeChildUInt = getBinaryNodeChildUInt;
54
54
  const assertNodeErrorFree = (node) => {
55
+ var _a, _b;
55
56
  const errNode = (0, exports.getBinaryNodeChild)(node, 'error');
56
57
  if (errNode) {
57
- throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
58
+ throw new boom_1.Boom(((_a = errNode.attrs) === null || _a === void 0 ? void 0 : _a.text) || 'Unknown error', {
59
+ data: Number((_b = errNode.attrs) === null || _b === void 0 ? void 0 : _b.code) || 0
60
+ });
58
61
  }
59
62
  };
60
63
  exports.assertNodeErrorFree = assertNodeErrorFree;
61
64
  const reduceBinaryNodeToDictionary = (node, tag) => {
62
65
  const nodes = (0, exports.getBinaryNodeChildren)(node, tag);
63
- const dict = nodes.reduce((dict, { attrs }) => {
64
- dict[attrs.name || attrs.config_code] = attrs.value || attrs.config_value;
66
+ return nodes.reduce((dict, { attrs }) => {
67
+ const name = (attrs === null || attrs === void 0 ? void 0 : attrs.name) || (attrs === null || attrs === void 0 ? void 0 : attrs.config_code);
68
+ const value = (attrs === null || attrs === void 0 ? void 0 : attrs.value) || (attrs === null || attrs === void 0 ? void 0 : attrs.config_value);
69
+ if (name && value) {
70
+ dict[name] = value;
71
+ }
65
72
  return dict;
66
73
  }, {});
67
- return dict;
68
74
  };
69
75
  exports.reduceBinaryNodeToDictionary = reduceBinaryNodeToDictionary;
70
76
  const getBinaryNodeMessages = ({ content }) => {
77
+ if (!Array.isArray(content)) {
78
+ return [];
79
+ }
71
80
  const msgs = [];
72
- if (Array.isArray(content)) {
73
- for (const item of content) {
74
- if (item.tag === 'message') {
81
+ for (const item of content) {
82
+ if (item.tag === 'message' && item.content) {
83
+ try {
75
84
  msgs.push(WAProto_1.proto.WebMessageInfo.decode(item.content));
76
85
  }
86
+ catch (error) {
87
+ // Handle decode error if needed
88
+ console.error('Failed to decode message:', error);
89
+ }
77
90
  }
78
91
  }
79
92
  return msgs;
@@ -89,7 +102,7 @@ function bufferToUInt(e, t) {
89
102
  const tabs = (n) => '\t'.repeat(n);
90
103
  function binaryNodeToString(node, i = 0) {
91
104
  if (!node) {
92
- return node;
105
+ return undefined;
93
106
  }
94
107
  if (typeof node === 'string') {
95
108
  return tabs(i) + node;
@@ -101,10 +114,12 @@ function binaryNodeToString(node, i = 0) {
101
114
  return node.map((x) => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
102
115
  }
103
116
  const children = binaryNodeToString(node.content, i + 1);
104
- const tag = `<${node.tag} ${Object.entries(node.attrs || {})
117
+ const attrs = Object.entries(node.attrs || {})
105
118
  .filter(([, v]) => v !== undefined)
106
119
  .map(([k, v]) => `${k}='${v}'`)
107
- .join(' ')}`;
120
+ .join(' ');
121
+ const tag = `<${node.tag}${attrs ? ' ' + attrs : ''}`;
108
122
  const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
109
123
  return tag + content;
110
124
  }
125
+ exports.binaryNodeToString = binaryNodeToString;
@@ -13,12 +13,16 @@ export type FullJid = JidWithDevice & {
13
13
  server: JidServer;
14
14
  domainType?: number;
15
15
  };
16
+ /**
17
+ Get Meta Ai's Jid
18
+ @shizothetechie
19
+ */
16
20
  export declare const getBotJid: (jid: string) => string;
17
21
  export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
18
22
  export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
19
23
  /** is the jid a user */
20
24
  export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
21
- /** is the jid Meta AI */
25
+ /** is the jid a bot (Meta Ai) */
22
26
  export declare const isJidMetaAI: (jid: string | undefined) => boolean | undefined;
23
27
  /** is the jid a user */
24
28
  export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
@@ -31,6 +35,6 @@ export declare const isJidNewsletter: (jid: string | undefined) => boolean | und
31
35
  /** is the jid a group */
32
36
  export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
33
37
  /** is the jid the status broadcast */
34
- export declare const isJidStatusBroadcast: (jid: string) => jid is "status@broadcast";
38
+ export declare const isJidStatusBroadcast: (jid: string) => boolean;
35
39
  export declare const isJidBot: (jid: string | undefined) => boolean | "" | undefined;
36
40
  export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -7,6 +7,10 @@ exports.SERVER_JID = 'server@c.us';
7
7
  exports.PSA_WID = '0@c.us';
8
8
  exports.STORIES_JID = 'status@broadcast';
9
9
  exports.META_AI_JID = '13135550002@c.us';
10
+ /**
11
+ Get Meta Ai's Jid
12
+ @shizothetechie
13
+ */
10
14
  const getBotJid = (jid) => {
11
15
  const BOT_MAP = new Map([["867051314767696", "13135550002"], ["1061492271844689", "13135550005"], ["245886058483988", "13135550009"], ["3509905702656130", "13135550012"], ["1059680132034576", "13135550013"], ["715681030623646", "13135550014"], ["1644971366323052", "13135550015"], ["582497970646566", "13135550019"], ["645459357769306", "13135550022"], ["294997126699143", "13135550023"], ["1522631578502677", "13135550027"], ["719421926276396", "13135550030"], ["1788488635002167", "13135550031"], ["24232338603080193", "13135550033"], ["689289903143209", "13135550035"], ["871626054177096", "13135550039"], ["362351902849370", "13135550042"], ["1744617646041527", "13135550043"], ["893887762270570", "13135550046"], ["1155032702135830", "13135550047"], ["333931965993883", "13135550048"], ["853748013058752", "13135550049"], ["1559068611564819", "13135550053"], ["890487432705716", "13135550054"], ["240254602395494", "13135550055"], ["1578420349663261", "13135550062"], ["322908887140421", "13135550065"], ["3713961535514771", "13135550067"], ["997884654811738", "13135550070"], ["403157239387035", "13135550081"], ["535242369074963", "13135550082"], ["946293427247659", "13135550083"], ["3664707673802291", "13135550084"], ["1821827464894892", "13135550085"], ["1760312477828757", "13135550086"], ["439480398712216", "13135550087"], ["1876735582800984", "13135550088"], ["984025089825661", "13135550089"], ["1001336351558186", "13135550090"], ["3739346336347061", "13135550091"], ["3632749426974980", "13135550092"], ["427864203481615", "13135550093"], ["1434734570493055", "13135550094"], ["992873449225921", "13135550095"], ["813087747426445", "13135550096"], ["806369104931434", "13135550098"], ["1220982902403148", "13135550099"], ["1365893374104393", "13135550100"], ["686482033622048", "13135550200"], ["1454999838411253", "13135550201"], ["718584497008509", "13135550202"], ["743520384213443", "13135550301"], ["1147715789823789", "13135550302"], ["1173034540372201", "13135550303"], ["974785541030953", "13135550304"], ["1122200255531507", "13135550305"], ["899669714813162", "13135550306"], ["631880108970650", "13135550307"], ["435816149330026", "13135550308"], ["1368717161184556", "13135550309"], ["7849963461784891", "13135550310"], ["3609617065968984", "13135550312"], ["356273980574602", "13135550313"], ["1043447920539760", "13135550314"], ["1052764336525346", "13135550315"], ["2631118843732685", "13135550316"], ["510505411332176", "13135550317"], ["1945664239227513", "13135550318"], ["1518594378764656", "13135550319"], ["1378821579456138", "13135550320"], ["490214716896013", "13135550321"], ["1028577858870699", "13135550322"], ["308915665545959", "13135550323"], ["845884253678900", "13135550324"], ["995031308616442", "13135550325"], ["2787365464763437", "13135550326"], ["1532790990671645", "13135550327"], ["302617036180485", "13135550328"], ["723376723197227", "13135550329"], ["8393570407377966", "13135550330"], ["1931159970680725", "13135550331"], ["401073885688605", "13135550332"], ["2234478453565422", "13135550334"], ["814748673882312", "13135550335"], ["26133635056281592", "13135550336"], ["1439804456676119", "13135550337"], ["889851503172161", "13135550338"], ["1018283232836879", "13135550339"], ["1012781386779537", "13135559000"], ["823280953239532", "13135559001"], ["1597090934573334", "13135559002"], ["485965054020343", "13135559003"], ["1033381648363446", "13135559004"], ["491802010206446", "13135559005"], ["1017139033184870", "13135559006"], ["499638325922174", "13135559008"], ["468946335863664", "13135559009"], ["1570389776875816", "13135559010"], ["1004342694328995", "13135559011"], ["1012240323971229", "13135559012"], ["392171787222419", "13135559013"], ["952081212945019", "13135559016"], ["444507875070178", "13135559017"], ["1274819440594668", "13135559018"], ["1397041101147050", "13135559019"], ["425657699872640", "13135559020"], ["532292852562549", "13135559021"], ["705863241720292", "13135559022"], ["476449815183959", "13135559023"], ["488071553854222", "13135559024"], ["468693832665397", "13135559025"], ["517422564037340", "13135559026"], ["819805466613825", "13135559027"], ["1847708235641382", "13135559028"], ["716282970644228", "13135559029"], ["521655380527741", "13135559030"], ["476193631941905", "13135559031"], ["485600497445562", "13135559032"], ["440217235683910", "13135559033"], ["523342446758478", "13135559034"], ["514784864360240", "13135559035"], ["505790121814530", "13135559036"], ["420008964419580", "13135559037"], ["492141680204555", "13135559038"], ["388462787271952", "13135559039"], ["423473920752072", "13135559040"], ["489574180468229", "13135559041"], ["432360635854105", "13135559042"], ["477878201669248", "13135559043"], ["351656951234045", "13135559044"], ["430178036732582", "13135559045"], ["434537312944552", "13135559046"], ["1240614300631808", "13135559047"], ["473135945605128", "13135559048"], ["423669800729310", "13135559049"], ["3685666705015792", "13135559050"], ["504196509016638", "13135559051"], ["346844785189449", "13135559052"], ["504823088911074", "13135559053"], ["402669415797083", "13135559054"], ["490939640234431", "13135559055"], ["875124128063715", "13135559056"], ["468788962654605", "13135559057"], ["562386196354570", "13135559058"], ["372159285928791", "13135559059"], ["531017479591050", "13135559060"], ["1328873881401826", "13135559061"], ["1608363646390484", "13135559062"], ["1229628561554232", "13135559063"], ["348802211530364", "13135559064"], ["3708535859420184", "13135559065"], ["415517767742187", "13135559066"], ["479330341612638", "13135559067"], ["480785414723083", "13135559068"], ["387299107507991", "13135559069"], ["333389813188944", "13135559070"], ["391794130316996", "13135559071"], ["457893470576314", "13135559072"], ["435550496166469", "13135559073"], ["1620162702100689", "13135559074"], ["867491058616043", "13135559075"], ["816224117357759", "13135559076"], ["334065176362830", "13135559077"], ["489973170554709", "13135559078"], ["473060669049665", "13135559079"], ["1221505815643060", "13135559080"], ["889000703096359", "13135559081"], ["475235961979883", "13135559082"], ["3434445653519934", "13135559084"], ["524503026827421", "13135559085"], ["1179639046403856", "13135559086"], ["471563305859144", "13135559087"], ["533896609192881", "13135559088"], ["365443583168041", "13135559089"], ["836082305329393", "13135559090"], ["1056787705969916", "13135559091"], ["503312598958357", "13135559092"], ["3718606738453460", "13135559093"], ["826066052850902", "13135559094"], ["1033611345091888", "13135559095"], ["3868390816783240", "13135559096"], ["7462677740498860", "13135559097"], ["436288576108573", "13135559098"], ["1047559746718900", "13135559099"], ["1099299455255491", "13135559100"], ["1202037301040633", "13135559101"], ["1720619402074074", "13135559102"], ["1030422235101467", "13135559103"], ["827238979523502", "13135559104"], ["1516443722284921", "13135559105"], ["1174442747196709", "13135559106"], ["1653165225503842", "13135559107"], ["1037648777635013", "13135559108"], ["551617757299900", "13135559109"], ["1158813558718726", "13135559110"], ["2463236450542262", "13135559111"], ["1550393252501466", "13135559112"], ["2057065188042796", "13135559113"], ["506163028760735", "13135559114"], ["2065249100538481", "13135559115"], ["1041382867195858", "13135559116"], ["886500209499603", "13135559117"], ["1491615624892655", "13135559118"], ["486563697299617", "13135559119"], ["1175736513679463", "13135559120"], ["491811473512352", "13165550064"]]);
12
16
  const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
@@ -48,7 +52,7 @@ const areJidsSameUser = (jid1, jid2) => {
48
52
  return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
49
53
  };
50
54
  exports.areJidsSameUser = areJidsSameUser;
51
- /** is the jid Meta AI */
55
+ /** is the jid a bot (Meta Ai) */
52
56
  const isJidMetaAI = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@bot'));
53
57
  exports.isJidMetaAI = isJidMetaAI;
54
58
  /** is the jid a user */
@@ -1,8 +1,18 @@
1
- import { EventInputType } from './constants';
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  export declare class BinaryInfo {
3
4
  protocolVersion: number;
4
5
  sequence: number;
5
- events: EventInputType[];
6
+ events: {
7
+ [x: string]: {
8
+ props: {
9
+ [x: string]: import("./constants").Value;
10
+ };
11
+ globals: {
12
+ [x: string]: import("./constants").Value;
13
+ };
14
+ };
15
+ }[];
6
16
  buffer: Buffer[];
7
17
  constructor(options?: Partial<BinaryInfo>);
8
18
  }
@@ -1,2 +1,4 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { BinaryInfo } from './BinaryInfo';
2
- export declare const encodeWAM: (binaryInfo: BinaryInfo) => Buffer<ArrayBuffer>;
4
+ export declare const encodeWAM: (binaryInfo: BinaryInfo) => Buffer;
@@ -9,7 +9,7 @@ class USyncContactProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'contact',
12
- attrs: {}
12
+ attrs: {},
13
13
  };
14
14
  }
15
15
  getUserElement(user) {
@@ -17,7 +17,7 @@ class USyncContactProtocol {
17
17
  return {
18
18
  tag: 'contact',
19
19
  attrs: {},
20
- content: user.phone
20
+ content: user.phone,
21
21
  };
22
22
  }
23
23
  parser(node) {
@@ -10,8 +10,8 @@ class USyncDeviceProtocol {
10
10
  return {
11
11
  tag: 'devices',
12
12
  attrs: {
13
- version: '2'
14
- }
13
+ version: '2',
14
+ },
15
15
  };
16
16
  }
17
17
  getUserElement( /* user: USyncUser */) {
@@ -27,29 +27,38 @@ class USyncDeviceProtocol {
27
27
  (0, WABinary_1.assertNodeErrorFree)(node);
28
28
  const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(node, 'device-list');
29
29
  const keyIndexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'key-index-list');
30
- if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
31
- for (const { tag, attrs } of deviceListNode.content) {
32
- const id = +attrs.id;
33
- const keyIndex = +attrs['key-index'];
34
- if (tag === 'device') {
30
+ if (deviceListNode && Array.isArray(deviceListNode.content)) {
31
+ for (const item of deviceListNode.content) {
32
+ if (item.tag === 'device' && item.attrs) {
33
+ const id = Number(item.attrs.id) || 0;
34
+ const keyIndexValue = item.attrs['key-index']
35
+ ? Number(item.attrs['key-index'])
36
+ : undefined;
37
+ const isHosted = item.attrs['is_hosted'] === 'true';
35
38
  deviceList.push({
36
39
  id,
37
- keyIndex,
38
- isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
40
+ keyIndex: keyIndexValue,
41
+ isHosted
39
42
  });
40
43
  }
41
44
  }
42
45
  }
43
- if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list') {
46
+ if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list' && keyIndexNode.attrs) {
47
+ const timestamp = Number(keyIndexNode.attrs['ts']) || 0;
48
+ const expectedTimestamp = keyIndexNode.attrs['expected_ts']
49
+ ? Number(keyIndexNode.attrs['expected_ts'])
50
+ : undefined;
44
51
  keyIndex = {
45
- timestamp: +keyIndexNode.attrs['ts'],
46
- signedKeyIndex: keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.content,
47
- expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
52
+ timestamp,
53
+ signedKeyIndex: keyIndexNode.content instanceof Uint8Array
54
+ ? keyIndexNode.content
55
+ : undefined,
56
+ expectedTimestamp
48
57
  };
49
58
  }
50
59
  }
51
60
  return {
52
- deviceList,
61
+ deviceList: deviceList.length > 0 ? deviceList : undefined,
53
62
  keyIndex
54
63
  };
55
64
  }
@@ -9,7 +9,7 @@ class USyncDisappearingModeProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'disappearing_mode',
12
- attrs: {}
12
+ attrs: {},
13
13
  };
14
14
  }
15
15
  getUserElement() {
@@ -22,7 +22,7 @@ class USyncDisappearingModeProtocol {
22
22
  const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
23
23
  return {
24
24
  duration,
25
- setAt
25
+ setAt,
26
26
  };
27
27
  }
28
28
  }
@@ -9,7 +9,7 @@ class USyncStatusProtocol {
9
9
  getQueryElement() {
10
10
  return {
11
11
  tag: 'status',
12
- attrs: {}
12
+ attrs: {},
13
13
  };
14
14
  }
15
15
  getUserElement() {
@@ -34,7 +34,7 @@ class USyncStatusProtocol {
34
34
  }
35
35
  return {
36
36
  status,
37
- setAt
37
+ setAt,
38
38
  };
39
39
  }
40
40
  }