@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.
- package/WAProto/index.js +138933 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +7 -0
- package/lib/Defaults/index.js +157 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +94 -0
- package/lib/Signal/Group/group_cipher.js +118 -0
- package/lib/Signal/Group/index.js +138 -0
- package/lib/Signal/Group/keyhelper.js +75 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +39 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
- package/lib/Signal/Group/sender-key-message.js +76 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +65 -0
- package/lib/Signal/Group/sender-key-state.js +114 -0
- package/lib/Signal/Group/sender-message-key.js +33 -0
- package/lib/Signal/libsignal.js +204 -0
- package/lib/Signal/lid-mapping.js +267 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +32 -0
- package/lib/Socket/Client/mobile-socket-client.js +82 -0
- package/lib/Socket/Client/web-socket-client.js +89 -0
- package/lib/Socket/Denzy-ZeroDay.js +805 -0
- package/lib/Socket/business.js +279 -0
- package/lib/Socket/chats.js +1169 -0
- package/lib/Socket/community.d.ts +120 -0
- package/lib/Socket/community.js +388 -0
- package/lib/Socket/graphql.js +1122 -0
- package/lib/Socket/groups.js +345 -0
- package/lib/Socket/index.js +22 -0
- package/lib/Socket/interop.js +265 -0
- package/lib/Socket/lid-mapping.js +111 -0
- package/lib/Socket/messages-recv.js +1385 -0
- package/lib/Socket/messages-send.js +956 -0
- package/lib/Socket/mex.js +69 -0
- package/lib/Socket/newsletter.js +424 -0
- package/lib/Socket/privacy.js +229 -0
- package/lib/Socket/registration.js +190 -0
- package/lib/Socket/socket.js +783 -0
- package/lib/Socket/username.d.ts +185 -0
- package/lib/Socket/username.js +168 -0
- package/lib/Socket/usync.js +80 -0
- package/lib/Store/index.js +14 -0
- package/lib/Store/keyed-db.js +158 -0
- package/lib/Store/make-cache-manager-store.js +88 -0
- package/lib/Store/make-in-memory-store.js +484 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +14 -0
- package/lib/Types/MexUpdates.js +19 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/RichType.js +30 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +58 -0
- package/lib/Utils/anti-ban.js +339 -0
- package/lib/Utils/anti-delete.d.ts +158 -0
- package/lib/Utils/anti-delete.js +293 -0
- package/lib/Utils/antiban-presets.js +91 -0
- package/lib/Utils/antiban-profiles.js +43 -0
- package/lib/Utils/auth-utils.js +210 -0
- package/lib/Utils/baileys-event-stream.js +66 -0
- package/lib/Utils/browser-utils.js +52 -0
- package/lib/Utils/business.js +261 -0
- package/lib/Utils/chat-control.d.ts +113 -0
- package/lib/Utils/chat-control.js +230 -0
- package/lib/Utils/chat-utils.js +922 -0
- package/lib/Utils/companion-reg-client-utils.js +37 -0
- package/lib/Utils/contact-graph-warmer.js +208 -0
- package/lib/Utils/crypto.js +196 -0
- package/lib/Utils/decode-wa-message.js +208 -0
- package/lib/Utils/delivery-tracker.js +110 -0
- package/lib/Utils/device-fingerprint.js +135 -0
- package/lib/Utils/event-buffer.js +531 -0
- package/lib/Utils/generics.js +571 -0
- package/lib/Utils/group-operation-guard.js +147 -0
- package/lib/Utils/health-monitor.js +207 -0
- package/lib/Utils/history.js +122 -0
- package/lib/Utils/human-entropy.js +226 -0
- package/lib/Utils/identity-change-handler.js +72 -0
- package/lib/Utils/index.js +83 -0
- package/lib/Utils/interactive-message.d.ts +139 -0
- package/lib/Utils/interactive-message.js +273 -0
- package/lib/Utils/legitimacy-signal-injector.js +180 -0
- package/lib/Utils/link-preview.js +106 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +54 -0
- package/lib/Utils/make-mutex.js +41 -0
- package/lib/Utils/message-composer.d.ts +106 -0
- package/lib/Utils/message-composer.js +721 -0
- package/lib/Utils/message-retry-manager.d.ts +88 -0
- package/lib/Utils/message-retry-manager.js +160 -0
- package/lib/Utils/message-search.d.ts +52 -0
- package/lib/Utils/message-search.js +226 -0
- package/lib/Utils/messages-media.js +899 -0
- package/lib/Utils/messages.js +2698 -0
- package/lib/Utils/noise-handler.js +175 -0
- package/lib/Utils/offline-node-processor.js +45 -0
- package/lib/Utils/pre-key-manager.js +131 -0
- package/lib/Utils/presence-choreographer.js +438 -0
- package/lib/Utils/process-message.js +423 -0
- package/lib/Utils/rate-limiter.js +232 -0
- package/lib/Utils/reconnect-throttle.js +157 -0
- package/lib/Utils/reply-ratio-guard.js +137 -0
- package/lib/Utils/reporting-utils.js +307 -0
- package/lib/Utils/retry-reason-tracker.js +140 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +400 -0
- package/lib/Utils/rich-response-utils.js +461 -0
- package/lib/Utils/scheduling.d.ts +135 -0
- package/lib/Utils/scheduling.js +246 -0
- package/lib/Utils/session-fingerprint.js +226 -0
- package/lib/Utils/session-stability.js +224 -0
- package/lib/Utils/signal.js +188 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/state-manager.js +91 -0
- package/lib/Utils/status-posting.d.ts +81 -0
- package/lib/Utils/status-posting.js +187 -0
- package/lib/Utils/stealth-connect.js +124 -0
- package/lib/Utils/sync-action-utils.js +55 -0
- package/lib/Utils/tc-token-utils.js +171 -0
- package/lib/Utils/templates.d.ts +54 -0
- package/lib/Utils/templates.js +244 -0
- package/lib/Utils/timelock-guard.js +162 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +81 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +86 -0
- package/lib/Utils/use-sqlite-auth-state.js +187 -0
- package/lib/Utils/vCard.d.ts +71 -0
- package/lib/Utils/vCard.js +196 -0
- package/lib/Utils/validate-connection.js +253 -0
- package/lib/Utils/warmup.js +154 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +270 -0
- package/lib/WABinary/encode.js +279 -0
- package/lib/WABinary/generic-utils.js +223 -0
- package/lib/WABinary/index.js +34 -0
- package/lib/WABinary/jid-utils.js +84 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15254 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +32 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +71 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +58 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +34 -0
- package/lib/WAUSync/USyncQuery.js +99 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/USyncUsernameProtocol.js +37 -0
- package/lib/WAUSync/index.js +32 -0
- package/lib/index.js +59 -0
- package/package.json +105 -5
- package/README.md +0 -5
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.makePrivacySocket = void 0
|
|
4
|
+
|
|
5
|
+
const { executeWMexQuery } = require('./mex')
|
|
6
|
+
|
|
7
|
+
const PRIVACY_MEX_IDS = {
|
|
8
|
+
GET_SETTINGS: '32774292262215380',
|
|
9
|
+
SET_SETTING: '26887749497493184',
|
|
10
|
+
UPDATE_CONTACT_LIST: '26375158178762800',
|
|
11
|
+
GET_CONTACT_LIST: '25700444246275824',
|
|
12
|
+
UPDATE_TEXT_STATUS: '25863197129975892',
|
|
13
|
+
GET_TEXT_STATUS_LIST: '25741205615468936',
|
|
14
|
+
UPDATE_USER_STATUS: '7452341274886724',
|
|
15
|
+
FETCH_USER_PICTURE: '24983561624604410',
|
|
16
|
+
PROFILE_PICTURE_MUTATION: '24714239711610700',
|
|
17
|
+
ACCOUNT_LOGIN: '27298465499757130',
|
|
18
|
+
ACCOUNT_LOGOUT: '26863447609979190',
|
|
19
|
+
MULTI_ACCOUNT_REVOKE: '25846242091639660',
|
|
20
|
+
ADD_MULTI_ACCOUNT_LINK: '25502812266025190',
|
|
21
|
+
ADD_TRUSTED_DEVICE: '24522952587403290',
|
|
22
|
+
GET_TRUSTED_DEVICES: '25123358920671964',
|
|
23
|
+
UNTRUST_TRUSTED_DEVICE: '26574930682133620',
|
|
24
|
+
DELETE_TRUSTED_DEVICE: '33867503889559536',
|
|
25
|
+
MOBILE_CONFIG_FETCH: '25676911271914596',
|
|
26
|
+
NOTIFY_PUSH_NAME: '25900490552974544',
|
|
27
|
+
CONTACT_INTEGRITY: '25924358997169496',
|
|
28
|
+
BIZ_INTEGRITY: '25975613018777536',
|
|
29
|
+
LINKED_PROFILES_SET: '25013968611531010',
|
|
30
|
+
LINKED_PROFILES_REMOVE: '24537675509265524',
|
|
31
|
+
LINKED_PROFILES_UPDATE: '24876967165297616',
|
|
32
|
+
MIGRATE_BLOCKLIST_LID: '25028600226770430',
|
|
33
|
+
QR_CODE_SCAN: '26287165600869744'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const makePrivacySocket = (sock) => {
|
|
37
|
+
const { query, generateMessageTag } = sock
|
|
38
|
+
const mexQuery = (variables, queryId, dataPath) =>
|
|
39
|
+
executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag)
|
|
40
|
+
|
|
41
|
+
const getPrivacySettings = (jid, features = null) => {
|
|
42
|
+
const users = [{ jid, ...(features ? { privacy_features: features } : {}) }]
|
|
43
|
+
return mexQuery({ users }, PRIVACY_MEX_IDS.GET_SETTINGS, 'xwa2_fetch_wa_users')
|
|
44
|
+
}
|
|
45
|
+
const setPrivacySetting = (feature, setting) =>
|
|
46
|
+
mexQuery({ feature, setting }, PRIVACY_MEX_IDS.SET_SETTING, 'xwa2_privacy_feature_update')
|
|
47
|
+
const updatePrivacyContactList = (feature, setting, jids) =>
|
|
48
|
+
mexQuery(
|
|
49
|
+
{ feature, setting, contacts: jids.map((jid) => ({ jid })) },
|
|
50
|
+
PRIVACY_MEX_IDS.UPDATE_CONTACT_LIST,
|
|
51
|
+
'xwa2_privacy_contact_list_update'
|
|
52
|
+
)
|
|
53
|
+
const getPrivacyContactList = (feature, setting) =>
|
|
54
|
+
mexQuery(
|
|
55
|
+
{ feature, setting },
|
|
56
|
+
PRIVACY_MEX_IDS.GET_CONTACT_LIST,
|
|
57
|
+
'xwa2_privacy_contact_list'
|
|
58
|
+
)
|
|
59
|
+
const updateTextStatus = (text, emoji = null) => {
|
|
60
|
+
const input = { text }
|
|
61
|
+
if (emoji) input.emoji = { content: emoji }
|
|
62
|
+
return mexQuery(
|
|
63
|
+
{ text_status_input: input },
|
|
64
|
+
PRIVACY_MEX_IDS.UPDATE_TEXT_STATUS,
|
|
65
|
+
'xwa2_text_status_update'
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
const getTextStatusList = (jids, lastUpdateTime = null) => {
|
|
69
|
+
const input = jids.map((jid) => ({ jid, last_update_time: lastUpdateTime }))
|
|
70
|
+
return mexQuery({ input }, PRIVACY_MEX_IDS.GET_TEXT_STATUS_LIST, 'xwa2_text_status_list')
|
|
71
|
+
}
|
|
72
|
+
const updateUserStatus = (status) =>
|
|
73
|
+
mexQuery({ status }, PRIVACY_MEX_IDS.UPDATE_USER_STATUS, 'xwa2_update_user_status')
|
|
74
|
+
const fetchUserPictureInfo = (jid) =>
|
|
75
|
+
mexQuery({ jid }, PRIVACY_MEX_IDS.FETCH_USER_PICTURE, 'xwa2_fetch_user_picture_info')
|
|
76
|
+
const setProfilePictureMex = (imageBase64, type = 'image') =>
|
|
77
|
+
mexQuery(
|
|
78
|
+
{ input: { image: imageBase64, type } },
|
|
79
|
+
PRIVACY_MEX_IDS.PROFILE_PICTURE_MUTATION,
|
|
80
|
+
'xwa2_profile_picture_mutation'
|
|
81
|
+
)
|
|
82
|
+
const accountLogin = (phoneNumber) =>
|
|
83
|
+
mexQuery(
|
|
84
|
+
{ input: { phone_number: phoneNumber } },
|
|
85
|
+
PRIVACY_MEX_IDS.ACCOUNT_LOGIN,
|
|
86
|
+
'xwa2_account_login'
|
|
87
|
+
)
|
|
88
|
+
const accountLogout = (phoneNumber, enabledBiometric = false) =>
|
|
89
|
+
mexQuery(
|
|
90
|
+
{ input: { phone_number: phoneNumber, enabled_biometric: enabledBiometric } },
|
|
91
|
+
PRIVACY_MEX_IDS.ACCOUNT_LOGOUT,
|
|
92
|
+
'xwa2_account_logout'
|
|
93
|
+
)
|
|
94
|
+
const addMultiAccountLink = (phoneNumber) =>
|
|
95
|
+
mexQuery(
|
|
96
|
+
{ input: { phone_number: phoneNumber } },
|
|
97
|
+
PRIVACY_MEX_IDS.ADD_MULTI_ACCOUNT_LINK,
|
|
98
|
+
'xwa2_add_multi_account_link'
|
|
99
|
+
)
|
|
100
|
+
const addTrustedDevice = (deviceId, deviceName) =>
|
|
101
|
+
mexQuery(
|
|
102
|
+
{ device_id: deviceId, device_name: deviceName },
|
|
103
|
+
PRIVACY_MEX_IDS.ADD_TRUSTED_DEVICE,
|
|
104
|
+
'xwa2_add_trusted_device'
|
|
105
|
+
)
|
|
106
|
+
const getTrustedDevices = () =>
|
|
107
|
+
mexQuery({}, PRIVACY_MEX_IDS.GET_TRUSTED_DEVICES, 'xwa2_get_trusted_devices')
|
|
108
|
+
const untrustTrustedDevice = (deviceId, reason = 'USER_INITIATED') =>
|
|
109
|
+
mexQuery(
|
|
110
|
+
{ device_id: deviceId, reason },
|
|
111
|
+
PRIVACY_MEX_IDS.UNTRUST_TRUSTED_DEVICE,
|
|
112
|
+
'xwa2_untrust_trusted_device'
|
|
113
|
+
)
|
|
114
|
+
const deleteTrustedDevice = (deviceId) =>
|
|
115
|
+
mexQuery(
|
|
116
|
+
{ device_id: deviceId },
|
|
117
|
+
PRIVACY_MEX_IDS.DELETE_TRUSTED_DEVICE,
|
|
118
|
+
'xwa2_delete_trusted_device'
|
|
119
|
+
)
|
|
120
|
+
const revokeMultiAccount = (accountJid) =>
|
|
121
|
+
mexQuery(
|
|
122
|
+
{ account_jid: accountJid },
|
|
123
|
+
PRIVACY_MEX_IDS.MULTI_ACCOUNT_REVOKE,
|
|
124
|
+
'xwa2_multi_account_revoke'
|
|
125
|
+
)
|
|
126
|
+
const fetchMobileConfig = (apiVersion = 0, epRefreshId = 0, flags = '') =>
|
|
127
|
+
mexQuery(
|
|
128
|
+
{ api_version: apiVersion, ep_refresh_id: epRefreshId, flags },
|
|
129
|
+
PRIVACY_MEX_IDS.MOBILE_CONFIG_FETCH,
|
|
130
|
+
'xwa2_mobile_config_fetch'
|
|
131
|
+
)
|
|
132
|
+
const notifyPushName = (groupJid, participants) =>
|
|
133
|
+
mexQuery(
|
|
134
|
+
{
|
|
135
|
+
input: {
|
|
136
|
+
group_jid: groupJid,
|
|
137
|
+
participants: participants.map(({ jid, pushName }) => ({
|
|
138
|
+
jid,
|
|
139
|
+
push_name: pushName
|
|
140
|
+
}))
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
PRIVACY_MEX_IDS.NOTIFY_PUSH_NAME,
|
|
144
|
+
'xwa2_notify_push_name'
|
|
145
|
+
)
|
|
146
|
+
const contactIntegrityQuery = (jids, useCase = 'START_CHAT_CONTEXT') =>
|
|
147
|
+
mexQuery(
|
|
148
|
+
{ users: jids.map((jid) => ({ jid })), use_case: useCase },
|
|
149
|
+
PRIVACY_MEX_IDS.CONTACT_INTEGRITY,
|
|
150
|
+
'xwa2_fetch_wa_users'
|
|
151
|
+
)
|
|
152
|
+
const bizIntegrityQuery = (jids) =>
|
|
153
|
+
mexQuery(
|
|
154
|
+
{ users: jids.map((jid) => ({ jid })) },
|
|
155
|
+
PRIVACY_MEX_IDS.BIZ_INTEGRITY,
|
|
156
|
+
'xwa2_fetch_wa_users'
|
|
157
|
+
)
|
|
158
|
+
const linkedProfilesSet = (profiles) => {
|
|
159
|
+
const mapped = profiles.map((p) => {
|
|
160
|
+
const entry = { type: p.type }
|
|
161
|
+
if (p.vid) entry.vid = p.vid
|
|
162
|
+
else if (p.username) entry.username = p.username
|
|
163
|
+
return entry
|
|
164
|
+
})
|
|
165
|
+
return mexQuery(
|
|
166
|
+
{ profiles: mapped },
|
|
167
|
+
PRIVACY_MEX_IDS.LINKED_PROFILES_SET,
|
|
168
|
+
'xwa2_linked_profiles_set'
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
const linkedProfilesRemove = (types) =>
|
|
172
|
+
mexQuery(
|
|
173
|
+
{ profiles: types.map((type) => ({ type })) },
|
|
174
|
+
PRIVACY_MEX_IDS.LINKED_PROFILES_REMOVE,
|
|
175
|
+
'xwa2_linked_profiles_remove'
|
|
176
|
+
)
|
|
177
|
+
const linkedProfilesUpdate = (profiles) =>
|
|
178
|
+
mexQuery(
|
|
179
|
+
{
|
|
180
|
+
profiles: profiles.map(({ type, showOnProfile }) => ({
|
|
181
|
+
type,
|
|
182
|
+
show_on_profile: showOnProfile
|
|
183
|
+
}))
|
|
184
|
+
},
|
|
185
|
+
PRIVACY_MEX_IDS.LINKED_PROFILES_UPDATE,
|
|
186
|
+
'xwa2_linked_profiles_update'
|
|
187
|
+
)
|
|
188
|
+
const migrateBlocklistLid = (jids, dhash = '', dirtyAck = true) =>
|
|
189
|
+
mexQuery(
|
|
190
|
+
{ input: { blocklist: jids.map((jid) => ({ jid })), dhash, dirty_ack: dirtyAck } },
|
|
191
|
+
PRIVACY_MEX_IDS.MIGRATE_BLOCKLIST_LID,
|
|
192
|
+
'xwa2_migrate_blocklist_lid'
|
|
193
|
+
)
|
|
194
|
+
const qrCodeScan = (qrData) =>
|
|
195
|
+
mexQuery({ qr_data: qrData }, PRIVACY_MEX_IDS.QR_CODE_SCAN, 'xwa2_qr_code_scan')
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
...sock,
|
|
199
|
+
getPrivacySettings,
|
|
200
|
+
setPrivacySetting,
|
|
201
|
+
updatePrivacyContactList,
|
|
202
|
+
getPrivacyContactList,
|
|
203
|
+
updateTextStatus,
|
|
204
|
+
getTextStatusList,
|
|
205
|
+
updateUserStatus,
|
|
206
|
+
fetchUserPictureInfo,
|
|
207
|
+
setProfilePictureMex,
|
|
208
|
+
accountLogin,
|
|
209
|
+
accountLogout,
|
|
210
|
+
addMultiAccountLink,
|
|
211
|
+
addTrustedDevice,
|
|
212
|
+
getTrustedDevices,
|
|
213
|
+
untrustTrustedDevice,
|
|
214
|
+
deleteTrustedDevice,
|
|
215
|
+
revokeMultiAccount,
|
|
216
|
+
fetchMobileConfig,
|
|
217
|
+
notifyPushName,
|
|
218
|
+
contactIntegrityQuery,
|
|
219
|
+
bizIntegrityQuery,
|
|
220
|
+
linkedProfilesSet,
|
|
221
|
+
linkedProfilesRemove,
|
|
222
|
+
linkedProfilesUpdate,
|
|
223
|
+
migrateBlocklistLid,
|
|
224
|
+
qrCodeScan,
|
|
225
|
+
PRIVACY_MEX_IDS
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
module.exports = { makePrivacySocket, PRIVACY_MEX_IDS }
|
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
exports.mobileRegisterFetch =
|
|
9
|
+
exports.mobileRegisterEncrypt =
|
|
10
|
+
exports.mobileRegister =
|
|
11
|
+
exports.mobileRegisterExists =
|
|
12
|
+
exports.mobileRegisterCode =
|
|
13
|
+
exports.registrationParams =
|
|
14
|
+
exports.makeRegistrationSocket =
|
|
15
|
+
void 0
|
|
16
|
+
/* eslint-disable camelcase */
|
|
17
|
+
const axios_1 = __importDefault(require('axios'))
|
|
18
|
+
const Defaults_1 = require('../Defaults')
|
|
19
|
+
const crypto_1 = require('../Utils/crypto')
|
|
20
|
+
const WABinary_1 = require('../WABinary')
|
|
21
|
+
const business_1 = require('./business')
|
|
22
|
+
const community_1 = require('./community')
|
|
23
|
+
const username_1 = require('./username')
|
|
24
|
+
function urlencode(str) {
|
|
25
|
+
return str.replace(/-/g, '%2d').replace(/_/g, '%5f').replace(/~/g, '%7e')
|
|
26
|
+
}
|
|
27
|
+
const validRegistrationOptions = (config) =>
|
|
28
|
+
(config === null || config === void 0 ? void 0 : config.phoneNumberCountryCode) &&
|
|
29
|
+
config.phoneNumberNationalNumber &&
|
|
30
|
+
config.phoneNumberMobileCountryCode
|
|
31
|
+
const makeRegistrationSocket = (config) => {
|
|
32
|
+
const sock = (0, username_1.makeUsernameSocket)(config)
|
|
33
|
+
const register = async (code) => {
|
|
34
|
+
if (!validRegistrationOptions(config.auth.creds.registration)) {
|
|
35
|
+
throw new Error('please specify the registration options')
|
|
36
|
+
}
|
|
37
|
+
const result = await mobileRegister(
|
|
38
|
+
{ ...sock.authState.creds, ...sock.authState.creds.registration, code },
|
|
39
|
+
config.options
|
|
40
|
+
)
|
|
41
|
+
sock.authState.creds.me = {
|
|
42
|
+
id: (0, WABinary_1.jidEncode)(result.login, 's.whatsapp.net'),
|
|
43
|
+
name: '~'
|
|
44
|
+
}
|
|
45
|
+
sock.authState.creds.registered = true
|
|
46
|
+
sock.ev.emit('creds.update', sock.authState.creds)
|
|
47
|
+
return result
|
|
48
|
+
}
|
|
49
|
+
const requestRegistrationCode = async (registrationOptions) => {
|
|
50
|
+
registrationOptions = registrationOptions || config.auth.creds.registration
|
|
51
|
+
if (!validRegistrationOptions(registrationOptions)) {
|
|
52
|
+
throw new Error('Invalid registration options')
|
|
53
|
+
}
|
|
54
|
+
sock.authState.creds.registration = registrationOptions
|
|
55
|
+
sock.ev.emit('creds.update', sock.authState.creds)
|
|
56
|
+
return mobileRegisterCode({ ...config.auth.creds, ...registrationOptions }, config.options)
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
...sock,
|
|
60
|
+
register,
|
|
61
|
+
requestRegistrationCode
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.makeRegistrationSocket = makeRegistrationSocket
|
|
65
|
+
function convertBufferToUrlHex(buffer) {
|
|
66
|
+
var id = ''
|
|
67
|
+
buffer.forEach((x) => {
|
|
68
|
+
// encode random identity_id buffer as percentage url encoding
|
|
69
|
+
id += `%${x.toString(16).padStart(2, '0').toLowerCase()}`
|
|
70
|
+
})
|
|
71
|
+
return id
|
|
72
|
+
}
|
|
73
|
+
function registrationParams(params) {
|
|
74
|
+
const e_regid = Buffer.alloc(4)
|
|
75
|
+
e_regid.writeInt32BE(params.registrationId)
|
|
76
|
+
const e_skey_id = Buffer.alloc(3)
|
|
77
|
+
e_skey_id.writeInt16BE(params.signedPreKey.keyId)
|
|
78
|
+
params.phoneNumberCountryCode = params.phoneNumberCountryCode.replace('+', '').trim()
|
|
79
|
+
params.phoneNumberNationalNumber = params.phoneNumberNationalNumber
|
|
80
|
+
.replace(/[/-\s)(]/g, '')
|
|
81
|
+
.trim()
|
|
82
|
+
return {
|
|
83
|
+
cc: params.phoneNumberCountryCode,
|
|
84
|
+
in: params.phoneNumberNationalNumber,
|
|
85
|
+
Rc: '0',
|
|
86
|
+
lg: 'en',
|
|
87
|
+
lc: 'GB',
|
|
88
|
+
mistyped: '6',
|
|
89
|
+
authkey: Buffer.from(params.noiseKey.public).toString('base64url'),
|
|
90
|
+
e_regid: e_regid.toString('base64url'),
|
|
91
|
+
e_keytype: 'BQ',
|
|
92
|
+
e_ident: Buffer.from(params.signedIdentityKey.public).toString('base64url'),
|
|
93
|
+
// e_skey_id: e_skey_id.toString('base64url'),
|
|
94
|
+
e_skey_id: 'AAAA',
|
|
95
|
+
e_skey_val: Buffer.from(params.signedPreKey.keyPair.public).toString('base64url'),
|
|
96
|
+
e_skey_sig: Buffer.from(params.signedPreKey.signature).toString('base64url'),
|
|
97
|
+
fdid: params.phoneId,
|
|
98
|
+
network_ratio_type: '1',
|
|
99
|
+
expid: params.deviceId,
|
|
100
|
+
simnum: '1',
|
|
101
|
+
hasinrc: '1',
|
|
102
|
+
pid: Math.floor(Math.random() * 1000).toString(),
|
|
103
|
+
id: convertBufferToUrlHex(params.identityId),
|
|
104
|
+
backup_token: convertBufferToUrlHex(params.backupToken),
|
|
105
|
+
token: (0, crypto_1.md5)(
|
|
106
|
+
Buffer.concat([Defaults_1.MOBILE_TOKEN, Buffer.from(params.phoneNumberNationalNumber)])
|
|
107
|
+
).toString('hex'),
|
|
108
|
+
fraud_checkpoint_code: params.captcha
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.registrationParams = registrationParams
|
|
112
|
+
/**
|
|
113
|
+
* Requests a registration code for the given phone number.
|
|
114
|
+
*/
|
|
115
|
+
function mobileRegisterCode(params, fetchOptions) {
|
|
116
|
+
return mobileRegisterFetch('/code', {
|
|
117
|
+
params: {
|
|
118
|
+
...registrationParams(params),
|
|
119
|
+
mcc: `${params.phoneNumberMobileCountryCode}`.padStart(3, '0'),
|
|
120
|
+
mnc: `${params.phoneNumberMobileNetworkCode || '001'}`.padStart(3, '0'),
|
|
121
|
+
sim_mcc: '000',
|
|
122
|
+
sim_mnc: '000',
|
|
123
|
+
method: (params === null || params === void 0 ? void 0 : params.method) || 'sms',
|
|
124
|
+
reason: '',
|
|
125
|
+
hasav: '1'
|
|
126
|
+
},
|
|
127
|
+
...fetchOptions
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
exports.mobileRegisterCode = mobileRegisterCode
|
|
131
|
+
function mobileRegisterExists(params, fetchOptions) {
|
|
132
|
+
return mobileRegisterFetch('/exist', {
|
|
133
|
+
params: registrationParams(params),
|
|
134
|
+
...fetchOptions
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
exports.mobileRegisterExists = mobileRegisterExists
|
|
138
|
+
/**
|
|
139
|
+
* Registers the phone number on whatsapp with the received OTP code.
|
|
140
|
+
*/
|
|
141
|
+
async function mobileRegister(params, fetchOptions) {
|
|
142
|
+
//const result = await mobileRegisterFetch(`/reg_onboard_abprop?cc=${params.phoneNumberCountryCode}&in=${params.phoneNumberNationalNumber}&rc=0`)
|
|
143
|
+
return mobileRegisterFetch('/register', {
|
|
144
|
+
params: { ...registrationParams(params), code: params.code.replace('-', '') },
|
|
145
|
+
...fetchOptions
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
exports.mobileRegister = mobileRegister
|
|
149
|
+
/**
|
|
150
|
+
* Encrypts the given string as AEAD aes-256-gcm with the public whatsapp key and a random keypair.
|
|
151
|
+
*/
|
|
152
|
+
function mobileRegisterEncrypt(data) {
|
|
153
|
+
const keypair = crypto_1.Curve.generateKeyPair()
|
|
154
|
+
const key = crypto_1.Curve.sharedKey(keypair.private, Defaults_1.REGISTRATION_PUBLIC_KEY)
|
|
155
|
+
const buffer = (0, crypto_1.aesEncryptGCM)(
|
|
156
|
+
Buffer.from(data),
|
|
157
|
+
new Uint8Array(key),
|
|
158
|
+
Buffer.alloc(12),
|
|
159
|
+
Buffer.alloc(0)
|
|
160
|
+
)
|
|
161
|
+
return Buffer.concat([Buffer.from(keypair.public), buffer]).toString('base64url')
|
|
162
|
+
}
|
|
163
|
+
exports.mobileRegisterEncrypt = mobileRegisterEncrypt
|
|
164
|
+
async function mobileRegisterFetch(path, opts = {}) {
|
|
165
|
+
let url = `${Defaults_1.MOBILE_REGISTRATION_ENDPOINT}${path}`
|
|
166
|
+
if (opts.params) {
|
|
167
|
+
const parameter = []
|
|
168
|
+
for (const param in opts.params) {
|
|
169
|
+
if (opts.params[param] !== null && opts.params[param] !== undefined) {
|
|
170
|
+
parameter.push(param + '=' + urlencode(opts.params[param]))
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
url += `?${parameter.join('&')}`
|
|
174
|
+
delete opts.params
|
|
175
|
+
}
|
|
176
|
+
if (!opts.headers) {
|
|
177
|
+
opts.headers = {}
|
|
178
|
+
}
|
|
179
|
+
opts.headers['User-Agent'] = Defaults_1.MOBILE_USERAGENT
|
|
180
|
+
const response = await (0, axios_1.default)(url, opts)
|
|
181
|
+
var json = response.data
|
|
182
|
+
if (response.status > 300 || json.reason) {
|
|
183
|
+
throw json
|
|
184
|
+
}
|
|
185
|
+
if (json.status && !['ok', 'sent'].includes(json.status)) {
|
|
186
|
+
throw json
|
|
187
|
+
}
|
|
188
|
+
return json
|
|
189
|
+
}
|
|
190
|
+
exports.mobileRegisterFetch = mobileRegisterFetch
|