@nexustechpro/baileys 2.0.2 → 2.0.6

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 (108) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +924 -1299
  3. package/WAProto/index.js +22 -18
  4. package/lib/Defaults/baileys-version.json +6 -2
  5. package/lib/Defaults/index.js +173 -172
  6. package/lib/Signal/libsignal.js +395 -292
  7. package/lib/Signal/lid-mapping.js +264 -171
  8. package/lib/Socket/Client/index.js +2 -2
  9. package/lib/Socket/Client/types.js +10 -10
  10. package/lib/Socket/Client/websocket.js +45 -310
  11. package/lib/Socket/business.js +375 -375
  12. package/lib/Socket/chats.js +916 -963
  13. package/lib/Socket/communities.js +430 -430
  14. package/lib/Socket/groups.js +342 -342
  15. package/lib/Socket/index.js +21 -22
  16. package/lib/Socket/messages-recv.js +963 -743
  17. package/lib/Socket/messages-send.js +273 -321
  18. package/lib/Socket/mex.js +50 -50
  19. package/lib/Socket/newsletter.js +148 -148
  20. package/lib/Socket/nexus-handler.js +296 -247
  21. package/lib/Socket/registration.js +50 -33
  22. package/lib/Socket/socket.js +872 -1201
  23. package/lib/Store/index.js +5 -5
  24. package/lib/Store/make-cache-manager-store.js +81 -81
  25. package/lib/Store/make-in-memory-store.js +416 -416
  26. package/lib/Store/make-ordered-dictionary.js +81 -81
  27. package/lib/Store/object-repository.js +30 -30
  28. package/lib/Types/Auth.js +1 -1
  29. package/lib/Types/Bussines.js +1 -1
  30. package/lib/Types/Call.js +1 -1
  31. package/lib/Types/Chat.js +7 -7
  32. package/lib/Types/Contact.js +1 -1
  33. package/lib/Types/Events.js +1 -1
  34. package/lib/Types/GroupMetadata.js +1 -1
  35. package/lib/Types/Label.js +24 -24
  36. package/lib/Types/LabelAssociation.js +6 -6
  37. package/lib/Types/Message.js +10 -10
  38. package/lib/Types/Newsletter.js +37 -29
  39. package/lib/Types/Product.js +1 -1
  40. package/lib/Types/Signal.js +1 -1
  41. package/lib/Types/Socket.js +2 -2
  42. package/lib/Types/State.js +55 -12
  43. package/lib/Types/USync.js +1 -1
  44. package/lib/Types/index.js +25 -25
  45. package/lib/Utils/auth-utils.js +264 -256
  46. package/lib/Utils/baileys-event-stream.js +55 -55
  47. package/lib/Utils/browser-utils.js +27 -27
  48. package/lib/Utils/business.js +228 -230
  49. package/lib/Utils/chat-utils.js +726 -764
  50. package/lib/Utils/companion-reg-client-utils.js +34 -0
  51. package/lib/Utils/crypto.js +109 -135
  52. package/lib/Utils/decode-wa-message.js +342 -314
  53. package/lib/Utils/event-buffer.js +547 -547
  54. package/lib/Utils/generics.js +295 -297
  55. package/lib/Utils/history.js +91 -83
  56. package/lib/Utils/index.js +25 -20
  57. package/lib/Utils/key-store.js +17 -0
  58. package/lib/Utils/link-preview.js +107 -98
  59. package/lib/Utils/logger.js +2 -2
  60. package/lib/Utils/lt-hash.js +47 -47
  61. package/lib/Utils/make-mutex.js +39 -39
  62. package/lib/Utils/message-retry-manager.js +148 -148
  63. package/lib/Utils/messages-media.js +579 -535
  64. package/lib/Utils/messages.js +821 -706
  65. package/lib/Utils/noise-handler.js +255 -255
  66. package/lib/Utils/pre-key-manager.js +105 -105
  67. package/lib/Utils/process-message.js +430 -412
  68. package/lib/Utils/reporting-utils.js +155 -0
  69. package/lib/Utils/signal.js +191 -159
  70. package/lib/Utils/sync-action-utils.js +33 -0
  71. package/lib/Utils/tc-token-utils.js +162 -0
  72. package/lib/Utils/use-multi-file-auth-state.js +120 -120
  73. package/lib/Utils/validate-connection.js +194 -194
  74. package/lib/WABinary/constants.js +1306 -1300
  75. package/lib/WABinary/decode.js +237 -237
  76. package/lib/WABinary/encode.js +232 -232
  77. package/lib/WABinary/generic-utils.js +252 -211
  78. package/lib/WABinary/index.js +6 -5
  79. package/lib/WABinary/jid-utils.js +279 -95
  80. package/lib/WABinary/types.js +1 -1
  81. package/lib/WAM/BinaryInfo.js +9 -9
  82. package/lib/WAM/constants.js +22852 -22852
  83. package/lib/WAM/encode.js +149 -149
  84. package/lib/WAM/index.js +3 -3
  85. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -28
  86. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
  87. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
  88. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
  89. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
  90. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
  91. package/lib/WAUSync/Protocols/index.js +4 -4
  92. package/lib/WAUSync/USyncQuery.js +93 -93
  93. package/lib/WAUSync/USyncUser.js +22 -22
  94. package/lib/WAUSync/index.js +3 -3
  95. package/lib/index.js +65 -66
  96. package/package.json +172 -143
  97. package/lib/Signal/Group/ciphertext-message.js +0 -12
  98. package/lib/Signal/Group/group-session-builder.js +0 -30
  99. package/lib/Signal/Group/group_cipher.js +0 -100
  100. package/lib/Signal/Group/index.js +0 -12
  101. package/lib/Signal/Group/keyhelper.js +0 -18
  102. package/lib/Signal/Group/sender-chain-key.js +0 -26
  103. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  104. package/lib/Signal/Group/sender-key-message.js +0 -66
  105. package/lib/Signal/Group/sender-key-name.js +0 -48
  106. package/lib/Signal/Group/sender-key-record.js +0 -41
  107. package/lib/Signal/Group/sender-key-state.js +0 -84
  108. package/lib/Signal/Group/sender-message-key.js +0 -26
