@hbmodsofc/baileys 1.7.8 → 2.2.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 (155) hide show
  1. package/LICENSE +1 -1
  2. package/lib/Defaults/baileys-version.json +3 -0
  3. package/lib/Defaults/index.d.ts +8 -12
  4. package/lib/Defaults/index.js +124 -90
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/group_cipher.d.ts +1 -0
  7. package/lib/Signal/Group/group_cipher.js +39 -28
  8. package/lib/Signal/Group/queue-job.d.ts +1 -0
  9. package/lib/Signal/Group/queue-job.js +57 -0
  10. package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
  11. package/lib/Signal/Group/sender-chain-key.js +2 -9
  12. package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
  13. package/lib/Signal/Group/sender-key-message.js +3 -3
  14. package/lib/Signal/Group/sender-key-state.d.ts +4 -4
  15. package/lib/Signal/Group/sender-key-state.js +16 -47
  16. package/lib/Signal/libsignal.d.ts +3 -7
  17. package/lib/Signal/libsignal.js +39 -224
  18. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -1
  19. package/lib/Socket/Client/index.d.ts +3 -2
  20. package/lib/Socket/Client/index.js +3 -2
  21. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  22. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  23. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  24. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +16 -10
  25. package/lib/Socket/business.d.ts +78 -94
  26. package/lib/Socket/business.js +11 -130
  27. package/lib/Socket/chats.d.ts +233 -63
  28. package/lib/Socket/chats.js +184 -234
  29. package/lib/Socket/groups.d.ts +41 -62
  30. package/lib/Socket/groups.js +64 -76
  31. package/lib/Socket/hbmods.d.ts +253 -0
  32. package/lib/Socket/hbmods.js +1 -0
  33. package/lib/Socket/index.d.ts +83 -129
  34. package/lib/Socket/index.js +6 -13
  35. package/lib/Socket/messages-recv.d.ts +48 -59
  36. package/lib/Socket/messages-recv.js +371 -516
  37. package/lib/Socket/messages-send.d.ts +67 -86
  38. package/lib/Socket/messages-send.js +1 -1091
  39. package/lib/Socket/newsletter.d.ts +64 -76
  40. package/lib/Socket/newsletter.js +1 -184
  41. package/lib/Socket/registration.d.ts +267 -0
  42. package/lib/Socket/registration.js +166 -0
  43. package/lib/Socket/socket.d.ts +13 -19
  44. package/lib/Socket/socket.js +1 -805
  45. package/lib/Socket/usync.d.ts +36 -0
  46. package/lib/Socket/usync.js +70 -0
  47. package/lib/Types/Auth.d.ts +10 -4
  48. package/lib/Types/Call.d.ts +1 -1
  49. package/lib/Types/Chat.d.ts +9 -29
  50. package/lib/Types/Chat.js +1 -7
  51. package/lib/Types/Contact.d.ts +1 -5
  52. package/lib/Types/Events.d.ts +14 -55
  53. package/lib/Types/GroupMetadata.d.ts +5 -15
  54. package/lib/Types/Label.d.ts +0 -11
  55. package/lib/Types/Label.js +1 -1
  56. package/lib/Types/LabelAssociation.js +1 -1
  57. package/lib/Types/Message.d.ts +49 -75
  58. package/lib/Types/Message.js +7 -10
  59. package/lib/Types/Newsletter.d.ts +98 -129
  60. package/lib/Types/Newsletter.js +38 -33
  61. package/lib/Types/Product.d.ts +1 -1
  62. package/lib/Types/Signal.d.ts +1 -29
  63. package/lib/Types/Socket.d.ts +22 -48
  64. package/lib/Types/State.d.ts +2 -13
  65. package/lib/Types/State.js +0 -12
  66. package/lib/Types/USync.d.ts +1 -1
  67. package/lib/Types/index.d.ts +3 -10
  68. package/lib/Types/index.js +2 -2
  69. package/lib/Utils/auth-utils.d.ts +3 -3
  70. package/lib/Utils/auth-utils.js +102 -378
  71. package/lib/Utils/baileys-event-stream.js +1 -1
  72. package/lib/Utils/business.d.ts +2 -2
  73. package/lib/Utils/business.js +13 -19
  74. package/lib/Utils/chat-utils.d.ts +22 -21
  75. package/lib/Utils/chat-utils.js +154 -201
  76. package/lib/Utils/crypto.d.ts +19 -18
  77. package/lib/Utils/crypto.js +37 -78
  78. package/lib/Utils/decode-wa-message.d.ts +7 -34
  79. package/lib/Utils/decode-wa-message.js +66 -138
  80. package/lib/Utils/event-buffer.d.ts +8 -6
  81. package/lib/Utils/event-buffer.js +43 -81
  82. package/lib/Utils/generics.d.ts +27 -27
  83. package/lib/Utils/generics.js +133 -128
  84. package/lib/Utils/history.d.ts +5 -9
  85. package/lib/Utils/history.js +23 -17
  86. package/lib/Utils/index.d.ts +0 -2
  87. package/lib/Utils/index.js +0 -2
  88. package/lib/Utils/link-preview.d.ts +4 -4
  89. package/lib/Utils/link-preview.js +12 -40
  90. package/lib/Utils/logger.d.ts +3 -11
  91. package/lib/Utils/lt-hash.d.ts +8 -8
  92. package/lib/Utils/lt-hash.js +24 -23
  93. package/lib/Utils/make-mutex.d.ts +2 -2
  94. package/lib/Utils/make-mutex.js +2 -3
  95. package/lib/Utils/messages-media.d.ts +41 -37
  96. package/lib/Utils/messages-media.js +368 -252
  97. package/lib/Utils/messages.d.ts +15 -13
  98. package/lib/Utils/messages.js +261 -274
  99. package/lib/Utils/noise-handler.d.ts +15 -13
  100. package/lib/Utils/noise-handler.js +26 -20
  101. package/lib/Utils/process-message.d.ts +8 -9
  102. package/lib/Utils/process-message.js +93 -157
  103. package/lib/Utils/signal.d.ts +5 -6
  104. package/lib/Utils/signal.js +29 -37
  105. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  106. package/lib/Utils/use-multi-file-auth-state.js +7 -12
  107. package/lib/Utils/validate-connection.d.ts +6 -5
  108. package/lib/Utils/validate-connection.js +97 -39
  109. package/lib/WABinary/constants.d.ts +27 -24
  110. package/lib/WABinary/constants.js +13 -1276
  111. package/lib/WABinary/decode.d.ts +4 -3
  112. package/lib/WABinary/decode.js +14 -28
  113. package/lib/WABinary/encode.d.ts +2 -1
  114. package/lib/WABinary/encode.js +147 -134
  115. package/lib/WABinary/generic-utils.d.ts +7 -4
  116. package/lib/WABinary/generic-utils.js +125 -40
  117. package/lib/WABinary/jid-utils.d.ts +8 -13
  118. package/lib/WABinary/jid-utils.js +16 -27
  119. package/lib/WAM/BinaryInfo.d.ts +11 -2
  120. package/lib/WAM/constants.d.ts +2 -3
  121. package/lib/WAM/constants.js +2359 -2252
  122. package/lib/WAM/encode.d.ts +2 -1
  123. package/lib/WAM/encode.js +11 -8
  124. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.js +4 -3
  126. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
  127. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
  128. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
  129. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
  130. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
  131. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +6 -5
  132. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
  133. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  134. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -4
  135. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -11
  136. package/lib/WAUSync/USyncQuery.d.ts +2 -2
  137. package/lib/WAUSync/USyncQuery.js +15 -19
  138. package/lib/WAUSync/USyncUser.d.ts +5 -5
  139. package/lib/WAUSync/index.d.ts +1 -1
  140. package/lib/WAUSync/index.js +1 -1
  141. package/package.json +102 -104
  142. package/WAProto/index.js +0 -37306
  143. package/lib/Signal/lid-mapping.d.ts +0 -26
  144. package/lib/Signal/lid-mapping.js +0 -146
  145. package/lib/Socket/communities.d.ts +0 -232
  146. package/lib/Socket/communities.js +0 -402
  147. package/lib/Socket/mex.d.ts +0 -2
  148. package/lib/Socket/mex.js +0 -45
  149. package/lib/Types/Bussines.d.ts +0 -24
  150. package/lib/Types/Bussines.js +0 -2
  151. package/lib/Utils/lidToJid-test.d.ts +0 -11
  152. package/lib/Utils/lidToJid-test.js +0 -27
  153. package/lib/Utils/message-retry-manager.d.ts +0 -81
  154. package/lib/Utils/message-retry-manager.js +0 -152
  155. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -1,6 +1,7 @@
