@badzz88/baileys 8.5.4 → 8.5.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 (269) hide show
  1. package/README.md +2 -2
  2. package/WAProto/fix-imports.js +69 -79
  3. package/WAProto/index.d.ts +15305 -87935
  4. package/WAProto/index.js +41109 -194076
  5. package/engine-requirements.js +15 -8
  6. package/package.json +23 -19
  7. package/src/Defaults/index.js +186 -0
  8. package/src/Signal/Group/ciphertext-message.js +15 -0
  9. package/src/Signal/Group/group-session-builder.js +86 -0
  10. package/src/Signal/Group/group_cipher.js +82 -0
  11. package/src/Signal/Group/index.js +140 -0
  12. package/src/Signal/Group/keyhelper.js +77 -0
  13. package/src/Signal/Group/sender-chain-key.js +29 -0
  14. package/src/Signal/Group/sender-key-distribution-message.js +66 -0
  15. package/src/Signal/Group/sender-key-message.js +69 -0
  16. package/src/Signal/Group/sender-key-name.js +51 -0
  17. package/src/Signal/Group/sender-key-record.js +44 -0
  18. package/src/Signal/Group/sender-key-state.js +87 -0
  19. package/src/Signal/Group/sender-message-key.js +29 -0
  20. package/src/Signal/libsignal.js +455 -0
  21. package/src/Signal/lid-mapping.js +273 -0
  22. package/src/Socket/Client/index.js +31 -0
  23. package/src/Socket/Client/types.js +13 -0
  24. package/src/Socket/Client/websocket.js +61 -0
  25. package/src/Socket/aigroups.js +221 -0
  26. package/src/Socket/business.js +411 -0
  27. package/src/Socket/chats.js +1449 -0
  28. package/src/Socket/communities.js +463 -0
  29. package/src/Socket/graphql.js +523 -0
  30. package/src/Socket/groups.js +516 -0
  31. package/src/Socket/index.js +31 -0
  32. package/src/Socket/interactive-handler.js +527 -0
  33. package/src/Socket/interop.js +339 -0
  34. package/src/Socket/luxu.js +349 -0
  35. package/src/Socket/managed-account.js +98 -0
  36. package/src/Socket/messages-recv.js +2685 -0
  37. package/src/Socket/messages-send.js +2047 -0
  38. package/src/Socket/mex.js +57 -0
  39. package/src/Socket/newsletter.js +455 -0
  40. package/src/Socket/privacy.js +125 -0
  41. package/src/Socket/registration.js +236 -0
  42. package/src/Socket/socket.js +983 -0
  43. package/src/Socket/text-router.js +65 -0
  44. package/src/Socket/username.js +130 -0
  45. package/src/Store/index.js +33 -0
  46. package/src/Store/keyed-db.js +118 -0
  47. package/src/Store/make-cache-manager-store.js +84 -0
  48. package/src/Store/make-in-memory-store.js +551 -0
  49. package/src/Store/make-ordered-dictionary.js +81 -0
  50. package/src/Store/object-repository.js +26 -0
  51. package/src/Types/Auth.js +31 -0
  52. package/src/Types/Bussines.js +2 -0
  53. package/src/Types/Call.js +2 -0
  54. package/src/Types/Chat.js +4 -0
  55. package/src/Types/Contact.js +2 -0
  56. package/src/Types/Events.js +2 -0
  57. package/src/Types/GroupMetadata.js +2 -0
  58. package/src/Types/Label.js +26 -0
  59. package/src/Types/LabelAssociation.js +8 -0
  60. package/src/Types/Message.js +93 -0
  61. package/src/Types/Mex.js +112 -0
  62. package/src/Types/Newsletter.js +109 -0
  63. package/src/Types/Product.js +2 -0
  64. package/src/Types/Signal.js +2 -0
  65. package/src/Types/Socket.js +2 -0
  66. package/src/Types/State.js +62 -0
  67. package/src/Types/USync.js +2 -0
  68. package/src/Types/index.js +56 -0
  69. package/src/Utils/auth-utils.js +254 -0
  70. package/src/Utils/browser-utils.js +112 -0
  71. package/src/Utils/business.js +240 -0
  72. package/src/Utils/chat-utils.js +1230 -0
  73. package/src/Utils/command-loader.d.ts +27 -0
  74. package/src/Utils/command-loader.js +89 -0
  75. package/src/Utils/companion-reg-client-utils.js +40 -0
  76. package/src/Utils/consumer-application.js +105 -0
  77. package/src/Utils/crypto.js +118 -0
  78. package/src/Utils/curve25519-js.js +242 -0
  79. package/src/Utils/decode-wa-message.js +529 -0
  80. package/src/Utils/event-buffer.js +580 -0
  81. package/src/Utils/generics.js +483 -0
  82. package/src/Utils/group-history.js +44 -0
  83. package/src/Utils/history.js +232 -0
  84. package/src/Utils/identity-change-handler.js +52 -0
  85. package/src/Utils/index.js +58 -0
  86. package/src/Utils/jid-display-normalization.js +195 -0
  87. package/src/Utils/link-preview.js +135 -0
  88. package/src/Utils/logger.js +8 -0
  89. package/src/Utils/lt-hash.js +25 -0
  90. package/src/Utils/make-mutex.js +36 -0
  91. package/src/Utils/message-composer.js +471 -0
  92. package/src/Utils/message-retry-manager.js +217 -0
  93. package/src/Utils/messages-media.js +843 -0
  94. package/src/Utils/messages.js +2817 -0
  95. package/src/Utils/meta-ai-msmsg.js +222 -0
  96. package/src/Utils/native-bridge.js +68 -0
  97. package/src/Utils/noise-handler.js +169 -0
  98. package/src/Utils/offline-node-processor.js +34 -0
  99. package/src/Utils/pre-key-manager.js +90 -0
  100. package/src/Utils/process-message.js +950 -0
  101. package/src/Utils/reporting-utils.js +261 -0
  102. package/src/Utils/session-pool.d.ts +14 -0
  103. package/src/Utils/session-pool.js +70 -0
  104. package/src/Utils/signal.js +217 -0
  105. package/src/Utils/stanza-ack.js +30 -0
  106. package/src/Utils/sticker.d.ts +13 -0
  107. package/src/Utils/sticker.js +123 -0
  108. package/src/Utils/sync-action-utils.js +45 -0
  109. package/src/Utils/tc-token-utils.js +158 -0
  110. package/src/Utils/use-multi-file-auth-state.js +111 -0
  111. package/src/Utils/validate-connection.js +209 -0
  112. package/src/Utils/view-once-cache.d.ts +12 -0
  113. package/src/Utils/view-once-cache.js +63 -0
  114. package/src/Utils/voip-rekey.js +22 -0
  115. package/src/WABinary/constants.js +1304 -0
  116. package/src/WABinary/decode.js +342 -0
  117. package/src/WABinary/encode.js +225 -0
  118. package/src/WABinary/generic-utils.js +238 -0
  119. package/src/WABinary/index.js +34 -0
  120. package/src/WABinary/jid-utils.js +351 -0
  121. package/src/WABinary/types.js +2 -0
  122. package/src/WAM/BinaryInfo.js +13 -0
  123. package/src/WAM/constants.js +39484 -0
  124. package/src/WAM/encode.js +149 -0
  125. package/src/WAM/index.js +32 -0
  126. package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
  127. package/src/WAUSync/Protocols/USyncBusinessProtocol.js +44 -0
  128. package/src/WAUSync/Protocols/USyncContactProtocol.js +55 -0
  129. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +55 -0
  130. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  131. package/src/WAUSync/Protocols/USyncFeatureProtocol.js +54 -0
  132. package/src/WAUSync/Protocols/USyncLIDProtocol.js +32 -0
  133. package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +473 -0
  134. package/src/WAUSync/Protocols/USyncPictureProtocol.js +34 -0
  135. package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  136. package/src/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  137. package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  138. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
  139. package/src/WAUSync/Protocols/index.js +40 -0
  140. package/src/WAUSync/USyncQuery.js +126 -0
  141. package/src/WAUSync/USyncUser.js +50 -0
  142. package/src/WAUSync/index.js +32 -0
  143. package/src/antiban.js +4152 -0
  144. package/{lib → src}/index.js +51 -49
  145. package/lib/Defaults/index.js +0 -195
  146. package/lib/Signal/Group/ciphertext-message.js +0 -15
  147. package/lib/Signal/Group/group-session-builder.js +0 -92
  148. package/lib/Signal/Group/group_cipher.js +0 -89
  149. package/lib/Signal/Group/index.js +0 -136
  150. package/lib/Signal/Group/keyhelper.js +0 -73
  151. package/lib/Signal/Group/sender-chain-key.js +0 -32
  152. package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
  153. package/lib/Signal/Group/sender-key-message.js +0 -69
  154. package/lib/Signal/Group/sender-key-name.js +0 -50
  155. package/lib/Signal/Group/sender-key-record.js +0 -44
  156. package/lib/Signal/Group/sender-key-state.js +0 -97
  157. package/lib/Signal/Group/sender-message-key.js +0 -30
  158. package/lib/Signal/libsignal.js +0 -470
  159. package/lib/Signal/lid-mapping.js +0 -280
  160. package/lib/Socket/Client/index.js +0 -30
  161. package/lib/Socket/Client/types.js +0 -13
  162. package/lib/Socket/Client/websocket.js +0 -62
  163. package/lib/Socket/aigroups.js +0 -240
  164. package/lib/Socket/business.js +0 -414
  165. package/lib/Socket/chats.js +0 -2165
  166. package/lib/Socket/communities.js +0 -545
  167. package/lib/Socket/graphql.js +0 -863
  168. package/lib/Socket/groups.js +0 -685
  169. package/lib/Socket/index.js +0 -41
  170. package/lib/Socket/interactive-handler.js +0 -579
  171. package/lib/Socket/interop.js +0 -430
  172. package/lib/Socket/managed-account.js +0 -214
  173. package/lib/Socket/messages-recv.js +0 -3000
  174. package/lib/Socket/messages-send.js +0 -2155
  175. package/lib/Socket/mex.js +0 -47
  176. package/lib/Socket/newsletter.js +0 -814
  177. package/lib/Socket/privacy.js +0 -261
  178. package/lib/Socket/registration.js +0 -434
  179. package/lib/Socket/socket.js +0 -1074
  180. package/lib/Socket/username.js +0 -160
  181. package/lib/Store/index.js +0 -36
  182. package/lib/Store/make-cache-manager-store.js +0 -90
  183. package/lib/Store/make-in-memory-store.js +0 -488
  184. package/lib/Store/make-ordered-dictionary.js +0 -81
  185. package/lib/Store/object-repository.js +0 -29
  186. package/lib/Types/Auth.js +0 -38
  187. package/lib/Types/Bussines.js +0 -2
  188. package/lib/Types/Call.js +0 -2
  189. package/lib/Types/Chat.js +0 -4
  190. package/lib/Types/Contact.js +0 -2
  191. package/lib/Types/Events.js +0 -2
  192. package/lib/Types/GroupMetadata.js +0 -2
  193. package/lib/Types/Label.js +0 -27
  194. package/lib/Types/LabelAssociation.js +0 -9
  195. package/lib/Types/Message.js +0 -95
  196. package/lib/Types/Newsletter.js +0 -152
  197. package/lib/Types/Product.js +0 -2
  198. package/lib/Types/Signal.js +0 -2
  199. package/lib/Types/Socket.js +0 -2
  200. package/lib/Types/State.js +0 -70
  201. package/lib/Types/USync.js +0 -2
  202. package/lib/Types/index.js +0 -55
  203. package/lib/Utils/auth-utils.js +0 -301
  204. package/lib/Utils/browser-utils.js +0 -114
  205. package/lib/Utils/business.js +0 -243
  206. package/lib/Utils/chat-utils.js +0 -1272
  207. package/lib/Utils/consumer-application.js +0 -107
  208. package/lib/Utils/crypto.js +0 -125
  209. package/lib/Utils/decode-wa-message.js +0 -793
  210. package/lib/Utils/event-buffer.js +0 -583
  211. package/lib/Utils/generics.js +0 -617
  212. package/lib/Utils/group-history.js +0 -51
  213. package/lib/Utils/history.js +0 -244
  214. package/lib/Utils/identity-change-handler.js +0 -52
  215. package/lib/Utils/index.js +0 -53
  216. package/lib/Utils/jid-display-normalization.js +0 -218
  217. package/lib/Utils/link-preview.js +0 -138
  218. package/lib/Utils/logger.js +0 -9
  219. package/lib/Utils/lt-hash.js +0 -6
  220. package/lib/Utils/make-mutex.js +0 -36
  221. package/lib/Utils/message-composer.js +0 -479
  222. package/lib/Utils/message-inspect.js +0 -393
  223. package/lib/Utils/message-retry-manager.js +0 -205
  224. package/lib/Utils/messages-media.js +0 -925
  225. package/lib/Utils/messages.js +0 -2482
  226. package/lib/Utils/meta-ai-msmsg.js +0 -122
  227. package/lib/Utils/noise-handler.js +0 -194
  228. package/lib/Utils/offline-node-processor.js +0 -37
  229. package/lib/Utils/pre-key-manager.js +0 -97
  230. package/lib/Utils/process-message.js +0 -1139
  231. package/lib/Utils/reporting-utils.js +0 -262
  232. package/lib/Utils/signal.js +0 -189
  233. package/lib/Utils/stanza-ack.js +0 -67
  234. package/lib/Utils/sync-action-utils.js +0 -51
  235. package/lib/Utils/tc-token-utils.js +0 -156
  236. package/lib/Utils/use-multi-file-auth-state.js +0 -137
  237. package/lib/Utils/validate-connection.js +0 -259
  238. package/lib/Utils/voip-rekey.js +0 -22
  239. package/lib/WABinary/constants.js +0 -1304
  240. package/lib/WABinary/decode.js +0 -377
  241. package/lib/WABinary/encode.js +0 -58
  242. package/lib/WABinary/generic-utils.js +0 -150
  243. package/lib/WABinary/index.js +0 -33
  244. package/lib/WABinary/jid-utils.js +0 -374
  245. package/lib/WABinary/types.js +0 -2
  246. package/lib/WAM/BinaryInfo.js +0 -13
  247. package/lib/WAM/constants.js +0 -39486
  248. package/lib/WAM/encode.js +0 -142
  249. package/lib/WAM/index.js +0 -31
  250. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -55
  251. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -100
  252. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -60
  253. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -65
  254. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
  255. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -72
  256. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -31
  257. package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -865
  258. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
  259. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
  260. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -44
  261. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
  262. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
  263. package/lib/WAUSync/Protocols/index.js +0 -40
  264. package/lib/WAUSync/USyncBackoff.js +0 -26
  265. package/lib/WAUSync/USyncQuery.js +0 -204
  266. package/lib/WAUSync/USyncUser.js +0 -58
  267. package/lib/WAUSync/index.js +0 -32
  268. package/lib/antiban.js +0 -4391
  269. /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
