Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jajbshjahavahh
GitHub Repository: jajbshjahavahh/Gojo-Satoru
Path: blob/master/node_modules/@adiwajshing/baileys/lib/Utils/validate-connection.js
2593 views
1
"use strict";
2
Object.defineProperty(exports, "__esModule", { value: true });
3
exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
4
const boom_1 = require("@hapi/boom");
5
const WAProto_1 = require("../../WAProto");
6
const WABinary_1 = require("../WABinary");
7
const crypto_1 = require("./crypto");
8
const generics_1 = require("./generics");
9
const signal_1 = require("./signal");
10
const ENCODED_VERSION = 'S9Kdc4pc4EJryo21snc5cg==';
11
const getUserAgent = ({ version, browser }) => ({
12
appVersion: {
13
primary: version[0],
14
secondary: version[1],
15
tertiary: version[2],
16
},
17
platform: 14,
18
releaseChannel: 0,
19
mcc: '000',
20
mnc: '000',
21
osVersion: browser[2],
22
manufacturer: '',
23
device: browser[1],
24
osBuildNumber: '0.1',
25
localeLanguageIso6391: 'en',
26
localeCountryIso31661Alpha2: 'en',
27
});
28
const generateLoginNode = (userJid, config) => {
29
const { user, device } = WABinary_1.jidDecode(userJid);
30
const payload = {
31
passive: true,
32
connectType: 1,
33
connectReason: 1,
34
userAgent: getUserAgent(config),
35
webInfo: { webSubPlatform: 0 },
36
username: parseInt(user, 10),
37
device: device,
38
};
39
return WAProto_1.proto.ClientPayload.encode(payload).finish();
40
};
41
exports.generateLoginNode = generateLoginNode;
42
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
43
const appVersionBuf = new Uint8Array(Buffer.from(ENCODED_VERSION, 'base64'));
44
const companion = {
45
os: config.browser[0],
46
version: {
47
primary: 10,
48
secondary: undefined,
49
tertiary: undefined,
50
},
51
platformType: 1,
52
requireFullSync: false,
53
};
54
const companionProto = WAProto_1.proto.CompanionProps.encode(companion).finish();
55
const registerPayload = {
56
connectReason: 1,
57
connectType: 1,
58
passive: false,
59
regData: {
60
buildHash: appVersionBuf,
61
companionProps: companionProto,
62
eRegid: generics_1.encodeInt(4, registrationId),
63
eKeytype: generics_1.encodeInt(1, 5),
64
eIdent: signedIdentityKey.public,
65
eSkeyId: generics_1.encodeInt(3, signedPreKey.keyId),
66
eSkeyVal: signedPreKey.keyPair.public,
67
eSkeySig: signedPreKey.signature,
68
},
69
userAgent: getUserAgent(config),
70
webInfo: {
71
webSubPlatform: 0,
72
},
73
};
74
return WAProto_1.proto.ClientPayload.encode(registerPayload).finish();
75
};
76
exports.generateRegistrationNode = generateRegistrationNode;
77
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
78
var _a, _b, _c, _d, _e;
79
const [pair] = WABinary_1.getAllBinaryNodeChildren(stanza);
80
const pairContent = Array.isArray(pair.content) ? pair.content : [];
81
const msgId = stanza.attrs.id;
82
const deviceIdentity = (_a = pairContent.find(m => m.tag === 'device-identity')) === null || _a === void 0 ? void 0 : _a.content;
83
const businessName = (_c = (_b = pairContent.find(m => m.tag === 'biz')) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.name;
84
const verifiedName = businessName || '';
85
const jid = (_e = (_d = pairContent.find(m => m.tag === 'device')) === null || _d === void 0 ? void 0 : _d.attrs) === null || _e === void 0 ? void 0 : _e.jid;
86
const { details, hmac } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentity);
87
const advSign = crypto_1.hmacSign(details, Buffer.from(advSecretKey, 'base64'));
88
if (Buffer.compare(hmac, advSign) !== 0) {
89
throw new boom_1.Boom('Invalid pairing');
90
}
91
const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
92
const { accountSignatureKey, accountSignature } = account;
93
const accountMsg = WABinary_1.Binary.build(new Uint8Array([6, 0]), account.details, signedIdentityKey.public).readByteArray();
94
if (!crypto_1.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
95
throw new boom_1.Boom('Failed to verify account signature');
96
}
97
const deviceMsg = WABinary_1.Binary.build(new Uint8Array([6, 1]), account.details, signedIdentityKey.public, account.accountSignatureKey).readByteArray();
98
account.deviceSignature = crypto_1.Curve.sign(signedIdentityKey.private, deviceMsg);
99
const identity = signal_1.createSignalIdentity(jid, accountSignatureKey);
100
const keyIndex = WAProto_1.proto.ADVDeviceIdentity.decode(account.details).keyIndex;
101
const accountEnc = WAProto_1.proto.ADVSignedDeviceIdentity.encode({
102
...account.toJSON(),
103
accountSignatureKey: undefined
104
}).finish();
105
const reply = {
106
tag: 'iq',
107
attrs: {
108
to: WABinary_1.S_WHATSAPP_NET,
109
type: 'result',
110
id: msgId,
111
},
112
content: [
113
{
114
tag: 'pair-device-sign',
115
attrs: {},
116
content: [
117
{ tag: 'device-identity', attrs: { 'key-index': `${keyIndex}` }, content: accountEnc }
118
]
119
}
120
]
121
};
122
const authUpdate = {
123
account,
124
me: { id: jid, verifiedName },
125
signalIdentities: [...(signalIdentities || []), identity]
126
};
127
return {
128
creds: authUpdate,
129
reply
130
};
131
};
132
exports.configureSuccessfulPairing = configureSuccessfulPairing;
133
134