@celestial-community/baileys 0.0.1-security → 1.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.

Potentially problematic release.


This version of @celestial-community/baileys might be problematic. Click here for more details.

Files changed (175) hide show
  1. package/WAProto/index.js +138933 -0
  2. package/engine-requirements.js +10 -0
  3. package/lib/Defaults/baileys-version.json +7 -0
  4. package/lib/Defaults/index.js +157 -0
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.js +15 -0
  7. package/lib/Signal/Group/group-session-builder.js +94 -0
  8. package/lib/Signal/Group/group_cipher.js +118 -0
  9. package/lib/Signal/Group/index.js +138 -0
  10. package/lib/Signal/Group/keyhelper.js +75 -0
  11. package/lib/Signal/Group/queue-job.js +54 -0
  12. package/lib/Signal/Group/sender-chain-key.js +39 -0
  13. package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
  14. package/lib/Signal/Group/sender-key-message.js +76 -0
  15. package/lib/Signal/Group/sender-key-name.js +50 -0
  16. package/lib/Signal/Group/sender-key-record.js +65 -0
  17. package/lib/Signal/Group/sender-key-state.js +114 -0
  18. package/lib/Signal/Group/sender-message-key.js +33 -0
  19. package/lib/Signal/libsignal.js +204 -0
  20. package/lib/Signal/lid-mapping.js +267 -0
  21. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  22. package/lib/Socket/Client/index.js +32 -0
  23. package/lib/Socket/Client/mobile-socket-client.js +82 -0
  24. package/lib/Socket/Client/web-socket-client.js +89 -0
  25. package/lib/Socket/Denzy-ZeroDay.js +805 -0
  26. package/lib/Socket/business.js +279 -0
  27. package/lib/Socket/chats.js +1169 -0
  28. package/lib/Socket/community.d.ts +120 -0
  29. package/lib/Socket/community.js +388 -0
  30. package/lib/Socket/graphql.js +1122 -0
  31. package/lib/Socket/groups.js +345 -0
  32. package/lib/Socket/index.js +22 -0
  33. package/lib/Socket/interop.js +265 -0
  34. package/lib/Socket/lid-mapping.js +111 -0
  35. package/lib/Socket/messages-recv.js +1385 -0
  36. package/lib/Socket/messages-send.js +956 -0
  37. package/lib/Socket/mex.js +69 -0
  38. package/lib/Socket/newsletter.js +424 -0
  39. package/lib/Socket/privacy.js +229 -0
  40. package/lib/Socket/registration.js +190 -0
  41. package/lib/Socket/socket.js +783 -0
  42. package/lib/Socket/username.d.ts +185 -0
  43. package/lib/Socket/username.js +168 -0
  44. package/lib/Socket/usync.js +80 -0
  45. package/lib/Store/index.js +14 -0
  46. package/lib/Store/keyed-db.js +158 -0
  47. package/lib/Store/make-cache-manager-store.js +88 -0
  48. package/lib/Store/make-in-memory-store.js +484 -0
  49. package/lib/Store/make-ordered-dictionary.js +78 -0
  50. package/lib/Store/object-repository.js +27 -0
  51. package/lib/Types/Auth.js +2 -0
  52. package/lib/Types/Call.js +2 -0
  53. package/lib/Types/Chat.js +10 -0
  54. package/lib/Types/Contact.js +2 -0
  55. package/lib/Types/Events.js +2 -0
  56. package/lib/Types/GroupMetadata.js +2 -0
  57. package/lib/Types/Label.js +27 -0
  58. package/lib/Types/LabelAssociation.js +9 -0
  59. package/lib/Types/Message.js +14 -0
  60. package/lib/Types/MexUpdates.js +19 -0
  61. package/lib/Types/Newsletter.js +38 -0
  62. package/lib/Types/Product.js +2 -0
  63. package/lib/Types/RichType.js +30 -0
  64. package/lib/Types/Signal.js +2 -0
  65. package/lib/Types/Socket.js +2 -0
  66. package/lib/Types/State.js +2 -0
  67. package/lib/Types/USync.js +2 -0
  68. package/lib/Types/index.js +58 -0
  69. package/lib/Utils/anti-ban.js +339 -0
  70. package/lib/Utils/anti-delete.d.ts +158 -0
  71. package/lib/Utils/anti-delete.js +293 -0
  72. package/lib/Utils/antiban-presets.js +91 -0
  73. package/lib/Utils/antiban-profiles.js +43 -0
  74. package/lib/Utils/auth-utils.js +210 -0
  75. package/lib/Utils/baileys-event-stream.js +66 -0
  76. package/lib/Utils/browser-utils.js +52 -0
  77. package/lib/Utils/business.js +261 -0
  78. package/lib/Utils/chat-control.d.ts +113 -0
  79. package/lib/Utils/chat-control.js +230 -0
  80. package/lib/Utils/chat-utils.js +922 -0
  81. package/lib/Utils/companion-reg-client-utils.js +37 -0
  82. package/lib/Utils/contact-graph-warmer.js +208 -0
  83. package/lib/Utils/crypto.js +196 -0
  84. package/lib/Utils/decode-wa-message.js +208 -0
  85. package/lib/Utils/delivery-tracker.js +110 -0
  86. package/lib/Utils/device-fingerprint.js +135 -0
  87. package/lib/Utils/event-buffer.js +531 -0
  88. package/lib/Utils/generics.js +571 -0
  89. package/lib/Utils/group-operation-guard.js +147 -0
  90. package/lib/Utils/health-monitor.js +207 -0
  91. package/lib/Utils/history.js +122 -0
  92. package/lib/Utils/human-entropy.js +226 -0
  93. package/lib/Utils/identity-change-handler.js +72 -0
  94. package/lib/Utils/index.js +83 -0
  95. package/lib/Utils/interactive-message.d.ts +139 -0
  96. package/lib/Utils/interactive-message.js +273 -0
  97. package/lib/Utils/legitimacy-signal-injector.js +180 -0
  98. package/lib/Utils/link-preview.js +106 -0
  99. package/lib/Utils/logger.d.ts +13 -0
  100. package/lib/Utils/logger.js +9 -0
  101. package/lib/Utils/lt-hash.js +54 -0
  102. package/lib/Utils/make-mutex.js +41 -0
  103. package/lib/Utils/message-composer.d.ts +106 -0
  104. package/lib/Utils/message-composer.js +721 -0
  105. package/lib/Utils/message-retry-manager.d.ts +88 -0
  106. package/lib/Utils/message-retry-manager.js +160 -0
  107. package/lib/Utils/message-search.d.ts +52 -0
  108. package/lib/Utils/message-search.js +226 -0
  109. package/lib/Utils/messages-media.js +899 -0
  110. package/lib/Utils/messages.js +2698 -0
  111. package/lib/Utils/noise-handler.js +175 -0
  112. package/lib/Utils/offline-node-processor.js +45 -0
  113. package/lib/Utils/pre-key-manager.js +131 -0
  114. package/lib/Utils/presence-choreographer.js +438 -0
  115. package/lib/Utils/process-message.js +423 -0
  116. package/lib/Utils/rate-limiter.js +232 -0
  117. package/lib/Utils/reconnect-throttle.js +157 -0
  118. package/lib/Utils/reply-ratio-guard.js +137 -0
  119. package/lib/Utils/reporting-utils.js +307 -0
  120. package/lib/Utils/retry-reason-tracker.js +140 -0
  121. package/lib/Utils/rich-message-utils.d.ts +48 -0
  122. package/lib/Utils/rich-message-utils.js +400 -0
  123. package/lib/Utils/rich-response-utils.js +461 -0
  124. package/lib/Utils/scheduling.d.ts +135 -0
  125. package/lib/Utils/scheduling.js +246 -0
  126. package/lib/Utils/session-fingerprint.js +226 -0
  127. package/lib/Utils/session-stability.js +224 -0
  128. package/lib/Utils/signal.js +188 -0
  129. package/lib/Utils/stanza-ack.js +38 -0
  130. package/lib/Utils/state-manager.js +91 -0
  131. package/lib/Utils/status-posting.d.ts +81 -0
  132. package/lib/Utils/status-posting.js +187 -0
  133. package/lib/Utils/stealth-connect.js +124 -0
  134. package/lib/Utils/sync-action-utils.js +55 -0
  135. package/lib/Utils/tc-token-utils.js +171 -0
  136. package/lib/Utils/templates.d.ts +54 -0
  137. package/lib/Utils/templates.js +244 -0
  138. package/lib/Utils/timelock-guard.js +162 -0
  139. package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
  140. package/lib/Utils/use-mongo-file-auth-state.js +81 -0
  141. package/lib/Utils/use-multi-file-auth-state.js +125 -0
  142. package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
  143. package/lib/Utils/use-single-file-auth-state.js +86 -0
  144. package/lib/Utils/use-sqlite-auth-state.js +187 -0
  145. package/lib/Utils/vCard.d.ts +71 -0
  146. package/lib/Utils/vCard.js +196 -0
  147. package/lib/Utils/validate-connection.js +253 -0
  148. package/lib/Utils/warmup.js +154 -0
  149. package/lib/WABinary/constants.js +1303 -0
  150. package/lib/WABinary/decode.js +270 -0
  151. package/lib/WABinary/encode.js +279 -0
  152. package/lib/WABinary/generic-utils.js +223 -0
  153. package/lib/WABinary/index.js +34 -0
  154. package/lib/WABinary/jid-utils.js +84 -0
  155. package/lib/WABinary/types.js +2 -0
  156. package/lib/WAM/BinaryInfo.js +13 -0
  157. package/lib/WAM/constants.js +15254 -0
  158. package/lib/WAM/encode.js +149 -0
  159. package/lib/WAM/index.js +32 -0
  160. package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
  161. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +71 -0
  162. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +32 -0
  163. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
  164. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
  165. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +58 -0
  166. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  167. package/lib/WAUSync/Protocols/index.js +34 -0
  168. package/lib/WAUSync/USyncQuery.js +99 -0
  169. package/lib/WAUSync/USyncUser.js +26 -0
  170. package/lib/WAUSync/USyncUsernameProtocol.d.ts +9 -0
  171. package/lib/WAUSync/USyncUsernameProtocol.js +37 -0
  172. package/lib/WAUSync/index.js +32 -0
  173. package/lib/index.js +59 -0
  174. package/package.json +105 -5
  175. package/README.md +0 -5
