@badzz88/baileys 8.5.3 → 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 -295
  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 +1 -1
  95. package/package.json +16 -20
  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
@@ -5,7 +5,7 @@ const WABinary_1 = require('../../WABinary')
5
5
  class USyncPictureProtocol {
6
6
  constructor(type = 'image') {
7
7
  this.name = 'picture'
8
- // "image" for full resolution, "preview" for thumbnail
8
+
9
9
  this.type = type
10
10
  }
11
11
  getQueryElement() {
@@ -5,7 +5,7 @@ const WABinary_1 = require('../../WABinary')
5
5
  class USyncSidelistProtocol {
6
6
  constructor(useLidAddressing = true) {
7
7
  this.name = 'sidelist'
8
- // When true, sends addressing_mode="lid" — required for interop/LID-mode contacts
8
+
9
9
  this.useLidAddressing = useLidAddressing
10
10
  }
11
11
  getQueryElement() {
@@ -22,7 +22,7 @@ class USyncSidelistProtocol {
22
22
  parser(node) {
23
23
  if (node.tag !== 'sidelist' && node.tag !== 'side_list') return null
24
24
  ;(0, WABinary_1.assertNodeErrorFree)(node)
25
- // Returns minimal parsed data; the full side_list is parsed in USyncQuery
25
+
26
26
  return { type: node.attrs?.type ?? null }
27
27
  }
28
28
  }
@@ -12,8 +12,13 @@ class USyncStatusProtocol {
12
12
  attrs: {}
13
13
  }
14
14
  }
15
- getUserElement() {
16
- return null
15
+ getUserElement(user) {
16
+ if (!user?.tcToken) return null
17
+ return {
18
+ tag: 'tctoken',
19
+ attrs: {},
20
+ content: user.tcToken
21
+ }
17
22
  }
18
23
  parser(node) {
19
24
  if (node.tag === 'status') {
@@ -23,7 +23,7 @@ class USyncTextStatusProtocol {
23
23
  const text = node.attrs?.text ?? null
24
24
  const emojiNode = (0, WABinary_1.getBinaryNodeChild)(node, 'emoji')
25
25
  const emoji = emojiNode?.attrs?.content ?? null
26
- // expiry is lastUpdateTime + ephemeralDuration (both in ms); 0 means no expiry
26
+
27
27
  const expiresAt = ephemeralDurationSec > 0
28
28
  ? new Date((lastUpdateTimeSec + ephemeralDurationSec) * 1000)
29
29
  : null
@@ -19,7 +19,8 @@ class USyncUsernameProtocol {
19
19
  parser(node) {
20
20
  if (node.tag === 'username') {
21
21
  ;(0, WABinary_1.assertNodeErrorFree)(node)
22
- return typeof node.content === 'string' ? node.content : null
22
+ const username = node.content != null ? node.content.toString() : null
23
+ return username && username.length > 0 ? username : null
23
24
  }
24
25
  return null
25
26
  }
@@ -35,5 +35,6 @@ __exportStar(require('./USyncBotProfileProtocol'), exports)
35
35
  __exportStar(require('./USyncBusinessProtocol'), exports)
36
36
  __exportStar(require('./USyncPictureProtocol'), exports)
37
37
  __exportStar(require('./USyncTextStatusProtocol'), exports)
38
+ __exportStar(require('./USyncLIDProtocol'), exports)
38
39
  __exportStar(require('./USyncSidelistProtocol'), exports)
39
40
  __exportStar(require('./USyncFeatureProtocol'), exports)
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.waitForBackoff = exports.setProtocolBackoffMs = void 0
4
+
5
+ const backoffPromises = new Map()
6
+
7
+ const setProtocolBackoffMs = (protocolName, ms) => {
8
+ backoffPromises.set(protocolName, new Promise(resolve => setTimeout(resolve, ms)))
9
+ }
10
+ exports.setProtocolBackoffMs = setProtocolBackoffMs
11
+
12
+ const shouldWaitForBackoff = query => {
13
+ if (query.context === 'interactive') {
14
+ return false
15
+ }
16
+ const protocolNames = query.protocols.map(p => p.name)
17
+ return !(protocolNames.includes('devices') && (query.context === 'message' || query.context === 'voip'))
18
+ }
19
+
20
+ const waitForBackoff = async query => {
21
+ if (!shouldWaitForBackoff(query)) {
22
+ return
23
+ }
24
+ await Promise.all(query.protocols.map(p => backoffPromises.get(p.name)))
25
+ }
26
+ exports.waitForBackoff = waitForBackoff
@@ -5,10 +5,10 @@ const WABinary_1 = require('../WABinary')
5
5
  const USyncBotProfileProtocol_1 = require('./Protocols/USyncBotProfileProtocol')
6
6
  const USyncLIDProtocol_1 = require('./Protocols/USyncLIDProtocol')
7
7
  const USyncBusinessProtocol_1 = require('./Protocols/USyncBusinessProtocol')
8
+ const USyncFeatureProtocol_1 = require('./Protocols/USyncFeatureProtocol')
8
9
  const USyncPictureProtocol_1 = require('./Protocols/USyncPictureProtocol')
9
10
  const USyncTextStatusProtocol_1 = require('./Protocols/USyncTextStatusProtocol')
10
11
  const USyncSidelistProtocol_1 = require('./Protocols/USyncSidelistProtocol')
11
- const USyncFeatureProtocol_1 = require('./Protocols/USyncFeatureProtocol')
12
12
  const Protocols_1 = require('./Protocols')
13
13
  class USyncQuery {
14
14
  constructor() {
@@ -39,26 +39,85 @@ class USyncQuery {
39
39
  })
40
40
  )
41
41
  const queryResult = {
42
- // TODO: implement errors etc.
42
+ errors: {},
43
+ refresh: {},
43
44
  list: [],
44
45
  sideList: []
45
46
  }
46
47
  const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync')
47
- //TODO: implement error backoff, refresh etc.
48
- //TODO: see if there are any errors in the result node
49
- //const resultNode = getBinaryNodeChild(usyncNode, 'result')
48
+
49
+
50
+
51
+
52
+ const resultNode = usyncNode ? (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'result') : undefined
53
+ if (resultNode) {
54
+ for (const protocol of this.protocols) {
55
+ const protocolNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, protocol.name)
56
+ if (!protocolNode) continue
57
+ const errorNode = (0, WABinary_1.getBinaryNodeChild)(protocolNode, 'error')
58
+ if (errorNode) {
59
+ queryResult.errors[protocol.name] = {
60
+ errorCode: errorNode.attrs.code ? +errorNode.attrs.code : undefined,
61
+ errorText: errorNode.attrs.text,
62
+ errorBackoff: errorNode.attrs.backoff ? +errorNode.attrs.backoff : undefined
63
+ }
64
+ } else if (protocolNode.attrs.refresh !== undefined) {
65
+ queryResult.refresh[protocol.name] = +protocolNode.attrs.refresh
66
+ }
67
+ }
68
+ }
50
69
  const parseUserNodes = nodes => {
51
70
  return nodes.reduce((acc, node) => {
52
71
  const id = node?.attrs.jid
53
72
  if (id) {
73
+
74
+
75
+ const userErrorCode = node?.attrs?.error ? parseInt(node.attrs.error, 10) : 0
76
+ const isBlockedByAttr = userErrorCode === 401 || userErrorCode === 403 || userErrorCode === 405
77
+
54
78
  const data = Array.isArray(node?.content)
55
79
  ? Object.fromEntries(
56
80
  node.content
57
81
  .map(content => {
58
82
  const protocol = content.tag
83
+
84
+
85
+
86
+ if (protocol === 'privacy') {
87
+ const tokenNode = (0, WABinary_1.getBinaryNodeChild)(content, 'token')
88
+ const modeTsNode = (0, WABinary_1.getBinaryNodeChild)(content, 'mode_ts')
89
+
90
+ const tokenVal = tokenNode?.content || content.attrs?.token
91
+ const modeTsVal =
92
+ modeTsNode?.content?.toString?.() || modeTsNode?.attrs?.value || content.attrs?.mode_ts || null
93
+ if (tokenVal) {
94
+ return [
95
+ 'privacy',
96
+ {
97
+ token:
98
+ Buffer.isBuffer(tokenVal) || tokenVal instanceof Uint8Array
99
+ ? Buffer.from(tokenVal)
100
+ : tokenVal,
101
+ modeTs: modeTsVal
102
+ }
103
+ ]
104
+ }
105
+ return ['privacy', null]
106
+ }
107
+
59
108
  const parser = protocolMap[protocol]
60
109
  if (parser) {
61
- return [protocol, parser(content)]
110
+ try {
111
+ return [protocol, parser(content)]
112
+ } catch (err) {
113
+
114
+
115
+ const errCode = err?.data ?? err?.output?.payload?.data
116
+ if (errCode === 401 || errCode === 403 || errCode === 405) {
117
+ return ['isBlockedByContact', true]
118
+ }
119
+ throw err
120
+ }
62
121
  } else {
63
122
  return [protocol, null]
64
123
  }
@@ -66,6 +125,18 @@ class USyncQuery {
66
125
  .filter(([, b]) => b !== null)
67
126
  )
68
127
  : {}
128
+
129
+
130
+ if (isBlockedByAttr) {
131
+ data.isBlockedByContact = true
132
+ }
133
+
134
+
135
+ if ('disappearing_mode' in data) {
136
+ data.disappearingMode = data.disappearing_mode
137
+ delete data.disappearing_mode
138
+ }
139
+
69
140
  acc.push({ ...data, id })
70
141
  }
71
142
  return acc
@@ -30,21 +30,29 @@ class USyncUser {
30
30
  this.personaId = personaId
31
31
  return this
32
32
  }
33
- withPictureId(pictureId) {
34
- this.pictureId = pictureId
33
+ withTcToken(tcToken) {
34
+ this.tcToken = tcToken
35
35
  return this
36
36
  }
37
- withVerifiedNameSerial(serial) {
38
- this.verifiedNameSerial = serial
37
+ withPnJid(pnJid) {
38
+ this.pnJid = pnJid
39
39
  return this
40
40
  }
41
- withBusinessProfileTag(tag) {
42
- this.businessProfileTag = tag
41
+ withDeviceHash(deviceHash) {
42
+ this.deviceHash = deviceHash
43
43
  return this
44
44
  }
45
- withSidelistDelete(del = true) {
46
- this.sidelistDelete = del
45
+ withTs(ts) {
46
+ this.ts = ts
47
47
  return this
48
48
  }
49
+ withExpectedTs(expectedTs) {
50
+ this.expectedTs = expectedTs
51
+ return this
52
+ }
53
+
54
+ validate() {
55
+ return !!(this.id || this.phone || this.username || this.pnJid)
56
+ }
49
57
  }
50
58
  exports.USyncUser = USyncUser
@@ -29,3 +29,4 @@ Object.defineProperty(exports, '__esModule', { value: true })
29
29
  __exportStar(require('./Protocols/index'), exports)
30
30
  __exportStar(require('./USyncQuery'), exports)
31
31
  __exportStar(require('./USyncUser'), exports)
32
+ __exportStar(require('./USyncBackoff'), exports)