@baileys-md/baileys 10.1.0 → 11.0.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/LICENSE +1 -1
- package/README.md +1303 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +4633 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.js +13516 -4182
- package/lib/Defaults/baileys-version.js +1 -0
- package/lib/Defaults/index.js +51 -72
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.js +94 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +19 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.js +67 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.js +50 -0
- package/lib/Signal/Group/sender-key-state.js +96 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +4 -16
- package/lib/Signal/libsignal.js +41 -61
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +50 -0
- package/lib/Socket/business.js +37 -42
- package/lib/Socket/chats.js +194 -187
- package/lib/Socket/communities.js +351 -0
- package/lib/Socket/groups.js +87 -90
- package/lib/Socket/index.js +7 -8
- package/lib/Socket/messages-recv.js +360 -335
- package/lib/Socket/messages-send.js +156 -279
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.js +144 -213
- package/lib/Socket/socket.js +128 -161
- package/lib/Socket/usync.js +19 -26
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.js +3 -5
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/Message.js +7 -7
- package/lib/Types/Newsletter.js +30 -17
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.js +2 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.js +15 -31
- package/lib/Utils/auth-utils.js +31 -47
- package/lib/Utils/baileys-event-stream.js +15 -22
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/chat-utils.js +200 -195
- package/lib/Utils/crypto.js +70 -85
- package/lib/Utils/decode-wa-message.js +47 -51
- package/lib/Utils/event-buffer.js +36 -46
- package/lib/Utils/generics.js +116 -188
- package/lib/Utils/history.js +37 -46
- package/lib/Utils/index.js +19 -33
- package/lib/Utils/link-preview.js +14 -55
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/lt-hash.js +23 -26
- package/lib/{Store → Utils}/make-in-memory-store.js +19 -27
- package/lib/Utils/make-mutex.js +7 -10
- package/lib/{Store → Utils}/make-ordered-dictionary.js +1 -3
- package/lib/Utils/messages-media.js +236 -368
- package/lib/Utils/messages.js +278 -510
- package/lib/Utils/noise-handler.js +22 -31
- package/lib/{Store → Utils}/object-repository.js +1 -4
- package/lib/Utils/process-message.js +144 -148
- package/lib/Utils/signal.js +71 -64
- package/lib/Utils/use-multi-file-auth-state.js +112 -84
- package/lib/Utils/validate-connection.js +72 -115
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/decode.js +15 -52
- package/lib/WABinary/encode.js +14 -48
- package/lib/WABinary/generic-utils.js +31 -39
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/jid-utils.js +23 -40
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/constants.js +2257 -2366
- package/lib/WAM/encode.js +17 -21
- package/lib/WAM/index.js +4 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +8 -11
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -6
- package/lib/WAUSync/Protocols/index.js +5 -20
- package/lib/WAUSync/USyncQuery.js +34 -32
- package/lib/WAUSync/USyncUser.js +2 -5
- package/lib/WAUSync/index.js +4 -19
- package/lib/index.js +11 -33
- package/package.json +25 -54
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.js +0 -166
- package/lib/Store/index.js +0 -8
- package/lib/Store/make-cache-manager-store.js +0 -83
- package/lib/Store/make-mongo-store.js +0 -567
|
@@ -1,47 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const crypto_2 = require("./crypto");
|
|
10
|
-
const generics_1 = require("./generics");
|
|
11
|
-
const signal_1 = require("./signal");
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
|
|
5
|
+
import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
6
|
+
import { Curve, hmacSign } from './crypto.js';
|
|
7
|
+
import { encodeBigEndian } from './generics.js';
|
|
8
|
+
import { createSignalIdentity } from './signal.js';
|
|
12
9
|
const getUserAgent = (config) => {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
const osVersion = config.mobile ? '15.3.1' : '0.1';
|
|
15
|
-
const version = config.mobile ? [2, 24, 6] : config.version;
|
|
16
|
-
const device = config.mobile ? 'iPhone_7' : 'Desktop';
|
|
17
|
-
const manufacturer = config.mobile ? 'Apple' : '';
|
|
18
|
-
const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
|
|
19
|
-
const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
|
|
20
10
|
return {
|
|
21
11
|
appVersion: {
|
|
22
|
-
primary: version[0],
|
|
23
|
-
secondary: version[1],
|
|
24
|
-
tertiary: version[2]
|
|
12
|
+
primary: config.version[0],
|
|
13
|
+
secondary: config.version[1],
|
|
14
|
+
tertiary: config.version[2]
|
|
25
15
|
},
|
|
26
|
-
platform,
|
|
27
|
-
releaseChannel:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
manufacturer,
|
|
32
|
-
device,
|
|
33
|
-
osBuildNumber: osVersion,
|
|
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',
|
|
34
21
|
localeLanguageIso6391: 'en',
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
mnc: '000',
|
|
23
|
+
mcc: '000',
|
|
24
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
37
25
|
};
|
|
38
26
|
};
|
|
39
27
|
const PLATFORM_MAP = {
|
|
40
|
-
'Mac OS':
|
|
41
|
-
|
|
28
|
+
'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
29
|
+
Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
42
30
|
};
|
|
43
31
|
const getWebInfo = (config) => {
|
|
44
|
-
let webSubPlatform =
|
|
32
|
+
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
45
33
|
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
|
|
46
34
|
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
47
35
|
}
|
|
@@ -49,64 +37,41 @@ const getWebInfo = (config) => {
|
|
|
49
37
|
};
|
|
50
38
|
const getClientPayload = (config) => {
|
|
51
39
|
const payload = {
|
|
52
|
-
connectType:
|
|
53
|
-
connectReason:
|
|
54
|
-
userAgent: getUserAgent(config)
|
|
40
|
+
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
41
|
+
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
42
|
+
userAgent: getUserAgent(config)
|
|
55
43
|
};
|
|
56
|
-
|
|
57
|
-
payload.webInfo = getWebInfo(config);
|
|
58
|
-
}
|
|
44
|
+
payload.webInfo = getWebInfo(config);
|
|
59
45
|
return payload;
|
|
60
46
|
};
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
throw new boom_1.Boom('No registration data found', { data: config });
|
|
64
|
-
}
|
|
65
|
-
const payload = {
|
|
66
|
-
...getClientPayload(config),
|
|
67
|
-
sessionId: Math.floor(Math.random() * 999999999 + 1),
|
|
68
|
-
shortConnect: true,
|
|
69
|
-
connectAttemptCount: 0,
|
|
70
|
-
device: 0,
|
|
71
|
-
dnsSource: {
|
|
72
|
-
appCached: false,
|
|
73
|
-
dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
|
|
74
|
-
},
|
|
75
|
-
passive: false, // XMPP heartbeat setting (false: server actively pings) (true: client actively pings)
|
|
76
|
-
pushName: 'test',
|
|
77
|
-
username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
|
|
78
|
-
};
|
|
79
|
-
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
80
|
-
};
|
|
81
|
-
exports.generateMobileNode = generateMobileNode;
|
|
82
|
-
const generateLoginNode = (userJid, config) => {
|
|
83
|
-
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
47
|
+
export const generateLoginNode = (userJid, config) => {
|
|
48
|
+
const { user, device } = jidDecode(userJid);
|
|
84
49
|
const payload = {
|
|
85
50
|
...getClientPayload(config),
|
|
86
51
|
passive: false,
|
|
87
52
|
pull: true,
|
|
88
53
|
username: +user,
|
|
89
|
-
device: device
|
|
54
|
+
device: device
|
|
90
55
|
};
|
|
91
|
-
return
|
|
56
|
+
return proto.ClientPayload.fromObject(payload);
|
|
92
57
|
};
|
|
93
|
-
exports.generateLoginNode = generateLoginNode;
|
|
94
58
|
const getPlatformType = (platform) => {
|
|
95
59
|
const platformType = platform.toUpperCase();
|
|
96
|
-
return
|
|
60
|
+
return (proto.DeviceProps.PlatformType[platformType] ||
|
|
61
|
+
proto.DeviceProps.PlatformType.DESKTOP);
|
|
97
62
|
};
|
|
98
|
-
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
63
|
+
export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
99
64
|
// the app version needs to be md5 hashed
|
|
100
65
|
// and passed in
|
|
101
|
-
const appVersionBuf =
|
|
66
|
+
const appVersionBuf = createHash('md5')
|
|
102
67
|
.update(config.version.join('.')) // join as string
|
|
103
68
|
.digest();
|
|
104
69
|
const companion = {
|
|
105
70
|
os: config.browser[0],
|
|
106
71
|
platformType: getPlatformType(config.browser[1]),
|
|
107
|
-
requireFullSync: config.syncFullHistory
|
|
72
|
+
requireFullSync: config.syncFullHistory
|
|
108
73
|
};
|
|
109
|
-
const companionProto =
|
|
74
|
+
const companionProto = proto.DeviceProps.encode(companion).finish();
|
|
110
75
|
const registerPayload = {
|
|
111
76
|
...getClientPayload(config),
|
|
112
77
|
passive: false,
|
|
@@ -114,54 +79,53 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
114
79
|
devicePairingData: {
|
|
115
80
|
buildHash: appVersionBuf,
|
|
116
81
|
deviceProps: companionProto,
|
|
117
|
-
eRegid:
|
|
118
|
-
eKeytype:
|
|
82
|
+
eRegid: encodeBigEndian(registrationId),
|
|
83
|
+
eKeytype: KEY_BUNDLE_TYPE,
|
|
119
84
|
eIdent: signedIdentityKey.public,
|
|
120
|
-
eSkeyId:
|
|
85
|
+
eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
|
|
121
86
|
eSkeyVal: signedPreKey.keyPair.public,
|
|
122
|
-
eSkeySig: signedPreKey.signature
|
|
123
|
-
}
|
|
87
|
+
eSkeySig: signedPreKey.signature
|
|
88
|
+
}
|
|
124
89
|
};
|
|
125
|
-
return
|
|
90
|
+
return proto.ClientPayload.fromObject(registerPayload);
|
|
126
91
|
};
|
|
127
|
-
|
|
128
|
-
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
92
|
+
export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
129
93
|
const msgId = stanza.attrs.id;
|
|
130
|
-
const pairSuccessNode =
|
|
131
|
-
const deviceIdentityNode =
|
|
132
|
-
const platformNode =
|
|
133
|
-
const deviceNode =
|
|
134
|
-
const businessNode =
|
|
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');
|
|
135
99
|
if (!deviceIdentityNode || !deviceNode) {
|
|
136
|
-
throw new
|
|
100
|
+
throw new Boom('Missing device-identity or device in pair success node', { data: stanza });
|
|
137
101
|
}
|
|
138
|
-
const bizName = businessNode
|
|
102
|
+
const bizName = businessNode?.attrs.name;
|
|
139
103
|
const jid = deviceNode.attrs.jid;
|
|
140
|
-
const { details, hmac } =
|
|
141
|
-
|
|
142
|
-
const
|
|
104
|
+
const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
105
|
+
const isHostedAccount = accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED;
|
|
106
|
+
const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0);
|
|
107
|
+
const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
143
108
|
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
144
|
-
throw new
|
|
109
|
+
throw new Boom('Invalid account signature');
|
|
145
110
|
}
|
|
146
|
-
const account =
|
|
111
|
+
const account = proto.ADVSignedDeviceIdentity.decode(details);
|
|
147
112
|
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
148
|
-
// verify the device signature matches
|
|
149
113
|
const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails, signedIdentityKey.public]);
|
|
150
|
-
if (!
|
|
151
|
-
throw new
|
|
114
|
+
if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
115
|
+
throw new Boom('Failed to verify account signature');
|
|
152
116
|
}
|
|
153
|
-
|
|
154
|
-
const deviceMsg = Buffer.concat([
|
|
155
|
-
account.deviceSignature =
|
|
156
|
-
const identity =
|
|
157
|
-
const accountEnc =
|
|
158
|
-
const deviceIdentity =
|
|
117
|
+
const devicePrefix = isHostedAccount ? Buffer.from([6, 6]) : Buffer.from([6, 1]);
|
|
118
|
+
const deviceMsg = Buffer.concat([devicePrefix, deviceDetails, signedIdentityKey.public, accountSignatureKey]);
|
|
119
|
+
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
120
|
+
const identity = createSignalIdentity(jid, accountSignatureKey);
|
|
121
|
+
const accountEnc = encodeSignedDeviceIdentity(account, false);
|
|
122
|
+
const deviceIdentity = proto.ADVDeviceIdentity.decode(account.details);
|
|
159
123
|
const reply = {
|
|
160
124
|
tag: 'iq',
|
|
161
125
|
attrs: {
|
|
162
|
-
to:
|
|
126
|
+
to: S_WHATSAPP_NET,
|
|
163
127
|
type: 'result',
|
|
164
|
-
id: msgId
|
|
128
|
+
id: msgId
|
|
165
129
|
},
|
|
166
130
|
content: [
|
|
167
131
|
{
|
|
@@ -180,28 +144,21 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
180
144
|
const authUpdate = {
|
|
181
145
|
account,
|
|
182
146
|
me: { id: jid, name: bizName },
|
|
183
|
-
signalIdentities: [
|
|
184
|
-
|
|
185
|
-
identity
|
|
186
|
-
],
|
|
187
|
-
platform: platformNode === null || platformNode === void 0 ? void 0 : platformNode.attrs.name
|
|
147
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
148
|
+
platform: platformNode?.attrs.name
|
|
188
149
|
};
|
|
189
150
|
return {
|
|
190
151
|
creds: authUpdate,
|
|
191
152
|
reply
|
|
192
153
|
};
|
|
193
154
|
};
|
|
194
|
-
|
|
195
|
-
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
196
|
-
var _a;
|
|
155
|
+
export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
197
156
|
account = { ...account };
|
|
198
157
|
// set to null if we are not to include the signature key
|
|
199
158
|
// or if we are including the signature key but it is empty
|
|
200
|
-
if (!includeSignatureKey || !
|
|
159
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
201
160
|
account.accountSignatureKey = null;
|
|
202
161
|
}
|
|
203
|
-
return
|
|
204
|
-
.encode(account)
|
|
205
|
-
.finish();
|
|
162
|
+
return proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
206
163
|
};
|
|
207
|
-
|
|
164
|
+
//# sourceMappingURL=validate-connection.js.map
|