@denzy-official/baileys 1.1.3 → 1.1.5

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 (97) hide show
  1. package/WAProto/index.js +77698 -117051
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Defaults/index.d.ts +6 -5
  4. package/lib/Defaults/index.js +118 -79
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  6. package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
  7. package/lib/Signal/Group/ciphertext-message.js +0 -1
  8. package/lib/Signal/Group/group-session-builder.d.ts +0 -1
  9. package/lib/Signal/Group/group-session-builder.js +0 -1
  10. package/lib/Signal/Group/group_cipher.d.ts +0 -1
  11. package/lib/Signal/Group/group_cipher.js +0 -1
  12. package/lib/Signal/Group/index.d.ts +0 -1
  13. package/lib/Signal/Group/index.js +0 -1
  14. package/lib/Signal/Group/keyhelper.d.ts +0 -1
  15. package/lib/Signal/Group/keyhelper.js +0 -1
  16. package/lib/Signal/Group/queue-job.d.ts +0 -1
  17. package/lib/Signal/Group/queue-job.js +0 -1
  18. package/lib/Signal/Group/sender-chain-key.d.ts +0 -1
  19. package/lib/Signal/Group/sender-chain-key.js +0 -1
  20. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -1
  21. package/lib/Signal/Group/sender-key-distribution-message.js +0 -1
  22. package/lib/Signal/Group/sender-key-message.d.ts +0 -1
  23. package/lib/Signal/Group/sender-key-message.js +0 -1
  24. package/lib/Signal/Group/sender-key-name.d.ts +0 -1
  25. package/lib/Signal/Group/sender-key-name.js +0 -1
  26. package/lib/Signal/Group/sender-key-record.d.ts +0 -1
  27. package/lib/Signal/Group/sender-key-record.js +0 -1
  28. package/lib/Signal/Group/sender-key-state.d.ts +0 -1
  29. package/lib/Signal/Group/sender-key-state.js +0 -1
  30. package/lib/Signal/Group/sender-message-key.d.ts +0 -1
  31. package/lib/Signal/Group/sender-message-key.js +0 -1
  32. package/lib/Signal/libsignal.d.ts +0 -1
  33. package/lib/Signal/libsignal.js +0 -1
  34. package/lib/Store/index.d.ts +2 -2
  35. package/lib/Store/index.js +3 -2
  36. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  37. package/lib/Store/make-cache-manager-store.js +83 -0
  38. package/lib/Store/make-in-memory-store.d.ts +24 -25
  39. package/lib/Store/make-in-memory-store.js +14 -27
  40. package/lib/Store/make-ordered-dictionary.d.ts +1 -2
  41. package/lib/Store/make-ordered-dictionary.js +2 -3
  42. package/lib/Store/object-repository.d.ts +0 -1
  43. package/lib/Store/object-repository.js +0 -1
  44. package/lib/Types/Auth.d.ts +7 -1
  45. package/lib/Types/Auth.js +0 -1
  46. package/lib/Types/Call.d.ts +1 -2
  47. package/lib/Types/Call.js +0 -1
  48. package/lib/Types/Chat.d.ts +7 -15
  49. package/lib/Types/Chat.js +0 -1
  50. package/lib/Types/Contact.d.ts +1 -6
  51. package/lib/Types/Contact.js +0 -1
  52. package/lib/Types/Events.d.ts +2 -45
  53. package/lib/Types/Events.js +0 -1
  54. package/lib/Types/GroupMetadata.d.ts +2 -12
  55. package/lib/Types/GroupMetadata.js +0 -1
  56. package/lib/Types/Label.d.ts +0 -1
  57. package/lib/Types/Label.js +1 -2
  58. package/lib/Types/LabelAssociation.d.ts +0 -1
  59. package/lib/Types/LabelAssociation.js +1 -2
  60. package/lib/Types/Message.d.ts +21 -149
  61. package/lib/Types/Message.js +2 -1
  62. package/lib/Types/Newsletter.d.ts +97 -74
  63. package/lib/Types/Newsletter.js +38 -19
  64. package/lib/Types/Socket.d.ts +9 -17
  65. package/lib/Types/index.d.ts +1 -9
  66. package/lib/Types/index.js +2 -3
  67. package/lib/WABinary/constants.d.ts +27 -25
  68. package/lib/WABinary/constants.js +13 -1277
  69. package/lib/WABinary/decode.d.ts +4 -4
  70. package/lib/WABinary/decode.js +13 -27
  71. package/lib/WABinary/encode.d.ts +2 -2
  72. package/lib/WABinary/encode.js +152 -138
  73. package/lib/WABinary/generic-utils.d.ts +4 -2
  74. package/lib/WABinary/generic-utils.js +125 -38
  75. package/lib/WABinary/index.d.ts +0 -1
  76. package/lib/WABinary/index.js +0 -1
  77. package/lib/WABinary/jid-utils.d.ts +5 -11
  78. package/lib/WABinary/jid-utils.js +5 -27
  79. package/lib/WABinary/types.d.ts +0 -1
  80. package/lib/WABinary/types.js +0 -1
  81. package/lib/WAM/BinaryInfo.d.ts +11 -3
  82. package/lib/WAM/BinaryInfo.js +0 -1
  83. package/lib/WAM/constants.d.ts +0 -1
  84. package/lib/WAM/constants.js +0 -1
  85. package/lib/WAM/encode.d.ts +2 -2
  86. package/lib/WAM/encode.js +0 -1
  87. package/lib/WAM/index.d.ts +0 -1
  88. package/lib/WAM/index.js +0 -1
  89. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  90. package/lib/index.js +23 -36
  91. package/package.json +94 -97
  92. package/WAProto/GenerateStatics.sh +0 -5
  93. package/WAProto/WAProto.proto +0 -4775
  94. package/WAProto/bocah rename tolol, baileys by denzy +0 -0
  95. package/WAProto/index.d.ts +0 -55058
  96. package/WAProto/index.ts.ts +0 -53474
  97. package/WAProto/p.html +0 -1
