@badzz88/baileys 8.5.7 → 8.5.8

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 (142) hide show
  1. package/README.md +337 -1055
  2. package/WAProto/WAProto.proto +284 -264
  3. package/WAProto/index.js +5 -5
  4. package/engine-requirements.js +7 -15
  5. package/lib/Defaults/index.js +130 -187
  6. package/lib/Signal/Group/ciphertext-message.js +11 -14
  7. package/lib/Signal/Group/group-session-builder.js +29 -91
  8. package/lib/Signal/Group/group_cipher.js +81 -88
  9. package/lib/Signal/Group/index.js +12 -136
  10. package/lib/Signal/Group/keyhelper.js +15 -70
  11. package/lib/Signal/Group/sender-chain-key.js +25 -31
  12. package/lib/Signal/Group/sender-key-distribution-message.js +62 -65
  13. package/lib/Signal/Group/sender-key-message.js +65 -68
  14. package/lib/Signal/Group/sender-key-name.js +41 -43
  15. package/lib/Signal/Group/sender-key-record.js +40 -43
  16. package/lib/Signal/Group/sender-key-state.js +83 -96
  17. package/lib/Signal/Group/sender-message-key.js +25 -29
  18. package/lib/Signal/libsignal.js +425 -453
  19. package/lib/Signal/lid-mapping.js +276 -259
  20. package/lib/Socket/Client/index.js +3 -30
  21. package/lib/Socket/Client/types.js +10 -12
  22. package/lib/Socket/Client/websocket.js +53 -61
  23. package/lib/Socket/business.js +379 -422
  24. package/lib/Socket/chats.js +1193 -1816
  25. package/lib/Socket/communities.js +431 -549
  26. package/lib/Socket/graphql.js +672 -612
  27. package/lib/Socket/groups.js +374 -764
  28. package/lib/Socket/index.js +17 -38
  29. package/lib/Socket/interop.js +417 -503
  30. package/lib/Socket/messages-recv.js +1915 -2441
  31. package/lib/Socket/messages-send.js +1213 -1630
  32. package/lib/Socket/mex.js +9 -15
  33. package/lib/Socket/newsletter.js +747 -808
  34. package/lib/Socket/privacy.js +310 -441
  35. package/lib/Socket/socket.js +1025 -1022
  36. package/lib/Socket/username.js +8 -15
  37. package/lib/Store/index.js +10 -36
  38. package/lib/Store/make-cache-manager-store.js +80 -85
  39. package/lib/Store/make-in-memory-store.js +231 -591
  40. package/lib/Store/make-ordered-dictionary.js +72 -78
  41. package/lib/Store/object-repository.js +28 -25
  42. package/lib/Types/Auth.js +2 -38
  43. package/lib/Types/Bussines.js +2 -2
  44. package/lib/Types/Call.js +2 -2
  45. package/lib/Types/Chat.js +8 -4
  46. package/lib/Types/Contact.js +2 -2
  47. package/lib/Types/Events.js +2 -2
  48. package/lib/Types/GroupMetadata.js +2 -2
  49. package/lib/Types/Label.js +24 -26
  50. package/lib/Types/LabelAssociation.js +6 -8
  51. package/lib/Types/Message.js +11 -95
  52. package/lib/Types/Mex.js +111 -112
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.js +2 -2
  55. package/lib/Types/Socket.js +3 -2
  56. package/lib/Types/State.js +56 -70
  57. package/lib/Types/USync.js +2 -2
  58. package/lib/Types/index.js +26 -55
  59. package/lib/Utils/auth-utils.js +288 -292
  60. package/lib/Utils/browser-utils.js +47 -113
  61. package/lib/Utils/business.js +224 -240
  62. package/lib/Utils/chat-utils.js +869 -1205
  63. package/lib/Utils/companion-reg-client-utils.js +34 -41
  64. package/lib/Utils/crypto.js +107 -144
  65. package/lib/Utils/decode-wa-message.js +308 -518
  66. package/lib/Utils/event-buffer.js +611 -596
  67. package/lib/Utils/generics.js +355 -515
  68. package/lib/Utils/history.js +134 -244
  69. package/lib/Utils/identity-change-handler.js +49 -51
  70. package/lib/Utils/index.js +23 -57
  71. package/lib/Utils/link-preview.js +77 -135
  72. package/lib/Utils/logger.js +3 -9
  73. package/lib/Utils/lt-hash.js +6 -37
  74. package/lib/Utils/make-mutex.js +33 -36
  75. package/lib/Utils/message-composer.js +233 -439
  76. package/lib/Utils/message-retry-manager.js +260 -265
  77. package/lib/Utils/messages-media.js +829 -855
  78. package/lib/Utils/messages.js +961 -2528
  79. package/lib/Utils/noise-handler.js +200 -195
  80. package/lib/Utils/offline-node-processor.js +33 -35
  81. package/lib/Utils/pre-key-manager.js +102 -103
  82. package/lib/Utils/process-message.js +560 -978
  83. package/lib/Utils/reporting-utils.js +253 -257
  84. package/lib/Utils/signal.js +195 -218
  85. package/lib/Utils/stanza-ack.js +29 -31
  86. package/lib/Utils/sticker.js +109 -144
  87. package/lib/Utils/sync-action-utils.js +45 -50
  88. package/lib/Utils/tc-token-utils.js +139 -137
  89. package/lib/Utils/use-multi-file-auth-state.js +109 -109
  90. package/lib/Utils/validate-connection.js +202 -218
  91. package/lib/WABinary/constants.js +1299 -1302
  92. package/lib/WABinary/decode.js +262 -343
  93. package/lib/WABinary/encode.js +4 -12
  94. package/lib/WABinary/generic-utils.js +187 -223
  95. package/lib/WABinary/index.js +6 -33
  96. package/lib/WABinary/jid-utils.js +88 -351
  97. package/lib/WABinary/types.js +2 -2
  98. package/lib/WAM/BinaryInfo.js +9 -12
  99. package/lib/WAM/constants.js +22853 -39486
  100. package/lib/WAM/encode.js +140 -132
  101. package/lib/WAM/index.js +4 -31
  102. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +21 -23
  103. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +9 -9
  104. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -7
  105. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +10 -10
  106. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +7 -7
  107. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +11 -12
  108. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +4 -5
  109. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +7 -7
  110. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +7 -8
  111. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -7
  112. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +8 -8
  113. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +7 -7
  114. package/lib/WAUSync/Protocols/index.js +12 -39
  115. package/lib/WAUSync/USyncQuery.js +67 -49
  116. package/lib/WAUSync/USyncUser.js +11 -5
  117. package/lib/WAUSync/index.js +3 -31
  118. package/lib/index.js +15 -48
  119. package/package.json +129 -99
  120. package/LICENSE +0 -21
  121. package/lib/Defaults/phonenumber-mcc.json +0 -223
  122. package/lib/Socket/aigroups.js +0 -240
  123. package/lib/Socket/interactive-handler.js +0 -522
  124. package/lib/Socket/managed-account.js +0 -183
  125. package/lib/Socket/registration.js +0 -427
  126. package/lib/Socket/text-router.js +0 -83
  127. package/lib/Types/Newsletter.js +0 -121
  128. package/lib/Utils/command-loader.d.ts +0 -31
  129. package/lib/Utils/command-loader.js +0 -100
  130. package/lib/Utils/consumer-application.js +0 -107
  131. package/lib/Utils/curve25519-js.js +0 -275
  132. package/lib/Utils/group-history.js +0 -60
  133. package/lib/Utils/jid-display-normalization.js +0 -218
  134. package/lib/Utils/meta-ai-msmsg.js +0 -262
  135. package/lib/Utils/native-bridge.js +0 -82
  136. package/lib/Utils/session-pool.d.ts +0 -16
  137. package/lib/Utils/session-pool.js +0 -94
  138. package/lib/Utils/sticker.d.ts +0 -17
  139. package/lib/Utils/view-once-cache.d.ts +0 -9
  140. package/lib/Utils/view-once-cache.js +0 -79
  141. package/lib/Utils/voip-rekey.js +0 -22
  142. package/lib/antiban.js +0 -4637
