@genuxofficial/baileys 3.0.0 → 4.0.0

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 (88) hide show
  1. package/WAProto/WAProto.proto +24 -206
  2. package/WAProto/index.d.ts +219 -2233
  3. package/WAProto/index.js +525 -6773
  4. package/WAProto/shizo.x +1 -0
  5. package/lib/Defaults/baileys-version.json +1 -1
  6. package/lib/Defaults/index.d.ts +231 -0
  7. package/lib/Defaults/index.js +17 -1
  8. package/lib/Defaults/phonenumber-mcc.json +223 -0
  9. package/lib/Socket/Client/index.d.ts +3 -2
  10. package/lib/Socket/Client/index.js +3 -2
  11. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  12. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  13. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  14. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
  15. package/lib/Socket/business.d.ts +7 -9
  16. package/lib/Socket/chats.d.ts +5 -8
  17. package/lib/Socket/chats.js +8 -38
  18. package/lib/Socket/groups.d.ts +5 -7
  19. package/lib/Socket/groups.js +2 -14
  20. package/lib/Socket/index.d.ts +9 -9
  21. package/lib/Socket/index.js +2 -2
  22. package/lib/Socket/messages-recv.d.ts +8 -10
  23. package/lib/Socket/messages-recv.js +11 -18
  24. package/lib/Socket/messages-send.d.ts +7 -14
  25. package/lib/Socket/messages-send.js +13 -36
  26. package/lib/Socket/newsletter.d.ts +7 -9
  27. package/lib/Socket/newsletter.js +3 -11
  28. package/lib/Socket/registration.d.ts +271 -0
  29. package/lib/Socket/registration.js +166 -0
  30. package/lib/Socket/socket.d.ts +4 -5
  31. package/lib/Socket/socket.js +18 -15
  32. package/lib/Socket/usync.d.ts +4 -4
  33. package/lib/Store/index.d.ts +2 -1
  34. package/lib/Store/index.js +3 -1
  35. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  36. package/lib/Store/make-cache-manager-store.js +83 -0
  37. package/lib/Store/make-in-memory-store.js +10 -8
  38. package/lib/Store/make-ordered-dictionary.js +2 -2
  39. package/lib/Types/Auth.d.ts +6 -0
  40. package/lib/Types/Chat.d.ts +0 -4
  41. package/lib/Types/Contact.d.ts +1 -1
  42. package/lib/Types/GroupMetadata.d.ts +0 -6
  43. package/lib/Types/Message.d.ts +5 -29
  44. package/lib/Types/Message.js +2 -0
  45. package/lib/Types/Socket.d.ts +4 -7
  46. package/lib/Utils/auth-utils.d.ts +1 -1
  47. package/lib/Utils/auth-utils.js +9 -2
  48. package/lib/Utils/business.js +3 -15
  49. package/lib/Utils/chat-utils.d.ts +4 -4
  50. package/lib/Utils/chat-utils.js +2 -1
  51. package/lib/Utils/decode-wa-message.d.ts +2 -4
  52. package/lib/Utils/decode-wa-message.js +24 -145
  53. package/lib/Utils/event-buffer.js +6 -4
  54. package/lib/Utils/generics.d.ts +4 -7
  55. package/lib/Utils/generics.js +17 -9
  56. package/lib/Utils/lt-hash.d.ts +3 -3
  57. package/lib/Utils/lt-hash.js +45 -11
  58. package/lib/Utils/messages-media.d.ts +4 -4
  59. package/lib/Utils/messages-media.js +57 -69
  60. package/lib/Utils/messages.js +39 -33
  61. package/lib/Utils/noise-handler.d.ts +2 -1
  62. package/lib/Utils/noise-handler.js +10 -5
  63. package/lib/Utils/use-multi-file-auth-state.js +11 -48
  64. package/lib/Utils/validate-connection.d.ts +1 -0
  65. package/lib/Utils/validate-connection.js +44 -10
  66. package/lib/WABinary/constants.js +5 -5
  67. package/lib/WABinary/encode.js +10 -23
  68. package/lib/WABinary/generic-utils.d.ts +5 -3
  69. package/lib/WABinary/generic-utils.js +19 -34
  70. package/lib/WABinary/jid-utils.d.ts +2 -11
  71. package/lib/WABinary/jid-utils.js +2 -27
  72. package/lib/WAM/BinaryInfo.d.ts +2 -2
  73. package/lib/WAM/constants.d.ts +2 -3
  74. package/lib/WAM/encode.js +2 -2
  75. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +12 -21
  76. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  77. package/lib/WAUSync/USyncQuery.d.ts +0 -2
  78. package/lib/WAUSync/USyncQuery.js +0 -10
  79. package/lib/WAUSync/USyncUser.d.ts +0 -2
  80. package/lib/WAUSync/USyncUser.js +0 -4
  81. package/package.json +5 -6
  82. package/LICENSE +0 -21
  83. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  84. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  85. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  86. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  87. /package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +0 -0
  88. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -40,11 +40,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