@@ -1,7 +1,7 @@
1
- // baileys by denzy
1
+ /// <reference types="node" />
2
2
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
- export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer<ArrayBufferLike>>;
4
- 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?: {
5
5
  index: number;
6
6
  }) => BinaryNode;
7
- export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
7
+ export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode;
@@ -1,4 +1,3 @@
1
- // baileys by denzy
2
1
  "use strict";
3
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
3
  if (k2 === undefined) k2 = k;
@@ -16,33 +15,21 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
16
15
  }) : function(o, v) {
17
16
  o["default"] = v;
18
17
  });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
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
+ };
36
25
  Object.defineProperty(exports, "__esModule", { value: true });
37
26
  exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
38
- const util_1 = require("util");
39
27
  const zlib_1 = require("zlib");
40
28
  const constants = __importStar(require("./constants"));
41
29
  const jid_utils_1 = require("./jid-utils");
42
- const inflatePromise = (0, util_1.promisify)(zlib_1.inflate);
43
- const decompressingIfRequired = async (buffer) => {
30
+ const decompressingIfRequired = (buffer) => {
44
31
  if (2 & buffer.readUInt8()) {
45
- buffer = await inflatePromise(buffer.slice(1));
32
+ buffer = (0, zlib_1.inflateSync)(buffer.slice(1));
46
33
  }
47
34
  else { // nodes with no compression have a 0x00 prefix, we remove that
48
35
  buffer = buffer.slice(1);
@@ -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,3 +1,3 @@
1
- // baileys by denzy
1
+ /// <reference types="node" />
2
2
  import type { BinaryNode, BinaryNodeCodingOptions } from './types';
3
- 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,251 +1,265 @@
1
- // baileys by denzy
2
- "use strict";
1
+ "use strict"
2
+
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
6
6
  if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
7
+ desc = { enumerable: true, get: function() { return m[k] } }
8
8
  }
9
- Object.defineProperty(o, k2, desc);
9
+ Object.defineProperty(o, k2, desc)
10
10
  }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
13
+ }))
14
+
14
15
  var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v })
