@periskope/baileys 6.7.15-alpha.6 → 6.7.16-alpha.1

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 (149) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +35 -1267
  3. package/WAProto/WAProto.proto +1299 -286
  4. package/WAProto/index.d.ts +16106 -2739
  5. package/WAProto/index.js +128593 -73944
  6. package/engine-requirements.js +10 -0
  7. package/lib/Defaults/baileys-version.json +3 -3
  8. package/lib/Defaults/index.d.ts +51 -53
  9. package/lib/Defaults/index.js +106 -107
  10. package/lib/Signal/libsignal.d.ts +3 -3
  11. package/lib/Signal/libsignal.js +161 -152
  12. package/lib/Socket/Client/index.d.ts +2 -2
  13. package/lib/Socket/Client/index.js +18 -18
  14. package/lib/Socket/Client/types.d.ts +15 -17
  15. package/lib/Socket/Client/types.js +13 -13
  16. package/lib/Socket/Client/websocket.d.ts +12 -12
  17. package/lib/Socket/Client/websocket.js +62 -62
  18. package/lib/Socket/business.d.ts +145 -149
  19. package/lib/Socket/business.js +260 -260
  20. package/lib/Socket/chats.d.ts +84 -85
  21. package/lib/Socket/chats.js +879 -850
  22. package/lib/Socket/groups.d.ts +123 -124
  23. package/lib/Socket/groups.js +314 -314
  24. package/lib/Socket/index.d.ts +145 -149
  25. package/lib/Socket/index.js +10 -10
  26. package/lib/Socket/messages-recv.d.ts +134 -136
  27. package/lib/Socket/messages-recv.js +925 -917
  28. package/lib/Socket/messages-send.d.ts +129 -130
  29. package/lib/Socket/messages-send.js +683 -673
  30. package/lib/Socket/socket.d.ts +43 -45
  31. package/lib/Socket/socket.js +622 -622
  32. package/lib/Socket/usync.d.ts +36 -38
  33. package/lib/Socket/usync.js +70 -70
  34. package/lib/Types/Auth.d.ts +103 -105
  35. package/lib/Types/Auth.js +2 -2
  36. package/lib/Types/Call.d.ts +13 -13
  37. package/lib/Types/Call.js +2 -2
  38. package/lib/Types/Chat.d.ts +112 -108
  39. package/lib/Types/Chat.js +4 -4
  40. package/lib/Types/Contact.d.ts +19 -19
  41. package/lib/Types/Contact.js +2 -2
  42. package/lib/Types/Events.d.ts +175 -175
  43. package/lib/Types/Events.js +2 -2
  44. package/lib/Types/GroupMetadata.d.ts +56 -56
  45. package/lib/Types/GroupMetadata.js +2 -2
  46. package/lib/Types/Label.d.ts +46 -46
  47. package/lib/Types/Label.js +27 -27
  48. package/lib/Types/LabelAssociation.d.ts +29 -29
  49. package/lib/Types/LabelAssociation.js +9 -9
  50. package/lib/Types/Message.d.ts +267 -271
  51. package/lib/Types/Message.js +9 -9
  52. package/lib/Types/Product.d.ts +78 -78
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.d.ts +57 -57
  55. package/lib/Types/Signal.js +2 -2
  56. package/lib/Types/Socket.d.ts +121 -118
  57. package/lib/Types/Socket.js +2 -2
  58. package/lib/Types/State.d.ts +27 -27
  59. package/lib/Types/State.js +2 -2
  60. package/lib/Types/USync.d.ts +25 -25
  61. package/lib/Types/USync.js +2 -2
  62. package/lib/Types/index.d.ts +63 -63
  63. package/lib/Types/index.js +41 -41
  64. package/lib/Utils/auth-utils.d.ts +18 -18
  65. package/lib/Utils/auth-utils.js +200 -200
  66. package/lib/Utils/baileys-event-stream.d.ts +16 -16
  67. package/lib/Utils/baileys-event-stream.js +63 -63
  68. package/lib/Utils/business.d.ts +22 -22
  69. package/lib/Utils/business.js +234 -234
  70. package/lib/Utils/chat-utils.d.ts +70 -72
  71. package/lib/Utils/chat-utils.js +745 -745
  72. package/lib/Utils/crypto.d.ts +40 -42
  73. package/lib/Utils/crypto.js +193 -181
  74. package/lib/Utils/decode-wa-message.d.ts +36 -36
  75. package/lib/Utils/decode-wa-message.js +205 -205
  76. package/lib/Utils/event-buffer.d.ts +35 -35
  77. package/lib/Utils/event-buffer.js +520 -520
  78. package/lib/Utils/generics.d.ts +90 -94
  79. package/lib/Utils/generics.js +398 -433
  80. package/lib/Utils/history.d.ts +19 -19
  81. package/lib/Utils/history.js +94 -94
  82. package/lib/Utils/index.d.ts +17 -17
  83. package/lib/Utils/index.js +33 -33
  84. package/lib/Utils/link-preview.d.ts +21 -21
  85. package/lib/Utils/link-preview.js +129 -119
  86. package/lib/Utils/logger.d.ts +11 -11
  87. package/lib/Utils/logger.js +7 -7
  88. package/lib/Utils/lt-hash.d.ts +12 -12
  89. package/lib/Utils/lt-hash.js +51 -51
  90. package/lib/Utils/make-mutex.d.ts +7 -7
  91. package/lib/Utils/make-mutex.js +44 -44
  92. package/lib/Utils/messages-media.d.ts +105 -109
  93. package/lib/Utils/messages-media.js +704 -694
  94. package/lib/Utils/messages.d.ts +75 -78
  95. package/lib/Utils/messages.js +761 -762
  96. package/lib/Utils/noise-handler.d.ts +19 -21
  97. package/lib/Utils/noise-handler.js +150 -150
  98. package/lib/Utils/process-message.d.ts +41 -42
  99. package/lib/Utils/process-message.js +385 -376
  100. package/lib/Utils/signal.d.ts +33 -33
  101. package/lib/Utils/signal.js +153 -153
  102. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -12
  103. package/lib/Utils/use-multi-file-auth-state.js +125 -94
  104. package/lib/Utils/validate-connection.d.ts +10 -10
  105. package/lib/Utils/validate-connection.js +175 -175
  106. package/lib/WABinary/constants.d.ts +27 -27
  107. package/lib/WABinary/constants.js +40 -40
  108. package/lib/WABinary/decode.d.ts +6 -8
  109. package/lib/WABinary/decode.js +264 -254
  110. package/lib/WABinary/encode.d.ts +2 -4
  111. package/lib/WABinary/encode.js +244 -234
  112. package/lib/WABinary/generic-utils.d.ts +14 -16
  113. package/lib/WABinary/generic-utils.js +110 -110
  114. package/lib/WABinary/index.d.ts +5 -5
  115. package/lib/WABinary/index.js +21 -21
  116. package/lib/WABinary/jid-utils.d.ts +33 -31
  117. package/lib/WABinary/jid-utils.js +66 -62
  118. package/lib/WABinary/types.d.ts +18 -18
  119. package/lib/WABinary/types.js +2 -2
  120. package/lib/WAM/BinaryInfo.d.ts +8 -18
  121. package/lib/WAM/BinaryInfo.js +13 -13
  122. package/lib/WAM/constants.d.ts +39 -39
  123. package/lib/WAM/constants.js +15350 -15350
  124. package/lib/WAM/encode.d.ts +2 -4
  125. package/lib/WAM/encode.js +155 -155
  126. package/lib/WAM/index.d.ts +3 -3
  127. package/lib/WAM/index.js +19 -19
  128. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
  129. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -32
  130. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -22
  131. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -57
  132. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -12
  133. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -30
  134. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -12
  135. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -42
  136. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  137. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  138. package/lib/WAUSync/Protocols/index.d.ts +4 -4
  139. package/lib/WAUSync/Protocols/index.js +20 -20
  140. package/lib/WAUSync/USyncQuery.d.ts +26 -26
  141. package/lib/WAUSync/USyncQuery.js +79 -79
  142. package/lib/WAUSync/USyncUser.d.ts +12 -10
  143. package/lib/WAUSync/USyncUser.js +26 -22
  144. package/lib/WAUSync/index.d.ts +3 -3
  145. package/lib/WAUSync/index.js +19 -19
  146. package/lib/index.d.ts +11 -12
  147. package/lib/index.js +30 -31
  148. package/package.json +20 -26
  149. package/WAProto/GenerateStatics.sh +0 -4