@@ -1,143 +1,85 @@
1
- 'use strict'
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k
7
- var desc = Object.getOwnPropertyDescriptor(m, k)
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k]
13
- }
14
- }
15
- }
16
- Object.defineProperty(o, k2, desc)
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k
20
- o[k2] = m[k]
21
- })
22
- var __setModuleDefault =
23
- (this && this.__setModuleDefault) ||
24
- (Object.create
25
- ? function (o, v) {
26
- Object.defineProperty(o, 'default', { enumerable: true, value: v })
27
- }
28
- : function (o, v) {
29
- o['default'] = v
30
- })
31
- var __importStar =
32
- (this && this.__importStar) ||
33
- (function () {
34
- var ownKeys = function (o) {
35
- ownKeys =
36
- Object.getOwnPropertyNames ||
37
- function (o) {
38
- var ar = []
39
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k
40
- return ar
41
- }
42
- return ownKeys(o)
43
- }
44
- return function (mod) {
45
- if (mod && mod.__esModule) return mod
46
- var result = {}
47
- if (mod != null)
48
- for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== 'default') __createBinding(result, mod, k[i])
49
- __setModuleDefault(result, mod)
50
- return result
51
- }
52
- })()
53
- Object.defineProperty(exports, '__esModule', { value: true })
54
- exports.getUrlInfo = void 0
55
- const messages_1 = require('./messages')
56
- const messages_media_1 = require('./messages-media')
57
- const THUMBNAIL_WIDTH_PX = 192
1
+ import { prepareWAMessageMedia } from './messages.js';
2
+ import { extractImageThumb, getHttpStream } from './messages-media.js';
3
+ const THUMBNAIL_WIDTH_PX = 192;
58
4
  /** Fetches an image and generates a thumbnail for it */
