@vinzsocket/baileys 2.8.10 → 2.8.30

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 (83) hide show
  1. package/lib/Defaults/index.js +75 -73
  2. package/lib/Signal/Group/ciphertext-message.js +9 -9
  3. package/lib/Signal/Group/group-session-builder.js +21 -21
  4. package/lib/Signal/Group/group_cipher.js +79 -81
  5. package/lib/Signal/Group/index.js +2 -2
  6. package/lib/Signal/Group/keyhelper.js +9 -9
  7. package/lib/Signal/Group/queue-job.js +43 -46
  8. package/lib/Signal/Group/sender-chain-key.js +24 -25
  9. package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
  10. package/lib/Signal/Group/sender-key-message.js +55 -60
  11. package/lib/Signal/Group/sender-key-name.js +38 -39
  12. package/lib/Signal/Group/sender-key-record.js +39 -41
  13. package/lib/Signal/Group/sender-key-state.js +85 -89
  14. package/lib/Signal/Group/sender-message-key.js +22 -22
  15. package/lib/Signal/libsignal.js +387 -292
  16. package/lib/Signal/lid-mapping.js +98 -93
  17. package/lib/Socket/Client/types.js +6 -6
  18. package/lib/Socket/Client/websocket.js +44 -44
  19. package/lib/Socket/business.js +350 -365
  20. package/lib/Socket/chats.js +1019 -914
  21. package/lib/Socket/communities.js +454 -376
  22. package/lib/Socket/groups.js +378 -310
  23. package/lib/Socket/index.js +11 -11
  24. package/lib/Socket/messages-recv.js +1355 -1182
  25. package/lib/Socket/messages-send.js +1224 -1081
  26. package/lib/Socket/mex.js +40 -34
  27. package/lib/Socket/newsletter.js +212 -169
  28. package/lib/Socket/socket.js +896 -757
  29. package/lib/Store/index.js +1 -1
  30. package/lib/Store/make-cache-manager-store.js +75 -79
  31. package/lib/Store/make-in-memory-store.js +450 -389
  32. package/lib/Store/make-ordered-dictionary.js +73 -76
  33. package/lib/Store/object-repository.js +24 -22
  34. package/lib/Types/Chat.js +1 -7
  35. package/lib/Types/Label.js +20 -20
  36. package/lib/Types/LabelAssociation.js +2 -2
  37. package/lib/Types/Message.js +2 -2
  38. package/lib/Types/Newsletter.js +24 -24
  39. package/lib/Types/Socket.js +1 -1
  40. package/lib/Types/State.js +8 -8
  41. package/lib/Types/index.js +10 -10
  42. package/lib/Utils/auth-utils.js +408 -401
  43. package/lib/Utils/baileys-event-stream.js +44 -35
  44. package/lib/Utils/business.js +200 -197
  45. package/lib/Utils/chat-utils.js +775 -708
  46. package/lib/Utils/crypto.js +97 -85
  47. package/lib/Utils/decode-wa-message.js +240 -227
  48. package/lib/Utils/event-buffer.js +547 -518
  49. package/lib/Utils/extended-messages.js +250 -203
  50. package/lib/Utils/generics.js +300 -289
  51. package/lib/Utils/history.js +76 -69
  52. package/lib/Utils/lid-resolver.js +47 -42
  53. package/lib/Utils/link-preview.js +75 -65
  54. package/lib/Utils/logger.js +3 -1
  55. package/lib/Utils/lt-hash.js +38 -34
  56. package/lib/Utils/make-mutex.js +32 -34
  57. package/lib/Utils/mention.js +79 -86
  58. package/lib/Utils/message-retry-manager.js +148 -136
  59. package/lib/Utils/messages-media.js +652 -562
  60. package/lib/Utils/messages.js +753 -707
  61. package/lib/Utils/noise-handler.js +156 -135
  62. package/lib/Utils/process-message.js +404 -341
  63. package/lib/Utils/signal.js +180 -118
  64. package/lib/Utils/use-multi-file-auth-state.js +87 -91
  65. package/lib/Utils/validate-connection.js +167 -142
  66. package/lib/WABinary/constants.js +28 -1293
  67. package/lib/WABinary/decode.js +220 -218
  68. package/lib/WABinary/encode.js +199 -201
  69. package/lib/WABinary/generic-utils.js +80 -77
  70. package/lib/WABinary/jid-utils.js +41 -35
  71. package/lib/WAM/BinaryInfo.js +7 -7
  72. package/lib/WAM/constants.js +1 -15241
  73. package/lib/WAM/encode.js +124 -131
  74. package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
  75. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
  76. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
  77. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
  78. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
  79. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
  80. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
  81. package/lib/WAUSync/USyncQuery.js +82 -84
  82. package/lib/WAUSync/USyncUser.js +20 -20
  83. package/package.json +4 -2