@@ -1,234 +1,244 @@
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 (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
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.encodeBinaryNode = void 0;
27
- const constants = __importStar(require("./constants"));
28
- const jid_utils_1 = require("./jid-utils");
29
- const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
30
- const encoded = encodeBinaryNodeInner(node, opts, buffer);
31
- return Buffer.from(encoded);
32
- };
33
- exports.encodeBinaryNode = encodeBinaryNode;
34
- const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
35
- const { TAGS, TOKEN_MAP } = opts;
36
- const pushByte = (value) => buffer.push(value & 0xff);
37
- const pushInt = (value, n, littleEndian = false) => {
38
- for (let i = 0; i < n; i++) {
39
- const curShift = littleEndian ? i : n - 1 - i;
40
- buffer.push((value >> (curShift * 8)) & 0xff);
41
- }
42
- };
43
- const pushBytes = (bytes) => {
44
- for (const b of bytes) {
45
- buffer.push(b);
46
- }
47
- };
48
- const pushInt16 = (value) => {
49
- pushBytes([(value >> 8) & 0xff, value & 0xff]);
50
- };
51
- const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]));
52
- const writeByteLength = (length) => {
53
- if (length >= 4294967296) {
54
- throw new Error('string too large to encode: ' + length);
55
- }
56
- if (length >= 1 << 20) {
57
- pushByte(TAGS.BINARY_32);
58
- pushInt(length, 4); // 32 bit integer
59
- }
60
- else if (length >= 256) {
61
- pushByte(TAGS.BINARY_20);
62
- pushInt20(length);
63
- }
64
- else {
65
- pushByte(TAGS.BINARY_8);
66
- pushByte(length);
67
- }
68
- };
69
- const writeStringRaw = (str) => {
70
- const bytes = Buffer.from(str, 'utf-8');
71
- writeByteLength(bytes.length);
72
- pushBytes(bytes);
73
- };
74
- const writeJid = ({ domainType, device, user, server }) => {
75
- if (typeof device !== 'undefined') {
76
- pushByte(TAGS.AD_JID);
77
- pushByte(domainType || 0);
78
- pushByte(device || 0);
79
- writeString(user);
80
- }
81
- else {
82
- pushByte(TAGS.JID_PAIR);
83
- if (user.length) {
84
- writeString(user);
85
- }
86
- else {
87
- pushByte(TAGS.LIST_EMPTY);
88
- }
89
- writeString(server);
90
- }
91
- };
92
- const packNibble = (char) => {
93
- switch (char) {
94
- case '-':
95
- return 10;
96
- case '.':
97
- return 11;
98
- case '\0':
99
- return 15;
100
- default:
101
- if (char >= '0' && char <= '9') {
102
- return char.charCodeAt(0) - '0'.charCodeAt(0);
103
- }
104
- throw new Error(`invalid byte for nibble "${char}"`);
105
- }
106
- };
107
- const packHex = (char) => {
108
- if (char >= '0' && char <= '9') {
109
- return char.charCodeAt(0) - '0'.charCodeAt(0);
110
- }
111
- if (char >= 'A' && char <= 'F') {
112
- return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
113
- }
114
- if (char >= 'a' && char <= 'f') {
115
- return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
116
- }
117
- if (char === '\0') {
118
- return 15;
119
- }
120
- throw new Error(`Invalid hex char "${char}"`);
121
- };
122
- const writePackedBytes = (str, type) => {
123
- if (str.length > TAGS.PACKED_MAX) {
124
- throw new Error('Too many bytes to pack');
125
- }
126
- pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
127
- let roundedLength = Math.ceil(str.length / 2.0);
128
- if (str.length % 2 !== 0) {
129
- roundedLength |= 128;
130
- }
131
- pushByte(roundedLength);
132
- const packFunction = type === 'nibble' ? packNibble : packHex;
133
- const packBytePair = (v1, v2) => {
134
- const result = (packFunction(v1) << 4) | packFunction(v2);
135
- return result;
136
- };
137
- const strLengthHalf = Math.floor(str.length / 2);
138
- for (let i = 0; i < strLengthHalf; i++) {
139
- pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
140
- }
141
- if (str.length % 2 !== 0) {
142
- pushByte(packBytePair(str[str.length - 1], '\x00'));
143
- }
144
- };
145
- const isNibble = (str) => {
146
- if (str.length > TAGS.PACKED_MAX) {
147
- return false;
148
- }
149
- for (const char of str) {
150
- const isInNibbleRange = char >= '0' && char <= '9';
151
- if (!isInNibbleRange && char !== '-' && char !== '.') {
152
- return false;
153
- }
154
- }
155
- return true;
156
- };
157
- const isHex = (str) => {
158
- if (str.length > TAGS.PACKED_MAX) {
159
- return false;
160
- }
161
- for (const char of str) {
162
- const isInNibbleRange = char >= '0' && char <= '9';
163
- if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
164
- return false;
165
- }
166
- }
167
- return true;
168
- };
169
- const writeString = (str) => {
170
- const tokenIndex = TOKEN_MAP[str];
171
- if (tokenIndex) {
172
- if (typeof tokenIndex.dict === 'number') {
173
- pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
174
- }
175
- pushByte(tokenIndex.index);
176
- }
177
- else if (isNibble(str)) {
178
- writePackedBytes(str, 'nibble');
179
- }
180
- else if (isHex(str)) {
181
- writePackedBytes(str, 'hex');
182
- }
183
- else if (str) {
184
- const decodedJid = (0, jid_utils_1.jidDecode)(str);
185
- if (decodedJid) {
186
- writeJid(decodedJid);
187
- }
188
- else {
189
- writeStringRaw(str);
190
- }
191
- }
192
- };
193
- const writeListStart = (listSize) => {
194
- if (listSize === 0) {
195
- pushByte(TAGS.LIST_EMPTY);
196
- }
197
- else if (listSize < 256) {
198
- pushBytes([TAGS.LIST_8, listSize]);
199
- }
200
- else {
201
- pushByte(TAGS.LIST_16);
202
- pushInt16(listSize);
203
- }
204
- };
205
- const validAttributes = Object.keys(attrs).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
206
- writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
207
- writeString(tag);
208
- for (const key of validAttributes) {
209
- if (typeof attrs[key] === 'string') {
210
- writeString(key);
211
- writeString(attrs[key]);
212
- }
213
- }
214
- if (typeof content === 'string') {
215
- writeString(content);
216
- }
217
- else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
218
- writeByteLength(content.length);
219
- pushBytes(content);
220
- }
221
- else if (Array.isArray(content)) {
222
- writeListStart(content.length);
223
- for (const item of content) {
224
- encodeBinaryNodeInner(item, opts, buffer);
225
- }
226
- }
227
- else if (typeof content === 'undefined') {
228
- // do nothing
229
- }
230
- else {
231
- throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
232
- }
233
- return buffer;
234
- };
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);
42
+ };
43
+ exports.encodeBinaryNode = encodeBinaryNode;
44
+ 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) => {
54
+ for (const b of bytes) {
55
+ buffer.push(b);
56
+ }
57
+ };
58
+ const pushInt16 = (value) => {
59
+ pushBytes([(value >> 8) & 0xff, value & 0xff]);
60
+ };
61
+ const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]));
62
+ const writeByteLength = (length) => {
63
+ if (length >= 4294967296) {
64
+ throw new Error('string too large to encode: ' + length);
65
+ }
66
+ if (length >= 1 << 20) {
67
+ pushByte(TAGS.BINARY_32);
68
+ pushInt(length, 4); // 32 bit integer
69
+ }
70
+ else if (length >= 256) {
71
+ pushByte(TAGS.BINARY_20);
72
+ pushInt20(length);
73
+ }
74
+ else {
75
+ pushByte(TAGS.BINARY_8);
76
+ pushByte(length);
77
+ }
78
+ };
79
+ const writeStringRaw = (str) => {
80
+ const bytes = Buffer.from(str, 'utf-8');
81
+ writeByteLength(bytes.length);
82
+ pushBytes(bytes);
83
+ };
84
+ const writeJid = ({ domainType, device, user, server }) => {
85
+ if (typeof device !== 'undefined') {
86
+ pushByte(TAGS.AD_JID);
87
+ pushByte(domainType || 0);
88
+ pushByte(device || 0);
89
+ writeString(user);
90
+ }
91
+ else {
92
+ pushByte(TAGS.JID_PAIR);
93
+ if (user.length) {
94
+ writeString(user);
95
+ }
96
+ else {
97
+ pushByte(TAGS.LIST_EMPTY);
98
+ }
99
+ writeString(server);
100
+ }
101
+ };
102
+ const packNibble = (char) => {
103
+ switch (char) {
104
+ case '-':
105
+ return 10;
106
+ case '.':
107
+ return 11;
108
+ case '\0':
109
+ return 15;
110
+ default:
111
+ if (char >= '0' && char <= '9') {
112
+ return char.charCodeAt(0) - '0'.charCodeAt(0);
113
+ }
114
+ throw new Error(`invalid byte for nibble "${char}"`);
115
+ }
116
+ };
117
+ const packHex = (char) => {
118
+ if (char >= '0' && char <= '9') {
119
+ return char.charCodeAt(0) - '0'.charCodeAt(0);
120
+ }
121
+ if (char >= 'A' && char <= 'F') {
122
+ return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
123
+ }
124
+ if (char >= 'a' && char <= 'f') {
125
+ return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
126
+ }
127
+ if (char === '\0') {
128
+ return 15;
129
+ }
130
+ throw new Error(`Invalid hex char "${char}"`);
131
+ };
132
+ const writePackedBytes = (str, type) => {
133
+ if (str.length > TAGS.PACKED_MAX) {
134
+ throw new Error('Too many bytes to pack');
135
+ }
136
+ pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
137
+ let roundedLength = Math.ceil(str.length / 2.0);
138
+ if (str.length % 2 !== 0) {
139
+ roundedLength |= 128;
140
+ }
141
+ pushByte(roundedLength);
142
+ const packFunction = type === 'nibble' ? packNibble : packHex;
143
+ const packBytePair = (v1, v2) => {
144
+ const result = (packFunction(v1) << 4) | packFunction(v2);
145
+ return result;
146
+ };
147
+ const strLengthHalf = Math.floor(str.length / 2);
148
+ for (let i = 0; i < strLengthHalf; i++) {
149
+ pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
150
+ }
151
+ if (str.length % 2 !== 0) {
152
+ pushByte(packBytePair(str[str.length - 1], '\x00'));
153
+ }
154
+ };
155
+ const isNibble = (str) => {
156
+ if (str.length > TAGS.PACKED_MAX) {
157
+ return false;
158
+ }
159
+ for (const char of str) {
160
+ const isInNibbleRange = char >= '0' && char <= '9';
161
+ if (!isInNibbleRange && char !== '-' && char !== '.') {
162
+ return false;
163
+ }
164
+ }
165
+ return true;
166
+ };
167
+ const isHex = (str) => {
168
+ if (str.length > TAGS.PACKED_MAX) {
169
+ return false;
170
+ }
171
+ for (const char of str) {
172
+ const isInNibbleRange = char >= '0' && char <= '9';
173
+ if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
174
+ return false;
175
+ }
176
+ }
177
+ return true;
178
+ };
179
+ const writeString = (str) => {
180
+ const tokenIndex = TOKEN_MAP[str];
181
+ if (tokenIndex) {
182
+ if (typeof tokenIndex.dict === 'number') {
183
+ pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
184
+ }
185
+ pushByte(tokenIndex.index);
186
+ }
187
+ else if (isNibble(str)) {
188
+ writePackedBytes(str, 'nibble');
189
+ }
190
+ else if (isHex(str)) {
191
+ writePackedBytes(str, 'hex');
192
+ }
193
+ else if (str) {
194
+ const decodedJid = (0, jid_utils_1.jidDecode)(str);
195
+ if (decodedJid) {
196
+ writeJid(decodedJid);
197
+ }
198
+ else {
199
+ writeStringRaw(str);
200
+ }
201
+ }
202
+ };
203
+ const writeListStart = (listSize) => {
204
+ if (listSize === 0) {
205
+ pushByte(TAGS.LIST_EMPTY);
206
+ }
207
+ else if (listSize < 256) {
208
+ pushBytes([TAGS.LIST_8, listSize]);
209
+ }
210
+ else {
211
+ pushByte(TAGS.LIST_16);
212
+ pushInt16(listSize);
213
+ }
214
+ };
215
+ const validAttributes = Object.keys(attrs).filter(k => (typeof attrs[k] !== 'undefined' && attrs[k] !== null));
216
+ writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
217
+ writeString(tag);
218
+ for (const key of validAttributes) {
219
+ if (typeof attrs[key] === 'string') {
220
+ writeString(key);
221
+ writeString(attrs[key]);
222
+ }
223
+ }
224
+ if (typeof content === 'string') {
225
+ writeString(content);
226
+ }
227
+ else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
228
+ writeByteLength(content.length);
229
+ pushBytes(content);
230
+ }
231
+ else if (Array.isArray(content)) {
232
+ writeListStart(content.length);
233
+ for (const item of content) {
234
+ encodeBinaryNodeInner(item, opts, buffer);
235
+ }
236
+ }
237
+ else if (typeof content === 'undefined') {
238
+ // do nothing
239
+ }
240
+ else {
241
+ throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
242
+ }
243
+ return buffer;
244
+ };
@@ -1,16 +1,14 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { proto } from '../../WAProto';
4
- import { BinaryNode } from './types';
5
- export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
6
- export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
7
- export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
8
- export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array | Buffer | undefined;
9
- export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
10
- export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
11
- export declare const assertNodeErrorFree: (node: BinaryNode) => void;
12
- export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => {
13
- [_: string]: string;
14
- };
15
- export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
16
- export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): any;
1
+ import { proto } from '../../WAProto';
2
+ import { BinaryNode } from './types';
3
+ export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
4
+ export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
5
+ 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 getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
8
+ export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
9
+ export declare const assertNodeErrorFree: (node: BinaryNode) => void;
10
+ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => {
11
+ [_: string]: string;
12
+ };
13
+ export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
14
+ export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): any;