@genuxofficial/baileys 2.0.0 → 4.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 (108) hide show
  1. package/WAProto/WAProto.proto +4451 -0
  2. package/WAProto/index.d.ts +219 -2233
  3. package/WAProto/index.js +525 -6773
  4. package/WAProto/shizo.x +1 -0
  5. package/engine-requirements.js +1 -1
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +236 -3
  8. package/lib/Defaults/index.js +24 -8
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Signal/libsignal.js +9 -18
  11. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -0
  12. package/lib/Socket/Client/index.d.ts +3 -2
  13. package/lib/Socket/Client/index.js +3 -2
  14. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  15. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  16. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  17. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +3 -3
  18. package/lib/Socket/business.d.ts +43 -43
  19. package/lib/Socket/chats.d.ts +17 -23
  20. package/lib/Socket/chats.js +9 -123
  21. package/lib/Socket/groups.d.ts +27 -32
  22. package/lib/Socket/groups.js +5 -18
  23. package/lib/Socket/index.d.ts +51 -49
  24. package/lib/Socket/index.js +2 -2
  25. package/lib/Socket/messages-recv.d.ts +41 -42
  26. package/lib/Socket/messages-recv.js +20 -39
  27. package/lib/Socket/messages-send.d.ts +33 -38
  28. package/lib/Socket/messages-send.js +16 -37
  29. package/lib/Socket/newsletter.d.ts +30 -35
  30. package/lib/Socket/newsletter.js +22 -26
  31. package/lib/Socket/registration.d.ts +271 -0
  32. package/lib/Socket/registration.js +166 -0
  33. package/lib/Socket/socket.d.ts +10 -9
  34. package/lib/Socket/socket.js +19 -16
  35. package/lib/Socket/usync.d.ts +12 -10
  36. package/lib/Socket/usync.js +15 -10
  37. package/lib/Store/index.d.ts +2 -1
  38. package/lib/Store/index.js +3 -1
  39. package/lib/Store/make-in-memory-store.d.ts +1 -1
  40. package/lib/Store/make-in-memory-store.js +10 -8
  41. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  42. package/lib/Store/make-ordered-dictionary.js +2 -2
  43. package/lib/Types/Auth.d.ts +8 -0
  44. package/lib/Types/Chat.d.ts +2 -12
  45. package/lib/Types/Contact.d.ts +1 -6
  46. package/lib/Types/GroupMetadata.d.ts +0 -7
  47. package/lib/Types/Label.d.ts +0 -11
  48. package/lib/Types/Label.js +1 -1
  49. package/lib/Types/LabelAssociation.js +1 -1
  50. package/lib/Types/Message.d.ts +8 -7
  51. package/lib/Types/Message.js +2 -0
  52. package/lib/Types/Newsletter.js +2 -2
  53. package/lib/Types/Socket.d.ts +6 -7
  54. package/lib/Types/index.js +1 -1
  55. package/lib/Utils/auth-utils.d.ts +1 -1
  56. package/lib/Utils/auth-utils.js +12 -5
  57. package/lib/Utils/business.js +2 -2
  58. package/lib/Utils/chat-utils.d.ts +13 -11
  59. package/lib/Utils/chat-utils.js +2 -28
  60. package/lib/Utils/crypto.d.ts +16 -14
  61. package/lib/Utils/crypto.js +22 -34
  62. package/lib/Utils/decode-wa-message.d.ts +2 -4
  63. package/lib/Utils/decode-wa-message.js +24 -160
  64. package/lib/Utils/event-buffer.js +6 -4
  65. package/lib/Utils/generics.d.ts +12 -40
  66. package/lib/Utils/generics.js +25 -103
  67. package/lib/Utils/link-preview.js +1 -34
  68. package/lib/Utils/lt-hash.d.ts +3 -3
  69. package/lib/Utils/lt-hash.js +45 -11
  70. package/lib/Utils/make-mutex.d.ts +2 -2
  71. package/lib/Utils/messages-media.d.ts +16 -26
  72. package/lib/Utils/messages-media.js +26 -102
  73. package/lib/Utils/messages.d.ts +8 -5
  74. package/lib/Utils/messages.js +15 -17
  75. package/lib/Utils/noise-handler.d.ts +8 -5
  76. package/lib/Utils/noise-handler.js +10 -5
  77. package/lib/Utils/process-message.js +2 -2
  78. package/lib/Utils/use-multi-file-auth-state.js +11 -48
  79. package/lib/Utils/validate-connection.d.ts +3 -2
  80. package/lib/Utils/validate-connection.js +44 -10
  81. package/lib/WABinary/constants.js +5 -5
  82. package/lib/WABinary/decode.d.ts +4 -2
  83. package/lib/WABinary/decode.js +7 -17
  84. package/lib/WABinary/encode.d.ts +3 -1
  85. package/lib/WABinary/encode.js +17 -40
  86. package/lib/WABinary/generic-utils.d.ts +3 -1
  87. package/lib/WABinary/generic-utils.js +2 -2
  88. package/lib/WABinary/jid-utils.d.ts +3 -8
  89. package/lib/WABinary/jid-utils.js +2 -23
  90. package/lib/WAM/BinaryInfo.d.ts +12 -2
  91. package/lib/WAM/constants.d.ts +2 -3
  92. package/lib/WAM/encode.d.ts +3 -1
  93. package/lib/WAM/encode.js +2 -2
  94. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  95. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
  96. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  97. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
  98. package/lib/WAUSync/USyncQuery.d.ts +0 -2
  99. package/lib/WAUSync/USyncQuery.js +13 -27
  100. package/lib/WAUSync/USyncUser.d.ts +0 -2
  101. package/lib/WAUSync/USyncUser.js +0 -4
  102. package/package.json +60 -55
  103. package/LICENSE +0 -21
  104. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  105. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  106. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  107. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  108. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -15,37 +15,71 @@ class d {
15
15
  add(e, t) {
16
16
  var r = this;
17
17
  for (const item of t) {
18
- e = r._addSingle(e, item);
18
+ try {
19
+ e = r._addSingle(e, item);
20
+ }
21
+ catch (error) {
22
+ continue;
23
+ }
19
24
  }
20
25
  return e;
21
26
  }
22
27
  subtract(e, t) {
23
28
  var r = this;
24
29
  for (const item of t) {
25
- e = r._subtractSingle(e, item);
30
+ try {
31
+ e = r._subtractSingle(e, item);
32
+ }
33
+ catch (error) {
34
+ continue;
35
+ }
26
36
  }
27
37
  return e;
28
38
  }
29
39
  subtractThenAdd(e, t, r) {
30
40
  var n = this;
31
- return n.add(n.subtract(e, r), t);
41
+ try {
42
+ return n.add(n.subtract(e, r), t);
43
+ }
44
+ catch (error) {
45
+ return e;
46
+ }
32
47
  }
33
48
  async _addSingle(e, t) {
34
49
  var r = this;
35
- const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
36
- return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t));
50
+ try {
51
+ const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
52
+ return r.performPointwiseWithOverflow(await e, n, ((e, t) => e + t));
53
+ }
54
+ catch (error) {
55
+ return e;
56
+ }
37
57
  }
