@hiroosy/baileys-lite 0.3.2 → 0.3.4

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 (42) hide show
  1. package/README.md +1 -1
  2. package/WAProto/index.js +1530 -1514
  3. package/package.json +1 -1
  4. package/src/binary/wa-binary.js +4 -2
  5. package/src/defaults.js +2 -1
  6. package/src/foundation/ai-rich.js +1 -19
  7. package/src/foundation/cache.js +99 -24
  8. package/src/foundation/image-thumb.js +5 -106
  9. package/src/foundation/memory.js +103 -0
  10. package/src/signal/libsignal.js +1 -8
  11. package/src/signal/signal-repository.js +6 -4
  12. package/src/socket/chats.js +2 -0
  13. package/src/socket/messages-recv.js +5 -3
  14. package/src/socket/messages-send.js +19 -2
  15. package/src/socket/socket-core.js +3 -0
  16. package/src/utils/auth-state-core.js +2 -1
  17. package/src/utils/chat-sync.js +4 -0
  18. package/src/utils/media.js +16 -11
  19. package/src/utils/message-processing.js +22 -6
  20. package/src/utils/wa-protocol-core.js +6 -5
  21. package/src/wam/wam-constants.js +22 -22851
  22. package/src/wam/wam-data.json +1 -0
  23. package/src/vendor/jpeg-js/decoder.js +0 -1091
  24. package/src/vendor/jpeg-js/encoder.js +0 -739
  25. package/src/vendor/pngjs/LICENSE +0 -20
  26. package/src/vendor/pngjs/bitmapper.js +0 -251
  27. package/src/vendor/pngjs/bitpacker.js +0 -159
  28. package/src/vendor/pngjs/constants.js +0 -30
  29. package/src/vendor/pngjs/crc.js +0 -41
  30. package/src/vendor/pngjs/filter-pack.js +0 -173
  31. package/src/vendor/pngjs/filter-parse-sync.js +0 -21
  32. package/src/vendor/pngjs/filter-parse.js +0 -175
  33. package/src/vendor/pngjs/format-normaliser.js +0 -95
  34. package/src/vendor/pngjs/interlace.js +0 -84
  35. package/src/vendor/pngjs/packer-sync.js +0 -54
  36. package/src/vendor/pngjs/packer.js +0 -130
  37. package/src/vendor/pngjs/paeth-predictor.js +0 -16
  38. package/src/vendor/pngjs/parser-sync.js +0 -113
  39. package/src/vendor/pngjs/parser.js +0 -275
  40. package/src/vendor/pngjs/png-sync.js +0 -12
  41. package/src/vendor/pngjs/sync-inflate.js +0 -165
  42. package/src/vendor/pngjs/sync-reader.js +0 -47
