@hansaka02/baileys 7.3.4 → 7.3.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.
- package/README.md +203 -247
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/connection.js +1 -1
- package/lib/Defaults/constants.js +13 -1
- package/lib/Defaults/history.js +3 -1
- package/lib/Signal/Group/sender-chain-key.js +1 -14
- package/lib/Signal/Group/sender-key-distribution-message.js +2 -2
- package/lib/Signal/Group/sender-key-record.js +2 -11
- package/lib/Signal/Group/sender-key-state.js +11 -57
- package/lib/Signal/libsignal.js +200 -116
- package/lib/Signal/lid-mapping.js +121 -68
- package/lib/Socket/Client/websocket.js +9 -2
- package/lib/Socket/business.js +5 -1
- package/lib/Socket/chats.js +180 -89
- package/lib/Socket/community.js +169 -41
- package/lib/Socket/groups.js +25 -21
- package/lib/Socket/messages-recv.js +458 -333
- package/lib/Socket/messages-send.js +517 -572
- package/lib/Socket/mex.js +61 -0
- package/lib/Socket/newsletter.js +159 -252
- package/lib/Socket/socket.js +283 -100
- package/lib/Types/Newsletter.js +32 -25
- package/lib/Utils/auth-utils.js +189 -354
- package/lib/Utils/browser-utils.js +43 -0
- package/lib/Utils/chat-utils.js +166 -41
- package/lib/Utils/decode-wa-message.js +77 -35
- package/lib/Utils/event-buffer.js +80 -24
- package/lib/Utils/generics.js +28 -128
- package/lib/Utils/history.js +10 -8
- package/lib/Utils/index.js +1 -1
- package/lib/Utils/link-preview.js +17 -32
- package/lib/Utils/lt-hash.js +28 -22
- package/lib/Utils/make-mutex.js +26 -28
- package/lib/Utils/message-retry-manager.js +51 -3
- package/lib/Utils/messages-media.js +343 -151
- package/lib/Utils/messages.js +806 -792
- package/lib/Utils/noise-handler.js +33 -2
- package/lib/Utils/pre-key-manager.js +126 -0
- package/lib/Utils/process-message.js +115 -55
- package/lib/Utils/signal.js +45 -18
- package/lib/Utils/validate-connection.js +52 -29
- package/lib/WABinary/constants.js +1268 -1268
- package/lib/WABinary/decode.js +58 -4
- package/lib/WABinary/encode.js +54 -7
- package/lib/WABinary/jid-utils.js +58 -11
- package/lib/WAM/constants.js +19064 -11563
- package/lib/WAM/encode.js +57 -8
- package/lib/WAUSync/USyncQuery.js +35 -19
- package/package.json +9 -8
- package/lib/Socket/usync.js +0 -83
package/lib/WAM/encode.js
CHANGED
|
@@ -17,20 +17,23 @@ const encodeWAM = (binaryInfo) => {
|
|
|
17
17
|
binaryInfo.buffer = []
|
|
18
18
|
encodeWAMHeader(binaryInfo)
|
|
19
19
|
encodeEvents(binaryInfo)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.reduce((a, b) => a + b)
|
|
20
|
+
|
|
21
|
+
const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b)
|
|
23
22
|
const buffer = Buffer.alloc(totalSize)
|
|
23
|
+
|
|
24
24
|
let offset = 0
|
|
25
|
+
|
|
25
26
|
for (const buffer_ of binaryInfo.buffer) {
|
|
26
27
|
buffer_.copy(buffer, offset)
|
|
27
28
|
offset += buffer_.length
|
|
28
29
|
}
|
|
30
|
+
|
|
29
31
|
return buffer
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
function encodeWAMHeader(binaryInfo) {
|
|
33
35
|
const headerBuffer = Buffer.alloc(8) // starting buffer
|
|
36
|
+
|
|
34
37
|
headerBuffer.write('WAM', 0, 'utf8')
|
|
35
38
|
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
|
|
36
39
|
headerBuffer.writeUInt8(1, 4) //random flag
|
|
@@ -41,35 +44,49 @@ function encodeWAMHeader(binaryInfo) {
|
|
|
41
44
|
|
|
42
45
|
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
43
46
|
for (const [key, _value] of Object.entries(globals)) {
|
|
44
|
-
const id = WEB_GLOBALS.find(a => a?.name === key)
|
|
47
|
+
const id = WEB_GLOBALS.find(a => a?.name === key).id
|
|
48
|
+
|
|
45
49
|
let value = _value
|
|
50
|
+
|
|
46
51
|
if (typeof value === 'boolean') {
|
|
47
52
|
value = value ? 1 : 0
|
|
48
53
|
}
|
|
54
|
+
|
|
49
55
|
binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL))
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
function encodeEvents(binaryInfo) {
|
|
54
|
-
for (const [name, { props, globals }
|
|
60
|
+
for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
|
|
55
61
|
encodeGlobalAttributes(binaryInfo, globals)
|
|
56
|
-
|
|
62
|
+
|
|
63
|
+
const event = WEB_EVENTS.find(a => a.name === name)
|
|
57
64
|
const props_ = Object.entries(props)
|
|
65
|
+
|
|
58
66
|
let extended = false
|
|
67
|
+
|
|
59
68
|
for (const [, value] of props_) {
|
|
60
69
|
extended || (extended = value !== null)
|
|
61
70
|
}
|
|
71
|
+
|
|
62
72
|
const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED
|
|
73
|
+
|
|
63
74
|
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
|
|
75
|
+
|
|
64
76
|
for (let i = 0; i < props_.length; i++) {
|
|
65
77
|
const [key, _value] = props_[i]
|
|
66
|
-
const id =
|
|
67
|
-
|
|
78
|
+
const id = event.props[key]?.[0]
|
|
79
|
+
|
|
80
|
+
extended = i < props_.length - 1
|
|
81
|
+
|
|
68
82
|
let value = _value
|
|
83
|
+
|
|
69
84
|
if (typeof value === 'boolean') {
|
|
70
85
|
value = value ? 1 : 0
|
|
71
86
|
}
|
|
87
|
+
|
|
72
88
|
const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED
|
|
89
|
+
|
|
73
90
|
binaryInfo.buffer.push(serializeData(id, value, fieldFlag))
|
|
74
91
|
}
|
|
75
92
|
}
|
|
@@ -77,77 +94,107 @@ function encodeEvents(binaryInfo) {
|
|
|
77
94
|
|
|
78
95
|
function serializeData(key, value, flag) {
|
|
79
96
|
const bufferLength = getHeaderBitLength(key)
|
|
97
|
+
|
|
80
98
|
let buffer
|
|
81
99
|
let offset = 0
|
|
100
|
+
|
|
82
101
|
if (value === null) {
|
|
83
102
|
if (flag === FLAG_GLOBAL) {
|
|
84
103
|
buffer = Buffer.alloc(bufferLength)
|
|
85
104
|
offset = serializeHeader(buffer, offset, key, flag)
|
|
105
|
+
|
|
86
106
|
return buffer
|
|
87
107
|
}
|
|
88
108
|
}
|
|
109
|
+
|
|
89
110
|
else if (typeof value === 'number' && Number.isInteger(value)) {
|
|
90
111
|
// is number
|
|
91
112
|
if (value === 0 || value === 1) {
|
|
92
113
|
buffer = Buffer.alloc(bufferLength)
|
|
93
114
|
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
|
|
115
|
+
|
|
94
116
|
return buffer
|
|
95
117
|
}
|
|
118
|
+
|
|
96
119
|
else if (-128 <= value && value < 128) {
|
|
97
120
|
buffer = Buffer.alloc(bufferLength + 1)
|
|
98
121
|
offset = serializeHeader(buffer, offset, key, flag | (3 << 4))
|
|
122
|
+
|
|
99
123
|
buffer.writeInt8(value, offset)
|
|
124
|
+
|
|
100
125
|
return buffer
|
|
101
126
|
}
|
|
127
|
+
|
|
102
128
|
else if (-32768 <= value && value < 32768) {
|
|
103
129
|
buffer = Buffer.alloc(bufferLength + 2)
|
|
104
130
|
offset = serializeHeader(buffer, offset, key, flag | (4 << 4))
|
|
131
|
+
|
|
105
132
|
buffer.writeInt16LE(value, offset)
|
|
133
|
+
|
|
106
134
|
return buffer
|
|
107
135
|
}
|
|
136
|
+
|
|
108
137
|
else if (-2147483648 <= value && value < 2147483648) {
|
|
109
138
|
buffer = Buffer.alloc(bufferLength + 4)
|
|
110
139
|
offset = serializeHeader(buffer, offset, key, flag | (5 << 4))
|
|
140
|
+
|
|
111
141
|
buffer.writeInt32LE(value, offset)
|
|
142
|
+
|
|
112
143
|
return buffer
|
|
113
144
|
}
|
|
145
|
+
|
|
114
146
|
else {
|
|
115
147
|
buffer = Buffer.alloc(bufferLength + 8)
|
|
116
148
|
offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
|
|
149
|
+
|
|
117
150
|
buffer.writeDoubleLE(value, offset)
|
|
151
|
+
|
|
118
152
|
return buffer
|
|
119
153
|
}
|
|
120
154
|
}
|
|
155
|
+
|
|
121
156
|
else if (typeof value === 'number') {
|
|
122
157
|
// is float
|
|
123
158
|
buffer = Buffer.alloc(bufferLength + 8)
|
|
124
159
|
offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
|
|
160
|
+
|
|
125
161
|
buffer.writeDoubleLE(value, offset)
|
|
162
|
+
|
|
126
163
|
return buffer
|
|
127
164
|
}
|
|
165
|
+
|
|
128
166
|
else if (typeof value === 'string') {
|
|
129
167
|
// is string
|
|
130
168
|
const utf8Bytes = Buffer.byteLength(value, 'utf8')
|
|
169
|
+
|
|
131
170
|
if (utf8Bytes < 256) {
|
|
132
171
|
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
|
|
133
172
|
offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
|
|
173
|
+
|
|
134
174
|
buffer.writeUint8(utf8Bytes, offset++)
|
|
135
175
|
}
|
|
176
|
+
|
|
136
177
|
else if (utf8Bytes < 65536) {
|
|
137
178
|
buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes)
|
|
138
179
|
offset = serializeHeader(buffer, offset, key, flag | (9 << 4))
|
|
180
|
+
|
|
139
181
|
buffer.writeUInt16LE(utf8Bytes, offset)
|
|
140
182
|
offset += 2
|
|
141
183
|
}
|
|
184
|
+
|
|
142
185
|
else {
|
|
143
186
|
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes)
|
|
144
187
|
offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
|
|
188
|
+
|
|
145
189
|
buffer.writeUInt32LE(utf8Bytes, offset)
|
|
146
190
|
offset += 4
|
|
147
191
|
}
|
|
192
|
+
|
|
148
193
|
buffer.write(value, offset, 'utf8')
|
|
194
|
+
|
|
149
195
|
return buffer
|
|
150
196
|
}
|
|
197
|
+
|
|
151
198
|
throw 'missing'
|
|
152
199
|
}
|
|
153
200
|
|
|
@@ -158,12 +205,14 @@ function serializeHeader(buffer, offset, key, flag) {
|
|
|
158
205
|
buffer.writeUInt8(key, offset)
|
|
159
206
|
offset += 1
|
|
160
207
|
}
|
|
208
|
+
|
|
161
209
|
else {
|
|
162
210
|
buffer.writeUInt8(flag | FLAG_BYTE, offset)
|
|
163
211
|
offset += 1
|
|
164
212
|
buffer.writeUInt16LE(key, offset)
|
|
165
213
|
offset += 2
|
|
166
214
|
}
|
|
215
|
+
|
|
167
216
|
return offset
|
|
168
217
|
}
|
|
169
218
|
|
|
@@ -32,38 +32,54 @@ class USyncQuery {
|
|
|
32
32
|
return this
|
|
33
33
|
}
|
|
34
34
|
parseUSyncQueryResult(result) {
|
|
35
|
-
if (result.attrs.type !== 'result') {
|
|
35
|
+
if (!result || result.attrs.type !== 'result') {
|
|
36
36
|
return
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
const protocolMap = Object.fromEntries(this.protocols.map(protocol => {
|
|
39
40
|
return [protocol.name, protocol.parser]
|
|
40
41
|
}))
|
|
42
|
+
|
|
41
43
|
const queryResult = {
|
|
42
44
|
// TODO: implement errors etc.
|
|
43
45
|
list: [],
|
|
44
|
-
sideList: []
|
|
46
|
+
sideList: []
|
|
45
47
|
}
|
|
48
|
+
|
|
46
49
|
const usyncNode = getBinaryNodeChild(result, 'usync')
|
|
50
|
+
|
|
47
51
|
//TODO: implement error backoff, refresh etc.
|
|
48
52
|
//TODO: see if there are any errors in the result node
|
|
49
53
|
//const resultNode = getBinaryNodeChild(usyncNode, 'result')
|
|
50
|
-
const listNode = getBinaryNodeChild(usyncNode, 'list')
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
const listNode = usyncNode ? getBinaryNodeChild(usyncNode, 'list') : undefined
|
|
55
|
+
|
|
56
|
+
if (listNode?.content && Array.isArray(listNode.content)) {
|
|
57
|
+
queryResult.list = listNode.content.reduce((acc, node) => {
|
|
58
|
+
const id = node?.attrs.jid
|
|
59
|
+
|
|
60
|
+
if (id) {
|
|
61
|
+
const data = Array.isArray(node?.content)
|
|
62
|
+
? Object.fromEntries(node.content
|
|
63
|
+
.map(content => {
|
|
64
|
+
const protocol = content.tag
|
|
65
|
+
const parser = protocolMap[protocol]
|
|
66
|
+
|
|
67
|
+
if (parser) {
|
|
68
|
+
return [protocol, parser(content)]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
else {
|
|
72
|
+
return [protocol, null]
|
|
73
|
+
}
|
|
74
|
+
}).filter(([, b]) => b !== null))
|
|
75
|
+
: {};
|
|
76
|
+
acc.push({ ...data, id })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return acc
|
|
80
|
+
}, [])
|
|
66
81
|
}
|
|
82
|
+
|
|
67
83
|
//TODO: implement side list
|
|
68
84
|
//const sideListNode = getBinaryNodeChild(usyncNode, 'side_list')
|
|
69
85
|
return queryResult
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hansaka02/baileys",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.6",
|
|
4
4
|
"description": "WhatsApp API Modification By hansaka",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"homepage": "https://github.com/hansaka02/Baileys",
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "git+ssh://git@github.com/
|
|
18
|
+
"url": "git+ssh://git@github.com/hansaka02/baileys.git"
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"author": "hansaka02",
|
|
@@ -39,18 +39,17 @@
|
|
|
39
39
|
"@hapi/boom": "^9.1.3",
|
|
40
40
|
"@adiwajshing/keyed-db": "^0.2.4",
|
|
41
41
|
"@cacheable/node-cache": "1.5.3",
|
|
42
|
-
"@itsukichan/eslint-config": "^1.0.0",
|
|
43
42
|
"@itsukichan/libsignal-node": "^1.0.1",
|
|
44
43
|
"async-mutex": "^0.5.0",
|
|
45
|
-
"axios": "^1.12.1",
|
|
46
44
|
"audio-decode": "^2.2.2",
|
|
47
45
|
"cache-manager": "^5.7.6",
|
|
48
46
|
"fflate": "^0.8.2",
|
|
49
47
|
"lodash": "^4.17.21",
|
|
50
|
-
"
|
|
48
|
+
"unfurl.js": "^6.4.0",
|
|
51
49
|
"lru-cache": "^11.1.0",
|
|
52
50
|
"music-metadata": "^7.12.3",
|
|
53
51
|
"pino": "^9.6",
|
|
52
|
+
"p-queue": "^9.0.0",
|
|
54
53
|
"protobufjs": "^7.2.4",
|
|
55
54
|
"qrcode-terminal": "^0.12.0",
|
|
56
55
|
"ws": "^8.13.0"
|
|
@@ -59,12 +58,13 @@
|
|
|
59
58
|
"@types/jest": "^29.5.14",
|
|
60
59
|
"@types/node": "^16.0.0",
|
|
61
60
|
"@types/ws": "^8.0.0",
|
|
61
|
+
"@itsukichan/eslint-config": "^1.0.0",
|
|
62
62
|
"conventional-changelog-cli": "^2.2.2",
|
|
63
63
|
"eslint": "^8.0.0",
|
|
64
64
|
"jest": "^30.1.1",
|
|
65
65
|
"jimp": "^0.22.12",
|
|
66
66
|
"json": "^11.0.0",
|
|
67
|
-
"
|
|
67
|
+
"unfurl.js": "^6.4.0",
|
|
68
68
|
"open": "^8.4.2",
|
|
69
69
|
"release-it": "^15.10.3",
|
|
70
70
|
"ts-jest": "^29.4.1",
|
|
@@ -74,7 +74,8 @@
|
|
|
74
74
|
"typescript": "^5.8.2"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"jimp": "^0.22.12"
|
|
77
|
+
"jimp": "^0.22.12",
|
|
78
|
+
"sharp": "*"
|
|
78
79
|
},
|
|
79
80
|
"peerDependenciesMeta": {
|
|
80
81
|
"jimp": {
|
|
@@ -89,6 +90,6 @@
|
|
|
89
90
|
"lib": "lib"
|
|
90
91
|
},
|
|
91
92
|
"bugs": {
|
|
92
|
-
"url": "https://github.com/
|
|
93
|
+
"url": "https://github.com/hansaka02/baileys/issues"
|
|
93
94
|
}
|
|
94
95
|
}
|
package/lib/Socket/usync.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
-
|
|
5
|
-
const { Boom } = require("@hapi/boom")
|
|
6
|
-
const { S_WHATSAPP_NET } = require("../WABinary")
|
|
7
|
-
const { makeSocket } = require("./socket")
|
|
8
|
-
|
|
9
|
-
const makeUSyncSocket = (config) => {
|
|
10
|
-
const suki = makeSocket(config)
|
|
11
|
-
const { generateMessageTag, query, } = suki
|
|
12
|
-
|
|
13
|
-
const executeUSyncQuery = async (usyncQuery) => {
|
|
14
|
-
if (usyncQuery.protocols.length === 0) {
|
|
15
|
-
throw new Boom('USyncQuery must have at least one protocol')
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// todo: validate users, throw WARNING on no valid users
|
|
19
|
-
// variable below has only validated users
|
|
20
|
-
const validUsers = usyncQuery.users
|
|
21
|
-
|
|
22
|
-
const userNodes = validUsers.map((user) => {
|
|
23
|
-
return {
|
|
24
|
-
tag: 'user',
|
|
25
|
-
attrs: {
|
|
26
|
-
jid: !user.phone ? user.id : undefined,
|
|
27
|
-
},
|
|
28
|
-
content: usyncQuery.protocols
|
|
29
|
-
.map((a) => a.getUserElement(user))
|
|
30
|
-
.filter(a => a !== null)
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const listNode = {
|
|
35
|
-
tag: 'list',
|
|
36
|
-
attrs: {},
|
|
37
|
-
content: userNodes
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const queryNode = {
|
|
41
|
-
tag: 'query',
|
|
42
|
-
attrs: {},
|
|
43
|
-
content: usyncQuery.protocols.map((a) => a.getQueryElement())
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const iq = {
|
|
47
|
-
tag: 'iq',
|
|
48
|
-
attrs: {
|
|
49
|
-
to: S_WHATSAPP_NET,
|
|
50
|
-
type: 'get',
|
|
51
|
-
xmlns: 'usync',
|
|
52
|
-
},
|
|
53
|
-
content: [
|
|
54
|
-
{
|
|
55
|
-
tag: 'usync',
|
|
56
|
-
attrs: {
|
|
57
|
-
context: usyncQuery.context,
|
|
58
|
-
mode: usyncQuery.mode,
|
|
59
|
-
sid: generateMessageTag(),
|
|
60
|
-
last: 'true',
|
|
61
|
-
index: '0',
|
|
62
|
-
},
|
|
63
|
-
content: [
|
|
64
|
-
queryNode,
|
|
65
|
-
listNode
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
],
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const result = await query(iq)
|
|
72
|
-
|
|
73
|
-
return usyncQuery.parseUSyncQueryResult(result)
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
...suki,
|
|
77
|
-
executeUSyncQuery
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
module.exports = {
|
|
82
|
-
makeUSyncSocket
|
|
83
|
-
}
|