@badzz88/baileys 8.5.2 → 8.5.4

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 (110) hide show
  1. package/README.md +1 -1
  2. package/WAProto/WAProto.proto +1256 -75
  3. package/WAProto/index.d.ts +36042 -19649
  4. package/WAProto/index.js +181990 -135645
  5. package/engine-requirements.js +7 -15
  6. package/lib/Defaults/index.js +22 -17
  7. package/lib/Signal/Group/group_cipher.js +5 -5
  8. package/lib/Signal/Group/keyhelper.js +4 -4
  9. package/lib/Signal/Group/sender-chain-key.js +2 -2
  10. package/lib/Signal/Group/sender-key-distribution-message.js +1 -1
  11. package/lib/Signal/Group/sender-key-message.js +3 -3
  12. package/lib/Signal/Group/sender-key-record.js +1 -1
  13. package/lib/Signal/Group/sender-message-key.js +5 -5
  14. package/lib/Signal/libsignal.js +39 -59
  15. package/lib/Signal/lid-mapping.js +28 -10
  16. package/lib/Socket/aigroups.js +5 -5
  17. package/lib/Socket/business.js +3 -11
  18. package/lib/Socket/chats.js +668 -319
  19. package/lib/Socket/communities.js +85 -89
  20. package/lib/Socket/graphql.js +435 -228
  21. package/lib/Socket/groups.js +132 -211
  22. package/lib/Socket/index.js +9 -7
  23. package/lib/Socket/interactive-handler.js +117 -60
  24. package/lib/Socket/interop.js +56 -175
  25. package/lib/Socket/managed-account.js +79 -48
  26. package/lib/Socket/messages-recv.js +898 -340
  27. package/lib/Socket/messages-send.js +462 -160
  28. package/lib/Socket/mex.js +40 -53
  29. package/lib/Socket/newsletter.js +291 -291
  30. package/lib/Socket/privacy.js +77 -265
  31. package/lib/Socket/registration.js +164 -157
  32. package/lib/Socket/socket.js +181 -199
  33. package/lib/Socket/username.js +144 -227
  34. package/lib/Store/make-cache-manager-store.js +2 -2
  35. package/lib/Store/make-in-memory-store.js +25 -141
  36. package/lib/Types/Auth.js +3 -3
  37. package/lib/Types/Label.js +1 -1
  38. package/lib/Types/LabelAssociation.js +1 -1
  39. package/lib/Types/Newsletter.js +96 -65
  40. package/lib/Types/State.js +4 -4
  41. package/lib/Types/index.js +1 -1
  42. package/lib/Utils/auth-utils.js +52 -57
  43. package/lib/Utils/browser-utils.js +1 -1
  44. package/lib/Utils/business.js +2 -6
  45. package/lib/Utils/chat-utils.js +102 -38
  46. package/lib/Utils/crypto.js +54 -84
  47. package/lib/Utils/decode-wa-message.js +316 -83
  48. package/lib/Utils/event-buffer.js +37 -61
  49. package/lib/Utils/generics.js +157 -103
  50. package/lib/Utils/group-history.js +3 -12
  51. package/lib/Utils/history.js +15 -15
  52. package/lib/Utils/index.js +1 -5
  53. package/lib/Utils/link-preview.js +3 -8
  54. package/lib/Utils/lt-hash.js +2 -35
  55. package/lib/Utils/make-mutex.js +1 -1
  56. package/lib/Utils/message-inspect.js +393 -0
  57. package/lib/Utils/message-retry-manager.js +27 -92
  58. package/lib/Utils/messages-media.js +159 -130
  59. package/lib/Utils/messages.js +144 -566
  60. package/lib/Utils/meta-ai-msmsg.js +62 -202
  61. package/lib/Utils/noise-handler.js +19 -21
  62. package/lib/Utils/offline-node-processor.js +3 -8
  63. package/lib/Utils/pre-key-manager.js +13 -23
  64. package/lib/Utils/process-message.js +197 -106
  65. package/lib/Utils/reporting-utils.js +2 -2
  66. package/lib/Utils/signal.js +28 -63
  67. package/lib/Utils/stanza-ack.js +39 -12
  68. package/lib/Utils/sync-action-utils.js +4 -7
  69. package/lib/Utils/tc-token-utils.js +20 -25
  70. package/lib/Utils/use-multi-file-auth-state.js +30 -14
  71. package/lib/Utils/validate-connection.js +59 -19
  72. package/lib/WABinary/decode.js +50 -16
  73. package/lib/WABinary/encode.js +54 -224
  74. package/lib/WABinary/generic-utils.js +7 -97
  75. package/lib/WABinary/jid-utils.js +27 -14
  76. package/lib/WAM/encode.js +7 -7
  77. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +58 -1
  78. package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -1
  79. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +13 -5
  80. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -4
  81. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +20 -7
  82. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +865 -0
  83. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +1 -1
  84. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +2 -2
  85. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -2
  86. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +1 -1
  87. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -1
  88. package/lib/WAUSync/Protocols/index.js +1 -0
  89. package/lib/WAUSync/USyncBackoff.js +26 -0
  90. package/lib/WAUSync/USyncQuery.js +77 -6
  91. package/lib/WAUSync/USyncUser.js +16 -8
  92. package/lib/WAUSync/index.js +1 -0
  93. package/lib/antiban.js +608 -854
  94. package/lib/index.js +3 -3
  95. package/package.json +16 -19
  96. package/lib/Socket/luxu.js +0 -387
  97. package/lib/Socket/text-router.js +0 -83
  98. package/lib/Store/keyed-db.js +0 -108
  99. package/lib/Types/Mex.js +0 -112
  100. package/lib/Utils/command-loader.d.ts +0 -31
  101. package/lib/Utils/command-loader.js +0 -100
  102. package/lib/Utils/companion-reg-client-utils.js +0 -42
  103. package/lib/Utils/curve25519-js.js +0 -275
  104. package/lib/Utils/native-bridge.js +0 -82
  105. package/lib/Utils/session-pool.d.ts +0 -16
  106. package/lib/Utils/session-pool.js +0 -94
  107. package/lib/Utils/sticker.d.ts +0 -17
  108. package/lib/Utils/sticker.js +0 -145
  109. package/lib/Utils/view-once-cache.d.ts +0 -9
  110. package/lib/Utils/view-once-cache.js +0 -79
