whalibmob 5.12.13 → 5.12.15
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/README.md +26 -0
- package/lib/Registration.js +24 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -300,6 +300,10 @@ WA_OS=android WA_DEVICE=samsung-s24-ultra wa registration --request-code 9196348
|
|
|
300
300
|
Set `WA_OS=android` in a `.env` file instead and the plain command is enough.
|
|
301
301
|
`--debug` prints every request and reply, which is worth having the first time.
|
|
302
302
|
|
|
303
|
+
The variables only matter for the command that *creates* the session. What a
|
|
304
|
+
session registered as is written into it, so the confirmation step and every
|
|
305
|
+
later connect follow the session, not whatever the shell carries at the time.
|
|
306
|
+
|
|
303
307
|
The CLI sends the code request, prints the result, and then **stays open** in the interactive shell. You will see:
|
|
304
308
|
|
|
305
309
|
```
|
|
@@ -1342,6 +1346,28 @@ registered session saved to /home/user/.waSession/919634847671.json
|
|
|
1342
1346
|
now run: /connect 919634847671
|
|
1343
1347
|
```
|
|
1344
1348
|
|
|
1349
|
+
**Registering as Android from the shell** works the same way, but `WA_OS` has to
|
|
1350
|
+
be set when the shell *starts* — the `wa>` prompt is already inside a running
|
|
1351
|
+
process, and nothing typed at it can change the environment that process was
|
|
1352
|
+
launched with:
|
|
1353
|
+
|
|
1354
|
+
```sh
|
|
1355
|
+
WA_OS=android WA_DEVICE=samsung-s24-ultra wa
|
|
1356
|
+
```
|
|
1357
|
+
```sh
|
|
1358
|
+
wa> /reg code 919634847671
|
|
1359
|
+
no Android token material yet — fetching the WhatsApp APK from Google Play
|
|
1360
|
+
...
|
|
1361
|
+
status sent
|
|
1362
|
+
wa> /reg confirm 919634847671 123456
|
|
1363
|
+
```
|
|
1364
|
+
|
|
1365
|
+
A `.env` file with `WA_OS=android` in the directory you start from does the same
|
|
1366
|
+
and saves the typing. Either way it only matters for the command that *creates*
|
|
1367
|
+
the session: what a session registered as is written into it, and every later
|
|
1368
|
+
step — the confirmation, a reconnect from a different shell tomorrow — follows
|
|
1369
|
+
the session rather than the environment.
|
|
1370
|
+
|
|
1345
1371
|
---
|
|
1346
1372
|
|
|
1347
1373
|
### Connection Commands (in-shell)
|
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;
|