@badzz88/baileys 8.4.9 → 8.5.1

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 (154) hide show
  1. package/README.md +1 -1
  2. package/WAProto/WAProto.proto +6 -347
  3. package/WAProto/fix-imports.js +85 -86
  4. package/WAProto/index.d.ts +25 -4913
  5. package/WAProto/index.js +93 -14069
  6. package/{src → lib}/Defaults/index.js +2 -13
  7. package/{src → lib}/Signal/Group/group_cipher.js +5 -5
  8. package/{src → lib}/Signal/Group/keyhelper.js +4 -4
  9. package/{src → lib}/Signal/Group/sender-chain-key.js +2 -2
  10. package/{src → lib}/Signal/Group/sender-key-distribution-message.js +1 -1
  11. package/{src → lib}/Signal/Group/sender-key-message.js +3 -3
  12. package/{src → lib}/Signal/Group/sender-key-record.js +1 -1
  13. package/{src → lib}/Signal/Group/sender-message-key.js +2 -2
  14. package/{src → lib}/Signal/libsignal.js +26 -6
  15. package/{src → lib}/Socket/chats.js +58 -616
  16. package/{src → lib}/Socket/communities.js +28 -59
  17. package/{src → lib}/Socket/graphql.js +103 -362
  18. package/{src → lib}/Socket/groups.js +29 -77
  19. package/{src → lib}/Socket/index.js +5 -3
  20. package/{src → lib}/Socket/interactive-handler.js +60 -117
  21. package/{src → lib}/Socket/interop.js +19 -36
  22. package/lib/Socket/luxu.js +387 -0
  23. package/{src → lib}/Socket/managed-account.js +27 -58
  24. package/{src → lib}/Socket/messages-recv.js +144 -715
  25. package/{src → lib}/Socket/messages-send.js +102 -412
  26. package/lib/Socket/mex.js +60 -0
  27. package/{src → lib}/Socket/newsletter.js +23 -266
  28. package/{src → lib}/Socket/privacy.js +38 -41
  29. package/{src → lib}/Socket/registration.js +106 -113
  30. package/{src → lib}/Socket/socket.js +101 -88
  31. package/{src → lib}/Socket/text-router.js +17 -1
  32. package/lib/Socket/username.js +243 -0
  33. package/lib/Store/keyed-db.js +108 -0
  34. package/{src → lib}/Store/make-in-memory-store.js +104 -6
  35. package/lib/Types/Mex.js +112 -0
  36. package/{src → lib}/Types/Newsletter.js +41 -72
  37. package/{src → lib}/Types/index.js +1 -0
  38. package/{src → lib}/Utils/chat-utils.js +9 -73
  39. package/lib/Utils/command-loader.d.ts +31 -0
  40. package/lib/Utils/command-loader.js +100 -0
  41. package/lib/Utils/companion-reg-client-utils.js +42 -0
  42. package/lib/Utils/crypto.js +155 -0
  43. package/lib/Utils/curve25519-js.js +275 -0
  44. package/{src → lib}/Utils/decode-wa-message.js +36 -284
  45. package/{src → lib}/Utils/event-buffer.js +27 -6
  46. package/{src → lib}/Utils/generics.js +37 -114
  47. package/{src → lib}/Utils/index.js +5 -1
  48. package/lib/Utils/lt-hash.js +39 -0
  49. package/{src → lib}/Utils/message-retry-manager.js +39 -0
  50. package/{src → lib}/Utils/messages-media.js +58 -105
  51. package/{src → lib}/Utils/messages.js +529 -115
  52. package/lib/Utils/meta-ai-msmsg.js +262 -0
  53. package/lib/Utils/native-bridge.js +82 -0
  54. package/{src → lib}/Utils/noise-handler.js +15 -13
  55. package/{src → lib}/Utils/process-message.js +55 -54
  56. package/{src → lib}/Utils/reporting-utils.js +2 -2
  57. package/lib/Utils/session-pool.d.ts +16 -0
  58. package/lib/Utils/session-pool.js +94 -0
  59. package/{src → lib}/Utils/signal.js +51 -19
  60. package/{src → lib}/Utils/stanza-ack.js +2 -36
  61. package/lib/Utils/sticker.d.ts +17 -0
  62. package/lib/Utils/sticker.js +145 -0
  63. package/{src → lib}/Utils/tc-token-utils.js +1 -1
  64. package/{src → lib}/Utils/validate-connection.js +11 -40
  65. package/lib/Utils/view-once-cache.d.ts +9 -0
  66. package/lib/Utils/view-once-cache.js +79 -0
  67. package/{src → lib}/WABinary/decode.js +4 -38
  68. package/lib/WABinary/encode.js +228 -0
  69. package/{src → lib}/WABinary/generic-utils.js +93 -1
  70. package/{src → lib}/WABinary/jid-utils.js +3 -16
  71. package/{src → lib}/WAM/encode.js +1 -1
  72. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  73. package/{src → lib}/WAUSync/Protocols/USyncContactProtocol.js +1 -7
  74. package/{src → lib}/WAUSync/Protocols/USyncDeviceProtocol.js +5 -13
  75. package/{src → lib}/WAUSync/Protocols/USyncDisappearingModeProtocol.js +4 -1
  76. package/{src → lib}/WAUSync/Protocols/USyncFeatureProtocol.js +2 -17
  77. package/{src → lib}/WAUSync/Protocols/USyncStatusProtocol.js +2 -7
  78. package/{src → lib}/WAUSync/Protocols/USyncUsernameProtocol.js +1 -2
  79. package/{src → lib}/WAUSync/Protocols/index.js +0 -1
  80. package/{src → lib}/WAUSync/USyncQuery.js +6 -77
  81. package/{src → lib}/WAUSync/USyncUser.js +8 -16
  82. package/{src → lib}/WAUSync/index.js +0 -1
  83. package/{src → lib}/antiban.js +266 -355
  84. package/{src → lib}/index.js +2 -2
  85. package/package.json +19 -16
  86. package/WAProto/fix-import.js +0 -38
  87. package/src/Socket/mex.js +0 -47
  88. package/src/Socket/username.js +0 -234
  89. package/src/Utils/crypto.js +0 -125
  90. package/src/Utils/lt-hash.js +0 -10
  91. package/src/Utils/message-inspect.js +0 -400
  92. package/src/Utils/meta-ai-msmsg.js +0 -133
  93. package/src/WABinary/encode.js +0 -58
  94. package/src/WAUSync/Protocols/USyncBusinessProtocol.js +0 -100
  95. package/src/WAUSync/USyncBackoff.js +0 -31
  96. /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
  97. /package/{src → lib}/Signal/Group/ciphertext-message.js +0 -0
  98. /package/{src → lib}/Signal/Group/group-session-builder.js +0 -0
  99. /package/{src → lib}/Signal/Group/index.js +0 -0
  100. /package/{src → lib}/Signal/Group/sender-key-name.js +0 -0
  101. /package/{src → lib}/Signal/Group/sender-key-state.js +0 -0
  102. /package/{src → lib}/Signal/lid-mapping.js +0 -0
  103. /package/{src → lib}/Socket/Client/index.js +0 -0
  104. /package/{src → lib}/Socket/Client/types.js +0 -0
  105. /package/{src → lib}/Socket/Client/websocket.js +0 -0
  106. /package/{src → lib}/Socket/aigroups.js +0 -0
  107. /package/{src → lib}/Socket/business.js +0 -0
  108. /package/{src → lib}/Store/index.js +0 -0
  109. /package/{src → lib}/Store/make-cache-manager-store.js +0 -0
  110. /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
  111. /package/{src → lib}/Store/object-repository.js +0 -0
  112. /package/{src → lib}/Types/Auth.js +0 -0
  113. /package/{src → lib}/Types/Bussines.js +0 -0
  114. /package/{src → lib}/Types/Call.js +0 -0
  115. /package/{src → lib}/Types/Chat.js +0 -0
  116. /package/{src → lib}/Types/Contact.js +0 -0
  117. /package/{src → lib}/Types/Events.js +0 -0
  118. /package/{src → lib}/Types/GroupMetadata.js +0 -0
  119. /package/{src → lib}/Types/Label.js +0 -0
  120. /package/{src → lib}/Types/LabelAssociation.js +0 -0
  121. /package/{src → lib}/Types/Message.js +0 -0
  122. /package/{src → lib}/Types/Product.js +0 -0
  123. /package/{src → lib}/Types/Signal.js +0 -0
  124. /package/{src → lib}/Types/Socket.js +0 -0
  125. /package/{src → lib}/Types/State.js +0 -0
  126. /package/{src → lib}/Types/USync.js +0 -0
  127. /package/{src → lib}/Utils/auth-utils.js +0 -0
  128. /package/{src → lib}/Utils/browser-utils.js +0 -0
  129. /package/{src → lib}/Utils/business.js +0 -0
  130. /package/{src → lib}/Utils/consumer-application.js +0 -0
  131. /package/{src → lib}/Utils/group-history.js +0 -0
  132. /package/{src → lib}/Utils/history.js +0 -0
  133. /package/{src → lib}/Utils/identity-change-handler.js +0 -0
  134. /package/{src → lib}/Utils/jid-display-normalization.js +0 -0
  135. /package/{src → lib}/Utils/link-preview.js +0 -0
  136. /package/{src → lib}/Utils/logger.js +0 -0
  137. /package/{src → lib}/Utils/make-mutex.js +0 -0
  138. /package/{src → lib}/Utils/message-composer.js +0 -0
  139. /package/{src → lib}/Utils/offline-node-processor.js +0 -0
  140. /package/{src → lib}/Utils/pre-key-manager.js +0 -0
  141. /package/{src → lib}/Utils/sync-action-utils.js +0 -0
  142. /package/{src → lib}/Utils/use-multi-file-auth-state.js +0 -0
  143. /package/{src → lib}/Utils/voip-rekey.js +0 -0
  144. /package/{src → lib}/WABinary/constants.js +0 -0
  145. /package/{src → lib}/WABinary/index.js +0 -0
  146. /package/{src → lib}/WABinary/types.js +0 -0
  147. /package/{src → lib}/WAM/BinaryInfo.js +0 -0
  148. /package/{src → lib}/WAM/constants.js +0 -0
  149. /package/{src → lib}/WAM/index.js +0 -0
  150. /package/{src → lib}/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -0
  151. /package/{src → lib}/WAUSync/Protocols/USyncLIDProtocol.js +0 -0
  152. /package/{src → lib}/WAUSync/Protocols/USyncPictureProtocol.js +0 -0
  153. /package/{src → lib}/WAUSync/Protocols/USyncSidelistProtocol.js +0 -0
  154. /package/{src → lib}/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -0