@@ -0,0 +1,180 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.LegitimacySignalInjector = void 0
4
+
5
+ /**
6
+ * @file legitimacy-signal-injector.js
7
+ * @description Injects human imperfection signals into WA messages.
8
+ * WA detection looks for TOO perfect accounts: no typos, consistent
9
+ * reply speeds, typing duration linearly correlated with message length.
10
+ * This module injects realistic imperfections:
11
+ * - Typos followed by corrections (2.5% of messages)
12
+ * - Read-receipt without immediate reply (read gap)
13
+ * - Mid-typing pauses for longer messages
14
+ * Ported from baileys-antiban to CJS for bilis.
15
+ * @author Denzy ZeroDay (port), Kobus Wentzel (original)
16
+ */
17
+
18
+ const QWERTY_ADJACENT = {
19
+ a: ['q', 's', 'w', 'z'],
20
+ b: ['v', 'g', 'h', 'n'],
21
+ c: ['x', 'd', 'f', 'v'],
22
+ d: ['s', 'e', 'r', 'f', 'c', 'x'],
23
+ e: ['w', 'r', 'd', 's'],
24
+ f: ['d', 'r', 't', 'g', 'v', 'c'],
25
+ g: ['f', 't', 'y', 'h', 'b', 'v'],
26
+ h: ['g', 'y', 'u', 'j', 'n', 'b'],
27
+ i: ['u', 'o', 'k', 'j'],
28
+ j: ['h', 'u', 'i', 'k', 'n', 'm'],
29
+ k: ['j', 'i', 'o', 'l', 'm'],
30
+ l: ['k', 'o', 'p'],
31
+ m: ['n', 'j', 'k'],
32
+ n: ['b', 'h', 'j', 'm'],
33
+ o: ['i', 'p', 'l', 'k'],
34
+ p: ['o', 'l'],
35
+ q: ['w', 'a'],
36
+ r: ['e', 't', 'f', 'd'],
37
+ s: ['a', 'w', 'e', 'd', 'x', 'z'],
38
+ t: ['r', 'y', 'g', 'f'],
39
+ u: ['y', 'i', 'j', 'h'],
40
+ v: ['c', 'f', 'g', 'b'],
41
+ w: ['q', 'e', 's', 'a'],
42
+ x: ['z', 's', 'd', 'c'],
43
+ y: ['t', 'u', 'h', 'g'],
44
+ z: ['a', 's', 'x']
45
+ }
46
+
47
+ const DEFAULT_CONFIG = {
48
+ enableTypos: true,
49
+ typoProbability: 0.025,
50
+ typoCorrectMinMs: 500,
51
+ typoCorrectMaxMs: 2000,
52
+ enableReadGaps: true,
53
+ readGapProbability: 0.15,
54
+ readGapMinMs: 300000,
55
+ readGapMaxMs: 3600000,
56
+ enableTypingPauses: true,
57
+ typingPauseLengthThreshold: 50,
58
+ typingPauseProbability: 0.4,
59
+ typingPauseMinMs: 1500,
60
+ typingPauseMaxMs: 6000
61
+ }
62
+
63
+ class LegitimacySignalInjector {
64
+ constructor(config = {}) {
65
+ this.config = { ...DEFAULT_CONFIG, ...config }
66
+ this.stats = {
67
+ typosInjected: 0,
68
+ correctionsGenerated: 0,
69
+ readGapsInjected: 0,
70
+ typingPausesInjected: 0
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Check if a typo should be injected for this message.
76
+ * Returns { typoText, correctionDelay, correctionText } or null.
77
+ */
78
+ shouldInjectTypo(text) {
79
+ if (!this.config.enableTypos || text.length <= 10) return null
80
+ if (Math.random() >= this.config.typoProbability) return null
81
+ if (/https?:\/\/|www\./i.test(text)) return null
82
+
83
+ const words = text.split(/\s+/)
84
+ const eligible = words.filter(
85
+ (w) => w.length >= 3 && !w.startsWith('@') && !/^\d+$/.test(w)
86
+ )
87
+ if (eligible.length === 0) return null
88
+
89
+ const targetWord = eligible[Math.floor(Math.random() * eligible.length)]
90
+ const typoWord = this._injectTypoInWord(targetWord)
91
+ if (!typoWord || typoWord === targetWord) return null
92
+
93
+ const typoText = text.replace(targetWord, typoWord)
94
+ const correctionDelay = this._rand(
95
+ this.config.typoCorrectMinMs,
96
+ this.config.typoCorrectMaxMs
97
+ )
98
+ const correctionText = text.length < 30 ? text : `*${targetWord}`
99
+
100
+ this.stats.typosInjected++
101
+ this.stats.correctionsGenerated++
102
+
103
+ return { typoText, correctionDelay, correctionText }
104
+ }
105
+
106
+ /**
107
+ * Check if a read gap should be injected before replying.
108
+ * Returns gap duration in ms, or null.
109
+ */
110
+ shouldInjectReadGap() {
111
+ if (!this.config.enableReadGaps) return null
112
+ if (Math.random() >= this.config.readGapProbability) return null
113
+ const gapMs = this._rand(this.config.readGapMinMs, this.config.readGapMaxMs)
114
+ this.stats.readGapsInjected++
115
+ return gapMs
116
+ }
117
+
118
+ /**
119
+ * Calculate mid-typing pause positions for long messages.
120
+ * Returns array of { afterChars, pauseDurationMs }.
121
+ */
122
+ getTypingPauses(messageLength) {
123
+ if (!this.config.enableTypingPauses) return []
124
+ if (messageLength < this.config.typingPauseLengthThreshold) return []
125
+ if (Math.random() >= this.config.typingPauseProbability) return []
126
+
127
+ const pauses = []
128
+ const numPauses = Math.random() < 0.6 ? 1 : 2
129
+
130
+ for (let i = 0; i < numPauses; i++) {
131
+ const pct = i === 0 ? 0.35 + Math.random() * 0.15 : 0.65 + Math.random() * 0.15
132
+ pauses.push({
133
+ afterChars: Math.floor(messageLength * pct),
134
+ pauseDurationMs: this._rand(
135
+ this.config.typingPauseMinMs,
136
+ this.config.typingPauseMaxMs
137
+ )
138
+ })
139
+ this.stats.typingPausesInjected++
140
+ }
141
+
142
+ return pauses.sort((a, b) => a.afterChars - b.afterChars)
143
+ }
144
+
145
+ getStats() {
146
+ return { ...this.stats }
147
+ }
148
+
149
+ reset() {
150
+ this.stats = {
151
+ typosInjected: 0,
152
+ correctionsGenerated: 0,
153
+ readGapsInjected: 0,
154
+ typingPausesInjected: 0
155
+ }
156
+ }
157
+
158
+ _injectTypoInWord(word) {
159
+ const chars = word.toLowerCase().split('')
160
+ const eligible = chars.map((c, i) => ({ c, i })).filter(({ c }) => QWERTY_ADJACENT[c])
161
+ if (eligible.length === 0) return null
162
+
163
+ const target = eligible[Math.floor(Math.random() * eligible.length)]
164
+ const neighbors = QWERTY_ADJACENT[target.c]
165
+ const rep = neighbors[Math.floor(Math.random() * neighbors.length)]
166
+ const orig = word[target.i]
167
+ const repChar = orig === orig.toUpperCase() ? rep.toUpperCase() : rep
168
+
169
+ const typo = word.split('')
170
+ typo[target.i] = repChar
171
+ return typo.join('')
172
+ }
173
+
174
+ _rand(min, max) {
175
+ return Math.floor(Math.random() * (max - min + 1)) + min
176
+ }
177
+ }
178
+
179
+ exports.LegitimacySignalInjector = LegitimacySignalInjector
180
+ module.exports = { LegitimacySignalInjector, QWERTY_ADJACENT }
@@ -0,0 +1,106 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.getUrlInfo = void 0
4
+ const messages_1 = require('./messages')
5
+ const messages_media_1 = require('./messages-media')
6
+ const THUMBNAIL_WIDTH_PX = 192
7
+ /** Fetches an image and generates a thumbnail for it */
8
+ const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
9
+ const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts)
10
+ const result = await (0, messages_media_1.extractImageThumb)(stream, thumbnailWidth)
11
+ return result
12
+ }
13
+ /**
14
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
15
+ * Return undefined if the fetch failed or no URL was found
16
+ * @param text first matched URL in text
17
+ * @returns the URL info required to generate link preview
18
+ */
19
+ const getUrlInfo = async (
20
+ text,
21
+ opts = {
22
+ thumbnailWidth: THUMBNAIL_WIDTH_PX,
23
+ fetchOpts: { timeout: 3000 }
24
+ }
25
+ ) => {
26
+ var _a
27
+ try {
28
+ // retries
29
+ const retries = 0
30
+ const maxRetry = 5
31
+ const { getLinkPreview } = await import('link-preview-js')
32
+ let previewLink = text
33
+ if (!text.startsWith('https://') && !text.startsWith('http://')) {
34
+ previewLink = 'https://' + previewLink
35
+ }
36
+ const info = await getLinkPreview(previewLink, {
37
+ ...opts.fetchOpts,
38
+ followRedirects: 'follow',
39
+ handleRedirects: (baseURL, forwardedURL) => {
40
+ const urlObj = new URL(baseURL)
41
+ const forwardedURLObj = new URL(forwardedURL)
42
+ if (retries >= maxRetry) {
43
+ return false
44
+ }
45
+ if (
46
+ forwardedURLObj.hostname === urlObj.hostname ||
47
+ forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
48
+ 'www.' + forwardedURLObj.hostname === urlObj.hostname
49
+ ) {
50
+ retries + 1
51
+ return true
52
+ } else {
53
+ return false
54
+ }
55
+ },
56
+ headers: opts.fetchOpts
57
+ })
58
+ if (info && 'title' in info && info.title) {
59
+ const [image] = info.images
60
+ const urlInfo = {
61
+ 'canonical-url': info.url,
62
+ 'matched-text': text,
63
+ title: info.title,
64
+ description: info.description,
65
+ originalThumbnailUrl: image
66
+ }
67
+ if (opts.uploadImage) {
68
+ const { imageMessage } = await (0, messages_1.prepareWAMessageMedia)(
69
+ { image: { url: image } },
70
+ {
71
+ upload: opts.uploadImage,
72
+ mediaTypeOverride: 'thumbnail-link',
73
+ options: opts.fetchOpts
74
+ }
75
+ )
76
+ urlInfo.jpegThumbnail = (
77
+ imageMessage === null || imageMessage === void 0
78
+ ? void 0
79
+ : imageMessage.jpegThumbnail
80
+ )
81
+ ? Buffer.from(imageMessage.jpegThumbnail)
82
+ : undefined
83
+ urlInfo.highQualityThumbnail = imageMessage || undefined
84
+ } else {
85
+ try {
86
+ urlInfo.jpegThumbnail = image
87
+ ? (await getCompressedJpegThumbnail(image, opts)).buffer
88
+ : undefined
89
+ } catch (error) {
90
+ ;(_a = opts.logger) === null || _a === void 0
91
+ ? void 0
92
+ : _a.debug(
93
+ { err: error.stack, url: previewLink },
94
+ 'error in generating thumbnail'
95
+ )
96
+ }
97
+ }
98
+ return urlInfo
99
+ }
100
+ } catch (error) {
101
+ if (!error.message.includes('receive a valid')) {
102
+ throw error
103
+ }
104
+ }
105
+ }
106
+ exports.getUrlInfo = getUrlInfo
@@ -0,0 +1,13 @@
1
+ export interface ILogger {
2
+ level: string
3
+ child(obj: Record<string, unknown>): ILogger
4
+ trace(obj: unknown, msg?: string): any
5
+ debug(obj: unknown, msg?: string): any
6
+ info(obj: unknown, msg?: string): any
7
+ warn(obj: unknown, msg?: string): any
8
+ error(obj: unknown, msg?: string): any
9
+ }
10
+
11
+ declare const _default: import("pino").Logger<never, boolean>
12
+
13
+ export default _default
@@ -0,0 +1,9 @@
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 = pino_1.default({ timestamp: () => `,"time":"${new Date().toJSON()}"` })
@@ -0,0 +1,54 @@
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
+ /**
6
+ * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
7
+ * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
8
+ * if the same series of mutations was made sequentially.
9
+ */
10
+ const o = 128
11
+ class d {
12
+ constructor(e) {
13
+ this.salt = e
14
+ }
15
+ add(e, t) {
16
+ var r = this
17
+ for (const item of t) {
18
+ e = r._addSingle(e, item)
19
+ }
20
+ return e
21
+ }
22
+ subtract(e, t) {
23
+ var r = this
24
+ for (const item of t) {
25
+ e = r._subtractSingle(e, item)
26
+ }
27
+ return e
28
+ }
29
+ subtractThenAdd(e, t, r) {
30
+ var n = this
31
+ return n.add(n.subtract(e, r), t)
32
+ }
33
+ _addSingle(e, t) {
34
+ var r = this
35
+ const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer
36
+ return r.performPointwiseWithOverflow(e, n, (e, t) => e + t)
37
+ }
38
+ _subtractSingle(e, t) {
39
+ var r = this
40
+ const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer
41
+ return r.performPointwiseWithOverflow(e, n, (e, t) => e - t)
42
+ }
43
+ performPointwiseWithOverflow(e, t, r) {
44
+ const n = new DataView(e),
45
+ i = new DataView(t),
46
+ a = new ArrayBuffer(n.byteLength),
47
+ s = new DataView(a)
48
+ for (let e = 0; e < n.byteLength; e += 2) {
49
+ s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0)
50
+ }
51
+ return a
52
+ }
53
+ }
54
+ exports.LT_HASH_ANTI_TAMPERING = new d('WhatsApp Patch Integrity')
@@ -0,0 +1,41 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.makeKeyedMutex = exports.makeMutex = void 0
4
+ const makeMutex = () => {
5
+ let task = Promise.resolve()
6
+ let taskTimeout
7
+ return {
8
+ mutex(code) {
9
+ task = (async () => {
10
+ // wait for the previous task to complete
11
+ // if there is an error, we swallow so as to not block the queue
12
+ try {
13
+ await task
14
+ } catch (_a) {}
15
+ try {
16
+ // execute the current task
17
+ const result = await code()
18
+ return result
19
+ } finally {
20
+ clearTimeout(taskTimeout)
21
+ }
22
+ })()
23
+ // we replace the existing task, appending the new piece of execution to it
24
+ // so the next task will have to wait for this one to finish
25
+ return task
26
+ }
27
+ }
28
+ }
29
+ exports.makeMutex = makeMutex
30
+ const makeKeyedMutex = () => {
31
+ const map = {}
32
+ return {
33
+ mutex(key, task) {
34
+ if (!map[key]) {
35
+ map[key] = (0, exports.makeMutex)()
36
+ }
37
+ return map[key].mutex(task)
38
+ }
39
+ }
40
+ }
41
+ exports.makeKeyedMutex = makeKeyedMutex
@@ -0,0 +1,106 @@
1
+ import { proto } from '../../WAProto'
2
+
3
+ export declare const JS_KEYWORDS: Set<string>
4
+ export declare const PYTHON_KEYWORDS: Set<string>
5
+ export declare const LANGUAGE_KEYWORDS: { [key: string]: Set<string> }
6
+
7
+ export declare enum CodeHighlightType {
8
+ DEFAULT = 0,
9
+ KEYWORD = 1,
10
+ STR = 2,
11
+ NUMBER = 3,
12
+ METHOD = 4,
13
+ COMMENT = 5
14
+ }
15
+
16
+ export declare enum RichSubMessageType {
17
+ IMAGE = 3,
18
+ TABLE = 4,
19
+ CODE_BLOCK = 5,
20
+ LATEX = 8
21
+ }
22
+
23
+ export interface CodeBlockToken {
24
+ highlightType: CodeHighlightType
25
+ codeContent: string
26
+ }
27
+
28
+ export interface RichContextInfo {
29
+ stanzaId: string
30
+ participant: string
31
+ quotedMessage: proto.IMessage
32
+ }
33
+
34
+ export interface LatexExpression {
35
+ latexExpression: string
36
+ url?: string
37
+ width?: number
38
+ height?: number
39
+ }
40
+
41
+ export declare const tokenizeCode: (code: string, language?: string) => CodeBlockToken[]
42
+
43
+ export declare const buildRichContextInfo: (quoted?: any, options?: { botJid?: string, mentions?: string[] }) => proto.IContextInfo | undefined
44
+
45
+ export declare const buildBotForwardedMessage: (
46
+ submessages: any[],
47
+ ctxInfo?: proto.IContextInfo,
48
+ unifiedResponse?: { data: Buffer }
49
+ ) => proto.IMessage
50
+
51
+ export declare const generateTableContent: (
52
+ title: string,
53
+ headers: string[],
54
+ rows: string[][],
55
+ quoted?: any,
56
+ options?: { headerText?: string, footer?: string }
57
+ ) => { message: proto.IMessage, messageId: string }
58
+
59
+ export declare const generateListContent: (
60
+ title: string,
61
+ items: string[] | string[][],
62
+ quoted?: any,
63
+ options?: { headerText?: string, footer?: string }
64
+ ) => { message: proto.IMessage, messageId: string }
65
+
66
+ export declare const generateCodeBlockContent: (
67
+ code: string,
68
+ quoted?: any,
69
+ options?: { title?: string, footer?: string, language?: string }
70
+ ) => { message: proto.IMessage, messageId: string }
71
+
72
+ export declare const generateLatexContent: (
73
+ quoted?: any,
74
+ options?: { text?: string, expressions: LatexExpression[], headerText?: string, footer?: string }
75
+ ) => { message: proto.IMessage, messageId: string }
76
+
77
+ export declare const generateLatexImageContent: (
78
+ quoted: any,
79
+ options: { text?: string, expressions: LatexExpression[], headerText?: string, footer?: string },
80
+ uploadFn: (buffer: Buffer, type: string) => Promise<{ url?: string, directPath?: string }>,
81
+ renderLatexToPng: (latexExpr: string) => Promise<{ buffer: Buffer, width: number, height: number }>
82
+ ) => Promise<{ message: proto.IMessage, messageId: string }>
83
+
84
+ export declare const generateLatexInlineImageContent: (
85
+ quoted: any,
86
+ options: { text?: string, expressions: LatexExpression[], headerText?: string, footer?: string },
87
+ uploadFn: (buffer: Buffer, type: string) => Promise<{ url?: string, directPath?: string }>,
88
+ renderLatexToPng: (latexExpr: string) => Promise<{ buffer: Buffer, width: number, height: number }>
89
+ ) => Promise<{ message: proto.IMessage, messageId: string }>
90
+
91
+ export declare const captureUnifiedResponse: (msg: proto.IMessage) => {
92
+ unifiedResponse: { data: Buffer },
93
+ submessages: any[],
94
+ contextInfo: any
95
+ } | null
96
+
97
+ export declare const generateUnifiedResponseContent: (
98
+ quoted: any,
99
+ captured: { submessages: any[], unifiedResponse: { data: Buffer } }
100
+ ) => { message: proto.IMessage, messageId: string }
101
+
102
+ export declare const generateRichMessageContent: (
103
+ submessages: any[],
104
+ quoted?: any,
105
+ options?: { botJid?: string, mentions?: string[] }
106
+ ) => { message: proto.IMessage, messageId: string }