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