@@ -0,0 +1,228 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.encodeBinaryNode = void 0
4
+ const constants = require('./constants')
5
+ const { jidDecode } = require('./jid-utils')
6
+
7
+ const encodeBinaryNodeJS = (node, opts = constants, buffer = [0]) => {
8
+ const encoded = encodeBinaryNodeInner(node, opts, buffer);
9
+ return Buffer.from(encoded);
10
+ };
11
+ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
12
+ const { TAGS, TOKEN_MAP } = opts;
13
+ const pushByte = (value) => buffer.push(value & 0xff);
14
+ const pushInt = (value, n, littleEndian = false) => {
15
+ for (let i = 0; i < n; i++) {
16
+ const curShift = littleEndian ? i : n - 1 - i;
17
+ buffer.push((value >> (curShift * 8)) & 0xff);
18
+ }
19
+ };
20
+ const pushBytes = (bytes) => {
21
+ for (const b of bytes) {
22
+ buffer.push(b);
23
+ }
24
+ };
25
+ const pushInt16 = (value) => {
26
+ pushBytes([(value >> 8) & 0xff, value & 0xff]);
27
+ };
28
+ const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
29
+ const writeByteLength = (length) => {
30
+ if (length >= 4294967296) {
31
+ throw new Error('string too large to encode: ' + length);
32
+ }
33
+ if (length >= 1 << 20) {
34
+ pushByte(TAGS.BINARY_32);
35
+ pushInt(length, 4); // 32 bit integer
36
+ }
37
+ else if (length >= 256) {
38
+ pushByte(TAGS.BINARY_20);
39
+ pushInt20(length);
40
+ }
41
+ else {
42
+ pushByte(TAGS.BINARY_8);
43
+ pushByte(length);
44
+ }
45
+ };
46
+ const writeStringRaw = (str) => {
47
+ const bytes = Buffer.from(str, 'utf-8');
48
+ writeByteLength(bytes.length);
49
+ pushBytes(bytes);
50
+ };
51
+ const writeJid = ({ domainType, device, user, server }) => {
52
+ if (typeof device !== 'undefined') {
53
+ pushByte(TAGS.AD_JID);
54
+ pushByte(domainType || 0);
55
+ pushByte(device || 0);
56
+ writeString(user);
57
+ }
58
+ else {
59
+ pushByte(TAGS.JID_PAIR);
60
+ if (user.length) {
61
+ writeString(user);
62
+ }
63
+ else {
64
+ pushByte(TAGS.LIST_EMPTY);
65
+ }
66
+ writeString(server);
67
+ }
68
+ };
69
+ const packNibble = (char) => {
70
+ switch (char) {
71
+ case '-':
72
+ return 10;
73
+ case '.':
74
+ return 11;
75
+ case '\0':
76
+ return 15;
77
+ default:
78
+ if (char >= '0' && char <= '9') {
79
+ return char.charCodeAt(0) - '0'.charCodeAt(0);
80
+ }
81
+ throw new Error(`invalid byte for nibble "${char}"`);
82
+ }
83
+ };
84
+ const packHex = (char) => {
85
+ if (char >= '0' && char <= '9') {
86
+ return char.charCodeAt(0) - '0'.charCodeAt(0);
87
+ }
88
+ if (char >= 'A' && char <= 'F') {
89
+ return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
90
+ }
91
+ if (char >= 'a' && char <= 'f') {
92
+ return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
93
+ }
94
+ if (char === '\0') {
95
+ return 15;
96
+ }
97
+ throw new Error(`Invalid hex char "${char}"`);
98
+ };
99
+ const writePackedBytes = (str, type) => {
100
+ if (str.length > TAGS.PACKED_MAX) {
101
+ throw new Error('Too many bytes to pack');
102
+ }
103
+ pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
104
+ let roundedLength = Math.ceil(str.length / 2.0);
105
+ if (str.length % 2 !== 0) {
106
+ roundedLength |= 128;
107
+ }
108
+ pushByte(roundedLength);
109
+ const packFunction = type === 'nibble' ? packNibble : packHex;
110
+ const packBytePair = (v1, v2) => {
111
+ const result = (packFunction(v1) << 4) | packFunction(v2);
112
+ return result;
113
+ };
114
+ const strLengthHalf = Math.floor(str.length / 2);
115
+ for (let i = 0; i < strLengthHalf; i++) {
116
+ pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
117
+ }
118
+ if (str.length % 2 !== 0) {
119
+ pushByte(packBytePair(str[str.length - 1], '\x00'));
120
+ }
121
+ };
122
+ const isNibble = (str) => {
123
+ if (!str || str.length > TAGS.PACKED_MAX) {
124
+ return false;
125
+ }
126
+ for (const char of str) {
127
+ const isInNibbleRange = char >= '0' && char <= '9';
128
+ if (!isInNibbleRange && char !== '-' && char !== '.') {
129
+ return false;
130
+ }
131
+ }
132
+ return true;
133
+ };
134
+ const isHex = (str) => {
135
+ if (!str || str.length > TAGS.PACKED_MAX) {
136
+ return false;
137
+ }
138
+ for (const char of str) {
139
+ const isInNibbleRange = char >= '0' && char <= '9';
140
+ if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
141
+ return false;
142
+ }
143
+ }
144
+ return true;
145
+ };
146
+ const writeString = (str) => {
147
+ if (str === undefined || str === null) {
148
+ pushByte(TAGS.LIST_EMPTY);
149
+ return;
150
+ }
151
+ if (str === '') {
152
+ writeStringRaw(str);
153
+ return;
154
+ }
155
+ const tokenIndex = TOKEN_MAP[str];
156
+ if (tokenIndex) {
157
+ if (typeof tokenIndex.dict === 'number') {
158
+ pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
159
+ }
160
+ pushByte(tokenIndex.index);
161
+ }
162
+ else if (isNibble(str)) {
163
+ writePackedBytes(str, 'nibble');
164
+ }
165
+ else if (isHex(str)) {
166
+ writePackedBytes(str, 'hex');
167
+ }
168
+ else {
169
+ const decodedJid = jidDecode(str);
170
+ if (decodedJid) {
171
+ writeJid(decodedJid);
172
+ }
173
+ else {
174
+ writeStringRaw(str);
175
+ }
176
+ }
177
+ };
178
+ const writeListStart = (listSize) => {
179
+ if (listSize === 0) {
180
+ pushByte(TAGS.LIST_EMPTY);
181
+ }
182
+ else if (listSize < 256) {
183
+ pushBytes([TAGS.LIST_8, listSize]);
184
+ }
185
+ else {
186
+ pushByte(TAGS.LIST_16);
187
+ pushInt16(listSize);
188
+ }
189
+ };
190
+ if (!tag) {
191
+ throw new Error('Invalid node: tag cannot be undefined');
192
+ }
193
+ const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
194
+ writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
195
+ writeString(tag);
196
+ for (const key of validAttributes) {
197
+ if (typeof attrs[key] === 'string') {
198
+ writeString(key);
199
+ writeString(attrs[key]);
200
+ }
201
+ }
202
+ if (typeof content === 'string') {
203
+ writeString(content);
204
+ }
205
+ else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
206
+ writeByteLength(content.length);
207
+ pushBytes(content);
208
+ }
209
+ else if (Array.isArray(content)) {
210
+ const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
211
+ writeListStart(validContent.length);
212
+ for (const item of validContent) {
213
+ encodeBinaryNodeInner(item, opts, buffer);
214
+ }
215
+ }
216
+ else if (typeof content === 'undefined') {
217
+ // do nothing
218
+ }
219
+ else {
220
+ throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
221
+ }
222
+ return buffer;
223
+ };
224
+
225
+ const encodeBinaryNode = (node, opts, buffer) => {
226
+ return encodeBinaryNodeJS(node, opts || constants, buffer || [0])
227
+ }
228
+ exports.encodeBinaryNode = encodeBinaryNode
@@ -53,7 +53,7 @@ exports.getBinaryNodeChildBuffer = getBinaryNodeChildBuffer
53
53
  const getBinaryNodeChildString = (node, childTag) => {
54
54
  const child = (0, exports.getBinaryNodeChild)(node, childTag)?.content
55
55
  if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
56
- return Buffer.from(child).toString('utf8')
56
+ return Buffer.from(child).toString('utf-8')
57
57
  } else if (typeof child === 'string') {
58
58
  return child
59
59
  }
