whalibmob 5.29.4 → 5.29.5

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.
@@ -986,18 +986,38 @@ function tryLoadAndroidMaterial(device) {
986
986
  * Silently ignoring WA_OS is how you end up watching an Android registration go
987
987
  * out under an iOS User-Agent and not knowing why.
988
988
  */
989
+ // A session's device identity, frozen for the whole registration.
990
+ //
991
+ // createNewStore captures the device when the session is created and writes it
992
+ // to disk with everything else, so a session always arrives here already
993
+ // carrying one. From that point it is frozen: /exist, /code, /register and
994
+ // every retry read this same identity, and no request can describe one handset
995
+ // while a sibling request in the same flow describes another.
996
+ //
997
+ // The bug this closes: the gate here used to be `registered || codePending`, so
998
+ // the very first /code of a session ignored the stored device and re-read it
999
+ // from the environment. /exist had already gone out as the stored device — an
1000
+ // Android/Samsung, say, loaded from the session file — and /code then went out
1001
+ // as the environment default (iOS/iPhone). One number, two phones, in one flow.
1002
+ // That is precisely the shape a "download the official app" block screen looks
1003
+ // for, and it was reproducible from the logs. See
1004
+ // test/registration-device-consistency.test.js.
1005
+ //
1006
+ // WA_OS / WA_BUSINESS therefore choose the device only for a session that does
1007
+ // not have one yet — which in practice means never, since createNewStore always
1008
+ // sets it. To change the platform of an existing session, start it over: delete
1009
+ // the session file, and the next createNewStore picks up the current WA_OS.
989
1010
  function deviceForRegistration(store, opts) {
990
1011
  const env = getDeviceConfig();
991
1012
  const stored = store && store.device;
992
- const settled = !!(store && (store.registered || store.codePending));
993
- if (!settled || !stored) return env;
1013
+ if (!stored || !stored.os) return env;
994
1014
 
995
1015
  const say = (opts && opts.onProgress) || (m => _whaDbg('[DBG] REG ' + m));
996
1016
 
997
1017
  if (stored.os !== env.os) {
998
1018
  say('note: this session was started as ' + stored.os + ', so it stays ' + stored.os +
999
- ' — WA_OS=' + env.os + ' does not apply to a number that is already part-way ' +
1000
- 'through registering. Delete the session file to start it over as ' + env.os + '.');
1019
+ ' — WA_OS=' + env.os + ' does not apply to a number that already has a ' +
1020
+ 'device. Delete the session file to start it over as ' + env.os + '.');
1001
1021
  }
1002
1022
 
1003
1023
  // The same rule for the variant: an account is created as Business or as
@@ -1007,13 +1027,36 @@ function deviceForRegistration(store, opts) {
1007
1027
  if (!!stored.business !== !!env.business) {
1008
1028
  say('note: this session was started as ' + (stored.business ? 'Business' : 'consumer') +
1009
1029
  ', so it stays that — WA_BUSINESS=' + (env.business ? '1' : '0') +
1010
- ' does not apply to a number that is already part-way through registering. ' +
1030
+ ' does not apply to a number that already has a device. ' +
1011
1031
  'Delete the session file to start it over.');
1012
1032
  }
1013
1033
 
1014
1034
  return stored;
1015
1035
  }
1016
1036
 
1037
+ // The device identity a request is about to go out with, logged so /exist and
1038
+ // /code can be compared side by side. Gated behind the debug channel — it costs
1039
+ // nothing when debug is off, and when a registration misbehaves it is the first
1040
+ // thing worth seeing. The User-Agent is built the same way the real request
1041
+ // builds it, so what this prints is what actually goes on the wire.
1042
+ function logDeviceIdentity(tag, store, waVersion) {
1043
+ const stored = store && store.device;
1044
+ const d = stored || getDeviceConfig();
1045
+ const ver = waVersion || (store && store.version) || '';
1046
+ let ua = '';
1047
+ try { ua = registrationHeaders(d, ver)['User-Agent']; } catch (_) {}
1048
+ _whaDbg('[DBG] DEVICE_IDENTITY ' + tag +
1049
+ ' os=' + d.os +
1050
+ ' osVersion=' + d.osVersion +
1051
+ ' manufacturer=' + (d.manufacturer || '-') +
1052
+ ' model=' + (d.model || d.modelId || '-') +
1053
+ ' modelId=' + (d.modelId || '-') +
1054
+ ' business=' + !!d.business +
1055
+ ' waVersion=' + (ver || '-') +
1056
+ ' source=' + (stored ? 'store.device (frozen)' : 'getDeviceConfig() (env/default)') +
1057
+ ' ua="' + ua + '"');
1058
+ }
1059
+
1017
1060
  /**
1018
1061
  * Have the Android token material ready, fetching the APK if it is not.
1019
1062
  *
@@ -1983,6 +2026,7 @@ async function assertRegistrationKeys(store, waVersion) {
1983
2026
 
1984
2027
  for (let attempt = 0; attempt < 2; attempt++) {
1985
2028
  try {
2029
+ logDeviceIdentity('before /exist', store, waVersion);
1986
2030
  const result = await sendRequest('/exist', store, waVersion, false, null);
1987
2031
  // reason === 'incorrect' → keys not found → fresh
1988
2032
  if (result && result.reason === 'incorrect') {
@@ -2087,6 +2131,7 @@ async function requestSmsCode(store, method, opts) {
2087
2131
  const verifyScreen = currentVerifyScreen(store);
2088
2132
  await sendFunnelLog(store, waVersion, verifyScreen, 'request_code', 'request_code_attempt');
2089
2133
 
2134
+ logDeviceIdentity('before /code', store, waVersion);
2090
2135
  const result = await sendRequest('/code', store, waVersion, true, extra);
2091
2136
 
2092
2137
  const status = result.status;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whalibmob",
3
- "version": "5.29.4",
3
+ "version": "5.29.5",
4
4
  "description": "Node.js library for WhatsApp — register a number over SMS, or link as a companion by QR. Signal E2E encryption, media, groups, channels.",
5
5
  "author": "Kunboruto20",
6
6
  "main": "index.js",