@hiroosy/baileys-lite 0.0.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.
- package/README.md +25 -0
- package/WAProto/index.d.ts +15932 -0
- package/WAProto/index.js +115856 -0
- package/engine-requirements.js +11 -0
- package/package.json +27 -0
- package/src/binary/wa-binary-constants.js +1300 -0
- package/src/binary/wa-binary.js +649 -0
- package/src/constants.js +143 -0
- package/src/defaults.js +102 -0
- package/src/foundation/audio-duration.js +530 -0
- package/src/foundation/audio-samples.js +268 -0
- package/src/foundation/boom.js +46 -0
- package/src/foundation/cache.js +142 -0
- package/src/foundation/concurrency.js +87 -0
- package/src/foundation/curve25519.js +221 -0
- package/src/foundation/link-preview.js +320 -0
- package/src/foundation/logger.js +69 -0
- package/src/foundation/long.js +140 -0
- package/src/foundation/protobuf-minimal.js +619 -0
- package/src/foundation/wa-crypto.js +76 -0
- package/src/foundation/zip.js +124 -0
- package/src/index.js +48 -0
- package/src/signal/libsignal.js +1051 -0
- package/src/signal/signal-group.js +487 -0
- package/src/signal/signal-repository.js +646 -0
- package/src/socket/business-communities.js +830 -0
- package/src/socket/chats.js +674 -0
- package/src/socket/groups-newsletter.js +342 -0
- package/src/socket/messages-recv.js +1835 -0
- package/src/socket/messages-send.js +1202 -0
- package/src/socket/socket-core.js +833 -0
- package/src/socket/usync.js +291 -0
- package/src/socket-client/websocket-client.js +124 -0
- package/src/utils/auth-state-core.js +764 -0
- package/src/utils/auth-state-storage.js +316 -0
- package/src/utils/chat-sync.js +1045 -0
- package/src/utils/media.js +841 -0
- package/src/utils/message-compose.js +1609 -0
- package/src/utils/message-processing.js +958 -0
- package/src/utils/wa-protocol-core.js +1283 -0
- package/src/vendor/jpeg-js/LICENSE +25 -0
- package/src/vendor/jpeg-js/decoder.js +1152 -0
- package/src/vendor/jpeg-js/encoder.js +824 -0
- package/src/vendor/pngjs/LICENSE +20 -0
- package/src/vendor/pngjs/bitmapper.js +273 -0
- package/src/vendor/pngjs/bitpacker.js +167 -0
- package/src/vendor/pngjs/constants.js +38 -0
- package/src/vendor/pngjs/crc.js +47 -0
- package/src/vendor/pngjs/filter-pack.js +179 -0
- package/src/vendor/pngjs/filter-parse-sync.js +27 -0
- package/src/vendor/pngjs/filter-parse.js +185 -0
- package/src/vendor/pngjs/format-normaliser.js +101 -0
- package/src/vendor/pngjs/interlace.js +101 -0
- package/src/vendor/pngjs/packer-sync.js +65 -0
- package/src/vendor/pngjs/packer.js +138 -0
- package/src/vendor/pngjs/paeth-predictor.js +22 -0
- package/src/vendor/pngjs/parser-sync.js +121 -0
- package/src/vendor/pngjs/parser.js +299 -0
- package/src/vendor/pngjs/png-sync.js +19 -0
- package/src/vendor/pngjs/sync-inflate.js +174 -0
- package/src/vendor/pngjs/sync-reader.js +54 -0
- package/src/wam/wam-constants.js +22853 -0
- package/src/wam/wam.js +151 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { deflateRawSync, crc32 } from 'node:zlib'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Replaces fflate's `zip()`. Baileys only uses it once, to build a WhatsApp
|
|
5
|
+
* sticker-pack .zip from `{ filename: [Uint8Array, { level }] }`, always with
|
|
6
|
+
* `level: 0` (store, no compression) for the entries it controls. This
|
|
7
|
+
* implementation supports store (level 0) and deflate (level > 0) so it's a
|
|
8
|
+
* drop-in for the one call site and any similar future one.
|
|
9
|
+
*
|
|
10
|
+
* Produces a standard ZIP: local file headers + data, then a central
|
|
11
|
+
* directory + end-of-central-directory record. No zip64, no encryption,
|
|
12
|
+
* no directory entries — matches what `zip()` from fflate produces for a
|
|
13
|
+
* flat file map.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function dosDateTime(date = new Date()) {
|
|
17
|
+
const dosTime = (date.getHours() << 11) | (date.getMinutes() << 5) | (date.getSeconds() >> 1)
|
|
18
|
+
const dosDate = ((date.getFullYear() - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate()
|
|
19
|
+
return { dosTime, dosDate }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function crc32Of(buf) {
|
|
23
|
+
// node:zlib exposes crc32 as of Node 21+; fall back to a small table-based impl otherwise.
|
|
24
|
+
if (typeof crc32 === 'function') return crc32(buf) >>> 0
|
|
25
|
+
return crc32Fallback(buf)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let CRC_TABLE
|
|
29
|
+
function crc32Fallback(buf) {
|
|
30
|
+
if (!CRC_TABLE) {
|
|
31
|
+
CRC_TABLE = new Uint32Array(256)
|
|
32
|
+
for (let n = 0; n < 256; n++) {
|
|
33
|
+
let c = n
|
|
34
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1
|
|
35
|
+
CRC_TABLE[n] = c >>> 0
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
let crc = 0xffffffff
|
|
39
|
+
for (let i = 0; i < buf.length; i++) {
|
|
40
|
+
crc = CRC_TABLE[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8)
|
|
41
|
+
}
|
|
42
|
+
return (crc ^ 0xffffffff) >>> 0
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param files {Record<string, [Uint8Array, { level?: number }?]>}
|
|
47
|
+
* @param callback {(err: Error|null, data?: Uint8Array) => void}
|
|
48
|
+
*/
|
|
49
|
+
export function zip(files, callback) {
|
|
50
|
+
try {
|
|
51
|
+
const localChunks = []
|
|
52
|
+
const centralChunks = []
|
|
53
|
+
let offset = 0
|
|
54
|
+
const { dosTime, dosDate } = dosDateTime()
|
|
55
|
+
|
|
56
|
+
for (const filename of Object.keys(files)) {
|
|
57
|
+
const [rawData, opts = {}] = files[filename]
|
|
58
|
+
const data = Buffer.isBuffer(rawData) ? rawData : Buffer.from(rawData)
|
|
59
|
+
const level = opts.level ?? 6
|
|
60
|
+
const store = level === 0
|
|
61
|
+
const compressed = store ? data : deflateRawSync(data, { level })
|
|
62
|
+
const method = store ? 0 : 8 // 0 = stored, 8 = deflate
|
|
63
|
+
const crc = crc32Of(data)
|
|
64
|
+
const nameBuf = Buffer.from(filename, 'utf8')
|
|
65
|
+
|
|
66
|
+
const localHeader = Buffer.alloc(30)
|
|
67
|
+
localHeader.writeUInt32LE(0x04034b50, 0) // local file header signature
|
|
68
|
+
localHeader.writeUInt16LE(20, 4) // version needed
|
|
69
|
+
localHeader.writeUInt16LE(0, 6) // flags
|
|
70
|
+
localHeader.writeUInt16LE(method, 8)
|
|
71
|
+
localHeader.writeUInt16LE(dosTime, 10)
|
|
72
|
+
localHeader.writeUInt16LE(dosDate, 12)
|
|
73
|
+
localHeader.writeUInt32LE(crc, 14)
|
|
74
|
+
localHeader.writeUInt32LE(compressed.length, 18)
|
|
75
|
+
localHeader.writeUInt32LE(data.length, 22)
|
|
76
|
+
localHeader.writeUInt16LE(nameBuf.length, 26)
|
|
77
|
+
localHeader.writeUInt16LE(0, 28) // extra field length
|
|
78
|
+
|
|
79
|
+
localChunks.push(localHeader, nameBuf, compressed)
|
|
80
|
+
|
|
81
|
+
const centralHeader = Buffer.alloc(46)
|
|
82
|
+
centralHeader.writeUInt32LE(0x02014b50, 0) // central directory signature
|
|
83
|
+
centralHeader.writeUInt16LE(20, 4) // version made by
|
|
84
|
+
centralHeader.writeUInt16LE(20, 6) // version needed
|
|
85
|
+
centralHeader.writeUInt16LE(0, 8) // flags
|
|
86
|
+
centralHeader.writeUInt16LE(method, 10)
|
|
87
|
+
centralHeader.writeUInt16LE(dosTime, 12)
|
|
88
|
+
centralHeader.writeUInt16LE(dosDate, 14)
|
|
89
|
+
centralHeader.writeUInt32LE(crc, 16)
|
|
90
|
+
centralHeader.writeUInt32LE(compressed.length, 20)
|
|
91
|
+
centralHeader.writeUInt32LE(data.length, 24)
|
|
92
|
+
centralHeader.writeUInt16LE(nameBuf.length, 28)
|
|
93
|
+
centralHeader.writeUInt16LE(0, 30) // extra field length
|
|
94
|
+
centralHeader.writeUInt16LE(0, 32) // comment length
|
|
95
|
+
centralHeader.writeUInt16LE(0, 34) // disk number start
|
|
96
|
+
centralHeader.writeUInt16LE(0, 36) // internal attrs
|
|
97
|
+
centralHeader.writeUInt32LE(0, 38) // external attrs
|
|
98
|
+
centralHeader.writeUInt32LE(offset, 42) // offset of local header
|
|
99
|
+
|
|
100
|
+
centralChunks.push(centralHeader, nameBuf)
|
|
101
|
+
|
|
102
|
+
offset += localHeader.length + nameBuf.length + compressed.length
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const centralDirSize = centralChunks.reduce((sum, c) => sum + c.length, 0)
|
|
106
|
+
const centralDirOffset = offset
|
|
107
|
+
const fileCount = Object.keys(files).length
|
|
108
|
+
|
|
109
|
+
const eocd = Buffer.alloc(22)
|
|
110
|
+
eocd.writeUInt32LE(0x06054b50, 0) // end of central directory signature
|
|
111
|
+
eocd.writeUInt16LE(0, 4) // disk number
|
|
112
|
+
eocd.writeUInt16LE(0, 6) // disk with central dir
|
|
113
|
+
eocd.writeUInt16LE(fileCount, 8) // entries on this disk
|
|
114
|
+
eocd.writeUInt16LE(fileCount, 10) // total entries
|
|
115
|
+
eocd.writeUInt32LE(centralDirSize, 12)
|
|
116
|
+
eocd.writeUInt32LE(centralDirOffset, 16)
|
|
117
|
+
eocd.writeUInt16LE(0, 20) // comment length
|
|
118
|
+
|
|
119
|
+
const result = Buffer.concat([...localChunks, ...centralChunks, eocd])
|
|
120
|
+
callback(null, result)
|
|
121
|
+
} catch (err) {
|
|
122
|
+
callback(err)
|
|
123
|
+
}
|
|
124
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* baileys-lite entry point. Mirrors the original lib/index.js export surface
|
|
3
|
+
* (Socket/index.js + the Utils/Types/Defaults/WABinary/WAM/WAUSync barrels),
|
|
4
|
+
* pointing at the consolidated files.
|
|
5
|
+
*/
|
|
6
|
+
import { DEFAULT_CONNECTION_CONFIG } from './defaults.js'
|
|
7
|
+
import { makeCommunitiesSocket } from './socket/business-communities.js'
|
|
8
|
+
|
|
9
|
+
// export the last socket layer (Socket/index.js in the original)
|
|
10
|
+
const makeWASocket = config => {
|
|
11
|
+
const newConfig = {
|
|
12
|
+
...DEFAULT_CONNECTION_CONFIG,
|
|
13
|
+
...config,
|
|
14
|
+
// object spread does NOT skip explicit `undefined`/`null` values, so a
|
|
15
|
+
// caller passing `logger: undefined` (e.g. a stale/missing logger ref
|
|
16
|
+
// on reconnect) would silently wipe out DEFAULT_CONNECTION_CONFIG's
|
|
17
|
+
// logger and crash later in makeNoiseHandler's `logger.child(...)`.
|
|
18
|
+
// Guard against that here, once, at the single entry point.
|
|
19
|
+
logger: config?.logger ?? DEFAULT_CONNECTION_CONFIG.logger
|
|
20
|
+
}
|
|
21
|
+
return makeCommunitiesSocket(newConfig)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// protobuf (was ../WAProto/index.js)
|
|
25
|
+
export * from '../WAProto/index.js'
|
|
26
|
+
|
|
27
|
+
// was Types/
|
|
28
|
+
export * from './constants.js'
|
|
29
|
+
// was Defaults/
|
|
30
|
+
export * from './defaults.js'
|
|
31
|
+
// was WABinary/
|
|
32
|
+
export * from './binary/wa-binary.js'
|
|
33
|
+
// was WAM/
|
|
34
|
+
export * from './wam/wam.js'
|
|
35
|
+
export * from './wam/wam-constants.js'
|
|
36
|
+
// was WAUSync/
|
|
37
|
+
export * from './socket/usync.js'
|
|
38
|
+
// was Utils/
|
|
39
|
+
export * from './utils/wa-protocol-core.js'
|
|
40
|
+
export * from './utils/auth-state-core.js'
|
|
41
|
+
export * from './utils/auth-state-storage.js'
|
|
42
|
+
export * from './utils/media.js'
|
|
43
|
+
export * from './utils/message-compose.js'
|
|
44
|
+
export * from './utils/chat-sync.js'
|
|
45
|
+
export * from './utils/message-processing.js'
|
|
46
|
+
|
|
47
|
+
export { makeWASocket }
|
|
48
|
+
export default makeWASocket
|