@hansaka02/baileys 7.3.4 → 7.3.6

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 (50) hide show
  1. package/README.md +203 -247
  2. package/lib/Defaults/baileys-version.json +2 -2
  3. package/lib/Defaults/connection.js +1 -1
  4. package/lib/Defaults/constants.js +13 -1
  5. package/lib/Defaults/history.js +3 -1
  6. package/lib/Signal/Group/sender-chain-key.js +1 -14
  7. package/lib/Signal/Group/sender-key-distribution-message.js +2 -2
  8. package/lib/Signal/Group/sender-key-record.js +2 -11
  9. package/lib/Signal/Group/sender-key-state.js +11 -57
  10. package/lib/Signal/libsignal.js +200 -116
  11. package/lib/Signal/lid-mapping.js +121 -68
  12. package/lib/Socket/Client/websocket.js +9 -2
  13. package/lib/Socket/business.js +5 -1
  14. package/lib/Socket/chats.js +180 -89
  15. package/lib/Socket/community.js +169 -41
  16. package/lib/Socket/groups.js +25 -21
  17. package/lib/Socket/messages-recv.js +458 -333
  18. package/lib/Socket/messages-send.js +517 -572
  19. package/lib/Socket/mex.js +61 -0
  20. package/lib/Socket/newsletter.js +159 -252
  21. package/lib/Socket/socket.js +283 -100
  22. package/lib/Types/Newsletter.js +32 -25
  23. package/lib/Utils/auth-utils.js +189 -354
  24. package/lib/Utils/browser-utils.js +43 -0
  25. package/lib/Utils/chat-utils.js +166 -41
  26. package/lib/Utils/decode-wa-message.js +77 -35
  27. package/lib/Utils/event-buffer.js +80 -24
  28. package/lib/Utils/generics.js +28 -128
  29. package/lib/Utils/history.js +10 -8
  30. package/lib/Utils/index.js +1 -1
  31. package/lib/Utils/link-preview.js +17 -32
  32. package/lib/Utils/lt-hash.js +28 -22
  33. package/lib/Utils/make-mutex.js +26 -28
  34. package/lib/Utils/message-retry-manager.js +51 -3
  35. package/lib/Utils/messages-media.js +343 -151
  36. package/lib/Utils/messages.js +806 -792
  37. package/lib/Utils/noise-handler.js +33 -2
  38. package/lib/Utils/pre-key-manager.js +126 -0
  39. package/lib/Utils/process-message.js +115 -55
  40. package/lib/Utils/signal.js +45 -18
  41. package/lib/Utils/validate-connection.js +52 -29
  42. package/lib/WABinary/constants.js +1268 -1268
  43. package/lib/WABinary/decode.js +58 -4
  44. package/lib/WABinary/encode.js +54 -7
  45. package/lib/WABinary/jid-utils.js +58 -11
  46. package/lib/WAM/constants.js +19064 -11563
  47. package/lib/WAM/encode.js +57 -8
  48. package/lib/WAUSync/USyncQuery.js +35 -19
  49. package/package.json +9 -8
  50. package/lib/Socket/usync.js +0 -83
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 3000, 1030003753]
3
- }
2
+ "version": [2, 3000, 1030831524]
3
+ }
@@ -40,7 +40,7 @@ const DEFAULT_CONNECTION_CONFIG = {
40
40
  patch: false,
41
41
  snapshot: false,
42
42
  },
43
- countryCode: 'EN',
43
+ countryCode: 'US',
44
44
  getMessage: async () => undefined,
45
45
  cachedGroupMetadata: async () => undefined,
46
46
  makeSignalRepository: makeLibSignalRepository
@@ -10,6 +10,14 @@ const DEFAULT_ORIGIN = 'https://web.whatsapp.com'
10
10
 
11
11
  const PHONE_CONNECTION_CB = 'CB:Pong'
12
12
 
13
+ const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0])
14
+
15
+ const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1])
16
+
17
+ const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5])
18
+
19
+ const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6])
20
+
13
21
  const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60
14
22
 
15
23
  const NOISE_MODE = 'Noise_XX_25519_AESGCM_SHA256\0\0\0\0'