1
+ /// <reference types="node" />
1
2
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
2
- export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer<ArrayBufferLike>>;
3
- export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, "DOUBLE_BYTE_TOKENS" | "SINGLE_BYTE_TOKENS" | "TAGS">, indexRef?: {
3
+ export declare const decompressingIfRequired: (buffer: Buffer) => Buffer;
4
+ export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
4
5
  index: number;
5
6
  }) => BinaryNode;
6
- export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
7
+ export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode;
@@ -15,36 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- })();
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
35
25
  Object.defineProperty(exports, "__esModule", { value: true });
36
26
  exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
37
- const util_1 = require("util");
38
27
  const zlib_1 = require("zlib");
39
28
  const constants = __importStar(require("./constants"));
40
29
  const jid_utils_1 = require("./jid-utils");
41
- const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
42
- const decompressingIfRequired = async (buffer) => {
30
+ const decompressingIfRequired = (buffer) => {
43
31
  if (2 & buffer.readUInt8()) {
44
- buffer = await inflatePromise(buffer.slice(1));
32
+ buffer = (0, zlib_1.inflateSync)(buffer.slice(1));
45
33
  }
46
- else {
47
- // nodes with no compression have a 0x00 prefix, we remove that
34
+ else { // nodes with no compression have a 0x00 prefix, we remove that
48
35
  buffer = buffer.slice(1);
49
36
  }
50
37
  return buffer;
@@ -157,11 +144,10 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
157
144
  throw new Error('invalid jid pair: ' + i + ', ' + j);
158
145
  };
159
146
  const readAdJid = () => {
160
- const rawDomainType = readByte();
161
- const domainType = Number(rawDomainType);
147
+ const agent = readByte();
162
148
  const device = readByte();
163
149
  const user = readString(readByte());
164
- return (0, jid_utils_1.jidEncode)(user, domainType === 0 || domainType === 128 ? 's.whatsapp.net' : 'lid', device);
150
+ return (0, jid_utils_1.jidEncode)(user, agent === 0 ? 's.whatsapp.net' : 'lid', device);
165
151
  };
166
152
  const readString = (tag) => {
167
153
  if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
@@ -259,8 +245,8 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
259
245
  };
260
246
  };
261
247
  exports.decodeDecompressedBinaryNode = decodeDecompressedBinaryNode;
262
- const decodeBinaryNode = async (buff) => {
263
- const decompBuff = await (0, exports.decompressingIfRequired)(buff);
248
+ const decodeBinaryNode = (buff) => {
249
+ const decompBuff = (0, exports.decompressingIfRequired)(buff);
264
250
  return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
265
251
  };
266
252
  exports.decodeBinaryNode = decodeBinaryNode;
@@ -1,2 +1,3 @@
1
+ /// <reference types="node" />
1
2
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
2
- export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, "TAGS" | "TOKEN_MAP">, buffer?: number[]) => Buffer;
3
+ export declare const encodeBinaryNode: ({ tag, attrs, content }: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => Buffer;
@@ -1,252 +1,265 @@
1
- "use strict";
1
+ "use strict"
2
+
2
3
  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);
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
5
6
  if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
+ desc = { enumerable: true, get: function() { return m[k] } }
7
8
  }
