@sanzoffc/baileys 3.0.1 → 3.0.3

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 (114) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/WAProto.proto +769 -233
  3. package/WAProto/index.js +65801 -141371
  4. package/lib/Defaults/index.js +117 -114
  5. package/lib/Defaults/index.js.bak +123 -0
  6. package/lib/KeyDB/BinarySearch.js +20 -0
  7. package/lib/KeyDB/KeyedDB.js +167 -0
  8. package/lib/KeyDB/index.js +4 -0
  9. package/lib/Signal/Group/ciphertext-message.js +12 -14
  10. package/lib/Signal/Group/group-session-builder.js +10 -42
  11. package/lib/Signal/Group/group_cipher.js +75 -87
  12. package/lib/Signal/Group/index.js +13 -57
  13. package/lib/Signal/Group/keyhelper.js +17 -52
  14. package/lib/Signal/Group/sender-chain-key.js +27 -33
  15. package/lib/Signal/Group/sender-key-distribution-message.js +62 -63
  16. package/lib/Signal/Group/sender-key-message.js +65 -66
  17. package/lib/Signal/Group/sender-key-name.js +45 -44
  18. package/lib/Signal/Group/sender-key-record.js +39 -49
  19. package/lib/Signal/Group/sender-key-state.js +80 -93
  20. package/lib/Signal/Group/sender-message-key.js +27 -28
  21. package/lib/Signal/libsignal.js +313 -163
  22. package/lib/Signal/lid-mapping.js +155 -0
  23. package/lib/Socket/Client/index.js +4 -18
  24. package/lib/Socket/Client/types.js +12 -12
  25. package/lib/Socket/Client/websocket.js +51 -71
  26. package/lib/Socket/Client/websocket.js.bak +53 -0
  27. package/lib/Socket/business.js +359 -242
  28. package/lib/Socket/chats.js +858 -945
  29. package/lib/Socket/communities.js +413 -0
  30. package/lib/Socket/groups.js +304 -324
  31. package/lib/Socket/index.js +15 -9
  32. package/lib/Socket/messages-recv.js +1105 -1046
  33. package/lib/Socket/messages-send.js +615 -389
  34. package/lib/Socket/mex.js +45 -0
  35. package/lib/Socket/newsletter.js +224 -227
  36. package/lib/Socket/socket.js +795 -621
  37. package/lib/Store/index.js +6 -8
  38. package/lib/Store/make-cache-manager-store.js +75 -0
  39. package/lib/Store/make-in-memory-store.js +286 -435
  40. package/lib/Store/make-ordered-dictionary.js +77 -79
  41. package/lib/Store/object-repository.js +24 -26
  42. package/lib/Types/Auth.js +3 -2
  43. package/lib/Types/Bussines.js +3 -0
  44. package/lib/Types/Call.js +3 -2
  45. package/lib/Types/Chat.js +9 -4
  46. package/lib/Types/Contact.js +3 -2
  47. package/lib/Types/Events.js +3 -2
  48. package/lib/Types/GroupMetadata.js +3 -2
  49. package/lib/Types/Label.js +24 -26
  50. package/lib/Types/LabelAssociation.js +6 -8
  51. package/lib/Types/Message.js +12 -7
  52. package/lib/Types/Newsletter.js +32 -17
  53. package/lib/Types/Newsletter.js.bak +33 -0
  54. package/lib/Types/Product.js +3 -2
  55. package/lib/Types/Signal.js +3 -2
  56. package/lib/Types/Socket.js +4 -2
  57. package/lib/Types/State.js +11 -2
  58. package/lib/Types/USync.js +3 -2
  59. package/lib/Types/index.js +27 -41
  60. package/lib/Utils/auth-utils.js +211 -191
  61. package/lib/Utils/baileys-event-stream.js +44 -0
  62. package/lib/Utils/browser-utils.js +21 -31
  63. package/lib/Utils/business.js +213 -214
  64. package/lib/Utils/chat-utils.js +711 -689
  65. package/lib/Utils/crypto.js +112 -175
  66. package/lib/Utils/decode-wa-message.js +254 -194
  67. package/lib/Utils/event-buffer.js +510 -500
  68. package/lib/Utils/generics.js +318 -430
  69. package/lib/Utils/history.js +83 -90
  70. package/lib/Utils/index.js +21 -35
  71. package/lib/Utils/link-preview.js +71 -116
  72. package/lib/Utils/logger.js +5 -7
  73. package/lib/Utils/lt-hash.js +40 -46
  74. package/lib/Utils/make-mutex.js +34 -41
  75. package/lib/Utils/message-retry-manager.js +33 -48
  76. package/lib/Utils/messages-media.js +573 -825
  77. package/lib/Utils/messages.js +349 -489
  78. package/lib/Utils/noise-handler.js +138 -144
  79. package/lib/Utils/pre-key-manager.js +85 -0
  80. package/lib/Utils/process-message.js +321 -384
  81. package/lib/Utils/signal.js +147 -139
  82. package/lib/Utils/use-multi-file-auth-state.js +95 -109
  83. package/lib/Utils/validate-connection.js +183 -212
  84. package/lib/WABinary/constants.js +1298 -1298
  85. package/lib/WABinary/decode.js +231 -256
  86. package/lib/WABinary/encode.js +207 -239
  87. package/lib/WABinary/generic-utils.js +119 -40
  88. package/lib/WABinary/index.js +7 -21
  89. package/lib/WABinary/jid-utils.js +87 -79
  90. package/lib/WABinary/types.js +3 -2
  91. package/lib/WAM/BinaryInfo.js +10 -12
  92. package/lib/WAM/constants.js +22851 -15348
  93. package/lib/WAM/encode.js +135 -136
  94. package/lib/WAM/index.js +5 -19
  95. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -30
  96. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +49 -53
  97. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -28
  98. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -39
  99. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  100. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +26 -20
  101. package/lib/WAUSync/Protocols/index.js +6 -20
  102. package/lib/WAUSync/USyncQuery.js +86 -85
  103. package/lib/WAUSync/USyncUser.js +23 -25
  104. package/lib/WAUSync/index.js +5 -19
  105. package/lib/index.js +18 -49
  106. package/package.json +65 -78
  107. package/README.MD +0 -1295
  108. package/WAProto/GenerateStatics.sh +0 -4
  109. package/WAProto/p.html +0 -1
  110. package/engine-requirements.js +0 -10
  111. package/lib/Defaults/wileys-version.json +0 -3
  112. package/lib/Signal/Group/queue-job.js +0 -57
  113. package/lib/Socket/usync.js +0 -70
  114. package/lib/Utils/wileys-event-stream.js +0 -63
