@x4r1s3/baileys 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +1262 -2
- package/SECURITY.md +47 -0
- package/WAProto/V +1 -0
- package/WAProto/WAProto.proto +8892 -0
- package/WAProto/index.d.ts +104128 -0
- package/WAProto/index.js +334920 -0
- package/assets/rolling-circle.svg +133 -0
- package/assets/x4r1s3-banner.svg +32 -0
- package/engine-requirements.js +27 -0
- package/lib/Builders/A2UI.js +245 -0
- package/lib/Builders/AIRich.js +179 -0
- package/lib/Builders/Button.js +108 -0
- package/lib/Builders/CFC.js +284 -0
- package/lib/Builders/Carousel.js +81 -0
- package/lib/Call/THIRD_PARTY_LICENSE.txt +21 -0
- package/lib/Call/audio-feeder.mjs +179 -0
- package/lib/Call/audio-recorder.mjs +250 -0
- package/lib/Call/fetch-wasm-resources.mjs +104 -0
- package/lib/Call/index.mjs +680 -0
- package/lib/Call/relay-transport.mjs +563 -0
- package/lib/Call/signaling.mjs +641 -0
- package/lib/Call/types.mjs +17 -0
- package/lib/Call/video-feeder.mjs +94 -0
- package/lib/Call/wasm-engine.mjs +1372 -0
- package/lib/Call/worker-bootstrap.mjs +1042 -0
- package/lib/Defaults/ban-checker.js +56 -0
- package/lib/Defaults/index.js +170 -0
- package/lib/Signal/Group/ciphertext-message.js +23 -0
- package/lib/Signal/Group/group-session-builder.js +41 -0
- package/lib/Signal/Group/group_cipher.js +93 -0
- package/lib/Signal/Group/index.js +23 -0
- package/lib/Signal/Group/keyhelper.js +29 -0
- package/lib/Signal/Group/sender-chain-key.js +37 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +74 -0
- package/lib/Signal/Group/sender-key-message.js +77 -0
- package/lib/Signal/Group/sender-key-name.js +59 -0
- package/lib/Signal/Group/sender-key-record.js +52 -0
- package/lib/Signal/Group/sender-key-state.js +95 -0
- package/lib/Signal/Group/sender-message-key.js +37 -0
- package/lib/Signal/libsignal.js +440 -0
- package/lib/Signal/lid-mapping.js +292 -0
- package/lib/Socket/Client/index.js +14 -0
- package/lib/Socket/Client/types.js +22 -0
- package/lib/Socket/Client/websocket.js +65 -0
- package/lib/Socket/aigroups.js +327 -0
- package/lib/Socket/ban-checker.js +165 -0
- package/lib/Socket/business.js +419 -0
- package/lib/Socket/chats.js +1921 -0
- package/lib/Socket/communities.js +443 -0
- package/lib/Socket/graphql.js +911 -0
- package/lib/Socket/groups.js +561 -0
- package/lib/Socket/index.js +49 -0
- package/lib/Socket/interactive-handler.js +612 -0
- package/lib/Socket/interop.js +575 -0
- package/lib/Socket/managed-account.js +220 -0
- package/lib/Socket/messages-recv.js +2191 -0
- package/lib/Socket/messages-send.js +4104 -0
- package/lib/Socket/mex.js +53 -0
- package/lib/Socket/newsletter.js +291 -0
- package/lib/Socket/privacy.js +458 -0
- package/lib/Socket/registration.js +440 -0
- package/lib/Socket/socket.js +1029 -0
- package/lib/Socket/status-actions.js +287 -0
- package/lib/Socket/username.js +241 -0
- package/lib/Store/index.js +16 -0
- package/lib/Store/make-cache-manager-store.js +101 -0
- package/lib/Store/make-in-memory-store.js +432 -0
- package/lib/Store/make-ordered-dictionary.js +90 -0
- package/lib/Store/object-repository.js +35 -0
- package/lib/Types/Auth.js +13 -0
- package/lib/Types/Bussines.js +13 -0
- package/lib/Types/Call.js +13 -0
- package/lib/Types/Chat.js +19 -0
- package/lib/Types/Contact.js +13 -0
- package/lib/Types/Events.js +13 -0
- package/lib/Types/GroupMetadata.js +13 -0
- package/lib/Types/Label.js +36 -0
- package/lib/Types/LabelAssociation.js +18 -0
- package/lib/Types/Message.js +30 -0
- package/lib/Types/Mex.js +53 -0
- package/lib/Types/Product.js +13 -0
- package/lib/Types/RichType.js +34 -0
- package/lib/Types/Signal.js +13 -0
- package/lib/Types/Socket.js +14 -0
- package/lib/Types/State.js +60 -0
- package/lib/Types/USync.js +13 -0
- package/lib/Types/index.js +37 -0
- package/lib/Utils/auth-utils.js +313 -0
- package/lib/Utils/ban-checker.js +48 -0
- package/lib/Utils/bot-capabilities.js +96 -0
- package/lib/Utils/bot-planning-replay.js +177 -0
- package/lib/Utils/browser-utils.js +40 -0
- package/lib/Utils/business.js +242 -0
- package/lib/Utils/c2582.js +147 -0
- package/lib/Utils/chat-utils.js +905 -0
- package/lib/Utils/companion-reg-client-utils.js +44 -0
- package/lib/Utils/consumer-application.js +114 -0
- package/lib/Utils/crypto.js +129 -0
- package/lib/Utils/decode-wa-message.js +496 -0
- package/lib/Utils/direct-chat-theme.js +164 -0
- package/lib/Utils/event-buffer.js +601 -0
- package/lib/Utils/experimental-proto.js +206 -0
- package/lib/Utils/games/miniapp.js +17 -0
- package/lib/Utils/games/slot-machine.js +270 -0
- package/lib/Utils/games/website-preview.js +306 -0
- package/lib/Utils/generics.js +402 -0
- package/lib/Utils/group-history.js +68 -0
- package/lib/Utils/group-wallpaper.js +168 -0
- package/lib/Utils/history.js +162 -0
- package/lib/Utils/identity-change-handler.js +60 -0
- package/lib/Utils/index.js +61 -0
- package/lib/Utils/jid-display-normalization.js +221 -0
- package/lib/Utils/link-preview.js +96 -0
- package/lib/Utils/logger.js +14 -0
- package/lib/Utils/lt-hash.js +19 -0
- package/lib/Utils/make-mutex.js +44 -0
- package/lib/Utils/message-composer.js +709 -0
- package/lib/Utils/message-inspect.js +79 -0
- package/lib/Utils/message-retry-manager.js +253 -0
- package/lib/Utils/message-security.js +167 -0
- package/lib/Utils/messages-media.js +1027 -0
- package/lib/Utils/messages.js +2467 -0
- package/lib/Utils/meta-ai-msmsg.js +215 -0
- package/lib/Utils/meta-compositing.js +239 -0
- package/lib/Utils/native-flow.js +158 -0
- package/lib/Utils/newsletter-live-update-utils.js +74 -0
- package/lib/Utils/newsletter-status-utils.js +152 -0
- package/lib/Utils/noise-handler.js +212 -0
- package/lib/Utils/offline-node-processor.js +51 -0
- package/lib/Utils/poll-manager.js +206 -0
- package/lib/Utils/portable-compat.js +12 -0
- package/lib/Utils/pre-key-manager.js +117 -0
- package/lib/Utils/process-message.js +610 -0
- package/lib/Utils/reporting-utils.js +269 -0
- package/lib/Utils/rich-message-utils.js +2841 -0
- package/lib/Utils/scheduled-message.js +107 -0
- package/lib/Utils/signal.js +212 -0
- package/lib/Utils/source-grep.js +57 -0
- package/lib/Utils/stanza-ack.js +49 -0
- package/lib/Utils/sticker-annotation.js +87 -0
- package/lib/Utils/sync-action-utils.js +59 -0
- package/lib/Utils/tc-token-utils.js +174 -0
- package/lib/Utils/use-multi-file-auth-state.js +132 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +120 -0
- package/lib/Utils/validate-connection.js +220 -0
- package/lib/Utils/view-once-utils.js +218 -0
- package/lib/Utils/voip-rekey.js +32 -0
- package/lib/Utils/website-preview.js +27 -0
- package/lib/Utils/welcome-flow.js +228 -0
- package/lib/Utils/x4r1s3.js +144 -0
- package/lib/WABinary/constants.js +1475 -0
- package/lib/WABinary/decode.js +273 -0
- package/lib/WABinary/encode.js +231 -0
- package/lib/WABinary/generic-utils.js +242 -0
- package/lib/WABinary/index.js +17 -0
- package/lib/WABinary/jid-utils.js +107 -0
- package/lib/WABinary/types.js +13 -0
- package/lib/WAM/BinaryInfo.js +21 -0
- package/lib/WAM/constants.js +22864 -0
- package/lib/WAM/encode.js +161 -0
- package/lib/WAM/index.js +15 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +108 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +68 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +82 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +40 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +46 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +36 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +40 -0
- package/lib/WAUSync/Protocols/index.js +24 -0
- package/lib/WAUSync/USyncQuery.js +213 -0
- package/lib/WAUSync/USyncUser.js +66 -0
- package/lib/WAUSync/index.js +15 -0
- package/lib/antiban.cjs +4726 -0
- package/lib/index.d.ts +1285 -0
- package/lib/index.js +30 -0
- package/package.json +125 -4
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { downloadMediaMessage, generateWAMessageContent } from '../Utils/messages.js';
|
|
3
|
+
import { isJidGroup, isJidStatusBroadcast, isLidUser, isPnUser, jidDecode, jidNormalizedUser } from '../WABinary/index.js';
|
|
4
|
+
|
|
5
|
+
const STATUS_JID = 'status@broadcast';
|
|
6
|
+
const GROUP_STATUS_FIELDS = new Set(['groupStatusMessage', 'groupStatusMessageV2']);
|
|
7
|
+
const MESSAGE_WRAPPERS = new Set([
|
|
8
|
+
'deviceSentMessage',
|
|
9
|
+
'documentWithCaptionMessage',
|
|
10
|
+
'editedMessage',
|
|
11
|
+
'ephemeralMessage',
|
|
12
|
+
'groupMentionedMessage',
|
|
13
|
+
'message',
|
|
14
|
+
'viewOnceMessage',
|
|
15
|
+
'viewOnceMessageV2',
|
|
16
|
+
'viewOnceMessageV2Extension'
|
|
17
|
+
]);
|
|
18
|
+
const NON_STORY_INTERACTIONS = new Set(['reactionMessage', 'protocolMessage']);
|
|
19
|
+
|
|
20
|
+
export const getStatusKey = (status) => {
|
|
21
|
+
const key = status?.key || status?.fakeObj?.key || status;
|
|
22
|
+
if (!key || typeof key !== 'object' || typeof key.id !== 'string' || !key.id.trim()) {
|
|
23
|
+
throw new Boom('A status message or message key with an id is required', { statusCode: 400 });
|
|
24
|
+
}
|
|
25
|
+
return key;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const findGroupStatusEnvelope = (status) => {
|
|
29
|
+
const roots = [status?.message, status?.fakeObj?.message, status?.message?.message];
|
|
30
|
+
const queue = roots.filter(value => value && typeof value === 'object');
|
|
31
|
+
const visited = new WeakSet();
|
|
32
|
+
let inspected = 0;
|
|
33
|
+
while (queue.length && inspected < 160) {
|
|
34
|
+
const current = queue.shift();
|
|
35
|
+
if (!current || typeof current !== 'object' || visited.has(current)) continue;
|
|
36
|
+
visited.add(current);
|
|
37
|
+
inspected += 1;
|
|
38
|
+
for (const [field, value] of Object.entries(current)) {
|
|
39
|
+
if (GROUP_STATUS_FIELDS.has(field)) return { field, value };
|
|
40
|
+
if (MESSAGE_WRAPPERS.has(field) && value && typeof value === 'object') queue.push(value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const isStatusInteraction = (status) => {
|
|
47
|
+
const roots = [status?.message, status?.fakeObj?.message, status?.message?.message];
|
|
48
|
+
const queue = roots.filter(value => value && typeof value === 'object');
|
|
49
|
+
const visited = new WeakSet();
|
|
50
|
+
let inspected = 0;
|
|
51
|
+
while (queue.length && inspected < 160) {
|
|
52
|
+
const current = queue.shift();
|
|
53
|
+
if (!current || typeof current !== 'object' || visited.has(current)) continue;
|
|
54
|
+
visited.add(current);
|
|
55
|
+
inspected += 1;
|
|
56
|
+
for (const [field, value] of Object.entries(current)) {
|
|
57
|
+
if (NON_STORY_INTERACTIONS.has(field)) return true;
|
|
58
|
+
if (MESSAGE_WRAPPERS.has(field) && value && typeof value === 'object') queue.push(value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const getStatusKind = (status) => {
|
|
65
|
+
if (findGroupStatusEnvelope(status)) return 'group';
|
|
66
|
+
const key = status?.key || status?.fakeObj?.key || status;
|
|
67
|
+
if ((isJidStatusBroadcast(key?.remoteJid) || isJidStatusBroadcast(key?.remoteJidAlt)) && !isStatusInteraction(status)) return 'status';
|
|
68
|
+
return undefined;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const getStatusAuthorJid = (status) => {
|
|
72
|
+
const key = status?.key || status?.fakeObj?.key || status;
|
|
73
|
+
const isPrimaryRemoteStatus = isJidStatusBroadcast(key?.remoteJid);
|
|
74
|
+
const candidates = isPrimaryRemoteStatus
|
|
75
|
+
? [key?.participant, key?.participantAlt, key?.remoteJidAlt, key?.remoteJid, status?.sender, status?.from]
|
|
76
|
+
: [key?.participant, key?.remoteJid, key?.participantAlt, key?.remoteJidAlt, status?.sender, status?.from];
|
|
77
|
+
for (const candidate of candidates) {
|
|
78
|
+
if (typeof candidate !== 'string' || !candidate) continue;
|
|
79
|
+
const normalized = jidNormalizedUser(candidate);
|
|
80
|
+
if (isPnUser(normalized) || isLidUser(normalized)) return normalized;
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const assertReactionText = (emoji) => {
|
|
86
|
+
if (typeof emoji !== 'string' || !emoji.trim()) {
|
|
87
|
+
throw new Boom('Reaction text must be a non-empty emoji/string; pass an empty string only through a dedicated remove-reaction API', { statusCode: 400 });
|
|
88
|
+
}
|
|
89
|
+
return emoji;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const makeStatusActionMethods = ({
|
|
93
|
+
socket,
|
|
94
|
+
ev,
|
|
95
|
+
readMessages,
|
|
96
|
+
resolveStatusRecipients,
|
|
97
|
+
authState,
|
|
98
|
+
logger,
|
|
99
|
+
upload,
|
|
100
|
+
lidMapping,
|
|
101
|
+
downloadMedia = downloadMediaMessage,
|
|
102
|
+
generateContent = generateWAMessageContent
|
|
103
|
+
}) => {
|
|
104
|
+
const getAliases = async (jid) => {
|
|
105
|
+
const normalized = jidNormalizedUser(jid);
|
|
106
|
+
const aliases = new Set([normalized]);
|
|
107
|
+
const mapping = lidMapping || {};
|
|
108
|
+
try {
|
|
109
|
+
const mapped = isLidUser(normalized)
|
|
110
|
+
? await mapping.getPNForLID?.(normalized)
|
|
111
|
+
: isPnUser(normalized)
|
|
112
|
+
? await mapping.getLIDForPN?.(normalized)
|
|
113
|
+
: undefined;
|
|
114
|
+
if (typeof mapped === 'string' && mapped) aliases.add(jidNormalizedUser(mapped));
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Preserve exact-JID matching if this account has not learned the PN/LID mapping yet.
|
|
118
|
+
}
|
|
119
|
+
return aliases;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const ownJids = [
|
|
123
|
+
authState?.creds?.me?.id,
|
|
124
|
+
authState?.creds?.me?.lid,
|
|
125
|
+
authState?.creds?.me?.jid
|
|
126
|
+
].filter(jid => typeof jid === 'string' && jid);
|
|
127
|
+
|
|
128
|
+
const isOwnStatusAuthor = async authorJid => {
|
|
129
|
+
if (!authorJid || !ownJids.length) return false;
|
|
130
|
+
const authorAliases = await getAliases(authorJid);
|
|
131
|
+
for (const ownJid of ownJids) {
|
|
132
|
+
const ownAliases = await getAliases(ownJid);
|
|
133
|
+
if ([...authorAliases].some(alias => ownAliases.has(alias))) return true;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const actionKeyFor = async (status, expectedKind) => {
|
|
139
|
+
const kind = getStatusKind(status);
|
|
140
|
+
if (kind !== expectedKind) {
|
|
141
|
+
throw new Boom(`Expected a ${expectedKind === 'group' ? 'group status' : 'personal status'} message`, { statusCode: 400 });
|
|
142
|
+
}
|
|
143
|
+
const key = getStatusKey(status);
|
|
144
|
+
const authorJid = getStatusAuthorJid(status);
|
|
145
|
+
if (!authorJid) {
|
|
146
|
+
throw new Boom('Could not resolve the status author from its JID/LID key fields', { statusCode: 400 });
|
|
147
|
+
}
|
|
148
|
+
if (await isOwnStatusAuthor(authorJid)) {
|
|
149
|
+
throw new Boom('Status actions require a status sent by another account', { statusCode: 400 });
|
|
150
|
+
}
|
|
151
|
+
if (key.fromMe && !ownJids.length) {
|
|
152
|
+
throw new Boom('Cannot safely verify the author of a status marked fromMe without the connected account identity', { statusCode: 400 });
|
|
153
|
+
}
|
|
154
|
+
if (expectedKind === 'group') {
|
|
155
|
+
if (!isJidGroup(key.remoteJid)) {
|
|
156
|
+
throw new Boom('Group status message key must contain its @g.us remoteJid', { statusCode: 400 });
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
...key,
|
|
160
|
+
fromMe: false,
|
|
161
|
+
remoteJid: key.remoteJid,
|
|
162
|
+
participant: key.participant || authorJid
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const statusRemoteJid = [key.remoteJid, key.remoteJidAlt].find(isJidStatusBroadcast) || STATUS_JID;
|
|
166
|
+
return {
|
|
167
|
+
...key,
|
|
168
|
+
fromMe: false,
|
|
169
|
+
remoteJid: statusRemoteJid,
|
|
170
|
+
participant: key.participant || authorJid
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const matchesTargets = async (status, selectors) => {
|
|
175
|
+
if (selectors == null || selectors === 'all' || selectors === '*') return true;
|
|
176
|
+
const list = Array.isArray(selectors) ? selectors : [selectors];
|
|
177
|
+
if (!list.length || list.some(value => typeof value !== 'string' || !value.trim())) {
|
|
178
|
+
throw new Boom('Status author filter must be "all", "*", or one or more JID/LID strings', { statusCode: 400 });
|
|
179
|
+
}
|
|
180
|
+
const key = status?.key || status?.fakeObj?.key || status;
|
|
181
|
+
const targets = new Set();
|
|
182
|
+
for (const selector of list) {
|
|
183
|
+
const aliases = await getAliases(selector);
|
|
184
|
+
for (const alias of aliases) targets.add(alias);
|
|
185
|
+
}
|
|
186
|
+
const candidates = [getStatusAuthorJid(status), key?.remoteJid, key?.remoteJidAlt]
|
|
187
|
+
.filter(candidate => typeof candidate === 'string' && candidate && !isJidStatusBroadcast(candidate))
|
|
188
|
+
.map(jidNormalizedUser);
|
|
189
|
+
for (const candidate of candidates) {
|
|
190
|
+
const aliases = await getAliases(candidate);
|
|
191
|
+
for (const alias of aliases) if (targets.has(alias)) return true;
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const onStatusMessage = (listener, options = {}) => {
|
|
197
|
+
if (typeof listener !== 'function') {
|
|
198
|
+
throw new Boom('onStatusMessage requires a listener function', { statusCode: 400 });
|
|
199
|
+
}
|
|
200
|
+
if (!ev?.on || !ev?.off) {
|
|
201
|
+
throw new Boom('The socket event emitter does not support on/off subscriptions', { statusCode: 501 });
|
|
202
|
+
}
|
|
203
|
+
const selectors = options.from ?? 'all';
|
|
204
|
+
const includeGroupStatus = options.includeGroupStatus !== false;
|
|
205
|
+
const handler = ({ messages = [], type } = {}) => {
|
|
206
|
+
for (const message of messages) {
|
|
207
|
+
const kind = getStatusKind(message);
|
|
208
|
+
if (!kind || (kind === 'group' && !includeGroupStatus)) continue;
|
|
209
|
+
void (async () => {
|
|
210
|
+
if (!(await matchesTargets(message, selectors))) return;
|
|
211
|
+
const authorJid = getStatusAuthorJid(message);
|
|
212
|
+
await listener({ message, authorJid, kind, type });
|
|
213
|
+
})().catch(error => logger?.error?.({ error }, 'status listener failed'));
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
ev.on('messages.upsert', handler);
|
|
217
|
+
return () => ev.off('messages.upsert', handler);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const likeStatus = async (status, emoji, options = {}) => {
|
|
221
|
+
const key = await actionKeyFor(status, 'status');
|
|
222
|
+
const authorJid = getStatusAuthorJid(status);
|
|
223
|
+
const statusJidList = await resolveStatusRecipients([authorJid]);
|
|
224
|
+
return socket.sendMessage(STATUS_JID, {
|
|
225
|
+
react: { text: assertReactionText(emoji), key }
|
|
226
|
+
}, { ...options, statusJidList });
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const viewStatus = async (status) => {
|
|
230
|
+
const key = await actionKeyFor(status, 'status');
|
|
231
|
+
return readMessages([key]);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const commentStatus = async (status, comment, options = {}) => {
|
|
235
|
+
const key = await actionKeyFor(status, 'status');
|
|
236
|
+
const authorJid = getStatusAuthorJid(status);
|
|
237
|
+
if (!(typeof comment === 'string' || (comment && typeof comment === 'object' && !Array.isArray(comment)))) {
|
|
238
|
+
throw new Boom('commentStatus content must be a string or message-content object', { statusCode: 400 });
|
|
239
|
+
}
|
|
240
|
+
const messageContent = typeof comment === 'string'
|
|
241
|
+
? { text: comment }
|
|
242
|
+
: comment.message && typeof comment.message === 'object'
|
|
243
|
+
? undefined
|
|
244
|
+
: comment;
|
|
245
|
+
if (typeof comment === 'string' && !comment.trim()) {
|
|
246
|
+
throw new Boom('commentStatus text cannot be empty', { statusCode: 400 });
|
|
247
|
+
}
|
|
248
|
+
const innerMessage = comment.message && typeof comment.message === 'object'
|
|
249
|
+
? comment.message
|
|
250
|
+
: await generateContent(messageContent, {
|
|
251
|
+
logger,
|
|
252
|
+
userJid: authState?.creds?.me?.id,
|
|
253
|
+
upload
|
|
254
|
+
});
|
|
255
|
+
return socket.sendMessage(authorJid, {
|
|
256
|
+
comment: { message: innerMessage, targetMessageKey: key }
|
|
257
|
+
}, options);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const downloadStatus = async (status, type = 'buffer', options = {}) => {
|
|
261
|
+
const kind = getStatusKind(status);
|
|
262
|
+
if (!kind) throw new Boom('downloadStatus requires a personal or group status message', { statusCode: 400 });
|
|
263
|
+
return downloadMedia(status, type, options);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const likeGroupStatus = async (status, emoji, options = {}) => {
|
|
267
|
+
const key = await actionKeyFor(status, 'group');
|
|
268
|
+
return socket.sendMessage(key.remoteJid, {
|
|
269
|
+
react: { text: assertReactionText(emoji), key }
|
|
270
|
+
}, options);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const viewGroupStatus = async (status) => {
|
|
274
|
+
const key = await actionKeyFor(status, 'group');
|
|
275
|
+
return readMessages([key]);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
onStatusMessage,
|
|
280
|
+
likeStatus,
|
|
281
|
+
viewStatus,
|
|
282
|
+
commentStatus,
|
|
283
|
+
downloadStatus,
|
|
284
|
+
likeGroupStatus,
|
|
285
|
+
viewGroupStatus
|
|
286
|
+
};
|
|
287
|
+
};
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/Socket/username.js
|
|
5
|
+
* About: Username module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: makeUsernameSocket
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { randomUUID } from 'crypto';
|
|
14
|
+
import { executeWMexQuery } from './mex.js';
|
|
15
|
+
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
16
|
+
import { makeNewsletterSocket } from './newsletter.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* w:mex query IDs for username operations.
|
|
20
|
+
*
|
|
21
|
+
* Source: whatsapp-android-mex_client_persist_ids.json (WA 2.26.26.4 APK assets)
|
|
22
|
+
* Cross-checked: live Frida capture on real device (wa-logger-2.26.26.4.js, 2026-06-30)
|
|
23
|
+
*/
|
|
24
|
+
const USERNAME_QUERY_IDS = {
|
|
25
|
+
CHECK: '26124072630599518', // UsernameCheck
|
|
26
|
+
CHECK_MULTI: '27134626522840286', // UsernameCheckMulti
|
|
27
|
+
SET: '27108705368767936', // UsernameSet
|
|
28
|
+
GET: '32618050064506055', // UsernameGet
|
|
29
|
+
GET_RECOMMENDATIONS: '26077456248616957', // UsernameGetRecommendationsQuery
|
|
30
|
+
PIN_SET: '25529696019976770' // UsernamePinSet
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Source enum values from EnumC141106Vn (UsernameCheck result)
|
|
35
|
+
* and EnumC141056Vi (rejection reasons) confirmed via C164057Wg.java
|
|
36
|
+
*/
|
|
37
|
+
const USERNAME_CHECK_RESULT = {
|
|
38
|
+
SUCCESS: 'SUCCESS',
|
|
39
|
+
INVALID: 'INVALID'
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const USERNAME_SOURCE = {
|
|
43
|
+
FB: 'FB',
|
|
44
|
+
IG: 'IG',
|
|
45
|
+
USER_INPUT: 'USER_INPUT',
|
|
46
|
+
SUGGESTION: 'SUGGESTION'
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const makeUsernameSocket = (config) => {
|
|
50
|
+
const sock = makeNewsletterSocket(config);
|
|
51
|
+
const { query, generateMessageTag, executeUSyncQuery } = sock;
|
|
52
|
+
|
|
53
|
+
const mexQuery = (variables, queryId, dataPath) =>
|
|
54
|
+
executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Check whether a username is available.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} username - The @username to check (without @)
|
|
60
|
+
* @param {boolean} includeSuggestions - Request alternative suggestions when taken
|
|
61
|
+
* @returns {object}
|
|
62
|
+
* On success: { available: true, username }
|
|
63
|
+
* On taken: { available: false, username, suggestions: string[], rejectionReasons: string[], suggestionsEligible: boolean }
|
|
64
|
+
* On rate-limit: throws Boom with statusCode 429
|
|
65
|
+
*
|
|
66
|
+
* Confirmed fields from C164057Wg.java:
|
|
67
|
+
* data.xwa2_username_check.result → 'SUCCESS' | 'INVALID'
|
|
68
|
+
* data.xwa2_username_check.suggestions
|
|
69
|
+
* data.xwa2_username_check.rejection_reasons
|
|
70
|
+
* data.xwa2_username_check.suggestions_eligible
|
|
71
|
+
*/
|
|
72
|
+
const checkUsername = async (username, includeSuggestions = true, sessionId) => {
|
|
73
|
+
// session_id ties this check to the subsequent set step — caller can pass one in
|
|
74
|
+
// so both use the same UUID (confirmed from live WA 2.26.26.4 capture).
|
|
75
|
+
const session_id = sessionId || randomUUID();
|
|
76
|
+
const data = await mexQuery(
|
|
77
|
+
{
|
|
78
|
+
username,
|
|
79
|
+
include_suggestions: includeSuggestions,
|
|
80
|
+
session_id,
|
|
81
|
+
source: USERNAME_SOURCE.USER_INPUT
|
|
82
|
+
},
|
|
83
|
+
USERNAME_QUERY_IDS.CHECK,
|
|
84
|
+
'xwa2_username_check'
|
|
85
|
+
);
|
|
86
|
+
if (data?.result === USERNAME_CHECK_RESULT.SUCCESS) {
|
|
87
|
+
return { available: true, username, session_id };
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
available: false,
|
|
91
|
+
username,
|
|
92
|
+
session_id,
|
|
93
|
+
suggestions: data?.suggestions ?? [],
|
|
94
|
+
rejectionReasons: data?.rejection_reasons ?? [],
|
|
95
|
+
suggestionsEligible: data?.suggestions_eligible ?? true
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Set your own username.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} username - The username to set (without @)
|
|
103
|
+
* @param {object} options
|
|
104
|
+
* @param {string} [options.source] - 'USER_INPUT' | 'FB' | 'IG' | 'SUGGESTION'
|
|
105
|
+
* @param {string} [options.sessionId] - Optional session tracking ID
|
|
106
|
+
* @param {string} [options.pin] - Optional PIN for protected usernames
|
|
107
|
+
*
|
|
108
|
+
* Confirmed variables from C1568872p.java A00():
|
|
109
|
+
* username, reserved (bool), session_id, source, pin
|
|
110
|
+
*/
|
|
111
|
+
const setUsername = async (username, options = {}) => {
|
|
112
|
+
const { source = USERNAME_SOURCE.USER_INPUT, sessionId, pin } = options;
|
|
113
|
+
// session_id links the check and set steps — generate one if caller doesn't supply it.
|
|
114
|
+
// reserved:true confirmed from live WA 2.26.26.4 capture (was wrongly false before).
|
|
115
|
+
const session_id = sessionId || randomUUID();
|
|
116
|
+
const variables = {
|
|
117
|
+
username,
|
|
118
|
+
reserved: true,
|
|
119
|
+
source,
|
|
120
|
+
session_id,
|
|
121
|
+
...(pin ? { pin } : {})
|
|
122
|
+
};
|
|
123
|
+
return mexQuery(variables, USERNAME_QUERY_IDS.SET, 'xwa2_username_set');
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Delete (unset) your own username.
|
|
128
|
+
*
|
|
129
|
+
* Confirmed from C1568872p.java:
|
|
130
|
+
* str4 = str == null ? "delete" : "set"
|
|
131
|
+
* → sending username=null triggers the delete path on the server.
|
|
132
|
+
*/
|
|
133
|
+
const deleteUsername = async () => {
|
|
134
|
+
return mexQuery({ username: null }, USERNAME_QUERY_IDS.SET, 'xwa2_username_delete');
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get your own current username.
|
|
139
|
+
*
|
|
140
|
+
* Confirmed from C1568872p.java A02():
|
|
141
|
+
* AbstractC41851rT.A0L(AbstractC130045pa.A0T(), C1363664w.class, "UsernameGet", false)
|
|
142
|
+
*/
|
|
143
|
+
const getMyUsername = async () => {
|
|
144
|
+
const data = await mexQuery({}, USERNAME_QUERY_IDS.GET, 'xwa2_username_get');
|
|
145
|
+
return data?.username ?? null;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Set or delete the PIN that protects your username.
|
|
150
|
+
*
|
|
151
|
+
* @param {string|null} pin - New PIN, or null to delete the PIN
|
|
152
|
+
*
|
|
153
|
+
* Confirmed from MexUsernamePinProtocolApi.java:
|
|
154
|
+
* operation "UsernamePinSet", variable "pin"
|
|
155
|
+
* pin=null triggers the "delete" path on the server.
|
|
156
|
+
*/
|
|
157
|
+
const setUsernamePin = async (pin) => {
|
|
158
|
+
// pin=null → delete PIN (server interprets empty/null variables as delete)
|
|
159
|
+
const variables = pin != null ? { pin } : {};
|
|
160
|
+
return mexQuery(variables, USERNAME_QUERY_IDS.PIN_SET, 'xwa2_username_pin_set');
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Look up a contact by their @username via USync.
|
|
165
|
+
*
|
|
166
|
+
* Confirmed via USyncContactProtocol.getUserElement():
|
|
167
|
+
* { tag: 'contact', attrs: { username, pin? } }
|
|
168
|
+
*
|
|
169
|
+
* @param {string} username - The username to look up (without @)
|
|
170
|
+
* @param {string} [pin] - Optional PIN if the username is PIN-protected
|
|
171
|
+
* @returns {{ jid, lid?, contact: boolean }|null}
|
|
172
|
+
*/
|
|
173
|
+
const findUserByUsername = async (username, pin) => {
|
|
174
|
+
const usyncQuery = new USyncQuery().withContactProtocol();
|
|
175
|
+
const user = new USyncUser().withUsername(username);
|
|
176
|
+
if (pin) user.withUsernameKey(pin);
|
|
177
|
+
usyncQuery.withUser(user);
|
|
178
|
+
const result = await executeUSyncQuery(usyncQuery);
|
|
179
|
+
if (!result?.list?.length) return null;
|
|
180
|
+
const entry = result.list[0];
|
|
181
|
+
return {
|
|
182
|
+
jid: entry.id,
|
|
183
|
+
contact: entry.contact ?? false
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Fetch the username of one or more contacts by their JID.
|
|
189
|
+
* Uses USync with the username protocol.
|
|
190
|
+
*
|
|
191
|
+
* @param {...string} jids - One or more JIDs
|
|
192
|
+
* @returns {Array<{ id, username: string|null }>}
|
|
193
|
+
*/
|
|
194
|
+
const fetchContactUsernames = async (...jids) => {
|
|
195
|
+
const usyncQuery = new USyncQuery().withUsernameProtocol();
|
|
196
|
+
for (const jid of jids) {
|
|
197
|
+
usyncQuery.withUser(new USyncUser().withId(jid));
|
|
198
|
+
}
|
|
199
|
+
const result = await executeUSyncQuery(usyncQuery);
|
|
200
|
+
return result?.list ?? [];
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Check multiple usernames for availability at once.
|
|
205
|
+
* @param {string[]} usernames - Array of usernames (without @)
|
|
206
|
+
*/
|
|
207
|
+
const checkUsernameMulti = async (usernames) => {
|
|
208
|
+
const data = await mexQuery(
|
|
209
|
+
{ usernames },
|
|
210
|
+
USERNAME_QUERY_IDS.CHECK_MULTI,
|
|
211
|
+
'xwa2_username_check_multi'
|
|
212
|
+
);
|
|
213
|
+
return data;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Fetch username recommendations for the current user.
|
|
218
|
+
* @param {string} [source] - Source hint: 'FB' | 'IG' | 'USER_INPUT'
|
|
219
|
+
*/
|
|
220
|
+
const getUsernameRecommendations = async (source = null) => {
|
|
221
|
+
const variables = {};
|
|
222
|
+
if (source) variables.source = source;
|
|
223
|
+
return mexQuery(variables, USERNAME_QUERY_IDS.GET_RECOMMENDATIONS, 'xwa2_username_get_recommendations');
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
...sock,
|
|
228
|
+
checkUsername,
|
|
229
|
+
checkUsernameMulti,
|
|
230
|
+
setUsername,
|
|
231
|
+
deleteUsername,
|
|
232
|
+
getMyUsername,
|
|
233
|
+
getUsernameRecommendations,
|
|
234
|
+
setUsernamePin,
|
|
235
|
+
findUserByUsername,
|
|
236
|
+
fetchContactUsernames,
|
|
237
|
+
USERNAME_QUERY_IDS,
|
|
238
|
+
USERNAME_CHECK_RESULT,
|
|
239
|
+
USERNAME_SOURCE
|
|
240
|
+
};
|
|
241
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/Store/index.js
|
|
5
|
+
* About: Store module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: No public exports detected; module side effects or declarations are local.
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
export * from './make-cache-manager-store.js';
|
|
14
|
+
export * from './make-in-memory-store.js';
|
|
15
|
+
export * from './make-ordered-dictionary.js';
|
|
16
|
+
export * from './object-repository.js';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/Store/make-cache-manager-store.js
|
|
5
|
+
* About: Make cache manager store module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: makeCacheManagerAuthState
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { createCache } from 'cache-manager';
|
|
14
|
+
import { proto } from '../../WAProto/index.js';
|
|
15
|
+
import { BufferJSON, initAuthCreds } from '../Utils/index.js';
|
|
16
|
+
import logger from '../Utils/logger.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Cache-manager backed auth state.
|
|
20
|
+
*
|
|
21
|
+
* `store` accepts anything cache-manager v7's createCache({ stores: [...] }) accepts:
|
|
22
|
+
* a Keyv-compatible store instance (e.g. keyv/redis, keyv/sqlite) or a store factory.
|
|
23
|
+
* Keys are namespaced under `${sessionKey}:` so multiple sessions can share one store.
|
|
24
|
+
*/
|
|
25
|
+
export const makeCacheManagerAuthState = async (store, sessionKey) => {
|
|
26
|
+
const defaultKey = file => `${sessionKey}:${file}`;
|
|
27
|
+
const databaseConn = createCache({ stores: [store], ttl: 0 });
|
|
28
|
+
const writeData = async (file, data) => {
|
|
29
|
+
let ttl = undefined;
|
|
30
|
+
if (file === 'creds') {
|
|
31
|
+
ttl = 63115200; // 2 years
|
|
32
|
+
}
|
|
33
|
+
await databaseConn.set(defaultKey(file), JSON.stringify(data, BufferJSON.replacer), ttl);
|
|
34
|
+
};
|
|
35
|
+
const readData = async (file) => {
|
|
36
|
+
try {
|
|
37
|
+
const data = await databaseConn.get(defaultKey(file));
|
|
38
|
+
if (data) {
|
|
39
|
+
return JSON.parse(data, BufferJSON.reviver);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
logger.error(error);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const removeData = async (file) => {
|
|
49
|
+
try {
|
|
50
|
+
return await databaseConn.del(defaultKey(file));
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
logger.error({ err }, `Error removing ${file} from session ${sessionKey}`);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const clearState = async () => {
|
|
57
|
+
try {
|
|
58
|
+
// Keyv-compatible stores expose keys(pattern); tolerate stores that don't.
|
|
59
|
+
const keyed = typeof store?.keys === 'function' ? store : databaseConn;
|
|
60
|
+
const keys = typeof keyed.keys === 'function' ? await keyed.keys(`${sessionKey}*`) : [];
|
|
61
|
+
await Promise.all(keys.map(async key => await databaseConn.del(key)));
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
logger.warn({ err }, 'clearState failed');
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const creds = (await readData('creds')) || initAuthCreds();
|
|
68
|
+
return {
|
|
69
|
+
clearState,
|
|
70
|
+
saveCreds: () => writeData('creds', creds),
|
|
71
|
+
state: {
|
|
72
|
+
creds,
|
|
73
|
+
keys: {
|
|
74
|
+
get: async (type, ids) => {
|
|
75
|
+
const data = {};
|
|
76
|
+
await Promise.all(
|
|
77
|
+
ids.map(async id => {
|
|
78
|
+
let value = await readData(`${type}-${id}`);
|
|
79
|
+
if (type === 'app-state-sync-key' && value) {
|
|
80
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
81
|
+
}
|
|
82
|
+
data[id] = value;
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
return data;
|
|
86
|
+
},
|
|
87
|
+
set: async (data) => {
|
|
88
|
+
const tasks = [];
|
|
89
|
+
for (const category in data) {
|
|
90
|
+
for (const id in data[category]) {
|
|
91
|
+
const value = data[category][id];
|
|
92
|
+
const key = `${category}-${id}`;
|
|
93
|
+
tasks.push(value ? writeData(key, value) : removeData(key));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
await Promise.all(tasks);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
};
|