@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
package/src/wam/wam.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WAM (telemetry) binary encoder. Combines BinaryInfo.js + encode.js.
|
|
3
|
+
* WEB_EVENTS/WEB_GLOBALS/flag constants (wam-constants.js) are a pure,
|
|
4
|
+
* effectively auto-generated data table — kept as its own file, unedited.
|
|
5
|
+
*/
|
|
6
|
+
import { FLAG_BYTE, FLAG_EVENT, FLAG_EXTENDED, FLAG_FIELD, FLAG_GLOBAL, WEB_EVENTS, WEB_GLOBALS } from './wam-constants.js'
|
|
7
|
+
|
|
8
|
+
export class BinaryInfo {
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.protocolVersion = 5
|
|
11
|
+
this.sequence = 0
|
|
12
|
+
this.events = []
|
|
13
|
+
this.buffer = []
|
|
14
|
+
Object.assign(this, options)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const getHeaderBitLength = key => (key < 256 ? 2 : 3)
|
|
19
|
+
|
|
20
|
+
export const encodeWAM = binaryInfo => {
|
|
21
|
+
binaryInfo.buffer = []
|
|
22
|
+
encodeWAMHeader(binaryInfo)
|
|
23
|
+
encodeEvents(binaryInfo)
|
|
24
|
+
const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b)
|
|
25
|
+
const buffer = Buffer.alloc(totalSize)
|
|
26
|
+
let offset = 0
|
|
27
|
+
for (const buffer_ of binaryInfo.buffer) {
|
|
28
|
+
buffer_.copy(buffer, offset)
|
|
29
|
+
offset += buffer_.length
|
|
30
|
+
}
|
|
31
|
+
return buffer
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function encodeWAMHeader(binaryInfo) {
|
|
35
|
+
const headerBuffer = Buffer.alloc(8)
|
|
36
|
+
headerBuffer.write('WAM', 0, 'utf8')
|
|
37
|
+
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
|
|
38
|
+
headerBuffer.writeUInt8(1, 4) // random flag
|
|
39
|
+
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5)
|
|
40
|
+
headerBuffer.writeUInt8(0, 7) // regular channel
|
|
41
|
+
binaryInfo.buffer.push(headerBuffer)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
45
|
+
for (const [key, _value] of Object.entries(globals)) {
|
|
46
|
+
const id = WEB_GLOBALS.find(a => a?.name === key).id
|
|
47
|
+
let value = _value
|
|
48
|
+
if (typeof value === 'boolean') value = value ? 1 : 0
|
|
49
|
+
binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL))
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function encodeEvents(binaryInfo) {
|
|
54
|
+
for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
|
|
55
|
+
encodeGlobalAttributes(binaryInfo, globals)
|
|
56
|
+
const event = WEB_EVENTS.find(a => a.name === name)
|
|
57
|
+
const props_ = Object.entries(props)
|
|
58
|
+
let extended = false
|
|
59
|
+
for (const [, value] of props_) extended || (extended = value !== null)
|
|
60
|
+
const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED
|
|
61
|
+
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
|
|
62
|
+
for (let i = 0; i < props_.length; i++) {
|
|
63
|
+
const [key, _value] = props_[i]
|
|
64
|
+
const id = event.props[key]?.[0]
|
|
65
|
+
extended = i < props_.length - 1
|
|
66
|
+
let value = _value
|
|
67
|
+
if (typeof value === 'boolean') value = value ? 1 : 0
|
|
68
|
+
const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED
|
|
69
|
+
binaryInfo.buffer.push(serializeData(id, value, fieldFlag))
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function serializeData(key, value, flag) {
|
|
75
|
+
const bufferLength = getHeaderBitLength(key)
|
|
76
|
+
let buffer
|
|
77
|
+
let offset = 0
|
|
78
|
+
if (value === null) {
|
|
79
|
+
if (flag === FLAG_GLOBAL) {
|
|
80
|
+
buffer = Buffer.alloc(bufferLength)
|
|
81
|
+
serializeHeader(buffer, offset, key, flag)
|
|
82
|
+
return buffer
|
|
83
|
+
}
|
|
84
|
+
} else if (typeof value === 'number' && Number.isInteger(value)) {
|
|
85
|
+
if (value === 0 || value === 1) {
|
|
86
|
+
buffer = Buffer.alloc(bufferLength)
|
|
87
|
+
serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
|
|
88
|
+
return buffer
|
|
89
|
+
} else if (-128 <= value && value < 128) {
|
|
90
|
+
buffer = Buffer.alloc(bufferLength + 1)
|
|
91
|
+
offset = serializeHeader(buffer, offset, key, flag | (3 << 4))
|
|
92
|
+
buffer.writeInt8(value, offset)
|
|
93
|
+
return buffer
|
|
94
|
+
} else if (-32768 <= value && value < 32768) {
|
|
95
|
+
buffer = Buffer.alloc(bufferLength + 2)
|
|
96
|
+
offset = serializeHeader(buffer, offset, key, flag | (4 << 4))
|
|
97
|
+
buffer.writeInt16LE(value, offset)
|
|
98
|
+
return buffer
|
|
99
|
+
} else if (-2147483648 <= value && value < 2147483648) {
|
|
100
|
+
buffer = Buffer.alloc(bufferLength + 4)
|
|
101
|
+
offset = serializeHeader(buffer, offset, key, flag | (5 << 4))
|
|
102
|
+
buffer.writeInt32LE(value, offset)
|
|
103
|
+
return buffer
|
|
104
|
+
} else {
|
|
105
|
+
buffer = Buffer.alloc(bufferLength + 8)
|
|
106
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
|
|
107
|
+
buffer.writeDoubleLE(value, offset)
|
|
108
|
+
return buffer
|
|
109
|
+
}
|
|
110
|
+
} else if (typeof value === 'number') {
|
|
111
|
+
buffer = Buffer.alloc(bufferLength + 8)
|
|
112
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
|
|
113
|
+
buffer.writeDoubleLE(value, offset)
|
|
114
|
+
return buffer
|
|
115
|
+
} else if (typeof value === 'string') {
|
|
116
|
+
const utf8Bytes = Buffer.byteLength(value, 'utf8')
|
|
117
|
+
if (utf8Bytes < 256) {
|
|
118
|
+
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
|
|
119
|
+
offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
|
|
120
|
+
buffer.writeUint8(utf8Bytes, offset++)
|
|
121
|
+
} else if (utf8Bytes < 65536) {
|
|
122
|
+
buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes)
|
|
123
|
+
offset = serializeHeader(buffer, offset, key, flag | (9 << 4))
|
|
124
|
+
buffer.writeUInt16LE(utf8Bytes, offset)
|
|
125
|
+
offset += 2
|
|
126
|
+
} else {
|
|
127
|
+
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes)
|
|
128
|
+
offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
|
|
129
|
+
buffer.writeUInt32LE(utf8Bytes, offset)
|
|
130
|
+
offset += 4
|
|
131
|
+
}
|
|
132
|
+
buffer.write(value, offset, 'utf8')
|
|
133
|
+
return buffer
|
|
134
|
+
}
|
|
135
|
+
throw new Error('missing')
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function serializeHeader(buffer, offset, key, flag) {
|
|
139
|
+
if (key < 256) {
|
|
140
|
+
buffer.writeUInt8(flag, offset)
|
|
141
|
+
offset += 1
|
|
142
|
+
buffer.writeUInt8(key, offset)
|
|
143
|
+
offset += 1
|
|
144
|
+
} else {
|
|
145
|
+
buffer.writeUInt8(flag | FLAG_BYTE, offset)
|
|
146
|
+
offset += 1
|
|
147
|
+
buffer.writeUInt16LE(key, offset)
|
|
148
|
+
offset += 2
|
|
149
|
+
}
|
|
150
|
+
return offset
|
|
151
|
+
}
|