@@ -1,238 +1,238 @@
1
- import { promisify } from 'util';
2
- import { inflate } from 'zlib';
3
- import * as constants from './constants.js';
4
- import { jidEncode, WAJIDDomains } from './jid-utils.js';
5
- const inflatePromise = promisify(inflate);
6
- export const decompressingIfRequired = async (buffer) => {
7
- if (2 & buffer.readUInt8()) {
8
- buffer = await inflatePromise(buffer.slice(1));
9
- }
10
- else {
11
- // nodes with no compression have a 0x00 prefix, we remove that
12
- buffer = buffer.slice(1);
13
- }
14
- return buffer;
15
- };
16
- export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
17
- const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts;
18
- const checkEOS = (length) => {
19
- if (indexRef.index + length > buffer.length) {
20
- throw new Error('end of stream');
21
- }
22
- };
23
- const next = () => {
24
- const value = buffer[indexRef.index];
25
- indexRef.index += 1;
26
- return value;
27
- };
28
- const readByte = () => {
29
- checkEOS(1);
30
- return next();
31
- };
32
- const readBytes = (n) => {
33
- checkEOS(n);
34
- const value = buffer.slice(indexRef.index, indexRef.index + n);
35
- indexRef.index += n;
36
- return value;
37
- };
38
- const readStringFromChars = (length) => {
39
- return readBytes(length).toString('utf-8');
40
- };
41
- const readInt = (n, littleEndian = false) => {
42
- checkEOS(n);
43
- let val = 0;
44
- for (let i = 0; i < n; i++) {
45
- const shift = littleEndian ? i : n - 1 - i;
46
- val |= next() << (shift * 8);
47
- }
48
- return val;
49
- };
50
- const readInt20 = () => {
51
- checkEOS(3);
52
- return ((next() & 15) << 16) + (next() << 8) + next();
53
- };
54
- const unpackHex = (value) => {
55
- if (value >= 0 && value < 16) {
56
- return value < 10 ? '0'.charCodeAt(0) + value : 'A'.charCodeAt(0) + value - 10;
57
- }
58
- throw new Error('invalid hex: ' + value);
59
- };
60
- const unpackNibble = (value) => {
61
- if (value >= 0 && value <= 9) {
62
- return '0'.charCodeAt(0) + value;
63
- }
64
- switch (value) {
65
- case 10:
66
- return '-'.charCodeAt(0);
67
- case 11:
68
- return '.'.charCodeAt(0);
69
- case 15:
70
- return '\0'.charCodeAt(0);
71
- default:
72
- throw new Error('invalid nibble: ' + value);
73
- }
74
- };
75
- const unpackByte = (tag, value) => {
76
- if (tag === TAGS.NIBBLE_8) {
77
- return unpackNibble(value);
78
- }
79
- else if (tag === TAGS.HEX_8) {
80
- return unpackHex(value);
81
- }
82
- else {
83
- throw new Error('unknown tag: ' + tag);
84
- }
85
- };
86
- const readPacked8 = (tag) => {
87
- const startByte = readByte();
88
- let value = '';
89
- for (let i = 0; i < (startByte & 127); i++) {
90
- const curByte = readByte();
91
- value += String.fromCharCode(unpackByte(tag, (curByte & 0xf0) >> 4));
92
- value += String.fromCharCode(unpackByte(tag, curByte & 0x0f));
93
- }
94
- if (startByte >> 7 !== 0) {
95
- value = value.slice(0, -1);
96
- }
97
- return value;
98
- };
99
- const isListTag = (tag) => {
100
- return tag === TAGS.LIST_EMPTY || tag === TAGS.LIST_8 || tag === TAGS.LIST_16;
101
- };
102
- const readListSize = (tag) => {
103
- switch (tag) {
104
- case TAGS.LIST_EMPTY:
105
- return 0;
106
- case TAGS.LIST_8:
107
- return readByte();
108
- case TAGS.LIST_16:
109
- return readInt(2);
110
- default:
111
- throw new Error('invalid tag for list size: ' + tag);
112
- }
113
- };
114
- const readJidPair = () => {
115
- const i = readString(readByte());
116
- const j = readString(readByte());
117
- if (j) {
118
- return (i || '') + '@' + j;
119
- }
120
- throw new Error('invalid jid pair: ' + i + ', ' + j);
121
- };
122
- const readAdJid = () => {
123
- const rawDomainType = readByte();
124
- const domainType = Number(rawDomainType);
125
- const device = readByte();
126
- const user = readString(readByte());
127
- let server = 's.whatsapp.net'; // default whatsapp server
128
- if (domainType === WAJIDDomains.LID) {
129
- server = 'lid';
130
- }
131
- else if (domainType === WAJIDDomains.HOSTED) {
132
- server = 'hosted';
133
- }
134
- else if (domainType === WAJIDDomains.HOSTED_LID) {
135
- server = 'hosted.lid';
136
- }
137
- return jidEncode(user, server, device);
138
- };
139
- const readString = (tag) => {
140
- if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
141
- return SINGLE_BYTE_TOKENS[tag] || '';
142
- }
143
- switch (tag) {
144
- case TAGS.DICTIONARY_0:
145
- case TAGS.DICTIONARY_1:
146
- case TAGS.DICTIONARY_2:
147
- case TAGS.DICTIONARY_3:
148
- return getTokenDouble(tag - TAGS.DICTIONARY_0, readByte());
149
- case TAGS.LIST_EMPTY:
150
- return '';
151
- case TAGS.BINARY_8:
152
- return readStringFromChars(readByte());
153
- case TAGS.BINARY_20:
154
- return readStringFromChars(readInt20());
155
- case TAGS.BINARY_32:
156
- return readStringFromChars(readInt(4));
157
- case TAGS.JID_PAIR:
158
- return readJidPair();
159
- case TAGS.AD_JID:
160
- return readAdJid();
161
- case TAGS.HEX_8:
162
- case TAGS.NIBBLE_8:
163
- return readPacked8(tag);
164
- default:
165
- throw new Error('invalid string with tag: ' + tag);
166
- }
167
- };
168
- const readList = (tag) => {
169
- const items = [];
170
- const size = readListSize(tag);
171
- for (let i = 0; i < size; i++) {
172
- items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef));
173
- }
174
- return items;
175
- };
176
- const getTokenDouble = (index1, index2) => {
177
- const dict = DOUBLE_BYTE_TOKENS[index1];
178
- if (!dict) {
179
- throw new Error(`Invalid double token dict (${index1})`);
180
- }
181
- const value = dict[index2];
182
- if (typeof value === 'undefined') {
183
- throw new Error(`Invalid double token (${index2})`);
184
- }
185
- return value;
186
- };
187
- const listSize = readListSize(readByte());
188
- const header = readString(readByte());
189
- if (!listSize || !header.length) {
190
- throw new Error('invalid node');
191
- }
192
- const attrs = {};
193
- let data;
194
- if (listSize === 0 || !header) {
195
- throw new Error('invalid node');
196
- }
197
- // read the attributes in
198
- const attributesLength = (listSize - 1) >> 1;
199
- for (let i = 0; i < attributesLength; i++) {
200
- const key = readString(readByte());
201
- const value = readString(readByte());
202
- attrs[key] = value;
203
- }
204
- if (listSize % 2 === 0) {
205
- const tag = readByte();
206
- if (isListTag(tag)) {
207
- data = readList(tag);
208
- }
209
- else {
210
- let decoded;
211
- switch (tag) {
212
- case TAGS.BINARY_8:
213
- decoded = readBytes(readByte());
214
- break;
215
- case TAGS.BINARY_20:
216
- decoded = readBytes(readInt20());
217
- break;
218
- case TAGS.BINARY_32:
219
- decoded = readBytes(readInt(4));
220
- break;
221
- default:
222
- decoded = readString(tag);
223
- break;
224
- }
225
- data = decoded;
226
- }
227
- }
228
- return {
229
- tag: header,
230
- attrs,
231
- content: data
232
- };
233
- };
234
- export const decodeBinaryNode = async (buff) => {
235
- const decompBuff = await decompressingIfRequired(buff);
236
- return decodeDecompressedBinaryNode(decompBuff, constants);
237
- };
1
+ import { promisify } from 'util';
2
+ import { inflate } from 'zlib';
3
+ import * as constants from './constants.js';
4
+ import { jidEncode, WAJIDDomains } from './jid-utils.js';
5
+ const inflatePromise = promisify(inflate);
6
+ export const decompressingIfRequired = async (buffer) => {
7
+ if (2 & buffer.readUInt8()) {
8
+ buffer = await inflatePromise(buffer.slice(1));
9
+ }
10
+ else {
11
+ // nodes with no compression have a 0x00 prefix, we remove that
12
+ buffer = buffer.slice(1);
13
+ }
14
+ return buffer;
15
+ };
16
+ export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
17
+ const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts;
18
+ const checkEOS = (length) => {
19
+ if (indexRef.index + length > buffer.length) {
20
+ throw new Error('end of stream');
21
+ }
22
+ };
23
+ const next = () => {
24
+ const value = buffer[indexRef.index];
25
+ indexRef.index += 1;
26
+ return value;
27
+ };
28
+ const readByte = () => {
29
+ checkEOS(1);
30
+ return next();
31
+ };
32
+ const readBytes = (n) => {
33
+ checkEOS(n);
34
+ const value = buffer.slice(indexRef.index, indexRef.index + n);
35
+ indexRef.index += n;
36
+ return value;
37
+ };
38
+ const readStringFromChars = (length) => {
39
+ return readBytes(length).toString('utf-8');
40
+ };
41
+ const readInt = (n, littleEndian = false) => {
42
+ checkEOS(n);
43
+ let val = 0;
44
+ for (let i = 0; i < n; i++) {
45
+ const shift = littleEndian ? i : n - 1 - i;
46
+ val |= next() << (shift * 8);
47
+ }
48
+ return val;
49
+ };
50
+ const readInt20 = () => {
51
+ checkEOS(3);
52
+ return ((next() & 15) << 16) + (next() << 8) + next();
53
+ };
54
+ const unpackHex = (value) => {
55
+ if (value >= 0 && value < 16) {
56
+ return value < 10 ? '0'.charCodeAt(0) + value : 'A'.charCodeAt(0) + value - 10;
57
+ }
58
+ throw new Error('invalid hex: ' + value);
59
+ };
60
+ const unpackNibble = (value) => {
61
+ if (value >= 0 && value <= 9) {
62
+ return '0'.charCodeAt(0) + value;
63
+ }
64
+ switch (value) {
65
+ case 10:
66
+ return '-'.charCodeAt(0);
67
+ case 11:
68
+ return '.'.charCodeAt(0);
69
+ case 15:
70
+ return '\0'.charCodeAt(0);
71
+ default:
72
+ throw new Error('invalid nibble: ' + value);
73
+ }
74
+ };
75
+ const unpackByte = (tag, value) => {
76
+ if (tag === TAGS.NIBBLE_8) {
77
+ return unpackNibble(value);
78
+ }
79
+ else if (tag === TAGS.HEX_8) {
80
+ return unpackHex(value);
81
+ }
82
+ else {
83
+ throw new Error('unknown tag: ' + tag);
84
+ }
85
+ };
86
+ const readPacked8 = (tag) => {
87
+ const startByte = readByte();
88
+ let value = '';
89
+ for (let i = 0; i < (startByte & 127); i++) {
90
+ const curByte = readByte();
91
+ value += String.fromCharCode(unpackByte(tag, (curByte & 0xf0) >> 4));
92
+ value += String.fromCharCode(unpackByte(tag, curByte & 0x0f));
93
+ }
94
+ if (startByte >> 7 !== 0) {
95
+ value = value.slice(0, -1);
96
+ }
97
+ return value;
98
+ };
99
+ const isListTag = (tag) => {
100
+ return tag === TAGS.LIST_EMPTY || tag === TAGS.LIST_8 || tag === TAGS.LIST_16;
101
+ };
102
+ const readListSize = (tag) => {
103
+ switch (tag) {
104
+ case TAGS.LIST_EMPTY:
105
+ return 0;
106
+ case TAGS.LIST_8:
107
+ return readByte();
108
+ case TAGS.LIST_16:
109
+ return readInt(2);
110
+ default:
111
+ throw new Error('invalid tag for list size: ' + tag);
112
+ }
113
+ };
114
+ const readJidPair = () => {
115
+ const i = readString(readByte());
116
+ const j = readString(readByte());
117
+ if (j) {
118
+ return (i || '') + '@' + j;
119
+ }
120
+ throw new Error('invalid jid pair: ' + i + ', ' + j);
121
+ };
122
+ const readAdJid = () => {
123
+ const rawDomainType = readByte();
124
+ const domainType = Number(rawDomainType);
125
+ const device = readByte();
126
+ const user = readString(readByte());
127
+ let server = 's.whatsapp.net'; // default whatsapp server
128
+ if (domainType === WAJIDDomains.LID) {
129
+ server = 'lid';
130
+ }
131
+ else if (domainType === WAJIDDomains.HOSTED) {
132
+ server = 'hosted';
133
+ }
134
+ else if (domainType === WAJIDDomains.HOSTED_LID) {
135
+ server = 'hosted.lid';
136
+ }
137
+ return jidEncode(user, server, device);
138
+ };
139
+ const readString = (tag) => {
140
+ if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
141
+ return SINGLE_BYTE_TOKENS[tag] || '';
142
+ }
143
+ switch (tag) {
144
+ case TAGS.DICTIONARY_0:
145
+ case TAGS.DICTIONARY_1:
146
+ case TAGS.DICTIONARY_2:
147
+ case TAGS.DICTIONARY_3:
148
+ return getTokenDouble(tag - TAGS.DICTIONARY_0, readByte());
149
+ case TAGS.LIST_EMPTY:
150
+ return '';
151
+ case TAGS.BINARY_8:
152
+ return readStringFromChars(readByte());
153
+ case TAGS.BINARY_20:
154
+ return readStringFromChars(readInt20());
155
+ case TAGS.BINARY_32:
156
+ return readStringFromChars(readInt(4));
157
+ case TAGS.JID_PAIR:
158
+ return readJidPair();
159
+ case TAGS.AD_JID:
160
+ return readAdJid();
161
+ case TAGS.HEX_8:
162
+ case TAGS.NIBBLE_8:
163
+ return readPacked8(tag);
164
+ default:
165
+ throw new Error('invalid string with tag: ' + tag);
166
+ }
167
+ };
168
+ const readList = (tag) => {
169
+ const items = [];
170
+ const size = readListSize(tag);
171
+ for (let i = 0; i < size; i++) {
172
+ items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef));
173
+ }
174
+ return items;
175
+ };
176
+ const getTokenDouble = (index1, index2) => {
177
+ const dict = DOUBLE_BYTE_TOKENS[index1];
178
+ if (!dict) {
179
+ throw new Error(`Invalid double token dict (${index1})`);
180
+ }
181
+ const value = dict[index2];
182
+ if (typeof value === 'undefined') {
183
+ throw new Error(`Invalid double token (${index2})`);
184
+ }
185
+ return value;
186
+ };
187
+ const listSize = readListSize(readByte());
188
+ const header = readString(readByte());
189
+ if (!listSize || !header.length) {
190
+ throw new Error('invalid node');
191
+ }
192
+ const attrs = {};
193
+ let data;
194
+ if (listSize === 0 || !header) {
195
+ throw new Error('invalid node');
196
+ }
197
+ // read the attributes in
198
+ const attributesLength = (listSize - 1) >> 1;
199
+ for (let i = 0; i < attributesLength; i++) {
200
+ const key = readString(readByte());
201
+ const value = readString(readByte());
202
+ attrs[key] = value;
203
+ }
204
+ if (listSize % 2 === 0) {
205
+ const tag = readByte();
206
+ if (isListTag(tag)) {
207
+ data = readList(tag);
208
+ }
209
+ else {
210
+ let decoded;
211
+ switch (tag) {
212
+ case TAGS.BINARY_8:
213
+ decoded = readBytes(readByte());
214
+ break;
215
+ case TAGS.BINARY_20:
216
+ decoded = readBytes(readInt20());
217
+ break;
218
+ case TAGS.BINARY_32:
219
+ decoded = readBytes(readInt(4));
220
+ break;
221
+ default:
222
+ decoded = readString(tag);
223
+ break;
224
+ }
225
+ data = decoded;
226
+ }
227
+ }
228
+ return {
229
+ tag: header,
230
+ attrs,
231
+ content: data
232
+ };
233
+ };
234
+ export const decodeBinaryNode = async (buff) => {
235
+ const decompBuff = await decompressingIfRequired(buff);
236
+ return decodeDecompressedBinaryNode(decompBuff, constants);
237
+ };
238
238
  //# sourceMappingURL=decode.js.map