@ubedsockets/baileys 1.6.6 → 1.6.7

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 (87) hide show
  1. package/WAProto/GenerateStatics.sh +4 -3
  2. package/WAProto/WAProto.proto +511 -1215
  3. package/WAProto/index.js +131318 -59331
  4. package/lib/Defaults/index.js +92 -76
  5. package/lib/Signal/Group/ciphertext-message.js +5 -2
  6. package/lib/Signal/Group/group-session-builder.js +41 -7
  7. package/lib/Signal/Group/group_cipher.js +51 -37
  8. package/lib/Signal/Group/index.js +57 -12
  9. package/lib/Signal/Group/keyhelper.js +44 -7
  10. package/lib/Signal/Group/sender-chain-key.js +15 -7
  11. package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
  12. package/lib/Signal/Group/sender-key-message.js +12 -9
  13. package/lib/Signal/Group/sender-key-name.js +5 -2
  14. package/lib/Signal/Group/sender-key-record.js +21 -9
  15. package/lib/Signal/Group/sender-key-state.js +42 -27
  16. package/lib/Signal/Group/sender-message-key.js +7 -4
  17. package/lib/Signal/libsignal.js +90 -347
  18. package/lib/Socket/Client/index.js +18 -3
  19. package/lib/Socket/Client/types.js +6 -4
  20. package/lib/Socket/Client/websocket.js +78 -21
  21. package/lib/Socket/business.js +43 -162
  22. package/lib/Socket/chats.js +249 -571
  23. package/lib/Socket/groups.js +99 -114
  24. package/lib/Socket/index.js +9 -11
  25. package/lib/Socket/messages-recv.js +559 -1277
  26. package/lib/Socket/messages-send.js +669 -674
  27. package/lib/Socket/newsletter.js +286 -149
  28. package/lib/Socket/socket.js +235 -548
  29. package/lib/Types/Auth.js +2 -2
  30. package/lib/Types/Call.js +2 -2
  31. package/lib/Types/Chat.js +4 -8
  32. package/lib/Types/Contact.js +2 -2
  33. package/lib/Types/Events.js +2 -2
  34. package/lib/Types/GroupMetadata.js +2 -2
  35. package/lib/Types/Label.js +5 -3
  36. package/lib/Types/LabelAssociation.js +5 -3
  37. package/lib/Types/Message.js +7 -11
  38. package/lib/Types/Product.js +2 -2
  39. package/lib/Types/Signal.js +2 -2
  40. package/lib/Types/Socket.js +2 -3
  41. package/lib/Types/State.js +2 -56
  42. package/lib/Types/USync.js +2 -2
  43. package/lib/Types/index.js +31 -15
  44. package/lib/Utils/auth-utils.js +136 -239
  45. package/lib/Utils/business.js +69 -66
  46. package/lib/Utils/chat-utils.js +238 -380
  47. package/lib/Utils/crypto.js +127 -56
  48. package/lib/Utils/decode-wa-message.js +63 -173
  49. package/lib/Utils/event-buffer.js +70 -174
  50. package/lib/Utils/generics.js +207 -159
  51. package/lib/Utils/history.js +53 -93
  52. package/lib/Utils/index.js +33 -22
  53. package/lib/Utils/link-preview.js +58 -17
  54. package/lib/Utils/logger.js +7 -3
  55. package/lib/Utils/lt-hash.js +46 -3
  56. package/lib/Utils/make-mutex.js +34 -24
  57. package/lib/Utils/messages-media.js +744 -483
  58. package/lib/Utils/messages.js +621 -411
  59. package/lib/Utils/noise-handler.js +99 -149
  60. package/lib/Utils/process-message.js +150 -459
  61. package/lib/Utils/signal.js +73 -112
  62. package/lib/Utils/use-multi-file-auth-state.js +27 -23
  63. package/lib/Utils/validate-connection.js +104 -74
  64. package/lib/WABinary/constants.js +11 -9
  65. package/lib/WABinary/decode.js +52 -49
  66. package/lib/WABinary/encode.js +49 -19
  67. package/lib/WABinary/generic-utils.js +43 -46
  68. package/lib/WABinary/index.js +21 -6
  69. package/lib/WABinary/jid-utils.js +45 -72
  70. package/lib/WABinary/types.js +2 -2
  71. package/lib/WAM/BinaryInfo.js +5 -2
  72. package/lib/WAM/constants.js +11958 -19461
  73. package/lib/WAM/encode.js +22 -17
  74. package/lib/WAM/index.js +19 -4
  75. package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
  76. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
  77. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +11 -8
  78. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
  79. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
  80. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
  81. package/lib/WAUSync/Protocols/index.js +20 -6
  82. package/lib/WAUSync/USyncQuery.js +35 -44
  83. package/lib/WAUSync/USyncUser.js +5 -10
  84. package/lib/WAUSync/index.js +19 -4
  85. package/lib/index.js +70 -11
  86. package/package.json +60 -100
  87. package/engine-requirements.js +0 -10
