@hansaka02/baileys 7.3.2 → 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/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +74 -0
- package/lib/Defaults/history.js +19 -0
- package/lib/Defaults/index.js +36 -142
- package/lib/Defaults/media.js +48 -0
- package/lib/Defaults/prefix.js +18 -0
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +9 -6
- package/lib/Signal/Group/index.js +39 -53
- package/lib/Signal/Group/keyhelper.js +8 -41
- package/lib/Signal/Group/sender-chain-key.js +5 -18
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.js +15 -61
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +237 -177
- package/lib/Signal/lid-mapping.js +128 -71
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +25 -16
- package/lib/Socket/business.js +46 -33
- package/lib/Socket/chats.js +286 -170
- package/lib/Socket/community.js +215 -77
- package/lib/Socket/groups.js +77 -61
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +629 -457
- package/lib/Socket/messages-send.js +645 -656
- package/lib/Socket/mex.js +61 -0
- package/lib/Socket/newsletter.js +166 -245
- package/lib/Socket/socket.js +396 -170
- package/lib/Store/index.js +27 -11
- package/lib/Store/make-cache-manager-store.js +14 -15
- package/lib/Store/make-in-memory-store.js +28 -24
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +6 -6
- package/lib/Types/MexUpdates.js +5 -5
- package/lib/Types/Newsletter.js +32 -25
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +212 -375
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/browser-utils.js +43 -0
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +241 -106
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +361 -311
- package/lib/Utils/event-buffer.js +97 -42
- package/lib/Utils/generics.js +90 -207
- package/lib/Utils/history.js +29 -27
- package/lib/Utils/index.js +28 -14
- package/lib/Utils/link-preview.js +24 -62
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +29 -23
- package/lib/Utils/make-mutex.js +26 -28
- package/lib/Utils/message-retry-manager.js +55 -7
- package/lib/Utils/messages-media.js +434 -247
- package/lib/Utils/messages.js +963 -917
- package/lib/Utils/noise-handler.js +60 -20
- package/lib/Utils/pre-key-manager.js +126 -0
- package/lib/Utils/process-message.js +216 -141
- package/lib/Utils/signal.js +75 -37
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +96 -66
- package/lib/WABinary/constants.js +1268 -1268
- package/lib/WABinary/decode.js +62 -34
- package/lib/WABinary/encode.js +57 -36
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WABinary/jid-utils.js +58 -11
- package/lib/WAM/constants.js +19064 -11563
- package/lib/WAM/encode.js +71 -14
- package/lib/WAM/index.js +27 -11
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/index.js +27 -11
- package/lib/WAUSync/USyncQuery.js +51 -28
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +12 -17
- package/WAProto/AICommon/AICommon.d.ts +0 -11702
- package/WAProto/Adv/Adv.d.ts +0 -643
- package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
- package/WAProto/Cert/Cert.d.ts +0 -613
- package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
- package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
- package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
- package/WAProto/E2E/E2E.d.ts +0 -41724
- package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
- package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
- package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
- package/WAProto/Protocol/Protocol.d.ts +0 -270
- package/WAProto/Reporting/Reporting.d.ts +0 -371
- package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
- package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
- package/WAProto/UserPassword/UserPassword.d.ts +0 -363
- package/WAProto/VnameCert/VnameCert.d.ts +0 -821
- package/WAProto/Wa6/Wa6.d.ts +0 -2128
- package/WAProto/Web/Web.d.ts +0 -46383
- package/WAProto/index.d.ts +0 -55
- package/lib/Defaults/index.d.ts +0 -77
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts +0 -19
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -16
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -19
- package/lib/Signal/Group/sender-key-record.d.ts +0 -32
- package/lib/Signal/Group/sender-key-state.d.ts +0 -44
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -8
- package/lib/Signal/lid-mapping.d.ts +0 -28
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -187
- package/lib/Socket/chats.d.ts +0 -97
- package/lib/Socket/community.d.ts +0 -129
- package/lib/Socket/groups.d.ts +0 -129
- package/lib/Socket/index.d.ts +0 -191
- package/lib/Socket/messages-recv.d.ts +0 -174
- package/lib/Socket/messages-send.d.ts +0 -165
- package/lib/Socket/newsletter.d.ts +0 -145
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -121
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Chat.d.ts +0 -143
- package/lib/Types/Contact.d.ts +0 -23
- package/lib/Types/Events.d.ts +0 -226
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/Label.d.ts +0 -48
- package/lib/Types/LabelAssociation.d.ts +0 -35
- package/lib/Types/Message.d.ts +0 -484
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/Newsletter.d.ts +0 -109
- package/lib/Types/Product.d.ts +0 -92
- package/lib/Types/Signal.d.ts +0 -98
- package/lib/Types/Socket.d.ts +0 -141
- package/lib/Types/State.d.ts +0 -41
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -80
- package/lib/Utils/auth-utils.d.ts +0 -21
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/business.d.ts +0 -29
- package/lib/Utils/chat-utils.d.ts +0 -82
- package/lib/Utils/crypto.d.ts +0 -56
- package/lib/Utils/decode-wa-message.d.ts +0 -53
- package/lib/Utils/event-buffer.d.ts +0 -39
- package/lib/Utils/generics.d.ts +0 -117
- package/lib/Utils/history.d.ts +0 -23
- package/lib/Utils/index.d.ts +0 -20
- package/lib/Utils/link-preview.d.ts +0 -23
- package/lib/Utils/logger.d.ts +0 -13
- package/lib/Utils/lt-hash.d.ts +0 -14
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -88
- package/lib/Utils/messages-media.d.ts +0 -135
- package/lib/Utils/messages.d.ts +0 -105
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -49
- package/lib/Utils/signal.d.ts +0 -42
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/Utils/validate-connection.d.ts +0 -13
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -9
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -28
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -58
- package/lib/WABinary/types.d.ts +0 -22
- package/lib/WAM/BinaryInfo.d.ts +0 -16
- package/lib/WAM/constants.d.ts +0 -47
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -31
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -13
package/lib/WABinary/decode.js
CHANGED
|
@@ -1,46 +1,26 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod
|
|
23
|
-
var result = {}
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
-
__setModuleDefault(result, mod)
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
|
|
29
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
30
4
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
5
|
+
const { promisify } = require("util")
|
|
6
|
+
const { inflate } = require("zlib")
|
|
7
|
+
const {
|
|
8
|
+
jidEncode,
|
|
9
|
+
WAJIDDomains
|
|
10
|
+
} = require("./jid-utils")
|
|
11
|
+
const constants = require("./constants")
|
|
12
|
+
const inflatePromise = promisify(inflate)
|
|
36
13
|
|
|
37
14
|
const decompressingIfRequired = async (buffer) => {
|
|
38
15
|
if (2 & buffer.readUInt8()) {
|
|
39
16
|
buffer = await inflatePromise(buffer.slice(1))
|
|
40
17
|
}
|
|
41
|
-
|
|
18
|
+
|
|
19
|
+
else {
|
|
20
|
+
// nodes with no compression have a 0x00 prefix, we remove that
|
|
42
21
|
buffer = buffer.slice(1)
|
|
43
22
|
}
|
|
23
|
+
|
|
44
24
|
return buffer
|
|
45
25
|
}
|
|
46
26
|
|
|
@@ -54,7 +34,9 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
54
34
|
|
|
55
35
|
const next = () => {
|
|
56
36
|
const value = buffer[indexRef.index]
|
|
37
|
+
|
|
57
38
|
indexRef.index += 1
|
|
39
|
+
|
|
58
40
|
return value
|
|
59
41
|
}
|
|
60
42
|
|
|
@@ -65,8 +47,11 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
65
47
|
|
|
66
48
|
const readBytes = (n) => {
|
|
67
49
|
checkEOS(n)
|
|
50
|
+
|
|
68
51
|
const value = buffer.slice(indexRef.index, indexRef.index + n)
|
|
52
|
+
|
|
69
53
|
indexRef.index += n
|
|
54
|
+
|
|
70
55
|
return value
|
|
71
56
|
}
|
|
72
57
|
|
|
@@ -76,11 +61,14 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
76
61
|
|
|
77
62
|
const readInt = (n, littleEndian = false) => {
|
|
78
63
|
checkEOS(n)
|
|
64
|
+
|
|
79
65
|
let val = 0
|
|
66
|
+
|
|
80
67
|
for (let i = 0; i < n; i++) {
|
|
81
68
|
const shift = littleEndian ? i : n - 1 - i
|
|
82
69
|
val |= next() << (shift * 8)
|
|
83
70
|
}
|
|
71
|
+
|
|
84
72
|
return val
|
|
85
73
|
}
|
|
86
74
|
|
|
@@ -93,6 +81,7 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
93
81
|
if (value >= 0 && value < 16) {
|
|
94
82
|
return value < 10 ? '0'.charCodeAt(0) + value : 'A'.charCodeAt(0) + value - 10
|
|
95
83
|
}
|
|
84
|
+
|
|
96
85
|
throw new Error('invalid hex: ' + value)
|
|
97
86
|
}
|
|
98
87
|
|
|
@@ -100,6 +89,7 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
100
89
|
if (value >= 0 && value <= 9) {
|
|
101
90
|
return '0'.charCodeAt(0) + value
|
|
102
91
|
}
|
|
92
|
+
|
|
103
93
|
switch (value) {
|
|
104
94
|
case 10:
|
|
105
95
|
return '-'.charCodeAt(0)
|
|
@@ -116,9 +106,11 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
116
106
|
if (tag === TAGS.NIBBLE_8) {
|
|
117
107
|
return unpackNibble(value)
|
|
118
108
|
}
|
|
109
|
+
|
|
119
110
|
else if (tag === TAGS.HEX_8) {
|
|
120
111
|
return unpackHex(value)
|
|
121
112
|
}
|
|
113
|
+
|
|
122
114
|
else {
|
|
123
115
|
throw new Error('unknown tag: ' + tag)
|
|
124
116
|
}
|
|
@@ -126,15 +118,20 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
126
118
|
|
|
127
119
|
const readPacked8 = (tag) => {
|
|
128
120
|
const startByte = readByte()
|
|
121
|
+
|
|
129
122
|
let value = ''
|
|
123
|
+
|
|
130
124
|
for (let i = 0; i < (startByte & 127); i++) {
|
|
131
125
|
const curByte = readByte()
|
|
126
|
+
|
|
132
127
|
value += String.fromCharCode(unpackByte(tag, (curByte & 0xf0) >> 4))
|
|
133
128
|
value += String.fromCharCode(unpackByte(tag, curByte & 0x0f))
|
|
134
129
|
}
|
|
130
|
+
|
|
135
131
|
if (startByte >> 7 !== 0) {
|
|
136
132
|
value = value.slice(0, -1)
|
|
137
133
|
}
|
|
134
|
+
|
|
138
135
|
return value
|
|
139
136
|
}
|
|
140
137
|
|
|
@@ -158,23 +155,42 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
158
155
|
const readJidPair = () => {
|
|
159
156
|
const i = readString(readByte())
|
|
160
157
|
const j = readString(readByte())
|
|
158
|
+
|
|
161
159
|
if (j) {
|
|
162
160
|
return (i || '') + '@' + j
|
|
163
161
|
}
|
|
162
|
+
|
|
164
163
|
throw new Error('invalid jid pair: ' + i + ', ' + j)
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
const readAdJid = () => {
|
|
168
|
-
const
|
|
167
|
+
const rawDomainType = readByte()
|
|
168
|
+
const domainType = Number(rawDomainType)
|
|
169
169
|
const device = readByte()
|
|
170
170
|
const user = readString(readByte())
|
|
171
|
-
|
|
171
|
+
|
|
172
|
+
let server = 's.whatsapp.net' // default whatsapp server
|
|
173
|
+
|
|
174
|
+
if (domainType === WAJIDDomains.LID) {
|
|
175
|
+
server = 'lid'
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
else if (domainType === WAJIDDomains.HOSTED) {
|
|
179
|
+
server = 'hosted'
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
else if (domainType === WAJIDDomains.HOSTED_LID) {
|
|
183
|
+
server = 'hosted.lid'
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return jidEncode(user, server, device)
|
|
172
187
|
}
|
|
173
188
|
|
|
174
189
|
const readString = (tag) => {
|
|
175
190
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
176
191
|
return SINGLE_BYTE_TOKENS[tag] || ''
|
|
177
192
|
}
|
|
193
|
+
|
|
178
194
|
switch (tag) {
|
|
179
195
|
case TAGS.DICTIONARY_0:
|
|
180
196
|
case TAGS.DICTIONARY_1:
|
|
@@ -204,21 +220,27 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
204
220
|
const readList = (tag) => {
|
|
205
221
|
const items = []
|
|
206
222
|
const size = readListSize(tag)
|
|
223
|
+
|
|
207
224
|
for (let i = 0; i < size; i++) {
|
|
208
225
|
items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef))
|
|
209
226
|
}
|
|
227
|
+
|
|
210
228
|
return items
|
|
211
229
|
}
|
|
212
230
|
|
|
213
231
|
const getTokenDouble = (index1, index2) => {
|
|
214
232
|
const dict = DOUBLE_BYTE_TOKENS[index1]
|
|
233
|
+
|
|
215
234
|
if (!dict) {
|
|
216
235
|
throw new Error(`Invalid double token dict (${index1})`)
|
|
217
236
|
}
|
|
237
|
+
|
|
218
238
|
const value = dict[index2]
|
|
239
|
+
|
|
219
240
|
if (typeof value === 'undefined') {
|
|
220
241
|
throw new Error(`Invalid double token (${index2})`)
|
|
221
242
|
}
|
|
243
|
+
|
|
222
244
|
return value
|
|
223
245
|
}
|
|
224
246
|
|
|
@@ -239,6 +261,7 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
239
261
|
|
|
240
262
|
// read the attributes in
|
|
241
263
|
const attributesLength = (listSize - 1) >> 1
|
|
264
|
+
|
|
242
265
|
for (let i = 0; i < attributesLength; i++) {
|
|
243
266
|
const key = readString(readByte())
|
|
244
267
|
const value = readString(readByte())
|
|
@@ -247,11 +270,14 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
247
270
|
|
|
248
271
|
if (listSize % 2 === 0) {
|
|
249
272
|
const tag = readByte()
|
|
273
|
+
|
|
250
274
|
if (isListTag(tag)) {
|
|
251
275
|
data = readList(tag)
|
|
252
276
|
}
|
|
277
|
+
|
|
253
278
|
else {
|
|
254
279
|
let decoded
|
|
280
|
+
|
|
255
281
|
switch (tag) {
|
|
256
282
|
case TAGS.BINARY_8:
|
|
257
283
|
decoded = readBytes(readByte())
|
|
@@ -266,9 +292,11 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
266
292
|
decoded = readString(tag)
|
|
267
293
|
break
|
|
268
294
|
}
|
|
295
|
+
|
|
269
296
|
data = decoded
|
|
270
297
|
}
|
|
271
298
|
}
|
|
299
|
+
|
|
272
300
|
return {
|
|
273
301
|
tag: header,
|
|
274
302
|
attrs,
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -1,35 +1,9 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
|
-
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod
|
|
23
|
-
var result = {}
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
-
__setModuleDefault(result, mod)
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
|
|
29
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
30
4
|
|
|
31
|
-
const
|
|
32
|
-
const
|
|
5
|
+
const { jidDecode } = require("./jid-utils")
|
|
6
|
+
const constants = require("./constants")
|
|
33
7
|
|
|
34
8
|
const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
35
9
|
const encoded = encodeBinaryNodeInner(node, opts, buffer)
|
|
@@ -53,22 +27,25 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
53
27
|
}
|
|
54
28
|
|
|
55
29
|
const pushInt16 = (value) => {
|
|
56
|
-
pushBytes([(value >> 8) & 0xff, value & 0xff])
|
|
30
|
+
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
57
31
|
}
|
|
58
32
|
|
|
59
|
-
const pushInt20 = (value) =>
|
|
33
|
+
const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff])
|
|
60
34
|
const writeByteLength = (length) => {
|
|
61
35
|
if (length >= 4294967296) {
|
|
62
|
-
throw new Error('string too large to encode: ' + length)
|
|
36
|
+
throw new Error('string too large to encode: ' + length);
|
|
63
37
|
}
|
|
38
|
+
|
|
64
39
|
if (length >= 1 << 20) {
|
|
65
40
|
pushByte(TAGS.BINARY_32)
|
|
66
41
|
pushInt(length, 4) // 32 bit integer
|
|
67
42
|
}
|
|
43
|
+
|
|
68
44
|
else if (length >= 256) {
|
|
69
45
|
pushByte(TAGS.BINARY_20)
|
|
70
46
|
pushInt20(length)
|
|
71
47
|
}
|
|
48
|
+
|
|
72
49
|
else {
|
|
73
50
|
pushByte(TAGS.BINARY_8)
|
|
74
51
|
pushByte(length)
|
|
@@ -77,6 +54,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
77
54
|
|
|
78
55
|
const writeStringRaw = (str) => {
|
|
79
56
|
const bytes = Buffer.from(str, 'utf-8')
|
|
57
|
+
|
|
80
58
|
writeByteLength(bytes.length)
|
|
81
59
|
pushBytes(bytes)
|
|
82
60
|
}
|
|
@@ -85,17 +63,21 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
85
63
|
if (typeof device !== 'undefined') {
|
|
86
64
|
pushByte(TAGS.AD_JID)
|
|
87
65
|
pushByte(domainType || 0)
|
|
88
|
-
pushByte(device || 0)
|
|
66
|
+
pushByte(device || 0)
|
|
89
67
|
writeString(user)
|
|
90
68
|
}
|
|
69
|
+
|
|
91
70
|
else {
|
|
92
71
|
pushByte(TAGS.JID_PAIR)
|
|
72
|
+
|
|
93
73
|
if (user.length) {
|
|
94
74
|
writeString(user)
|
|
95
75
|
}
|
|
76
|
+
|
|
96
77
|
else {
|
|
97
78
|
pushByte(TAGS.LIST_EMPTY)
|
|
98
79
|
}
|
|
80
|
+
|
|
99
81
|
writeString(server)
|
|
100
82
|
}
|
|
101
83
|
}
|
|
@@ -112,6 +94,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
112
94
|
if (char >= '0' && char <= '9') {
|
|
113
95
|
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
114
96
|
}
|
|
97
|
+
|
|
115
98
|
throw new Error(`invalid byte for nibble "${char}"`)
|
|
116
99
|
}
|
|
117
100
|
}
|
|
@@ -120,15 +103,19 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
120
103
|
if (char >= '0' && char <= '9') {
|
|
121
104
|
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
122
105
|
}
|
|
106
|
+
|
|
123
107
|
if (char >= 'A' && char <= 'F') {
|
|
124
108
|
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
|
|
125
109
|
}
|
|
110
|
+
|
|
126
111
|
if (char >= 'a' && char <= 'f') {
|
|
127
112
|
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
|
|
128
113
|
}
|
|
114
|
+
|
|
129
115
|
if (char === '\0') {
|
|
130
116
|
return 15
|
|
131
117
|
}
|
|
118
|
+
|
|
132
119
|
throw new Error(`Invalid hex char "${char}"`)
|
|
133
120
|
}
|
|
134
121
|
|
|
@@ -136,21 +123,29 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
136
123
|
if (str.length > TAGS.PACKED_MAX) {
|
|
137
124
|
throw new Error('Too many bytes to pack')
|
|
138
125
|
}
|
|
126
|
+
|
|
139
127
|
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8)
|
|
128
|
+
|
|
140
129
|
let roundedLength = Math.ceil(str.length / 2.0)
|
|
130
|
+
|
|
141
131
|
if (str.length % 2 !== 0) {
|
|
142
132
|
roundedLength |= 128
|
|
143
133
|
}
|
|
134
|
+
|
|
144
135
|
pushByte(roundedLength)
|
|
136
|
+
|
|
145
137
|
const packFunction = type === 'nibble' ? packNibble : packHex
|
|
146
138
|
const packBytePair = (v1, v2) => {
|
|
147
139
|
const result = (packFunction(v1) << 4) | packFunction(v2)
|
|
148
140
|
return result
|
|
149
141
|
}
|
|
142
|
+
|
|
150
143
|
const strLengthHalf = Math.floor(str.length / 2)
|
|
144
|
+
|
|
151
145
|
for (let i = 0; i < strLengthHalf; i++) {
|
|
152
146
|
pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
|
|
153
147
|
}
|
|
148
|
+
|
|
154
149
|
if (str.length % 2 !== 0) {
|
|
155
150
|
pushByte(packBytePair(str[str.length - 1], '\x00'))
|
|
156
151
|
}
|
|
@@ -160,12 +155,15 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
160
155
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
161
156
|
return false
|
|
162
157
|
}
|
|
158
|
+
|
|
163
159
|
for (const char of str) {
|
|
164
160
|
const isInNibbleRange = char >= '0' && char <= '9'
|
|
161
|
+
|
|
165
162
|
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
166
163
|
return false
|
|
167
164
|
}
|
|
168
165
|
}
|
|
166
|
+
|
|
169
167
|
return true
|
|
170
168
|
}
|
|
171
169
|
|
|
@@ -173,38 +171,49 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
173
171
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
174
172
|
return false
|
|
175
173
|
}
|
|
174
|
+
|
|
176
175
|
for (const char of str) {
|
|
177
176
|
const isInNibbleRange = char >= '0' && char <= '9'
|
|
177
|
+
|
|
178
178
|
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
179
179
|
return false
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
+
|
|
182
183
|
return true
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
const writeString = (str) => {
|
|
186
|
-
|
|
187
|
+
if (str === undefined || str === null) {
|
|
187
188
|
pushByte(TAGS.LIST_EMPTY)
|
|
188
189
|
return
|
|
189
190
|
}
|
|
191
|
+
|
|
190
192
|
const tokenIndex = TOKEN_MAP[str]
|
|
193
|
+
|
|
191
194
|
if (tokenIndex) {
|
|
192
195
|
if (typeof tokenIndex.dict === 'number') {
|
|
193
196
|
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
|
|
194
197
|
}
|
|
198
|
+
|
|
195
199
|
pushByte(tokenIndex.index)
|
|
196
200
|
}
|
|
201
|
+
|
|
197
202
|
else if (isNibble(str)) {
|
|
198
203
|
writePackedBytes(str, 'nibble')
|
|
199
204
|
}
|
|
205
|
+
|
|
200
206
|
else if (isHex(str)) {
|
|
201
207
|
writePackedBytes(str, 'hex')
|
|
202
208
|
}
|
|
209
|
+
|
|
203
210
|
else if (str) {
|
|
204
|
-
const decodedJid =
|
|
211
|
+
const decodedJid = jidDecode(str)
|
|
212
|
+
|
|
205
213
|
if (decodedJid) {
|
|
206
214
|
writeJid(decodedJid)
|
|
207
215
|
}
|
|
216
|
+
|
|
208
217
|
else {
|
|
209
218
|
writeStringRaw(str)
|
|
210
219
|
}
|
|
@@ -215,9 +224,11 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
215
224
|
if (listSize === 0) {
|
|
216
225
|
pushByte(TAGS.LIST_EMPTY)
|
|
217
226
|
}
|
|
227
|
+
|
|
218
228
|
else if (listSize < 256) {
|
|
219
229
|
pushBytes([TAGS.LIST_8, listSize])
|
|
220
230
|
}
|
|
231
|
+
|
|
221
232
|
else {
|
|
222
233
|
pushByte(TAGS.LIST_16)
|
|
223
234
|
pushInt16(listSize)
|
|
@@ -228,35 +239,45 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
228
239
|
throw new Error('Invalid node: tag cannot be undefined')
|
|
229
240
|
}
|
|
230
241
|
|
|
231
|
-
const validAttributes = Object.keys(attrs).filter(k =>
|
|
242
|
+
const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null)
|
|
243
|
+
|
|
232
244
|
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0))
|
|
233
245
|
writeString(tag)
|
|
246
|
+
|
|
234
247
|
for (const key of validAttributes) {
|
|
235
248
|
if (typeof attrs[key] === 'string') {
|
|
236
249
|
writeString(key)
|
|
237
250
|
writeString(attrs[key])
|
|
238
251
|
}
|
|
239
252
|
}
|
|
253
|
+
|
|
240
254
|
if (typeof content === 'string') {
|
|
241
255
|
writeString(content)
|
|
242
256
|
}
|
|
257
|
+
|
|
243
258
|
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
244
259
|
writeByteLength(content.length)
|
|
245
260
|
pushBytes(content)
|
|
246
261
|
}
|
|
262
|
+
|
|
247
263
|
else if (Array.isArray(content)) {
|
|
248
|
-
|
|
264
|
+
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'))
|
|
265
|
+
|
|
249
266
|
writeListStart(validContent.length)
|
|
267
|
+
|
|
250
268
|
for (const item of validContent) {
|
|
251
269
|
encodeBinaryNodeInner(item, opts, buffer)
|
|
252
270
|
}
|
|
253
271
|
}
|
|
272
|
+
|
|
254
273
|
else if (typeof content === 'undefined') {
|
|
255
274
|
// do nothing
|
|
256
275
|
}
|
|
276
|
+
|
|
257
277
|
else {
|
|
258
278
|
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
|
|
259
279
|
}
|
|
280
|
+
|
|
260
281
|
return buffer
|
|
261
282
|
}
|
|
262
283
|
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const { Boom } = require("@hapi/boom")
|
|
6
|
+
const { proto } = require("../../WAProto")
|
|
7
7
|
|
|
8
8
|
// some extra useful utilities
|
|
9
9
|
const getBinaryNodeChildren = (node, childTag) => {
|
|
@@ -53,7 +53,7 @@ const getBinaryNodeChildUInt = (node, childTag, length) => {
|
|
|
53
53
|
const assertNodeErrorFree = (node) => {
|
|
54
54
|
const errNode = getBinaryNodeChild(node, 'error')
|
|
55
55
|
if (errNode) {
|
|
56
|
-
throw new
|
|
56
|
+
throw new Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code })
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -71,7 +71,7 @@ const getBinaryNodeMessages = ({ content }) => {
|
|
|
71
71
|
if (Array.isArray(content)) {
|
|
72
72
|
for (const item of content) {
|
|
73
73
|
if (item.tag === 'message') {
|
|
74
|
-
msgs.push(
|
|
74
|
+
msgs.push(proto.WebMessageInfo.decode(item.content))
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
package/lib/WABinary/index.js
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
let desc = Object.getOwnPropertyDescriptor(m, k)
|
|
7
|
+
|
|
6
8
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return m[k]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
8
15
|
}
|
|
9
|
-
Object.defineProperty(o, k2, desc)
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k
|
|
12
|
-
o[k2] = m[k]
|
|
13
|
-
}))
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
Object.defineProperty(o, k2, desc)
|
|
18
|
+
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k
|
|
21
|
+
o[k2] = m[k]
|
|
22
|
+
}
|
|
23
|
+
))
|
|
24
|
+
|
|
25
|
+
const __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) {
|
|
27
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
28
|
+
__createBinding(exports, m, p)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
17
31
|
}
|
|
18
32
|
|
|
19
|
-
Object.defineProperty(exports, "__esModule", {
|
|
33
|
+
Object.defineProperty(exports, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
})
|
|
20
36
|
|
|
21
37
|
__exportStar(require("./encode"), exports)
|
|
22
38
|
__exportStar(require("./decode"), exports)
|