@@ -25,7 +33,7 @@ const URL_REGEX = /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{
25
33
 
26
34
  const MIN_PREKEY_COUNT = 5
27
35
 
28
- const INITIAL_PREKEY_COUNT = 30
36
+ const INITIAL_PREKEY_COUNT = 812
29
37
 
30
38
  const UPLOAD_TIMEOUT = 30000 // 30 seconds
31
39
 
@@ -47,6 +55,10 @@ module.exports = {
47
55
  PHONENUMBER_MCC,
48
56
  DEFAULT_ORIGIN,
49
57
  PHONE_CONNECTION_CB,
58
+ WA_ADV_ACCOUNT_SIG_PREFIX,
59
+ WA_ADV_DEVICE_SIG_PREFIX,
60
+ WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX,
61
+ WA_ADV_HOSTED_DEVICE_SIG_PREFIX,
50
62
  WA_DEFAULT_EPHEMERAL,
51
63
  NOISE_MODE,
52
64
  DICT_VERSION,
@@ -9,7 +9,9 @@ const PROCESSABLE_HISTORY_TYPES = [
9
9
  proto.Message.HistorySyncType.PUSH_NAME,
10
10
  proto.Message.HistorySyncType.RECENT,
11
11
  proto.Message.HistorySyncType.FULL,
12
- proto.Message.HistorySyncType.ON_DEMAND
12
+ proto.Message.HistorySyncType.ON_DEMAND,
13
+ proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
14
+ proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3
13
15
  ]
14
16
 
15
17
  module.exports = {
@@ -10,20 +10,7 @@ class SenderChainKey {
10
10
  this.MESSAGE_KEY_SEED = Buffer.from([0x01])
11
11
  this.CHAIN_KEY_SEED = Buffer.from([0x02])
12
12
  this.iteration = iteration
13
- if (Buffer.isBuffer(chainKey)) {
14
- // backported from @MartinSchere's PR
15
- this.chainKey = chainKey
16
- }
17
- else if (chainKey instanceof Uint8Array) {
18
- this.chainKey = Buffer.from(chainKey)
19
- }
20
- else if (chainKey && typeof chainKey === 'object') {
21
- // backported from @MartinSchere (#1741)
22
- this.chainKey = Buffer.from(Object.values(chainKey)) // temp fix // backported from @MartinSchere (#1741)
23
- }
24
- else {
25
- this.chainKey = Buffer.alloc(0)
26
- }
13
+ this.chainKey = Buffer.from(chainKey)
27
14
  }
28
15
  getIteration() {
29
16
  return this.iteration
@@ -56,10 +56,10 @@ class SenderKeyDistributionMessage extends CiphertextMessage {
56
56
  return this.iteration
57
57
  }
58
58
  getChainKey() {
59
- return typeof this.chainKey === 'string' ? Buffer.from(this.chainKey, 'base64') : this.chainKey
59
+ return this.chainKey
60
60
  }
61
61
  getSignatureKey() {
62
- return typeof this.signatureKey === 'string' ? Buffer.from(this.signatureKey, 'base64') : this.signatureKey
62
+ return this.signatureKey
63
63
  }
64
64
  getId() {
65
65
  return this.id
@@ -38,17 +38,8 @@ class SenderKeyRecord {
38
38
  return this.senderKeyStates.map(state => state.getStructure())
39
39
  }
40
40
  static deserialize(data) {
41
- let parsed
42
- if (typeof data === 'string') {
43
- parsed = JSON.parse(data, BufferJSON.reviver)
44
- }
45
- else if (data instanceof Uint8Array) {
46
- const str = Buffer.from(data).toString('utf-8')
47
- parsed = JSON.parse(str, BufferJSON.reviver)
48
- }
49
- else {
50
- parsed = data
51
- }
41
+ const str = Buffer.from(data).toString('utf-8')
42
+ const parsed = JSON.parse(str, BufferJSON.reviver)
52
43
  return new SenderKeyRecord(parsed)
53
44
  }
54
45
  }
@@ -9,16 +9,6 @@ class SenderKeyState {
9
9
  constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
10
10
  this.MAX_MESSAGE_KEYS = 2000
11
11
 
12
- const toBuffer = (val) => {
13
- if (!val)
14
- return Buffer.alloc(0)
15
- if (typeof val === 'string')
16
- return Buffer.from(val, 'base64')
17
- if (val instanceof Uint8Array || Array.isArray(val))
18
- return Buffer.from(val)
19
- return Buffer.alloc(0)
20
- }
21
-
22
12
  if (senderKeyStateStructure) {
23
13
  this.senderKeyStateStructure = {
24
14
  ...senderKeyStateStructure,
@@ -32,22 +22,17 @@ class SenderKeyState {
32
22
  signatureKeyPublic = signatureKeyPair.public
33
23
  signatureKeyPrivate = signatureKeyPair.private
34
24
  }
35
- chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey
36
-
37
- const senderChainKeyStructure = {
38
- iteration: iteration || 0,
39
- seed: chainKey ? toBuffer(chainKey) : Buffer.alloc(0)
40
- }
41
-
42
- const signingKeyStructure = {
43
- public: toBuffer(signatureKeyPublic),
44
- private: signatureKeyPrivate ? toBuffer(signatureKeyPrivate) : undefined
45
- }
46
25
 
47
26
  this.senderKeyStateStructure = {
48
27
  senderKeyId: id || 0,
49
- senderChainKey: senderChainKeyStructure,
50
- senderSigningKey: signingKeyStructure,
28
+ senderChainKey: {
29
+ iteration: iteration || 0,
30
+ seed: Buffer.from(chainKey || [])
31
+ },
32
+ senderSigningKey: {
33
+ public: Buffer.from(signatureKeyPublic || []),
34
+ private: Buffer.from(signatureKeyPrivate || [])
35
+ },
51
36
  senderMessageKeys: []
52
37
  }
53
38
  }
@@ -65,25 +50,7 @@ class SenderKeyState {
65
50
  }
66
51
  }
67
52
  getSigningKeyPublic() {
68
- let key = this.senderKeyStateStructure.senderSigningKey.public
69
-
70
- // normalize into Buffer
71
- if (!Buffer.isBuffer(key)) {
72
- if (key instanceof Uint8Array) {
73
- key = Buffer.from(key)
74
- }
75
- else if (typeof key === 'string') {
76
- key = Buffer.from(key, 'base64')
77
- }
78
- else if (key && typeof key === 'object') {
79
- return Buffer.from(Object.values(key)) // temp fix // inspired by @MartinSchere 's #1741
80
- }
81
- else {
82
- key = Buffer.from(key || [])
83
- }
84
- }
85
-
86
- const publicKey = key
53
+ const publicKey = Buffer.from(this.senderKeyStateStructure.senderSigningKey.public)
87
54
 
88
55
  if (publicKey.length === 32) {
89
56
  const fixed = Buffer.alloc(33)
@@ -98,21 +65,6 @@ class SenderKeyState {
98
65
  }
99
66
  getSigningKeyPrivate() {
100
67
  const privateKey = this.senderKeyStateStructure.senderSigningKey.private
101
- if (!privateKey) {
102
- return undefined
103
- }
104
- if (Buffer.isBuffer(privateKey)) {
105
- return privateKey
106
- }
107
- else if (privateKey instanceof Uint8Array) {
108
- return Buffer.from(privateKey)
109
- }
110
- else if (privateKey && typeof privateKey === 'object') {
111
- return Buffer.from(Object.values(privateKey)) // temp fix // inspired by @MartinSchere 's #1741
112
- }
113
- else if (typeof privateKey === 'string') {
114
- return Buffer.from(privateKey, 'base64')
115
- }
116
68
  return Buffer.from(privateKey || [])
117
69
  }
118
70
  hasSenderMessageKey(iteration) {
@@ -130,11 +82,13 @@ class SenderKeyState {
130
82
  }
131
83
  removeSenderMessageKey(iteration) {
132
84
  const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration)
85
+
133
86
  if (index !== -1) {
134
87
  const messageKey = this.senderKeyStateStructure.senderMessageKeys[index]
135
88
  this.senderKeyStateStructure.senderMessageKeys.splice(index, 1)
136
89
  return new SenderMessageKey(messageKey.iteration, messageKey.seed)
137
90
  }
91
+
138
92
  return null
139
93
  }
140
94
  getStructure() {