@realvare/based 2.5.8 → 2.6.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/README.MD +77 -116
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Signal/libsignal.js +21 -0
- package/lib/Socket/messages-recv.js +29 -0
- package/lib/Socket/messages-send.js +6 -2
- package/lib/Socket/socket.js +406 -1
- package/lib/Types/Auth.d.ts +8 -1
- package/lib/Types/Contact.d.ts +6 -0
- package/lib/Types/Newsletter.d.ts +17 -74
- package/lib/Types/Signal.d.ts +6 -0
- package/lib/Types/Socket.d.ts +9 -0
- package/lib/Utils/auth-utils.js +10 -0
- package/lib/Utils/cache-manager.js +21 -1
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/messages-media.js +15 -2
- package/lib/Utils/messages.js +1373 -1338
- package/lib/Utils/newsletter-utils.d.ts +2 -0
- package/lib/Utils/newsletter-utils.js +48 -0
- package/lib/Utils/performance-config.d.ts +4 -0
- package/lib/Utils/performance-config.js +8 -4
- package/lib/Utils/rate-limiter.js +95 -0
- package/lib/Utils/validate-connection.js +144 -84
- package/lib/WABinary/jid-utils.js +10 -3
- package/package.json +3 -6
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseNewsletterMessage = exports.parseNewsletterMetadata = void 0;
|
|
4
|
+
const WABinary_1 = require("../WABinary");
|
|
5
|
+
const generics_1 = require("./generics");
|
|
6
|
+
const parseNewsletterMetadata = (node) => {
|
|
7
|
+
const newsletter = (0, WABinary_1.getBinaryNodeChild)(node, 'newsletter');
|
|
8
|
+
const name = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'name');
|
|
9
|
+
const description = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'description');
|
|
10
|
+
const invite = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'invite');
|
|
11
|
+
const handle = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'handle');
|
|
12
|
+
const verification = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'verification');
|
|
13
|
+
const picture = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'picture');
|
|
14
|
+
const preview = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'preview');
|
|
15
|
+
const creationTime = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'creation_time');
|
|
16
|
+
const state = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'state');
|
|
17
|
+
const subscribers = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'subscribers');
|
|
18
|
+
const viewRole = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'view_role');
|
|
19
|
+
const subscribe = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'subscribe');
|
|
20
|
+
const muted = (0, WABinary_1.getBinaryNodeChild)(newsletter, 'mute');
|
|
21
|
+
return {
|
|
22
|
+
id: newsletter.attrs.id,
|
|
23
|
+
name: name === null || name === void 0 ? void 0 : name.content.toString(),
|
|
24
|
+
description: description === null || description === void 0 ? void 0 : description.content.toString(),
|
|
25
|
+
inviteCode: invite === null || invite === void 0 ? void 0 : invite.content.toString(),
|
|
26
|
+
handle: handle === null || handle === void 0 ? void 0 : handle.content.toString(),
|
|
27
|
+
subscriberCount: +(subscribers === null || subscribers === void 0 ? void 0 : subscribers.content.toString()),
|
|
28
|
+
verification: verification === null || verification === void 0 ? void 0 : verification.content.toString(),
|
|
29
|
+
picture: picture === null || picture === void 0 ? void 0 : picture.content.toString(),
|
|
30
|
+
preview: preview === null || preview === void 0 ? void 0 : preview.content.toString(),
|
|
31
|
+
creationTime: +(creationTime === null || creationTime === void 0 ? void 0 : creationTime.content.toString()),
|
|
32
|
+
muted: (muted === null || muted === void 0 ? void 0 : muted.content.toString()) === 'true',
|
|
33
|
+
state: state === null || state === void 0 ? void 0 : state.content.toString(),
|
|
34
|
+
viewRole: viewRole === null || viewRole === void 0 ? void 0 : viewRole.content.toString(),
|
|
35
|
+
subscribe: subscribe === null || subscribe === void 0 ? void 0 : subscribe.content.toString(),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
exports.parseNewsletterMetadata = parseNewsletterMetadata;
|
|
39
|
+
const parseNewsletterMessage = (node) => {
|
|
40
|
+
const message = (0, WABinary_1.getBinaryNodeChild)(node, 'message');
|
|
41
|
+
const views = (0, WABinary_1.getBinaryNodeChild)(node, 'views');
|
|
42
|
+
return {
|
|
43
|
+
serverMsgId: +(node.attrs.server_id || 0),
|
|
44
|
+
views: +(views === null || views === void 0 ? void 0 : views.content.toString()),
|
|
45
|
+
message: (0, generics_1.normalizeMessageContent)(message),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.parseNewsletterMessage = parseNewsletterMessage;
|
|
@@ -18,6 +18,10 @@ export interface PerformanceSettings {
|
|
|
18
18
|
maxRetryDelay: number;
|
|
19
19
|
maxMsgRetryCount: number;
|
|
20
20
|
memoryThreshold: number;
|
|
21
|
+
// Anti-ban specific settings
|
|
22
|
+
markOnlineOnConnect?: boolean;
|
|
23
|
+
syncFullHistory?: boolean;
|
|
24
|
+
keepAliveIntervalMs?: number;
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
export interface DebugSettings {
|
|
@@ -26,18 +26,22 @@ class PerformanceConfig {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
// Performance settings
|
|
29
|
+
// Performance settings - Conservative defaults for anti-ban protection
|
|
30
30
|
this.performance = {
|
|
31
31
|
enableCache: true,
|
|
32
32
|
enableLogging: false,
|
|
33
33
|
enableMetrics: true,
|
|
34
|
-
batchSize: 50
|
|
35
|
-
maxRetries: 5
|
|
34
|
+
batchSize: 20, // Reduced from 50 for anti-ban
|
|
35
|
+
maxRetries: 3, // Reduced from 5 for anti-ban
|
|
36
36
|
retryDelay: 5000,
|
|
37
37
|
retryBackoffMultiplier: 1.5,
|
|
38
38
|
maxRetryDelay: 60000,
|
|
39
39
|
maxMsgRetryCount: 3,
|
|
40
|
-
memoryThreshold: 0.85 // 85% memory usage threshold
|
|
40
|
+
memoryThreshold: 0.85, // 85% memory usage threshold
|
|
41
|
+
// Anti-ban specific settings
|
|
42
|
+
markOnlineOnConnect: false, // Don't appear always online
|
|
43
|
+
syncFullHistory: false, // Limit initial sync
|
|
44
|
+
keepAliveIntervalMs: 30000 // Maintain connection without excess
|
|
41
45
|
};
|
|
42
46
|
|
|
43
47
|
// Debug settings
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* RateLimiter class for controlling message sending frequency
|
|
5
|
+
* to prevent ban detection by simulating human-like behavior
|
|
6
|
+
*/
|
|
7
|
+
class RateLimiter {
|
|
8
|
+
constructor(limitPerSecond = 1) {
|
|
9
|
+
this.limitPerSecond = limitPerSecond;
|
|
10
|
+
this.interval = 1000 / limitPerSecond; // milliseconds between messages
|
|
11
|
+
this.queue = [];
|
|
12
|
+
this.processing = false;
|
|
13
|
+
this.lastSendTime = 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Add a task to the rate limiting queue
|
|
18
|
+
* @param {Function} task - Async function to execute
|
|
19
|
+
* @returns {Promise} - Promise that resolves when task is complete
|
|
20
|
+
*/
|
|
21
|
+
async add(task) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
this.queue.push({ task, resolve, reject });
|
|
24
|
+
if (!this.processing) {
|
|
25
|
+
this.process();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Process the queue with rate limiting
|
|
32
|
+
*/
|
|
33
|
+
async process() {
|
|
34
|
+
if (this.processing || this.queue.length === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
this.processing = true;
|
|
39
|
+
|
|
40
|
+
while (this.queue.length > 0) {
|
|
41
|
+
const { task, resolve, reject } = this.queue.shift();
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
const timeSinceLastSend = now - this.lastSendTime;
|
|
44
|
+
|
|
45
|
+
// Wait if we need to respect the rate limit
|
|
46
|
+
if (timeSinceLastSend < this.interval) {
|
|
47
|
+
const waitTime = this.interval - timeSinceLastSend;
|
|
48
|
+
await new Promise(r => setTimeout(r, waitTime));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const result = await task();
|
|
53
|
+
this.lastSendTime = Date.now();
|
|
54
|
+
resolve(result);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
reject(error);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Add small random delay to simulate human behavior (0-500ms)
|
|
60
|
+
const randomDelay = Math.random() * 500;
|
|
61
|
+
await new Promise(r => setTimeout(r, randomDelay));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.processing = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Update the rate limit
|
|
69
|
+
* @param {number} newLimit - New messages per second limit
|
|
70
|
+
*/
|
|
71
|
+
setLimit(newLimit) {
|
|
72
|
+
this.limitPerSecond = newLimit;
|
|
73
|
+
this.interval = 1000 / newLimit;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get current queue length
|
|
78
|
+
* @returns {number} - Number of pending tasks
|
|
79
|
+
*/
|
|
80
|
+
getQueueLength() {
|
|
81
|
+
return this.queue.length;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Clear all pending tasks
|
|
86
|
+
*/
|
|
87
|
+
clear() {
|
|
88
|
+
this.queue.forEach(({ reject }) => {
|
|
89
|
+
reject(new Error('Rate limiter cleared'));
|
|
90
|
+
});
|
|
91
|
+
this.queue = [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = RateLimiter;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const boom_1 = require("@hapi/boom")
|
|
6
|
+
const crypto_1 = require("crypto")
|
|
7
|
+
const WAProto_1 = require("../../WAProto")
|
|
8
|
+
const Defaults_1 = require("../Defaults")
|
|
9
|
+
const WABinary_1 = require("../WABinary")
|
|
10
|
+
const crypto_2 = require("./crypto")
|
|
11
|
+
const generics_1 = require("./generics")
|
|
12
|
+
const signal_1 = require("./signal")
|
|
13
|
+
|
|
12
14
|
const getUserAgent = (config) => {
|
|
13
15
|
return {
|
|
14
16
|
appVersion: {
|
|
@@ -22,57 +24,93 @@ const getUserAgent = (config) => {
|
|
|
22
24
|
device: 'Desktop',
|
|
23
25
|
osBuildNumber: '0.1',
|
|
24
26
|
localeLanguageIso6391: 'en',
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
mnc: '000',
|
|
28
|
+
mcc: '000',
|
|
29
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
28
33
|
const PLATFORM_MAP = {
|
|
29
34
|
'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
30
|
-
'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
31
|
-
|
|
35
|
+
'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32,
|
|
36
|
+
'Android': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
const getWebInfo = (config) => {
|
|
33
|
-
let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
|
|
40
|
+
let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
|
|
34
41
|
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
|
|
35
|
-
webSubPlatform = PLATFORM_MAP[config.browser[0]]
|
|
42
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]]
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
webSubPlatform,
|
|
46
|
+
coexistence: config.coexistence,
|
|
36
47
|
}
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
const getClientPayload = (config) => {
|
|
40
51
|
const payload = {
|
|
41
52
|
connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
42
53
|
connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
43
54
|
userAgent: getUserAgent(config),
|
|
44
|
-
}
|
|
45
|
-
payload.webInfo = getWebInfo(config)
|
|
46
|
-
return payload
|
|
47
|
-
}
|
|
55
|
+
}
|
|
56
|
+
payload.webInfo = getWebInfo(config)
|
|
57
|
+
return payload
|
|
58
|
+
}
|
|
59
|
+
|
|
48
60
|
const generateLoginNode = (userJid, config) => {
|
|
49
|
-
const { user, device } =
|
|
61
|
+
const { user, device } = WABinary_1.jidDecode(userJid)
|
|
50
62
|
const payload = {
|
|
51
63
|
...getClientPayload(config),
|
|
52
64
|
passive: false,
|
|
53
65
|
pull: true,
|
|
54
66
|
username: +user,
|
|
55
67
|
device: device,
|
|
56
|
-
}
|
|
57
|
-
return WAProto_1.proto.ClientPayload.fromObject(payload)
|
|
58
|
-
}
|
|
59
|
-
|
|
68
|
+
}
|
|
69
|
+
return WAProto_1.proto.ClientPayload.fromObject(payload)
|
|
70
|
+
}
|
|
71
|
+
|
|
60
72
|
const getPlatformType = (platform) => {
|
|
61
|
-
const platformType = platform.toUpperCase()
|
|
62
|
-
return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP
|
|
63
|
-
}
|
|
73
|
+
const platformType = platform.toUpperCase()
|
|
74
|
+
return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP
|
|
75
|
+
}
|
|
76
|
+
|
|
64
77
|
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
65
78
|
// the app version needs to be md5 hashed
|
|
66
79
|
// and passed in
|
|
67
|
-
const appVersionBuf =
|
|
80
|
+
const appVersionBuf = crypto_1.createHash('md5')
|
|
68
81
|
.update(config.version.join('.')) // join as string
|
|
69
|
-
.digest()
|
|
82
|
+
.digest()
|
|
83
|
+
|
|
70
84
|
const companion = {
|
|
71
85
|
os: config.browser[0],
|
|
72
86
|
platformType: getPlatformType(config.browser[1]),
|
|
73
87
|
requireFullSync: config.syncFullHistory,
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
historySyncConfig: {
|
|
89
|
+
storageQuotaMb: 10240,
|
|
90
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
91
|
+
recentSyncDaysLimit: undefined,
|
|
92
|
+
supportCallLogHistory: false,
|
|
93
|
+
supportBotUserAgentChatHistory: true,
|
|
94
|
+
supportCagReactionsAndPolls: true,
|
|
95
|
+
supportBizHostedMsg: true,
|
|
96
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
97
|
+
supportHostedGroupMsg: true,
|
|
98
|
+
supportFbidBotChatHistory: true,
|
|
99
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
100
|
+
supportMessageAssociation: true,
|
|
101
|
+
supportGroupHistory: false,
|
|
102
|
+
onDemandReady: undefined,
|
|
103
|
+
supportGuestChat: undefined
|
|
104
|
+
},
|
|
105
|
+
version: {
|
|
106
|
+
primary: 10,
|
|
107
|
+
secondary: 15,
|
|
108
|
+
tertiary: 7
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish()
|
|
113
|
+
|
|
76
114
|
const registerPayload = {
|
|
77
115
|
...getClientPayload(config),
|
|
78
116
|
passive: false,
|
|
@@ -80,48 +118,67 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
80
118
|
devicePairingData: {
|
|
81
119
|
buildHash: appVersionBuf,
|
|
82
120
|
deviceProps: companionProto,
|
|
83
|
-
eRegid:
|
|
121
|
+
eRegid: generics_1.encodeBigEndian(registrationId),
|
|
84
122
|
eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
|
|
85
123
|
eIdent: signedIdentityKey.public,
|
|
86
|
-
eSkeyId:
|
|
124
|
+
eSkeyId: generics_1.encodeBigEndian(signedPreKey.keyId, 3),
|
|
87
125
|
eSkeyVal: signedPreKey.keyPair.public,
|
|
88
126
|
eSkeySig: signedPreKey.signature,
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return WAProto_1.proto.ClientPayload.fromObject(registerPayload)
|
|
131
|
+
}
|
|
132
|
+
|
|
94
133
|
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
95
|
-
const msgId = stanza.attrs.id
|
|
96
|
-
const pairSuccessNode =
|
|
97
|
-
const deviceIdentityNode =
|
|
98
|
-
const platformNode =
|
|
99
|
-
const deviceNode =
|
|
100
|
-
const businessNode =
|
|
134
|
+
const msgId = stanza.attrs.id
|
|
135
|
+
const pairSuccessNode = WABinary_1.getBinaryNodeChild(stanza, 'pair-success')
|
|
136
|
+
const deviceIdentityNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device-identity')
|
|
137
|
+
const platformNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'platform')
|
|
138
|
+
const deviceNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device')
|
|
139
|
+
const businessNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'biz')
|
|
101
140
|
if (!deviceIdentityNode || !deviceNode) {
|
|
102
|
-
throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza })
|
|
141
|
+
throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza })
|
|
142
|
+
}
|
|
143
|
+
const bizName = businessNode?.attrs?.name
|
|
144
|
+
const jid = deviceNode.attrs.jid
|
|
145
|
+
const lid = deviceNode.attrs.lid
|
|
146
|
+
const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content)
|
|
147
|
+
|
|
148
|
+
let hmacPrefix = Buffer.from([])
|
|
149
|
+
if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
|
|
150
|
+
hmacPrefix = Buffer.from([6, 5])
|
|
103
151
|
}
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
107
|
-
const isHostedAccount = accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED;
|
|
108
|
-
const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0);
|
|
109
|
-
const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
152
|
+
|
|
153
|
+
const advSign = crypto_2.hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))
|
|
110
154
|
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
111
|
-
throw new boom_1.Boom('Invalid account signature')
|
|
155
|
+
throw new boom_1.Boom('Invalid account signature')
|
|
112
156
|
}
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
const
|
|
157
|
+
|
|
158
|
+
const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details)
|
|
159
|
+
const { accountSignatureKey, accountSignature, details: deviceDetails } = account
|
|
160
|
+
|
|
161
|
+
const decodedDeviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails)
|
|
162
|
+
|
|
163
|
+
const accountSignaturePrefix =
|
|
164
|
+
decodedDeviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
|
|
165
|
+
? Buffer.from([6, 5])
|
|
166
|
+
: Buffer.from([6, 0])
|
|
167
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public])
|
|
116
168
|
if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
117
|
-
throw new boom_1.Boom('Failed to verify account signature')
|
|
169
|
+
throw new boom_1.Boom('Failed to verify account signature')
|
|
118
170
|
}
|
|
119
|
-
|
|
120
|
-
const deviceMsg = Buffer.concat([
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
171
|
+
|
|
172
|
+
const deviceMsg = Buffer.concat([
|
|
173
|
+
Buffer.from([6, 1]),
|
|
174
|
+
deviceDetails,
|
|
175
|
+
signedIdentityKey.public,
|
|
176
|
+
accountSignatureKey
|
|
177
|
+
])
|
|
178
|
+
account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg)
|
|
179
|
+
const identity = signal_1.createSignalIdentity(lid, accountSignatureKey)
|
|
180
|
+
const accountEnc = encodeSignedDeviceIdentity(account, false)
|
|
181
|
+
const deviceIdentityData = WAProto_1.proto.ADVDeviceIdentity.decode(account.details)
|
|
125
182
|
const reply = {
|
|
126
183
|
tag: 'iq',
|
|
127
184
|
attrs: {
|
|
@@ -136,38 +193,41 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
136
193
|
content: [
|
|
137
194
|
{
|
|
138
195
|
tag: 'device-identity',
|
|
139
|
-
attrs: { 'key-index':
|
|
196
|
+
attrs: { 'key-index': deviceIdentityData.keyIndex.toString() },
|
|
140
197
|
content: accountEnc
|
|
141
198
|
}
|
|
142
199
|
]
|
|
143
200
|
}
|
|
144
201
|
]
|
|
145
|
-
}
|
|
202
|
+
}
|
|
146
203
|
const authUpdate = {
|
|
147
204
|
account,
|
|
148
|
-
me: { id: jid, name: bizName },
|
|
205
|
+
me: { id: jid, name: bizName, lid },
|
|
149
206
|
signalIdentities: [
|
|
150
207
|
...(signalIdentities || []),
|
|
151
208
|
identity
|
|
152
209
|
],
|
|
153
|
-
platform: platformNode
|
|
154
|
-
}
|
|
210
|
+
platform: platformNode?.attrs?.name
|
|
211
|
+
}
|
|
155
212
|
return {
|
|
156
213
|
creds: authUpdate,
|
|
157
214
|
reply
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
161
218
|
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
162
|
-
|
|
163
|
-
account = { ...account };
|
|
219
|
+
account = { ...account }
|
|
164
220
|
// set to null if we are not to include the signature key
|
|
165
221
|
// or if we are including the signature key but it is empty
|
|
166
|
-
if (!includeSignatureKey || !
|
|
167
|
-
account.accountSignatureKey = null
|
|
222
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
223
|
+
account.accountSignatureKey = null
|
|
168
224
|
}
|
|
169
|
-
return WAProto_1.proto.ADVSignedDeviceIdentity
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
225
|
+
return WAProto_1.proto.ADVSignedDeviceIdentity.encode(account).finish()
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
module.exports = {
|
|
229
|
+
generateLoginNode,
|
|
230
|
+
generateRegistrationNode,
|
|
231
|
+
configureSuccessfulPairing,
|
|
232
|
+
encodeSignedDeviceIdentity
|
|
233
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lidToJid = exports.getBotJid = exports.jidNormalizedUser = exports.isJidBot = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidNewsletter = exports.isJidBroadcast = exports.
|
|
3
|
+
exports.lidToJid = exports.getBotJid = exports.jidNormalizedUser = exports.isJidBot = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidNewsletter = exports.isJidBroadcast = exports.isLid = exports.assertLid = exports.isJidUser = exports.isJidMetaAi = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.META_AI_JID = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
|
|
4
4
|
exports.S_WHATSAPP_NET = '@s.whatsapp.net';
|
|
5
5
|
exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
|
|
6
6
|
exports.SERVER_JID = 'server@c.us';
|
|
@@ -41,8 +41,15 @@ exports.isJidMetaAi = isJidMetaAi;
|
|
|
41
41
|
const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
|
|
42
42
|
exports.isJidUser = isJidUser;
|
|
43
43
|
/** is the jid a group */
|
|
44
|
-
const
|
|
45
|
-
exports.
|
|
44
|
+
const isLid = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@lid'));
|
|
45
|
+
exports.isLid = isLid;
|
|
46
|
+
/** assert the jid is a LID */
|
|
47
|
+
const assertLid = (jid) => {
|
|
48
|
+
if (!isLid(jid)) {
|
|
49
|
+
throw new Error(`JID "${jid}" is not a LID`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.assertLid = assertLid;
|
|
46
53
|
/** is the jid a broadcast */
|
|
47
54
|
const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));
|
|
48
55
|
exports.isJidBroadcast = isJidBroadcast;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realvare/based",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "whatsapp api by sam",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
|
|
38
38
|
"preinstall": "node ./engine-requirements.js",
|
|
39
39
|
"release": "release-it",
|
|
40
|
-
"test": "
|
|
40
|
+
"test": "test"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@adiwajshing/keyed-db": "^0.2.4",
|
|
@@ -97,9 +97,6 @@
|
|
|
97
97
|
"link-preview-js": {
|
|
98
98
|
"optional": true
|
|
99
99
|
},
|
|
100
|
-
"qrcode-terminal": {
|
|
101
|
-
"optional": true
|
|
102
|
-
},
|
|
103
100
|
"sharp": {
|
|
104
101
|
"optional": true
|
|
105
102
|
}
|
|
@@ -108,4 +105,4 @@
|
|
|
108
105
|
"engines": {
|
|
109
106
|
"node": ">=20.0.0"
|
|
110
107
|
}
|
|
111
|
-
}
|
|
108
|
+
}
|