38
58
  async _subtractSingle(e, t) {
39
59
  var r = this;
40
- const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
41
- return r.performPointwiseWithOverflow(await e, n, ((e, t) => e - t));
60
+ try {
61
+ const n = new Uint8Array(await (0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
62
+ return r.performPointwiseWithOverflow(e, n, ((e, t) => e - t));
63
+ }
64
+ catch (error) {
65
+ return e;
66
+ }
42
67
  }
43
68
  performPointwiseWithOverflow(e, t, r) {
44
- const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a);
45
- for (let e = 0; e < n.byteLength; e += 2) {
46
- s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0);
69
+ try {
70
+ const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a);
71
+ for (let e = 0; e < n.byteLength; e += 2) {
72
+ try {
73
+ s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0);
74
+ }
75
+ catch (error) {
76
+ }
77
+ }
78
+ return a;
79
+ }
80
+ catch (error) {
81
+ return e;
47
82
  }
48
- return a;
49
83
  }
50
84
  }
51
85
  exports.LT_HASH_ANTI_TAMPERING = new d('WhatsApp Patch Integrity');
@@ -1,7 +1,7 @@
1
1
  export declare const makeMutex: () => {
2
- mutex<T>(code: () => Promise<T> | T): Promise<T>;
2
+ mutex<T>(code: () => T | Promise<T>): Promise<T>;
3
3
  };
4
4
  export type Mutex = ReturnType<typeof makeMutex>;