@@ -1,6 +1,12 @@
1
1
  'use strict'
2
2
  Object.defineProperty(exports, '__esModule', { value: true })
3
- exports.signedKeyPair = exports.Curve = exports.generateSignalPubKey = exports.hkdf = exports.md5 = void 0
3
+ exports.signedKeyPair =
4
+ exports.Curve =
5
+ exports.generateSignalPubKey =
6
+ exports.getEnabledFeatures =
7
+ exports.hkdf =
8
+ exports.md5 =
9
+ void 0
4
10
  exports.aesEncryptGCM = aesEncryptGCM
5
11
  exports.aesDecryptGCM = aesDecryptGCM
6
12
  exports.aesEncryptCTR = aesEncryptCTR
@@ -14,64 +20,36 @@ exports.sha256 = sha256
14
20
  exports.derivePairingCodeKey = derivePairingCodeKey
15
21
  const { subtle } = globalThis.crypto
16
22
  const Defaults_1 = require('../Defaults')
17
- const nodeCrypto = require('crypto')
18
-
19
- // Pure Node.js `crypto` / hand-written JS only -- no native/WASM module
20
- // dependency anywhere in this file (including `Curve`, X25519 key exchange +
21
- // XEdDSA signing). XEdDSA specifically is validated against the official
22
- // RFC 8032 Ed25519 test vectors, RFC 7748-style X25519 DH vectors, and
23
- // hundreds of randomized Montgomery<->Edwards interop + self-consistency
24
- // checks -- see ./curve25519-js.js for details and references.
25
-
26
- // ── MD5 ────────────────────────────────────────────────────────────────────────
27
- const md5 = buffer => nodeCrypto.createHash('md5').update(buffer).digest()
28
- Object.defineProperty(exports, 'md5', { enumerable: true, get: () => md5 })
29
-
30
- // ── HKDF (RFC 5869) ─────────────────────────────────────────────────────────────
31
- const hkdfExtractJS = (salt, ikm) => nodeCrypto.createHmac('sha256', salt).update(ikm).digest()
32
- const hkdfExpandJS = (prk, length, info) => {
33
- const hashLen = 32
34
- const n = Math.ceil(length / hashLen)
35
- let t = Buffer.alloc(0)
36
- let okm = Buffer.alloc(0)
37
- for (let i = 1; i <= n; i++) {
38
- t = nodeCrypto
39
- .createHmac('sha256', prk)
40
- .update(Buffer.concat([t, info, Buffer.from([i])]))
41
- .digest()
42
- okm = Buffer.concat([okm, t])
43
- }
44
- return okm.subarray(0, length)
45
- }
46
- const hkdf = (ikm, length, options = {}) => {
47
- const ikmBuf = Buffer.isBuffer(ikm) ? ikm : Buffer.from(ikm)
48
- const saltBuf = options.salt
49
- ? Buffer.isBuffer(options.salt)
50
- ? options.salt
51
- : Buffer.from(options.salt)
52
- : Buffer.alloc(32) // RFC 5869: default salt is HashLen zero bytes
53
- const infoBuf = options.info
54
- ? Buffer.isBuffer(options.info)
55
- ? options.info
56
- : Buffer.from(options.info)
57
- : Buffer.alloc(0)
58
- const prk = hkdfExtractJS(saltBuf, ikmBuf)
59
- return hkdfExpandJS(prk, length, infoBuf)
60
- }
61
- Object.defineProperty(exports, 'hkdf', { enumerable: true, get: () => hkdf })
23
+ const rb = require('whatsapp-rust-bridge')
24
+
25
+
26
+ Object.defineProperty(exports, 'md5', { enumerable: true, get: () => rb.md5 })
27
+ Object.defineProperty(exports, 'hkdf', { enumerable: true, get: () => rb.hkdf })
28
+ Object.defineProperty(exports, 'getEnabledFeatures', { enumerable: true, get: () => rb.getEnabledFeatures })
29
+
62
30
 