@@ -1,275 +0,0 @@
1
- "use strict";
2
-
3
- import constants from './constants.js'
4
- import CrcCalculator from './crc.js'
5
-
6
- let Parser = function (options, dependencies) {
7
- this._options = options;
8
- options.checkCRC = options.checkCRC !== false;
9
-
10
- this._hasIHDR = false;
11
- this._hasIEND = false;
12
- this._emittedHeadersFinished = false;
13
-
14
- this._palette = [];
15
- this._colorType = 0;
16
-
17
- this._chunks = {};
18
- this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
19
- this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
20
- this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
21
- this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
22
- this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
23
- this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
24
-
25
- this.read = dependencies.read;
26
- this.error = dependencies.error;
27
- this.metadata = dependencies.metadata;
28
- this.gamma = dependencies.gamma;
29
- this.transColor = dependencies.transColor;
30
- this.palette = dependencies.palette;
31
- this.parsed = dependencies.parsed;
32
- this.inflateData = dependencies.inflateData;
33
- this.finished = dependencies.finished;
34
- this.simpleTransparency = dependencies.simpleTransparency;
35
- this.headersFinished = dependencies.headersFinished || function () {};
36
- };
37
-
38
- Parser.prototype.start = function () {
39
- this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
40
- };
41
-
42
- Parser.prototype._parseSignature = function (data) {
43
- let signature = constants.PNG_SIGNATURE;
44
-
45
- for (let i = 0; i < signature.length; i++) {
46
- if (data[i] !== signature[i]) {
47
- this.error(new Error("Invalid file signature"));
48
- return;
49
- }
50
- }
51
- this.read(8, this._parseChunkBegin.bind(this));
52
- };
53
-
54
- Parser.prototype._parseChunkBegin = function (data) {
55
-
56
- let length = data.readUInt32BE(0);
57
-
58
- let type = data.readUInt32BE(4);
59
- let name = "";
60
- for (let i = 4; i < 8; i++) {
61
- name += String.fromCharCode(data[i]);
62
- }
63
-
64
- let ancillary = Boolean(data[4] & 0x20);
65
-
66
- if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
67
- this.error(new Error("Expected IHDR on beggining"));
68
- return;
69
- }
70
-
71
- this._crc = new CrcCalculator();
72
- this._crc.write(Buffer.from(name));
73
-
74
- if (this._chunks[type]) {
75
- return this._chunks[type](length);
76
- }
77
-
78
- if (!ancillary) {
79
- this.error(new Error("Unsupported critical chunk type " + name));
80
- return;
81
- }
82
-
83
- this.read(length + 4, this._skipChunk.bind(this));
84
- };
85
-
86
- Parser.prototype._skipChunk = function () {
87
- this.read(8, this._parseChunkBegin.bind(this));
88
- };
89
-
90
- Parser.prototype._handleChunkEnd = function () {
91
- this.read(4, this._parseChunkEnd.bind(this));
92
- };
93
-
94
- Parser.prototype._parseChunkEnd = function (data) {
95
- let fileCrc = data.readInt32BE(0);
96
- let calcCrc = this._crc.crc32();
97
-
98
- if (this._options.checkCRC && calcCrc !== fileCrc) {
99
- this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
100
- return;
101
- }
102
-
103
- if (!this._hasIEND) {
104
- this.read(8, this._parseChunkBegin.bind(this));
105
- }
106
- };
107
-
108
- Parser.prototype._handleIHDR = function (length) {
109
- this.read(length, this._parseIHDR.bind(this));
110
- };
111
- Parser.prototype._parseIHDR = function (data) {
112
- this._crc.write(data);
113
-
114
- let width = data.readUInt32BE(0);
115
- let height = data.readUInt32BE(4);
116
- let depth = data[8];
117
- let colorType = data[9];
118
- let compr = data[10];
119
- let filter = data[11];
120
- let interlace = data[12];
121
-
122
- if (
123
- depth !== 8 &&
124
- depth !== 4 &&
125
- depth !== 2 &&
126
- depth !== 1 &&
127
- depth !== 16
128
- ) {
129
- this.error(new Error("Unsupported bit depth " + depth));
130
- return;
131
- }
132
- if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
133
- this.error(new Error("Unsupported color type"));
134
- return;
135
- }
136
- if (compr !== 0) {
137
- this.error(new Error("Unsupported compression method"));
138
- return;
139
- }
140
- if (filter !== 0) {
141
- this.error(new Error("Unsupported filter method"));
142
- return;
143
- }
144
- if (interlace !== 0 && interlace !== 1) {
145
- this.error(new Error("Unsupported interlace method"));
146
- return;
147
- }
148
-
149
- this._colorType = colorType;
150
-
151
- let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
152
-
153
- this._hasIHDR = true;
154
-
155
- this.metadata({
156
- width: width,
157
- height: height,
158
- depth: depth,
159
- interlace: Boolean(interlace),
160
- palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
161
- color: Boolean(colorType & constants.COLORTYPE_COLOR),
162
- alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
163
- bpp: bpp,
164
- colorType: colorType,
165
- });
166
-
167
- this._handleChunkEnd();
168
- };
169
-
170
- Parser.prototype._handlePLTE = function (length) {
171
- this.read(length, this._parsePLTE.bind(this));
172
- };
173
- Parser.prototype._parsePLTE = function (data) {
174
- this._crc.write(data);
175
-
176
- let entries = Math.floor(data.length / 3);
177
-
178
- for (let i = 0; i < entries; i++) {
179
- this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 0xff]);
180
- }
181
-
182
- this.palette(this._palette);
183
-
184
- this._handleChunkEnd();
185
- };
186
-
187
- Parser.prototype._handleTRNS = function (length) {
188
- this.simpleTransparency();
189
- this.read(length, this._parseTRNS.bind(this));
190
- };
191
- Parser.prototype._parseTRNS = function (data) {
192
- this._crc.write(data);
193
-
194
- if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
195
- if (this._palette.length === 0) {
196
- this.error(new Error("Transparency chunk must be after palette"));
197
- return;
198
- }
199
- if (data.length > this._palette.length) {
200
- this.error(new Error("More transparent colors than palette size"));
201
- return;
202
- }
203
- for (let i = 0; i < data.length; i++) {
204
- this._palette[i][3] = data[i];
205
- }
206
- this.palette(this._palette);
207
- }
208
-
209
- if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
210
-
211
- this.transColor([data.readUInt16BE(0)]);
212
- }
213
- if (this._colorType === constants.COLORTYPE_COLOR) {
214
- this.transColor([
215
- data.readUInt16BE(0),
216
- data.readUInt16BE(2),
217
- data.readUInt16BE(4),
218
- ]);
219
- }
220
-
221
- this._handleChunkEnd();
222
- };
223
-
224
- Parser.prototype._handleGAMA = function (length) {
225
- this.read(length, this._parseGAMA.bind(this));
226
- };
227
- Parser.prototype._parseGAMA = function (data) {
228
- this._crc.write(data);
229
- this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
230
-
231
- this._handleChunkEnd();
232
- };
233
-
234
- Parser.prototype._handleIDAT = function (length) {
235
- if (!this._emittedHeadersFinished) {
236
- this._emittedHeadersFinished = true;
237
- this.headersFinished();
238
- }
239
- this.read(-length, this._parseIDAT.bind(this, length));
240
- };
241
- Parser.prototype._parseIDAT = function (length, data) {
242
- this._crc.write(data);
243
-
244
- if (
245
- this._colorType === constants.COLORTYPE_PALETTE_COLOR &&
246
- this._palette.length === 0
247
- ) {
248
- throw new Error("Expected palette not found");
249
- }
250
-
251
- this.inflateData(data);
252
- let leftOverLength = length - data.length;
253
-
254
- if (leftOverLength > 0) {
255
- this._handleIDAT(leftOverLength);
256
- } else {
257
- this._handleChunkEnd();
258
- }
259
- };
260
-
261
- Parser.prototype._handleIEND = function (length) {
262
- this.read(length, this._parseIEND.bind(this));
263
- };
264
- Parser.prototype._parseIEND = function (data) {
265
- this._crc.write(data);
266
-
267
- this._hasIEND = true;
268
- this._handleChunkEnd();
269
-
270
- if (this.finished) {
271
- this.finished();
272
- }
273
- };
274
-
275
- export default Parser;
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- import parse from './parser-sync.js'
4
- import pack from './packer-sync.js'
5
-
6
- export const read = function (buffer, options) {
7
- return parse(buffer, options || {});
8
- };
9
-
10
- export const write = function (png, options) {
11
- return pack(png, options);
12
- };
@@ -1,165 +0,0 @@
1
- "use strict";
2
-
3
- import assertModule from 'node:assert'
4
- const assert = assertModule.ok
5
- import zlib from 'node:zlib'
6
- import util from 'node:util'
7
-
8
- import { kMaxLength } from 'node:buffer'
9
-
10
- function Inflate(opts) {
11
- if (!(this instanceof Inflate)) {
12
- return new Inflate(opts);
13
- }
14
-
15
- if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
16
- opts.chunkSize = zlib.Z_MIN_CHUNK;
17
- }
18
-
19
- zlib.Inflate.call(this, opts);
20
-
21
- this._offset = this._offset === undefined ? this._outOffset : this._offset;
22
- this._buffer = this._buffer || this._outBuffer;
23
-
24
- if (opts && opts.maxLength != null) {
25
- this._maxLength = opts.maxLength;
26
- }
27
- }
28
-
29
- function createInflate(opts) {
30
- return new Inflate(opts);
31
- }
32
-
33
- function _close(engine, callback) {
34
- if (callback) {
35
- process.nextTick(callback);
36
- }
37
-
38
- if (!engine._handle) {
39
- return;
40
- }
41
-
42
- engine._handle.close();
43
- engine._handle = null;
44
- }
45
-
46
- Inflate.prototype._processChunk = function (chunk, flushFlag, asyncCb) {
47
- if (typeof asyncCb === "function") {
48
- return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
49
- }
50
-
51
- let self = this;
52
-
53
- let availInBefore = chunk && chunk.length;
54
- let availOutBefore = this._chunkSize - this._offset;
55
- let leftToInflate = this._maxLength;
56
- let inOff = 0;
57
-
58
- let buffers = [];
59
- let nread = 0;
60
-
61
- let error;
62
- this.on("error", function (err) {
63
- error = err;
64
- });
65
-
66
- function handleChunk(availInAfter, availOutAfter) {
67
- if (self._hadError) {
68
- return;
69
- }
70
-
71
- let have = availOutBefore - availOutAfter;
72
- assert(have >= 0, "have should not go down");
73
-
74
- if (have > 0) {
75
- let out = self._buffer.slice(self._offset, self._offset + have);
76
- self._offset += have;
77
-
78
- if (out.length > leftToInflate) {
79
- out = out.slice(0, leftToInflate);
80
- }
81
-
82
- buffers.push(out);
83
- nread += out.length;
84
- leftToInflate -= out.length;
85
-
86
- if (leftToInflate === 0) {
87
- return false;
88
- }
89
- }
90
-
91
- if (availOutAfter === 0 || self._offset >= self._chunkSize) {
92
- availOutBefore = self._chunkSize;
93
- self._offset = 0;
94
- self._buffer = Buffer.allocUnsafe(self._chunkSize);
95
- }
96
-
97
- if (availOutAfter === 0) {
98
- inOff += availInBefore - availInAfter;
99
- availInBefore = availInAfter;
100
-
101
- return true;
102
- }
103
-
104
- return false;
105
- }
106
-
107
- assert(this._handle, "zlib binding closed");
108
- let res;
109
- do {
110
- res = this._handle.writeSync(
111
- flushFlag,
112
- chunk,
113
- inOff,
114
- availInBefore,
115
- this._buffer,
116
- this._offset,
117
- availOutBefore
118
- );
119
-
120
- res = res || this._writeState;
121
- } while (!this._hadError && handleChunk(res[0], res[1]));
122
-
123
- if (this._hadError) {
124
- throw error;
125
- }
126
-
127
- if (nread >= kMaxLength) {
128
- _close(this);
129
- throw new RangeError(
130
- "Cannot create final Buffer. It would be larger than 0x" +
131
- kMaxLength.toString(16) +
132
- " bytes"
133
- );
134
- }
135
-
136
- let buf = Buffer.concat(buffers, nread);
137
- _close(this);
138
-
139
- return buf;
140
- };
141
-
142
- util.inherits(Inflate, zlib.Inflate);
143
-
144
- function zlibBufferSync(engine, buffer) {
145
- if (typeof buffer === "string") {
146
- buffer = Buffer.from(buffer);
147
- }
148
- if (!(buffer instanceof Buffer)) {
149
- throw new TypeError("Not a string or buffer");
150
- }
151
-
152
- let flushFlag = engine._finishFlushFlag;
153
- if (flushFlag == null) {
154
- flushFlag = zlib.Z_FINISH;
155
- }
156
-
157
- return engine._processChunk(buffer, flushFlag);
158
- }
159
-
160
- function inflateSync(buffer, opts) {
161
- return zlibBufferSync(new Inflate(opts), buffer);
162
- }
163
-
164
- export { Inflate, createInflate, inflateSync };
165
- export default inflateSync;
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- let SyncReader = function (buffer) {
4
- this._buffer = buffer;
5
- this._reads = [];
6
- };
7
-
8
- SyncReader.prototype.read = function (length, callback) {
9
- this._reads.push({
10
- length: Math.abs(length),
11
- allowLess: length < 0,
12
- func: callback,
13
- });
14
- };
15
-
16
- SyncReader.prototype.process = function () {
17
-
18
- while (this._reads.length > 0 && this._buffer.length) {
19
- let read = this._reads[0];
20
-
21
- if (
22
- this._buffer.length &&
23
- (this._buffer.length >= read.length || read.allowLess)
24
- ) {
25
-
26
- this._reads.shift();
27
-
28
- let buf = this._buffer;
29
-
30
- this._buffer = buf.slice(read.length);
31
-
32
- read.func.call(this, buf.slice(0, read.length));
33
- } else {
34
- break;
35
- }
36
- }
37
-
38
- if (this._reads.length > 0) {
39
- throw new Error("There are some read requests waitng on finished stream");
40
- }
41
-
42
- if (this._buffer.length > 0) {
43
- throw new Error("unrecognised content at end of stream");
44
- }
45
- };
46
-
47
- export default SyncReader;