@baileys-md/baileys 11.0.3 → 11.1.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 (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/WAProto/index.js +4182 -13516
  4. package/WASignalGroup/GroupProtocol.js +1697 -0
  5. package/WASignalGroup/ciphertext_message.js +16 -0
  6. package/WASignalGroup/group_cipher.js +120 -0
  7. package/WASignalGroup/group_session_builder.js +46 -0
  8. package/WASignalGroup/index.js +5 -0
  9. package/WASignalGroup/keyhelper.js +21 -0
  10. package/WASignalGroup/protobufs.js +3 -0
  11. package/WASignalGroup/queue_job.js +69 -0
  12. package/WASignalGroup/sender_chain_key.js +50 -0
  13. package/WASignalGroup/sender_key_distribution_message.js +78 -0
  14. package/WASignalGroup/sender_key_message.js +92 -0
  15. package/WASignalGroup/sender_key_name.js +70 -0
  16. package/WASignalGroup/sender_key_record.js +56 -0
  17. package/WASignalGroup/sender_key_state.js +129 -0
  18. package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -4
  19. package/lib/Defaults/baileys-version.json +3 -0
  20. package/lib/Defaults/index.js +71 -52
  21. package/lib/Defaults/{phonenumber-mcc.js → phonenumber-mcc.json} +1 -1
  22. package/lib/Signal/libsignal.js +61 -41
  23. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  24. package/lib/Socket/Client/index.js +19 -3
  25. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  26. package/lib/Socket/Client/web-socket-client.js +62 -0
  27. package/lib/Socket/business.js +42 -37
  28. package/lib/Socket/chats.js +187 -194
  29. package/lib/Socket/groups.js +90 -87
  30. package/lib/Socket/index.js +8 -7
  31. package/lib/Socket/messages-recv.js +335 -360
  32. package/lib/Socket/messages-send.js +279 -156
  33. package/lib/Socket/newsletter.js +213 -144
  34. package/lib/Socket/registration.js +166 -0
  35. package/lib/Socket/socket.js +161 -128
  36. package/lib/Socket/usync.js +26 -19
  37. package/lib/Store/index.js +8 -0
  38. package/lib/Store/make-cache-manager-store.js +83 -0
  39. package/lib/{Utils → Store}/make-in-memory-store.js +27 -19
  40. package/lib/Store/make-mongo-store.js +567 -0
  41. package/lib/{Utils → Store}/make-ordered-dictionary.js +5 -2
  42. package/lib/{Utils → Store}/object-repository.js +4 -1
  43. package/lib/Types/Auth.js +2 -2
  44. package/lib/Types/Call.js +2 -2
  45. package/lib/Types/Chat.js +4 -8
  46. package/lib/Types/Contact.js +2 -2
  47. package/lib/Types/Events.js +2 -2
  48. package/lib/Types/GroupMetadata.js +2 -2
  49. package/lib/Types/Label.js +5 -3
  50. package/lib/Types/LabelAssociation.js +5 -3
  51. package/lib/Types/Message.js +7 -7
  52. package/lib/Types/Newsletter.js +17 -30
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.js +2 -2
  55. package/lib/Types/Socket.js +2 -3
  56. package/lib/Types/State.js +2 -2
  57. package/lib/Types/USync.js +2 -2
  58. package/lib/Types/index.js +31 -15
  59. package/lib/Utils/auth-utils.js +47 -31
  60. package/lib/Utils/baileys-event-stream.js +22 -15
  61. package/lib/Utils/business.js +69 -66
  62. package/lib/Utils/chat-utils.js +195 -200
  63. package/lib/Utils/crypto.js +85 -70
  64. package/lib/Utils/decode-wa-message.js +51 -46
  65. package/lib/Utils/event-buffer.js +46 -36
  66. package/lib/Utils/generics.js +188 -116
  67. package/lib/Utils/history.js +46 -37
  68. package/lib/Utils/index.js +33 -19
  69. package/lib/Utils/link-preview.js +55 -14
  70. package/lib/Utils/logger.js +7 -3
  71. package/lib/Utils/lt-hash.js +26 -23
  72. package/lib/Utils/make-mutex.js +10 -7
  73. package/lib/Utils/messages-media.js +368 -239
  74. package/lib/Utils/messages.js +510 -278
  75. package/lib/Utils/noise-handler.js +31 -22
  76. package/lib/Utils/process-message.js +148 -144
  77. package/lib/Utils/signal.js +64 -71
  78. package/lib/Utils/use-multi-file-auth-state.js +32 -14
  79. package/lib/Utils/validate-connection.js +115 -72
  80. package/lib/WABinary/constants.js +20 -1281
  81. package/lib/WABinary/decode.js +52 -15
  82. package/lib/WABinary/encode.js +48 -14
  83. package/lib/WABinary/generic-utils.js +39 -31
  84. package/lib/WABinary/index.js +21 -6
  85. package/lib/WABinary/jid-utils.js +40 -23
  86. package/lib/WABinary/types.js +2 -2
  87. package/lib/WAM/BinaryInfo.js +5 -2
  88. package/lib/WAM/constants.js +2366 -2257
  89. package/lib/WAM/encode.js +21 -17
  90. package/lib/WAM/index.js +19 -4
  91. package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
  92. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
  93. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
  94. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
  95. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
  96. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -3
  97. package/lib/WAUSync/Protocols/index.js +20 -5
  98. package/lib/WAUSync/USyncQuery.js +32 -34
  99. package/lib/WAUSync/USyncUser.js +5 -2
  100. package/lib/WAUSync/index.js +19 -4
  101. package/lib/index.js +33 -11
  102. package/package.json +61 -21
  103. package/WAProto/GenerateStatics.sh +0 -3
  104. package/WAProto/WAProto.proto +0 -4633
  105. package/WAProto/fix-imports.js +0 -29
  106. package/lib/Defaults/baileys-version.js +0 -1
  107. package/lib/Signal/Group/ciphertext-message.js +0 -12
  108. package/lib/Signal/Group/group-session-builder.js +0 -30
  109. package/lib/Signal/Group/group_cipher.js +0 -94
  110. package/lib/Signal/Group/index.js +0 -12
  111. package/lib/Signal/Group/keyhelper.js +0 -19
  112. package/lib/Signal/Group/queue-job.js +0 -54
  113. package/lib/Signal/Group/sender-chain-key.js +0 -32
  114. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  115. package/lib/Signal/Group/sender-key-message.js +0 -67
  116. package/lib/Signal/Group/sender-key-name.js +0 -48
  117. package/lib/Signal/Group/sender-key-record.js +0 -50
  118. package/lib/Signal/Group/sender-key-state.js +0 -96
  119. package/lib/Socket/Client/types.js +0 -11
  120. package/lib/Socket/Client/websocket.js +0 -50
  121. package/lib/Socket/communities.js +0 -351
  122. package/lib/Socket/mex.js +0 -42
@@ -1,19 +1,55 @@
1
- import { promisify } from 'util';
2
- import { inflate } from 'zlib';
3
- import * as constants from './constants.js';
4
- import { jidEncode } from './jid-utils.js';
5
- const inflatePromise = promisify(inflate);
6
- export const decompressingIfRequired = async (buffer) => {
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
37
+ const util_1 = require("util");
38
+ const zlib_1 = require("zlib");
39
+ const constants = __importStar(require("./constants"));
40
+ const jid_utils_1 = require("./jid-utils");
41
+ const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
42
+ const decompressingIfRequired = async (buffer) => {
7
43
  if (2 & buffer.readUInt8()) {
8
44
  buffer = await inflatePromise(buffer.slice(1));
9
45
  }
10
- else {
11
- // nodes with no compression have a 0x00 prefix, we remove that
46
+ else { // nodes with no compression have a 0x00 prefix, we remove that
12
47
  buffer = buffer.slice(1);
13
48
  }
14
49
  return buffer;
15
50
  };
16
- export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
51
+ exports.decompressingIfRequired = decompressingIfRequired;
52
+ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
17
53
  const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts;
18
54
  const checkEOS = (length) => {
19
55
  if (indexRef.index + length > buffer.length) {
@@ -124,7 +160,7 @@ export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0
124
160
  const domainType = Number(rawDomainType);
125
161
  const device = readByte();
126
162
  const user = readString(readByte());
127
- return jidEncode(user, domainType === 0 || domainType === 128 ? 's.whatsapp.net' : 'lid', device);
163
+ return (0, jid_utils_1.jidEncode)(user, domainType === 0 || domainType === 128 ? 's.whatsapp.net' : 'lid', device);
128
164
  };
129
165
  const readString = (tag) => {
130
166
  if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
@@ -159,7 +195,7 @@ export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0
159
195
  const items = [];
160
196
  const size = readListSize(tag);
161
197
  for (let i = 0; i < size; i++) {
162
- items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef));
198
+ items.push((0, exports.decodeDecompressedBinaryNode)(buffer, opts, indexRef));
163
199
  }
164
200
  return items;
165
201
  };
@@ -221,8 +257,9 @@ export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0
221
257
  content: data
222
258
  };
223
259
  };
