whalibmob 5.40.38 → 5.40.39

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 (51) hide show
  1. package/README.md +1 -0
  2. package/cli.js +5 -4
  3. package/docs/events-history.md +47 -0
  4. package/index.d.ts +19 -0
  5. package/index.js +6 -0
  6. package/lib/AndroidApk.js +13 -12
  7. package/lib/BinaryNode.js +2 -1
  8. package/lib/Client.js +273 -269
  9. package/lib/CompanionPairing.js +3 -1
  10. package/lib/DeviceManager.js +2 -1
  11. package/lib/HistorySyncHandler.js +13 -11
  12. package/lib/MediaService.js +14 -12
  13. package/lib/OfflineNodeProcessor.js +3 -1
  14. package/lib/PairingCode.js +2 -1
  15. package/lib/PasskeyPairing.js +18 -17
  16. package/lib/PlayStore.js +15 -13
  17. package/lib/PrimaryLinkCrypto.js +2 -1
  18. package/lib/Registration.js +37 -35
  19. package/lib/Store.js +6 -5
  20. package/lib/WebSocketStream.js +3 -2
  21. package/lib/WebVersion.js +5 -3
  22. package/lib/apns-courier.js +15 -13
  23. package/lib/apns.js +6 -4
  24. package/lib/argo/ArgoDecoder.js +16 -14
  25. package/lib/auth-utils.js +10 -9
  26. package/lib/cli/linkCommands.js +5 -2
  27. package/lib/curve.js +5 -4
  28. package/lib/errors.js +42 -0
  29. package/lib/fcm.js +7 -5
  30. package/lib/image/JpegEncoder.js +4 -2
  31. package/lib/messages/MediaRetry.js +3 -2
  32. package/lib/messages/MessageSecret.js +9 -8
  33. package/lib/messages/MessageSender.js +30 -28
  34. package/lib/noise.js +13 -11
  35. package/lib/plist.js +18 -15
  36. package/lib/primary/HistoryExport.js +2 -1
  37. package/lib/primary/MessageStore.js +8 -2
  38. package/lib/proto/MessageProto.js +3 -1
  39. package/lib/signal/SenderKey.js +5 -4
  40. package/lib/signal/WaSignalGroup/group-session-builder.js +2 -1
  41. package/lib/signal/WaSignalGroup/group_cipher.js +10 -9
  42. package/lib/signal/WaSignalGroup/sender-key-distribution-message.js +2 -1
  43. package/lib/signal/WaSignalGroup/sender-key-message.js +2 -1
  44. package/lib/socks.js +9 -8
  45. package/lib/store/Backend.js +3 -1
  46. package/lib/store/FileBackend.js +2 -1
  47. package/lib/store/MemoryBackend.js +2 -1
  48. package/lib/store/SqliteBackend.js +6 -5
  49. package/lib/store/migrate.js +2 -1
  50. package/llms.txt +1 -0
  51. package/package.json +2 -1
package/lib/plist.js CHANGED
@@ -1,4 +1,7 @@
1
1
  'use strict';
2
+
3
+ const { Boom } = require('@hapi/boom');
4
+
2
5
  //
3
6
  // ─── Property lists ───────────────────────────────────────────────────────────
4
7
  //
@@ -194,7 +197,7 @@ class XmlScanner {
194
197
  expectClose(name) {
195
198
  const tag = this.nextTag();
196
199
  if (!tag || !tag.closing || tag.name !== name) {
197
- throw new Error('plist: expected </' + name + '>');
200
+ throw new Boom('plist: expected </' + name + '>', { statusCode: 400 });
198
201
  }
199
202
  }
200
203
  }