40
40
  buffer.push((value >> (curShift * 8)) & 0xff);
41
41
  }
42
42
  };
43
- const pushBytes = (bytes) => {
44
- for (const b of bytes) {
45
- buffer.push(b);
46
- }
47
- };
43
+ const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
48
44
  const pushInt16 = (value) => {
49
45
  pushBytes([(value >> 8) & 0xff, value & 0xff]);
50
46
  };
@@ -143,10 +139,11 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
143
139
  }
144
140
  };
145
141
  const isNibble = (str) => {
146
- if (!str || str.length > TAGS.PACKED_MAX) {
142
+ if (str.length > TAGS.PACKED_MAX) {
147
143
  return false;
148
144
  }
149
- for (const char of str) {
145
+ for (let i = 0; i < str.length; i++) {
146
+ const char = str[i];
150
147
  const isInNibbleRange = char >= '0' && char <= '9';
151
148
  if (!isInNibbleRange && char !== '-' && char !== '.') {
152
149
  return false;
@@ -155,10 +152,11 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
155
152
  return true;
156
153
  };
157
154
  const isHex = (str) => {
158
- if (!str || str.length > TAGS.PACKED_MAX) {
155
+ if (str.length > TAGS.PACKED_MAX) {
159
156
  return false;
160
157
  }
161
- for (const char of str) {
158
+ for (let i = 0; i < str.length; i++) {
159
+ const char = str[i];
162
160
  const isInNibbleRange = char >= '0' && char <= '9';
163
161
  if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
164
162
  return false;
@@ -167,10 +165,6 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
167
165
  return true;
168
166
  };
169
167
  const writeString = (str) => {
170
- if (str === undefined || str === null) {
171
- pushByte(TAGS.LIST_EMPTY);
172
- return;
173
- }
174
168
  const tokenIndex = TOKEN_MAP[str];
175
169
  if (tokenIndex) {
176
170
  if (typeof tokenIndex.dict === 'number') {
@@ -181,9 +175,6 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
181
175
  else if (isNibble(str)) {
182
176
  writePackedBytes(str, 'nibble');
183
177
  }
184
- else if (isHex(str)) {
185
- writePackedBytes(str, 'hex');
186
- }
187
178
  else if (str) {
188
179
  const decodedJid = (0, jid_utils_1.jidDecode)(str);
189
180
  if (decodedJid) {
@@ -206,10 +197,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
206
197
  pushInt16(listSize);
207
198
  }
208
199
  };
209
- if (!tag) {
210
- throw new Error('Invalid node: tag cannot be undefined');
211
- }
212
- const validAttributes = Object.keys(attrs || {}).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
200
+ const validAttributes = Object.keys(attrs).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
213
201
  writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
214
202
  writeString(tag);
215
203
  for (const key of validAttributes) {
@@ -226,9 +214,8 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
226
214
  pushBytes(content);
227
215
  }
228
216
  else if (Array.isArray(content)) {
229
- const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
230
- writeListStart(validContent.length);
231
- for (const item of validContent) {
217
+ writeListStart(content.length);
218
+ for (const item of content) {
232
219
  encodeBinaryNodeInner(item, opts, buffer);
233
220
  }
234
221
  }
@@ -7,8 +7,10 @@ export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => Bina
7
7
  export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
8
8
  export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
9
9
  export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
10
- export declare const getBinaryNodeChildUInt: (node: BinaryNode | undefined, childTag: string, length: number) => number | undefined;
10
+ export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
11
11
  export declare const assertNodeErrorFree: (node: BinaryNode) => void;
12
- export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => Record<string, string>;
12
+ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => {
13
+ [_: string]: string;
14
+ };
13
15
  export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
14
- export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'] | undefined, i?: number): string | undefined;
16
+ export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): any;
@@ -5,21 +5,23 @@ const boom_1 = require("@hapi/boom");
5
5
  const WAProto_1 = require("../../WAProto");
6
6
  // some extra useful utilities
7
7
  const getBinaryNodeChildren = (node, childTag) => {
8
- if (!node || !Array.isArray(node.content)) {
9
- return [];
8
+ if (Array.isArray(node === null || node === void 0 ? void 0 : node.content)) {
9
+ return node.content.filter(item => item.tag === childTag);
10
10
  }
11
- return node.content.filter((item) => item.tag === childTag);
11
+ return [];
12
12
  };
13
13
  exports.getBinaryNodeChildren = getBinaryNodeChildren;
14
14
  const getAllBinaryNodeChildren = ({ content }) => {
15
- return Array.isArray(content) ? content : [];
15
+ if (Array.isArray(content)) {
16
+ return content;
17
+ }
18
+ return [];
16
19
  };
17
20
  exports.getAllBinaryNodeChildren = getAllBinaryNodeChildren;
18
21
  const getBinaryNodeChild = (node, childTag) => {
19
- if (!node || !Array.isArray(node.content)) {
20
- return undefined;
22
+ if (Array.isArray(node === null || node === void 0 ? void 0 : node.content)) {
23
+ return node === null || node === void 0 ? void 0 : node.content.find(item => item.tag === childTag);
21
24
  }
22
- return node.content.find(item => item.tag === childTag);
23
25
  };
24
26
  exports.getBinaryNodeChild = getBinaryNodeChild;
25
27
  const getBinaryNodeChildBuffer = (node, childTag) => {
@@ -28,7 +30,6 @@ const getBinaryNodeChildBuffer = (node, childTag) => {
28
30
  if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
29
31
  return child;
30
32
  }
31
- return undefined;
32
33
  };
33
34
  exports.getBinaryNodeChildBuffer = getBinaryNodeChildBuffer;
34
35
  const getBinaryNodeChildString = (node, childTag) => {
@@ -40,7 +41,6 @@ const getBinaryNodeChildString = (node, childTag) => {
40
41
  else if (typeof child === 'string') {
41
42
  return child;
42
43
  }
43
- return undefined;
44
44
  };
45
45
  exports.getBinaryNodeChildString = getBinaryNodeChildString;
46
46
  const getBinaryNodeChildUInt = (node, childTag, length) => {
@@ -48,45 +48,31 @@ const getBinaryNodeChildUInt = (node, childTag, length) => {
48
48
  if (buff) {
49
49
  return bufferToUInt(buff, length);
50
50
  }
51
- return undefined;
52
51
  };
53
52
  exports.getBinaryNodeChildUInt = getBinaryNodeChildUInt;
54
53
  const assertNodeErrorFree = (node) => {
55
- var _a, _b;
56
54
  const errNode = (0, exports.getBinaryNodeChild)(node, 'error');
57
55
  if (errNode) {
58
- throw new boom_1.Boom(((_a = errNode.attrs) === null || _a === void 0 ? void 0 : _a.text) || 'Unknown error', {
59
- data: Number((_b = errNode.attrs) === null || _b === void 0 ? void 0 : _b.code) || 0
60
- });
56
+ throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
61
57
  }
62
58
  };
63
59
  exports.assertNodeErrorFree = assertNodeErrorFree;
64
60
  const reduceBinaryNodeToDictionary = (node, tag) => {
65
61
  const nodes = (0, exports.getBinaryNodeChildren)(node, tag);
66
- return nodes.reduce((dict, { attrs }) => {
67
- const name = (attrs === null || attrs === void 0 ? void 0 : attrs.name) || (attrs === null || attrs === void 0 ? void 0 : attrs.config_code);
68
- const value = (attrs === null || attrs === void 0 ? void 0 : attrs.value) || (attrs === null || attrs === void 0 ? void 0 : attrs.config_value);
69
- if (name && value) {
70
- dict[name] = value;
71
- }
62
+ const dict = nodes.reduce((dict, { attrs }) => {
63
+ dict[attrs.name || attrs.config_code] = attrs.value || attrs.config_value;
72
64
  return dict;
73
65
  }, {});
66
+ return dict;
74
67
  };
75
68
  exports.reduceBinaryNodeToDictionary = reduceBinaryNodeToDictionary;
76
69
  const getBinaryNodeMessages = ({ content }) => {
77
- if (!Array.isArray(content)) {
78
- return [];
79
- }
80
70
  const msgs = [];
81
- for (const item of content) {
82
- if (item.tag === 'message' && item.content) {
83
- try {
71
+ if (Array.isArray(content)) {
72
+ for (const item of content) {
73
+ if (item.tag === 'message') {
84
74
  msgs.push(WAProto_1.proto.WebMessageInfo.decode(item.content));
85
75
  }
86
- catch (error) {
87
- // Handle decode error if needed
88
- console.error('Failed to decode message:', error);
89
- }
90
76
  }
91
77
  }
92
78
  return msgs;
@@ -102,7 +88,7 @@ function bufferToUInt(e, t) {
102
88
  const tabs = (n) => '\t'.repeat(n);
103
89
  function binaryNodeToString(node, i = 0) {
104
90
  if (!node) {
105
- return undefined;
91
+ return node;
106
92
  }
107
93
  if (typeof node === 'string') {
108
94
  return tabs(i) + node;
@@ -114,11 +100,10 @@ function binaryNodeToString(node, i = 0) {
114
100
  return node.map((x) => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
115
101
  }
116
102
  const children = binaryNodeToString(node.content, i + 1);
117
- const attrs = Object.entries(node.attrs || {})
103
+ const tag = `<${node.tag} ${Object.entries(node.attrs || {})
118
104
  .filter(([, v]) => v !== undefined)
119
105
  .map(([k, v]) => `${k}='${v}'`)
120
- .join(' ');
121
- const tag = `<${node.tag}${attrs ? ' ' + attrs : ''}`;
106
+ .join(' ')}`;
122
107
  const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
123
108
  return tag + content;
124
109
  }
@@ -3,27 +3,19 @@ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
3
3
  export declare const SERVER_JID = "server@c.us";
4
4
  export declare const PSA_WID = "0@c.us";
5
5
  export declare const STORIES_JID = "status@broadcast";
6
- export declare const META_AI_JID = "13135550002@c.us";
7
- export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter' | 'bot';
6
+ export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter';
8
7
  export type JidWithDevice = {
9
8
  user: string;
10
9
  device?: number;
11
10
  };
12
11
  export type FullJid = JidWithDevice & {
13
- server: JidServer;
12
+ server: JidServer | string;
14
13
  domainType?: number;
15
14
  };
16
- /**
17
- Get Meta Ai's Jid
18
- @shizothetechie
19
- */
20
- export declare const getBotJid: (jid: string) => string;
21
15
  export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
22
16
  export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
23
17
  /** is the jid a user */
24
18
  export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
25
- /** is the jid a bot (Meta Ai) */
26
- export declare const isJidMetaAI: (jid: string | undefined) => boolean | undefined;
27
19
  /** is the jid a user */
28
20
  export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
29
21
  /** is the jid a group */
@@ -36,5 +28,4 @@ export declare const isJidNewsletter: (jid: string | undefined) => boolean | und
36
28
  export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
37
29
  /** is the jid the status broadcast */
38
30
  export declare const isJidStatusBroadcast: (jid: string) => boolean;
39
- export declare const isJidBot: (jid: string | undefined) => boolean | "" | undefined;
40
31
  export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -1,30 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jidNormalizedUser = exports.isJidBot = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidNewsletter = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.isJidMetaAI = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.getBotJid = exports.META_AI_JID = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
3
+ exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidNewsletter = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
4
  exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
5
  exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
6
  exports.SERVER_JID = 'server@c.us';
7
7
  exports.PSA_WID = '0@c.us';
8
8
  exports.STORIES_JID = 'status@broadcast';
9
- exports.META_AI_JID = '13135550002@c.us';
10
- /**
11
- Get Meta Ai's Jid
12
- @shizothetechie
13
- */
14
- const getBotJid = (jid) => {
15
- const BOT_MAP = new Map([["867051314767696", "13135550002"], ["1061492271844689", "13135550005"], ["245886058483988", "13135550009"], ["3509905702656130", "13135550012"], ["1059680132034576", "13135550013"], ["715681030623646", "13135550014"], ["1644971366323052", "13135550015"], ["582497970646566", "13135550019"], ["645459357769306", "13135550022"], ["294997126699143", "13135550023"], ["1522631578502677", "13135550027"], ["719421926276396", "13135550030"], ["1788488635002167", "13135550031"], ["24232338603080193", "13135550033"], ["689289903143209", "13135550035"], ["871626054177096", "13135550039"], ["362351902849370", "13135550042"], ["1744617646041527", "13135550043"], ["893887762270570", "13135550046"], ["1155032702135830", "13135550047"], ["333931965993883", "13135550048"], ["853748013058752", "13135550049"], ["1559068611564819", "13135550053"], ["890487432705716", "13135550054"], ["240254602395494", "13135550055"], ["1578420349663261", "13135550062"], ["322908887140421", "13135550065"], ["3713961535514771", "13135550067"], ["997884654811738", "13135550070"], ["403157239387035", "13135550081"], ["535242369074963", "13135550082"], ["946293427247659", "13135550083"], ["3664707673802291", "13135550084"], ["1821827464894892", "13135550085"], ["1760312477828757", "13135550086"], ["439480398712216", "13135550087"], ["1876735582800984", "13135550088"], ["984025089825661", "13135550089"], ["1001336351558186", "13135550090"], ["3739346336347061", "13135550091"], ["3632749426974980", "13135550092"], ["427864203481615", "13135550093"], ["1434734570493055", "13135550094"], ["992873449225921", "13135550095"], ["813087747426445", "13135550096"], ["806369104931434", "13135550098"], ["1220982902403148", "13135550099"], ["1365893374104393", "13135550100"], ["686482033622048", "13135550200"], ["1454999838411253", "13135550201"], ["718584497008509", "13135550202"], ["743520384213443", "13135550301"], ["1147715789823789", "13135550302"], ["1173034540372201", "13135550303"], ["974785541030953", "13135550304"], ["1122200255531507", "13135550305"], ["899669714813162", "13135550306"], ["631880108970650", "13135550307"], ["435816149330026", "13135550308"], ["1368717161184556", "13135550309"], ["7849963461784891", "13135550310"], ["3609617065968984", "13135550312"], ["356273980574602", "13135550313"], ["1043447920539760", "13135550314"], ["1052764336525346", "13135550315"], ["2631118843732685", "13135550316"], ["510505411332176", "13135550317"], ["1945664239227513", "13135550318"], ["1518594378764656", "13135550319"], ["1378821579456138", "13135550320"], ["490214716896013", "13135550321"], ["1028577858870699", "13135550322"], ["308915665545959", "13135550323"], ["845884253678900", "13135550324"], ["995031308616442", "13135550325"], ["2787365464763437", "13135550326"], ["1532790990671645", "13135550327"], ["302617036180485", "13135550328"], ["723376723197227", "13135550329"], ["8393570407377966", "13135550330"], ["1931159970680725", "13135550331"], ["401073885688605", "13135550332"], ["2234478453565422", "13135550334"], ["814748673882312", "13135550335"], ["26133635056281592", "13135550336"], ["1439804456676119", "13135550337"], ["889851503172161", "13135550338"], ["1018283232836879", "13135550339"], ["1012781386779537", "13135559000"], ["823280953239532", "13135559001"], ["1597090934573334", "13135559002"], ["485965054020343", "13135559003"], ["1033381648363446", "13135559004"], ["491802010206446", "13135559005"], ["1017139033184870", "13135559006"], ["499638325922174", "13135559008"], ["468946335863664", "13135559009"], ["1570389776875816", "13135559010"], ["1004342694328995", "13135559011"], ["1012240323971229", "13135559012"], ["392171787222419", "13135559013"], ["952081212945019", "13135559016"], ["444507875070178", "13135559017"], ["1274819440594668", "13135559018"], ["1397041101147050", "13135559019"], ["425657699872640", "13135559020"], ["532292852562549", "13135559021"], ["705863241720292", "13135559022"], ["476449815183959", "13135559023"], ["488071553854222", "13135559024"], ["468693832665397", "13135559025"], ["517422564037340", "13135559026"], ["819805466613825", "13135559027"], ["1847708235641382", "13135559028"], ["716282970644228", "13135559029"], ["521655380527741", "13135559030"], ["476193631941905", "13135559031"], ["485600497445562", "13135559032"], ["440217235683910", "13135559033"], ["523342446758478", "13135559034"], ["514784864360240", "13135559035"], ["505790121814530", "13135559036"], ["420008964419580", "13135559037"], ["492141680204555", "13135559038"], ["388462787271952", "13135559039"], ["423473920752072", "13135559040"], ["489574180468229", "13135559041"], ["432360635854105", "13135559042"], ["477878201669248", "13135559043"], ["351656951234045", "13135559044"], ["430178036732582", "13135559045"], ["434537312944552", "13135559046"], ["1240614300631808", "13135559047"], ["473135945605128", "13135559048"], ["423669800729310", "13135559049"], ["3685666705015792", "13135559050"], ["504196509016638", "13135559051"], ["346844785189449", "13135559052"], ["504823088911074", "13135559053"], ["402669415797083", "13135559054"], ["490939640234431", "13135559055"], ["875124128063715", "13135559056"], ["468788962654605", "13135559057"], ["562386196354570", "13135559058"], ["372159285928791", "13135559059"], ["531017479591050", "13135559060"], ["1328873881401826", "13135559061"], ["1608363646390484", "13135559062"], ["1229628561554232", "13135559063"], ["348802211530364", "13135559064"], ["3708535859420184", "13135559065"], ["415517767742187", "13135559066"], ["479330341612638", "13135559067"], ["480785414723083", "13135559068"], ["387299107507991", "13135559069"], ["333389813188944", "13135559070"], ["391794130316996", "13135559071"], ["457893470576314", "13135559072"], ["435550496166469", "13135559073"], ["1620162702100689", "13135559074"], ["867491058616043", "13135559075"], ["816224117357759", "13135559076"], ["334065176362830", "13135559077"], ["489973170554709", "13135559078"], ["473060669049665", "13135559079"], ["1221505815643060", "13135559080"], ["889000703096359", "13135559081"], ["475235961979883", "13135559082"], ["3434445653519934", "13135559084"], ["524503026827421", "13135559085"], ["1179639046403856", "13135559086"], ["471563305859144", "13135559087"], ["533896609192881", "13135559088"], ["365443583168041", "13135559089"], ["836082305329393", "13135559090"], ["1056787705969916", "13135559091"], ["503312598958357", "13135559092"], ["3718606738453460", "13135559093"], ["826066052850902", "13135559094"], ["1033611345091888", "13135559095"], ["3868390816783240", "13135559096"], ["7462677740498860", "13135559097"], ["436288576108573", "13135559098"], ["1047559746718900", "13135559099"], ["1099299455255491", "13135559100"], ["1202037301040633", "13135559101"], ["1720619402074074", "13135559102"], ["1030422235101467", "13135559103"], ["827238979523502", "13135559104"], ["1516443722284921", "13135559105"], ["1174442747196709", "13135559106"], ["1653165225503842", "13135559107"], ["1037648777635013", "13135559108"], ["551617757299900", "13135559109"], ["1158813558718726", "13135559110"], ["2463236450542262", "13135559111"], ["1550393252501466", "13135559112"], ["2057065188042796", "13135559113"], ["506163028760735", "13135559114"], ["2065249100538481", "13135559115"], ["1041382867195858", "13135559116"], ["886500209499603", "13135559117"], ["1491615624892655", "13135559118"], ["486563697299617", "13135559119"], ["1175736513679463", "13135559120"], ["491811473512352", "13165550064"]]);
16
- const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
17
- if (sepIdx < 0) {
18
- return jid;
19
- }
20
- const server = jid.slice(sepIdx + 1);
21
- if (server !== 'bot')
22
- return jid;
23
- const user = jid.slice(0, sepIdx);
24
- const mappedNumber = BOT_MAP.get(user);
25
- return mappedNumber ? `${mappedNumber}@s.whatsapp.net` : jid;
26
- };
27
- exports.getBotJid = getBotJid;
28
9
  const jidEncode = (user, server, device, agent) => {
29
10
  return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
30
11
  };
@@ -39,7 +20,7 @@ const jidDecode = (jid) => {
39
20
  const [userAgent, device] = userCombined.split(':');
40
21
  const user = userAgent.split('_')[0];
41
22
  return {
42
- server: server,
23
+ server,
43
24
  user,
44
25
  domainType: server === 'lid' ? 1 : 0,
45
26
  device: device ? +device : undefined
@@ -52,9 +33,6 @@ const areJidsSameUser = (jid1, jid2) => {
52
33
  return (((_a = (0, exports.jidDecode)(jid1)) === null || _a === void 0 ? void 0 : _a.user) === ((_b = (0, exports.jidDecode)(jid2)) === null || _b === void 0 ? void 0 : _b.user));
53
34
  };
54
35
  exports.areJidsSameUser = areJidsSameUser;
55
- /** is the jid a bot (Meta Ai) */
56
- const isJidMetaAI = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@bot'));
57
- exports.isJidMetaAI = isJidMetaAI;
58
36
  /** is the jid a user */
59
37
  const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
60
38
  exports.isJidUser = isJidUser;
@@ -73,9 +51,6 @@ exports.isJidGroup = isJidGroup;
73
51
  /** is the jid the status broadcast */
74
52
  const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
75
53
  exports.isJidStatusBroadcast = isJidStatusBroadcast;
76
- const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
77
- const isJidBot = (jid) => (jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us'));
78
- exports.isJidBot = isJidBot;
79
54
  const jidNormalizedUser = (jid) => {
80
55
  const result = (0, exports.jidDecode)(jid);
81
56
  if (!result) {
@@ -6,10 +6,10 @@ export declare class BinaryInfo {
6
6
  events: {
7
7
  [x: string]: {
8
8
  props: {
9
- [x: string]: import("./constants").Value;
9
+ [x: string]: any;
10
10
  };
11
11
  globals: {
12
- [x: string]: import("./constants").Value;
12
+ [x: string]: any;
13
13
  };
14
14
  };
15
15
  }[];
@@ -28,12 +28,11 @@ type EventByName<T extends Event['name']> = Extract<Event, {
28
28
  export type EventInputType = {
29
29
  [key in Event['name']]: {
30
30
  props: {
31
- [k in keyof EventByName<key>['props']]: Value;
31
+ [k in keyof EventByName<key>['props']]: any;
32
32
  };
33
33
  globals: {
34
- [x: string]: Value;
34
+ [x: string]: any;
35
35
  };
36
36
  };
37
37
  } & {};
38
- export type Value = number | null | string;
39
38
  export {};
package/lib/WAM/encode.js CHANGED
@@ -13,10 +13,10 @@ const encodeWAM = (binaryInfo) => {
13
13
  .reduce((a, b) => a + b);
14
14
  const buffer = Buffer.alloc(totalSize);
15
15
  let offset = 0;
16
- for (const buffer_ of binaryInfo.buffer) {
16
+ binaryInfo.buffer.forEach((buffer_) => {
17
17
  buffer_.copy(buffer, offset);
18
18
  offset += buffer_.length;
19
- }
19
+ });
20
20
  return buffer;
21
21
  };
22
22
  exports.encodeWAM = encodeWAM;
@@ -27,38 +27,29 @@ class USyncDeviceProtocol {
27
27
  (0, WABinary_1.assertNodeErrorFree)(node);
28
28
  const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(node, 'device-list');
29
29
  const keyIndexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'key-index-list');
30
- if (deviceListNode && Array.isArray(deviceListNode.content)) {
31
- for (const item of deviceListNode.content) {
32
- if (item.tag === 'device' && item.attrs) {
33
- const id = Number(item.attrs.id) || 0;
34
- const keyIndexValue = item.attrs['key-index']
35
- ? Number(item.attrs['key-index'])
36
- : undefined;
37
- const isHosted = item.attrs['is_hosted'] === 'true';
30
+ if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
31
+ for (const { tag, attrs } of deviceListNode.content) {
32
+ const id = +attrs.id;
33
+ const keyIndex = +attrs['key-index'];
34
+ if (tag === 'device') {
38
35
  deviceList.push({
39
36
  id,
40
- keyIndex: keyIndexValue,
41
- isHosted
37
+ keyIndex,
38
+ isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
42
39
  });
43
40
  }
44
41
  }
45
42
  }
46
- if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list' && keyIndexNode.attrs) {
47
- const timestamp = Number(keyIndexNode.attrs['ts']) || 0;
48
- const expectedTimestamp = keyIndexNode.attrs['expected_ts']
49
- ? Number(keyIndexNode.attrs['expected_ts'])
50
- : undefined;
43
+ if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list') {
51
44
  keyIndex = {
52
- timestamp,
53
- signedKeyIndex: keyIndexNode.content instanceof Uint8Array
54
- ? keyIndexNode.content
55
- : undefined,
56
- expectedTimestamp
45
+ timestamp: +keyIndexNode.attrs['ts'],
46
+ signedKeyIndex: keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.content,
47
+ expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
57
48
  };
58
49
  }
59
50
  }
60
51
  return {
61
- deviceList: deviceList.length > 0 ? deviceList : undefined,
52
+ deviceList,
62
53
  keyIndex
63
54
  };
64
55
  }
@@ -16,13 +16,13 @@ class USyncStatusProtocol {
16
16
  return null;
17
17
  }
18
18
  parser(node) {
19
- var _a, _b, _c;
19
+ var _a;
20
20
  if (node.tag === 'status') {
21
21
  (0, WABinary_1.assertNodeErrorFree)(node);
22
- let status = (_b = (_a = node === null || node === void 0 ? void 0 : node.content) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : null;
22
+ let status = node === null || node === void 0 ? void 0 : node.content.toString();
23
23
  const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
24
24
  if (!status) {
25
- if (+((_c = node.attrs) === null || _c === void 0 ? void 0 : _c.code) === 401) {
25
+ if (+((_a = node.attrs) === null || _a === void 0 ? void 0 : _a.code) === 401) {
26
26
  status = '';
27
27
  }
28
28
  else {
@@ -23,6 +23,4 @@ export declare class USyncQuery {
23
23
  withContactProtocol(): this;
24
24
  withStatusProtocol(): this;
25
25
  withDisappearingModeProtocol(): this;
26
- withBotProfileProtocol(): this;
27
- withLIDProtocol(): this;
28
26
  }
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.USyncQuery = void 0;
4
4
  const WABinary_1 = require("../WABinary");
5
- const UsyncBotProfileProtocol_1 = require("./Protocols/UsyncBotProfileProtocol");
6
- const UsyncLIDProtocol_1 = require("./Protocols/UsyncLIDProtocol");
7
5
  const Protocols_1 = require("./Protocols");
8
6
  class USyncQuery {
9
7
  constructor() {
@@ -77,13 +75,5 @@ class USyncQuery {
77
75
  this.protocols.push(new Protocols_1.USyncDisappearingModeProtocol());
78
76
  return this;
79
77
  }
80
- withBotProfileProtocol() {
81
- this.protocols.push(new UsyncBotProfileProtocol_1.USyncBotProfileProtocol());
82
- return this;
83
- }
84
- withLIDProtocol() {
85
- this.protocols.push(new UsyncLIDProtocol_1.USyncLIDProtocol());
86
- return this;
87
- }
88
78
  }
89
79
  exports.USyncQuery = USyncQuery;
@@ -3,10 +3,8 @@ export declare class USyncUser {
3
3
  lid: string;
4
4
  phone: string;
5
5
  type: string;
6
- personaId: string;
7
6
  withId(id: string): this;
8
7
  withLid(lid: string): this;
9
8
  withPhone(phone: string): this;
10
9
  withType(type: string): this;
11
- withPersonaId(personaId: string): this;
12
10
  }
@@ -18,9 +18,5 @@ class USyncUser {
18
18
  this.type = type;
19
19
  return this;
20
20
  }
21
- withPersonaId(personaId) {
22
- this.personaId = personaId;
23
- return this;
24
- }
25
21
  }
26
22
  exports.USyncUser = USyncUser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genuxofficial/baileys",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "baileys",
@@ -19,7 +19,7 @@
19
19
  "url": "https://github.com/genux-official/Baileys.git"
20
20
  },
21
21
  "license": "MIT",
22
- "author": "Genux Official",
22
+ "author": "Yugesh Singh",
23
23
  "main": "lib/index.js",
24
24
  "types": "lib/index.d.ts",
25
25
  "files": [
@@ -36,6 +36,7 @@
36
36
  "changelog:preview": "conventional-changelog -p angular -u",
37
37
  "changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
38
38
  "example": "node --inspect -r ts-node/register Example/example.ts",
39
+ "example:mobile": "node --inspect -r ts-node/register Example/example.ts --mobile",
39
40
  "gen:protobuf": "sh WAProto/GenerateStatics.sh",
40
41
  "lint": "eslint src --ext .js,.ts,.jsx,.tsx",
41
42
  "lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
@@ -47,14 +48,12 @@
47
48
  "dependencies": {
48
49
  "@adiwajshing/keyed-db": "^0.2.4",
49
50
  "@hapi/boom": "^9.1.3",
50
- "async-mutex": "^0.5.0",
51
51
  "async-lock": "^1.4.1",
52
- "futoin-hkdf": "^1.5.1",
53
52
  "audio-decode": "^2.1.3",
54
53
  "axios": "^1.6.0",
55
54
  "cache-manager": "^5.7.6",
56
55
  "libphonenumber-js": "^1.10.20",
57
- "libsignal": "git+https://github.com/WhiskeySockets/libsignal-node.git",
56
+ "libsignal": "https://github.com/shizo-devs/libsignal-node.git",
58
57
  "lodash": "^4.17.21",
59
58
  "music-metadata": "^7.12.3",
60
59
  "@cacheable/node-cache": "^1.4.0",
@@ -86,7 +85,7 @@
86
85
  "typescript": "^4.6.4"
87
86
  },
88
87
  "peerDependencies": {
89
- "jimp": "^0.22.12",
88
+ "jimp": "^0.16.1",
90
89
  "link-preview-js": "^3.0.0",
91
90
  "qrcode-terminal": "^0.12.0",
92
91
  "sharp": "^0.32.6"
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Genux Official
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,25 +0,0 @@
1
- import { USyncQueryProtocol } from '../../Types/USync';
2
- import { BinaryNode } from '../../WABinary';
3
- import { USyncUser } from '../USyncUser';
4
- export type BotProfileCommand = {
5
- name: string;
6
- description: string;
7
- };
8
- export type BotProfileInfo = {
9
- jid: string;
10
- name: string;
11
- attributes: string;
12
- description: string;
13
- category: string;
14
- isDefault: boolean;
15
- prompts: string[];
16
- personaId: string;
17
- commands: BotProfileCommand[];
18
- commandsDescription: string;
19
- };
20
- export declare class USyncBotProfileProtocol implements USyncQueryProtocol {
21
- name: string;
22
- getQueryElement(): BinaryNode;
23
- getUserElement(user: USyncUser): BinaryNode;
24
- parser(node: BinaryNode): BotProfileInfo;
25
- }