whalibmob 5.5.45 → 5.5.48

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/.env.example ADDED
@@ -0,0 +1,49 @@
1
+ # ─────────────────────────────────────────────────────────────────────────────
2
+ # whalibmob — Device Emulation Configuration
3
+ # Copy this file to .env in your project root and set the values you need.
4
+ # All variables are optional; defaults emulate an iPhone 15 Pro running iOS 17.
5
+ # ─────────────────────────────────────────────────────────────────────────────
6
+
7
+ # Operating system to emulate. Accepted values: ios | android
8
+ # Default: ios
9
+ # WA_OS=android
10
+
11
+ # Named device profile.
12
+ #
13
+ # iOS profiles (WA_OS=ios):
14
+ # iphone_15_pro, iphone_15, iphone_14_pro, iphone_14, iphone_13_pro,
15
+ # iphone_13, iphone_12_pro, iphone_12, iphone_11_pro, iphone_11,
16
+ # iphone_se3, iphone_xs
17
+ #
18
+ # Android profiles (WA_OS=android):
19
+ # pixel_8_pro, pixel_8, pixel_7, pixel_7a,
20
+ # samsung_s24_ultra, samsung_s24, samsung_s23_ultra, samsung_s23, samsung_a55,
21
+ # oneplus_12, oneplus_11, xiaomi_14, xiaomi_13, oppo_find_x7, realme_gt5
22
+ #
23
+ # Default: iphone_15_pro (or pixel_8_pro when WA_OS=android)
24
+ # WA_DEVICE=pixel_8_pro
25
+
26
+ # ── Custom device overrides (applied on top of the selected profile) ─────────
27
+ # Use these to fine-tune any field without creating a new profile.
28
+
29
+ # WA_DEVICE_MODEL=SM-S928B
30
+ # WA_DEVICE_MANUFACTURER=samsung
31
+ # WA_DEVICE_OS_VERSION=14
32
+ # WA_DEVICE_BUILD=UP1A.231005.007
33
+ # WA_DEVICE_MODEL_ID=samsung-sm-s928b
34
+
35
+ # ── Version & token overrides ─────────────────────────────────────────────────
36
+
37
+ # Pin the WhatsApp version string instead of fetching the latest from the store.
38
+ # Format: 2.x.x.x (four-part)
39
+ # WA_VERSION=2.24.13.80
40
+
41
+ # Override the static token used in registration token computation.
42
+ # Only needed if WhatsApp rotates the bundled token.
43
+ # WA_STATIC_TOKEN=Y29Cs6AVNR2bj5PBeKSYFd1nAKuvNQ3h
44
+
45
+ # ── Proxy / Tor ───────────────────────────────────────────────────────────────
46
+
47
+ # Route registration HTTP traffic through a SOCKS5 proxy or Tor.
48
+ # TOR_PROXY=socks5://127.0.0.1:9050
49
+ # SOCKS_PROXY=socks5://user:pass@proxy.example.com:1080
@@ -59,29 +59,6 @@ function phoneFromJid(jid) {
59
59
  return user;
60
60
  }
61
61
 
62
- // ─── JID object → string (device-preserving) ─────────────────────────────────
63
- //
64
- // The WA binary decoder produces AD_JID objects with shape:
65
- // { user: 'N', agent: A, device: D, server: 's.whatsapp.net' }
66
- // The built-in toString() on these objects returns "N@server" — dropping the
67
- // device number. Always use jidObjToStr() when stringifying a JID that may
68
- // have come from the binary decoder (e.g. response node attrs.jid).
69
- //
70
- // This is the root cause of the multi-device fanout bug: fetchBundles was
71
- // calling String(jidRaw) and getting the same "N@s.whatsapp.net" key for all
72
- // four response bundles (device 0, 13, 14, 15), causing the Map to overwrite
73
- // itself three times and return count=1 instead of count=4.
74
- //
75
- function jidObjToStr(jidRaw) {
76
- if (typeof jidRaw === 'string') return jidRaw;
77
- if (!jidRaw) return '';
78
- const user = String(jidRaw.user || '');
79
- const server = String(jidRaw.server || 's.whatsapp.net');
80
- const device = parseInt(jidRaw.device, 10) || 0;
81
- if (device > 0) return `${user}:${device}@${server}`;
82
- return `${user}@${server}`;
83
- }
84
-
85
62
  // ─── Bundle parsing ───────────────────────────────────────────────────────────
86
63
 