@@ -245,7 +248,7 @@ function parseXmlValue(scanner, tag) {
245
248
  if (tag.selfClosing) return items;
246
249
  for (;;) {
247
250
  const next = scanner.nextTag();
248
- if (!next) throw new Error('plist: unterminated <array>');
251
+ if (!next) throw new Boom('plist: unterminated <array>', { statusCode: 400 });
249
252
  if (next.closing && next.name === 'array') return items;
250
253
  items.push(parseXmlValue(scanner, next));
251
254
  }
@@ -255,17 +258,17 @@ function parseXmlValue(scanner, tag) {
255
258
  if (tag.selfClosing) return dict;
256
259
  for (;;) {
257
260
  const keyTag = scanner.nextTag();
258
- if (!keyTag) throw new Error('plist: unterminated <dict>');
261
+ if (!keyTag) throw new Boom('plist: unterminated <dict>', { statusCode: 400 });
259
262
  if (keyTag.closing && keyTag.name === 'dict') return dict;
260
- if (keyTag.name !== 'key') throw new Error('plist: expected <key>, saw <' + keyTag.name + '>');
263
+ if (keyTag.name !== 'key') throw new Boom('plist: expected <key>, saw <' + keyTag.name + '>', { statusCode: 400 });
261
264
  const key = parseXmlValue(scanner, keyTag);
262
265
  const valueTag = scanner.nextTag();
263
- if (!valueTag) throw new Error('plist: <key>' + key + '</key> has no value');
266
+ if (!valueTag) throw new Boom('plist: <key>' + key + '</key> has no value', { statusCode: 400 });
264
267
  dict[key] = parseXmlValue(scanner, valueTag);
265
268
  }
266
269
  }
267
270
  default:
268
- throw new Error('plist: unsupported element <' + tag.name + '>');
271
+ throw new Boom('plist: unsupported element <' + tag.name + '>', { statusCode: 400 });
269
272
  }
270
273
  }
271
274
 