8
- Object.defineProperty(o, k2, desc);
9
+ Object.defineProperty(o, k2, desc)
9
10
  }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
13
+ }))
14
+
13
15
  var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v })
15
17
  }) : 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");
18
+ o["default"] = v
19
+ })
20
+
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod
23
+ var result = {}
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
25
+ __setModuleDefault(result, mod)
26
+ return result
27
+ }
28
+
29
+ Object.defineProperty(exports, "__esModule", { value: true })
30
+
31
+ const constants = __importStar(require("./constants"))
32
+ const jid_utils_1 = require("./jid-utils")
33
+
39
34
  const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
40
- const encoded = encodeBinaryNodeInner(node, opts, buffer);
41
- return Buffer.from(encoded);
42
- };
43
- exports.encodeBinaryNode = encodeBinaryNode;
35
+ const encoded = encodeBinaryNodeInner(node, opts, buffer)
36
+ return Buffer.from(encoded)
37
+ }
38
+
44
39
  const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
45
- const { TAGS, TOKEN_MAP } = opts;
46
- const pushByte = (value) => buffer.push(value & 0xff);
40
+ const { TAGS, TOKEN_MAP } = opts
41
+ const pushByte = (value) => buffer.push(value & 0xff)
47
42
  const pushInt = (value, n, littleEndian = false) => {
48
43
  for (let i = 0; i < n; i++) {
49
- const curShift = littleEndian ? i : n - 1 - i;
50
- buffer.push((value >> (curShift * 8)) & 0xff);
44
+ const curShift = littleEndian ? i : n - 1 - i
45
+ buffer.push((value >> (curShift * 8)) & 0xff)
51
46
  }
52
- };
47
+ }
48
+
53
49
  const pushBytes = (bytes) => {
54
50
  for (const b of bytes) {
55
- buffer.push(b);
51
+ buffer.push(b)
56
52
  }
57
- };
53
+ }
54
+
58
55
  const pushInt16 = (value) => {
59
- pushBytes([(value >> 8) & 0xff, value & 0xff]);
60
- };
61
- const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
56
+ pushBytes([(value >> 8) & 0xff, value & 0xff])
57
+ }
58
+
59
+ const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]))
62
60
  const writeByteLength = (length) => {
63
61
  if (length >= 4294967296) {
64
- throw new Error('string too large to encode: ' + length);
62
+ throw new Error('string too large to encode: ' + length)
65
63
  }
66
64
  if (length >= 1 << 20) {
67
- pushByte(TAGS.BINARY_32);
68
- pushInt(length, 4); // 32 bit integer
65
+ pushByte(TAGS.BINARY_32)
66
+ pushInt(length, 4) // 32 bit integer
69
67
  }
70
68
  else if (length >= 256) {
71
- pushByte(TAGS.BINARY_20);
72
- pushInt20(length);
69
+ pushByte(TAGS.BINARY_20)
70
+ pushInt20(length)
73
71
  }
74
72
  else {
75
- pushByte(TAGS.BINARY_8);
76
- pushByte(length);
73
+ pushByte(TAGS.BINARY_8)
74
+ pushByte(length)
77
75
  }
78
- };
76
+ }
77
+
79
78
  const writeStringRaw = (str) => {
80
- const bytes = Buffer.from(str, 'utf-8');
81
- writeByteLength(bytes.length);
82
- pushBytes(bytes);
83
- };
79
+ const bytes = Buffer.from(str, 'utf-8')
80
+ writeByteLength(bytes.length)
81
+ pushBytes(bytes)
82
+ }
83
+
84
84
  const writeJid = ({ domainType, device, user, server }) => {
85
85
  if (typeof device !== 'undefined') {
86
- pushByte(TAGS.AD_JID);
87
- pushByte(domainType || 0);
88
- pushByte(device || 0);
89
- writeString(user);
86
+ pushByte(TAGS.AD_JID)
87
+ pushByte(domainType || 0)
88
+ pushByte(device || 0)
89
+ writeString(user)
90
90
  }
91
91
  else {
92
- pushByte(TAGS.JID_PAIR);
92
+ pushByte(TAGS.JID_PAIR)
93
93
  if (user.length) {
94
- writeString(user);
94
+ writeString(user)
95
95
  }
96
96
  else {
97
- pushByte(TAGS.LIST_EMPTY);
97
+ pushByte(TAGS.LIST_EMPTY)
98
98
  }
99
- writeString(server);
99
+ writeString(server)
100
100
  }
101
- };
101
+ }
102
+
102
103
  const packNibble = (char) => {
103
104
  switch (char) {
104
105
  case '-':
105
- return 10;
106
+ return 10
106
107
  case '.':
107
- return 11;
108
+ return 11
108
109
  case '\0':
109
- return 15;
110
+ return 15
110
111
  default:
111
112
  if (char >= '0' && char <= '9') {
112
- return char.charCodeAt(0) - '0'.charCodeAt(0);
113
+ return char.charCodeAt(0) - '0'.charCodeAt(0)
113
114
  }
114
- throw new Error(`invalid byte for nibble "${char}"`);
115
+ throw new Error(`invalid byte for nibble "${char}"`)
115
116
  }
116
- };
117
+ }
118
+
117
119
  const packHex = (char) => {
118
120
  if (char >= '0' && char <= '9') {
119
- return char.charCodeAt(0) - '0'.charCodeAt(0);
121
+ return char.charCodeAt(0) - '0'.charCodeAt(0)
120
122
  }
121
123
  if (char >= 'A' && char <= 'F') {
122
- return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
124
+ return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
123
125
  }
124
126
  if (char >= 'a' && char <= 'f') {
125
- return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
127
+ return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
126
128
  }
127
129
  if (char === '\0') {
128
- return 15;
130
+ return 15
129
131
  }
130
- throw new Error(`Invalid hex char "${char}"`);
131
- };
132
+ throw new Error(`Invalid hex char "${char}"`)
133
+ }
134
+
132
135
  const writePackedBytes = (str, type) => {
133
136
  if (str.length > TAGS.PACKED_MAX) {
134
- throw new Error('Too many bytes to pack');
137
+ throw new Error('Too many bytes to pack')
135
138
  }
136
- pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
137
- let roundedLength = Math.ceil(str.length / 2.0);
139
+ pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8)
140
+ let roundedLength = Math.ceil(str.length / 2.0)
138
141
  if (str.length % 2 !== 0) {
139
- roundedLength |= 128;
142
+ roundedLength |= 128
140
143
  }
