whalibmob 5.5.24 → 5.5.25

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.
Files changed (2) hide show
  1. package/lib/Store.js +60 -19
  2. package/package.json +2 -2
package/lib/Store.js CHANGED
@@ -47,12 +47,12 @@ function sign(privKey32, message) {
47
47
  // ─────────────────────────────────────────────────────────
48
48
 
49
49
  function createNewStore(phoneNumber) {
50
- const noiseKeyPair = generateKeyPair();
51
- const identityKeyPair = generateKeyPair();
50
+ const noiseKeyPair = generateKeyPair();
51
+ const identityKeyPair = generateKeyPair();
52
52
  const signedPreKeyPair = generateKeyPair();
53
53
 
54
54
  const signedPreKeyId = (crypto.randomBytes(3).readUIntBE(0, 3) & 0xffffff) || 1;
55
- const signature = sign(identityKeyPair.private, signedPreKeyPair.public);
55
+ const signature = sign(identityKeyPair.private, signedPreKeyPair.public);
56
56
 
57
57
  const registrationId = (crypto.randomBytes(2).readUInt16BE(0) & 0x3fff) + 1;
58
58
  const fdid = uuidv4();
@@ -62,8 +62,10 @@ function createNewStore(phoneNumber) {
62
62
  const device = getDeviceConfig();
63
63
  const version = device.os === 'android' ? ANDROID_VERSION_FALLBACK : IOS_VERSION_FALLBACK;
64
64
 
65
+ const normalizedPhone = String(phoneNumber || '').replace(/^\+/, '');
66
+
65
67
  return {
66
- phoneNumber: String(phoneNumber).replace(/^\+/, ''),
68
+ phoneNumber: normalizedPhone,
67
69
  noiseKeyPair,
68
70
  identityKeyPair,
69
71
  signedPreKey: {
@@ -92,8 +94,24 @@ function createNewStore(phoneNumber) {
92
94
  // ─────────────────────────────────────────────────────────
93
95
 
94
96
  function storeToJson(store) {
97
+ if (!store) {
98
+ throw new Error('storeToJson: store is undefined or null');
99
+ }
100
+
101
+ const normalizedPhone = store.phoneNumber
102
+ ? String(store.phoneNumber).replace(/^\+/, '')
103
+ : '';
104
+
105
+ const name = store.name || 'User';
106
+ const version = store.version || IOS_VERSION_FALLBACK;
107
+ const device = store.device ? Object.assign({}, IOS_DEVICE, store.device) : IOS_DEVICE;
108
+
109
+ const advIdentity = store.advIdentity
110
+ ? store.advIdentity.toString('base64')
111
+ : null;
112
+
95
113
  return {
96
- phoneNumber: store.phoneNumber,
114
+ phoneNumber: normalizedPhone,
97
115
  noiseKeyPair: {
98
116
  private: store.noiseKeyPair.private.toString('base64'),
99
117
  public: store.noiseKeyPair.public.toString('base64')
@@ -112,18 +130,24 @@ function storeToJson(store) {
112
130
  fdid: store.fdid,
113
131
  deviceId: store.deviceId.toString('base64'),
114
132
  identityId: store.identityId.toString('base64'),
115
- registered: store.registered,
133
+ registered: !!store.registered,
116
134
  codePending: store.codePending || false,
117
- name: store.name,
118
- version: store.version,
119
- device: store.device,
120
- advIdentity: store.advIdentity
121
- ? store.advIdentity.toString('base64')
122
- : null
135
+ name,
136
+ version,
137
+ device,
138
+ advIdentity
123
139
  };
124
140
  }
125
141
 
126
142
  function storeFromJson(obj) {
143
+ if (!obj) {
144
+ throw new Error('storeFromJson: input object is undefined or null');
145
+ }
146
+
147
+ const name = obj.name || 'User';
148
+ const version = obj.version || IOS_VERSION_FALLBACK;
149
+ const device = obj.device ? Object.assign({}, IOS_DEVICE, obj.device) : IOS_DEVICE;
150
+
127
151
  return {
128
152
  phoneNumber: obj.phoneNumber,
129
153
  noiseKeyPair: {
@@ -144,11 +168,11 @@ function storeFromJson(obj) {
144
168
  fdid: obj.fdid,
145
169
  deviceId: Buffer.from(obj.deviceId, 'base64'),
146
170
  identityId: Buffer.from(obj.identityId, 'base64'),
147
- registered: obj.registered,
171
+ registered: !!obj.registered,
148
172
  codePending: obj.codePending || false,
149
- name: obj.name || 'User',
150
- version: obj.version || IOS_VERSION_FALLBACK,
151
- device: obj.device ? Object.assign({}, IOS_DEVICE, obj.device) : IOS_DEVICE,
173
+ name,
174
+ version,
175
+ device,
152
176
  advIdentity: obj.advIdentity
153
177
  ? Buffer.from(obj.advIdentity, 'base64')
154
178
  : null
@@ -156,14 +180,23 @@ function storeFromJson(obj) {
156
180
  }
157
181
 
158
182
  function saveStore(store, filePath) {
183
+ // MAIN FIX: avoid crashing when called with undefined/null store
184
+ if (!store) {
185
+ console.warn('saveStore: called with empty store, skipping write for', filePath);
186
+ return;
187
+ }
188
+
159
189
  const dir = path.dirname(filePath);
160
190
  if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
161
- fs.writeFileSync(filePath, JSON.stringify(storeToJson(store), null, 2), 'utf8');
191
+
192
+ const json = storeToJson(store);
193
+ fs.writeFileSync(filePath, JSON.stringify(json, null, 2), 'utf8');
162
194
  }
163
195
 
164
196
  function loadStore(filePath) {
165
197
  if (!fs.existsSync(filePath)) return null;
166
- return storeFromJson(JSON.parse(fs.readFileSync(filePath, 'utf8')));
198
+ const raw = fs.readFileSync(filePath, 'utf8');
199
+ return storeFromJson(JSON.parse(raw));
167
200
  }
168
201
 
169
202
  // ─────────────────────────────────────────────────────────
@@ -171,8 +204,16 @@ function loadStore(filePath) {
171
204
  // ─────────────────────────────────────────────────────────
172
205
 
173
206
  function toSixParts(store) {
207
+ if (!store) {
208
+ throw new Error('toSixParts: store is undefined or null');
209
+ }
210
+
211
+ const normalizedPhone = store.phoneNumber
212
+ ? String(store.phoneNumber).replace(/^\+/, '')
213
+ : '';
214
+
174
215
  return [
175
- store.phoneNumber,
216
+ normalizedPhone,
176
217
  store.noiseKeyPair.public.toString('base64'),
177
218
  store.noiseKeyPair.private.toString('base64'),
178
219
  store.identityKeyPair.public.toString('base64'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whalibmob",
3
- "version": "5.5.24",
3
+ "version": "5.5.25",
4
4
  "description": "WhatsApp library for interaction with WhatsApp Mobile API no web",
5
5
  "author": "Kunboruto20",
6
6
  "main": "index.js",
@@ -48,4 +48,4 @@
48
48
  "async-mutex": "^0.5.0",
49
49
  "@cacheable/node-cache": "^3.0.1"
50
50
  }
51
- }
51
+ }