63
- // ── Signal pub key helper ─────────────────────────────────────────────────────
64
31
  const generateSignalPubKey = pubKey =>
65
32
  pubKey.length === 33 ? pubKey : Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey])
66
33
  exports.generateSignalPubKey = generateSignalPubKey
67
34
 
68
- // ── Curve — X25519 key exchange + XEdDSA signing ──────────────────────────────
69
- const curve25519JS = require('./curve25519-js')
35
+
70
36
  exports.Curve = {
71
- generateKeyPair: () => curve25519JS.generateKeyPairJS(),
72
- sharedKey: (privateKey, publicKey) => curve25519JS.sharedKeyJS(privateKey, publicKey),
73
- sign: (privateKey, buf) => curve25519JS.signJS(privateKey, buf),
74
- verify: (pubKey, message, signature) => curve25519JS.verifyJS(pubKey, message, signature)
37
+ generateKeyPair: () => {
38
+ const pair = rb.generateKeyPair()
39
+ return {
40
+ private: Buffer.from(pair.privKey),
41
+ public: Buffer.from(pair.pubKey).subarray(1)
42
+ }
43
+ },
44
+ sharedKey: (privateKey, publicKey) => Buffer.from(rb.calculateAgreement(generateSignalPubKey(publicKey), privateKey)),
45
+ sign: (privateKey, buf) => rb.calculateSignature(privateKey, buf),
46
+ verify: (pubKey, message, signature) => {
47
+ try {
48
+ return rb.verifySignature(generateSignalPubKey(pubKey), message, signature)
49
+ } catch {
50
+ return false
51
+ }
52
+ }
75
53
  }
76
54
 