87
64
  function findChild(node, desc) {
@@ -376,11 +353,8 @@ class DeviceManager {
376
353
  if (!userNode || userNode.description !== 'user') continue;
377
354
  const jidRaw = userNode.attrs && userNode.attrs.jid;
378
355
  if (!jidRaw) continue;
379
- // Use jidObjToStr (NOT String()) so the device number is preserved from
380
- // the binary-decoded AD_JID object. String() / toString() only returns
381
- // "user@server", losing the ":device" part — which caused all 4 per-device
382
- // bundles to overwrite each other in the Map, producing count=1.
383
- const jidStr = jidObjToStr(jidRaw);
356
+ // Always normalise to a string key so Map lookups are consistent
357
+ const jidStr = String(jidRaw);
384
358
  _whaDbg('[DBG] FETCH_BUNDLES_USER jid=' + jidStr +
385
359
  ' childTags=' + (Array.isArray(userNode.content)
386
360
  ? userNode.content.map(c => c && c.description).filter(Boolean).join(',')
@@ -715,66 +689,31 @@ class DeviceManager {
715
689
  }
716
690
 
717
691
  if (allowPkmsg && fetchJids.length > 0) {
718
- // ── parseAndInjectE2ESessions pattern (Baileys-equivalent) ─────────────
719
- //
720
- // The WA server responds to bundle-fetch IQs for LID device JIDs
721
- // (e.g. 112713111982325:13@lid) only for device 0 — device-specific
722
- // @lid JIDs are silently ignored and the server returns a single bundle
723
- // for the primary device only.
724
- //
725
- // SOLUTION: fetch bundles using PN (phone number) AD_JID format instead
726
- // — the server responds to "40756469325:13@s.whatsapp.net" correctly and
727
- // returns all four device bundles. We then build the Signal sessions
728
- // keyed by the corresponding LID device JID ("112713111982325:13@lid")
729
- // so that MessageSender finds them when encrypting for the @lid routing
730
- // address. This is the same principle as Baileys' parseAndInjectE2ESessions:
731
- // separate "where to fetch the bundle from" and "what JID to key the session under".
732
- //
733
- const pnForLid = this._client._lidToPn && this._client._lidToPn.get(lidUser);
734
-
735
- let bundleFetchJids;
736
- if (pnForLid) {
737
- // Build PN AD_JID fetch list matching each LID device JID by device number.
738
- bundleFetchJids = fetchJids.map(lidDevJid => {
739
- const { device } = stripUser(lidDevJid);
740
- return makeDeviceJid(pnForLid, device);
741
- });
742
- _whaDbg('[DBG] LID_PN_FETCH pn=' + pnForLid +
743
- ' jids=[' + bundleFetchJids.join(',') + ']\n');
744
- } else {
745
- // No PN known — fall back to LID JIDs (may only return device 0)
746
- bundleFetchJids = fetchJids;
747
- _whaDbg('[DBG] LID_FALLBACK_FETCH no-pn jids=[' + fetchJids.join(',') + ']\n');
748
- }
749
-
750
- const bundles = await this.fetchBundles(bundleFetchJids);
751
-
752
- for (const [bundleJid, bundle] of bundles) {
753
- // Determine the LID session JID for this device.
754
- // If we fetched by PN, bundleJid is "40756469325:13@s.whatsapp.net"
755
- // → extract device number → build "112713111982325:13@lid"
756
- // If we fetched by LID, bundleJid is "112713111982325@s.whatsapp.net"
757
- // → strip server → append @lid
758
- let lidDevJid;
759
- if (pnForLid) {
760
- const { device } = stripUser(bundleJid);
761
- lidDevJid = makeDeviceJid(lidUser, device, 'lid');
762
- } else {
763
- const jidBase = bundleJid.replace(/@(?:s\.whatsapp\.net|lid)$/, '');
764
- lidDevJid = jidBase + '@lid';
765
- }
766
-
692
+ const bundles = await this.fetchBundles(fetchJids);
693
+ for (const [jid, bundle] of bundles) {
767
694
  try {
768
- // Build (or overwrite) the Signal session keyed by the LID device JID.
769
- // The session address is (user, device) @server suffix is stripped
770
- // internally so "112713111982325:13@lid" and "112713111982325:13@s.whatsapp.net"
771
- // resolve to the same Signal address. We always push @lid form so the
772
- // participants node is consistent with the outer message routing address.
773
- await signalProto.buildSessionFromBundle(lidDevJid, bundle);
774
- readyJids.push(lidDevJid);
775
- _whaDbg('[DBG] LID_SESSION_BUILT bundle=' + bundleJid + ' → participant=' + lidDevJid);
695
+ await signalProto.buildSessionFromBundle(jid, bundle);
696
+ // ── CRITICAL: remap bundle JID back to @lid format ────────────────────
697
+ // fetchBundles always returns JIDs in @s.whatsapp.net format (because the
698
+ // WA server uses its own AD_JID / JID_PAIR encoding in responses).
699
+ // But the outer <message to="lidUser@lid"> requires ALL participant <to>
700
+ // nodes to also use @lid format — mixing @s.whatsapp.net participants with
701
+ // a @lid routing address causes the server to close the connection.
702
+ //
703
+ // The Signal session address is keyed only by (user, device) — the @server
704
+ // suffix is stripped by jidToAddress() — so the session is reachable via
705
+ // either @lid or @s.whatsapp.net. We push the @lid form so the participants
706
+ // node is consistent with the routing.
707
+ //
708
+ // Mapping: strip @s.whatsapp.net / @lid suffix from jid, re-append @lid
709
+ // e.g. "112713111982325@s.whatsapp.net" → "112713111982325@lid"
710
+ // "112713111982325:2@s.whatsapp.net" → "112713111982325:2@lid"
711
+ const jidBase = jid.replace(/@(?:s\.whatsapp\.net|lid)$/, '');
712
+ const lidJidForDevice = jidBase + '@lid';
713
+ readyJids.push(lidJidForDevice);
714
+ _whaDbg('[DBG] LID_SESSION_BUILT jid=' + jid + ' → participant=' + lidJidForDevice);
776
715
  } catch (e) {
777
- _whaDbg('[DBG] LID_SESSION_ERR jid=' + lidDevJid + ' err=' + e.message);
716
+ _whaDbg('[DBG] LID_SESSION_ERR jid=' + jid + ' err=' + e.message);
778
717
  }
779
718
  }
780
719
  }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
+
1
2
  {
2
3
  "name": "whalibmob",
3
- "version": "5.5.45",
4
+ "version": "5.5.48",
4
5
  "description": "WhatsApp library for interaction with WhatsApp Mobile API no web",
5
6
  "author": "Kunboruto50",
6
7
  "main": "index.js",