16
17
  }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.encodeBinaryNode = void 0;
38
- const constants = __importStar(require("./constants"));
39
- 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
+
40
34
  const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
41
- const encoded = encodeBinaryNodeInner(node, opts, buffer);
42
- return Buffer.from(encoded);
43
- };
44
- exports.encodeBinaryNode = encodeBinaryNode;
35
+ const encoded = encodeBinaryNodeInner(node, opts, buffer)
36
+ return Buffer.from(encoded)
37
+ }
38
+
45
39
  const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
46
- const { TAGS, TOKEN_MAP } = opts;
47
- const pushByte = (value) => buffer.push(value & 0xff);
40
+ const { TAGS, TOKEN_MAP } = opts
41
+ const pushByte = (value) => buffer.push(value & 0xff)
48
42
  const pushInt = (value, n, littleEndian = false) => {
49
43
  for (let i = 0; i < n; i++) {
50
- const curShift = littleEndian ? i : n - 1 - i;
51
- buffer.push((value >> (curShift * 8)) & 0xff);
44
+ const curShift = littleEndian ? i : n - 1 - i
45
+ buffer.push((value >> (curShift * 8)) & 0xff)
52
46
  }
53
- };
54
- const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
47
+ }
48
+
49
+ const pushBytes = (bytes) => {
50
+ for (const b of bytes) {
51
+ buffer.push(b)
52
+ }
53
+ }
54
+
55
55
  const pushInt16 = (value) => {
56
- pushBytes([(value >> 8) & 0xff, value & 0xff]);
57
- };
58
- 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]))
59
60
  const writeByteLength = (length) => {
60
61
  if (length >= 4294967296) {
61
- throw new Error('string too large to encode: ' + length);
62
+ throw new Error('string too large to encode: ' + length)
62
63
  }
63
64
  if (length >= 1 << 20) {
64
- pushByte(TAGS.BINARY_32);
65
- pushInt(length, 4); // 32 bit integer
65
+ pushByte(TAGS.BINARY_32)
66
+ pushInt(length, 4) // 32 bit integer
66
67
  }
67
68
  else if (length >= 256) {
68
- pushByte(TAGS.BINARY_20);
69
- pushInt20(length);
69
+ pushByte(TAGS.BINARY_20)
70
+ pushInt20(length)
70
71
  }
71
72
  else {
72
- pushByte(TAGS.BINARY_8);
73
- pushByte(length);
73
+ pushByte(TAGS.BINARY_8)
74
+ pushByte(length)
74
75
  }
75
- };
76
+ }
77
+
76
78
  const writeStringRaw = (str) => {
77
- const bytes = Buffer.from(str, 'utf-8');
78
- writeByteLength(bytes.length);
79
- pushBytes(bytes);
80
- };
79
+ const bytes = Buffer.from(str, 'utf-8')
80
+ writeByteLength(bytes.length)
81
+ pushBytes(bytes)
82
+ }
83
+
81
84
  const writeJid = ({ domainType, device, user, server }) => {
82
85
  if (typeof device !== 'undefined') {
83
- pushByte(TAGS.AD_JID);
84
- pushByte(domainType || 0);
85
- pushByte(device || 0);
86
- writeString(user);
86
+ pushByte(TAGS.AD_JID)
87
+ pushByte(domainType || 0)
88
+ pushByte(device || 0)
89
+ writeString(user)
87
90
  }
88
91
  else {
89
- pushByte(TAGS.JID_PAIR);
92
+ pushByte(TAGS.JID_PAIR)
90
93
  if (user.length) {
91
- writeString(user);
94
+ writeString(user)
92
95
  }
93
96
  else {
94
- pushByte(TAGS.LIST_EMPTY);
97
+ pushByte(TAGS.LIST_EMPTY)
95
98
  }
96
- writeString(server);
99
+ writeString(server)
97
100
  }
98
- };
101
+ }
102
+
99
103
  const packNibble = (char) => {
100
104
  switch (char) {
101
105
  case '-':
102
- return 10;
106
+ return 10
103
107
  case '.':
104
- return 11;
108
+ return 11
105
109
  case '\0':
106
- return 15;
110
+ return 15
107
111
  default:
108
112
  if (char >= '0' && char <= '9') {
109
- return char.charCodeAt(0) - '0'.charCodeAt(0);
113
+ return char.charCodeAt(0) - '0'.charCodeAt(0)
110
114
  }
111
- throw new Error(`invalid byte for nibble "${char}"`);
115
+ throw new Error(`invalid byte for nibble "${char}"`)
112
116
  }
113
- };
117
+ }
118
+
114
119
  const packHex = (char) => {
115
120
  if (char >= '0' && char <= '9') {
116
- return char.charCodeAt(0) - '0'.charCodeAt(0);
121
+ return char.charCodeAt(0) - '0'.charCodeAt(0)
117
122
  }
118
123
  if (char >= 'A' && char <= 'F') {
119
- return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
124
+ return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
120
125
  }
121
126
  if (char >= 'a' && char <= 'f') {
122
- return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
127
+ return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
123
128
  }
124
129
  if (char === '\0') {
125
- return 15;
130
+ return 15
126
131
  }
127
- throw new Error(`Invalid hex char "${char}"`);
128
- };
132
+ throw new Error(`Invalid hex char "${char}"`)
133
+ }
134
+
129
135
  const writePackedBytes = (str, type) => {
130
136
  if (str.length > TAGS.PACKED_MAX) {
131
- throw new Error('Too many bytes to pack');
137
+ throw new Error('Too many bytes to pack')
132
138
  }
133
- pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
134
- 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)
135
141
  if (str.length % 2 !== 0) {
136
- roundedLength |= 128;
142
+ roundedLength |= 128
137
143
  }