5
5
  export declare const makeKeyedMutex: () => {
6
- mutex<T>(key: string, task: () => Promise<T> | T): Promise<T>;
6
+ mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>;
7
7
  };
@@ -1,3 +1,7 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
1
5
  import { Boom } from '@hapi/boom';
2
6
  import { AxiosRequestConfig } from 'axios';
3
7
  import { Readable, Transform } from 'stream';
@@ -10,7 +14,7 @@ export declare const hkdfInfoKey: (type: MediaType) => string;
10
14
  /** generates all the keys required to encrypt/decrypt & sign a media message */
11
15
  export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): Promise<MediaDecryptionKeyInfo>;
12
16
  export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
13
- buffer: Buffer<ArrayBufferLike>;
17
+ buffer: Buffer;
14
18
  original: {
15
19
  width: number | undefined;
16
20
  height: number | undefined;
@@ -18,21 +22,7 @@ export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | s
18
22
  }>;
19
23
  export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
20
24
  export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Promise<{
21
- img: Buffer<ArrayBufferLike>;
22
- }>;
23
- export declare const generateProfilePictureFull: (img: any) => Promise<{
24
- img: any;
25
- }>;
26
- export declare const generateProfilePictureFP: (buffer: any) => Promise<{
27
- img: any;
28
- preview: any;
29
- }>;
30
- export declare const generatePP: (buffer: any) => Promise<{
31
- img: any;
32
- preview: any;
33
- }>;
34
- export declare const changeprofileFull: (img: any) => Promise<{
35
- img: any;
25
+ img: Buffer;
36
26
  }>;
37
27
  /** gets the SHA256 of the given media message */
38
28
  export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
@@ -40,9 +30,9 @@ export declare function getAudioDuration(buffer: Buffer | string | Readable): Pr
40
30
  /**
41
31
  referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
42
32
  */
43
- export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: ILogger): Promise<Uint8Array<ArrayBuffer> | undefined>;
33
+ export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: ILogger): Promise<Uint8Array | undefined>;
44
34
  export declare const toReadable: (buffer: Buffer) => Readable;
45
- export declare const toBuffer: (stream: Readable) => Promise<Buffer<ArrayBuffer>>;
35
+ export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
46
36
  export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
47
37
  readonly stream: Readable;
48
38
  readonly type: "buffer";
@@ -76,20 +66,20 @@ type EncryptedStreamOptions = {
76
66
  };
77
67
  export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
78
68
  mediaKey: undefined;
79
- encWriteStream: Buffer<ArrayBuffer>;
69
+ encWriteStream: Buffer;
80
70
  fileLength: number;
81
- fileSha256: Buffer<ArrayBufferLike>;
71
+ fileSha256: Buffer;
82
72
  fileEncSha256: undefined;
83
73
  bodyPath: string | undefined;
84
74
  didSaveToTmpPath: boolean;
85
75
  }>;
86
76
  export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
87
- mediaKey: Buffer<ArrayBufferLike>;
77
+ mediaKey: Buffer;
88
78
  encWriteStream: Readable;
89
79
  bodyPath: string | undefined;
90
- mac: Buffer<ArrayBuffer>;
91
- fileEncSha256: Buffer<ArrayBufferLike>;
92
- fileSha256: Buffer<ArrayBufferLike>;
80
+ mac: Buffer;
81
+ fileEncSha256: Buffer;
82
+ fileSha256: Buffer;
93
83
  fileLength: number;
94
84
  didSaveToTmpPath: boolean;
95
85
  }>;
@@ -116,8 +106,8 @@ export declare const decodeMediaRetryNode: (node: BinaryNode) => {
116
106
  media?: {
117
107
  ciphertext: Uint8Array;
118
108
  iv: Uint8Array;
119
- };
120
- error?: Boom;
109
+ } | undefined;
110
+ error?: Boom<any> | undefined;
121
111
  };
122
112
  export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
123
113
  ciphertext: Uint8Array;
@@ -15,33 +15,18 @@ 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
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
27
  };
