@itsliaaa/baileys 0.1.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 +22 -0
- package/README.md +1078 -0
- package/WAProto/index.js +100441 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +144 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.js +402 -0
- package/lib/Signal/lid-mapping.js +270 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.js +378 -0
- package/lib/Socket/chats.js +1048 -0
- package/lib/Socket/communities.js +430 -0
- package/lib/Socket/groups.js +328 -0
- package/lib/Socket/index.js +11 -0
- package/lib/Socket/messages-recv.js +1442 -0
- package/lib/Socket/messages-send.js +1153 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.js +227 -0
- package/lib/Socket/socket.js +936 -0
- package/lib/Store/index.js +3 -0
- package/lib/Store/make-in-memory-store.js +421 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Newsletter.js +33 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.js +25 -0
- package/lib/Utils/auth-utils.js +289 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.js +811 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.js +282 -0
- package/lib/Utils/event-buffer.js +573 -0
- package/lib/Utils/generics.js +385 -0
- package/lib/Utils/history.js +130 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.js +19 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-retry-manager.js +224 -0
- package/lib/Utils/messages-media.js +789 -0
- package/lib/Utils/messages.js +1832 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.js +527 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/signal.js +158 -0
- package/lib/Utils/sync-action-utils.js +47 -0
- package/lib/Utils/tc-token-utils.js +17 -0
- package/lib/Utils/use-multi-file-auth-state.js +120 -0
- package/lib/Utils/validate-connection.js +206 -0
- package/lib/WABinary/constants.js +1300 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.js +197 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.js +4 -0
- package/lib/WAUSync/USyncQuery.js +93 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/index.js +11 -0
- package/package.json +72 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import { KEY_BUNDLE_TYPE, WA_ADV_ACCOUNT_SIG_PREFIX, WA_ADV_DEVICE_SIG_PREFIX, WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX } 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';
|
|
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: config.browser[1].toLocaleLowerCase().includes('android')
|
|
17
|
+
? proto.ClientPayload.UserAgent.Platform.ANDROID
|
|
18
|
+
: proto.ClientPayload.UserAgent.Platform.WEB,
|
|
19
|
+
releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
20
|
+
osVersion: '0.1',
|
|
21
|
+
device: 'Desktop',
|
|
22
|
+
osBuildNumber: '0.1',
|
|
23
|
+
localeLanguageIso6391: 'en',
|
|
24
|
+
mnc: '000',
|
|
25
|
+
mcc: '000',
|
|
26
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const PLATFORM_MAP = {
|
|
30
|
+
'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
31
|
+
Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
32
|
+
};
|
|
33
|
+
const getWebInfo = (config) => {
|
|
34
|
+
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
35
|
+
if (config.syncFullHistory &&
|
|
36
|
+
PLATFORM_MAP[config.browser[0]] &&
|
|
37
|
+
config.browser[1] === 'Desktop') {
|
|
38
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
39
|
+
}
|
|
40
|
+
return { webSubPlatform };
|
|
41
|
+
};
|
|
42
|
+
const getClientPayload = (config) => {
|
|
43
|
+
const payload = {
|
|
44
|
+
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
45
|
+
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
46
|
+
userAgent: getUserAgent(config)
|
|
47
|
+
};
|
|
48
|
+
if (!config.browser[1].toLocaleLowerCase().includes('android')) {
|
|
49
|
+
payload.webInfo = getWebInfo(config);
|
|
50
|
+
}
|
|
51
|
+
return payload;
|
|
52
|
+
};
|
|
53
|
+
export const generateLoginNode = (userJid, config) => {
|
|
54
|
+
const { user, device } = jidDecode(userJid);
|
|
55
|
+
const payload = {
|
|
56
|
+
...getClientPayload(config),
|
|
57
|
+
passive: true,
|
|
58
|
+
pull: true,
|
|
59
|
+
username: +user,
|
|
60
|
+
device: device,
|
|
61
|
+
// TODO: investigate (hard set as false atm)
|
|
62
|
+
lidDbMigrated: false
|
|
63
|
+
};
|
|
64
|
+
return proto.ClientPayload.fromObject(payload);
|
|
65
|
+
};
|
|
66
|
+
const getPlatformType = (platform) => {
|
|
67
|
+
const platformType = platform.toUpperCase();
|
|
68
|
+
if (platformType === 'ANDROID') {
|
|
69
|
+
return proto.DeviceProps.PlatformType.ANDROID_PHONE;
|
|
70
|
+
}
|
|
71
|
+
return (proto.DeviceProps.PlatformType[platformType] ||
|
|
72
|
+
proto.DeviceProps.PlatformType.CHROME);
|
|
73
|
+
};
|
|
74
|
+
export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
75
|
+
// the app version needs to be md5 hashed
|
|
76
|
+
// and passed in
|
|
77
|
+
const appVersionBuf = createHash('md5')
|
|
78
|
+
.update(config.version.join('.')) // join as string
|
|
79
|
+
.digest();
|
|
80
|
+
const companion = {
|
|
81
|
+
os: config.browser[0],
|
|
82
|
+
platformType: getPlatformType(config.browser[1]),
|
|
83
|
+
requireFullSync: config.syncFullHistory,
|
|
84
|
+
historySyncConfig: {
|
|
85
|
+
storageQuotaMb: 10240,
|
|
86
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
87
|
+
recentSyncDaysLimit: undefined,
|
|
88
|
+
supportCallLogHistory: false,
|
|
89
|
+
supportBotUserAgentChatHistory: true,
|
|
90
|
+
supportCagReactionsAndPolls: true,
|
|
91
|
+
supportBizHostedMsg: true,
|
|
92
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
93
|
+
supportHostedGroupMsg: true,
|
|
94
|
+
supportFbidBotChatHistory: true,
|
|
95
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
96
|
+
supportMessageAssociation: true,
|
|
97
|
+
supportGroupHistory: false,
|
|
98
|
+
onDemandReady: undefined,
|
|
99
|
+
supportGuestChat: undefined
|
|
100
|
+
},
|
|
101
|
+
version: {
|
|
102
|
+
primary: 10,
|
|
103
|
+
secondary: 15,
|
|
104
|
+
tertiary: 7
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const companionProto = proto.DeviceProps.encode(companion).finish();
|
|
108
|
+
const registerPayload = {
|
|
109
|
+
...getClientPayload(config),
|
|
110
|
+
passive: false,
|
|
111
|
+
pull: false,
|
|
112
|
+
devicePairingData: {
|
|
113
|
+
buildHash: appVersionBuf,
|
|
114
|
+
deviceProps: companionProto,
|
|
115
|
+
eRegid: encodeBigEndian(registrationId),
|
|
116
|
+
eKeytype: KEY_BUNDLE_TYPE,
|
|
117
|
+
eIdent: signedIdentityKey.public,
|
|
118
|
+
eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
|
|
119
|
+
eSkeyVal: signedPreKey.keyPair.public,
|
|
120
|
+
eSkeySig: signedPreKey.signature
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return proto.ClientPayload.fromObject(registerPayload);
|
|
124
|
+
};
|
|
125
|
+
export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
126
|
+
const msgId = stanza.attrs.id;
|
|
127
|
+
const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success');
|
|
128
|
+
const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity');
|
|
129
|
+
const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform');
|
|
130
|
+
const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device');
|
|
131
|
+
const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz');
|
|
132
|
+
if (!deviceIdentityNode || !deviceNode) {
|
|
133
|
+
throw new Boom('Missing device-identity or device in pair success node', { data: stanza });
|
|
134
|
+
}
|
|
135
|
+
const bizName = businessNode?.attrs.name;
|
|
136
|
+
const jid = deviceNode.attrs.jid;
|
|
137
|
+
const lid = deviceNode.attrs.lid;
|
|
138
|
+
const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
139
|
+
let hmacPrefix = Buffer.from([]);
|
|
140
|
+
if (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED) {
|
|
141
|
+
hmacPrefix = WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
|
|
142
|
+
}
|
|
143
|
+
const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
144
|
+
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
145
|
+
throw new Boom('Invalid account signature');
|
|
146
|
+
}
|
|
147
|
+
const account = proto.ADVSignedDeviceIdentity.decode(details);
|
|
148
|
+
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
149
|
+
const deviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails);
|
|
150
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
|
|
151
|
+
? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
152
|
+
: WA_ADV_ACCOUNT_SIG_PREFIX;
|
|
153
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
|
|
154
|
+
if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
155
|
+
throw new Boom('Failed to verify account signature');
|
|
156
|
+
}
|
|
157
|
+
const deviceMsg = Buffer.concat([
|
|
158
|
+
WA_ADV_DEVICE_SIG_PREFIX,
|
|
159
|
+
deviceDetails,
|
|
160
|
+
signedIdentityKey.public,
|
|
161
|
+
accountSignatureKey
|
|
162
|
+
]);
|
|
163
|
+
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
164
|
+
const identity = createSignalIdentity(lid, accountSignatureKey);
|
|
165
|
+
const accountEnc = encodeSignedDeviceIdentity(account, false);
|
|
166
|
+
const reply = {
|
|
167
|
+
tag: 'iq',
|
|
168
|
+
attrs: {
|
|
169
|
+
to: S_WHATSAPP_NET,
|
|
170
|
+
type: 'result',
|
|
171
|
+
id: msgId
|
|
172
|
+
},
|
|
173
|
+
content: [
|
|
174
|
+
{
|
|
175
|
+
tag: 'pair-device-sign',
|
|
176
|
+
attrs: {},
|
|
177
|
+
content: [
|
|
178
|
+
{
|
|
179
|
+
tag: 'device-identity',
|
|
180
|
+
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
181
|
+
content: accountEnc
|
|
182
|
+
}
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
};
|
|
187
|
+
const authUpdate = {
|
|
188
|
+
account,
|
|
189
|
+
me: { id: jid, name: bizName, lid },
|
|
190
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
191
|
+
platform: platformNode?.attrs.name
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
creds: authUpdate,
|
|
195
|
+
reply
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
199
|
+
account = { ...account };
|
|
200
|
+
// set to null if we are not to include the signature key
|
|
201
|
+
// or if we are including the signature key but it is empty
|
|
202
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
203
|
+
account.accountSignatureKey = null;
|
|
204
|
+
}
|
|
205
|
+
return proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
206
|
+
};
|