138
- pushByte(roundedLength);
139
- const packFunction = type === 'nibble' ? packNibble : packHex;
144
+ pushByte(roundedLength)
145
+ const packFunction = type === 'nibble' ? packNibble : packHex
140
146
  const packBytePair = (v1, v2) => {
141
- const result = (packFunction(v1) << 4) | packFunction(v2);
142
- return result;
143
- };
144
- 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)
145
151
  for (let i = 0; i < strLengthHalf; i++) {
146
- pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
152
+ pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
147
153
  }
148
154
  if (str.length % 2 !== 0) {
149
- pushByte(packBytePair(str[str.length - 1], '\x00'));
155
+ pushByte(packBytePair(str[str.length - 1], '\x00'))
150
156
  }
151
- };
157
+ }
158
+
152
159
  const isNibble = (str) => {
153
160
  if (!str || str.length > TAGS.PACKED_MAX) {
154
- return false;
161
+ return false
155
162
  }
156
- for (let i = 0; i < str.length; i++) {
157
- const char = str[i];
158
- const isInNibbleRange = char >= '0' && char <= '9';
163
+ for (const char of str) {
164
+ const isInNibbleRange = char >= '0' && char <= '9'
159
165
  if (!isInNibbleRange && char !== '-' && char !== '.') {
160
- return false;
166
+ return false
161
167
  }
162
168
  }
163
- return true;
164
- };
169
+ return true
170
+ }
171
+
165
172
  const isHex = (str) => {
166
173
  if (!str || str.length > TAGS.PACKED_MAX) {
167
- return false;
174
+ return false
168
175
  }
169
- for (let i = 0; i < str.length; i++) {
170
- const char = str[i];
171
- const isInNibbleRange = char >= '0' && char <= '9';
176
+ for (const char of str) {
177
+ const isInNibbleRange = char >= '0' && char <= '9'
172
178
  if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
173
- return false;
179
+ return false
174
180
  }
175
181
  }
176
- return true;
177
- };
182
+ return true
183
+ }
184
+
178
185
  const writeString = (str) => {
179
- if (str === undefined || str === null) {
180
- pushByte(TAGS.LIST_EMPTY);
181
- return;
186
+ if (str === undefined || str === null) {
187
+ pushByte(TAGS.LIST_EMPTY)
188
+ return
182
189
  }
183
- const tokenIndex = TOKEN_MAP[str];
190
+ const tokenIndex = TOKEN_MAP[str]
184
191
  if (tokenIndex) {
185
192
  if (typeof tokenIndex.dict === 'number') {
186
- pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
193
+ pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
187
194
  }
188
- pushByte(tokenIndex.index);
195
+ pushByte(tokenIndex.index)
189
196
  }
190
197
  else if (isNibble(str)) {
191
- writePackedBytes(str, 'nibble');
198
+ writePackedBytes(str, 'nibble')
192
199
  }
193
200
  else if (isHex(str)) {
194
- writePackedBytes(str, 'hex');
201
+ writePackedBytes(str, 'hex')
195
202
  }
196
203
  else if (str) {
197
- const decodedJid = (0, jid_utils_1.jidDecode)(str);
204
+ const decodedJid = (0, jid_utils_1.jidDecode)(str)
198
205
  if (decodedJid) {
199
- writeJid(decodedJid);
206
+ writeJid(decodedJid)
200
207
  }
201
208
  else {
202
- writeStringRaw(str);
209
+ writeStringRaw(str)
203
210
  }
204
211
  }
205
- };
212
+ }
213
+
206
214
  const writeListStart = (listSize) => {
207
215
  if (listSize === 0) {
208
- pushByte(TAGS.LIST_EMPTY);
216
+ pushByte(TAGS.LIST_EMPTY)
209
217
  }
210
218
  else if (listSize < 256) {
211
- pushBytes([TAGS.LIST_8, listSize]);
219
+ pushBytes([TAGS.LIST_8, listSize])
212
220
  }
213
221
  else {
214
- pushByte(TAGS.LIST_16);
215
- pushInt16(listSize);
222
+ pushByte(TAGS.LIST_16)
223
+ pushInt16(listSize)
216
224
  }
217
- };
225
+ }
226
+
218
227
  if (!tag) {
219
- throw new Error('Invalid node: tag cannot be undefined');
228
+ throw new Error('Invalid node: tag cannot be undefined')
220
229
  }