224
- export const decodeBinaryNode = async (buff) => {
225
- const decompBuff = await decompressingIfRequired(buff);
226
- return decodeDecompressedBinaryNode(decompBuff, constants);
260
+ exports.decodeDecompressedBinaryNode = decodeDecompressedBinaryNode;
261
+ const decodeBinaryNode = async (buff) => {
262
+ const decompBuff = await (0, exports.decompressingIfRequired)(buff);
263
+ return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
227
264
  };
228
- //# sourceMappingURL=decode.js.map
265
+ exports.decodeBinaryNode = decodeBinaryNode;
@@ -1,9 +1,46 @@
1
- import * as constants from './constants.js';
2
- import { jidDecode } from './jid-utils.js';
3
- export const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.encodeBinaryNode = void 0;
37
+ const constants = __importStar(require("./constants"));
38
+ const jid_utils_1 = require("./jid-utils");
39
+ const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
4
40
  const encoded = encodeBinaryNodeInner(node, opts, buffer);
5
41
  return Buffer.from(encoded);
6
42
  };
43
+ exports.encodeBinaryNode = encodeBinaryNode;
7
44
  const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
8
45
  const { TAGS, TOKEN_MAP } = opts;
9
46
  const pushByte = (value) => buffer.push(value & 0xff);
