whalibmob 5.40.45 → 5.40.47

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/index.d.ts +4 -6
  2. package/index.js +16 -14
  3. package/lib/Client.js +77 -28
  4. package/lib/signal/SenderKey.js +1 -1
  5. package/lib/signal/SignalProtocol.js +204 -65
  6. package/lib/signal/SignalStore.js +9 -5
  7. package/lib/signal/core/LICENSE +27 -0
  8. package/lib/signal/core/THIRD_PARTY_LICENSES.md +4225 -0
  9. package/lib/signal/core/index.cjs +2805 -0
  10. package/lib/signal/core/wasm/nosimd.wasm +0 -0
  11. package/lib/signal/core/wasm/simd.wasm +0 -0
  12. package/lib/signal/libsignal/LICENSE +21 -0
  13. package/lib/signal/libsignal/address.js +27 -0
  14. package/lib/signal/libsignal/bytes.js +16 -0
  15. package/lib/signal/libsignal/crypto.js +60 -93
  16. package/lib/signal/libsignal/curve.js +47 -138
  17. package/lib/signal/libsignal/errors.js +68 -27
  18. package/lib/signal/libsignal/group.js +85 -0
  19. package/lib/signal/libsignal/index.js +35 -10
  20. package/lib/signal/libsignal/keys.js +27 -0
  21. package/lib/signal/libsignal/legacy-session-codec.js +135 -0
  22. package/lib/signal/libsignal/legacy-session.js +31 -0
  23. package/lib/signal/libsignal/lock.js +46 -0
  24. package/lib/signal/libsignal/prekey-header.js +59 -0
  25. package/lib/signal/libsignal/session-format.js +43 -0
  26. package/lib/signal/libsignal/session.js +198 -0
  27. package/lib/signal/libsignal/store.js +2 -0
  28. package/package.json +7 -2
  29. package/lib/signal/WaSignalGroup/ciphertext-message.js +0 -15
  30. package/lib/signal/WaSignalGroup/group-session-builder.js +0 -46
  31. package/lib/signal/WaSignalGroup/group_cipher.js +0 -93
  32. package/lib/signal/WaSignalGroup/index.js +0 -27
  33. package/lib/signal/WaSignalGroup/keyhelper.js +0 -24
  34. package/lib/signal/WaSignalGroup/sender-chain-key.js +0 -35
  35. package/lib/signal/WaSignalGroup/sender-key-distribution-message.js +0 -137
  36. package/lib/signal/WaSignalGroup/sender-key-message.js +0 -140
  37. package/lib/signal/WaSignalGroup/sender-key-name.js +0 -59
  38. package/lib/signal/WaSignalGroup/sender-key-record.js +0 -63
  39. package/lib/signal/WaSignalGroup/sender-key-state.js +0 -101
  40. package/lib/signal/WaSignalGroup/sender-message-key.js +0 -34
  41. package/lib/signal/libsignal/WhisperTextProtocol.js +0 -933
  42. package/lib/signal/libsignal/base_key_type.js +0 -7
  43. package/lib/signal/libsignal/chain_type.js +0 -6
  44. package/lib/signal/libsignal/keyhelper.js +0 -45
  45. package/lib/signal/libsignal/numeric_fingerprint.js +0 -83
  46. package/lib/signal/libsignal/protobufs.js +0 -10
  47. package/lib/signal/libsignal/protocol_address.js +0 -40
  48. package/lib/signal/libsignal/queue_job.js +0 -71
  49. package/lib/signal/libsignal/session_builder.js +0 -171
  50. package/lib/signal/libsignal/session_cipher.js +0 -334
  51. package/lib/signal/libsignal/session_record.js +0 -316
