whalibmob 5.12.13 → 5.12.14
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/Registration.js +24 -16
- package/package.json +1 -1
package/lib/Registration.js
CHANGED
|
@@ -137,7 +137,7 @@ function socksProxyUrl() {
|
|
|
137
137
|
return process.env.TOR_PROXY || process.env.SOCKS_PROXY || '';
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
async function httpPostViaSocks(path, body, waVersion, proxyUrl, authHeader) {
|
|
140
|
+
async function httpPostViaSocks(path, body, waVersion, proxyUrl, authHeader, device) {
|
|
141
141
|
const proxy = parseSocksProxy(proxyUrl);
|
|
142
142
|
const dHost = 'v.whatsapp.net';
|
|
143
143
|
const dPort = 443;
|
|
@@ -164,7 +164,7 @@ async function httpPostViaSocks(path, body, waVersion, proxyUrl, authHeader) {
|
|
|
164
164
|
tlsSocket.once('error', rej);
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
-
const headers = registrationHeaders(getDeviceConfig(), waVersion);
|
|
167
|
+
const headers = registrationHeaders(device || getDeviceConfig(), waVersion);
|
|
168
168
|
const reqLines = [
|
|
169
169
|
`POST /v2${path} HTTP/1.1`,
|
|
170
170
|
`Host: ${dHost}`,
|
|
@@ -590,9 +590,9 @@ function tryLoadAndroidMaterial() {
|
|
|
590
590
|
* A no-op on iOS, and WA_NO_APK_DOWNLOAD=1 turns it off for anyone who would
|
|
591
591
|
* rather a hundred megabytes were never fetched without being asked for.
|
|
592
592
|
*/
|
|
593
|
-
async function ensureAndroidMaterial(opts) {
|
|
593
|
+
async function ensureAndroidMaterial(opts, device) {
|
|
594
594
|
opts = opts || {};
|
|
595
|
-
|
|
595
|
+
device = device || getDeviceConfig();
|
|
596
596
|
if (device.os !== 'android') return null;
|
|
597
597
|
|
|
598
598
|
try {
|
|
@@ -676,8 +676,8 @@ function loadAndroidMaterial() {
|
|
|
676
676
|
return _androidMaterial;
|
|
677
677
|
}
|
|
678
678
|
|
|
679
|
-
function computeToken(waVersion, national) {
|
|
680
|
-
|
|
679
|
+
function computeToken(waVersion, national, device) {
|
|
680
|
+
device = device || getDeviceConfig();
|
|
681
681
|
if (device.os === 'android') {
|
|
682
682
|
return AndroidApk.computeToken(loadAndroidMaterial(), national);
|
|
683
683
|
}
|
|
@@ -817,8 +817,8 @@ function toBase64Url(buf) {
|
|
|
817
817
|
async function buildPayload(store, waVersion, useToken, extraPairs) {
|
|
818
818
|
const { cc, national } = parsePhone(store.phoneNumber);
|
|
819
819
|
const meta = getCountryMeta(cc);
|
|
820
|
-
const token = useToken ? computeToken(waVersion, national) : null;
|
|
821
820
|
const device = store.device || getDeviceConfig();
|
|
821
|
+
const token = useToken ? computeToken(waVersion, national, device) : null;
|
|
822
822
|
// Android formats fdid lowercase, iOS uppercase (matches the native clients).
|
|
823
823
|
const fdid = device.os === 'android'
|
|
824
824
|
? store.fdid.toLowerCase()
|
|
@@ -874,14 +874,14 @@ function encryptPayload(plaintext) {
|
|
|
874
874
|
|
|
875
875
|
// ---------- HTTP ----------
|
|
876
876
|
|
|
877
|
-
function httpPost(path, body, waVersion, authHeader) {
|
|
877
|
+
function httpPost(path, body, waVersion, authHeader, device) {
|
|
878
878
|
const proxy = socksProxyUrl();
|
|
879
|
-
if (proxy) return httpPostViaSocks(path, body, waVersion, proxy, authHeader);
|
|
879
|
+
if (proxy) return httpPostViaSocks(path, body, waVersion, proxy, authHeader, device);
|
|
880
880
|
|
|
881
881
|
return new Promise((resolve, reject) => {
|
|
882
882
|
const bodyBuf = Buffer.from(body, 'utf8');
|
|
883
883
|
const headers = Object.assign(
|
|
884
|
-
registrationHeaders(getDeviceConfig(), waVersion),
|
|
884
|
+
registrationHeaders(device || getDeviceConfig(), waVersion),
|
|
885
885
|
{ 'Content-Length': bodyBuf.length }
|
|
886
886
|
);
|
|
887
887
|
// Attestation cert-chain / App Attest header (Android cert chain, iOS
|
|
@@ -943,7 +943,7 @@ async function sendEncrypted(path, plaintext, store, waVersion) {
|
|
|
943
943
|
|
|
944
944
|
_whaDbg('[DBG] REG → ' + path + ' (' + body.length + ' bytes' +
|
|
945
945
|
(bodyAtt.bodyAttestation ? ', attested' : '') + ')');
|
|
946
|
-
const result = await httpPost(path, body, waVersion, bodyAtt.authorizationHeader);
|
|
946
|
+
const result = await httpPost(path, body, waVersion, bodyAtt.authorizationHeader, device);
|
|
947
947
|
_whaDbg('[DBG] REG ← ' + path + ' ' +
|
|
948
948
|
(result && result.status ? result.status : JSON.stringify(result).slice(0, 120)) +
|
|
949
949
|
(result && result.reason ? ' reason=' + result.reason : ''));
|
|
@@ -1193,7 +1193,7 @@ async function handle2FA(store, waVersion, opts) {
|
|
|
1193
1193
|
// ---------- Public API ----------
|
|
1194
1194
|
|
|
1195
1195
|
async function checkIfRegistered(store) {
|
|
1196
|
-
const waVersion = await fetchWaVersion(getDeviceConfig());
|
|
1196
|
+
const waVersion = await fetchWaVersion(store.device || getDeviceConfig());
|
|
1197
1197
|
return sendRequest('/exist', store, waVersion, false, null);
|
|
1198
1198
|
}
|
|
1199
1199
|
|
|
@@ -1333,8 +1333,12 @@ async function requestSmsCode(store, method, opts) {
|
|
|
1333
1333
|
opts = opts || {};
|
|
1334
1334
|
// Before the version is read, since on Android the version comes out of the
|
|
1335
1335
|
// APK this fetches.
|
|
1336
|
-
|
|
1337
|
-
|
|
1336
|
+
// What a session registered as is settled when it is created, so it is the
|
|
1337
|
+
// store that decides — not whatever WA_OS the shell happens to carry now. A
|
|
1338
|
+
// confirmation run from a shell without the variables would otherwise sign an
|
|
1339
|
+
// Android registration with an iOS token.
|
|
1340
|
+
const _device = store.device || getDeviceConfig();
|
|
1341
|
+
await ensureAndroidMaterial(opts, _device);
|
|
1338
1342
|
const waVersion = await fetchWaVersion(_device);
|
|
1339
1343
|
store.version = waVersion;
|
|
1340
1344
|
store.device = _device;
|
|
@@ -1455,8 +1459,12 @@ async function verifyCode(store, code, opts) {
|
|
|
1455
1459
|
opts = opts || {};
|
|
1456
1460
|
// Normally already there from the code request, but a confirmation can be run
|
|
1457
1461
|
// from a fresh shell that never made one.
|
|
1458
|
-
|
|
1459
|
-
|
|
1462
|
+
// What a session registered as is settled when it is created, so it is the
|
|
1463
|
+
// store that decides — not whatever WA_OS the shell happens to carry now. A
|
|
1464
|
+
// confirmation run from a shell without the variables would otherwise sign an
|
|
1465
|
+
// Android registration with an iOS token.
|
|
1466
|
+
const _device = store.device || getDeviceConfig();
|
|
1467
|
+
await ensureAndroidMaterial(opts, _device);
|
|
1460
1468
|
const waVersion = await fetchWaVersion(_device);
|
|
1461
1469
|
store.version = waVersion;
|
|
1462
1470
|
store.device = _device;
|