@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,113 @@
1
+ /** Standard disappearing-message durations in seconds */
2
+ export declare const DISAPPEARING_DURATIONS: {
3
+ readonly OFF: 0
4
+ readonly HOURS_24: 86400
5
+ readonly DAYS_7: 604800
6
+ readonly DAYS_90: 7776000
7
+ }
8
+
9
+ export interface TypingOptions {
10
+ /** How long to show the indicator before auto-pausing (ms) */
11
+ duration?: number
12
+ /** Auto-pause after duration (default: true) */
13
+ autoPause?: boolean
14
+ }
15
+
16
+ /**
17
+ * Typing / recording presence indicator helper.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { createTypingIndicator } from '@innovatorssoft/baileys'
22
+ *
23
+ * const typing = createTypingIndicator(
24
+ * (jid, presence) => sock.sendPresenceUpdate(presence, jid)
25
+ * )
26
+ *
27
+ * // Simulate typing, then send
28
+ * await typing.simulateTyping(jid, 1500, () =>
29
+ * sock.sendMessage(jid, { text: 'Here is your answer!' })
30
+ * )
31
+ *
32
+ * // Manual control
33
+ * await typing.startTyping(jid, { duration: 3000 })
34
+ * await typing.stopTyping(jid)
35
+ *
36
+ * // Voice note indicator
37
+ * await typing.startRecording(jid, { duration: 2000 })
38
+ * ```
39
+ */
40
+ export declare class TypingIndicator {
41
+ constructor(sendPresence: (jid: string, presence: 'composing' | 'paused' | 'recording') => Promise<void>)
42
+
43
+ /** Show the "typing..." composing indicator */
44
+ startTyping(jid: string, options?: TypingOptions): Promise<void>
45
+
46
+ /** Show the recording indicator (for voice notes) */
47
+ startRecording(jid: string, options?: TypingOptions): Promise<void>
48
+
49
+ /** Stop typing/recording and send 'paused' */
50
+ stopTyping(jid: string): Promise<void>
51
+
52
+ /** Stop all active indicators */
53
+ stopAll(): Promise<void>
54
+
55
+ /**
56
+ * Show "typing..." for `duration` ms, run `callback`, then return its result.
57
+ * This is the core helper used by AutoReplyHandler's `simulateTyping` option.
58
+ */
59
+ simulateTyping<T>(jid: string, duration: number, callback: () => Promise<T>): Promise<T>
60
+ }
61
+
62
+ export interface PinnedMessage {
63
+ messageId: string
64
+ jid: string
65
+ pinnedAt: Date
66
+ pinnedBy?: string
67
+ expiresAt?: Date
68
+ }
69
+
70
+ /** Client-side pinned-message tracker */
71
+ export declare class PinnedMessagesManager {
72
+ pin(jid: string, messageId: string, pinnedBy?: string, expiresAt?: Date): PinnedMessage
73
+ unpin(jid: string, messageId: string): boolean
74
+ getPinned(jid: string): PinnedMessage[]
75
+ isPinned(jid: string, messageId: string): boolean
76
+ clearPins(jid: string): void
77
+ clearExpired(): number
78
+ }
79
+
80
+ /** Create a TypingIndicator wired to your socket's sendPresenceUpdate */
81
+ export declare const createTypingIndicator: (
82
+ sendPresence: (jid: string, presence: 'composing' | 'paused' | 'recording') => Promise<void>
83
+ ) => TypingIndicator
84
+
85
+ /** Create a PinnedMessagesManager */
86
+ export declare const createPinnedMessagesManager: () => PinnedMessagesManager
87
+
88
+ export interface ReadReceiptConfig {
89
+ /** Enable read receipts (blue ticks) */
90
+ enabled: boolean
91
+ /** Auto-read messages (if you write an auto-read loop) */
92
+ autoRead?: boolean
93
+ /** Delay before marking as read (ms) */
94
+ readDelay?: number
95
+ /** JIDs that should stay unread */
96
+ excludeJids?: string[]
97
+ }
98
+
99
+ /**
100
+ * Creates a ReadReceiptController that wraps sock.readMessages and holds state/configuration.
101
+ */
102
+ export declare const createReadReceiptController: (
103
+ sendReadReceipt: (jid: string, participant: string | undefined, messageIds: string[]) => Promise<void>,
104
+ config?: ReadReceiptConfig
105
+ ) => {
106
+ setConfig(newConfig: Partial<ReadReceiptConfig>): void
107
+ getConfig(): ReadReceiptConfig
108
+ enable(): void
109
+ disable(): void
110
+ isEnabled(): boolean
111
+ markRead(jid: string, participant: string | undefined, messageIds: string[]): Promise<void>
112
+ forceMarkRead(jid: string, participant: string | undefined, messageIds: string[]): Promise<void>
113
+ }
@@ -0,0 +1,230 @@
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true })
4
+ exports.createReadReceiptController =
5
+ exports.createPinnedMessagesManager =
6
+ exports.createTypingIndicator =
7
+ exports.DISAPPEARING_DURATIONS =
8
+ exports.PinnedMessagesManager =
9
+ exports.TypingIndicator =
10
+ void 0
11
+
12
+ /**
13
+ * Chat Control Utilities
14
+ * Ported from Baileys-Joss: TypingIndicator, ReadReceiptController, PinnedMessagesManager.
15
+ */
16
+
17
+ /**
18
+ * Standard disappearing-message duration constants (in seconds).
19
+ */
20
+ const DISAPPEARING_DURATIONS = {
21
+ OFF: 0,
22
+ HOURS_24: 86400,
23
+ DAYS_7: 604800,
24
+ DAYS_90: 7776000
25
+ }
26
+ exports.DISAPPEARING_DURATIONS = DISAPPEARING_DURATIONS
27
+
28
+ /**
29
+ * Typing / recording presence indicator helper.
30
+ *
31
+ * Wire in sock.sendPresenceUpdate to show/hide the "typing..." bubble.
32
+ *
33
+ * @example
34
+ * const typing = createTypingIndicator(
35
+ * (jid, presence) => sock.sendPresenceUpdate(presence, jid)
36
+ * )
37
+ *
38
+ * // Simple — show typing for 2 s then send
39
+ * await typing.simulateTyping(jid, 2000, () => sock.sendMessage(jid, { text: 'Hello!' }))
40
+ *
41
+ * // Manual control
42
+ * await typing.startTyping(jid, { duration: 3000 }) // auto-pauses after 3 s
43
+ * await typing.stopTyping(jid)
44
+ *
45
+ * // Voice note indicator
46
+ * await typing.startRecording(jid, { duration: 2000 })
47
+ */
48
+ class TypingIndicator {
49
+ constructor(sendPresence) {
50
+ this.intervals = new Map()
51
+ this.sendPresence = sendPresence
52
+ }
53
+
54
+ /**
55
+ * Start the composing (typing) indicator.
56
+ * @param {string} jid
57
+ * @param {{ duration?: number, autoPause?: boolean }} [options]
58
+ */
59
+ async startTyping(jid, options = {}) {
60
+ this.stopTyping(jid) // clear any existing timer for this JID
61
+ await this.sendPresence(jid, 'composing')
62
+
63
+ if (options.autoPause !== false && options.duration) {
64
+ const timeout = setTimeout(() => this.stopTyping(jid), options.duration)
65
+ this.intervals.set(jid, timeout)
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Start the recording (voice note) indicator.
71
+ * @param {string} jid
72
+ * @param {{ duration?: number, autoPause?: boolean }} [options]
73
+ */
74
+ async startRecording(jid, options = {}) {
75
+ this.stopTyping(jid)
76
+ await this.sendPresence(jid, 'recording')
77
+
78
+ if (options.autoPause !== false && options.duration) {
79
+ const timeout = setTimeout(() => this.stopTyping(jid), options.duration)
80
+ this.intervals.set(jid, timeout)
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Stop the typing / recording indicator for a JID.
86
+ * @param {string} jid
87
+ */
88
+ async stopTyping(jid) {
89
+ const existing = this.intervals.get(jid)
90
+ if (existing) {
91
+ clearTimeout(existing)
92
+ this.intervals.delete(jid)
93
+ }
94
+ try {
95
+ await this.sendPresence(jid, 'paused')
96
+ } catch {}
97
+ }
98
+
99
+ /** Stop all active typing indicators. */
100
+ async stopAll() {
101
+ for (const [jid] of this.intervals) {
102
+ await this.stopTyping(jid)
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Show "typing..." for `duration` ms, run `callback`, then return its result.
108
+ *
109
+ * @template T
110
+ * @param {string} jid
111
+ * @param {number} duration - How long to show the indicator (ms)
112
+ * @param {() => Promise<T>} callback - Action to run after the delay
113
+ * @returns {Promise<T>}
114
+ *
115
+ * @example
116
+ * const sent = await typing.simulateTyping(jid, 1500, () =>
117
+ * sock.sendMessage(jid, { text: 'Here is your answer!' })
118
+ * )
119
+ */
120
+ async simulateTyping(jid, duration, callback) {
121
+ await this.startTyping(jid)
122
+ await new Promise((r) => setTimeout(r, duration))
123
+ await this.stopTyping(jid)
124
+ return callback()
125
+ }
126
+ }
127
+
128
+ exports.TypingIndicator = TypingIndicator
129
+
130
+ /**
131
+ * Client-side pinned messages tracker.
132
+ * (WhatsApp protocol sends pin events via `messages.update`; this class stores them locally.)
133
+ */
134
+ class PinnedMessagesManager {
135
+ constructor() {
136
+ this.pinnedMessages = new Map()
137
+ }
138
+
139
+ pin(jid, messageId, pinnedBy, expiresAt) {
140
+ const pinned = { messageId, jid, pinnedAt: new Date(), pinnedBy, expiresAt }
141
+ const existing = this.pinnedMessages.get(jid) || []
142
+ const filtered = existing.filter((p) => p.messageId !== messageId)
143
+ filtered.push(pinned)
144
+ this.pinnedMessages.set(jid, filtered)
145
+ return pinned
146
+ }
147
+
148
+ unpin(jid, messageId) {
149
+ const existing = this.pinnedMessages.get(jid)
150
+ if (!existing) return false
151
+ const filtered = existing.filter((p) => p.messageId !== messageId)
152
+ if (filtered.length === existing.length) return false
153
+ this.pinnedMessages.set(jid, filtered)
154
+ return true
155
+ }
156
+
157
+ getPinned(jid) {
158
+ return this.pinnedMessages.get(jid) || []
159
+ }
160
+
161
+ isPinned(jid, messageId) {
162
+ return (this.pinnedMessages.get(jid) || []).some((p) => p.messageId === messageId)
163
+ }
164
+
165
+ clearPins(jid) {
166
+ this.pinnedMessages.delete(jid)
167
+ }
168
+
169
+ clearExpired() {
170
+ let cleared = 0
171
+ const now = Date.now()
172
+ for (const [jid, pins] of this.pinnedMessages) {
173
+ const valid = pins.filter((p) => !p.expiresAt || p.expiresAt.getTime() > now)
174
+ if (valid.length < pins.length) {
175
+ cleared += pins.length - valid.length
176
+ this.pinnedMessages.set(jid, valid)
177
+ }
178
+ }
179
+ return cleared
180
+ }
181
+ }
182
+
183
+ exports.PinnedMessagesManager = PinnedMessagesManager
184
+
185
+ /** Factory — create a TypingIndicator */
186
+ const createTypingIndicator = (sendPresence) => new TypingIndicator(sendPresence)
187
+ exports.createTypingIndicator = createTypingIndicator
188
+
189
+ /** Factory — create a PinnedMessagesManager */
190
+ const createPinnedMessagesManager = () => new PinnedMessagesManager()
191
+ exports.createPinnedMessagesManager = createPinnedMessagesManager
192
+
193
+ /**
194
+ * Create read receipt controller
195
+ */
196
+ const createReadReceiptController = (sendReadReceipt, config = { enabled: true }) => {
197
+ let currentConfig = { ...config }
198
+
199
+ return {
200
+ setConfig(newConfig) {
201
+ currentConfig = { ...currentConfig, ...newConfig }
202
+ },
203
+ getConfig() {
204
+ return { ...currentConfig }
205
+ },
206
+ enable() {
207
+ currentConfig.enabled = true
208
+ },
209
+ disable() {
210
+ currentConfig.enabled = false
211
+ },
212
+ isEnabled() {
213
+ return currentConfig.enabled
214
+ },
215
+ async markRead(jid, participant, messageIds) {
216
+ if (!currentConfig.enabled) return
217
+ if (currentConfig.excludeJids?.includes(jid)) return
218
+
219
+ if (currentConfig.readDelay) {
220
+ await new Promise((r) => setTimeout(r, currentConfig.readDelay))
221
+ }
222
+
223
+ await sendReadReceipt(jid, participant, messageIds)
224
+ },
225
+ async forceMarkRead(jid, participant, messageIds) {
226
+ await sendReadReceipt(jid, participant, messageIds)
227
+ }
228
+ }
229
+ }
230
+ exports.createReadReceiptController = createReadReceiptController