package/index.d.ts CHANGED
@@ -2408,19 +2408,17 @@ export declare const Messages: {
2408
2408
 
2409
2409
  /**
2410
2410
  * `whalibmob/lib/signal/` — SignalProtocol.js, SignalStore.js and SenderKey.js
2411
- * gathered into one namespace, with the two vendored libraries under their own.
2411
+ * gathered into one namespace, with the vendored libsignal under its own.
2412
2412
  */
2413
2413
  export declare const Signal: LibModule & {
2414
2414
  SignalProtocol: any;
2415
2415
  SignalStore: any;
2416
2416
  SenderKeyStore: any;
2417
2417
  SenderKeyCrypto: any;
2418
- /** Group ciphers and sender-key records. */
2419
- WaSignalGroup: LibModule;
2420
2418
  /**
2421
- * The vendored libsignal. Its own barrel leaves six modules out; they are
2422
- * here — `BaseKeyType`, `ChainType`, `protobufs`, `queueJob`,
2423
- * `FingerprintGenerator`, `textsecure`.
2419
+ * The vendored libsignal (MIT, WebAssembly core): `encrypt`, `decrypt`,
2420
+ * `processPreKeyBundle`, `groupEncrypt`, `groupDecrypt`,
2421
+ * `createSenderKeyDistribution`, `processSenderKeyDistribution`, ...
2424
2422
  */
2425
2423
  libsignal: LibModule;
2426
2424
  };
package/index.js CHANGED
@@ -196,26 +196,28 @@ const Argo = require('./lib/argo/ArgoDecoder');
196
196
  const WAUSync = require('./lib/WAUSync');
197
197
 
198
198
  // Signal — lib/signal/. SignalProtocol.js, SignalStore.js and SenderKey.js have
199
- // no name in common, so the three are one namespace. The two vendored libraries
200
- // keep theirs, being libraries.
199
+ // no name in common, so the three are one namespace. The vendored libsignal
200
+ // (lib/signal/libsignal, MIT, WebAssembly core) keeps its own names.
201
201
  const Signal = Object.assign({},
202
202
  require('./lib/signal/SignalProtocol'),
203
203
  require('./lib/signal/SignalStore'),
204
204
  require('./lib/signal/SenderKey'),
205
205
  {
206
- WaSignalGroup: require('./lib/signal/WaSignalGroup'),
207
- // libsignal's own barrel leaves six of its modules out. They are added to a
208
- // copy of it here rather than written into it, so
209
- // require('whalibmob/lib/signal/libsignal') stays exactly what it was.
206
+ // The barrel, plus the modules it builds on, under `internals`. Added to a
207
+ // copy so require('whalibmob/lib/signal/libsignal') stays what it is.
210
208
  libsignal: Object.assign({}, require('./lib/signal/libsignal'), {
211
- BaseKeyType: require('./lib/signal/libsignal/base_key_type'),
212
- ChainType: require('./lib/signal/libsignal/chain_type'),
213
- protobufs: require('./lib/signal/libsignal/protobufs'),
214
- queueJob: require('./lib/signal/libsignal/queue_job'),
215
- FingerprintGenerator:
216
- require('./lib/signal/libsignal/numeric_fingerprint').FingerprintGenerator,
217
- textsecure:
218
- require('./lib/signal/libsignal/WhisperTextProtocol').textsecure
209
+ internals: {
210
+ bytes: require('./lib/signal/libsignal/bytes'),
211
+ crypto: require('./lib/signal/libsignal/crypto'),
212
+ curve: require('./lib/signal/libsignal/curve'),
213
+ errors: require('./lib/signal/libsignal/errors'),
214
+ legacySessionCodec: require('./lib/signal/libsignal/legacy-session-codec'),
215
+ legacySession: require('./lib/signal/libsignal/legacy-session'),
216
+ lock: require('./lib/signal/libsignal/lock'),
217
+ prekeyHeader: require('./lib/signal/libsignal/prekey-header'),
218
+ sessionFormat: require('./lib/signal/libsignal/session-format'),
219
+ store: require('./lib/signal/libsignal/store')
220
+ }
219
221
  })
220
222
  });
221
223
 
package/lib/Client.js CHANGED
@@ -5,6 +5,25 @@ const { statusFrom } = require('./errors');
5
5
  const { dbg: _whaDbg, configureLogger: _whaConfigLogger } = require('./logger');
6
6
 
7
7
  const EventEmitter = require('events');
8
+
9
+ // _processNotification returns this when it already acked (primary pairing).
10
+ const NOTIFICATION_ACK_OWNED = Symbol('notification-ack-owned');
11
+
12
+ // Ack a notification. Every push needs one or the server closes the stream
13
+ // after ~5 min; echo participant/recipient like whatsmeow's sendAck.
14
+ function sendNotificationAck(client, attrs, type) {
15
+ if (!client._socket || !client._connected) return;
16
+ attrs = attrs || {};
17
+ const ack = {
18
+ id: attrs.id || '',
19
+ class: 'notification',
20
+ type: type || '',
21
+ to: attrs.from || 's.whatsapp.net'
22
+ };
23
+ if (attrs.participant) ack.participant = String(attrs.participant);
24
+ if (attrs.recipient) ack.recipient = String(attrs.recipient);
25
+ client._socket.sendNode(new BinaryNode('ack', ack, null));
26
+ }
8
27
  const path = require('path');
9
28
  const fs = require('fs');
10
29
  const crypto = require('crypto');
@@ -64,6 +83,12 @@ const {
64
83
  // Status posts are messages addressed here.
65
84
  const STATUS_BROADCAST_JID = 'status@broadcast';
66
85
 
86
+ // A top-level <status> stanza: a contact's status update, handled like a
87
+ // message from status@broadcast but acked with its own class.
88
+ function _isStatusStanza(node) {
89
+ return !!node && node.description === 'status';
90
+ }
91
+
67
92
  // The two prefixes a call-link token is wrapped in, as WhatsApp Web uses them.
68
93
  const CALL_AUDIO_PREFIX = 'https://call.whatsapp.com/voice/';
69
94
  const CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
@@ -3986,6 +4011,7 @@ class WhalibmobClient extends EventEmitter {
3986
4011
  const { makeOfflineNodeProcessor } = require('./OfflineNodeProcessor');
3987
4012
  this.__offlineQueue = makeOfflineNodeProcessor(new Map([
3988
4013
  ['message', (n) => this._handleMessage(n)],
4014
+ ['status', (n) => this._handleMessage(n)],
3989
4015
  ['receipt', (n) => this._handleReceipt(n)],
3990
4016
  ['notification', (n) => this._handleNotification(n)],
3991
4017
  ['call', (n) => this._handleCall(n)]
@@ -4021,7 +4047,7 @@ class WhalibmobClient extends EventEmitter {
4021
4047
  // `offline`, and handling a burst of them the way live stanzas are
4022
4048
  // handled starts every one of them at once — see OfflineNodeProcessor.
4023
4049
  if (node.attrs && node.attrs.offline &&
4024
- (tag === 'message' || tag === 'receipt' ||
4050
+ (tag === 'message' || tag === 'status' || tag === 'receipt' ||
4025
4051
  tag === 'notification' || tag === 'call')) {
4026
4052
  this._offlineQueue.enqueue(tag, node);
4027
4053
  return;
@@ -4029,6 +4055,12 @@ class WhalibmobClient extends EventEmitter {
4029
4055
 
4030
4056
  if (tag === 'iq') this._handleIq(node);
4031
4057
  else if (tag === 'message') this._handleMessage(node);
4058
+ // A contact's status update. It used to come as a <message> addressed
4059
+ // from status@broadcast; the server now also pushes it as a top-level
4060
+ // <status> stanza of the same shape. Left unacked, it holds back the
4061
+ // offline backlog and every live message queued behind it, and the
4062
+ // server ends the stream with <stream:error><ack class="status"/>.
4063
+ else if (tag === 'status') this._handleMessage(node);
4032
4064
  else if (tag === 'receipt') this._handleReceipt(node);
4033
4065
  else if (tag === 'ack') this._handleAck(node);
4034
4066
  else if (tag === 'notification') this._handleNotification(node);
@@ -4100,6 +4132,14 @@ class WhalibmobClient extends EventEmitter {
4100
4132
  return;
4101
4133
  }
4102
4134
 
4135
+ if (childTag === 'ack') {
4136
+ // Server closed the stream on an unacked stanza; the child names which.
4137
+ const a = (child && child.attrs) || {};
4138
+ _whaDbg('[DBG] STREAM_ERROR ack — server closed the stream on an unacked stanza' +
4139
+ ' id=' + (a.id || '?') + ' class=' + (a.class || '?') + ' type=' + (a.type || '?') +
4140
+ ' from=' + (a.from || a.to || '?'));
4141
+ }
4142
+
4103
4143
  const reason = attrs.reason || conflictType || childTag || code || 'unknown';
4104
4144
  _whaDbg('[DBG] STREAM_ERROR code=' + code + ' child=' + childTag +
4105
4145
  ' conflict=' + conflictType + ' reason=' + reason);
@@ -4257,7 +4297,7 @@ class WhalibmobClient extends EventEmitter {
4257
4297
  // told it is in flight before that, never after.
4258
4298
  if (skmsgNode && isGroup) {
4259
4299
  this._captureInflight(id, from, ts);
4260
- this._sendMessageAck(id, fromRaw, partRaw);
4300
+ this._ackIncoming(node, id, fromRaw, partRaw);
4261
4301
  this._sendDeliveryReceipt(id, fromRaw, partRaw);
4262
4302
  this._queueIncoming(this._messageMutex, 'MSG', async () => {
4263
4303
  // SKDM must be processed (awaited) before we attempt skmsg decryption,
@@ -4272,7 +4312,7 @@ class WhalibmobClient extends EventEmitter {
4272
4312
 
4273
4313
  if (dmEncNode && this._signal) {
4274
4314
  this._captureInflight(id, from, ts);
4275
- this._sendMessageAck(id, fromRaw, partRaw);
4315
+ this._ackIncoming(node, id, fromRaw, partRaw);
4276
4316
  this._sendDeliveryReceipt(id, fromRaw, partRaw);
4277
4317
  this._queueIncoming(this._messageMutex, 'MSG', () =>
4278
4318
  this._decryptDMMessage({ node, from, participant, fromRaw, partRaw, senderPn, id, ts, dmEncNode }));
@@ -4289,13 +4329,23 @@ class WhalibmobClient extends EventEmitter {
4289
4329
  // Nothing here this client can open into a message, so nothing to keep:
4290
4330
  // the store counts it as one it could not read rather than miss it.
4291
4331
  this._captureDecryptFailure(id, from);
4292
- this._sendMessageAck(id, fromRaw, partRaw);
4332
+ this._ackIncoming(node, id, fromRaw, partRaw);
4293
4333
  this._sendDeliveryReceipt(id, fromRaw, partRaw);
4294
4334
  this.emit('message', {
4295
4335
  id, from, participant, ts, text, node,
4296
4336
  fromMe: false, chat: from
4297
4337
  });
4298
- this._sendReadReceipt(id, fromRaw, partRaw);
4338
+ if (!_isStatusStanza(node)) this._sendReadReceipt(id, fromRaw, partRaw);
4339
+ }
4340
+
4341
+ // The transport ack for a stanza _handleMessage took in.
4342
+ //
4343
+ // A <message> is acked with class="message" and no type. A <status> is acked
4344
+ // the way every other pushed stanza is: class="status", echoing its type and
4345
+ // participant. Acking it as a message leaves the <status> itself unacked.
4346
+ _ackIncoming(node, id, fromRaw, partRaw) {
4347
+ if (_isStatusStanza(node)) this._sendStanzaAck(node);
4348
+ else this._sendMessageAck(id, fromRaw, partRaw);
4299
4349
  }
4300
4350
 
4301
4351
  // The other name this contact answers to, with the device kept.
@@ -4560,7 +4610,7 @@ class WhalibmobClient extends EventEmitter {
4560
4610
  _whaDbg('[DBG] SKDM_ONLY_ERR ' + e.message);
4561
4611
  }
4562
4612
  }
4563
- this._sendReadReceipt(id, fromRaw, partRaw);
4613
+ if (!_isStatusStanza(node)) this._sendReadReceipt(id, fromRaw, partRaw);
4564
4614
  return;
4565
4615
  }
4566
4616
 
@@ -4601,7 +4651,9 @@ class WhalibmobClient extends EventEmitter {
4601
4651
  // Nothing is read by receiving our own message back. A read receipt for
4602
4652
  // it would be addressed to ourselves and marks the chat read on every
4603
4653
  // other device — which is not what happened.
4604
- if (!dest) this._sendReadReceipt(id, fromRaw, partRaw);
4654
+ // A status is not read by arriving: "seen" is reported to its author,
4655
+ // so it is left to the caller (markRead) rather than sent on delivery.
4656
+ if (!dest && !_isStatusStanza(node)) this._sendReadReceipt(id, fromRaw, partRaw);
4605
4657
 
4606
4658
  // ── pkmsg = peer opened a new Signal session (identity/device change) ──
4607
4659
  // Re-issue our tcToken to them so the fresh session carries a valid
@@ -5067,23 +5119,16 @@ class WhalibmobClient extends EventEmitter {
5067
5119
 
5068
5120
  _handleReceipt(node) {
5069
5121
  const attrs = node.attrs || {};
5122
+ // Ack first (a throwing listener below must not skip it). _sendStanzaAck
5123
+ // puts participant/recipient each on its own attribute; the old inline ack
5124
+ // put participant on `recipient`, so the server re-delivered it every login.
5125
+ this._sendStanzaAck(node);
5070
5126
  this.emit('receipt', {
5071
5127
  id: attrs.id ? String(attrs.id) : '',
5072
5128
  from: attrs.from ? String(attrs.from) : '',
5073
5129
  type: attrs.type ? String(attrs.type) : ''
5074
5130
  });
5075
5131
  this._captureReceipt(node);
5076
- // ACK the receipt back to server (include type so server clears from offline queue)
5077
- if (this._socket && this._connected) {
5078
- const ackAttrs = {
5079
- id: attrs.id || '',
5080
- class: 'receipt',
5081
- to: attrs.from || ''
5082
- };
5083
- if (attrs.type) ackAttrs.type = String(attrs.type);
5084
- if (attrs.participant) ackAttrs.recipient = String(attrs.participant);
5085
- this._socket.sendNode(new BinaryNode('ack', ackAttrs, null));
5086
- }
5087
5132
  // If the recipient couldn't decrypt our message, re-send with fresh Signal session
5088
5133
  if (String(attrs.type || '') === 'retry') {
5089
5134
  this._handleRetryFromRecipient(attrs);
@@ -5617,7 +5662,20 @@ class WhalibmobClient extends EventEmitter {
5617
5662
  });
5618
5663
  }
5619
5664
 
5665
+ // Ack on every exit path (early return or a throwing listener), like
5666
+ // whatsmeow's deferred maybeDeferredAck(). Primary pairing acks itself.
5620
5667
  _handleNotification(node) {
5668
+ const attrs = (node && node.attrs) || {};
5669
+ let ackOwnedElsewhere = false;
5670
+ try {
5671
+ ackOwnedElsewhere = WhalibmobClient.prototype._processNotification.call(this, node) ===
5672
+ NOTIFICATION_ACK_OWNED;
5673
+ } finally {
5674
+ if (!ackOwnedElsewhere) sendNotificationAck(this, attrs, attrs.type || '');
5675
+ }
5676
+ }
5677
+
5678
+ _processNotification(node) {
5621
5679
  const attrs = node.attrs || {};
5622
5680
  const type = attrs.type || '';
5623
5681
 
@@ -5702,7 +5760,7 @@ class WhalibmobClient extends EventEmitter {
5702
5760
  });
5703
5761
  }
5704
5762
  // Primary handler owns durability and the transport ACK.
5705
- return;
5763
+ return NOTIFICATION_ACK_OWNED;
5706
5764
  }
5707
5765
  }
5708
5766
 
@@ -5843,15 +5901,6 @@ class WhalibmobClient extends EventEmitter {
5843
5901
  this.emit('identity_change', { jid: fromJid, user: fromPhone });
5844
5902
  }
5845
5903
 
5846
- // Ack the notification
5847
- if (this._socket && this._connected) {
5848
- this._socket.sendNode(new BinaryNode('ack', {
5849
- id: attrs.id || '',
5850
- class: 'notification',
5851
- type: type,
5852
- to: attrs.from || 's.whatsapp.net'
5853
- }, null));
5854
- }
5855
5904
  }
5856
5905
 
5857
5906
  /**
@@ -354,7 +354,7 @@ class SenderKeyStore {
354
354
  this._save();
355
355
  }
356
356
 
357
- // Raw access for WaSignalGroup SenderKeyRecord storage (JSON-serialized Buffer format)
357
+ // Raw access for sender-key record storage (JSON-serialized Buffer format)
358
358
  loadRecord(key) {
359
359
  const v = this._data['wsg:' + key];
360
360
  if (!v) return null;