@@ -117,6 +117,98 @@ const getBinaryFilteredBizBot = nodeContent => {
117
117
  }
118
118
  exports.getBinaryFilteredBizBot = getBinaryFilteredBizBot
119
119
 
120
+ const getAdditionalNode = name => {
121
+ if (name) name = name.toLowerCase()
122
+ const ts = Math.floor(Date.now() / 1000) - 77980457
123
+ const order_response_name = {
124
+ review_and_pay: 'order_details',
125
+ review_order: 'order_status',
126
+ order_status: 'order_status',
127
+ payment_info: 'payment_info',
128
+ payment_status: 'payment_status',
129
+ payment_method: 'payment_method',
130
+ catalog_message: 'catalog_message'
131
+ }
132
+ const flow_name = {
133
+ cta_catalog: 'cta_catalog',
134
+ mpm: 'mpm',
135
+ call_request: 'call_permission_request',
136
+ view_catalog: 'automated_greeting_message_view_catalog',
137
+ wa_pay_detail: 'wa_payment_transaction_details',
138
+ send_location: 'send_location',
139
+ payment_key_info: 'payment_key_info'
140
+ }
141
+ if (order_response_name[name]) {
142
+ return [
143
+ {
144
+ tag: 'biz',
145
+ attrs: {
146
+ native_flow_name: order_response_name[name]
147
+ },
148
+ content: []
149
+ }
150
+ ]
151
+ } else if (flow_name[name] || name === 'interactive' || name === 'buttons') {
152
+ return [
153
+ {
154
+ tag: 'biz',
155
+ attrs: {
156
+ actual_actors: '2',
157
+ host_storage: '2',
158
+ privacy_mode_ts: `${ts}`
159
+ },
160
+ content: [
161
+ {
162
+ tag: 'engagement',
163
+ attrs: {
164
+ customer_service_state: 'open',
165
+ conversation_state: 'open'
166
+ }
167
+ },
168
+ {
169
+ tag: 'interactive',
170
+ attrs: {
171
+ type: 'native_flow',
172
+ v: '1'
173
+ },
174
+ content: [
175
+ {
176
+ tag: 'native_flow',
177
+ attrs: {
178
+ v: '9',
179
+ name: flow_name[name] ?? 'mixed'
180
+ },
181
+ content: []
182
+ }
183
+ ]
184
+ }
185
+ ]
186
+ }
187
+ ]
188
+ } else {
189
+ return [
190
+ {
191
+ tag: 'biz',
192
+ attrs: {
193
+ actual_actors: '2',
194
+ host_storage: '2',
195
+ privacy_mode_ts: `${ts}`
196
+ },
197
+ content: [
198
+ {
199
+ tag: 'engagement',
200
+ attrs: {
201
+ customer_service_state: 'open',
202
+ conversation_state: 'open'
203
+ }
204
+ }
205
+ ]
206
+ }
207
+ ]
208
+ }
209
+ }
210
+ exports.getAdditionalNode = getAdditionalNode
211
+
120
212
  function bufferToUInt(e, t) {
121
213
  let a = 0
122
214
  for (let i = 0; i < t; i++) {
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, '__esModule', { value: true })
3
3
  exports.transferDevice =
4
4
  exports.jidNormalizedUser =
5
- exports.isJidLid =
6
5
  exports.isJidBot =
7
6
  exports.isHostedLidUser =
8
7
  exports.isHostedPnUser =
@@ -24,13 +23,9 @@ exports.transferDevice =
24
23
  exports.PSA_WID =
25
24
  exports.SERVER_JID =
26
25
  exports.OFFICIAL_BIZ_JID =
27
- exports.BOT_WHATSAPP_NET =
28
- exports.BOT_SERVER =
29
26
  exports.S_WHATSAPP_NET =
30
27
  void 0
31
28
  exports.S_WHATSAPP_NET = '@s.whatsapp.net'
32
- exports.BOT_WHATSAPP_NET = '@bot.whatsapp.net' // kept for compat; wire domain is '@bot'
33
- exports.BOT_SERVER = '@bot'
34
29
  exports.OFFICIAL_BIZ_JID = '16505361212@c.us'
35
30
  exports.SERVER_JID = 'server@c.us'
36
31
  exports.PSA_WID = '0@c.us'
@@ -40,7 +35,6 @@ var WAJIDDomains
40
35
  ;(function (WAJIDDomains) {
41
36
  WAJIDDomains[(WAJIDDomains['WHATSAPP'] = 0)] = 'WHATSAPP'
42
37
  WAJIDDomains[(WAJIDDomains['LID'] = 1)] = 'LID'
43
- WAJIDDomains[(WAJIDDomains['BOT'] = 2)] = 'BOT'
44
38
  WAJIDDomains[(WAJIDDomains['HOSTED'] = 128)] = 'HOSTED'
45
39
  WAJIDDomains[(WAJIDDomains['HOSTED_LID'] = 129)] = 'HOSTED_LID'
46
40
  })(WAJIDDomains || (exports.WAJIDDomains = WAJIDDomains = {}))
@@ -48,8 +42,6 @@ const getServerFromDomainType = (initialServer, domainType) => {
48
42
  switch (domainType) {
49
43
  case WAJIDDomains.LID:
50
44
  return 'lid'
51
- case WAJIDDomains.BOT:
52
- return 'bot'
53
45
  case WAJIDDomains.HOSTED:
54
46
  return 'hosted'
55
47
  case WAJIDDomains.HOSTED_LID:
@@ -288,6 +280,7 @@ const jidEncode = (user, server, device, agent) => {
288
280
  }
289
281
  exports.jidEncode = jidEncode
290
282
  const jidDecode = jid => {
283
+ // todo: investigate how to implement hosted ids in this case
291
284
  const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1
292
285
  if (sepIdx < 0) {
293
286
  return undefined
@@ -299,14 +292,12 @@ const jidDecode = jid => {
299
292
  let domainType = WAJIDDomains.WHATSAPP
300
293
  if (server === 'lid') {
301
294
  domainType = WAJIDDomains.LID
302
- } else if (server === 'bot') {
303
- domainType = WAJIDDomains.BOT
304
295
  } else if (server === 'hosted') {
305
296
  domainType = WAJIDDomains.HOSTED
306
297
  } else if (server === 'hosted.lid') {
307
298
  domainType = WAJIDDomains.HOSTED_LID
308
299
  } else if (agent) {
309
- domainType = parseInt(agent, 10)
300
+ domainType = parseInt(agent)
310
301
  }
311
302
  return {
312
303
  server: server,
@@ -331,9 +322,6 @@ exports.isInteropUser = isInteropUser
331
322
  /** is the jid a LID */
332
323
  const isLidUser = jid => jid?.endsWith('@lid')
333
324
  exports.isLidUser = isLidUser
334
- /** is the jid a LID (isJidLid is an alias for isLidUser) */
335
- const isJidLid = jid => jid?.endsWith('@lid')
336
- exports.isJidLid = isJidLid
337
325
  /** is the jid a broadcast */
338
326
  const isJidBroadcast = jid => jid?.endsWith('@broadcast')
339
327
  exports.isJidBroadcast = isJidBroadcast
@@ -353,8 +341,7 @@ exports.isHostedPnUser = isHostedPnUser
353
341
  const isHostedLidUser = jid => jid?.endsWith('@hosted.lid')
354
342
  exports.isHostedLidUser = isHostedLidUser
355
343
  const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/
356
- /** is the jid a bot — covers @bot wire domain and @c.us number patterns for WA-native bots */
357
- const isJidBot = jid => jid && ((botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us')) || jid.endsWith('@bot'))
344
+ const isJidBot = jid => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us')
358
345
  exports.isJidBot = isJidBot
359
346
  const jidNormalizedUser = jid => {
360
347
  const result = (0, exports.jidDecode)(jid)
@@ -124,7 +124,7 @@ function serializeData(key, value, flag) {
124
124
  buffer.write(value, offset, 'utf8')
125
125
  return buffer
126
126
  }
127
- throw new Error(`WAM serializeData: unsupported value type ${typeof value} for key ${key}`)
127
+ throw 'missing'
128
128
  }
129
129
  function serializeHeader(buffer, offset, key, flag) {
130
130
  if (key < 256) {
@@ -0,0 +1,43 @@
1
+ 'use strict'
2
+ Object.defineProperty(exports, '__esModule', { value: true })
3
+ exports.USyncBusinessProtocol = void 0
4
+ const WABinary_1 = require('../../WABinary')
5
+ class USyncBusinessProtocol {
6
+ constructor(profileVersion = '2') {
7
+ this.name = 'business'
8
+ this.profileVersion = profileVersion
9
+ }
10
+ getQueryElement() {
11
+ return {
12
+ tag: 'business',
13
+ attrs: {},
14
+ content: [
15
+ { tag: 'verified_name', attrs: {} },
16
+ { tag: 'profile', attrs: { v: this.profileVersion } }
17
+ ]
18
+ }
19
+ }
20
+ getUserElement(user) {
21
+ const children = []
22
+ if (user.verifiedNameSerial) {
23
+ children.push({ tag: 'verified_name', attrs: { serial: user.verifiedNameSerial } })
24
+ }
25
+ if (user.businessProfileTag) {
26
+ children.push({ tag: 'profile', attrs: { tag: user.businessProfileTag } })
27
+ }
28
+ return children.length > 0 ? { tag: 'business', attrs: {}, content: children } : null
29
+ }
30
+ parser(node) {
31
+ if (node.tag !== 'business') return null
32
+ ;(0, WABinary_1.assertNodeErrorFree)(node)
33
+ const verifiedNameNode = (0, WABinary_1.getBinaryNodeChild)(node, 'verified_name')
34
+ const profileNode = (0, WABinary_1.getBinaryNodeChild)(node, 'profile')
35
+ return {
36
+ verifiedName: verifiedNameNode?.content ?? null,
37
+ verifiedLevel: verifiedNameNode?.attrs?.verified_level ?? null,
38
+ profileTag: profileNode?.attrs?.tag ?? null,
39
+ pnJid: node.attrs?.pn_jid ?? null
40
+ }
41
+ }
42
+ }
43
+ exports.USyncBusinessProtocol = USyncBusinessProtocol
@@ -46,13 +46,7 @@ class USyncContactProtocol {
46
46
  parser(node) {
47
47
  if (node.tag === 'contact') {
48
48
  ;(0, WABinary_1.assertNodeErrorFree)(node)
49
- const inWA = node?.attrs?.type === 'in'
50
- const restrictionType = node?.attrs?.stella_addressbook_restriction_type
51
- if (restrictionType !== undefined) {
52
- // Return object with extra metadata when restriction type is present
53
- return { inWA, stellaAddressbookRestrictionType: restrictionType }
54
- }
55
- return inWA
49
+ return node?.attrs?.type === 'in'
56
50
  }
57
51
  return false
58
52
  }
@@ -14,19 +14,11 @@ class USyncDeviceProtocol {
14
14
  }
15
15
  }
16
16
  }
17
- getUserElement(user) {
18
- const { deviceHash, ts, expectedTs } = user
19
- if (deviceHash == null && ts == null && expectedTs == null) {
20
- return null
21
- }
22
- const attrs = {}
23
- if (deviceHash != null) attrs.device_hash = deviceHash
24
- if (ts != null) attrs.ts = String(ts)
25
- if (expectedTs != null) attrs.expected_ts = String(expectedTs)
26
- return {
27
- tag: 'devices',
28
- attrs
29
- }
17
+ getUserElement(/* user: USyncUser */) {
18
+ //TODO: Implement device phashing, ts and expectedTs
19
+ //TODO: if all are not present, return null <- current behavior
20
+ //TODO: otherwise return a node w tag 'devices' w those as attrs
21
+ return null
30
22
  }
31
23
  parser(node) {
32
24
  const deviceList = []
@@ -20,7 +20,10 @@ class USyncDisappearingModeProtocol {
20
20
  ;(0, WABinary_1.assertNodeErrorFree)(node)
21
21
  const duration = +node?.attrs.duration
22
22
  const setAt = new Date(+(node?.attrs.t || 0) * 1000)
23
- return { duration, setAt }
23
+ return {
24
+ duration,
25
+ setAt
26
+ }
24
27
  }
25
28
  }
26
29
  }
@@ -15,9 +15,7 @@ exports.USYNC_FEATURES = [
15
15
  'encrypt_url',
16
16
  'encrypt_v2',
17
17
  'voip',
18
- 'voip_legacy',
19
- 'multi_agent',
20
- 'bot_eligible'
18
+ 'multi_agent'
21
19
  ]
22
20
  class USyncFeatureProtocol {
23
21
  /**
@@ -48,24 +46,11 @@ class USyncFeatureProtocol {
48
46
  errorText: errorNode.attrs?.text
49
47
  }
50
48
  }
51
- const CAMEL_MAP = {
52
- encrypt_v2: 'encryptV2',
53
- voip_legacy: 'voipLegacy',
54
- multi_agent: 'multiAgent',
55
- bot_eligible: 'botEligible',
56
- encrypt_blist: 'encryptBlist',
57
- encrypt_contact: 'encryptContact',
58
- encrypt_group_gen2: 'encryptGroupGen2',
59
- encrypt_image: 'encryptImage',
60
- encrypt_location: 'encryptLocation',
61
- encrypt_url: 'encryptUrl'
62
- }
63
49
  const features = {}
64
50
  const children = Array.isArray(node.content) ? node.content : []
65
51
  for (const child of children) {
66
52
  if (child?.attrs && child.attrs.value !== undefined) {
67
- const key = CAMEL_MAP[child.tag] || child.tag
68
- features[key] = child.attrs.value
53
+ features[child.tag] = child.attrs.value
69
54
  }
70
55
  }
71
56
  return features
@@ -12,13 +12,8 @@ class USyncStatusProtocol {
12
12
  attrs: {}
13
13
  }
14
14
  }
15
- getUserElement(user) {
16
- if (!user?.tcToken) return null
17
- return {
18
- tag: 'tctoken',
19
- attrs: {},
20
- content: user.tcToken
21
- }
15
+ getUserElement() {
16
+ return null
22
17
  }
23
18
  parser(node) {
24
19
  if (node.tag === 'status') {
@@ -19,8 +19,7 @@ class USyncUsernameProtocol {
19
19
  parser(node) {
20
20
  if (node.tag === 'username') {
21
21
  ;(0, WABinary_1.assertNodeErrorFree)(node)
22
- const username = node.content != null ? node.content.toString() : null
23
- return username && username.length > 0 ? username : null
22
+ return typeof node.content === 'string' ? node.content : null
24
23
  }
25
24
  return null
26
25
  }
@@ -35,6 +35,5 @@ __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)
39
38
  __exportStar(require('./USyncSidelistProtocol'), exports)
40
39
  __exportStar(require('./USyncFeatureProtocol'), exports)