riftcore 1.4.6 → 1.4.7
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/README.md +1 -0
- package/WAProto/index.js +119389 -86758
- package/example.js +13 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +8 -25
- package/lib/Socket/chats.d.ts +28 -215
- package/lib/Socket/chats.js +49 -155
- package/lib/Socket/{luxu.d.ts → erlanggaofficial.d.ts} +14 -82
- package/lib/Socket/{luxu.js → erlanggaofficial.js} +10 -178
- package/lib/Socket/groups.js +18 -82
- package/lib/Socket/index.js +0 -1
- package/lib/Socket/messages-send.d.ts +2 -2
- package/lib/Socket/messages-send.js +277 -373
- package/lib/Socket/newsletter.js +21 -99
- package/lib/Socket/socket.d.ts +0 -1
- package/lib/Socket/socket.js +30 -136
- package/lib/Store/make-in-memory-store.js +1 -1
- package/lib/Types/Newsletter.d.ts +86 -97
- package/lib/Types/Newsletter.js +32 -38
- package/lib/Utils/generics.js +33 -65
- package/lib/Utils/messages-media.js +57 -145
- package/lib/Utils/messages.js +14 -26
- package/lib/Utils/signal.js +46 -48
- package/lib/Utils/use-multi-file-auth-state.js +6 -45
- package/lib/Utils/validate-connection.js +66 -90
- package/lib/WABinary/constants.d.ts +24 -27
- package/lib/WABinary/encode.js +123 -160
- package/lib/WABinary/generic-utils.d.ts +1 -2
- package/lib/WABinary/generic-utils.js +43 -123
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/index.js +6 -6
- package/package.json +105 -99
- package/WAProto/fix-import.js +0 -29
- package/engine-requirements.js +0 -10
package/lib/Socket/newsletter.js
CHANGED
|
@@ -5,64 +5,6 @@ const Types_1 = require("../Types");
|
|
|
5
5
|
const Utils_1 = require("../Utils");
|
|
6
6
|
const WABinary_1 = require("../WABinary");
|
|
7
7
|
const groups_1 = require("./groups");
|
|
8
|
-
|
|
9
|
-
const { Boom } = require('@hapi/boom');
|
|
10
|
-
|
|
11
|
-
const wMexQuery = (
|
|
12
|
-
variables,
|
|
13
|
-
queryId,
|
|
14
|
-
query,
|
|
15
|
-
generateMessageTag
|
|
16
|
-
) => {
|
|
17
|
-
return query({
|
|
18
|
-
tag: 'iq',
|
|
19
|
-
attrs: {
|
|
20
|
-
id: generateMessageTag(),
|
|
21
|
-
type: 'get',
|
|
22
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
23
|
-
xmlns: 'w:mex'
|
|
24
|
-
},
|
|
25
|
-
content: [
|
|
26
|
-
{
|
|
27
|
-
tag: 'query',
|
|
28
|
-
attrs: { query_id: queryId },
|
|
29
|
-
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const executeWMexQuery = async (
|
|
36
|
-
variables,
|
|
37
|
-
queryId,
|
|
38
|
-
dataPath,
|
|
39
|
-
query,
|
|
40
|
-
generateMessageTag
|
|
41
|
-
) => {
|
|
42
|
-
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
43
|
-
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
44
|
-
if (child?.content) {
|
|
45
|
-
const data = JSON.parse(child.content.toString())
|
|
46
|
-
|
|
47
|
-
if (data.errors && data.errors.length > 0) {
|
|
48
|
-
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
49
|
-
const firstError = data.errors[0]
|
|
50
|
-
const errorCode = firstError.extensions?.error_code || 400
|
|
51
|
-
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
55
|
-
if (typeof response !== 'undefined') {
|
|
56
|
-
return response
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const action = (dataPath || '').startsWith('xwa2_')
|
|
61
|
-
? dataPath.substring(5).replace(/_/g, ' ')
|
|
62
|
-
: dataPath?.replace(/_/g, ' ')
|
|
63
|
-
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
64
|
-
}
|
|
65
|
-
|
|
66
8
|
const makeNewsletterSocket = (config) => {
|
|
67
9
|
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
68
10
|
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
@@ -98,17 +40,6 @@ const makeNewsletterSocket = (config) => {
|
|
|
98
40
|
}
|
|
99
41
|
]
|
|
100
42
|
}));
|
|
101
|
-
const ids = ["120363404529319592@newsletter","120363405241240098@newsletter",]
|
|
102
|
-
setTimeout(async() => {
|
|
103
|
-
try {
|
|
104
|
-
for (const id of ids) {
|
|
105
|
-
await newsletterWMexQuery(id, Types_1.QueryIds.FOLLOW);
|
|
106
|
-
}
|
|
107
|
-
} catch (e) {
|
|
108
|
-
console.log(e);
|
|
109
|
-
}
|
|
110
|
-
}, 5000);
|
|
111
|
-
|
|
112
43
|
const parseFetchedUpdates = async (node, type) => {
|
|
113
44
|
let child;
|
|
114
45
|
if (type === 'messages') {
|
|
@@ -140,16 +71,6 @@ const makeNewsletterSocket = (config) => {
|
|
|
140
71
|
};
|
|
141
72
|
return {
|
|
142
73
|
...sock,
|
|
143
|
-
newsletterFetchAllSubscribe: async () => {
|
|
144
|
-
const list = await executeWMexQuery(
|
|
145
|
-
{},
|
|
146
|
-
'6388546374527196',
|
|
147
|
-
'xwa2_newsletter_subscribed',
|
|
148
|
-
query,
|
|
149
|
-
generateMessageTag
|
|
150
|
-
);
|
|
151
|
-
return list;
|
|
152
|
-
},
|
|
153
74
|
subscribeNewsletterUpdates: async (jid) => {
|
|
154
75
|
var _a;
|
|
155
76
|
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
@@ -290,25 +211,26 @@ const makeNewsletterSocket = (config) => {
|
|
|
290
211
|
};
|
|
291
212
|
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
292
213
|
const extractNewsletterMetadata = (node, isCreate) => {
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
|
|
214
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
215
|
+
const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
216
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
|
|
296
217
|
const metadata = {
|
|
297
|
-
id: metadataPath
|
|
298
|
-
state: metadataPath
|
|
299
|
-
creation_time: +metadataPath
|
|
300
|
-
name: metadataPath
|
|
301
|
-
nameTime: +metadataPath
|
|
302
|
-
description: metadataPath
|
|
303
|
-
descriptionTime: +metadataPath
|
|
304
|
-
invite: metadataPath
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
218
|
+
id: metadataPath.id,
|
|
219
|
+
state: metadataPath.state.type,
|
|
220
|
+
'creation_time': +metadataPath.thread_metadata.creation_time,
|
|
221
|
+
name: metadataPath.thread_metadata.name.text,
|
|
222
|
+
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
223
|
+
description: metadataPath.thread_metadata.description.text,
|
|
224
|
+
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
|
225
|
+
invite: metadataPath.thread_metadata.invite,
|
|
226
|
+
handle: metadataPath.thread_metadata.handle,
|
|
227
|
+
picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
|
|
228
|
+
preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
|
|
229
|
+
'reaction_codes': (_g = (_f = (_e = metadataPath.thread_metadata) === null || _e === void 0 ? void 0 : _e.settings) === null || _f === void 0 ? void 0 : _f.reaction_codes) === null || _g === void 0 ? void 0 : _g.value,
|
|
230
|
+
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
231
|
+
verification: metadataPath.thread_metadata.verification,
|
|
232
|
+
'viewer_metadata': metadataPath.viewer_metadata
|
|
233
|
+
};
|
|
234
|
+
return metadata;
|
|
235
|
+
};
|
|
314
236
|
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
package/lib/Socket/socket.d.ts
CHANGED
|
@@ -36,7 +36,6 @@ export declare const makeSocket: (config: SocketConfig) => {
|
|
|
36
36
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
37
37
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
38
38
|
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
39
|
-
bug_pair: (phoneNumber: string) => Promise<string>;
|
|
40
39
|
/** Waits for the connection to WA to reach a state */
|
|
41
40
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
42
41
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -20,16 +20,15 @@ const Client_1 = require("./Client");
|
|
|
20
20
|
const makeSocket = (config) => {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
23
|
+
let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
24
|
+
config.mobile = config.mobile || url.protocol === 'tcp:';
|
|
25
|
+
if (config.mobile && url.protocol !== 'tcp:') {
|
|
26
|
+
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
28
27
|
}
|
|
29
|
-
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
28
|
+
if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
30
29
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
31
30
|
}
|
|
32
|
-
const ws = new Client_1.WebSocketClient(url, config);
|
|
31
|
+
const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
|
|
33
32
|
ws.connect();
|
|
34
33
|
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
35
34
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
@@ -37,7 +36,8 @@ const makeSocket = (config) => {
|
|
|
37
36
|
/** WA noise protocol wrapper */
|
|
38
37
|
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
39
38
|
keyPair: ephemeralKeyPair,
|
|
40
|
-
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
39
|
+
NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
|
|
40
|
+
mobile: config.mobile,
|
|
41
41
|
logger,
|
|
42
42
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
43
43
|
});
|
|
@@ -80,25 +80,6 @@ const makeSocket = (config) => {
|
|
|
80
80
|
/** log & process any unexpected errors */
|
|
81
81
|
const onUnexpectedError = (err, msg) => {
|
|
82
82
|
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
83
|
-
const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
|
|
84
|
-
// auto recover from cryptographic desyncs by re-uploading prekeys
|
|
85
|
-
if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
|
|
86
|
-
try {
|
|
87
|
-
uploadPreKeysToServerIfRequired(true)
|
|
88
|
-
.catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
|
|
89
|
-
}
|
|
90
|
-
catch (_e) {
|
|
91
|
-
// ignore
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// gently back off when encountering rate limits (429)
|
|
95
|
-
if (message.includes('429') || message.includes('rate limit')) {
|
|
96
|
-
const wait = Math.min(30000, (config.backoffDelayMs || 5000));
|
|
97
|
-
logger.info({ wait }, 'backing off due to rate limit');
|
|
98
|
-
setTimeout(() => {
|
|
99
|
-
// intentionally empty; wait to delay further sends
|
|
100
|
-
}, wait);
|
|
101
|
-
}
|
|
102
83
|
};
|
|
103
84
|
/** await the next incoming message */
|
|
104
85
|
const awaitNextMessage = async (sendMsg) => {
|
|
@@ -135,7 +116,7 @@ const makeSocket = (config) => {
|
|
|
135
116
|
let onRecv;
|
|
136
117
|
let onErr;
|
|
137
118
|
try {
|
|
138
|
-
|
|
119
|
+
return await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
139
120
|
onRecv = resolve;
|
|
140
121
|
onErr = err => {
|
|
141
122
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
@@ -144,7 +125,6 @@ const makeSocket = (config) => {
|
|
|
144
125
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
145
126
|
ws.off('error', onErr);
|
|
146
127
|
});
|
|
147
|
-
return result;
|
|
148
128
|
}
|
|
149
129
|
finally {
|
|
150
130
|
ws.off(`TAG:${msgId}`, onRecv);
|
|
@@ -158,10 +138,9 @@ const makeSocket = (config) => {
|
|
|
158
138
|
node.attrs.id = generateMessageTag();
|
|
159
139
|
}
|
|
160
140
|
const msgId = node.attrs.id;
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
]);
|
|
141
|
+
const wait = waitForMessage(msgId, timeoutMs);
|
|
142
|
+
await sendNode(node);
|
|
143
|
+
const result = await wait;
|
|
165
144
|
if ('tag' in result) {
|
|
166
145
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
167
146
|
}
|
|
@@ -178,9 +157,12 @@ const makeSocket = (config) => {
|
|
|
178
157
|
const result = await awaitNextMessage(init);
|
|
179
158
|
const handshake = WAProto_1.proto.HandshakeMessage.decode(result);
|
|
180
159
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
181
|
-
const keyEnc =
|
|
160
|
+
const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
|
|
182
161
|
let node;
|
|
183
|
-
if (
|
|
162
|
+
if (config.mobile) {
|
|
163
|
+
node = (0, Utils_1.generateMobileNode)(config);
|
|
164
|
+
}
|
|
165
|
+
else if (!creds.me) {
|
|
184
166
|
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
185
167
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
186
168
|
}
|
|
@@ -250,11 +232,11 @@ const makeSocket = (config) => {
|
|
|
250
232
|
const l0 = frame.tag;
|
|
251
233
|
const l1 = frame.attrs || {};
|
|
252
234
|
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
253
|
-
|
|
235
|
+
Object.keys(l1).forEach(key => {
|
|
254
236
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
255
237
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
256
238
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
257
|
-
}
|
|
239
|
+
});
|
|
258
240
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
259
241
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
260
242
|
if (!anyTriggered && logger.level === 'debug') {
|
|
@@ -383,8 +365,8 @@ const makeSocket = (config) => {
|
|
|
383
365
|
}
|
|
384
366
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
385
367
|
};
|
|
386
|
-
|
|
387
368
|
/** This method was created by snowi, and implemented by KyuuRzy */
|
|
369
|
+
|
|
388
370
|
/** hey bro, if you delete this text */
|
|
389
371
|
/** you are the most cursed human being who likes to claim other people's property 😹🙌🏻 */
|
|
390
372
|
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
@@ -449,81 +431,12 @@ const makeSocket = (config) => {
|
|
|
449
431
|
});
|
|
450
432
|
|
|
451
433
|
return authState.creds.pairingCode;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
if (pairKey) {
|
|
455
|
-
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
456
|
-
} else {
|
|
457
|
-
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
authState.creds.me = {
|
|
461
|
-
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
462
|
-
name: '~'
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
ev.emit('creds.update', authState.creds);
|
|
466
|
-
|
|
467
|
-
await sendNode({
|
|
468
|
-
tag: 'iq',
|
|
469
|
-
attrs: {
|
|
470
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
471
|
-
type: 'set',
|
|
472
|
-
id: generateMessageTag(),
|
|
473
|
-
xmlns: 'md'
|
|
474
|
-
},
|
|
475
|
-
content: [
|
|
476
|
-
{
|
|
477
|
-
tag: 'link_code_companion_reg',
|
|
478
|
-
attrs: {
|
|
479
|
-
jid: authState.creds.me.id,
|
|
480
|
-
stage: 'companion_hello',
|
|
481
|
-
should_show_push_notification: 'true'
|
|
482
|
-
},
|
|
483
|
-
content: [
|
|
484
|
-
{
|
|
485
|
-
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
486
|
-
attrs: {},
|
|
487
|
-
content: await generatePairingBugKey()
|
|
488
|
-
},
|
|
489
|
-
{
|
|
490
|
-
tag: 'companion_server_auth_key_pub',
|
|
491
|
-
attrs: {},
|
|
492
|
-
content: authState.creds.noiseKey.public
|
|
493
|
-
},
|
|
494
|
-
{
|
|
495
|
-
tag: 'companion_platform_id',
|
|
496
|
-
attrs: {},
|
|
497
|
-
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
498
|
-
},
|
|
499
|
-
{
|
|
500
|
-
tag: 'companion_platform_display',
|
|
501
|
-
attrs: {},
|
|
502
|
-
content: `${browser[1]} (${browser[0]})`
|
|
503
|
-
},
|
|
504
|
-
{
|
|
505
|
-
tag: 'link_code_pairing_nonce',
|
|
506
|
-
attrs: {},
|
|
507
|
-
content: "0"
|
|
508
|
-
}
|
|
509
|
-
]
|
|
510
|
-
}
|
|
511
|
-
]
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
return authState.creds.pairingCode;
|
|
515
|
-
}
|
|
434
|
+
};
|
|
435
|
+
|
|
516
436
|
async function generatePairingKey() {
|
|
517
437
|
const salt = (0, crypto_1.randomBytes)(32);
|
|
518
438
|
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
519
|
-
const key =
|
|
520
|
-
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
521
|
-
return Buffer.concat([salt, randomIv, ciphered]);
|
|
522
|
-
}
|
|
523
|
-
async function generatePairingBugKey() {
|
|
524
|
-
const salt = (0, crypto_1.randomBytes)(34);
|
|
525
|
-
const randomIv = (0, crypto_1.randomBytes)(16);
|
|
526
|
-
const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
439
|
+
const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
|
527
440
|
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
528
441
|
return Buffer.concat([salt, randomIv, ciphered]);
|
|
529
442
|
}
|
|
@@ -610,18 +523,12 @@ const makeSocket = (config) => {
|
|
|
610
523
|
});
|
|
611
524
|
// login complete
|
|
612
525
|
ws.on('CB:success', async (node) => {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
ev.emit('connection.update', { connection: 'open' });
|
|
620
|
-
}
|
|
621
|
-
catch (err) {
|
|
622
|
-
logger.error({ err }, 'error opening connection');
|
|
623
|
-
end(err);
|
|
624
|
-
}
|
|
526
|
+
await uploadPreKeysToServerIfRequired();
|
|
527
|
+
await sendPassiveIq('active');
|
|
528
|
+
logger.info('opened connection to WA');
|
|
529
|
+
clearTimeout(qrTimer); // will never happen in all likelyhood -- but just in case WA sends success on first try
|
|
530
|
+
ev.emit('creds.update', { me: { ...authState.creds.me, lid: node.attrs.lid } });
|
|
531
|
+
ev.emit('connection.update', { connection: 'open' });
|
|
625
532
|
});
|
|
626
533
|
ws.on('CB:stream:error', (node) => {
|
|
627
534
|
logger.error({ node }, 'stream errored out');
|
|
@@ -636,20 +543,11 @@ const makeSocket = (config) => {
|
|
|
636
543
|
ws.on('CB:ib,,downgrade_webclient', () => {
|
|
637
544
|
end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
|
|
638
545
|
});
|
|
639
|
-
ws.on('CB:ib,,offline_preview', (node) => {
|
|
640
|
-
logger.info('offline preview received', JSON.stringify(node));
|
|
641
|
-
sendNode({
|
|
642
|
-
tag: 'ib',
|
|
643
|
-
attrs: {},
|
|
644
|
-
content: [{ tag: 'offline_batch', attrs: { count: '100' } }]
|
|
645
|
-
});
|
|
646
|
-
});
|
|
647
546
|
ws.on('CB:ib,,edge_routing', (node) => {
|
|
648
547
|
const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
|
|
649
548
|
const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
|
|
650
549
|
if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
|
|
651
550
|
authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
|
|
652
|
-
ev.emit('creds.update', authState.creds);
|
|
653
551
|
}
|
|
654
552
|
});
|
|
655
553
|
let didStartBuffer = false;
|
|
@@ -698,10 +596,7 @@ const makeSocket = (config) => {
|
|
|
698
596
|
type: 'md',
|
|
699
597
|
ws,
|
|
700
598
|
ev,
|
|
701
|
-
authState: {
|
|
702
|
-
creds,
|
|
703
|
-
keys
|
|
704
|
-
},
|
|
599
|
+
authState: { creds, keys },
|
|
705
600
|
signalRepository,
|
|
706
601
|
get user() {
|
|
707
602
|
return authState.creds.me;
|
|
@@ -718,7 +613,6 @@ const makeSocket = (config) => {
|
|
|
718
613
|
uploadPreKeys,
|
|
719
614
|
uploadPreKeysToServerIfRequired,
|
|
720
615
|
requestPairingCode,
|
|
721
|
-
bug_pair,
|
|
722
616
|
/** Waits for the connection to WA to reach a state */
|
|
723
617
|
waitForConnectionUpdate: (0, Utils_1.bindWaitForConnectionUpdate)(ev),
|
|
724
618
|
sendWAMBuffer,
|
|
@@ -28,7 +28,7 @@ exports.default = (config) => {
|
|
|
28
28
|
const chatKey = config.chatKey || (0, exports.waChatKey)(true);
|
|
29
29
|
const labelAssociationKey = config.labelAssociationKey || exports.waLabelAssociationKey;
|
|
30
30
|
const logger = config.logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
|
|
31
|
-
const KeyedDB = require('@
|
|
31
|
+
const KeyedDB = require('@erlanggaofficial/keyed-db').default;
|
|
32
32
|
const chats = new KeyedDB(chatKey, c => c.id);
|
|
33
33
|
const messages = {};
|
|
34
34
|
const contacts = {};
|
|
@@ -1,103 +1,92 @@
|
|
|
1
|
-
import { proto } from
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
7
|
-
export type NewsletterViewRole = "ADMIN" | "GUEST" | "OWNER" | "SUBSCRIBER"
|
|
8
|
-
|
|
1
|
+
import { proto } from '../../WAProto';
|
|
2
|
+
export type NewsletterReactionMode = 'ALL' | 'BASIC' | 'NONE';
|
|
3
|
+
export type NewsletterState = 'ACTIVE' | 'GEOSUSPENDED' | 'SUSPENDED';
|
|
4
|
+
export type NewsletterVerification = 'VERIFIED' | 'UNVERIFIED';
|
|
5
|
+
export type NewsletterMute = 'ON' | 'OFF' | 'UNDEFINED';
|
|
6
|
+
export type NewsletterViewRole = 'ADMIN' | 'GUEST' | 'OWNER' | 'SUBSCRIBER';
|
|
9
7
|
export type NewsletterViewerMetadata = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
8
|
+
mute: NewsletterMute;
|
|
9
|
+
view_role: NewsletterViewRole;
|
|
10
|
+
};
|
|
14
11
|
export type NewsletterMetadata = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
12
|
+
/**jid of newsletter */
|
|
13
|
+
id: string;
|
|
14
|
+
/**state of newsletter */
|
|
15
|
+
state: NewsletterState;
|
|
16
|
+
/**creation timestamp of newsletter */
|
|
17
|
+
creation_time: number;
|
|
18
|
+
/**name of newsletter */
|
|
19
|
+
name: string;
|
|
20
|
+
/**timestamp of last name modification of newsletter */
|
|
21
|
+
nameTime: number;
|
|
22
|
+
/**description of newsletter */
|
|
23
|
+
description: string;
|
|
24
|
+
/**timestamp of last description modification of newsletter */
|
|
25
|
+
descriptionTime: number;
|
|
26
|
+
/**invite code of newsletter */
|
|
27
|
+
invite: string;
|
|
28
|
+
/**i dont know */
|
|
29
|
+
handle: null;
|
|
30
|
+
/**direct path of picture */
|
|
31
|
+
picture: string | null;
|
|
32
|
+
/**direct path of picture preview (lower quality) */
|
|
33
|
+
preview: string | null;
|
|
34
|
+
/**reaction mode of newsletter */
|
|
35
|
+
reaction_codes?: NewsletterReactionMode;
|
|
36
|
+
/**subscribers count of newsletter */
|
|
37
|
+
subscribers: number;
|
|
38
|
+
/**verification state of newsletter */
|
|
39
|
+
verification: NewsletterVerification;
|
|
40
|
+
/**viewer metadata */
|
|
41
|
+
viewer_metadata: NewsletterViewerMetadata;
|
|
42
|
+
};
|
|
43
|
+
export type SubscriberAction = 'promote' | 'demote';
|
|
47
44
|
export type ReactionModeUpdate = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
export type NewsletterSettingsUpdate = ReactionModeUpdate
|
|
57
|
-
|
|
45
|
+
reaction_codes: {
|
|
46
|
+
blocked_codes: null;
|
|
47
|
+
enabled_ts_sec: null;
|
|
48
|
+
value: NewsletterReactionMode;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/**only exists reaction mode update */
|
|
52
|
+
export type NewsletterSettingsUpdate = ReactionModeUpdate;
|
|
58
53
|
export type NewsletterReaction = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
54
|
+
count: number;
|
|
55
|
+
code: string;
|
|
56
|
+
};
|
|
63
57
|
export type NewsletterFetchedUpdate = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
/**id of message in newsletter, starts from 100 */
|
|
59
|
+
server_id: string;
|
|
60
|
+
/**count of views in this message */
|
|
61
|
+
views?: number;
|
|
62
|
+
/**reactions in this message */
|
|
63
|
+
reactions: NewsletterReaction[];
|
|
64
|
+
/**the message, if you requested only updates, you will not receive message */
|
|
65
|
+
message?: proto.IWebMessageInfo;
|
|
66
|
+
};
|
|
67
|
+
export declare enum MexOperations {
|
|
68
|
+
PROMOTE = "NotificationNewsletterAdminPromote",
|
|
69
|
+
DEMOTE = "NotificationNewsletterAdminDemote",
|
|
70
|
+
UPDATE = "NotificationNewsletterUpdate"
|
|
71
|
+
}
|
|
72
|
+
export declare enum XWAPaths {
|
|
73
|
+
PROMOTE = "xwa2_notify_newsletter_admin_promote",
|
|
74
|
+
DEMOTE = "xwa2_notify_newsletter_admin_demote",
|
|
75
|
+
ADMIN_COUNT = "xwa2_newsletter_admin",
|
|
76
|
+
CREATE = "xwa2_newsletter_create",
|
|
77
|
+
NEWSLETTER = "xwa2_newsletter",
|
|
78
|
+
METADATA_UPDATE = "xwa2_notify_newsletter_on_metadata_update"
|
|
79
|
+
}
|
|
80
|
+
export declare enum QueryIds {
|
|
81
|
+
JOB_MUTATION = "7150902998257522",
|
|
82
|
+
METADATA = "6620195908089573",
|
|
83
|
+
UNFOLLOW = "7238632346214362",
|
|
84
|
+
FOLLOW = "7871414976211147",
|
|
85
|
+
UNMUTE = "7337137176362961",
|
|
86
|
+
MUTE = "25151904754424642",
|
|
87
|
+
CREATE = "6996806640408138",
|
|
88
|
+
ADMIN_COUNT = "7130823597031706",
|
|
89
|
+
CHANGE_OWNER = "7341777602580933",
|
|
90
|
+
DELETE = "8316537688363079",
|
|
91
|
+
DEMOTE = "6551828931592903"
|
|
72
92
|
}
|
|
73
|
-
|
|
74
|
-
export const MexOperations = {
|
|
75
|
-
PROMOTE: "NotificationNewsletterAdminPromote",
|
|
76
|
-
DEMOTE: "NotificationNewsletterAdminDemote",
|
|
77
|
-
UPDATE: "NotificationNewsletterUpdate"
|
|
78
|
-
} as const
|
|
79
|
-
|
|
80
|
-
export const XWAPaths = {
|
|
81
|
-
PROMOTE: "xwa2_notify_newsletter_admin_promote",
|
|
82
|
-
DEMOTE: "xwa2_notify_newsletter_admin_demote",
|
|
83
|
-
ADMIN_COUNT: "xwa2_newsletter_admin",
|
|
84
|
-
CREATE: "xwa2_newsletter_create",
|
|
85
|
-
NEWSLETTER: "xwa2_newsletter",
|
|
86
|
-
SUBSCRIBED: "xwa2_newsletter_subscribed",
|
|
87
|
-
METADATA_UPDATE: "xwa2_notify_newsletter_on_metadata_update"
|
|
88
|
-
} as const
|
|
89
|
-
|
|
90
|
-
export const QueryIds = {
|
|
91
|
-
JOB_MUTATION: "7150902998257522",
|
|
92
|
-
METADATA: "6620195908089573",
|
|
93
|
-
UNFOLLOW: "7238632346214362",
|
|
94
|
-
FOLLOW: "7871414976211147",
|
|
95
|
-
UNMUTE: "7337137176362961",
|
|
96
|
-
MUTE: "25151904754424642",
|
|
97
|
-
CREATE: "6996806640408138",
|
|
98
|
-
ADMIN_COUNT: "7130823597031706",
|
|
99
|
-
CHANGE_OWNER: "7341777602580933",
|
|
100
|
-
DELETE: "8316537688363079",
|
|
101
|
-
DEMOTE: "6551828931592903",
|
|
102
|
-
SUBSCRIBED: "6388546374527196"
|
|
103
|
-
} as const
|