38
28
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.prepareStream = exports.getHttpStream = exports.getStream = exports.toBuffer = exports.toReadable = exports.mediaMessageSHA256B64 = exports.changeprofileFull = exports.generatePP = exports.generateProfilePictureFP = exports.generateProfilePictureFull = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.hkdfInfoKey = void 0;
40
- exports.getMediaKeys = getMediaKeys;
41
- exports.getAudioDuration = getAudioDuration;
42
- exports.getAudioWaveform = getAudioWaveform;
43
- exports.generateThumbnail = generateThumbnail;
44
- exports.extensionForMediaMessage = extensionForMediaMessage;
29
+ exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.extensionForMediaMessage = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.prepareStream = exports.getHttpStream = exports.generateThumbnail = exports.getStream = exports.toBuffer = exports.toReadable = exports.getAudioWaveform = exports.getAudioDuration = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getMediaKeys = exports.hkdfInfoKey = void 0;
45
30
  const boom_1 = require("@hapi/boom");
46
31
  const axios_1 = __importDefault(require("axios"));
47
32
  const child_process_1 = require("child_process");
@@ -61,11 +46,13 @@ const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
61
46
  const getImageProcessingLibrary = async () => {
62
47
  const [_jimp, sharp] = await Promise.all([
63
48
  (async () => {
64
- const jimp = await (Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { }));
49
+ const jimp = await (import('jimp')
50
+ .catch(() => { }));
65
51
  return jimp;
66
52
  })(),
67
53
  (async () => {
68
- const sharp = await (Promise.resolve().then(() => __importStar(require('sharp'))).catch(() => { }));
54
+ const sharp = await (import('sharp')
55
+ .catch(() => { }));
69
56
  return sharp;
70
57
  })()
71
58
  ]);
@@ -99,6 +86,7 @@ async function getMediaKeys(buffer, mediaType) {
99
86
  macKey: expandedMediaKey.slice(48, 80),
100
87
  };
101
88
  }
89
+ exports.getMediaKeys = getMediaKeys;
102
90
  /** Extracts video thumb using FFMPEG */