@@ -13,15 +50,11 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
13
50
  buffer.push((value >> (curShift * 8)) & 0xff);
14
51
  }
15
52
  };
16
- const pushBytes = (bytes) => {
17
- for (const b of bytes) {
18
- buffer.push(b);
19
- }
20
- };
53
+ const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
21
54
  const pushInt16 = (value) => {
22
55
  pushBytes([(value >> 8) & 0xff, value & 0xff]);
23
56
  };
24
- const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
57
+ const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]));
25
58
  const writeByteLength = (length) => {
26
59
  if (length >= 4294967296) {
27
60
  throw new Error('string too large to encode: ' + length);
@@ -119,7 +152,8 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
119
152
  if (!str || str.length > TAGS.PACKED_MAX) {
120
153
  return false;
121
154
  }
122
- for (const char of str) {
155
+ for (let i = 0; i < str.length; i++) {
156
+ const char = str[i];
123
157
  const isInNibbleRange = char >= '0' && char <= '9';
124
158
  if (!isInNibbleRange && char !== '-' && char !== '.') {
125
159
  return false;
@@ -131,7 +165,8 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
131
165
  if (!str || str.length > TAGS.PACKED_MAX) {
132
166
  return false;
133
167
  }
134
- for (const char of str) {
168
+ for (let i = 0; i < str.length; i++) {
169
+ const char = str[i];
135
170
  const isInNibbleRange = char >= '0' && char <= '9';
136
171
  if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
137
172
  return false;
@@ -158,7 +193,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
158
193
  writePackedBytes(str, 'hex');
159
194
  }
160
195
  else if (str) {
161
- const decodedJid = jidDecode(str);
196
+ const decodedJid = (0, jid_utils_1.jidDecode)(str);
162
197
  if (decodedJid) {
163
198
  writeJid(decodedJid);
164
199
  }
@@ -182,7 +217,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
182
217
  if (!tag) {
183
218
  throw new Error('Invalid node: tag cannot be undefined');
184
219
  }
185
- const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
220
+ const validAttributes = Object.keys(attrs || {}).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
186
221
  writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
187
222
  writeString(tag);
188
223
  for (const key of validAttributes) {
@@ -213,4 +248,3 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
213
248
  }
214
249
  return buffer;
215
250
  };
216
- //# sourceMappingURL=encode.js.map
@@ -1,32 +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
- export const getBinaryNodeChildren = (node, childTag) => {
6
- if (Array.isArray(node?.content)) {
8
+ const getBinaryNodeChildren = (node, childTag) => {
9
+ if (Array.isArray(node === null || node === void 0 ? void 0 : node.content)) {
7
10
  return node.content.filter(item => item.tag === childTag);
8
11
  }
9
12
  return [];
10
13
  };
11
- export const getAllBinaryNodeChildren = ({ content }) => {
14
+ exports.getBinaryNodeChildren = getBinaryNodeChildren;
15
+ const getAllBinaryNodeChildren = ({ content }) => {
12
16
  if (Array.isArray(content)) {
13
17
  return content;
14
18
  }
15
19
  return [];
16
20
  };
17
- export const getBinaryNodeChild = (node, childTag) => {
18
- if (Array.isArray(node?.content)) {
19
- return node?.content.find(item => item.tag === childTag);
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);
20
25
  }
21
26
  };
22
- export const getBinaryNodeChildBuffer = (node, childTag) => {
23
- const child = getBinaryNodeChild(node, childTag)?.content;
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;
24
31
  if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
25
32
  return child;
26
33
  }
27
34
  };
28
- export const getBinaryNodeChildString = (node, childTag) => {
29
- 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;
30
39
  if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
31
40
  return Buffer.from(child).toString('utf-8');
32
41
  }
@@ -34,42 +43,42 @@ export const getBinaryNodeChildString = (node, childTag) => {
34
43
  return child;
35
44
  }
36
45
  };
37
- export const getBinaryNodeChildUInt = (node, childTag, length) => {
38
- const buff = getBinaryNodeChildBuffer(node, childTag);
46
+ exports.getBinaryNodeChildString = getBinaryNodeChildString;
47
+ const getBinaryNodeChildUInt = (node, childTag, length) => {
48
+ const buff = (0, exports.getBinaryNodeChildBuffer)(node, childTag);
39
49
  if (buff) {
40
50
  return bufferToUInt(buff, length);
41
51
  }
42
52
  };
43
- export const assertNodeErrorFree = (node) => {
44
- const errNode = getBinaryNodeChild(node, 'error');
53
+ exports.getBinaryNodeChildUInt = getBinaryNodeChildUInt;
54
+ const assertNodeErrorFree = (node) => {
55
+ const errNode = (0, exports.getBinaryNodeChild)(node, 'error');
45
56
  if (errNode) {
46
- 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 });
47
58
  }
48
59
  };
49
- export const reduceBinaryNodeToDictionary = (node, tag) => {
50
- const nodes = getBinaryNodeChildren(node, tag);
60
+ exports.assertNodeErrorFree = assertNodeErrorFree;
61
+ const reduceBinaryNodeToDictionary = (node, tag) => {
62
+ const nodes = (0, exports.getBinaryNodeChildren)(node, tag);
51
63
  const dict = nodes.reduce((dict, { attrs }) => {
52
- if (typeof attrs.name === 'string') {
53
- dict[attrs.name] = attrs.value || attrs.config_value;
54
- }
55
- else {
56
- dict[attrs.config_code] = attrs.value || attrs.config_value;
57
- }
64
+ dict[attrs.name || attrs.config_code] = attrs.value || attrs.config_value;
58
65
  return dict;
59
66
  }, {});
60
67
  return dict;
61
68
  };
62
- export const getBinaryNodeMessages = ({ content }) => {
69
+ exports.reduceBinaryNodeToDictionary = reduceBinaryNodeToDictionary;
70
+ const getBinaryNodeMessages = ({ content }) => {
63
71
  const msgs = [];
64
72
  if (Array.isArray(content)) {
65
73
  for (const item of content) {
66
74
  if (item.tag === 'message') {
67
- msgs.push(proto.WebMessageInfo.decode(item.content));
75
+ msgs.push(WAProto_1.proto.WebMessageInfo.decode(item.content));
68
76
  }
69
77
  }
70
78
  }
71
79
  return msgs;
72
80
  };
81
+ exports.getBinaryNodeMessages = getBinaryNodeMessages;
73
82
  function bufferToUInt(e, t) {
74
83
  let a = 0;
75
84
  for (let i = 0; i < t; i++) {
@@ -78,7 +87,7 @@ function bufferToUInt(e, t) {
78
87
  return a;
79
88
  }
80
89
  const tabs = (n) => '\t'.repeat(n);
81
- export function binaryNodeToString(node, i = 0) {
90
+ function binaryNodeToString(node, i = 0) {
82
91
  if (!node) {
83
92
  return node;
84
93
  }
@@ -89,7 +98,7 @@ export function binaryNodeToString(node, i = 0) {
89
98
  return tabs(i) + Buffer.from(node).toString('hex');
90
99
  }
91
100
  if (Array.isArray(node)) {
92
- 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');
93
102
  }
94
103
  const children = binaryNodeToString(node.content, i + 1);
95
104
  const tag = `<${node.tag} ${Object.entries(node.attrs || {})
@@ -99,4 +108,3 @@ export function binaryNodeToString(node, i = 0) {
99
108
  const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
100
109
  return tag + content;
101
110
  }
102
- //# 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,13 +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 const jidEncode = (user, server, device, agent) => {
1
+ "use strict";
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.isJidMetaIa = 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) => {
8
11
  return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`;
9
12
  };
10
- export const jidDecode = (jid) => {
13
+ exports.jidEncode = jidEncode;
14
+ const jidDecode = (jid) => {
11
15
  const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1;
12
16
  if (sepIdx < 0) {
13
17
  return undefined;
@@ -17,36 +21,49 @@ export const jidDecode = (jid) => {
17
21
  const [userAgent, device] = userCombined.split(':');
18
22
  const user = userAgent.split('_')[0];
19
23
  return {
20
- server: server,
24
+ server,
21
25
  user,
22
26
  domainType: server === 'lid' ? 1 : 0,
23
27
  device: device ? +device : undefined
24
28
  };
25
29
  };
30
+ exports.jidDecode = jidDecode;
26
31
  /** is the jid a user */
27
- export const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user;
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;
28
37
  /** is the jid Meta IA */
29
- export const isJidMetaIa = (jid) => jid?.endsWith('@bot');
38
+ const isJidMetaIa = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@bot'));
39
+ exports.isJidMetaIa = isJidMetaIa;
30
40
  /** is the jid a user */
31
- export const isJidUser = (jid) => jid?.endsWith('@s.whatsapp.net');
41
+ const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
42
+ exports.isJidUser = isJidUser;
32
43
  /** is the jid a group */
33
- export const isLidUser = (jid) => jid?.endsWith('@lid');
44
+ const isLidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@lid'));
45
+ exports.isLidUser = isLidUser;
34
46
  /** is the jid a broadcast */
35
- 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;
36
52
  /** is the jid a group */
37
- 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;
38
55
  /** is the jid the status broadcast */
39
- export const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
40
- /** is the jid a newsletter */
41
- export const isJidNewsletter = (jid) => jid?.endsWith('@newsletter');
56
+ const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
57
+ exports.isJidStatusBroadcast = isJidStatusBroadcast;
42
58
  const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
43
- export const isJidBot = (jid) => jid && botRegexp.test(jid.split('@')[0]) && jid.endsWith('@c.us');
44
- export const jidNormalizedUser = (jid) => {
45
- 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);
46
63
  if (!result) {
47
64
  return '';
48
65
  }
49
66
  const { user, server } = result;
50
- return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server);
67
+ return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
51
68
  };
52
- //# 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;