59
5
  const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
60
- const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts)
61
- const result = await (0, messages_media_1.extractImageThumb)(stream, thumbnailWidth)
62
- return result
63
- }
6
+ const stream = await getHttpStream(url, fetchOpts);
7
+ const result = await extractImageThumb(stream, thumbnailWidth);
8
+ return result;
9
+ };
64
10
  /**
65
11
  * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
66
12
  * Return undefined if the fetch failed or no URL was found
67
13
  * @param text first matched URL in text
68
14
  * @returns the URL info required to generate link preview
69
15
  */
70
- const getUrlInfo = async (
71
- text,
72
- opts = {
73
- thumbnailWidth: THUMBNAIL_WIDTH_PX,
74
- fetchOpts: { timeout: 3000 }
75
- }
76
- ) => {
77
- try {
78
- // retries
79
- const retries = 0
80
- const maxRetry = 5
81
- const { getLinkPreview } = await Promise.resolve().then(() => __importStar(require('link-preview-js')))
82
- let previewLink = text
83
- if (!text.startsWith('https://') && !text.startsWith('http://')) {
84
- previewLink = 'https://' + previewLink
85
- }
86
- const info = await getLinkPreview(previewLink, {
87
- ...opts.fetchOpts,
88
- followRedirects: 'follow',
89
- handleRedirects: (baseURL, forwardedURL) => {
90
- const urlObj = new URL(baseURL)
91
- const forwardedURLObj = new URL(forwardedURL)
92
- if (retries >= maxRetry) {
93
- return false
94
- }
95
- if (
96
- forwardedURLObj.hostname === urlObj.hostname ||
97
- forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
98
- 'www.' + forwardedURLObj.hostname === urlObj.hostname
99
- ) {
100
- retries + 1
101
- return true
102
- } else {
103
- return false
104
- }
105
- },
106
- headers: opts.fetchOpts?.headers
107
- })
108
- if (info && 'title' in info && info.title) {
109
- const [image] = info.images
110
- const urlInfo = {
111
- 'canonical-url': info.url,
112
- 'matched-text': text,
113
- title: info.title,
114
- description: info.description,
115
- originalThumbnailUrl: image
116
- }
117
- if (opts.uploadImage) {
118
- const { imageMessage } = await (0, messages_1.prepareWAMessageMedia)(
119
- { image: { url: image } },
120
- {
121
- upload: opts.uploadImage,
122
- mediaTypeOverride: 'thumbnail-link',
123
- options: opts.fetchOpts
124
- }
125
- )
126
- urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined
127
- urlInfo.highQualityThumbnail = imageMessage || undefined
128
- } else {
129
- try {
130
- urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined
131
- } catch (error) {
132
- opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail')
133
- }
134
- }
135
- return urlInfo
136
- }
137
- } catch (error) {
138
- if (!error.message.includes('receive a valid')) {
139
- throw error
140
- }
141
- }
142
- }
143
- exports.getUrlInfo = getUrlInfo
16
+ export const getUrlInfo = async (text, opts = {
17
+ thumbnailWidth: THUMBNAIL_WIDTH_PX,
18
+ fetchOpts: { timeout: 3000 }
19
+ }) => {
20
+ try {
21
+ // retries
22
+ let retries = 0;
23
+ const maxRetry = 5;
24
+ const { getLinkPreview } = await import('link-preview-js');
25
+ let previewLink = text;
26
+ if (!text.startsWith('https://') && !text.startsWith('http://')) {
27
+ previewLink = 'https://' + previewLink;
28
+ }
29
+ const info = await getLinkPreview(previewLink, {
30
+ ...opts.fetchOpts,
31
+ followRedirects: 'follow',
32
+ handleRedirects: (baseURL, forwardedURL) => {
33
+ const urlObj = new URL(baseURL);
34
+ const forwardedURLObj = new URL(forwardedURL);
35
+ if (retries >= maxRetry) {
36
+ return false;
37
+ }
38
+ if (forwardedURLObj.hostname === urlObj.hostname ||
39
+ forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
40
+ 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
41
+ retries += 1;
42
+ return true;
43
+ }
44
+ else {
45
+ return false;
46
+ }
47
+ },
48
+ headers: opts.fetchOpts?.headers
49
+ });
50
+ if (info && 'title' in info && info.title) {
51
+ const [image] = info.images;
52
+ const urlInfo = {
53
+ 'canonical-url': info.url,
54
+ 'matched-text': text,
55
+ title: info.title,
56
+ description: info.description,
57
+ originalThumbnailUrl: image
58
+ };
59
+ if (opts.uploadImage) {
60
+ const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
61
+ upload: opts.uploadImage,
62
+ mediaTypeOverride: 'thumbnail-link',
63
+ options: opts.fetchOpts
64
+ });
65
+ urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
66
+ urlInfo.highQualityThumbnail = imageMessage || undefined;
67
+ }
68
+ else {
69
+ try {
70
+ urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
71
+ }
72
+ catch (error) {
73
+ opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
74
+ }
75
+ }
76
+ return urlInfo;
77
+ }
78
+ }
79
+ catch (error) {
80
+ if (!error.message.includes('receive a valid')) {
81
+ throw error;
82
+ }
83
+ }
84
+ };
85
+ //# sourceMappingURL=link-preview.js.map
@@ -1,9 +1,3 @@
1
- 'use strict'
2
- var __importDefault =
3
- (this && this.__importDefault) ||
4
- function (mod) {
5
- return mod && mod.__esModule ? mod : { default: mod }
6
- }
7
- Object.defineProperty(exports, '__esModule', { value: true })
8
- const pino_1 = __importDefault(require('pino'))
9
- exports.default = (0, pino_1.default)({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
1
+ import P from 'pino';
2
+ export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
3
+ //# sourceMappingURL=logger.js.map
@@ -1,39 +1,8 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.LT_HASH_ANTI_TAMPERING = void 0
4
- const crypto_1 = require('./crypto')
5
-
1
+ import { LTHashAntiTampering } from 'whatsapp-rust-bridge';
6
2
  /**
7
- * LT Hash ("lthash16") is a summation-based homomorphic hash algorithm that
8
- * maintains the integrity of a piece of data over a series of mutations. You
9
- * can add/remove mutations and it'll return a hash equal to if the same
10
- * series of mutations was made sequentially.
11
- *
12
- * WhatsApp expands each element to 128 bytes via HKDF (info = "WhatsApp Patch
13
- * Integrity"), treats that as 64 little-endian uint16 lanes, and combines
14
- * elements by adding/subtracting lane-wise mod 2^16 -- this is a pure HKDF +
15
- * integer-arithmetic algorithm, no elliptic-curve math involved. Pure-JS,
16
- * built on the already-validated `hkdf` implementation.
3
+ * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
4
+ * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
5
+ * if the same series of mutations was made sequentially.
17
6
  */
18
- const LTHASH_INFO = 'WhatsApp Patch Integrity'
19
- const LTHASH_SIZE = 128 // bytes = 64 uint16 lanes
20
-
21
- const expand = element => (0, crypto_1.hkdf)(element, LTHASH_SIZE, { info: LTHASH_INFO })
22
-
23
- const applyDelta = (result, element, sign) => {
24
- const expanded = expand(element)
25
- for (let i = 0; i < LTHASH_SIZE; i += 2) {
26
- const lane = result.readUInt16LE(i)
27
- const delta = expanded.readUInt16LE(i)
28
- result.writeUInt16LE((lane + sign * delta) & 0xffff, i)
29
- }
30
- }
31
-
32
- exports.LT_HASH_ANTI_TAMPERING = {
33
- subtractThenAdd: (base, subtract = [], add = []) => {
34
- const result = Buffer.from(base)
35
- for (const element of subtract) applyDelta(result, element, -1)
36
- for (const element of add) applyDelta(result, element, 1)
37
- return result
38
- }
39
- }
7
+ export const LT_HASH_ANTI_TAMPERING = new LTHashAntiTampering();
8
+ //# sourceMappingURL=lt-hash.js.map
@@ -1,36 +1,33 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.makeKeyedMutex = exports.makeMutex = void 0
4
- const async_mutex_1 = require('async-mutex')
5
- const makeMutex = () => {
6
- const mutex = new async_mutex_1.Mutex()
7
- return {
8
- mutex(code) {
9
- return mutex.runExclusive(code)
10
- }
11
- }
12
- }
13
- exports.makeMutex = makeMutex
14
- const makeKeyedMutex = () => {
15
- const map = new Map()
16
- return {
17
- async mutex(key, task) {
18
- let entry = map.get(key)
19
- if (!entry) {
20
- entry = { mutex: new async_mutex_1.Mutex(), refCount: 0 }
21
- map.set(key, entry)
22
- }
23
- entry.refCount++
24
- try {
25
- return await entry.mutex.runExclusive(task)
26
- } finally {
27
- entry.refCount--
28
- // only delete it if this is still the current entry
29
- if (entry.refCount === 0 && map.get(key) === entry) {
30
- map.delete(key)
31
- }
32
- }
33
- }
34
- }
35
- }
36
- exports.makeKeyedMutex = makeKeyedMutex
1
+ import { Mutex as AsyncMutex } from 'async-mutex';
2
+ export const makeMutex = () => {
3
+ const mutex = new AsyncMutex();
4
+ return {
5
+ mutex(code) {
6
+ return mutex.runExclusive(code);
7
+ }
8
+ };
9
+ };
10
+ export const makeKeyedMutex = () => {
11
+ const map = new Map();
12
+ return {
13
+ async mutex(key, task) {
14
+ let entry = map.get(key);
15
+ if (!entry) {
16
+ entry = { mutex: new AsyncMutex(), refCount: 0 };
17
+ map.set(key, entry);
18
+ }
19
+ entry.refCount++;
20
+ try {
21
+ return await entry.mutex.runExclusive(task);
22
+ }
23
+ finally {
24
+ entry.refCount--;
25
+ // only delete it if this is still the current entry
26
+ if (entry.refCount === 0 && map.get(key) === entry) {
27
+ map.delete(key);
28
+ }
29
+ }
30
+ }
31
+ };
32
+ };
33
+ //# sourceMappingURL=make-mutex.js.map