77
55
  const signedKeyPair = (identityKeyPair, keyId) => {
@@ -82,65 +60,57 @@ const signedKeyPair = (identityKeyPair, keyId) => {
82
60
  }
83
61
  exports.signedKeyPair = signedKeyPair
84
62
 
85
- // ── AES-256-GCM ───────────────────────────────────────────────────────────────
63
+
86
64
  function aesEncryptGCM(plaintext, key, iv, additionalData) {
87
- const cipher = nodeCrypto.createCipheriv('aes-256-gcm', key, iv)
88
- if (additionalData) cipher.setAAD(additionalData)
89
- const encrypted = Buffer.concat([cipher.update(plaintext), cipher.final()])
90
- return Buffer.concat([encrypted, cipher.getAuthTag()])
65
+ return Buffer.from(rb.aesEncryptGCM(plaintext, key, iv, additionalData))
91
66
  }
92
67
 
93
68
  function aesDecryptGCM(ciphertext, key, iv, additionalData) {
94
- const authTag = ciphertext.subarray(ciphertext.length - 16)
95
- const encrypted = ciphertext.subarray(0, ciphertext.length - 16)
96
- const decipher = nodeCrypto.createDecipheriv('aes-256-gcm', key, iv)
97
- if (additionalData) decipher.setAAD(additionalData)
98
- decipher.setAuthTag(authTag)
99
- return Buffer.concat([decipher.update(encrypted), decipher.final()])
69
+ return Buffer.from(rb.aesDecryptGCM(ciphertext, key, iv, additionalData))
100
70
  }
101
71
 
102
- // ── AES-256-CTR ───────────────────────────────────────────────────────────────
72
+
103
73
  function aesEncryptCTR(plaintext, key, iv) {
104
- const cipher = nodeCrypto.createCipheriv('aes-256-ctr', key, iv)
105
- return Buffer.concat([cipher.update(plaintext), cipher.final()])
74
+ return Buffer.from(rb.aesEncryptCTR(plaintext, key, iv))
106
75
  }
107
76
 
108
77
  function aesDecryptCTR(ciphertext, key, iv) {
109
- const decipher = nodeCrypto.createDecipheriv('aes-256-ctr', key, iv)
110
- return Buffer.concat([decipher.update(ciphertext), decipher.final()])
78
+ return Buffer.from(rb.aesDecryptCTR(ciphertext, key, iv))
111
79
  }
112
80
 
113
- // ── AES-256-CBC (no explicit IV -- zero IV, legacy/unused elsewhere in this lib) ─
81
+
114
82
  function aesDecrypt(buffer, key) {
115
- return aesDecryptWithIV(buffer, key, Buffer.alloc(16))
83
+ return Buffer.from(rb.aesDecrypt(buffer, key))
116
84
  }
117
85
 
118
- function aesEncrypt(buffer, key) {
119
- return aesEncrypWithIV(buffer, key, Buffer.alloc(16))
86
+ function aesDecryptWithIV(buffer, key, IV) {
87
+ return Buffer.from(rb.aesDecryptWithIV(buffer, key, IV))
120
88
  }
121
89
 
122
- // ── AES-256-CBC (explicit IV) ─────────────────────────────────────────────────
123
- function aesDecryptWithIV(buffer, key, IV) {
124
- const decipher = nodeCrypto.createDecipheriv('aes-256-cbc', key, IV)
125
- return Buffer.concat([decipher.update(buffer), decipher.final()])
90
+ function aesEncrypt(buffer, key) {
91
+ return Buffer.from(rb.aesEncrypt(buffer, key))
126
92
  }
127
93
 
128
94
  function aesEncrypWithIV(buffer, key, IV) {
129
- const cipher = nodeCrypto.createCipheriv('aes-256-cbc', key, IV)
130
- return Buffer.concat([cipher.update(buffer), cipher.final()])
95
+ return Buffer.from(rb.aesEncrypWithIV(buffer, key, IV))
131
96
  }
132
97
 
133
- // ── HMAC-SHA256 ───────────────────────────────────────────────────────────────
98
+
134
99
  function hmacSign(buffer, key, variant = 'sha256') {
135
- return nodeCrypto.createHmac(variant, key).update(buffer).digest()
100
+ if (variant !== 'sha256') {
101
+
102
+ const { createHmac } = require('crypto')
103
+ return createHmac(variant, key).update(buffer).digest()
104
+ }
105
+ return Buffer.from(rb.hmacSign(buffer, key))
136
106
  }
137
107
 
138
- // ── SHA-256 ───────────────────────────────────────────────────────────────────
108
+
139
109
  function sha256(buffer) {
140
- return nodeCrypto.createHash('sha256').update(buffer).digest()
110
+ return Buffer.from(rb.sha256(buffer))
141
111
  }
142
112
 
143
- // ── PBKDF2 pairing code key ───────────────────────────────────────────────────
113
+
144
114
  async function derivePairingCodeKey(pairingCode, salt) {
145
115
  const encoder = new TextEncoder()
146
116
  const pairingCodeBuffer = encoder.encode(pairingCode)