@@ -1,43 +1,41 @@
1
- import { Boom } from '@hapi/boom';
2
- import { proto } from '../../WAProto/index.js';
3
- import {} from './types.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBinaryNodeMessages = exports.reduceBinaryNodeToDictionary = exports.assertNodeErrorFree = exports.getBinaryNodeChildUInt = exports.getBinaryNodeChildString = exports.getBinaryNodeChildBuffer = exports.getBinaryNodeChild = exports.getAllBinaryNodeChildren = exports.getBinaryNodeChildren = void 0;
4
+ exports.binaryNodeToString = binaryNodeToString;
5
+ const boom_1 = require("@hapi/boom");
6
+ const WAProto_1 = require("../../WAProto");
4
7
  // some extra useful utilities
5
- const indexCache = new WeakMap();
6
- export const getBinaryNodeChildren = (node, childTag) => {
7
- if (!node || !Array.isArray(node.content))
8
- return [];
9
- let index = indexCache.get(node);
10
- // Build the index once per node
11
- if (!index) {
12
- index = new Map();
13
- for (const child of node.content) {
14
- let arr = index.get(child.tag);
15
- if (!arr)
16
- index.set(child.tag, (arr = []));
17
- arr.push(child);
18
- }
19
- indexCache.set(node, index);
8
+ const getBinaryNodeChildren = (node, childTag) => {
9
+ if (Array.isArray(node === null || node === void 0 ? void 0 : node.content)) {
10
+ return node.content.filter(item => item.tag === childTag);
20
11
  }
21
- // Return first matching child
22
- return index.get(childTag) || [];
23
- };
24
- export const getBinaryNodeChild = (node, childTag) => {
25
- return getBinaryNodeChildren(node, childTag)[0];
12
+ return [];
26
13
  };
27
- export const getAllBinaryNodeChildren = ({ content }) => {
14
+ exports.getBinaryNodeChildren = getBinaryNodeChildren;
15
+ const getAllBinaryNodeChildren = ({ content }) => {
28
16
  if (Array.isArray(content)) {
29
17
  return content;
30
18
  }
31
19
  return [];
32
20
  };
33
- export const getBinaryNodeChildBuffer = (node, childTag) => {
34
- const child = getBinaryNodeChild(node, childTag)?.content;
21
+ exports.getAllBinaryNodeChildren = getAllBinaryNodeChildren;
22
+ const getBinaryNodeChild = (node, childTag) => {
23
+ if (Array.isArray(node === null || node === void 0 ? void 0 : node.content)) {
24
+ return node === null || node === void 0 ? void 0 : node.content.find(item => item.tag === childTag);
25
+ }
26
+ };
27
+ exports.getBinaryNodeChild = getBinaryNodeChild;
28
+ const getBinaryNodeChildBuffer = (node, childTag) => {
29
+ var _a;
30
+ const child = (_a = (0, exports.getBinaryNodeChild)(node, childTag)) === null || _a === void 0 ? void 0 : _a.content;
35
31
  if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
36
32
  return child;
37
33
  }
38
34
  };
39
- export const getBinaryNodeChildString = (node, childTag) => {
40
- const child = getBinaryNodeChild(node, childTag)?.content;
35
+ exports.getBinaryNodeChildBuffer = getBinaryNodeChildBuffer;
36
+ const getBinaryNodeChildString = (node, childTag) => {
37
+ var _a;
38
+ const child = (_a = (0, exports.getBinaryNodeChild)(node, childTag)) === null || _a === void 0 ? void 0 : _a.content;
41
39
  if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
42
40
  return Buffer.from(child).toString('utf-8');
43
41
  }
@@ -45,42 +43,42 @@ export const getBinaryNodeChildString = (node, childTag) => {
45
43
  return child;
46
44
  }
47
45
  };
48
- export const getBinaryNodeChildUInt = (node, childTag, length) => {
49
- const buff = getBinaryNodeChildBuffer(node, childTag);
46
+ exports.getBinaryNodeChildString = getBinaryNodeChildString;
47
+ const getBinaryNodeChildUInt = (node, childTag, length) => {
48
+ const buff = (0, exports.getBinaryNodeChildBuffer)(node, childTag);
50
49
  if (buff) {
51
50
  return bufferToUInt(buff, length);
52
51
  }
53
52
  };
54
- export const assertNodeErrorFree = (node) => {
55
- const errNode = getBinaryNodeChild(node, 'error');
53
+ exports.getBinaryNodeChildUInt = getBinaryNodeChildUInt;
54
+ const assertNodeErrorFree = (node) => {
55
+ const errNode = (0, exports.getBinaryNodeChild)(node, 'error');
56
56
  if (errNode) {
57
- throw new Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
57
+ throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
58
58
  }
59
59
  };
60
- export const reduceBinaryNodeToDictionary = (node, tag) => {
61
- const nodes = getBinaryNodeChildren(node, tag);
60
+ exports.assertNodeErrorFree = assertNodeErrorFree;
61
+ const reduceBinaryNodeToDictionary = (node, tag) => {
62
+ const nodes = (0, exports.getBinaryNodeChildren)(node, tag);
62
63
  const dict = nodes.reduce((dict, { attrs }) => {
63
- if (typeof attrs.name === 'string') {
64
- dict[attrs.name] = attrs.value || attrs.config_value;
65
- }
66
- else {
67
- dict[attrs.config_code] = attrs.value || attrs.config_value;
68
- }
64
+ dict[attrs.name || attrs.config_code] = attrs.value || attrs.config_value;
69
65
  return dict;
70
66
  }, {});
71
67
  return dict;
72
68
  };
73
- export const getBinaryNodeMessages = ({ content }) => {
69
+ exports.reduceBinaryNodeToDictionary = reduceBinaryNodeToDictionary;
70
+ const getBinaryNodeMessages = ({ content }) => {
74
71
  const msgs = [];
75
72
  if (Array.isArray(content)) {
76
73
  for (const item of content) {
77
74
  if (item.tag === 'message') {
78
- msgs.push(proto.WebMessageInfo.decode(item.content).toJSON());
75
+ msgs.push(WAProto_1.proto.WebMessageInfo.decode(item.content));
79
76
  }
80
77
  }
81
78
  }
82
79
  return msgs;
83
80
  };
81
+ exports.getBinaryNodeMessages = getBinaryNodeMessages;
84
82
  function bufferToUInt(e, t) {
85
83
  let a = 0;
86
84
  for (let i = 0; i < t; i++) {
@@ -89,7 +87,7 @@ function bufferToUInt(e, t) {
89
87
  return a;
90
88
  }
91
89
  const tabs = (n) => '\t'.repeat(n);
92
- export function binaryNodeToString(node, i = 0) {
90
+ function binaryNodeToString(node, i = 0) {
93
91
  if (!node) {
94
92
  return node;
95
93
  }
@@ -100,7 +98,7 @@ export function binaryNodeToString(node, i = 0) {
100
98
  return tabs(i) + Buffer.from(node).toString('hex');
101
99
  }
102
100
  if (Array.isArray(node)) {
103
- return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
101
+ return node.map((x) => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
104
102
  }
105
103
  const children = binaryNodeToString(node.content, i + 1);
106
104
  const tag = `<${node.tag} ${Object.entries(node.attrs || {})
@@ -110,4 +108,3 @@ export function binaryNodeToString(node, i = 0) {
110
108
  const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
111
109
  return tag + content;
112
110
  }
113
- //# sourceMappingURL=generic-utils.js.map
@@ -1,6 +1,21 @@
1
- export * from './encode.js';
2
- export * from './decode.js';
3
- export * from './generic-utils.js';
4
- export * from './jid-utils.js';
5
- export * from './types.js';
6
- //# sourceMappingURL=index.js.map
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./encode"), exports);
18
+ __exportStar(require("./decode"), exports);
19
+ __exportStar(require("./generic-utils"), exports);
20
+ __exportStar(require("./jid-utils"), exports);
21
+ __exportStar(require("./types"), exports);
@@ -1,34 +1,17 @@
1
- export const S_WHATSAPP_NET = '@s.whatsapp.net';
2
- export const OFFICIAL_BIZ_JID = '16505361212@c.us';
3
- export const SERVER_JID = 'server@c.us';
4
- export const PSA_WID = '0@c.us';
5
- export const STORIES_JID = 'status@broadcast';
6
- export const META_AI_JID = '13135550002@c.us';
7
- export var WAJIDDomains;
8
- (function (WAJIDDomains) {
9
- WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
10
- WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
11
- WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
12
- WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
13
- })(WAJIDDomains || (WAJIDDomains = {}));
14
- export const getServerFromDomainType = (initialServer, domainType) => {
15
- switch (domainType) {
16
- case WAJIDDomains.LID:
17
- return 'lid';
18
- case WAJIDDomains.HOSTED:
19
- return 'hosted';
20
- case WAJIDDomains.HOSTED_LID:
21
- return 'hosted.lid';
22
- case WAJIDDomains.WHATSAPP:
23
- default:
24
- return initialServer;
25
- }
26
- };
27
- export const jidEncode = (user, server, device, agent) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBotJid = 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.META_AI_JID = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
+ exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
+ exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
+ exports.SERVER_JID = 'server@c.us';
7
+ exports.PSA_WID = '0@c.us';
8
+ exports.STORIES_JID = 'status@broadcast';
9
+ exports.META_AI_JID = '13135550002@c.us';
10
+ const jidEncode = (user, server, device, agent) => {
28
11
  return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
29
12
  };
30
- export const jidDecode = (jid) => {
31
- // todo: investigate how to implement hosted ids in this case
13
+ exports.jidEncode = jidEncode;
14
+ const jidDecode = (jid) => {
32
15
  const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
33
16
  if (sepIdx < 0) {
34
17
  return undefined;
@@ -36,61 +19,51 @@ export const jidDecode = (jid) => {
36
19
  const server = jid.slice(sepIdx + 1);
37
20
  const userCombined = jid.slice(0, sepIdx);
38
21
  const [userAgent, device] = userCombined.split(':');
39
- const [user, agent] = userAgent.split('_');
40
- let domainType = WAJIDDomains.WHATSAPP;
41
- if (server === 'lid') {
42
- domainType = WAJIDDomains.LID;
43
- }
44
- else if (server === 'hosted') {
45
- domainType = WAJIDDomains.HOSTED;
46
- }
47
- else if (server === 'hosted.lid') {
48
- domainType = WAJIDDomains.HOSTED_LID;
49
- }
50
- else if (agent) {
51
- domainType = parseInt(agent);
52
- }
22
+ const user = userAgent.split('_')[0];
53
23
  return {
54
24
  server: server,
55
- user: user,
56
- domainType,
25
+ user,
26
+ domainType: server === 'lid' ? 1 : 0,
57
27
  device: device ? +device : undefined
58
28
  };
59
29
  };
30
+ exports.jidDecode = jidDecode;
60
31
  /** is the jid a user */
61
- export const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user;
62
- /** is the jid Meta AI */
63
- export const isJidMetaAI = (jid) => jid?.endsWith('@bot');
64
- /** is the jid a PN user */
65
- export const isPnUser = (jid) => jid?.endsWith('@s.whatsapp.net');
66
- /** is the jid a LID */
67
- export const isLidUser = (jid) => jid?.endsWith('@lid');
32
+ const areJidsSameUser = (jid1, jid2) => {
33
+ var _a, _b;
34
+ 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));
35
+ };
36
+ exports.areJidsSameUser = areJidsSameUser;
37
+ /** is the jid Meta IA */
38
+ const isJidMetaAi = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@bot'));
39
+ exports.isJidMetaAi = isJidMetaAi;
40
+ /** is the jid a user */
41
+ const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
42
+ exports.isJidUser = isJidUser;
43
+ /** is the jid a group */
44
+ const isLidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@lid'));
45
+ exports.isLidUser = isLidUser;
68
46
  /** is the jid a broadcast */
69
- export const isJidBroadcast = (jid) => jid?.endsWith('@broadcast');
47
+ const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));
48
+ exports.isJidBroadcast = isJidBroadcast;
49
+ /** is the jid a newsletter */
50
+ const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
51
+ exports.isJidNewsletter = isJidNewsletter;
70
52
  /** is the jid a group */
71
- export const isJidGroup = (jid) => jid?.endsWith('@g.us');
53
+ const isJidGroup = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@g.us'));
54
+ exports.isJidGroup = isJidGroup;
72
55
  /** is the jid the status broadcast */
73
- export const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
74
- /** is the jid a newsletter */
75
- export const isJidNewsletter = (jid) => jid?.endsWith('@newsletter');
76
- /** is the jid a hosted PN */
77
- export const isHostedPnUser = (jid) => jid?.endsWith('@hosted');
78
- /** is the jid a hosted LID */
79
- export const isHostedLidUser = (jid) => jid?.endsWith('@hosted.lid');
56
+ const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
57
+ exports.isJidStatusBroadcast = isJidStatusBroadcast;
80
58
  const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
81
- export const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
82
- export const jidNormalizedUser = (jid) => {
83
- const result = jidDecode(jid);
59
+ const isJidBot = (jid) => (jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us'));
60
+ exports.isJidBot = isJidBot;
61
+ const jidNormalizedUser = (jid) => {
62
+ const result = (0, exports.jidDecode)(jid);
84
63
  if (!result) {
85
64
  return '';
86
65
  }
87
66
  const { user, server } = result;
88
- return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server);
89
- };
90
- export const transferDevice = (fromJid, toJid) => {
91
- const fromDecoded = jidDecode(fromJid);
92
- const deviceId = fromDecoded?.device || 0;
93
- const { server, user } = jidDecode(toJid);
94
- return jidEncode(user, server, deviceId);
67
+ return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
95
68
  };
96
- //# sourceMappingURL=jid-utils.js.map
69
+ exports.jidNormalizedUser = jidNormalizedUser;
@@ -1,2 +1,2 @@
1
- import * as constants from './constants.js';
2
- //# sourceMappingURL=types.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,7 @@
1
- export class BinaryInfo {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BinaryInfo = void 0;
4
+ class BinaryInfo {
2
5
  constructor(options = {}) {
3
6
  this.protocolVersion = 5;
4
7
  this.sequence = 0;
@@ -7,4 +10,4 @@ export class BinaryInfo {
7
10
  Object.assign(this, options);
8
11
  }
9
12
  }
10
- //# sourceMappingURL=BinaryInfo.js.map
13
+ exports.BinaryInfo = BinaryInfo;