@vinzsocket/baileys 2.8.10 → 2.8.20
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/lib/Defaults/index.js +75 -73
- package/lib/Signal/Group/ciphertext-message.js +9 -9
- package/lib/Signal/Group/group-session-builder.js +21 -21
- package/lib/Signal/Group/group_cipher.js +79 -81
- package/lib/Signal/Group/index.js +2 -2
- package/lib/Signal/Group/keyhelper.js +9 -9
- package/lib/Signal/Group/queue-job.js +43 -46
- package/lib/Signal/Group/sender-chain-key.js +24 -25
- package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
- package/lib/Signal/Group/sender-key-message.js +55 -60
- package/lib/Signal/Group/sender-key-name.js +38 -39
- package/lib/Signal/Group/sender-key-record.js +39 -41
- package/lib/Signal/Group/sender-key-state.js +85 -89
- package/lib/Signal/Group/sender-message-key.js +22 -22
- package/lib/Signal/libsignal.js +387 -292
- package/lib/Signal/lid-mapping.js +98 -93
- package/lib/Socket/Client/types.js +6 -6
- package/lib/Socket/Client/websocket.js +44 -44
- package/lib/Socket/business.js +350 -365
- package/lib/Socket/chats.js +1019 -914
- package/lib/Socket/communities.js +454 -376
- package/lib/Socket/groups.js +378 -310
- package/lib/Socket/index.js +11 -11
- package/lib/Socket/messages-recv.js +1355 -1182
- package/lib/Socket/messages-send.js +1224 -1081
- package/lib/Socket/mex.js +40 -34
- package/lib/Socket/newsletter.js +212 -169
- package/lib/Socket/socket.js +896 -757
- package/lib/Store/index.js +1 -1
- package/lib/Store/make-cache-manager-store.js +75 -79
- package/lib/Store/make-in-memory-store.js +450 -389
- package/lib/Store/make-ordered-dictionary.js +73 -76
- package/lib/Store/object-repository.js +24 -22
- package/lib/Types/Chat.js +1 -7
- package/lib/Types/Label.js +20 -20
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +2 -2
- package/lib/Types/Newsletter.js +24 -24
- package/lib/Types/Socket.js +1 -1
- package/lib/Types/State.js +8 -8
- package/lib/Types/index.js +10 -10
- package/lib/Utils/auth-utils.js +408 -401
- package/lib/Utils/baileys-event-stream.js +44 -35
- package/lib/Utils/business.js +200 -197
- package/lib/Utils/chat-utils.js +775 -708
- package/lib/Utils/crypto.js +97 -85
- package/lib/Utils/decode-wa-message.js +240 -227
- package/lib/Utils/event-buffer.js +547 -518
- package/lib/Utils/extended-messages.js +250 -203
- package/lib/Utils/generics.js +300 -289
- package/lib/Utils/history.js +76 -69
- package/lib/Utils/lid-resolver.js +47 -42
- package/lib/Utils/link-preview.js +75 -65
- package/lib/Utils/logger.js +3 -1
- package/lib/Utils/lt-hash.js +38 -34
- package/lib/Utils/make-mutex.js +32 -34
- package/lib/Utils/mention.js +79 -86
- package/lib/Utils/message-retry-manager.js +148 -136
- package/lib/Utils/messages-media.js +652 -562
- package/lib/Utils/messages.js +753 -707
- package/lib/Utils/noise-handler.js +156 -135
- package/lib/Utils/process-message.js +404 -341
- package/lib/Utils/signal.js +180 -118
- package/lib/Utils/use-multi-file-auth-state.js +87 -91
- package/lib/Utils/validate-connection.js +167 -142
- package/lib/WABinary/constants.js +28 -1293
- package/lib/WABinary/decode.js +220 -218
- package/lib/WABinary/encode.js +199 -201
- package/lib/WABinary/generic-utils.js +80 -77
- package/lib/WABinary/jid-utils.js +41 -35
- package/lib/WAM/BinaryInfo.js +7 -7
- package/lib/WAM/constants.js +1 -15241
- package/lib/WAM/encode.js +124 -131
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
- package/lib/WAUSync/USyncQuery.js +82 -84
- package/lib/WAUSync/USyncUser.js +20 -20
- package/package.json +5 -2
|
@@ -6,160 +6,185 @@ import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary/index
|
|
|
6
6
|
import { Curve, hmacSign } from './crypto.js';
|
|
7
7
|
import { encodeBigEndian } from './generics.js';
|
|
8
8
|
import { createSignalIdentity } from './signal.js';
|
|
9
|
-
const getUserAgent =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
const getUserAgent = config => {
|
|
10
|
+
return {
|
|
11
|
+
appVersion: {
|
|
12
|
+
primary: config.version[0],
|
|
13
|
+
secondary: config.version[1],
|
|
14
|
+
tertiary: config.version[2]
|
|
15
|
+
},
|
|
16
|
+
platform: proto.ClientPayload.UserAgent.Platform.WEB,
|
|
17
|
+
releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
18
|
+
osVersion: '0.1',
|
|
19
|
+
device: 'Desktop',
|
|
20
|
+
osBuildNumber: '0.1',
|
|
21
|
+
localeLanguageIso6391: 'en',
|
|
22
|
+
mnc: '000',
|
|
23
|
+
mcc: '000',
|
|
24
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
25
|
+
};
|
|
26
26
|
};
|
|
27
27
|
const PLATFORM_MAP = {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
29
|
+
Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
30
30
|
};
|
|
31
|
-
const getWebInfo =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
const getWebInfo = config => {
|
|
32
|
+
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
33
|
+
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
|
|
34
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
webSubPlatform
|
|
38
|
+
};
|
|
37
39
|
};
|
|
38
|
-
const getClientPayload =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
const getClientPayload = config => {
|
|
41
|
+
const payload = {
|
|
42
|
+
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
43
|
+
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
44
|
+
userAgent: getUserAgent(config)
|
|
45
|
+
};
|
|
46
|
+
payload.webInfo = getWebInfo(config);
|
|
47
|
+
return payload;
|
|
46
48
|
};
|
|
47
49
|
export const generateLoginNode = (userJid, config) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
const {
|
|
51
|
+
user,
|
|
52
|
+
device
|
|
53
|
+
} = jidDecode(userJid);
|
|
54
|
+
const payload = {
|
|
55
|
+
...getClientPayload(config),
|
|
56
|
+
passive: false,
|
|
57
|
+
pull: true,
|
|
58
|
+
username: +user,
|
|
59
|
+
device: device
|
|
60
|
+
};
|
|
61
|
+
return proto.ClientPayload.create(payload);
|
|
57
62
|
};
|
|
58
|
-
const getPlatformType =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
proto.DeviceProps.PlatformType.DESKTOP);
|
|
63
|
+
const getPlatformType = platform => {
|
|
64
|
+
const platformType = platform.toUpperCase();
|
|
65
|
+
return proto.DeviceProps.PlatformType[platformType] || proto.DeviceProps.PlatformType.DESKTOP;
|
|
62
66
|
};
|
|
63
|
-
export const generateRegistrationNode = ({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
93
|
-
const msgId = stanza.attrs.id;
|
|
94
|
-
const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success');
|
|
95
|
-
const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity');
|
|
96
|
-
const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform');
|
|
97
|
-
const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device');
|
|
98
|
-
const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz');
|
|
99
|
-
if (!deviceIdentityNode || !deviceNode) {
|
|
100
|
-
throw new Boom('Missing device-identity or device in pair success node', { data: stanza });
|
|
101
|
-
}
|
|
102
|
-
const bizName = businessNode?.attrs.name;
|
|
103
|
-
const jid = deviceNode.attrs.jid;
|
|
104
|
-
const lid = deviceNode.attrs.lid;
|
|
105
|
-
const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
106
|
-
const isHostedAccount = accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED;
|
|
107
|
-
const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0);
|
|
108
|
-
const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
109
|
-
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
110
|
-
throw new Boom('Invalid account signature');
|
|
67
|
+
export const generateRegistrationNode = ({
|
|
68
|
+
registrationId,
|
|
69
|
+
signedPreKey,
|
|
70
|
+
signedIdentityKey
|
|
71
|
+
}, config) => {
|
|
72
|
+
// the app version needs to be md5 hashed
|
|
73
|
+
// and passed in
|
|
74
|
+
const appVersionBuf = createHash('md5').update(config.version.join('.')) // join as string
|
|
75
|
+
.digest();
|
|
76
|
+
const companion = {
|
|
77
|
+
os: config.browser[0],
|
|
78
|
+
platformType: getPlatformType(config.browser[1]),
|
|
79
|
+
requireFullSync: config.syncFullHistory
|
|
80
|
+
};
|
|
81
|
+
const companionProto = proto.DeviceProps.encode(companion).finish();
|
|
82
|
+
const registerPayload = {
|
|
83
|
+
...getClientPayload(config),
|
|
84
|
+
passive: false,
|
|
85
|
+
pull: false,
|
|
86
|
+
devicePairingData: {
|
|
87
|
+
buildHash: appVersionBuf,
|
|
88
|
+
deviceProps: companionProto,
|
|
89
|
+
eRegid: encodeBigEndian(registrationId),
|
|
90
|
+
eKeytype: KEY_BUNDLE_TYPE,
|
|
91
|
+
eIdent: signedIdentityKey.public,
|
|
92
|
+
eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
|
|
93
|
+
eSkeyVal: signedPreKey.keyPair.public,
|
|
94
|
+
eSkeySig: signedPreKey.signature
|
|
111
95
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
96
|
+
};
|
|
97
|
+
return proto.ClientPayload.create(registerPayload);
|
|
98
|
+
};
|
|
99
|
+
export const configureSuccessfulPairing = (stanza, {
|
|
100
|
+
advSecretKey,
|
|
101
|
+
signedIdentityKey,
|
|
102
|
+
signalIdentities
|
|
103
|
+
}) => {
|
|
104
|
+
const msgId = stanza.attrs.id;
|
|
105
|
+
const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success');
|
|
106
|
+
const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity');
|
|
107
|
+
const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform');
|
|
108
|
+
const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device');
|
|
109
|
+
const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz');
|
|
110
|
+
if (!deviceIdentityNode || !deviceNode) {
|
|
111
|
+
throw new Boom('Missing device-identity or device in pair success node', {
|
|
112
|
+
data: stanza
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const bizName = businessNode?.attrs.name;
|
|
116
|
+
const jid = deviceNode.attrs.jid;
|
|
117
|
+
const lid = deviceNode.attrs.lid;
|
|
118
|
+
const {
|
|
119
|
+
details,
|
|
120
|
+
hmac,
|
|
121
|
+
accountType
|
|
122
|
+
} = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
123
|
+
const isHostedAccount = accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED;
|
|
124
|
+
const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0);
|
|
125
|
+
const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
126
|
+
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
127
|
+
throw new Boom('Invalid account signature');
|
|
128
|
+
}
|
|
129
|
+
const account = proto.ADVSignedDeviceIdentity.decode(details);
|
|
130
|
+
const {
|
|
131
|
+
accountSignatureKey,
|
|
132
|
+
accountSignature,
|
|
133
|
+
details: deviceDetails
|
|
134
|
+
} = account;
|
|
135
|
+
const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public]);
|
|
136
|
+
if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
137
|
+
throw new Boom('Failed to verify account signature');
|
|
138
|
+
}
|
|
139
|
+
const devicePrefix = isHostedAccount ? Buffer.from([6, 6]) : Buffer.from([6, 1]);
|
|
140
|
+
const deviceMsg = Buffer.concat([devicePrefix, deviceDetails, signedIdentityKey.public, accountSignatureKey]);
|
|
141
|
+
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
142
|
+
const identity = createSignalIdentity(lid, accountSignatureKey);
|
|
143
|
+
const accountEnc = encodeSignedDeviceIdentity(account, false);
|
|
144
|
+
const deviceIdentity = proto.ADVDeviceIdentity.decode(account.details);
|
|
145
|
+
const reply = {
|
|
146
|
+
tag: 'iq',
|
|
147
|
+
attrs: {
|
|
148
|
+
to: S_WHATSAPP_NET,
|
|
149
|
+
type: 'result',
|
|
150
|
+
id: msgId
|
|
151
|
+
},
|
|
152
|
+
content: [{
|
|
153
|
+
tag: 'pair-device-sign',
|
|
154
|
+
attrs: {},
|
|
155
|
+
content: [{
|
|
156
|
+
tag: 'device-identity',
|
|
126
157
|
attrs: {
|
|
127
|
-
|
|
128
|
-
type: 'result',
|
|
129
|
-
id: msgId
|
|
158
|
+
'key-index': deviceIdentity.keyIndex.toString()
|
|
130
159
|
},
|
|
131
|
-
content:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
platform: platformNode?.attrs.name
|
|
150
|
-
};
|
|
151
|
-
return {
|
|
152
|
-
creds: authUpdate,
|
|
153
|
-
reply
|
|
154
|
-
};
|
|
160
|
+
content: accountEnc
|
|
161
|
+
}]
|
|
162
|
+
}]
|
|
163
|
+
};
|
|
164
|
+
const authUpdate = {
|
|
165
|
+
account,
|
|
166
|
+
me: {
|
|
167
|
+
id: jid,
|
|
168
|
+
name: bizName,
|
|
169
|
+
lid
|
|
170
|
+
},
|
|
171
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
172
|
+
platform: platformNode?.attrs.name
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
creds: authUpdate,
|
|
176
|
+
reply
|
|
177
|
+
};
|
|
155
178
|
};
|
|
156
179
|
export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
180
|
+
account = {
|
|
181
|
+
...account
|
|
182
|
+
};
|
|
183
|
+
// set to null if we are not to include the signature key
|
|
184
|
+
// or if we are including the signature key but it is empty
|
|
185
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
186
|
+
account.accountSignatureKey = null;
|
|
187
|
+
}
|
|
188
|
+
return proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
164
189
|
};
|
|
165
190
|
//# sourceMappingURL=validate-connection.js.map
|