141
- pushByte(roundedLength);
142
- const packFunction = type === 'nibble' ? packNibble : packHex;
144
+ pushByte(roundedLength)
145
+ const packFunction = type === 'nibble' ? packNibble : packHex
143
146
  const packBytePair = (v1, v2) => {
144
- const result = (packFunction(v1) << 4) | packFunction(v2);
145
- return result;
146
- };
147
- const strLengthHalf = Math.floor(str.length / 2);
147
+ const result = (packFunction(v1) << 4) | packFunction(v2)
148
+ return result
149
+ }
150
+ const strLengthHalf = Math.floor(str.length / 2)
148
151
  for (let i = 0; i < strLengthHalf; i++) {
149
- pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
152
+ pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
150
153
  }
151
154
  if (str.length % 2 !== 0) {
152
- pushByte(packBytePair(str[str.length - 1], '\x00'));
155
+ pushByte(packBytePair(str[str.length - 1], '\x00'))
153
156
  }
154
- };
157
+ }
158
+
155
159
  const isNibble = (str) => {
156
160
  if (!str || str.length > TAGS.PACKED_MAX) {
157
- return false;
161
+ return false
158
162
  }
159
163
  for (const char of str) {
160
- const isInNibbleRange = char >= '0' && char <= '9';
164
+ const isInNibbleRange = char >= '0' && char <= '9'
161
165
  if (!isInNibbleRange && char !== '-' && char !== '.') {
162
- return false;
166
+ return false
163
167
  }
164
168
  }
165
- return true;
166
- };
169
+ return true
170
+ }
171
+
167
172
  const isHex = (str) => {
168
173
  if (!str || str.length > TAGS.PACKED_MAX) {
169
- return false;
174
+ return false
170
175
  }
171
176
  for (const char of str) {
172
- const isInNibbleRange = char >= '0' && char <= '9';
177
+ const isInNibbleRange = char >= '0' && char <= '9'
173
178
  if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
174
- return false;
179
+ return false
175
180
  }
176
181
  }