@@ -1,216 +1,214 @@
1
1
  import * as constants from './constants.js';
2
2
  import { jidDecode } from './jid-utils.js';
3
3
  export const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
4
- const encoded = encodeBinaryNodeInner(node, opts, buffer);
5
- return Buffer.from(encoded);
4
+ const encoded = encodeBinaryNodeInner(node, opts, buffer);
5
+ return Buffer.from(encoded);
6
6
  };
7
- const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
8
- const { TAGS, TOKEN_MAP } = opts;
9
- const pushByte = (value) => buffer.push(value & 0xff);
10
- const pushInt = (value, n, littleEndian = false) => {
11
- for (let i = 0; i < n; i++) {
12
- const curShift = littleEndian ? i : n - 1 - i;
13
- buffer.push((value >> (curShift * 8)) & 0xff);
14
- }
15
- };
16
- const pushBytes = (bytes) => {
17
- for (const b of bytes) {
18
- buffer.push(b);
19
- }
20
- };
21
- const pushInt16 = (value) => {
22
- pushBytes([(value >> 8) & 0xff, value & 0xff]);
23
- };
24
- const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
25
- const writeByteLength = (length) => {
26
- if (length >= 4294967296) {
27
- throw new Error('string too large to encode: ' + length);
28
- }
29
- if (length >= 1 << 20) {
30
- pushByte(TAGS.BINARY_32);
31
- pushInt(length, 4); // 32 bit integer
32
- }
33
- else if (length >= 256) {
34
- pushByte(TAGS.BINARY_20);
35
- pushInt20(length);
36
- }
37
- else {
38
- pushByte(TAGS.BINARY_8);
39
- pushByte(length);
40
- }
41
- };
42
- const writeStringRaw = (str) => {
43
- const bytes = Buffer.from(str, 'utf-8');
44
- writeByteLength(bytes.length);
45
- pushBytes(bytes);
46
- };
47
- const writeJid = ({ domainType, device, user, server }) => {
48
- if (typeof device !== 'undefined') {
49
- pushByte(TAGS.AD_JID);
50
- pushByte(domainType || 0);
51
- pushByte(device || 0);
52
- writeString(user);
53
- }
54
- else {
55
- pushByte(TAGS.JID_PAIR);
56
- if (user.length) {
57
- writeString(user);
58
- }
59
- else {
60
- pushByte(TAGS.LIST_EMPTY);
61
- }
62
- writeString(server);
63
- }
64
- };
65
- const packNibble = (char) => {
66
- switch (char) {
67
- case '-':
68
- return 10;
69
- case '.':
70
- return 11;
71
- case '\0':
72
- return 15;
73
- default:
74
- if (char >= '0' && char <= '9') {
75
- return char.charCodeAt(0) - '0'.charCodeAt(0);
76
- }
77
- throw new Error(`invalid byte for nibble "${char}"`);
78
- }
79
- };
80
- const packHex = (char) => {
7
+ const encodeBinaryNodeInner = ({
8
+ tag,
9
+ attrs,
10
+ content
11
+ }, opts, buffer) => {
12
+ const {
13
+ TAGS,
14
+ TOKEN_MAP
15
+ } = opts;
16
+ const pushByte = value => buffer.push(value & 0xff);
17
+ const pushInt = (value, n, littleEndian = false) => {
18
+ for (let i = 0; i < n; i++) {
19
+ const curShift = littleEndian ? i : n - 1 - i;
20
+ buffer.push(value >> curShift * 8 & 0xff);
21
+ }
22
+ };
23
+ const pushBytes = bytes => {
24
+ for (const b of bytes) {
25
+ buffer.push(b);
26
+ }
27
+ };
28
+ const pushInt16 = value => {
29
+ pushBytes([value >> 8 & 0xff, value & 0xff]);
30
+ };
31
+ const pushInt20 = value => pushBytes([value >> 16 & 0x0f, value >> 8 & 0xff, value & 0xff]);
32
+ const writeByteLength = length => {
33
+ if (length >= 4294967296) {
34
+ throw new Error('string too large to encode: ' + length);
35
+ }
36
+ if (length >= 1 << 20) {
37
+ pushByte(TAGS.BINARY_32);
38
+ pushInt(length, 4); // 32 bit integer
39
+ } else if (length >= 256) {
40
+ pushByte(TAGS.BINARY_20);
41
+ pushInt20(length);
42
+ } else {
43
+ pushByte(TAGS.BINARY_8);
44
+ pushByte(length);
45
+ }
46
+ };
47
+ const writeStringRaw = str => {
48
+ const bytes = Buffer.from(str, 'utf-8');
49
+ writeByteLength(bytes.length);
50
+ pushBytes(bytes);
51
+ };
52
+ const writeJid = ({
53
+ domainType,
54
+ device,
55
+ user,
56
+ server
57
+ }) => {
58
+ if (typeof device !== 'undefined') {
59
+ pushByte(TAGS.AD_JID);
60
+ pushByte(domainType || 0);
61
+ pushByte(device || 0);
62
+ writeString(user);
63
+ } else {
64
+ pushByte(TAGS.JID_PAIR);
65
+ if (user.length) {
66
+ writeString(user);
67
+ } else {
68
+ pushByte(TAGS.LIST_EMPTY);
69
+ }
70
+ writeString(server);
71
+ }
72
+ };
73
+ const packNibble = char => {
74
+ switch (char) {
75
+ case '-':
76
+ return 10;
77
+ case '.':
78
+ return 11;
79
+ case '\0':
80
+ return 15;
81
+ default:
81
82
  if (char >= '0' && char <= '9') {
82
- return char.charCodeAt(0) - '0'.charCodeAt(0);
83
- }
84
- if (char >= 'A' && char <= 'F') {
85
- return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
86
- }
87
- if (char >= 'a' && char <= 'f') {
88
- return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
89
- }
90
- if (char === '\0') {
91
- return 15;
92
- }
93
- throw new Error(`Invalid hex char "${char}"`);
94
- };
95
- const writePackedBytes = (str, type) => {
96
- if (str.length > TAGS.PACKED_MAX) {
97
- throw new Error('Too many bytes to pack');
98
- }
99
- pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
100
- let roundedLength = Math.ceil(str.length / 2.0);
101
- if (str.length % 2 !== 0) {
102
- roundedLength |= 128;
103
- }
104
- pushByte(roundedLength);
105
- const packFunction = type === 'nibble' ? packNibble : packHex;
106
- const packBytePair = (v1, v2) => {
107
- const result = (packFunction(v1) << 4) | packFunction(v2);
108
- return result;
109
- };
110
- const strLengthHalf = Math.floor(str.length / 2);
111
- for (let i = 0; i < strLengthHalf; i++) {
112
- pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
113
- }
114
- if (str.length % 2 !== 0) {
115
- pushByte(packBytePair(str[str.length - 1], '\x00'));
116
- }
117
- };
118
- const isNibble = (str) => {
119
- if (!str || str.length > TAGS.PACKED_MAX) {
120
- return false;
121
- }
122
- for (const char of str) {
123
- const isInNibbleRange = char >= '0' && char <= '9';
124
- if (!isInNibbleRange && char !== '-' && char !== '.') {
125
- return false;
126
- }
127
- }
128
- return true;
129
- };
130
- const isHex = (str) => {
131
- if (!str || str.length > TAGS.PACKED_MAX) {
132
- return false;
133
- }
134
- for (const char of str) {
135
- const isInNibbleRange = char >= '0' && char <= '9';
136
- if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
137
- return false;
138
- }
139
- }
140
- return true;
141
- };
142
- const writeString = (str) => {
143
- if (str === undefined || str === null) {
144
- pushByte(TAGS.LIST_EMPTY);
145
- return;
146
- }
147
- const tokenIndex = TOKEN_MAP[str];
148
- if (tokenIndex) {
149
- if (typeof tokenIndex.dict === 'number') {
150
- pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
151
- }
152
- pushByte(tokenIndex.index);
153
- }
154
- else if (isNibble(str)) {
155
- writePackedBytes(str, 'nibble');
156
- }
157
- else if (isHex(str)) {
158
- writePackedBytes(str, 'hex');
159
- }
160
- else if (str) {
161
- const decodedJid = jidDecode(str);
162
- if (decodedJid) {
163
- writeJid(decodedJid);
164
- }
165
- else {
166
- writeStringRaw(str);
167
- }
168
- }
169
- };
170
- const writeListStart = (listSize) => {
171
- if (listSize === 0) {
172
- pushByte(TAGS.LIST_EMPTY);
173
- }
174
- else if (listSize < 256) {
175
- pushBytes([TAGS.LIST_8, listSize]);
176
- }
177
- else {
178
- pushByte(TAGS.LIST_16);
179
- pushInt16(listSize);
83
+ return char.charCodeAt(0) - '0'.charCodeAt(0);
180
84
  }
85
+ throw new Error(`invalid byte for nibble "${char}"`);
86
+ }
87
+ };
88
+ const packHex = char => {
89
+ if (char >= '0' && char <= '9') {
90
+ return char.charCodeAt(0) - '0'.charCodeAt(0);
91
+ }
92
+ if (char >= 'A' && char <= 'F') {
93
+ return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
94
+ }
95
+ if (char >= 'a' && char <= 'f') {
96
+ return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
97
+ }
98
+ if (char === '\0') {
99
+ return 15;
100
+ }
101
+ throw new Error(`Invalid hex char "${char}"`);
102
+ };
103
+ const writePackedBytes = (str, type) => {
104
+ if (str.length > TAGS.PACKED_MAX) {
105
+ throw new Error('Too many bytes to pack');
106
+ }
107
+ pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
108
+ let roundedLength = Math.ceil(str.length / 2.0);
109
+ if (str.length % 2 !== 0) {
110
+ roundedLength |= 128;
111
+ }
112
+ pushByte(roundedLength);
113
+ const packFunction = type === 'nibble' ? packNibble : packHex;
114
+ const packBytePair = (v1, v2) => {
115
+ const result = packFunction(v1) << 4 | packFunction(v2);
116
+ return result;
181
117
  };
182
- if (!tag) {
183
- throw new Error('Invalid node: tag cannot be undefined');
184
- }
185
- const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
186
- writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
187
- writeString(tag);
188
- for (const key of validAttributes) {
189
- if (typeof attrs[key] === 'string') {
190
- writeString(key);
191
- writeString(attrs[key]);
192
- }
118
+ const strLengthHalf = Math.floor(str.length / 2);
119
+ for (let i = 0; i < strLengthHalf; i++) {
120
+ pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
193
121
  }
194
- if (typeof content === 'string') {
195
- writeString(content);
122
+ if (str.length % 2 !== 0) {
123
+ pushByte(packBytePair(str[str.length - 1], '\x00'));
196
124
  }
197
- else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
198
- writeByteLength(content.length);
199
- pushBytes(content);
125
+ };
126
+ const isNibble = str => {
127
+ if (!str || str.length > TAGS.PACKED_MAX) {
128
+ return false;
200
129
  }
201
- else if (Array.isArray(content)) {
202
- const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
203
- writeListStart(validContent.length);
204
- for (const item of validContent) {
205
- encodeBinaryNodeInner(item, opts, buffer);
206
- }
130
+ for (const char of str) {
131
+ const isInNibbleRange = char >= '0' && char <= '9';
132
+ if (!isInNibbleRange && char !== '-' && char !== '.') {
133
+ return false;
134
+ }
135
+ }
136
+ return true;
137
+ };
138
+ const isHex = str => {
139
+ if (!str || str.length > TAGS.PACKED_MAX) {
140
+ return false;
141
+ }
142
+ for (const char of str) {
143
+ const isInNibbleRange = char >= '0' && char <= '9';
144
+ if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
145
+ return false;
146
+ }
147
+ }
148
+ return true;
149
+ };
150
+ const writeString = str => {
151
+ if (str === undefined || str === null) {
152
+ pushByte(TAGS.LIST_EMPTY);
153
+ return;
154
+ }
155
+ const tokenIndex = TOKEN_MAP[str];
156
+ if (tokenIndex) {
157
+ if (typeof tokenIndex.dict === 'number') {
158
+ pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
159
+ }
160
+ pushByte(tokenIndex.index);
161
+ } else if (isNibble(str)) {
162
+ writePackedBytes(str, 'nibble');
163
+ } else if (isHex(str)) {
164
+ writePackedBytes(str, 'hex');
165
+ } else if (str) {
166
+ const decodedJid = jidDecode(str);
167
+ if (decodedJid) {
168
+ writeJid(decodedJid);
169
+ } else {
170
+ writeStringRaw(str);
171
+ }
172
+ }
173
+ };
174
+ const writeListStart = listSize => {
175
+ if (listSize === 0) {
176
+ pushByte(TAGS.LIST_EMPTY);
177
+ } else if (listSize < 256) {
178
+ pushBytes([TAGS.LIST_8, listSize]);
179
+ } else {
180
+ pushByte(TAGS.LIST_16);
181
+ pushInt16(listSize);
207
182
  }
208
- else if (typeof content === 'undefined') {
209
- // do nothing
183
+ };
184
+ if (!tag) {
185
+ throw new Error('Invalid node: tag cannot be undefined');
186
+ }
187
+ const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
188
+ writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
189
+ writeString(tag);
190
+ for (const key of validAttributes) {
191
+ if (typeof attrs[key] === 'string') {
192
+ writeString(key);
193
+ writeString(attrs[key]);
210
194
  }
211
- else {
212
- throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
195
+ }
196
+ if (typeof content === 'string') {
197
+ writeString(content);
198
+ } else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
199
+ writeByteLength(content.length);
200
+ pushBytes(content);
201
+ } else if (Array.isArray(content)) {
202
+ const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
203
+ writeListStart(validContent.length);
204
+ for (const item of validContent) {
205
+ encodeBinaryNodeInner(item, opts, buffer);
213
206
  }
214
- return buffer;
207
+ } else if (typeof content === 'undefined') {
208
+ // do nothing
209
+ } else {
210
+ throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
211
+ }
212
+ return buffer;
215
213
  };
216
214
  //# sourceMappingURL=encode.js.map
@@ -1,102 +1,105 @@
1
1
  import { Boom } from '@hapi/boom';
2
2
  import { proto } from '../../WAProto/index.js';
3
- import {} from './types.js';
3
+ import './types.js';
4
4
  // some extra useful utilities
5
5
  export const getBinaryNodeChildren = (node, childTag) => {
6
- if (Array.isArray(node?.content)) {
7
- return node.content.filter(item => item.tag === childTag);
8
- }
9
- return [];
6
+ if (Array.isArray(node?.content)) {
7
+ return node.content.filter(item => item.tag === childTag);
8
+ }
9
+ return [];
10
10
  };
11
- export const getAllBinaryNodeChildren = ({ content }) => {
12
- if (Array.isArray(content)) {
13
- return content;
14
- }
15
- return [];
11
+ export const getAllBinaryNodeChildren = ({
12
+ content
13
+ }) => {
14
+ if (Array.isArray(content)) {
15
+ return content;
16
+ }
17
+ return [];
16
18
  };
17
19
  export const getBinaryNodeChild = (node, childTag) => {
18
- if (Array.isArray(node?.content)) {
19
- return node?.content.find(item => item.tag === childTag);
20
- }
20
+ if (Array.isArray(node?.content)) {
21
+ return node?.content.find(item => item.tag === childTag);
22
+ }
21
23
  };
22
24
  export const getBinaryNodeChildBuffer = (node, childTag) => {
23
- const child = getBinaryNodeChild(node, childTag)?.content;
24
- if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
25
- return child;
26
- }
25
+ const child = getBinaryNodeChild(node, childTag)?.content;
26
+ if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
27
+ return child;
28
+ }
27
29
  };
28
30
  export const getBinaryNodeChildString = (node, childTag) => {
29
- const child = getBinaryNodeChild(node, childTag)?.content;
30
- if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
31
- return Buffer.from(child).toString('utf-8');
32
- }
33
- else if (typeof child === 'string') {
34
- return child;
35
- }
31
+ const child = getBinaryNodeChild(node, childTag)?.content;
32
+ if (Buffer.isBuffer(child) || child instanceof Uint8Array) {
33
+ return Buffer.from(child).toString('utf-8');
34
+ } else if (typeof child === 'string') {
35
+ return child;
36
+ }
36
37
  };
37
38
  export const getBinaryNodeChildUInt = (node, childTag, length) => {
38
- const buff = getBinaryNodeChildBuffer(node, childTag);
39
- if (buff) {
40
- return bufferToUInt(buff, length);
41
- }
39
+ const buff = getBinaryNodeChildBuffer(node, childTag);
40
+ if (buff) {
41
+ return bufferToUInt(buff, length);
42
+ }
42
43
  };
43
- export const assertNodeErrorFree = (node) => {
44
- const errNode = getBinaryNodeChild(node, 'error');
45
- if (errNode) {
46
- throw new Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code });
47
- }
44
+ export const assertNodeErrorFree = node => {
45
+ const errNode = getBinaryNodeChild(node, 'error');
46
+ if (errNode) {
47
+ throw new Boom(errNode.attrs.text || 'Unknown error', {
48
+ data: +errNode.attrs.code
49
+ });
50
+ }
48
51
  };