103
91
  const extractVideoThumb = async (path, destPath, time, size) => new Promise((resolve, reject) => {
104
92
  const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`;
@@ -180,76 +168,6 @@ const generateProfilePicture = async (mediaUpload) => {
180
168
  };
181
169
  };
182
170
  exports.generateProfilePicture = generateProfilePicture;
183
- const generateProfilePictureFull = async (img) => {
184
- const Jimp = require('jimp');
185
- const { read, MIME_JPEG, RESIZE_BILINEAR } = require('jimp');
186
- const jimp = await read(img);
187
- const min = Math.min(jimp.getWidth(), jimp.getHeight());
188
- const cropped = jimp.crop(0, 0, jimp.getWidth(), jimp.getHeight());
189
- let width = jimp.getWidth(), hight = jimp.getHeight(), ratio;
190
- if (width > hight) {
191
- ratio = jimp.getWidth() / 720;
192
- }
193
- else {
194
- ratio = jimp.getWidth() / 324;
195
- }
196
- ;
197
- width = width / ratio;
198
- hight = hight / ratio;
199
- img = cropped.quality(100).resize(width, hight).getBufferAsync(MIME_JPEG);
200
- return {
201
- img: await cropped.quality(100).resize(width, hight).getBufferAsync(MIME_JPEG),
202
- };
203
- };
204
- exports.generateProfilePictureFull = generateProfilePictureFull;
205
- const generateProfilePictureFP = async (buffer) => {
206
- const Jimp = require('jimp');
207
- const { read, MIME_JPEG, RESIZE_BILINEAR } = require('jimp');
208
- const jimp = await Jimp.read(buffer);
209
- const min = jimp.getWidth();
210
- const max = jimp.getHeight();
211
- const cropped = jimp.crop(0, 0, min, max);
212
- return {
213
- img: await cropped.scaleToFit(720, 720).getBufferAsync(Jimp.MIME_JPEG),
214
- preview: await cropped.normalize().getBufferAsync(Jimp.MIME_JPEG),
215
- };
216
- };
217
- exports.generateProfilePictureFP = generateProfilePictureFP;
218
- const generatePP = async (buffer) => {
219
- const Jimp = require('jimp');
220
- const { read, MIME_JPEG, RESIZE_BILINEAR } = require('jimp');
221
- const jimp = await Jimp.read(buffer);
222
- const min = jimp.getWidth();
223
- const max = jimp.getHeight();
224
- const cropped = jimp.crop(0, 0, min, max);
225
- return {
226
- img: await cropped.scaleToFit(720, 720).getBufferAsync(Jimp.MIME_JPEG),
227
- preview: await cropped.normalize().getBufferAsync(Jimp.MIME_JPEG),
228
- };
229
- };
230
- exports.generatePP = generatePP;
231
- const changeprofileFull = async (img) => {
232
- const Jimp = require('jimp');
233
- const { read, MIME_JPEG, RESIZE_BILINEAR } = require('jimp');
234
- const jimp = await read(img);
235
- const min = Math.min(jimp.getWidth(), jimp.getHeight());
236
- const cropped = jimp.crop(0, 0, jimp.getWidth(), jimp.getHeight());
237
- let width = jimp.getWidth(), hight = jimp.getHeight(), ratio;
238
- if (width > hight) {
239
- ratio = jimp.getWidth() / 720;
240
- }
241
- else {
242
- ratio = jimp.getWidth() / 324;
243
- }
244
- ;
245
- width = width / ratio;
246
- hight = hight / ratio;
247
- img = cropped.quality(100).resize(width, hight).getBufferAsync(MIME_JPEG);
248
- return {
249
- img: await cropped.quality(100).resize(width, hight).getBufferAsync(MIME_JPEG),
250
- };
251
- };
252
- exports.changeprofileFull = changeprofileFull;
253
171
  /** gets the SHA256 of the given media message */
254
172
  const mediaMessageSHA256B64 = (message) => {
255
173
  const media = Object.values(message)[0];
@@ -257,7 +175,7 @@ const mediaMessageSHA256B64 = (message) => {
257
175
  };
258
176
  exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
259
177
  async function getAudioDuration(buffer) {
260
- const musicMetadata = await Promise.resolve().then(() => __importStar(require('music-metadata')));
178
+ const musicMetadata = await import('music-metadata');
261
179
  let metadata;
262
180
  if (Buffer.isBuffer(buffer)) {
263
181
  metadata = await musicMetadata.parseBuffer(buffer, undefined, { duration: true });
@@ -276,6 +194,7 @@ async function getAudioDuration(buffer) {
276
194
  }
277
195
  return metadata.format.duration;
278
196
  }
197
+ exports.getAudioDuration = getAudioDuration;
279
198
  /**
280
199
  referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
281
200
  */
@@ -317,6 +236,7 @@ async function getAudioWaveform(buffer, logger) {
317
236
  logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
318
237
  }
319
238
  }
239
+ exports.getAudioWaveform = getAudioWaveform;
320
240
  const toReadable = (buffer) => {
321
241
  const readable = new stream_1.Readable({ read: () => { } });
322
242
  readable.push(buffer);
@@ -362,7 +282,7 @@ async function generateThumbnail(file, mediaType, options) {
362
282
  }
363
283
  }
364
284
  else if (mediaType === 'video') {
365
- const imgFilename = (0, path_1.join)(getTmpFilesDirectory(), (0, generics_1.generateMessageIDV2)() + '.jpg');
285
+ const imgFilename = (0, path_1.join)(getTmpFilesDirectory(), (0, generics_1.generateMessageID)() + '.jpg');
366
286
  try {
367
287
  await extractVideoThumb(file, imgFilename, '00:00:00', { width: 32, height: 32 });
368
288
  const buff = await fs_1.promises.readFile(imgFilename);
@@ -378,6 +298,7 @@ async function generateThumbnail(file, mediaType, options) {
378
298
  originalImageDimensions
379
299
  };
380
300
  }
301
+ exports.generateThumbnail = generateThumbnail;
381
302
  const getHttpStream = async (url, options = {}) => {
382
303
  const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
383
304
  return fetched.data;
@@ -394,7 +315,7 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
394
315
  bodyPath = media.url;
395
316
  }
396
317
  else if (saveOriginalFileIfRequired) {
397
- bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageIDV2)());
318
+ bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
398
319
  (0, fs_1.writeFileSync)(bodyPath, buffer);
399
320
  didSaveToTmpPath = true;
400
321
  }
@@ -437,10 +358,10 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
437
358
  let writeStream;
438
359
  let didSaveToTmpPath = false;
439
360
  if (type === 'file') {
440
- bodyPath = media.url.toString();
361
+ bodyPath = media.url;
441
362
  }
442
363
  else if (saveOriginalFileIfRequired) {
443
- bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageIDV2)());
364
+ bodyPath = (0, path_1.join)(getTmpFilesDirectory(), mediaType + (0, generics_1.generateMessageID)());
444
365
  writeStream = (0, fs_1.createWriteStream)(bodyPath);
445
366
  didSaveToTmpPath = true;
446
367
  }
@@ -460,8 +381,10 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
460
381
  });
461
382
  }
462
383
  sha256Plain = sha256Plain.update(data);
463
- if (writeStream && !writeStream.write(data)) {
464
- await (0, events_1.once)(writeStream, 'drain');
384
+ if (writeStream) {
385
+ if (!writeStream.write(data)) {
386
+ await (0, events_1.once)(writeStream, 'drain');
387
+ }
465
388
  }
466
389
  onChunk(aes.update(data));
467
390
  }
@@ -628,6 +551,7 @@ function extensionForMediaMessage(message) {
628
551
  }
629
552
  return extension;
630
553
  }
554
+ exports.extensionForMediaMessage = extensionForMediaMessage;
631
555
  const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
632
556
  return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
633
557
  var _a, _b;
@@ -1,3 +1,6 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
1
4
  import { type Transform } from 'stream';
2
5
  import { proto } from '../../WAProto';
3
6
  import { ILogger } from './logger';
@@ -9,7 +12,7 @@ import { MediaDownloadOptions } from './messages-media';
9
12
  * @returns the URL, eg. https://google.com
10
13
  */
11
14
  export declare const extractUrlFromText: (text: string) => string | undefined;
12
- export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions["getUrlInfo"], logger: MessageGenerationOptions["logger"]) => Promise<import("../Types").WAUrlInfo | undefined>;
15
+ export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions['getUrlInfo'], logger: MessageGenerationOptions['logger']) => Promise<import("../Types").WAUrlInfo | undefined>;
13
16
  export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MediaGenerationOptions) => Promise<proto.Message>;
14
17
  export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => proto.Message;
15
18
  /**
@@ -40,11 +43,11 @@ export declare const extractMessageContent: (content: WAMessageContent | undefin
40
43
  */
41
44
  export declare const getDevice: (id: string) => "android" | "unknown" | "web" | "ios" | "desktop";
42
45
  /** Upserts a receipt in the message */
43
- export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, "userReceipt">, receipt: MessageUserReceipt) => void;
46
+ export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, 'userReceipt'>, receipt: MessageUserReceipt) => void;
44
47
  /** Update the message with a new reaction */
45
- export declare const updateMessageWithReaction: (msg: Pick<WAMessage, "reactions">, reaction: proto.IReaction) => void;
48
+ export declare const updateMessageWithReaction: (msg: Pick<WAMessage, 'reactions'>, reaction: proto.IReaction) => void;
46
49
  /** Update the message with a new poll update */
47
- export declare const updateMessageWithPollUpdate: (msg: Pick<WAMessage, "pollUpdates">, update: proto.IPollUpdate) => void;
50
+ export declare const updateMessageWithPollUpdate: (msg: Pick<WAMessage, 'pollUpdates'>, update: proto.IPollUpdate) => void;
48
51
  type VoteAggregation = {
49
52
  name: string;
50
53
  voters: string[];
@@ -69,7 +72,7 @@ type DownloadMediaMessageContext = {
69
72
  /**
70
73
  * Downloads the given message. Throws an error if it's not a media message
71
74
  */
72
- export declare const downloadMediaMessage: <Type extends "buffer" | "stream">(message: WAMessage, type: Type, options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Type extends "buffer" ? Buffer<ArrayBufferLike> : Transform>;
75
+ export declare const downloadMediaMessage: <Type extends "stream" | "buffer">(message: WAMessage, type: Type, options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Type extends "buffer" ? Buffer : Transform>;
73
76
  /** Checks whether the given message is a media message; if it is returns the inner content */
74
77
  export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
75
78
  export {};
@@ -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");
@@ -275,9 +274,6 @@ const generateWAMessageContent = async (message, options) => {
275
274
  extContent.font = options.font;
276
275
  }
277
276
  m.extendedTextMessage = extContent;
278
- m.messageContextInfo = {
279
- messageSecret: (0, crypto_1.randomBytes)(32)
280
- };
281
277
  }
282
278
  else if ('contacts' in message) {
283
279
  const contactLen = message.contacts.contacts.length;
@@ -737,7 +733,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
737
733
  key: {
738
734
  remoteJid: jid,
739
735
  fromMe: true,
740
- id: (options === null || options === void 0 ? void 0 : options.messageId) || (0, generics_1.generateMessageIDV2)(),
736
+ id: (options === null || options === void 0 ? void 0 : options.messageId) || (0, generics_1.generateMessageID)(),
741
737
  },
742
738
  message: message,
743
739
  messageTimestamp: timestamp,
@@ -801,10 +797,7 @@ const normalizeMessageContent = (content) => {
801
797
  || (message === null || message === void 0 ? void 0 : message.pollCreationMessageV4)
802
798
  || (message === null || message === void 0 ? void 0 : message.pollCreationMessageV5)
803
799
  || (message === null || message === void 0 ? void 0 : message.statusAddYours)
804
- || (message === null || message === void 0 ? void 0 : message.groupStatusMessage)
805
- || (message === null || message === void 0 ? void 0 : message.limitSharingMessage)
806
- || (message === null || message === void 0 ? void 0 : message.botTaskMessage)
807
- || (message === null || message === void 0 ? void 0 : message.questionMessage));
800
+ || (message === null || message === void 0 ? void 0 : message.groupStatusMessage));
808
801
  }
809
802
  };
810
803
  exports.normalizeMessageContent = normalizeMessageContent;
@@ -932,6 +925,7 @@ function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
932
925
  }
933
926
  return Object.values(voteHashMap);
934
927
  }
928
+ exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage;
935
929
  /** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
936
930
  const aggregateMessageKeysNotFromMe = (keys) => {
937
931
  const keyMap = {};
@@ -959,13 +953,17 @@ const downloadMediaMessage = async (message, type, options, ctx) => {
959
953
  const result = await downloadMsg()
960
954
  .catch(async (error) => {
961
955
  var _a;
962
- if (ctx && axios_1.default.isAxiosError(error) && // check if the message requires a reupload
963
- REUPLOAD_REQUIRED_STATUS.includes((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
964
- ctx.logger.info({ key: message.key }, 'sending reupload media request...');
965
- // request reupload
966
- message = await ctx.reuploadRequest(message);
967
- const result = await downloadMsg();
968
- return result;
956
+ if (ctx) {
957
+ if (axios_1.default.isAxiosError(error)) {
958
+ // check if the message requires a reupload
959
+ if (REUPLOAD_REQUIRED_STATUS.includes((_a = error.response) === null || _a === void 0 ? void 0 : _a.status)) {
960
+ ctx.logger.info({ key: message.key }, 'sending reupload media request...');
961
+ // request reupload
962
+ message = await ctx.reuploadRequest(message);
963
+ const result = await downloadMsg();
964
+ return result;
965
+ }
966
+ }
969
967
  }
970
968
  throw error;
971
969
  });
@@ -1,19 +1,22 @@
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';
4
6
  import { BinaryNode } from '../WABinary';
5
- export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
7
+ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }: {
6
8
  keyPair: KeyPair;
7
9
  NOISE_HEADER: Uint8Array;
10
+ mobile: boolean;
8
11
  logger: ILogger;
9
12
  routingInfo?: Buffer | undefined;
10
13
  }) => {
11
- encrypt: (plaintext: Uint8Array) => Buffer<ArrayBuffer>;
12
- decrypt: (ciphertext: Uint8Array) => Buffer<ArrayBuffer>;
14
+ encrypt: (plaintext: Uint8Array) => Buffer;
15
+ decrypt: (ciphertext: Uint8Array) => Buffer;
13
16
  authenticate: (data: Uint8Array) => void;
14
17
  mixIntoKey: (data: Uint8Array) => Promise<void>;
15
18
  finishInit: () => Promise<void>;
16
- processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Promise<Buffer<ArrayBuffer>>;
17
- encodeFrame: (data: Buffer | Uint8Array) => Buffer<ArrayBuffer>;
19
+ processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Promise<Buffer>;
20
+ encodeFrame: (data: Buffer | Uint8Array) => Buffer;
18
21
  decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void>;
19
22
  };
@@ -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, logger, routingInfo }) => {
14
+ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }) => {
15
15
  logger = logger.child({ class: 'ns' });
16
16
  const authenticate = (data) => {
17
17
  if (!isFinished) {
@@ -83,10 +83,15 @@ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey },
83
83
  const decStaticContent = decrypt(serverHello.static);
84
84
  await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent));
85
85
  const certDecoded = decrypt(serverHello.payload);
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 });
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
+ }
90
95
  }
91
96
  const keyEnc = encrypt(noiseKey.public);
92
97
  await mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
@@ -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;