177
- return true;
178
- };
182
+ return true
183
+ }
184
+
179
185
  const writeString = (str) => {
180
- if (str === undefined || str === null) {
181
- pushByte(TAGS.LIST_EMPTY);
182
- return;
186
+ if (str === undefined || str === null) {
187
+ pushByte(TAGS.LIST_EMPTY)
188
+ return
183
189
  }
184
- const tokenIndex = TOKEN_MAP[str];
190
+ const tokenIndex = TOKEN_MAP[str]
185
191
  if (tokenIndex) {
186
192
  if (typeof tokenIndex.dict === 'number') {
187
- pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
193
+ pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
188
194
  }
189
- pushByte(tokenIndex.index);
195
+ pushByte(tokenIndex.index)
190
196
  }
191
197
  else if (isNibble(str)) {
192
- writePackedBytes(str, 'nibble');
198
+ writePackedBytes(str, 'nibble')
193
199
  }
194
200
  else if (isHex(str)) {
195
- writePackedBytes(str, 'hex');
201
+ writePackedBytes(str, 'hex')
196
202
  }
197
203
  else if (str) {
198
- const decodedJid = (0, jid_utils_1.jidDecode)(str);
204
+ const decodedJid = (0, jid_utils_1.jidDecode)(str)
199
205
  if (decodedJid) {
200
- writeJid(decodedJid);
206
+ writeJid(decodedJid)
201
207
  }
202
208
  else {
203
- writeStringRaw(str);
209
+ writeStringRaw(str)
204
210
  }
205
211
  }
206
- };
212
+ }
213
+
207
214
  const writeListStart = (listSize) => {
208
215
  if (listSize === 0) {
209
- pushByte(TAGS.LIST_EMPTY);
216
+ pushByte(TAGS.LIST_EMPTY)
210
217
  }
211
218
  else if (listSize < 256) {
212
- pushBytes([TAGS.LIST_8, listSize]);
219
+ pushBytes([TAGS.LIST_8, listSize])
213
220
  }
214
221
  else {
215
- pushByte(TAGS.LIST_16);
216
- pushInt16(listSize);
222
+ pushByte(TAGS.LIST_16)
223
+ pushInt16(listSize)
217
224
  }
218
- };
225
+ }
226
+
219
227
  if (!tag) {
220
- throw new Error('Invalid node: tag cannot be undefined');
228
+ throw new Error('Invalid node: tag cannot be undefined')
221
229
  }