49
52
  export const reduceBinaryNodeToDictionary = (node, tag) => {
50
- const nodes = getBinaryNodeChildren(node, tag);
51
- const dict = nodes.reduce((dict, { attrs }) => {
52
- if (typeof attrs.name === 'string') {
53
- dict[attrs.name] = attrs.value || attrs.config_value;
54
- }
55
- else {
56
- dict[attrs.config_code] = attrs.value || attrs.config_value;
57
- }
58
- return dict;
59
- }, {});
53
+ const nodes = getBinaryNodeChildren(node, tag);
54
+ const dict = nodes.reduce((dict, {
55
+ attrs
56
+ }) => {
57
+ if (typeof attrs.name === 'string') {
58
+ dict[attrs.name] = attrs.value || attrs.config_value;
59
+ } else {
60
+ dict[attrs.config_code] = attrs.value || attrs.config_value;
61
+ }
60
62
  return dict;
63
+ }, {});
64
+ return dict;
61
65
  };
62
- export const getBinaryNodeMessages = ({ content }) => {
63
- const msgs = [];
64
- if (Array.isArray(content)) {
65
- for (const item of content) {
66
- if (item.tag === 'message') {
67
- msgs.push(proto.WebMessageInfo.decode(item.content));
68
- }
69
- }
66
+ export const getBinaryNodeMessages = ({
67
+ content
68
+ }) => {
69
+ const msgs = [];
70
+ if (Array.isArray(content)) {
71
+ for (const item of content) {
72
+ if (item.tag === 'message') {
73
+ msgs.push(proto.WebMessageInfo.decode(item.content));
74
+ }
70
75
  }
71
- return msgs;
76
+ }
77
+ return msgs;
72
78
  };
73
79
  function bufferToUInt(e, t) {
74
- let a = 0;
75
- for (let i = 0; i < t; i++) {
76
- a = 256 * a + e[i];
77
- }
78
- return a;
80
+ let a = 0;
81
+ for (let i = 0; i < t; i++) {
82
+ a = 256 * a + e[i];
83
+ }
84
+ return a;
79
85
  }
80
- const tabs = (n) => '\t'.repeat(n);
86
+ const tabs = n => '\t'.repeat(n);
81
87
  export function binaryNodeToString(node, i = 0) {
82
- if (!node) {
83
- return node;
84
- }
85
- if (typeof node === 'string') {
86
- return tabs(i) + node;
87
- }
88
- if (node instanceof Uint8Array) {
89
- return tabs(i) + Buffer.from(node).toString('hex');
90
- }
91
- if (Array.isArray(node)) {
92
- return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
93
- }
94
- const children = binaryNodeToString(node.content, i + 1);
95
- const tag = `<${node.tag} ${Object.entries(node.attrs || {})
96
- .filter(([, v]) => v !== undefined)
97
- .map(([k, v]) => `${k}='${v}'`)
98
- .join(' ')}`;
99
- const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
100
- return tag + content;
88
+ if (!node) {
89
+ return node;
90
+ }
91
+ if (typeof node === 'string') {
92
+ return tabs(i) + node;
93
+ }
94
+ if (node instanceof Uint8Array) {
95
+ return tabs(i) + Buffer.from(node).toString('hex');
96
+ }
97
+ if (Array.isArray(node)) {
98
+ return node.map(x => tabs(i + 1) + binaryNodeToString(x, i + 1)).join('\n');
99
+ }
100
+ const children = binaryNodeToString(node.content, i + 1);
101
+ const tag = `<${node.tag} ${Object.entries(node.attrs || {}).filter(([, v]) => v !== undefined).map(([k, v]) => `${k}='${v}'`).join(' ')}`;
102
+ const content = children ? `>\n${children}\n${tabs(i)}</${node.tag}>` : '/>';
103
+ return tag + content;
101
104
  }
102
105
  //# sourceMappingURL=generic-utils.js.map