@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,71 @@
1
+ export interface VCardContact {
2
+ /** Full name */
3
+ fullName: string
4
+ /** Display name (optional) */
5
+ displayName?: string
6
+ /** Organization/Company */
7
+ organization?: string
8
+ /** Title/Position */
9
+ title?: string
10
+ /** Phone numbers */
11
+ phones?: Array<{
12
+ number: string
13
+ type?: 'CELL' | 'WORK' | 'HOME' | 'MAIN' | 'FAX' | 'PAGER'
14
+ label?: string
15
+ }>
16
+ /** Email addresses */
17
+ emails?: Array<{
18
+ email: string
19
+ type?: 'WORK' | 'HOME' | 'OTHER'
20
+ }>
21
+ /** Website URLs */
22
+ urls?: Array<{
23
+ url: string
24
+ type?: 'WORK' | 'HOME' | 'OTHER'
25
+ }>
26
+ /** Physical addresses */
27
+ addresses?: Array<{
28
+ street?: string
29
+ city?: string
30
+ state?: string
31
+ postalCode?: string
32
+ country?: string
33
+ type?: 'WORK' | 'HOME' | 'OTHER'
34
+ }>
35
+ /** Birthday (YYYY-MM-DD format) */
36
+ birthday?: string
37
+ /** Notes */
38
+ note?: string
39
+ }
40
+
41
+ /** Generate vCard string from contact data */
42
+ export declare const generateVCard: (contact: VCardContact) => string
43
+
44
+ /** Generate multiple vCards (for contact array) */
45
+ export declare const generateVCards: (contacts: VCardContact[]) => string
46
+
47
+ /** Parse vCard string to contact data (basic parser) */
48
+ export declare const parseVCard: (vcard: string) => Partial<VCardContact>
49
+
50
+ /** Create a simple contact card message content */
51
+ export declare const createContactCard: (contact: VCardContact) => {
52
+ contacts: {
53
+ displayName: string
54
+ contacts: Array<{ vcard: string }>
55
+ }
56
+ }
57
+
58
+ /** Create an array of contact cards message content */
59
+ export declare const createContactCards: (contacts: VCardContact[]) => {
60
+ contacts: {
61
+ displayName: string
62
+ contacts: Array<{ vcard: string }>
63
+ }
64
+ }
65
+
66
+ /** Quick helper to create contact from phone number */
67
+ export declare const quickContact: (
68
+ name: string,
69
+ phone: string,
70
+ options?: { organization?: string; email?: string }
71
+ ) => VCardContact
@@ -0,0 +1,196 @@
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true })
4
+ exports.quickContact =
5
+ exports.createContactCards =
6
+ exports.createContactCard =
7
+ exports.parseVCard =
8
+ exports.generateVCards =
9
+ exports.generateVCard =
10
+ void 0
11
+
12
+ /**
13
+ * Baileys-Joss: vCard / Contact Card Generator
14
+ * Ported to provide simple, robust vCard generation.
15
+ */
16
+
17
+ const escapeVCard = (str) => {
18
+ return str
19
+ .replace(/\\/g, '\\\\')
20
+ .replace(/;/g, '\\;')
21
+ .replace(/,/g, '\\,')
22
+ .replace(/\n/g, '\\n')
23
+ }
24
+
25
+ const formatPhone = (phone) => {
26
+ return phone.replace(/[^\d+]/g, '')
27
+ }
28
+
29
+ /** Generate vCard string from contact data */
30
+ const generateVCard = (contact) => {
31
+ const lines = []
32
+
33
+ // vCard header
34
+ lines.push('BEGIN:VCARD')
35
+ lines.push('VERSION:3.0')
36
+
37
+ // Full name
38
+ const escapedName = escapeVCard(contact.fullName)
39
+ lines.push(`FN:${escapedName}`)
40
+
41
+ // Structured name
42
+ const nameParts = contact.fullName.split(' ')
43
+ if (nameParts.length >= 2) {
44
+ const lastName = nameParts[nameParts.length - 1] || ''
45
+ const firstName = nameParts.slice(0, -1).join(' ')
46
+ lines.push(`N:${escapeVCard(lastName)};${escapeVCard(firstName)};;;`)
47
+ } else {
48
+ lines.push(`N:${escapedName};;;;`)
49
+ }
50
+
51
+ if (contact.organization) {
52
+ lines.push(`ORG:${escapeVCard(contact.organization)}`)
53
+ }
54
+
55
+ if (contact.title) {
56
+ lines.push(`TITLE:${escapeVCard(contact.title)}`)
57
+ }
58
+
59
+ if (contact.phones && contact.phones.length > 0) {
60
+ for (const phone of contact.phones) {
61
+ const type = phone.type || 'CELL'
62
+ const formattedPhone = formatPhone(phone.number)
63
+ if (phone.label) {
64
+ lines.push(
65
+ `TEL;type=${type};type=VOICE;X-ABLabel=${escapeVCard(phone.label)}:${formattedPhone}`
66
+ )
67
+ } else {
68
+ lines.push(`TEL;type=${type};type=VOICE:${formattedPhone}`)
69
+ }
70
+ }
71
+ }
72
+
73
+ if (contact.emails && contact.emails.length > 0) {
74
+ for (const email of contact.emails) {
75
+ const type = email.type || 'OTHER'
76
+ lines.push(`EMAIL;type=${type}:${email.email}`)
77
+ }
78
+ }
79
+
80
+ if (contact.urls && contact.urls.length > 0) {
81
+ for (const url of contact.urls) {
82
+ const type = url.type || 'OTHER'
83
+ lines.push(`URL;type=${type}:${url.url}`)
84
+ }
85
+ }
86
+
87
+ if (contact.addresses && contact.addresses.length > 0) {
88
+ for (const addr of contact.addresses) {
89
+ const type = addr.type || 'OTHER'
90
+ const parts = [
91
+ '', // PO Box
92
+ '', // Extended address
93
+ addr.street || '',
94
+ addr.city || '',
95
+ addr.state || '',
96
+ addr.postalCode || '',
97
+ addr.country || ''
98
+ ].map((p) => escapeVCard(p))
99
+ lines.push(`ADR;type=${type}:${parts.join(';')}`)
100
+ }
101
+ }
102
+
103
+ if (contact.birthday) {
104
+ lines.push(`BDAY:${contact.birthday}`)
105
+ }
106
+
107
+ if (contact.note) {
108
+ lines.push(`NOTE:${escapeVCard(contact.note)}`)
109
+ }
110
+
111
+ lines.push('END:VCARD')
112
+ return lines.join('\r\n')
113
+ }
114
+ exports.generateVCard = generateVCard
115
+
116
+ /** Generate multiple vCards (for contact array) */
117
+ const generateVCards = (contacts) => {
118
+ return contacts.map(exports.generateVCard).join('\r\n')
119
+ }
120
+ exports.generateVCards = generateVCards
121
+
122
+ /** Parse vCard string to contact data (basic parser) */
123
+ const parseVCard = (vcard) => {
124
+ const contact = {}
125
+ const lines = vcard.split(/\r?\n/)
126
+
127
+ for (const line of lines) {
128
+ const [key, ...valueParts] = line.split(':')
129
+ if (!key) continue
130
+ const value = valueParts.join(':')
131
+
132
+ if (key.startsWith('FN')) {
133
+ contact.fullName = value.replace(/\\([;,n\\])/g, '$1').replace(/\\n/g, '\n')
134
+ } else if (key.startsWith('ORG')) {
135
+ contact.organization = value.replace(/\\([;,n\\])/g, '$1')
136
+ } else if (key.startsWith('TITLE')) {
137
+ contact.title = value.replace(/\\([;,n\\])/g, '$1')
138
+ } else if (key.startsWith('TEL')) {
139
+ contact.phones = contact.phones || []
140
+ const typeMatch = key.match(/type=(\w+)/i)
141
+ const phoneType = typeMatch?.[1]?.toUpperCase() || 'CELL'
142
+ contact.phones.push({ number: value, type: phoneType })
143
+ } else if (key.startsWith('EMAIL')) {
144
+ contact.emails = contact.emails || []
145
+ const typeMatch = key.match(/type=(\w+)/i)
146
+ contact.emails.push({
147
+ email: value,
148
+ type: typeMatch?.[1]?.toUpperCase() || 'OTHER'
149
+ })
150
+ } else if (key.startsWith('BDAY')) {
151
+ contact.birthday = value
152
+ } else if (key.startsWith('NOTE')) {
153
+ contact.note = value.replace(/\\n/g, '\n')
154
+ }
155
+ }
156
+
157
+ return contact
158
+ }
159
+ exports.parseVCard = parseVCard
160
+
161
+ /** Create a simple contact card message content */
162
+ const createContactCard = (contact) => {
163
+ return {
164
+ contacts: {
165
+ displayName: contact.displayName || contact.fullName,
166
+ contacts: [{ vcard: (0, exports.generateVCard)(contact) }]
167
+ }
168
+ }
169
+ }
170
+ exports.createContactCard = createContactCard
171
+
172
+ /** Create an array of contact cards message content */
173
+ const createContactCards = (contacts) => {
174
+ const firstContact = contacts[0]
175
+ return {
176
+ contacts: {
177
+ displayName:
178
+ contacts.length === 1 && firstContact
179
+ ? firstContact.displayName || firstContact.fullName
180
+ : `${contacts.length} Contacts`,
181
+ contacts: contacts.map((c) => ({ vcard: (0, exports.generateVCard)(c) }))
182
+ }
183
+ }
184
+ }
185
+ exports.createContactCards = createContactCards
186
+
187
+ /** Quick helper to create contact from phone number */
188
+ const quickContact = (name, phone, options) => {
189
+ return {
190
+ fullName: name,
191
+ phones: [{ number: phone, type: 'CELL' }],
192
+ organization: options?.organization,
193
+ emails: options?.email ? [{ email: options.email, type: 'WORK' }] : undefined
194
+ }
195
+ }
196
+ exports.quickContact = quickContact
@@ -0,0 +1,253 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.encodeSignedDeviceIdentity =
4
+ exports.configureSuccessfulPairing =
5
+ exports.generateRegistrationNode =
6
+ exports.generateLoginNode =
7
+ void 0
8
+ const boom_1 = require('@hapi/boom')
9
+ const crypto_1 = require('crypto')
10
+ const WAProto_1 = require('../../WAProto')
11
+ const Defaults_1 = require('../Defaults')
12
+ const WABinary_1 = require('../WABinary')
13
+ const crypto_2 = require('./crypto')
14
+ const generics_1 = require('./generics')
15
+ const signal_1 = require('./signal')
16
+
17
+ const getUserAgent = (config) => {
18
+ return {
19
+ appVersion: {
20
+ primary: config.version[0],
21
+ secondary: config.version[1],
22
+ tertiary: config.version[2]
23
+ },
24
+ // WA started rejecting Platform.WEB on fresh pairing (405 frc/rva) in
25
+ // Feb 2026 — MACOS still gets through registration.
26
+ platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.MACOS,
27
+ releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
28
+ osVersion: '0.1',
29
+ device: 'Desktop',
30
+ osBuildNumber: '0.1',
31
+ localeLanguageIso6391: 'en',
32
+ mnc: '000',
33
+ mcc: '000',
34
+ localeCountryIso31661Alpha2: config.countryCode || 'US'
35
+ }
36
+ }
37
+
38
+ const PLATFORM_MAP = {
39
+ 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
40
+ Windows: WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
41
+ }
42
+
43
+ const getWebInfo = (config) => {
44
+ let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
45
+ if (
46
+ config.syncFullHistory &&
47
+ PLATFORM_MAP[config.browser[0]] &&
48
+ config.browser[1] === 'Desktop'
49
+ ) {
50
+ webSubPlatform = PLATFORM_MAP[config.browser[0]]
51
+ }
52
+ return { webSubPlatform }
53
+ }
54
+
55
+ const getClientPayload = (config) => {
56
+ const payload = {
57
+ connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
58
+ connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
59
+ userAgent: getUserAgent(config)
60
+ }
61
+ payload.webInfo = getWebInfo(config)
62
+ return payload
63
+ }
64
+
65
+ const generateLoginNode = (userJid, config) => {
66
+ const { user, device } = (0, WABinary_1.jidDecode)(userJid)
67
+ const payload = {
68
+ ...getClientPayload(config),
69
+ passive: true,
70
+ pull: true,
71
+ username: +user,
72
+ device: device,
73
+ lidDbMigrated: false
74
+ }
75
+ return WAProto_1.proto.ClientPayload.fromObject(payload)
76
+ }
77
+ exports.generateLoginNode = generateLoginNode
78
+
79
+ const getPlatformType = (platform) => {
80
+ const platformType = platform.toUpperCase()
81
+ return (
82
+ WAProto_1.proto.DeviceProps.PlatformType[platformType] ||
83
+ WAProto_1.proto.DeviceProps.PlatformType.CHROME
84
+ )
85
+ }
86
+
87
+ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
88
+ const appVersionBuf = (0, crypto_1.createHash)('md5').update(config.version.join('.')).digest()
89
+
90
+ const companion = {
91
+ os: config.browser[0],
92
+ platformType: getPlatformType(config.browser[1]),
93
+ requireFullSync: config.syncFullHistory,
94
+ historySyncConfig: {
95
+ storageQuotaMb: 10240,
96
+ inlineInitialPayloadInE2EeMsg: true,
97
+ recentSyncDaysLimit: undefined,
98
+ supportCallLogHistory: false,
99
+ supportBotUserAgentChatHistory: true,
100
+ supportCagReactionsAndPolls: true,
101
+ supportBizHostedMsg: true,
102
+ supportRecentSyncChunkMessageCountTuning: true,
103
+ supportHostedGroupMsg: true,
104
+ supportFbidBotChatHistory: true,
105
+ supportAddOnHistorySyncMigration: undefined,
106
+ supportMessageAssociation: true,
107
+ supportGroupHistory: false,
108
+ onDemandReady: undefined,
109
+ supportGuestChat: undefined
110
+ },
111
+ version: {
112
+ primary: 10,
113
+ secondary: 15,
114
+ tertiary: 7
115
+ }
116
+ }
117
+
118
+ const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish()
119
+
120
+ const registerPayload = {
121
+ ...getClientPayload(config),
122
+ passive: false,
123
+ pull: false,
124
+ devicePairingData: {
125
+ buildHash: appVersionBuf,
126
+ deviceProps: companionProto,
127
+ eRegid: (0, generics_1.encodeBigEndian)(registrationId),
128
+ eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
129
+ eIdent: signedIdentityKey.public,
130
+ eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
131
+ eSkeyVal: signedPreKey.keyPair.public,
132
+ eSkeySig: signedPreKey.signature
133
+ }
134
+ }
135
+ return WAProto_1.proto.ClientPayload.fromObject(registerPayload)
136
+ }
137
+ exports.generateRegistrationNode = generateRegistrationNode
138
+
139
+ const configureSuccessfulPairing = (
140
+ stanza,
141
+ { advSecretKey, signedIdentityKey, signalIdentities }
142
+ ) => {
143
+ const msgId = stanza.attrs.id
144
+ const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success')
145
+ const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(
146
+ pairSuccessNode,
147
+ 'device-identity'
148
+ )
149
+ const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform')
150
+ const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device')
151
+ const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz')
152
+
153
+ if (!deviceIdentityNode || !deviceNode) {
154
+ throw new boom_1.Boom('Missing device-identity or device in pair success node', {
155
+ data: stanza
156
+ })
157
+ }
158
+
159
+ const bizName = businessNode?.attrs.name
160
+ const jid = deviceNode.attrs.jid
161
+ const lid = deviceNode.attrs.lid
162
+
163
+ const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(
164
+ deviceIdentityNode.content
165
+ )
166
+
167
+ let hmacPrefix = Buffer.from([])
168
+ if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
169
+ hmacPrefix = Buffer.from([0x06, 0x05])
170
+ }
171
+
172
+ const advSign = (0, crypto_2.hmacSign)(
173
+ Buffer.concat([hmacPrefix, details]),
174
+ Buffer.from(advSecretKey, 'base64')
175
+ )
176
+ if (Buffer.compare(hmac, advSign) !== 0) {
177
+ throw new boom_1.Boom('Invalid account signature')
178
+ }
179
+
180
+ const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details)
181
+ const { accountSignatureKey, accountSignature, details: deviceDetails } = account
182
+
183
+ const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails)
184
+
185
+ const accountSignaturePrefix =
186
+ deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
187
+ ? Buffer.from([0x06, 0x05])
188
+ : Buffer.from([0x06, 0x00])
189
+ const accountMsg = Buffer.concat([
190
+ accountSignaturePrefix,
191
+ deviceDetails,
192
+ signedIdentityKey.public
193
+ ])
194
+
195
+ if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
196
+ throw new boom_1.Boom('Failed to verify account signature')
197
+ }
198
+
199
+ const deviceMsg = Buffer.concat([
200
+ Buffer.from([0x06, 0x01]),
201
+ deviceDetails,
202
+ signedIdentityKey.public,
203
+ accountSignatureKey
204
+ ])
205
+ account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg)
206
+
207
+ const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey)
208
+ const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false)
209
+
210
+ const reply = {
211
+ tag: 'iq',
212
+ attrs: {
213
+ to: WABinary_1.S_WHATSAPP_NET,
214
+ type: 'result',
215
+ id: msgId
216
+ },
217
+ content: [
218
+ {
219
+ tag: 'pair-device-sign',
220
+ attrs: {},
221
+ content: [
222
+ {
223
+ tag: 'device-identity',
224
+ attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
225
+ content: accountEnc
226
+ }
227
+ ]
228
+ }
229
+ ]
230
+ }
231
+
232
+ const authUpdate = {
233
+ account,
234
+ me: { id: jid, name: bizName, lid },
235
+ signalIdentities: [...(signalIdentities || []), identity],
236
+ platform: platformNode?.attrs.name
237
+ }
238
+
239
+ return {
240
+ creds: authUpdate,
241
+ reply
242
+ }
243
+ }
244
+ exports.configureSuccessfulPairing = configureSuccessfulPairing
245
+
246
+ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
247
+ account = { ...account }
248
+ if (!includeSignatureKey || !account.accountSignatureKey?.length) {
249
+ account.accountSignatureKey = null
250
+ }
251
+ return WAProto_1.proto.ADVSignedDeviceIdentity.encode(account).finish()
252
+ }
253
+ exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity
@@ -0,0 +1,154 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.WarmUp = void 0
4
+
5
+ /**
6
+ * @file warmup.js
7
+ * @description Gradual activity increase for new/reconnected WA numbers.
8
+ * Prevents ban by enforcing a 7-day ramp-up of messaging activity.
9
+ * Ported from baileys-antiban to CJS for bilis.
10
+ * @author Denzy ZeroDay (port), original by baileys-antiban contributors
11
+ */
12
+
13
+ const MS_PER_DAY = 86400000
14
+
15
+ /** Random growth factor in [1.5, 2.2] — avoids cross-account fingerprinting */
16
+ const randomGrowthFactor = () => Math.round((1.5 + Math.random() * 0.7) * 100) / 100
17
+
18
+ const DEFAULT_CONFIG = {
19
+ warmUpDays: 7,
20
+ day1Limit: 20,
21
+ growthFactor: null, // null = randomized per instance
22
+ inactivityThresholdHours: 72
23
+ }
24
+
25
+ class WarmUp {
26
+ /**
27
+ * @param {object} config - Optional config overrides
28
+ * @param {object} existingState - Optional restored state from persistence
29
+ */
30
+ constructor(config = {}, existingState = null) {
31
+ this.config = { ...DEFAULT_CONFIG, ...config }
32
+ if (!this.config.growthFactor) {
33
+ this.config.growthFactor = randomGrowthFactor()
34
+ }
35
+ this.state = existingState || this._freshState()
36
+ }
37
+
38
+ /**
39
+ * Get current daily message limit based on warm-up phase.
40
+ * Returns Infinity if graduated.
41
+ */
42
+ getDailyLimit() {
43
+ if (this.state.graduated) return Infinity
44
+ const day = this._getCurrentDay()
45
+ if (day >= this.config.warmUpDays) {
46
+ this.state.graduated = true
47
+ return Infinity
48
+ }
49
+ return Math.round(this.config.day1Limit * Math.pow(this.config.growthFactor, day))
50
+ }
51
+
52
+ /**
53
+ * Check if a message can be sent within warm-up limits.
54
+ */
55
+ canSend() {
56
+ this._checkInactivity()
57
+ if (this.state.graduated) return true
58
+ const day = this._getCurrentDay()
59
+ const todayCount = this.state.dailyCounts[day] || 0
60
+ return todayCount < this.getDailyLimit()
61
+ }
62
+
63
+ /**
64
+ * Record a sent message.
65
+ */
66
+ record() {
67
+ const now = Date.now()
68
+ const day = this._getCurrentDay()
69
+ while (this.state.dailyCounts.length <= day) {
70
+ this.state.dailyCounts.push(0)
71
+ }
72
+ this.state.dailyCounts[day]++
73
+ this.state.lastActiveAt = now
74
+ }
75
+
76
+ /**
77
+ * Get current warm-up status.
78
+ */
79
+ getStatus() {
80
+ const day = this._getCurrentDay()
81
+ const todaySent = this.state.dailyCounts[day] || 0
82
+ const limit = this.getDailyLimit()
83
+ return {
84
+ phase: this.state.graduated ? 'graduated' : 'warming',
85
+ day: Math.min(day + 1, this.config.warmUpDays),
86
+ totalDays: this.config.warmUpDays,
87
+ todayLimit: limit === Infinity ? -1 : limit,
88
+ todaySent,
89
+ progress: this.state.graduated ? 100 : Math.round((day / this.config.warmUpDays) * 100)
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Export state for persistence (save to DB/file).
95
+ */
96
+ exportState() {
97
+ const day = this._getCurrentDay()
98
+ const todaySent = this.state.dailyCounts[day] || 0
99
+ const todayDate = new Date().toISOString().split('T')[0]
100
+ return { ...this.state, todaySentCount: todaySent, todayDate }
101
+ }
102
+
103
+ /**
104
+ * Import state from persistence (restore from DB/file).
105
+ */
106
+ importState(state) {
107
+ this.state = { ...state }
108
+ if (state.todayDate && state.todaySentCount !== undefined) {
109
+ const todayDate = new Date().toISOString().split('T')[0]
110
+ if (state.todayDate === todayDate) {
111
+ const day = this._getCurrentDay()
112
+ while (this.state.dailyCounts.length <= day) {
113
+ this.state.dailyCounts.push(0)
114
+ }
115
+ this.state.dailyCounts[day] = Math.max(
116
+ this.state.dailyCounts[day] || 0,
117
+ state.todaySentCount
118
+ )
119
+ }
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Reset warm-up (e.g. after detected ban risk).
125
+ */
126
+ reset() {
127
+ this.state = this._freshState()
128
+ }
129
+
130
+ _getCurrentDay() {
131
+ return Math.floor((Date.now() - this.state.startedAt) / MS_PER_DAY)
132
+ }
133
+
134
+ _checkInactivity() {
135
+ const hoursSinceActive = (Date.now() - this.state.lastActiveAt) / 3600000
136
+ if (hoursSinceActive > this.config.inactivityThresholdHours && this.state.graduated) {
137
+ this.state = this._freshState()
138
+ this.state.graduated = false
139
+ }
140
+ }
141
+
142
+ _freshState() {
143
+ const now = Date.now()
144
+ return {
145
+ startedAt: now,
146
+ lastActiveAt: now,
147
+ dailyCounts: [],
148
+ graduated: false
149
+ }
150
+ }
151
+ }
152
+
153
+ exports.WarmUp = WarmUp
154
+ module.exports = { WarmUp }