@@ -273,7 +276,7 @@ function parseXml(buf) {
273
276
  const scanner = new XmlScanner(buf.toString('utf8'));
274
277
  for (;;) {
275
278
  const tag = scanner.nextTag();
276
- if (!tag) throw new Error('plist: no root element');
279
+ if (!tag) throw new Boom('plist: no root element', { statusCode: 400 });
277
280
  // <plist> is a container, not a value; step through it to its single child.
278
281
  if (tag.name === 'plist' && !tag.closing) continue;
279
282
  if (tag.closing) continue;
@@ -294,7 +297,7 @@ function isBinary(buf) {
294
297
 
295
298
  class BinaryPlistReader {
296
299
  constructor(buf) {
297
- if (buf.length < MAGIC.length + 32) throw new Error('plist: binary plist too short');
300
+ if (buf.length < MAGIC.length + 32) throw new Boom('plist: binary plist too short', { statusCode: 400 });
298
301
  const trailer = buf.length - 32;
299
302
  this.buf = buf;
300
303
  this.offsetSize = buf[trailer + 6];
@@ -304,10 +307,10 @@ class BinaryPlistReader {
304
307
  this.tableOffset = Number(buf.readBigUInt64BE(trailer + 24));
305
308
 
306
309
  if (this.offsetSize < 1 || this.offsetSize > 8 || this.refSize < 1 || this.refSize > 8) {
307
- throw new Error('plist: implausible binary plist trailer');
310
+ throw new Boom('plist: implausible binary plist trailer', { statusCode: 400 });
308
311
  }
309
312
  if (this.tableOffset + this.count * this.offsetSize > trailer) {
310
- throw new Error('plist: binary plist offset table out of range');
313
+ throw new Boom('plist: binary plist offset table out of range', { statusCode: 400 });
311
314
  }
312
315
  }
313
316
 
@@ -318,7 +321,7 @@ class BinaryPlistReader {
318
321
  }
319
322
 
320
323
  offsetOf(index) {
321
- if (index < 0 || index >= this.count) throw new Error('plist: object index out of range');
324
+ if (index < 0 || index >= this.count) throw new Boom('plist: object index out of range', { statusCode: 400 });
322
325
  return Number(this.uint(this.tableOffset + index * this.offsetSize, this.offsetSize));
323
326
  }
324
327
 
@@ -328,7 +331,7 @@ class BinaryPlistReader {
328
331
  sizeAt(offset, info) {
329
332
  if (info !== 0x0f) return { count: info, start: offset + 1 };
330
333
  const marker = this.buf[offset + 1];
331
- if ((marker & 0xf0) !== 0x10) throw new Error('plist: bad extended length marker');
334
+ if ((marker & 0xf0) !== 0x10) throw new Boom('plist: bad extended length marker', { statusCode: 400 });
332
335
  const width = 1 << (marker & 0x0f);
333
336
  return {
334
337
  count: Number(this.uint(offset + 2, width)),
@@ -347,7 +350,7 @@ class BinaryPlistReader {
347
350
  if (info === 0x00) return null;
348
351
  if (info === 0x08) return false;
349
352
  if (info === 0x09) return true;
350
- throw new Error('plist: unsupported singleton 0x0' + info.toString(16));
353
+ throw new Boom('plist: unsupported singleton 0x0' + info.toString(16), { statusCode: 400 });
351
354
 
352
355
  case 0x1: {
353
356
  const width = 1 << info;
@@ -362,7 +365,7 @@ class BinaryPlistReader {
362
365
  case 0x2:
363
366
  if (info === 2) return this.buf.readFloatBE(offset + 1);
364
367
  if (info === 3) return this.buf.readDoubleBE(offset + 1);
365
- throw new Error('plist: unsupported real width');
368
+ throw new Boom('plist: unsupported real width', { statusCode: 400 });
366
369
 
367
370
  case 0x3:
368
371
  return new Date(this.buf.readDoubleBE(offset + 1) * 1000 + APPLE_EPOCH_OFFSET_MS);
@@ -412,7 +415,7 @@ class BinaryPlistReader {
412
415
  }
413
416
 
414
417
  default:
415
- throw new Error('plist: unsupported marker 0x' + marker.toString(16));
418
+ throw new Boom('plist: unsupported marker 0x' + marker.toString(16), { statusCode: 400 });
416
419
  }
417
420
  }
418
421
  }
@@ -16,6 +16,7 @@
16
16
  // than exported with a quiet hole in it. A contact the store kept under both
17
17
  // their phone number and their lid goes over as one conversation, as the
18
18
  // phone shows them.
19
+ const { Boom } = require('@hapi/boom');
19
20
  const zlib = require('node:zlib');
20
21
  const { Writer } = require('protobufjs/minimal');
21
22
 
@@ -32,7 +33,7 @@ const isUint = (v, max) => Number.isInteger(v) && v >= 0 && v <= max;
32
33
 
33
34
  function failure(code, detail) {
34
35
  const full = 'PRIMARY_HISTORY_EXPORT_' + code;
35
- const error = new Error(detail ? full + ': ' + detail : full);
36
+ const error = new Boom(detail ? full + ': ' + detail : full);
36
37
  error.code = full;
37
38
  return error;
38
39
  }
@@ -25,6 +25,7 @@
25
25
  // refused to write all end up in `losses`. Revoked, expired and view-once
26
26
  // content is dropped the moment it is known, never handed out, and taken off
27
27
  // the disk at the next turn of the event loop.
28
+ const { Boom } = require('@hapi/boom');
28
29
  const fs = require('node:fs');
29
30
  const path = require('node:path');
30
31
  const crypto = require('node:crypto');
@@ -72,7 +73,12 @@ const isGroup = jid => jid.endsWith('@g.us');
72
73
 
73
74
  function failure(code, detail, cause) {
74
75
  const full = 'PRIMARY_MESSAGE_STORE_' + code;
75
- const error = new Error(detail ? full + ': ' + detail : full, cause ? { cause } : undefined);
76
+ const error = new Boom(detail ? full + ': ' + detail : full);
77
+ // Boom takes no `cause`; set it the way Error's own option does.
78
+ if (cause) {
79
+ Object.defineProperty(error, 'cause',
80
+ { value: cause, writable: true, configurable: true, enumerable: false });
81
+ }
76
82
  error.code = full;
77
83
  return error;
78
84
  }
@@ -215,7 +221,7 @@ function setCorruptAside(files, at) {
215
221
  const moved = [];
216
222
  try {
217
223
  for (const file of files.filter(exists)) {
218
- if (exists(file + suffix)) throw new Error(file + suffix + ' already exists');
224
+ if (exists(file + suffix)) throw new Boom(file + suffix + ' already exists', { statusCode: 409 });
219
225
  fs.renameSync(file, file + suffix);
220
226
  moved.push(file);
221
227
  }
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const { Boom } = require('@hapi/boom');
4
+
3
5
  const WIRE_VARINT = 0;
4
6
  const WIRE_64 = 1;
5
7
  const WIRE_LEN = 2;
@@ -366,7 +368,7 @@ function encodePinInChatMessage(opts) {
366
368
  const ENC_ADDON_FIELD = { encReaction: 56, encComment: 71, encEventResponse: 76 };
367
369
  function encodeEncAddOnMessage(type, opts) {
368
370
  const num = ENC_ADDON_FIELD[type];
369
- if (!num) throw new Error('unknown encrypted add-on ' + type);
371
+ if (!num) throw new Boom('unknown encrypted add-on ' + type, { statusCode: 400 });
370
372
  return field(num, WIRE_LEN, Buffer.concat([
371
373
  field(1, WIRE_LEN, encodeMessageKey(opts.key)),
372
374
  field(2, WIRE_LEN, bytes(opts.encPayload)),
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const { Boom } = require('@hapi/boom');
3
4
  const { dbg: _whaDbg } = require('../logger');
4
5
  const { hkdfSha256 } = require('../hkdf');
5
6
 
@@ -411,10 +412,10 @@ class SenderKeyCrypto {
411
412
  }
412
413
  const currentIter = state.iteration;
413
414
  if (iteration < currentIter) {
414
- throw new Error('SenderKey: old message key not found for iteration ' + iteration);
415
+ throw new Boom('SenderKey: old message key not found for iteration ' + iteration, { statusCode: 404 });
415
416
  }
416
417
  if (iteration - currentIter > 2000) {
417
- throw new Error('SenderKey: message too far ahead (over 2000 iterations)');
418
+ throw new Boom('SenderKey: message too far ahead (over 2000 iterations)', { statusCode: 400 });
418
419
  }
419
420
  // Advance chain, caching skipped keys
420
421
  let chainKey = state.chainKey;
@@ -470,7 +471,7 @@ class SenderKeyCrypto {
470
471
 
471
472
  const version = ciphertext[0];
472
473
  if ((version & 0xf) !== 3) {
473
- throw new Error('Unknown SenderKeyMessage version: ' + version);
474
+ throw new Boom('Unknown SenderKeyMessage version: ' + version, { statusCode: 400 });
474
475
  }
475
476
 
476
477
  const SIG_LEN = 64;
@@ -487,7 +488,7 @@ class SenderKeyCrypto {
487
488
  const sigPub = senderKeyState.signingKey.pub;
488
489
 
489
490
  const ok = curveJs.verify(sigPub, forVerify, sig);
490
- if (!ok) throw new Error('SenderKeyMessage signature verification failed');
491
+ if (!ok) throw new Boom('SenderKeyMessage signature verification failed', { statusCode: 400 });
491
492
 
492
493
  const messageKey = this._getMessageKeyAtIteration(senderKeyState, iteration);
493
494
  const { iv, cipherKey } = deriveMessageKeys(messageKey);
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const { Boom } = require('@hapi/boom');
3
4
  const keyhelper = require('./keyhelper');
4
5
  const { SenderKeyDistributionMessage } = require('./sender-key-distribution-message');
5
6
  const { SenderKeyRecord } = require('./sender-key-record');
@@ -31,7 +32,7 @@ class GroupSessionBuilder {
31
32
  }
32
33
  const state = senderKeyRecord.getSenderKeyState();
33
34
  if (!state) {
34
- throw new Error('No session state available');
35
+ throw new Boom('No session state available', { statusCode: 404 });
35
36
  }
36
37
  return new SenderKeyDistributionMessage(
37
38
  state.getKeyId(),
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const { Boom } = require('@hapi/boom');
3
4
  const { decrypt, encrypt } = require('../libsignal/crypto');
4
5
  const { SenderKeyMessage } = require('./sender-key-message');
5
6
  const { SenderKeyRecord } = require('./sender-key-record');
@@ -13,11 +14,11 @@ class GroupCipher {
13
14
  async encrypt(paddedPlaintext) {
14
15
  const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
15
16
  if (!record) {
16
- throw new Error('No SenderKeyRecord found for encryption');
17
+ throw new Boom('No SenderKeyRecord found for encryption', { statusCode: 404 });
17
18
  }
18
19
  const senderKeyState = record.getSenderKeyState();
19
20
  if (!senderKeyState) {
20
- throw new Error('No session to encrypt message');
21
+ throw new Boom('No session to encrypt message', { statusCode: 404 });
21
22
  }
22
23
  const iteration = senderKeyState.getSenderChainKey().getIteration();
23
24
  const senderKey = this.getSenderKey(senderKeyState, iteration === 0 ? 0 : iteration + 1);
@@ -35,12 +36,12 @@ class GroupCipher {
35
36
  async decrypt(senderKeyMessageBytes) {
36
37
  const record = await this.senderKeyStore.loadSenderKey(this.senderKeyName);
37
38
  if (!record) {
38
- throw new Error('No SenderKeyRecord found for decryption');
39
+ throw new Boom('No SenderKeyRecord found for decryption', { statusCode: 404 });
39
40
  }
40
41
  const senderKeyMessage = new SenderKeyMessage(null, null, null, null, senderKeyMessageBytes);
41
42
  const senderKeyState = record.getSenderKeyState(senderKeyMessage.getKeyId());
42
43
  if (!senderKeyState) {
43
- throw new Error('No session found to decrypt message');
44
+ throw new Boom('No session found to decrypt message', { statusCode: 404 });
44
45
  }
45
46
  senderKeyMessage.verifySignature(senderKeyState.getSigningKeyPublic());
46
47
  const senderKey = this.getSenderKey(senderKeyState, senderKeyMessage.getIteration());
@@ -55,14 +56,14 @@ class GroupCipher {
55
56
  if (senderKeyState.hasSenderMessageKey(iteration)) {
56
57
  const messageKey = senderKeyState.removeSenderMessageKey(iteration);
57
58
  if (!messageKey) {
58
- throw new Error('No sender message key found for iteration');
59
+ throw new Boom('No sender message key found for iteration', { statusCode: 404 });
59
60
  }
60
61
  return messageKey;
61
62
  }
62
- throw new Error(`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`);
63
+ throw new Boom(`Received message with old counter: ${senderChainKey.getIteration()}, ${iteration}`, { statusCode: 400 });
63
64
  }
64
65
  if (iteration - senderChainKey.getIteration() > 2000) {
65
- throw new Error('Over 2000 messages into the future!');
66
+ throw new Boom('Over 2000 messages into the future!', { statusCode: 400 });
66
67
  }
67
68
  while (senderChainKey.getIteration() < iteration) {
68
69
  senderKeyState.addSenderMessageKey(senderChainKey.getSenderMessageKey());
@@ -76,7 +77,7 @@ class GroupCipher {
76
77
  try {
77
78
  return decrypt(key, ciphertext, iv);
78
79
  } catch (e) {
79
- throw new Error('InvalidMessageException');
80
+ throw new Boom('InvalidMessageException', { statusCode: 400 });
80
81
  }
81
82
  }
82
83
 
@@ -84,7 +85,7 @@ class GroupCipher {
84
85
  try {
85
86
  return encrypt(key, plaintext, iv);
86
87
  } catch (e) {
87
- throw new Error('InvalidMessageException');
88
+ throw new Boom('InvalidMessageException', { statusCode: 400 });
88
89
  }
89
90
  }
90
91
  }
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const { Boom } = require('@hapi/boom');
3
4
  const { CiphertextMessage } = require('./ciphertext-message');
4
5
 
5
6
  // ─── Minimal protobuf encode/decode for SenderKeyDistributionMessage ──────────
@@ -91,7 +92,7 @@ class SenderKeyDistributionMessage extends CiphertextMessage {
91
92
  ? decoded.signingKey
92
93
  : Buffer.from(decoded.signingKey);
93
94
  } catch (e) {
94
- throw new Error(String(e));
95
+ throw new Boom(String(e));
95
96
  }
96
97
  } else {
97
98
  const version = this.intsToByteHighAndLow(this.CURRENT_VERSION, this.CURRENT_VERSION);
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const { Boom } = require('@hapi/boom');
3
4
  const { calculateSignature, verifySignature } = require('../libsignal/curve');
4
5
  const { CiphertextMessage } = require('./ciphertext-message');
5
6
 
@@ -120,7 +121,7 @@ class SenderKeyMessage extends CiphertextMessage {
120
121
  const part1 = this.serialized.slice(0, this.serialized.length - this.SIGNATURE_LENGTH);
121
122
  const part2 = this.serialized.slice(-1 * this.SIGNATURE_LENGTH);
122
123
  const res = verifySignature(signatureKey, part1, part2);
123
- if (!res) throw new Error('Invalid signature!');
124
+ if (!res) throw new Boom('Invalid signature!', { statusCode: 400 });
124
125
  }
125
126
 
126
127
  getSignature(signatureKey, serialized) {
package/lib/socks.js CHANGED
@@ -26,6 +26,7 @@
26
26
  // curl honours SOCKS_PROXY, https.get does not. Same machine, same proxy,
27
27
  // opposite results.
28
28
 
29
+ const { Boom } = require('@hapi/boom');
29
30
  const https = require('https');
30
31
  const tls = require('tls');
31
32
 
@@ -51,16 +52,16 @@ function loadSocks() {
51
52
  if (override) {
52
53
  try { return require(override); }
53
54
  catch (err) {
54
- throw new Error('WA_SOCKS_LIB points at ' + override +
55
+ throw new Boom('WA_SOCKS_LIB points at ' + override +
55
56
  ' but it could not be loaded: ' + err.message);
56
57
  }
57
58
  }
58
59
  try {
59
60
  return require('socks');
60
61
  } catch (_) {
61
- throw new Error(
62
+ throw new Boom(
62
63
  "A SOCKS proxy is configured but the 'socks' package is not installed. " +
63
- 'Run: npm install socks'
64
+ 'Run: npm install socks', { statusCode: 501 }
64
65
  );
65
66
  }
66
67
  }
@@ -73,7 +74,7 @@ function loadSocks() {
73
74
  */
74
75
  function parseSocksProxy(proxyUrl) {
75
76
  let raw = String(proxyUrl || '').trim();
76
- if (!raw) throw new Error('No SOCKS proxy configured');
77
+ if (!raw) throw new Boom('No SOCKS proxy configured', { statusCode: 400 });
77
78
 
78
79
  // A bare host:port is what .env.example has always shown and what most people
79
80
  // type. Without a scheme `new URL` reads "127.0.0.1:" as the protocol and the
@@ -82,14 +83,14 @@ function parseSocksProxy(proxyUrl) {
82
83
 
83
84
  let url;
84
85
  try { url = new URL(raw); }
85
- catch (_) { throw new Error('Invalid SOCKS proxy URL: ' + proxyUrl); }
86
+ catch (_) { throw new Boom('Invalid SOCKS proxy URL: ' + proxyUrl, { statusCode: 400 }); }
86
87
 
87
88
  const type = SOCKS_SCHEMES[url.protocol];
88
89
  if (!type) {
89
- throw new Error('Unsupported proxy scheme "' + url.protocol + '" — use ' +
90
- Object.keys(SOCKS_SCHEMES).map(s => s.replace(':', '')).join(', '));
90
+ throw new Boom('Unsupported proxy scheme "' + url.protocol + '" — use ' +
91
+ Object.keys(SOCKS_SCHEMES).map(s => s.replace(':', '')).join(', '), { statusCode: 400 });
91
92
  }
92
- if (!url.hostname) throw new Error('SOCKS proxy URL has no host: ' + proxyUrl);
93
+ if (!url.hostname) throw new Boom('SOCKS proxy URL has no host: ' + proxyUrl, { statusCode: 400 });
93
94
 
94
95
  const proxy = {
95
96
  host: url.hostname,
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const { Boom } = require('@hapi/boom');
4
+
3
5
  // Where a session's state is kept.
4
6
  //
5
7
  // Every piece of state a number owns — the credentials, the Signal sessions,
@@ -106,7 +108,7 @@ const PRE_KEY_PREFIX = 'pre-key/';
106
108
  function preKeyKey(id) {
107
109
  const n = Number(id);
108
110
  if (!Number.isInteger(n) || n < 0) {
109
- throw new Error('preKeyKey: id must be a non-negative integer, got ' + id);
111
+ throw new Boom('preKeyKey: id must be a non-negative integer, got ' + id, { statusCode: 400 });
110
112
  }
111
113
  return PRE_KEY_PREFIX + n;
112
114
  }
@@ -23,6 +23,7 @@
23
23
  // a process that died mid-write — which, for the file holding a number's
24
24
  // identity keys, is the difference between a session and a lost number.
25
25
 
26
+ const { Boom } = require('@hapi/boom');
26
27
  const fs = require('fs');
27
28
  const path = require('path');
28
29
 
@@ -85,7 +86,7 @@ class FileBackend {
85
86
  return path.join(this.dir, this._stem + PRE_KEY_INFIX + id + '.json');
86
87
  }
87
88
  const suffix = KEY_SUFFIX[key];
88
- if (!suffix) throw new Error('FileBackend: unknown key ' + JSON.stringify(key));
89
+ if (!suffix) throw new Boom('FileBackend: unknown key ' + JSON.stringify(key), { statusCode: 400 });
89
90
  return path.join(this.dir, this._stem + suffix);
90
91
  }
91
92
 
@@ -19,6 +19,7 @@
19
19
  // registration is spent, the number is taken, and the keys that proved it was
20
20
  // yours are gone. Use it for sessions that were never meant to outlive the run.
21
21
 
22
+ const { Boom } = require('@hapi/boom');
22
23
  const { isValidKey } = require('./Backend');
23
24
 
24
25
  class MemoryBackend {
@@ -65,7 +66,7 @@ class MemoryBackend {
65
66
  // which is the one failure a second implementation exists to catch.
66
67
  _assertKey(key) {
67
68
  if (!isValidKey(key)) {
68
- throw new Error('MemoryBackend: unknown key ' + JSON.stringify(key));
69
+ throw new Boom('MemoryBackend: unknown key ' + JSON.stringify(key), { statusCode: 400 });
69
70
  }
70
71
  }
71
72
  }
@@ -34,6 +34,7 @@
34
34
  // the bytes go in and come back exactly, whatever is in them, so that is what
35
35
  // the column is and the conversion happens here rather than in the caller.
36
36
 
37
+ const { Boom } = require('@hapi/boom');
37
38
  const path = require('path');
38
39
  const fs = require('fs');
39
40
 
@@ -117,7 +118,7 @@ function resolveDriver(prefer) {
117
118
  if (!driver) {
118
119
  const [major, minor] = process.versions.node.split('.').map(Number);
119
120
  const tooOld = major < 22 || (major === 22 && minor < 5);
120
- throw new Error(
121
+ throw new Boom(
121
122
  'SqliteBackend: no SQLite driver available.\n' +
122
123
  (tooOld
123
124
  ? ` Node ${process.versions.node} has no built-in SQLite — it arrives in 22.5.0.\n` +
@@ -126,7 +127,7 @@ function resolveDriver(prefer) {
126
127
  : ` node:sqlite should be present on Node ${process.versions.node} but could not ` +
127
128
  'be loaded.\n Install the fallback driver instead:\n' +
128
129
  ' npm install better-sqlite3\n') +
129
- ' Or leave it out entirely: the default FileBackend needs nothing installed.'
130
+ ' Or leave it out entirely: the default FileBackend needs nothing installed.', { statusCode: 501 }
130
131
  );
131
132
  }
132
133
 
@@ -169,10 +170,10 @@ function _acquire(file, prefer) {
169
170
  const version = found ? Number(found.user_version) : 0;
170
171
  if (version > SCHEMA_VERSION) {
171
172
  db.close();
172
- throw new Error(
173
+ throw new Boom(
173
174
  `SqliteBackend: ${key} was written by a newer whalibmob (schema ` +
174
175
  `${version}, this one understands ${SCHEMA_VERSION}). Upgrade whalibmob ` +
175
- 'rather than letting an older release write to it.'
176
+ 'rather than letting an older release write to it.', { statusCode: 409 }
176
177
  );
177
178
  }
178
179
  if (version < SCHEMA_VERSION) db.exec('PRAGMA user_version = ' + SCHEMA_VERSION);
@@ -234,7 +235,7 @@ class SqliteBackend {
234
235
 
235
236
  _assertKey(key) {
236
237
  if (!isValidKey(key)) {
237
- throw new Error('SqliteBackend: unknown key ' + JSON.stringify(key));
238
+ throw new Boom('SqliteBackend: unknown key ' + JSON.stringify(key), { statusCode: 400 });
238
239
  }
239
240
  return key;
240
241
  }
@@ -12,6 +12,7 @@
12
12
  // otherwise, which makes an interrupted copy safe to run again — it picks up
13
13
  // what did not make it the first time and does not undo what did.
14
14
 
15
+ const { Boom } = require('@hapi/boom');
15
16
  const { assertBackend } = require('./Backend');
16
17
 
17
18
  /**
@@ -26,7 +27,7 @@ const { assertBackend } = require('./Backend');
26
27
  function copySession(from, to, opts) {
27
28
  assertBackend(from, 'source backend');
28
29
  assertBackend(to, 'destination backend');
29
- if (from === to) throw new Error('copySession: source and destination are the same backend');
30
+ if (from === to) throw new Boom('copySession: source and destination are the same backend', { statusCode: 400 });
30
31
 
31
32
  const overwrite = !!(opts && opts.overwrite);
32
33
  const copied = [], skipped = [];
package/llms.txt CHANGED
@@ -134,6 +134,7 @@ main().catch((err) => { console.error(err.message || err); process.exit(1); });
134
134
  - [Media Messages](https://github.com/Kunboruto20/whalibmob#media-messages): images, video, audio, voice notes, documents, stickers
135
135
  - [Receiving Media](https://github.com/Kunboruto20/whalibmob#receiving-media): downloading and decrypting what arrives
136
136
  - [Handling Events](https://github.com/Kunboruto20/whalibmob#handling-events): the full event list, keepalive and offline-sync events included
137
+ - [Handling Errors](https://github.com/Kunboruto20/whalibmob/blob/main/docs/events-history.md#handling-errors): every error the library raises is a Boom (`@hapi/boom`) with an HTTP-style `err.output.statusCode` — 400 bad input, 401 not authenticated, 408 timed out, 428 not connected, 502 a server answered wrongly, or the server's own status passed through
137
138
  - [Encrypted add-ons](https://github.com/Kunboruto20/whalibmob/blob/main/docs/messaging.md#encrypted-reactions-comments-event-responses-and-edits): poll votes, encrypted reactions, comments, event responses and edits; `sendRawMessage` for any encoded Message
138
139
  - [History Sync](https://github.com/Kunboruto20/whalibmob#history-sync): the backlog the server sends on first connect, and reading it back
139
140
  - [Status / Stories](https://github.com/Kunboruto20/whalibmob#status--stories): posting to status
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whalibmob",
3
- "version": "5.40.38",
3
+ "version": "5.40.39",
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",
@@ -66,6 +66,7 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "@cacheable/node-cache": "3.1.1",
69
+ "@hapi/boom": "^10.0.1",
69
70
  "@noble/hashes": "^1.7.2",
70
71
  "async-mutex": "^0.5.0",
71
72
  "axios": "^1.7.2",