221
- const validAttributes = Object.keys(attrs || {}).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
222
- writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
223
- 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)
224
234
  for (const key of validAttributes) {
225
235
  if (typeof attrs[key] === 'string') {
226
- writeString(key);
227
- writeString(attrs[key]);
236
+ writeString(key)
237
+ writeString(attrs[key])
228
238
  }
229
239
  }
230
240
  if (typeof content === 'string') {
231
- writeString(content);
241
+ writeString(content)
232
242
  }
233
243
  else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
234
- writeByteLength(content.length);
235
- pushBytes(content);
244
+ writeByteLength(content.length)
245
+ pushBytes(content)
236
246
  }
237
247
  else if (Array.isArray(content)) {
238
- const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
239
- 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)
240
250
  for (const item of validContent) {
241
- encodeBinaryNodeInner(item, opts, buffer);
251
+ encodeBinaryNodeInner(item, opts, buffer)
242
252
  }
243
253
  }
244
254
  else if (typeof content === 'undefined') {
245
255
  // do nothing
246
256
  }
247
257
  else {
248
- throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
258
+ throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
249
259
  }
250
- return buffer;
251
- };
260
+ return buffer
261
+ }
262
+
263
+ module.exports = {
264
+ encodeBinaryNode
265
+ }
@@ -1,10 +1,10 @@
1
- // baileys by denzy
1
+ /// <reference types="node" />
2
2
  import { proto } from '../../WAProto';
3
3
  import { BinaryNode } from './types';
4
4
  export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
5
5
  export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
6
6
  export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
7
- 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;
8
8
  export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
9
9
  export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
10
10
  export declare const assertNodeErrorFree: (node: BinaryNode) => void;
@@ -13,3 +13,5 @@ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: strin
13
13
  };
14
14
  export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
15
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[];