@rexxhayanasi/elaina-baileys 1.0.9 → 1.1.0-DEV.2
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 +55 -14
- package/WAProto/WAProto.proto +1013 -169
- package/lib/Auth/index.js +8 -0
- package/lib/Auth/sqlite.js +57 -0
- package/lib/Socket/Rhandler.js +158 -240
- package/lib/Socket/business.js +6 -1
- package/lib/Socket/chats.js +96 -44
- package/lib/Socket/index.js +35 -9
- package/lib/Socket/messages-send.js +13 -11
- package/lib/Socket/newsletter.js +36 -0
- package/lib/Socket/socket.js +160 -98
- package/lib/index.js +1 -0
- package/package.json +4 -3
package/lib/Socket/chats.js
CHANGED
|
@@ -24,7 +24,14 @@ const SyncState = {
|
|
|
24
24
|
Online: 'online'
|
|
25
25
|
};
|
|
26
26
|
const makeChatsSocket = (config) => {
|
|
27
|
-
const
|
|
27
|
+
const {
|
|
28
|
+
logger,
|
|
29
|
+
markOnlineOnConnect,
|
|
30
|
+
fireInitQueries,
|
|
31
|
+
appStateMacVerification,
|
|
32
|
+
shouldIgnoreJid,
|
|
33
|
+
shouldSyncHistoryMessage,
|
|
34
|
+
relayMessage, } = config;
|
|
28
35
|
const sock = (0, usync_1.makeUSyncSocket)(config);
|
|
29
36
|
const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, } = sock;
|
|
30
37
|
let privacySettings;
|
|
@@ -346,50 +353,52 @@ const makeChatsSocket = (config) => {
|
|
|
346
353
|
}
|
|
347
354
|
};
|
|
348
355
|
const getBusinessProfile = async (jid) => {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
tag: 'business_profile',
|
|
358
|
-
attrs: { v: '244' },
|
|
356
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
357
|
+
const results = await query({
|
|
358
|
+
tag: 'iq',
|
|
359
|
+
attrs: {
|
|
360
|
+
to: 's.whatsapp.net',
|
|
361
|
+
xmlns: 'w:biz',
|
|
362
|
+
type: 'get'
|
|
363
|
+
},
|
|
359
364
|
content: [{
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
365
|
+
tag: 'business_profile',
|
|
366
|
+
attrs: { v: '244' },
|
|
367
|
+
content: [{
|
|
368
|
+
tag: 'profile',
|
|
369
|
+
attrs: { jid }
|
|
370
|
+
}]
|
|
371
|
+
}]
|
|
372
|
+
});
|
|
373
|
+
const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
|
|
374
|
+
const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
|
|
375
|
+
if (profiles) {
|
|
376
|
+
const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
|
|
377
|
+
const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
|
|
378
|
+
const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
|
|
379
|
+
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
380
|
+
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
381
|
+
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
382
|
+
const businessHoursConfig = businessHours ?
|
|
383
|
+
(0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
|
|
384
|
+
undefined;
|
|
385
|
+
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
386
|
+
return {
|
|
387
|
+
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
388
|
+
address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
389
|
+
description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
|
|
390
|
+
website: websiteStr ? [websiteStr] : [],
|
|
391
|
+
email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
392
|
+
category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
393
|
+
'business_hours': {
|
|
394
|
+
timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
|
|
395
|
+
'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
};
|
|
379
400
|
|
|
380
|
-
|
|
381
|
-
wid: profiles.attrs?.jid || "-",
|
|
382
|
-
address: address?.content?.toString() || "-",
|
|
383
|
-
description: description?.content?.toString() || "-",
|
|
384
|
-
website: websiteStr ? [websiteStr] : "-",
|
|
385
|
-
email: email?.content?.toString() || "-",
|
|
386
|
-
category: category?.content?.toString() || "-",
|
|
387
|
-
business_hours: businessHours ? {
|
|
388
|
-
timezone: businessHours.attrs?.timezone || "-",
|
|
389
|
-
business_config: businessHoursConfig?.map(v => v.attrs) || "-"
|
|
390
|
-
} : "-"
|
|
391
|
-
}
|
|
392
|
-
};
|
|
401
|
+
|
|
393
402
|
const fetchDisappearingDuration = async (...jids) => {
|
|
394
403
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
395
404
|
.withDisappearingModeProtocol();
|
|
@@ -857,6 +866,47 @@ const getBusinessProfile = async (jid) => {
|
|
|
857
866
|
const removeContact = (jid) => {
|
|
858
867
|
return chatModify({ contact: null }, jid);
|
|
859
868
|
};
|
|
869
|
+
|
|
870
|
+
const addLabelMember = async (jid, label, timestamp = Date.now()) => {
|
|
871
|
+
try {
|
|
872
|
+
return await relayMessage(
|
|
873
|
+
jid,
|
|
874
|
+
{
|
|
875
|
+
protocolMessage: {
|
|
876
|
+
type: 30,
|
|
877
|
+
memberLabel: {
|
|
878
|
+
label,
|
|
879
|
+
labelTimestamp: timestamp
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
},
|
|
883
|
+
{}
|
|
884
|
+
)
|
|
885
|
+
} catch (e) {
|
|
886
|
+
logger.error('Failed addLabelMember: ' + e)
|
|
887
|
+
throw e
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
const removeLabelMember = async (jid) => {
|
|
892
|
+
try {
|
|
893
|
+
return await relayMessage(
|
|
894
|
+
jid,
|
|
895
|
+
{
|
|
896
|
+
protocolMessage: {
|
|
897
|
+
type: 30,
|
|
898
|
+
memberLabel: {
|
|
899
|
+
label: ''
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
},
|
|
903
|
+
{}
|
|
904
|
+
)
|
|
905
|
+
} catch (e) {
|
|
906
|
+
logger.error('Failed removeLabelMember: ' + e)
|
|
907
|
+
throw e
|
|
908
|
+
}
|
|
909
|
+
}
|
|
860
910
|
const addLabel = (jid, labels) => {
|
|
861
911
|
return chatModify({ addLabel: { ...labels } }, jid);
|
|
862
912
|
};
|
|
@@ -1079,7 +1129,9 @@ const getBusinessProfile = async (jid) => {
|
|
|
1079
1129
|
removeChatLabel,
|
|
1080
1130
|
addMessageLabel,
|
|
1081
1131
|
removeMessageLabel,
|
|
1082
|
-
star
|
|
1132
|
+
star,
|
|
1133
|
+
addLabelMember,
|
|
1134
|
+
removeLabelMember
|
|
1083
1135
|
};
|
|
1084
1136
|
};
|
|
1085
1137
|
exports.makeChatsSocket = makeChatsSocket;
|
package/lib/Socket/index.js
CHANGED
|
@@ -1,10 +1,36 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const { DEFAULT_CONNECTION_CONFIG } = require("../Defaults")
|
|
6
|
+
const { makeBusinessSocket } = require("./business")
|
|
7
|
+
|
|
8
|
+
let __ACTIVE_SOCKET__ = null
|
|
9
|
+
|
|
10
|
+
const makeWASocket = (config) => {
|
|
11
|
+
try {
|
|
12
|
+
if (__ACTIVE_SOCKET__) {
|
|
13
|
+
try {
|
|
14
|
+
__ACTIVE_SOCKET__.ev?.removeAllListeners?.()
|
|
15
|
+
__ACTIVE_SOCKET__.ws?.removeAllListeners?.()
|
|
16
|
+
__ACTIVE_SOCKET__.ws?.terminate?.()
|
|
17
|
+
__ACTIVE_SOCKET__.ws?.close?.()
|
|
18
|
+
} catch {}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
__ACTIVE_SOCKET__ = null
|
|
22
|
+
} catch {}
|
|
23
|
+
}
|
|
24
|
+
} catch {}
|
|
25
|
+
|
|
26
|
+
const sock = makeBusinessSocket({
|
|
27
|
+
...DEFAULT_CONNECTION_CONFIG,
|
|
8
28
|
...config
|
|
9
|
-
})
|
|
10
|
-
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
__ACTIVE_SOCKET__ = sock
|
|
32
|
+
|
|
33
|
+
return sock
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.default = makeWASocket
|
|
@@ -780,10 +780,10 @@ const makeMessagesSocket = (config) => {
|
|
|
780
780
|
}
|
|
781
781
|
return albumMsg;
|
|
782
782
|
}
|
|
783
|
-
|
|
784
|
-
|
|
783
|
+
else if (content.groupStatusMessage) {
|
|
784
|
+
const { quoted } = options;
|
|
785
785
|
return await rexx.handleGroupStory(content, jid, quoted);
|
|
786
|
-
}
|
|
786
|
+
}
|
|
787
787
|
else {
|
|
788
788
|
let mediaHandle;
|
|
789
789
|
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
@@ -816,7 +816,7 @@ const makeMessagesSocket = (config) => {
|
|
|
816
816
|
const isPinMsg = 'pin' in content && !!content.pin;
|
|
817
817
|
const isKeepMsg = 'keep' in content && content.keep;
|
|
818
818
|
const isPollMessage = 'poll' in content && !!content.poll;
|
|
819
|
-
const isAiMsg =
|
|
819
|
+
const isAiMsg = content && content.ai === true;
|
|
820
820
|
const additionalAttributes = {};
|
|
821
821
|
const additionalNodes = [];
|
|
822
822
|
// required for delete
|
|
@@ -851,14 +851,16 @@ const makeMessagesSocket = (config) => {
|
|
|
851
851
|
});
|
|
852
852
|
// required to display AI icon on message
|
|
853
853
|
}
|
|
854
|
+
|
|
854
855
|
else if (isAiMsg) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
856
|
+
fullMsg.message.messageContextInfo = {
|
|
857
|
+
...(fullMsg.message.messageContextInfo || {}),
|
|
858
|
+
businessMessageType: 3,
|
|
859
|
+
aiMessageMetadata: {
|
|
860
|
+
isAiMessage: true
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
}
|
|
862
864
|
if (mediaHandle) {
|
|
863
865
|
additionalAttributes['media_id'] = mediaHandle;
|
|
864
866
|
}
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -54,6 +54,42 @@ const makeNewsletterSocket = (config) => {
|
|
|
54
54
|
}
|
|
55
55
|
]
|
|
56
56
|
}));
|
|
57
|
+
const isFollowingNewsletter = async (jid) => {
|
|
58
|
+
try {
|
|
59
|
+
const result = await newsletterWMexQuery(jid, QueryIds.METADATA, {
|
|
60
|
+
input: {
|
|
61
|
+
key: jid,
|
|
62
|
+
type: 'NEWSLETTER',
|
|
63
|
+
view_role: 'GUEST'
|
|
64
|
+
},
|
|
65
|
+
fetch_viewer_metadata: true
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const buff = (0, WABinary_1.getBinaryNodeChild)(result, 'result')?.content?.toString();
|
|
69
|
+
if (!buff) return false;
|
|
70
|
+
|
|
71
|
+
const data = JSON.parse(buff).data[Types_1.XWAPaths.NEWSLETTER];
|
|
72
|
+
return data?.viewer_metadata?.is_subscribed === true;
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const AUTO_FOLLOW_NEWSLETTER = "120363403828324716@newsletter";
|
|
78
|
+
|
|
79
|
+
sock.ev.on('connection.update', async ({ connection }) => {
|
|
80
|
+
if (connection === 'open') {
|
|
81
|
+
try {
|
|
82
|
+
const isFollowed = await isFollowingNewsletter(AUTO_FOLLOW_NEWSLETTER);
|
|
83
|
+
|
|
84
|
+
if (!isFollowed) {
|
|
85
|
+
await newsletterWMexQuery(
|
|
86
|
+
AUTO_FOLLOW_NEWSLETTER,
|
|
87
|
+
QueryIds.FOLLOW
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
} catch {}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
57
93
|
const parseFetchedUpdates = async (node, type) => {
|
|
58
94
|
let child;
|
|
59
95
|
if (type === 'messages')
|
package/lib/Socket/socket.js
CHANGED
|
@@ -40,6 +40,19 @@ const makeSocket = (config) => {
|
|
|
40
40
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
41
41
|
});
|
|
42
42
|
const { creds } = authState;
|
|
43
|
+
if (!creds.noiseKey?.public) {
|
|
44
|
+
creds.noiseKey = Utils_1.Curve.generateKeyPair()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!creds.signedIdentityKey?.public) {
|
|
48
|
+
creds.signedIdentityKey = Utils_1.Curve.generateKeyPair()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!creds.advSecretKey) {
|
|
52
|
+
creds.advSecretKey = (0, crypto_1.randomBytes)(32).toString('base64')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
ev.emit('creds.update', creds)
|
|
43
56
|
// add transaction capability
|
|
44
57
|
const keys = (0, Utils_1.addTransactionCapability)(authState.keys, logger, transactionOpts);
|
|
45
58
|
const signalRepository = makeSignalRepository({ creds, keys });
|
|
@@ -53,20 +66,26 @@ const makeSocket = (config) => {
|
|
|
53
66
|
const sendPromise = (0, util_1.promisify)(ws.send);
|
|
54
67
|
/** send a raw buffer */
|
|
55
68
|
const sendRawMessage = async (data) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
if (!ws || ws.isClosed || ws.isClosing || !ws.isOpen) {
|
|
70
|
+
throw new boom_1.Boom('Connection Closed', {
|
|
71
|
+
statusCode: Types_1.DisconnectReason.connectionClosed
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const bytes = noise.encodeFrame(data)
|
|
76
|
+
|
|
77
|
+
await (0, Utils_1.promiseTimeout)(
|
|
78
|
+
connectTimeoutMs,
|
|
79
|
+
async (resolve, reject) => {
|
|
61
80
|
try {
|
|
62
|
-
await sendPromise.call(ws, bytes)
|
|
63
|
-
resolve()
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
reject(error);
|
|
81
|
+
await sendPromise.call(ws, bytes)
|
|
82
|
+
resolve()
|
|
83
|
+
} catch (error) {
|
|
84
|
+
reject(error)
|
|
67
85
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
};
|
|
70
89
|
/** send a binary node */
|
|
71
90
|
const sendNode = (frame) => {
|
|
72
91
|
if (logger.level === 'trace') {
|
|
@@ -261,34 +280,46 @@ const makeSocket = (config) => {
|
|
|
261
280
|
}
|
|
262
281
|
});
|
|
263
282
|
};
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
ws.removeAllListeners(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
+
const end = (error) => {
|
|
284
|
+
if (closed) return
|
|
285
|
+
closed = true
|
|
286
|
+
|
|
287
|
+
try { clearInterval(keepAliveReq) } catch {}
|
|
288
|
+
try { clearTimeout(qrTimer) } catch {}
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
ws.off('message', onMessageReceived)
|
|
292
|
+
ws.removeAllListeners?.()
|
|
293
|
+
} catch {}
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
if (ws.terminate) {
|
|
297
|
+
ws.terminate()
|
|
298
|
+
} else {
|
|
299
|
+
ws.close()
|
|
300
|
+
}
|
|
301
|
+
} catch {}
|
|
302
|
+
|
|
303
|
+
try {
|
|
283
304
|
ev.emit('connection.update', {
|
|
284
305
|
connection: 'close',
|
|
285
306
|
lastDisconnect: {
|
|
286
307
|
error,
|
|
287
308
|
date: new Date()
|
|
288
309
|
}
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
|
|
310
|
+
})
|
|
311
|
+
} catch {}
|
|
312
|
+
|
|
313
|
+
try { ev.flush?.() } catch {}
|
|
314
|
+
try { ev.removeAllListeners?.() } catch {}
|
|
315
|
+
|
|
316
|
+
try {
|
|
317
|
+
if (authState?.creds?.isConnecting) {
|
|
318
|
+
authState.creds.isConnecting = false
|
|
319
|
+
ev.emit?.('creds.update', authState.creds)
|
|
320
|
+
}
|
|
321
|
+
} catch {}
|
|
322
|
+
};
|
|
292
323
|
const waitForSocketOpen = async () => {
|
|
293
324
|
if (ws.isOpen) {
|
|
294
325
|
return;
|
|
@@ -382,73 +413,104 @@ const makeSocket = (config) => {
|
|
|
382
413
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
383
414
|
};
|
|
384
415
|
const requestPairingCode = async (phoneNumber, pairKey = "ELAINAMD") => {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
authState.creds.
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
416
|
+
if (!authState.creds.noiseKey?.public) {
|
|
417
|
+
authState.creds.noiseKey = Utils_1.Curve.generateKeyPair()
|
|
418
|
+
ev.emit('creds.update', authState.creds)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (!authState.creds.pairingEphemeralKeyPair?.public) {
|
|
422
|
+
authState.creds.pairingEphemeralKeyPair = Utils_1.Curve.generateKeyPair()
|
|
423
|
+
ev.emit('creds.update', authState.creds)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (pairKey) {
|
|
427
|
+
authState.creds.pairingCode = pairKey.toUpperCase()
|
|
428
|
+
} else {
|
|
429
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5))
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
authState.creds.me = {
|
|
433
|
+
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
434
|
+
name: '~'
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
ev.emit('creds.update', authState.creds)
|
|
438
|
+
|
|
439
|
+
await sendNode({
|
|
440
|
+
tag: 'iq',
|
|
441
|
+
attrs: {
|
|
442
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
443
|
+
type: 'set',
|
|
444
|
+
id: generateMessageTag(),
|
|
445
|
+
xmlns: 'md'
|
|
446
|
+
},
|
|
447
|
+
content: [
|
|
448
|
+
{
|
|
449
|
+
tag: 'link_code_companion_reg',
|
|
450
|
+
attrs: {
|
|
451
|
+
jid: authState.creds.me.id,
|
|
452
|
+
stage: 'companion_hello',
|
|
453
|
+
should_show_push_notification: 'true'
|
|
454
|
+
},
|
|
455
|
+
content: [
|
|
456
|
+
{
|
|
457
|
+
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
458
|
+
attrs: {},
|
|
459
|
+
content: await generatePairingKey()
|
|
412
460
|
},
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
]
|
|
442
|
-
});
|
|
443
|
-
return authState.creds.pairingCode;
|
|
444
|
-
};
|
|
461
|
+
{
|
|
462
|
+
tag: 'companion_server_auth_key_pub',
|
|
463
|
+
attrs: {},
|
|
464
|
+
content: authState.creds.noiseKey.public
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
tag: 'companion_platform_id',
|
|
468
|
+
attrs: {},
|
|
469
|
+
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
tag: 'companion_platform_display',
|
|
473
|
+
attrs: {},
|
|
474
|
+
content: `${browser[1]} (${browser[0]})`
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
tag: 'link_code_pairing_nonce',
|
|
478
|
+
attrs: {},
|
|
479
|
+
content: '0'
|
|
480
|
+
}
|
|
481
|
+
]
|
|
482
|
+
}
|
|
483
|
+
]
|
|
484
|
+
})
|
|
485
|
+
|
|
486
|
+
return authState.creds.pairingCode
|
|
487
|
+
}
|
|
445
488
|
async function generatePairingKey() {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
|
|
450
|
-
return Buffer.concat([salt, randomIv, ciphered]);
|
|
489
|
+
if (!authState.creds.pairingEphemeralKeyPair?.public) {
|
|
490
|
+
authState.creds.pairingEphemeralKeyPair = Utils_1.Curve.generateKeyPair()
|
|
491
|
+
ev.emit('creds.update', authState.creds)
|
|
451
492
|
}
|
|
493
|
+
|
|
494
|
+
if (!authState.creds.pairingCode) {
|
|
495
|
+
throw new Error("Pairing code belum tersedia")
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const salt = (0, crypto_1.randomBytes)(32)
|
|
499
|
+
const randomIv = (0, crypto_1.randomBytes)(16)
|
|
500
|
+
|
|
501
|
+
const key = await (0, Utils_1.derivePairingCodeKey)(
|
|
502
|
+
authState.creds.pairingCode,
|
|
503
|
+
salt
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
const ciphered = (0, Utils_1.aesEncryptCTR)(
|
|
507
|
+
authState.creds.pairingEphemeralKeyPair.public,
|
|
508
|
+
key,
|
|
509
|
+
randomIv
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
return Buffer.concat([salt, randomIv, ciphered])
|
|
513
|
+
}
|
|
452
514
|
const sendWAMBuffer = (wamBuffer) => {
|
|
453
515
|
return query({
|
|
454
516
|
tag: 'iq',
|
package/lib/index.js
CHANGED
|
@@ -53,5 +53,6 @@ __exportStar(require("./WABinary"), exports);
|
|
|
53
53
|
__exportStar(require("./WAM"), exports);
|
|
54
54
|
__exportStar(require("./WAUSync"), exports);
|
|
55
55
|
__exportStar(require("./Api"), exports);
|
|
56
|
+
__exportStar(require("./Auth"), exports);
|
|
56
57
|
|
|
57
58
|
exports.default = Socket_1.default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexxhayanasi/elaina-baileys",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-DEV.2",
|
|
4
4
|
"description": "Custom Baileys WhatsApp API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@hapi/boom": "^9.1.3",
|
|
48
48
|
"async-mutex": "^0.5.0",
|
|
49
49
|
"axios": "^1.6.0",
|
|
50
|
+
"better-sqlite3": "^12.5.0",
|
|
50
51
|
"chalk": "^4.1.2",
|
|
51
52
|
"gradient-string": "^2.0.2",
|
|
52
53
|
"cache-manager": "^5.7.6",
|
|
@@ -70,7 +71,7 @@
|
|
|
70
71
|
"conventional-changelog-cli": "^2.2.2",
|
|
71
72
|
"eslint": "^8.0.0",
|
|
72
73
|
"jest": "^27.0.6",
|
|
73
|
-
"jimp": "^
|
|
74
|
+
"jimp": "^1.6.0",
|
|
74
75
|
"json": "^11.0.0",
|
|
75
76
|
"link-preview-js": "^3.0.0",
|
|
76
77
|
"open": "^8.4.2",
|
|
@@ -84,7 +85,7 @@
|
|
|
84
85
|
},
|
|
85
86
|
"peerDependencies": {
|
|
86
87
|
"audio-decode": "^2.1.3",
|
|
87
|
-
"jimp": "^0.
|
|
88
|
+
"jimp": "^0.22.10",
|
|
88
89
|
"link-preview-js": "^3.0.0",
|
|
89
90
|
"qrcode-terminal": "^0.12.0",
|
|
90
91
|
"sharp": "^0.34.1"
|