@@ -1,250 +1,218 @@
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]) => {
40
- const encoded = encodeBinaryNodeInner(node, opts, buffer);
41
- return Buffer.from(encoded);
1
+ //=======================================================//
2
+ import * as constants from "./constants.js";
3
+ import { jidDecode } from "./jid-utils.js";
4
+ //=======================================================//
5
+ export const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
6
+ const encoded = encodeBinaryNodeInner(node, opts, buffer);
7
+ return Buffer.from(encoded);
42
8
  };
43
- exports.encodeBinaryNode = encodeBinaryNode;
9
+ //=======================================================//
44
10
  const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
45
- const { TAGS, TOKEN_MAP } = opts;
46
- const pushByte = (value) => buffer.push(value & 0xff);
47
- const pushInt = (value, n, littleEndian = false) => {
48
- for (let i = 0; i < n; i++) {
49
- const curShift = littleEndian ? i : n - 1 - i;
50
- buffer.push((value >> (curShift * 8)) & 0xff);
51
- }
52
- };
53
- const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
54
- const pushInt16 = (value) => {
55
- pushBytes([(value >> 8) & 0xff, value & 0xff]);
56
- };
57
- const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]));
58
- const writeByteLength = (length) => {
59
- if (length >= 4294967296) {
60
- throw new Error('string too large to encode: ' + length);
61
- }
62
- if (length >= 1 << 20) {
63
- pushByte(TAGS.BINARY_32);
64
- pushInt(length, 4); // 32 bit integer
65
- }
66
- else if (length >= 256) {
67
- pushByte(TAGS.BINARY_20);
68
- pushInt20(length);
69
- }
70
- else {
71
- pushByte(TAGS.BINARY_8);
72
- pushByte(length);
73
- }
74
- };
75
- const writeStringRaw = (str) => {
76
- const bytes = Buffer.from(str, 'utf-8');
77
- writeByteLength(bytes.length);
78
- pushBytes(bytes);
79
- };
80
- const writeJid = ({ domainType, device, user, server }) => {
81
- if (typeof device !== 'undefined') {
82
- pushByte(TAGS.AD_JID);
83
- pushByte(domainType || 0);
84
- pushByte(device || 0);
85
- writeString(user);
86
- }
87
- else {
88
- pushByte(TAGS.JID_PAIR);
89
- if (user.length) {
90
- writeString(user);
91
- }
92
- else {
93
- pushByte(TAGS.LIST_EMPTY);
94
- }
95
- writeString(server);
96
- }
97
- };
98
- const packNibble = (char) => {
99
- switch (char) {
100
- case '-':
101
- return 10;
102
- case '.':
103
- return 11;
104
- case '\0':
105
- return 15;
106
- default:
107
- if (char >= '0' && char <= '9') {
108
- return char.charCodeAt(0) - '0'.charCodeAt(0);
109
- }
110
- throw new Error(`invalid byte for nibble "${char}"`);
111
- }
112
- };
113
- const packHex = (char) => {
114
- if (char >= '0' && char <= '9') {
115
- return char.charCodeAt(0) - '0'.charCodeAt(0);
116
- }
117
- if (char >= 'A' && char <= 'F') {
118
- return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
119
- }
120
- if (char >= 'a' && char <= 'f') {
121
- return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
122
- }
123
- if (char === '\0') {
124
- return 15;
125
- }
126
- throw new Error(`Invalid hex char "${char}"`);
127
- };
128
- const writePackedBytes = (str, type) => {
129
- if (str.length > TAGS.PACKED_MAX) {
130
- throw new Error('Too many bytes to pack');
131
- }
132
- pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
133
- let roundedLength = Math.ceil(str.length / 2.0);
134
- if (str.length % 2 !== 0) {
135
- roundedLength |= 128;
136
- }
137
- pushByte(roundedLength);
138
- const packFunction = type === 'nibble' ? packNibble : packHex;
139
- const packBytePair = (v1, v2) => {
140
- const result = (packFunction(v1) << 4) | packFunction(v2);
141
- return result;
142
- };
143
- const strLengthHalf = Math.floor(str.length / 2);
144
- for (let i = 0; i < strLengthHalf; i++) {
145
- pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
146
- }
147
- if (str.length % 2 !== 0) {
148
- pushByte(packBytePair(str[str.length - 1], '\x00'));
149
- }
150
- };
151
- const isNibble = (str) => {
152
- if (!str || str.length > TAGS.PACKED_MAX) {
153
- return false;
154
- }
155
- for (let i = 0; i < str.length; i++) {
156
- const char = str[i];
157
- const isInNibbleRange = char >= '0' && char <= '9';
158
- if (!isInNibbleRange && char !== '-' && char !== '.') {
159
- return false;
160
- }
161
- }
162
- return true;
163
- };
164
- const isHex = (str) => {
165
- if (!str || str.length > TAGS.PACKED_MAX) {
166
- return false;
167
- }
168
- for (let i = 0; i < str.length; i++) {
169
- const char = str[i];
170
- const isInNibbleRange = char >= '0' && char <= '9';
171
- if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
172
- return false;
173
- }
174
- }
175
- return true;
176
- };
177
- const writeString = (str) => {
178
- if (str === undefined || str === null) {
179
- pushByte(TAGS.LIST_EMPTY);
180
- return;
181
- }
182
- const tokenIndex = TOKEN_MAP[str];
183
- if (tokenIndex) {
184
- if (typeof tokenIndex.dict === 'number') {
185
- pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
186
- }
187
- pushByte(tokenIndex.index);
188
- }
189
- else if (isNibble(str)) {
190
- writePackedBytes(str, 'nibble');
191
- }
192
- else if (isHex(str)) {
193
- writePackedBytes(str, 'hex');
194
- }
195
- else if (str) {
196
- const decodedJid = (0, jid_utils_1.jidDecode)(str);
197
- if (decodedJid) {
198
- writeJid(decodedJid);
199
- }
200
- else {
201
- writeStringRaw(str);
202
- }
203
- }
204
- };
205
- const writeListStart = (listSize) => {
206
- if (listSize === 0) {
207
- pushByte(TAGS.LIST_EMPTY);
208
- }
209
- else if (listSize < 256) {
210
- pushBytes([TAGS.LIST_8, listSize]);
211
- }
212
- else {
213
- pushByte(TAGS.LIST_16);
214
- pushInt16(listSize);
215
- }
11
+ const { TAGS, TOKEN_MAP } = opts;
12
+ const pushByte = (value) => buffer.push(value & 0xff);
13
+ const pushInt = (value, n, littleEndian = false) => {
14
+ for (let i = 0; i < n; i++) {
15
+ const curShift = littleEndian ? i : n - 1 - i;
16
+ buffer.push((value >> (curShift * 8)) & 0xff);
17
+ }
18
+ };
19
+ const pushBytes = (bytes) => {
20
+ for (const b of bytes) {
21
+ buffer.push(b);
22
+ }
23
+ };
24
+ const pushInt16 = (value) => {
25
+ pushBytes([(value >> 8) & 0xff, value & 0xff]);
26
+ };
27
+ const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
28
+ const writeByteLength = (length) => {
29
+ if (length >= 4294967296) {
30
+ throw new Error("string too large to encode: " + length);
31
+ }
32
+ if (length >= 1 << 20) {
33
+ pushByte(TAGS.BINARY_32);
34
+ pushInt(length, 4);
35
+ }
36
+ else if (length >= 256) {
37
+ pushByte(TAGS.BINARY_20);
38
+ pushInt20(length);
39
+ }
40
+ else {
41
+ pushByte(TAGS.BINARY_8);
42
+ pushByte(length);
43
+ }
44
+ };
45
+ const writeStringRaw = (str) => {
46
+ const bytes = Buffer.from(str, "utf-8");
47
+ writeByteLength(bytes.length);
48
+ pushBytes(bytes);
49
+ };
50
+ const writeJid = ({ domainType, device, user, server }) => {
51
+ if (typeof device !== "undefined") {
52
+ pushByte(TAGS.AD_JID);
53
+ pushByte(domainType || 0);
54
+ pushByte(device || 0);
55
+ writeString(user);
56
+ }
57
+ else {
58
+ pushByte(TAGS.JID_PAIR);
59
+ if (user.length) {
60
+ writeString(user);
61
+ }
62
+ else {
63
+ pushByte(TAGS.LIST_EMPTY);
64
+ }
65
+ writeString(server);
66
+ }
67
+ };
68
+ const packNibble = (char) => {
69
+ switch (char) {
70
+ case "-":
71
+ return 10;
72
+ case ".":
73
+ return 11;
74
+ case "\0":
75
+ return 15;
76
+ default:
77
+ if (char >= "0" && char <= "9") {
78
+ return char.charCodeAt(0) - "0".charCodeAt(0);
79
+ }
80
+ throw new Error(`invalid byte for nibble "${char}"`);
81
+ }
82
+ };
83
+ const packHex = (char) => {
84
+ if (char >= "0" && char <= "9") {
85
+ return char.charCodeAt(0) - "0".charCodeAt(0);
86
+ }
87
+ if (char >= "A" && char <= "F") {
88
+ return 10 + char.charCodeAt(0) - "A".charCodeAt(0);
89
+ }
90
+ if (char >= "a" && char <= "f") {
91
+ return 10 + char.charCodeAt(0) - "a".charCodeAt(0);
92
+ }
93
+ if (char === "\0") {
94
+ return 15;
95
+ }
96
+ throw new Error(`Invalid hex char "${char}"`);
97
+ };
98
+ const writePackedBytes = (str, type) => {
99
+ if (str.length > TAGS.PACKED_MAX) {
100
+ throw new Error("Too many bytes to pack");
101
+ }
102
+ pushByte(type === "nibble" ? TAGS.NIBBLE_8 : TAGS.HEX_8);
103
+ let roundedLength = Math.ceil(str.length / 2.0);
104
+ if (str.length % 2 !== 0) {
105
+ roundedLength |= 128;
106
+ }
107
+ pushByte(roundedLength);
108
+ const packFunction = type === "nibble" ? packNibble : packHex;
109
+ const packBytePair = (v1, v2) => {
110
+ const result = (packFunction(v1) << 4) | packFunction(v2);
111
+ return result;
216
112
  };
217
- if (!tag) {
218
- throw new Error('Invalid node: tag cannot be undefined');
219
- }
220
- const validAttributes = Object.keys(attrs || {}).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
221
- writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
222
- writeString(tag);
223
- for (const key of validAttributes) {
224
- if (typeof attrs[key] === 'string') {
225
- writeString(key);
226
- writeString(attrs[key]);
227
- }
113
+ const strLengthHalf = Math.floor(str.length / 2);
114
+ for (let i = 0; i < strLengthHalf; i++) {
115
+ pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
228
116
  }
229
- if (typeof content === 'string') {
230
- writeString(content);
117
+ if (str.length % 2 !== 0) {
118
+ pushByte(packBytePair(str[str.length - 1], "\x00"));
231
119
  }
232
- else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
233
- writeByteLength(content.length);
234
- pushBytes(content);
120
+ };
121
+ const isNibble = (str) => {
122
+ if (!str || str.length > TAGS.PACKED_MAX) {
123
+ return false;
235
124
  }
236
- else if (Array.isArray(content)) {
237
- const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
238
- writeListStart(validContent.length);
239
- for (const item of validContent) {
240
- encodeBinaryNodeInner(item, opts, buffer);
241
- }
125
+ for (const char of str) {
126
+ const isInNibbleRange = char >= "0" && char <= "9";
127
+ if (!isInNibbleRange && char !== "-" && char !== ".") {
128
+ return false;
129
+ }
130
+ }
131
+ return true;
132
+ };
133
+ const isHex = (str) => {
134
+ if (!str || str.length > TAGS.PACKED_MAX) {
135
+ return false;
136
+ }
137
+ for (const char of str) {
138
+ const isInNibbleRange = char >= "0" && char <= "9";
139
+ if (!isInNibbleRange && !(char >= "A" && char <= "F")) {
140
+ return false;
141
+ }
242
142
  }
243
- else if (typeof content === 'undefined') {
244
- // do nothing
143
+ return true;
144
+ };
145
+ const writeString = (str) => {
146
+ if (str === undefined || str === null) {
147
+ pushByte(TAGS.LIST_EMPTY);
148
+ return;
149
+ }
150
+ const tokenIndex = TOKEN_MAP[str];
151
+ if (tokenIndex) {
152
+ if (typeof tokenIndex.dict === "number") {
153
+ pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
154
+ }
155
+ pushByte(tokenIndex.index);
156
+ }
157
+ else if (isNibble(str)) {
158
+ writePackedBytes(str, "nibble");
159
+ }
160
+ else if (isHex(str)) {
161
+ writePackedBytes(str, "hex");
162
+ }
163
+ else if (str) {
164
+ const decodedJid = jidDecode(str);
165
+ if (decodedJid) {
166
+ writeJid(decodedJid);
167
+ }
168
+ else {
169
+ writeStringRaw(str);
170
+ }
171
+ }
172
+ };
173
+ const writeListStart = (listSize) => {
174
+ if (listSize === 0) {
175
+ pushByte(TAGS.LIST_EMPTY);
176
+ }
177
+ else if (listSize < 256) {
178
+ pushBytes([TAGS.LIST_8, listSize]);
245
179
  }
246
180
  else {
247
- throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
181
+ pushByte(TAGS.LIST_16);
182
+ pushInt16(listSize);
183
+ }
184
+ };
185
+ if (!tag) {
186
+ throw new Error("Invalid node: tag cannot be undefined");
187
+ }
188
+ const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== "undefined" && attrs[k] !== null);
189
+ writeListStart(2 * validAttributes.length + 1 + (typeof content !== "undefined" ? 1 : 0));
190
+ writeString(tag);
191
+ for (const key of validAttributes) {
192
+ if (typeof attrs[key] === "string") {
193
+ writeString(key);
194
+ writeString(attrs[key]);
195
+ }
196
+ }
197
+ if (typeof content === "string") {
198
+ writeString(content);
199
+ }
200
+ else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
201
+ writeByteLength(content.length);
202
+ pushBytes(content);
203
+ }
204
+ else if (Array.isArray(content)) {
205
+ const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === "string"));
206
+ writeListStart(validContent.length);
207
+ for (const item of validContent) {
208
+ encodeBinaryNodeInner(item, opts, buffer);
248
209
  }
249
- return buffer;
210
+ }
211
+ else if (typeof content === "undefined") {
212
+ }
213
+ else {
214
+ throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
215
+ }
216
+ return buffer;
250
217
  };
218
+ //=======================================================//