222
- const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
223
- writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
224
- writeString(tag);
230
+
231
+ const validAttributes = Object.keys(attrs).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null))
232
+ writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0))
233
+ writeString(tag)
225
234
  for (const key of validAttributes) {
226
235
  if (typeof attrs[key] === 'string') {
227
- writeString(key);
228
- writeString(attrs[key]);
236
+ writeString(key)
237
+ writeString(attrs[key])
229
238
  }
230
239
  }
231
240
  if (typeof content === 'string') {
232
- writeString(content);
241
+ writeString(content)
233
242
  }
234
243
  else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
235
- writeByteLength(content.length);
236
- pushBytes(content);
244
+ writeByteLength(content.length)
245
+ pushBytes(content)
237
246
  }
238
247
  else if (Array.isArray(content)) {
239
- const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
240
- writeListStart(validContent.length);
248
+ const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'))
249
+ writeListStart(validContent.length)
241
250
  for (const item of validContent) {
242
- encodeBinaryNodeInner(item, opts, buffer);
251
+ encodeBinaryNodeInner(item, opts, buffer)
243
252
  }
244
253
  }
245
254
  else if (typeof content === 'undefined') {
246
255
  // do nothing
247
256
  }
248
257
  else {
249
- throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
258
+ throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
250
259
  }
251
- return buffer;
252
- };
260
+ return buffer
261
+ }
262
+
263
+ module.exports = {
264
+ encodeBinaryNode
265
+ }
@@ -1,9 +1,10 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import { type BinaryNode } from './types';
1
+ /// <reference types="node" />
2
+ import { proto } from '../../WAProto';
3
+ import { BinaryNode } from './types';
3
4
  export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
4
5
  export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
5
6
  export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
6
- export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | undefined;
7
+ export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
7
8
  export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
8
9
  export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
9
10
  export declare const assertNodeErrorFree: (node: BinaryNode) => void;
@@ -11,4 +12,6 @@ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: strin
11
12
  [_: string]: string;
12
13
  };
13
14
  export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
14
- export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): string;
15
+ export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): any;
16
+ export declare const getBinaryNodeFilter: (node: BinaryNode[]) => boolean;
17
+ export declare const getAdditionalNode: (name: string) => BinaryNode[];