@@ -0,0 +1,238 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.getBinaryNodeMessages =
4
+ exports.reduceBinaryNodeToDictionary =
5
+ exports.assertNodeErrorFree =
6
+ exports.getBinaryNodeChildUInt =
7
+ exports.getBinaryNodeChildString =
8
+ exports.getBinaryNodeChildBuffer =
9
+ exports.getAllBinaryNodeChildren =
10
+ exports.getBinaryNodeChild =
11
+ exports.getBinaryNodeChildren =
12
+ void 0;
13
+ exports.binaryNodeToString = binaryNodeToString;
14
+ const boom_1 = require('@hapi/boom');
15
+ const index_js_1 = require('../../WAProto/index.js');
16
+ const indexCache = new WeakMap();
17
+ const getBinaryNodeChildren = (node, childTag) => {
18
+ if (!node || !Array.isArray(node.content))
19
+ return [];
20
+ let index = indexCache.get(node);
21
+ if (!index) {
22
+ index = new Map();
23
+ for (const child of node.content) {
24
+ let arr = index.get(child.tag);
25
+ if (!arr)
26
+ index.set(child.tag, (arr = []));
27
+ arr.push(child);
28
+ }
29
+ indexCache.set(node, index);
30
+ }
31
+ return index.get(childTag) || [];
32
+ };
33
+ exports.getBinaryNodeChildren = getBinaryNodeChildren;
34
+ const getBinaryNodeChild = (node, childTag) => {
35
+ return (0, exports.getBinaryNodeChildren)(node, childTag)[0];
36
+ };
37
+ exports.getBinaryNodeChild = getBinaryNodeChild;
38
+ const getAllBinaryNodeChildren = ({ content }) => {
39
+ if (Array.isArray(content)) {
40
+ return content;
41
+ }
42
+ return [];
43
+ };
44
+ exports.getAllBinaryNodeChildren = getAllBinaryNodeChildren;
45
+ const getBinaryNodeChildBuffer = (node, childTag) => {
46
+ const child = (0, exports.getBinaryNodeChild)(node, childTag)?.content;
47
+ if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
48
+ return child;
49
+ }
50
+ };
51
+ exports.getBinaryNodeChildBuffer = getBinaryNodeChildBuffer;
52
+ const getBinaryNodeChildString = (node, childTag) => {
53
+ const child = (0, exports.getBinaryNodeChild)(node, childTag)?.content;
54
+ if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
55
+ return Buffer.from(child).toString('utf-8');
56
+ }
57
+ else if (typeof child === 'string') {
58
+ return child;
59
+ }
60
+ };
61
+ exports.getBinaryNodeChildString = getBinaryNodeChildString;
62
+ const getBinaryNodeChildUInt = (node, childTag, length) => {
63
+ const buff = (0, exports.getBinaryNodeChildBuffer)(node, childTag);
64
+ if (buff) {
65
+ return bufferToUInt(buff, length);
66
+ }
67
+ };
68
+ exports.getBinaryNodeChildUInt = getBinaryNodeChildUInt;
69
+ const assertNodeErrorFree = node => {
70
+ const errNode = (0, exports.getBinaryNodeChild)(node, 'error');
71
+ if (errNode) {
72
+ throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
73
+ }
74
+ };
75
+ exports.assertNodeErrorFree = assertNodeErrorFree;
76
+ const reduceBinaryNodeToDictionary = (node, tag) => {
77
+ const nodes = (0, exports.getBinaryNodeChildren)(node, tag);
78
+ const dict = nodes.reduce((dict, { attrs }) => {
79
+ if (typeof attrs.name === 'string') {
80
+ dict[attrs.name] = attrs.value || attrs.config_value;
81
+ }
82
+ else {
83
+ dict[attrs.config_code] = attrs.value || attrs.config_value;
84
+ }
85
+ return dict;
86
+ }, {});
87
+ return dict;
88
+ };
89
+ exports.reduceBinaryNodeToDictionary = reduceBinaryNodeToDictionary;
90
+ const getBinaryNodeMessages = ({ content }) => {
91
+ const msgs = [];
92
+ if (Array.isArray(content)) {
93
+ for (const item of content) {
94
+ if (item.tag === 'message') {
95
+ msgs.push(index_js_1.proto.WebMessageInfo.decode(item.content).toJSON());
96
+ }
97
+ }
98
+ }
99
+ return msgs;
100
+ };
101
+ exports.getBinaryNodeMessages = getBinaryNodeMessages;
102
+ const getBinaryFilteredButtons = nodeContent => {
103
+ if (!Array.isArray(nodeContent))
104
+ return false;
105
+ return nodeContent.some(a => ['native_flow'].includes(a?.content?.[0]?.content?.[0]?.tag) ||
106
+ ['interactive', 'buttons', 'list'].includes(a?.content?.[0]?.tag) ||
107
+ ['hsm', 'biz'].includes(a?.tag));
108
+ };
109
+ exports.getBinaryFilteredButtons = getBinaryFilteredButtons;
110
+ const getBinaryFilteredBizBot = nodeContent => {
111
+ if (!Array.isArray(nodeContent))
112
+ return false;
113
+ return nodeContent.some(b => ['bot'].includes(b?.tag) && b?.attrs?.biz_bot === '1');
114
+ };
115
+ exports.getBinaryFilteredBizBot = getBinaryFilteredBizBot;
116
+ const getAdditionalNode = name => {
117
+ if (name)
118
+ name = name.toLowerCase();
119
+ const ts = Math.floor(Date.now() / 1000) - 77980457;
120
+ const order_response_name = {
121
+ review_and_pay: 'order_details',
122
+ review_order: 'order_status',
123
+ order_status: 'order_status',
124
+ payment_info: 'payment_info',
125
+ payment_status: 'payment_status',
126
+ payment_method: 'payment_method',
127
+ catalog_message: 'catalog_message'
128
+ };
129
+ const flow_name = {
130
+ cta_catalog: 'cta_catalog',
131
+ mpm: 'mpm',
132
+ call_request: 'call_permission_request',
133
+ view_catalog: 'automated_greeting_message_view_catalog',
134
+ wa_pay_detail: 'wa_payment_transaction_details',
135
+ send_location: 'send_location',
136
+ payment_key_info: 'payment_key_info'
137
+ };
138
+ if (order_response_name[name]) {
139
+ return [
140
+ {
141
+ tag: 'biz',
142
+ attrs: {
143
+ native_flow_name: order_response_name[name]
144
+ },
145
+ content: []
146
+ }
147
+ ];
148
+ }
149
+ else if (flow_name[name] || name === 'interactive' || name === 'buttons') {
150
+ return [
151
+ {
152
+ tag: 'biz',
153
+ attrs: {
154
+ actual_actors: '2',
155
+ host_storage: '2',
156
+ privacy_mode_ts: `${ts}`
157
+ },
158
+ content: [
159
+ {
160
+ tag: 'engagement',
161
+ attrs: {
162
+ customer_service_state: 'open',
163
+ conversation_state: 'open'
164
+ }
165
+ },
166
+ {
167
+ tag: 'interactive',
168
+ attrs: {
169
+ type: 'native_flow',
170
+ v: '1'
171
+ },
172
+ content: [
173
+ {
174
+ tag: 'native_flow',
175
+ attrs: {
176
+ v: '9',
177
+ name: flow_name[name] ?? 'mixed'
178
+ },
179
+ content: []
180
+ }
181
+ ]
182
+ }
183
+ ]
184
+ }
185
+ ];
186
+ }
187
+ else {
188
+ return [
189
+ {
190
+ tag: 'biz',
191
+ attrs: {
192
+ actual_actors: '2',
193
+ host_storage: '2',
194
+ privacy_mode_ts: `${ts}`
195
+ },
196
+ content: [
197
+ {
198
+ tag: 'engagement',
199
+ attrs: {
200
+ customer_service_state: 'open',
201
+ conversation_state: 'open'
202
+ }
203
+ }
204
+ ]
205
+ }
206
+ ];
207
+ }
208
+ };
209
+ exports.getAdditionalNode = getAdditionalNode;
210
+ function bufferToUInt(e, t) {
211
+ let a = 0;
212
+ for (let i = 0; i < t; i++) {
213
+ a = 256 * a + e[i];
214
+ }
215
+ return a;
216
+ }
217
+ const tabs = n => '\t'.repeat(n);
218
+ function binaryNodeToString(node, i = 0) {
219
+ if (!node) {
220
+ return node;
221
+ }
222
+ if (typeof node === 'string') {
223
+ return tabs(i) + node;
224
+ }
225
+ if (node instanceof Uint8Array) {
226
+ return tabs(i) + Buffer.from(node).toString('hex');
227
+ }
228
+ if (Array.isArray(node)) {
229
+ return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
230
+ }
231
+ const children = binaryNodeToString(node.content, i + 1);
232
+ const tag = `<${node.tag} ${Object.entries(node.attrs || {})
233
+ .filter(([, v]) => v !== undefined)
234
+ .map(([k, v]) => `${k}='${v}'`)
235
+ .join(' ')}`;
236
+ const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
237
+ return tag + content;
238
+ }
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+ var __createBinding = (this && this.__createBinding) ||
3
+ (Object.create
4
+ ? function (o, m, k, k2) {
5
+ if (k2 === undefined)
6
+ k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ }
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined)
20
+ k2 = k;
21
+ o[k2] = m[k];
22
+ });
23
+ var __exportStar = (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m)
26
+ if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
27
+ __createBinding(exports, m, p);
28
+ };
29
+ Object.defineProperty(exports, '__esModule', { value: true });
30
+ __exportStar(require('./encode'), exports);
31
+ __exportStar(require('./decode'), exports);
32
+ __exportStar(require('./generic-utils'), exports);
33
+ __exportStar(require('./jid-utils'), exports);
34
+ __exportStar(require('./types'), exports);
@@ -0,0 +1,351 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.transferDevice =
4
+ exports.jidNormalizedUser =
5
+ exports.isJidBot =
6
+ exports.isHostedLidUser =
7
+ exports.isHostedPnUser =
8
+ exports.isJidNewsletter =
9
+ exports.isJidStatusBroadcast =
10
+ exports.isJidGroup =
11
+ exports.isJidBroadcast =
12
+ exports.isLidUser =
13
+ exports.isPnUser =
14
+ exports.isInteropUser =
15
+ exports.isJidMetaAI =
16
+ exports.areJidsSameUser =
17
+ exports.jidDecode =
18
+ exports.jidEncode =
19
+ exports.getServerFromDomainType =
20
+ exports.WAJIDDomains =
21
+ exports.META_AI_JID =
22
+ exports.STORIES_JID =
23
+ exports.PSA_WID =
24
+ exports.SERVER_JID =
25
+ exports.OFFICIAL_BIZ_JID =
26
+ exports.S_WHATSAPP_NET =
27
+ void 0;
28
+ exports.S_WHATSAPP_NET = '@s.whatsapp.net';
29
+ exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
30
+ exports.SERVER_JID = 'server@c.us';
31
+ exports.PSA_WID = '0@c.us';
32
+ exports.STORIES_JID = 'status@broadcast';
33
+ exports.META_AI_JID = '13135550002@c.us';
34
+ var WAJIDDomains;
35
+ (function (WAJIDDomains) {
36
+ WAJIDDomains[(WAJIDDomains['WHATSAPP'] = 0)] = 'WHATSAPP';
37
+ WAJIDDomains[(WAJIDDomains['LID'] = 1)] = 'LID';
38
+ WAJIDDomains[(WAJIDDomains['HOSTED'] = 128)] = 'HOSTED';
39
+ WAJIDDomains[(WAJIDDomains['HOSTED_LID'] = 129)] = 'HOSTED_LID';
40
+ })(WAJIDDomains || (exports.WAJIDDomains = WAJIDDomains = {}));
41
+ const getServerFromDomainType = (initialServer, domainType) => {
42
+ switch (domainType) {
43
+ case WAJIDDomains.LID:
44
+ return 'lid';
45
+ case WAJIDDomains.HOSTED:
46
+ return 'hosted';
47
+ case WAJIDDomains.HOSTED_LID:
48
+ return 'hosted.lid';
49
+ case WAJIDDomains.WHATSAPP:
50
+ default:
51
+ return initialServer;
52
+ }
53
+ };
54
+ exports.getServerFromDomainType = getServerFromDomainType;
55
+ const getBotJid = jid => {
56
+ const BOT_MAP = new Map([
57
+ ['867051314767696', '13135550002'],
58
+ ['1061492271844689', '13135550005'],
59
+ ['245886058483988', '13135550009'],
60
+ ['3509905702656130', '13135550012'],
61
+ ['1059680132034576', '13135550013'],
62
+ ['715681030623646', '13135550014'],
63
+ ['1644971366323052', '13135550015'],
64
+ ['582497970646566', '13135550019'],
65
+ ['645459357769306', '13135550022'],
66
+ ['294997126699143', '13135550023'],
67
+ ['1522631578502677', '13135550027'],
68
+ ['719421926276396', '13135550030'],
69
+ ['1788488635002167', '13135550031'],
70
+ ['24232338603080193', '13135550033'],
71
+ ['689289903143209', '13135550035'],
72
+ ['871626054177096', '13135550039'],
73
+ ['362351902849370', '13135550042'],
74
+ ['1744617646041527', '13135550043'],
75
+ ['893887762270570', '13135550046'],
76
+ ['1155032702135830', '13135550047'],
77
+ ['333931965993883', '13135550048'],
78
+ ['853748013058752', '13135550049'],
79
+ ['1559068611564819', '13135550053'],
80
+ ['890487432705716', '13135550054'],
81
+ ['240254602395494', '13135550055'],
82
+ ['1578420349663261', '13135550062'],
83
+ ['322908887140421', '13135550065'],
84
+ ['3713961535514771', '13135550067'],
85
+ ['997884654811738', '13135550070'],
86
+ ['403157239387035', '13135550081'],
87
+ ['535242369074963', '13135550082'],
88
+ ['946293427247659', '13135550083'],
89
+ ['3664707673802291', '13135550084'],
90
+ ['1821827464894892', '13135550085'],
91
+ ['1760312477828757', '13135550086'],
92
+ ['439480398712216', '13135550087'],
93
+ ['1876735582800984', '13135550088'],
94
+ ['984025089825661', '13135550089'],
95
+ ['1001336351558186', '13135550090'],
96
+ ['3739346336347061', '13135550091'],
97
+ ['3632749426974980', '13135550092'],
98
+ ['427864203481615', '13135550093'],
99
+ ['1434734570493055', '13135550094'],
100
+ ['992873449225921', '13135550095'],
101
+ ['813087747426445', '13135550096'],
102
+ ['806369104931434', '13135550098'],
103
+ ['1220982902403148', '13135550099'],
104
+ ['1365893374104393', '13135550100'],
105
+ ['686482033622048', '13135550200'],
106
+ ['1454999838411253', '13135550201'],
107
+ ['718584497008509', '13135550202'],
108
+ ['743520384213443', '13135550301'],
109
+ ['1147715789823789', '13135550302'],
110
+ ['1173034540372201', '13135550303'],
111
+ ['974785541030953', '13135550304'],
112
+ ['1122200255531507', '13135550305'],
113
+ ['899669714813162', '13135550306'],
114
+ ['631880108970650', '13135550307'],
115
+ ['435816149330026', '13135550308'],
116
+ ['1368717161184556', '13135550309'],
117
+ ['7849963461784891', '13135550310'],
118
+ ['3609617065968984', '13135550312'],
119
+ ['356273980574602', '13135550313'],
120
+ ['1043447920539760', '13135550314'],
121
+ ['1052764336525346', '13135550315'],
122
+ ['2631118843732685', '13135550316'],
123
+ ['510505411332176', '13135550317'],
124
+ ['1945664239227513', '13135550318'],
125
+ ['1518594378764656', '13135550319'],
126
+ ['1378821579456138', '13135550320'],
127
+ ['490214716896013', '13135550321'],
128
+ ['1028577858870699', '13135550322'],
129
+ ['308915665545959', '13135550323'],
130
+ ['845884253678900', '13135550324'],
131
+ ['995031308616442', '13135550325'],
132
+ ['2787365464763437', '13135550326'],
133
+ ['1532790990671645', '13135550327'],
134
+ ['302617036180485', '13135550328'],
135
+ ['723376723197227', '13135550329'],
136
+ ['8393570407377966', '13135550330'],
137
+ ['1931159970680725', '13135550331'],
138
+ ['401073885688605', '13135550332'],
139
+ ['2234478453565422', '13135550334'],
140
+ ['814748673882312', '13135550335'],
141
+ ['26133635056281592', '13135550336'],
142
+ ['1439804456676119', '13135550337'],
143
+ ['889851503172161', '13135550338'],
144
+ ['1018283232836879', '13135550339'],
145
+ ['1012781386779537', '13135559000'],
146
+ ['823280953239532', '13135559001'],
147
+ ['1597090934573334', '13135559002'],
148
+ ['485965054020343', '13135559003'],
149
+ ['1033381648363446', '13135559004'],
150
+ ['491802010206446', '13135559005'],
151
+ ['1017139033184870', '13135559006'],
152
+ ['499638325922174', '13135559008'],
153
+ ['468946335863664', '13135559009'],
154
+ ['1570389776875816', '13135559010'],
155
+ ['1004342694328995', '13135559011'],
156
+ ['1012240323971229', '13135559012'],
157
+ ['392171787222419', '13135559013'],
158
+ ['952081212945019', '13135559016'],
159
+ ['444507875070178', '13135559017'],
160
+ ['1274819440594668', '13135559018'],
161
+ ['1397041101147050', '13135559019'],
162
+ ['425657699872640', '13135559020'],
163
+ ['532292852562549', '13135559021'],
164
+ ['705863241720292', '13135559022'],
165
+ ['476449815183959', '13135559023'],
166
+ ['488071553854222', '13135559024'],
167
+ ['468693832665397', '13135559025'],
168
+ ['517422564037340', '13135559026'],
169
+ ['819805466613825', '13135559027'],
170
+ ['1847708235641382', '13135559028'],
171
+ ['716282970644228', '13135559029'],
172
+ ['521655380527741', '13135559030'],
173
+ ['476193631941905', '13135559031'],
174
+ ['485600497445562', '13135559032'],
175
+ ['440217235683910', '13135559033'],
176
+ ['523342446758478', '13135559034'],
177
+ ['514784864360240', '13135559035'],
178
+ ['505790121814530', '13135559036'],
179
+ ['420008964419580', '13135559037'],
180
+ ['492141680204555', '13135559038'],
181
+ ['388462787271952', '13135559039'],
182
+ ['423473920752072', '13135559040'],
183
+ ['489574180468229', '13135559041'],
184
+ ['432360635854105', '13135559042'],
185
+ ['477878201669248', '13135559043'],
186
+ ['351656951234045', '13135559044'],
187
+ ['430178036732582', '13135559045'],
188
+ ['434537312944552', '13135559046'],
189
+ ['1240614300631808', '13135559047'],
190
+ ['473135945605128', '13135559048'],
191
+ ['423669800729310', '13135559049'],
192
+ ['3685666705015792', '13135559050'],
193
+ ['504196509016638', '13135559051'],
194
+ ['346844785189449', '13135559052'],
195
+ ['504823088911074', '13135559053'],
196
+ ['402669415797083', '13135559054'],
197
+ ['490939640234431', '13135559055'],
198
+ ['875124128063715', '13135559056'],
199
+ ['468788962654605', '13135559057'],
200
+ ['562386196354570', '13135559058'],
201
+ ['372159285928791', '13135559059'],
202
+ ['531017479591050', '13135559060'],
203
+ ['1328873881401826', '13135559061'],
204
+ ['1608363646390484', '13135559062'],
205
+ ['1229628561554232', '13135559063'],
206
+ ['348802211530364', '13135559064'],
207
+ ['3708535859420184', '13135559065'],
208
+ ['415517767742187', '13135559066'],
209
+ ['479330341612638', '13135559067'],
210
+ ['480785414723083', '13135559068'],
211
+ ['387299107507991', '13135559069'],
212
+ ['333389813188944', '13135559070'],
213
+ ['391794130316996', '13135559071'],
214
+ ['457893470576314', '13135559072'],
215
+ ['435550496166469', '13135559073'],
216
+ ['1620162702100689', '13135559074'],
217
+ ['867491058616043', '13135559075'],
218
+ ['816224117357759', '13135559076'],
219
+ ['334065176362830', '13135559077'],
220
+ ['489973170554709', '13135559078'],
221
+ ['473060669049665', '13135559079'],
222
+ ['1221505815643060', '13135559080'],
223
+ ['889000703096359', '13135559081'],
224
+ ['475235961979883', '13135559082'],
225
+ ['3434445653519934', '13135559084'],
226
+ ['524503026827421', '13135559085'],
227
+ ['1179639046403856', '13135559086'],
228
+ ['471563305859144', '13135559087'],
229
+ ['533896609192881', '13135559088'],
230
+ ['365443583168041', '13135559089'],
231
+ ['836082305329393', '13135559090'],
232
+ ['1056787705969916', '13135559091'],
233
+ ['503312598958357', '13135559092'],
234
+ ['3718606738453460', '13135559093'],
235
+ ['826066052850902', '13135559094'],
236
+ ['1033611345091888', '13135559095'],
237
+ ['3868390816783240', '13135559096'],
238
+ ['7462677740498860', '13135559097'],
239
+ ['436288576108573', '13135559098'],
240
+ ['1047559746718900', '13135559099'],
241
+ ['1099299455255491', '13135559100'],
242
+ ['1202037301040633', '13135559101'],
243
+ ['1720619402074074', '13135559102'],
244
+ ['1030422235101467', '13135559103'],
245
+ ['827238979523502', '13135559104'],
246
+ ['1516443722284921', '13135559105'],
247
+ ['1174442747196709', '13135559106'],
248
+ ['1653165225503842', '13135559107'],
249
+ ['1037648777635013', '13135559108'],
250
+ ['551617757299900', '13135559109'],
251
+ ['1158813558718726', '13135559110'],
252
+ ['2463236450542262', '13135559111'],
253
+ ['1550393252501466', '13135559112'],
254
+ ['2057065188042796', '13135559113'],
255
+ ['506163028760735', '13135559114'],
256
+ ['2065249100538481', '13135559115'],
257
+ ['1041382867195858', '13135559116'],
258
+ ['886500209499603', '13135559117'],
259
+ ['1491615624892655', '13135559118'],
260
+ ['486563697299617', '13135559119'],
261
+ ['1175736513679463', '13135559120'],
262
+ ['491811473512352', '13165550064']
263
+ ]);
264
+ const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
265
+ if (sepIdx < 0) {
266
+ return jid;
267
+ }
268
+ const server = jid.slice(sepIdx + 1);
269
+ if (server !== 'bot')
270
+ return jid;
271
+ const user = jid.slice(0, sepIdx);
272
+ const mappedNumber = BOT_MAP.get(user);
273
+ return mappedNumber ? `${mappedNumber}@s.whatsapp.net` : jid;
274
+ };
275
+ exports.getBotJid = getBotJid;
276
+ const jidEncode = (user, server, device, agent) => {
277
+ const isInterop = server === 'interop';
278
+ return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device || (device === 0 && !isInterop) ? `:${device}` : ''}@${server}`;
279
+ };
280
+ exports.jidEncode = jidEncode;
281
+ const jidDecode = jid => {
282
+ const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
283
+ if (sepIdx < 0) {
284
+ return undefined;
285
+ }
286
+ const server = jid.slice(sepIdx + 1);
287
+ const userCombined = jid.slice(0, sepIdx);
288
+ const [userAgent, device] = userCombined.split(':');
289
+ const [user, agent] = userAgent.split('_');
290
+ let domainType = WAJIDDomains.WHATSAPP;
291
+ if (server === 'lid') {
292
+ domainType = WAJIDDomains.LID;
293
+ }
294
+ else if (server === 'hosted') {
295
+ domainType = WAJIDDomains.HOSTED;
296
+ }
297
+ else if (server === 'hosted.lid') {
298
+ domainType = WAJIDDomains.HOSTED_LID;
299
+ }
300
+ else if (agent) {
301
+ domainType = parseInt(agent);
302
+ }
303
+ return {
304
+ server: server,
305
+ user: user,
306
+ domainType,
307
+ device: device ? +device : undefined
308
+ };
309
+ };
310
+ exports.jidDecode = jidDecode;
311
+ const areJidsSameUser = (jid1, jid2) => (0, exports.jidDecode)(jid1)?.user === (0, exports.jidDecode)(jid2)?.user;
312
+ exports.areJidsSameUser = areJidsSameUser;
313
+ const isJidMetaAI = jid => jid?.endsWith('@bot');
314
+ exports.isJidMetaAI = isJidMetaAI;
315
+ const isPnUser = jid => jid?.endsWith('@s.whatsapp.net');
316
+ exports.isPnUser = isPnUser;
317
+ const isInteropUser = jid => jid?.endsWith('@interop');
318
+ exports.isInteropUser = isInteropUser;
319
+ const isLidUser = jid => jid?.endsWith('@lid');
320
+ exports.isLidUser = isLidUser;
321
+ const isJidBroadcast = jid => jid?.endsWith('@broadcast');
322
+ exports.isJidBroadcast = isJidBroadcast;
323
+ const isJidGroup = jid => jid?.endsWith('@g.us');
324
+ exports.isJidGroup = isJidGroup;
325
+ const isJidStatusBroadcast = jid => jid === 'status@broadcast';
326
+ exports.isJidStatusBroadcast = isJidStatusBroadcast;
327
+ const isJidNewsletter = jid => jid?.endsWith('@newsletter');
328
+ exports.isJidNewsletter = isJidNewsletter;
329
+ const isHostedPnUser = jid => jid?.endsWith('@hosted');
330
+ exports.isHostedPnUser = isHostedPnUser;
331
+ const isHostedLidUser = jid => jid?.endsWith('@hosted.lid');
332
+ exports.isHostedLidUser = isHostedLidUser;
333
+ const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
334
+ const isJidBot = jid => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
335
+ exports.isJidBot = isJidBot;
336
+ const jidNormalizedUser = jid => {
337
+ const result = (0, exports.jidDecode)(jid);
338
+ if (!result) {
339
+ return '';
340
+ }
341
+ const { user, server } = result;
342
+ return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
343
+ };
344
+ exports.jidNormalizedUser = jidNormalizedUser;
345
+ const transferDevice = (fromJid, toJid) => {
346
+ const fromDecoded = (0, exports.jidDecode)(fromJid);
347
+ const deviceId = fromDecoded?.device || 0;
348
+ const { server, user } = (0, exports.jidDecode)(toJid);
349
+ return (0, exports.jidEncode)(user, server, deviceId);
350
+ };
351
+ exports.transferDevice = transferDevice;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.BinaryInfo = void 0;
4
+ class BinaryInfo {
5
+ constructor(options = {}) {
6
+ this.protocolVersion = 5;
7
+ this.sequence = 0;
8
+ this.events = [];
9
+ this.buffer = [];
10
+ Object.assign(this, options);
11
+ }
12
+ }
13
+ exports.BinaryInfo = BinaryInfo;