@pontalabs/baileys 1.0.6 → 1.0.7
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/LICENSE +1 -1
- package/README.md +839 -267
- package/WAProto/GenerateStatics.sh +4 -3
- package/WAProto/WAProto.proto +511 -1215
- package/WAProto/index.d.ts +55 -14017
- package/WAProto/index.js +29 -97689
- package/lib/Defaults/index.d.ts +74 -72
- package/lib/Defaults/index.js +108 -94
- package/lib/Signal/Group/ciphertext-message.d.ts +7 -8
- package/lib/Signal/Group/ciphertext-message.js +16 -9
- package/lib/Signal/Group/group-session-builder.d.ts +13 -11
- package/lib/Signal/Group/group-session-builder.js +61 -19
- package/lib/Signal/Group/group_cipher.d.ts +16 -14
- package/lib/Signal/Group/group_cipher.js +70 -41
- package/lib/Signal/Group/index.d.ts +11 -12
- package/lib/Signal/Group/index.js +61 -12
- package/lib/Signal/Group/keyhelper.d.ts +14 -9
- package/lib/Signal/Group/keyhelper.js +58 -10
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
- package/lib/Signal/Group/sender-chain-key.js +34 -13
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
- package/lib/Signal/Group/sender-key-distribution-message.js +36 -28
- package/lib/Signal/Group/sender-key-message.d.ts +18 -18
- package/lib/Signal/Group/sender-key-message.js +45 -38
- package/lib/Signal/Group/sender-key-name.d.ts +15 -14
- package/lib/Signal/Group/sender-key-name.js +31 -20
- package/lib/Signal/Group/sender-key-record.d.ts +25 -24
- package/lib/Signal/Group/sender-key-record.js +35 -18
- package/lib/Signal/Group/sender-key-state.d.ts +34 -29
- package/lib/Signal/Group/sender-key-state.js +100 -37
- package/lib/Signal/Group/sender-message-key.d.ts +10 -11
- package/lib/Signal/Group/sender-message-key.js +22 -15
- package/lib/Signal/libsignal.d.ts +8 -5
- package/lib/Signal/libsignal.js +142 -288
- package/lib/Signal/lid-mapping.d.ts +28 -23
- package/lib/Signal/lid-mapping.js +184 -277
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +22 -3
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.js +15 -8
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.js +37 -29
- package/lib/Socket/business.d.ts +178 -208
- package/lib/Socket/business.js +127 -91
- package/lib/Socket/chats.d.ts +93 -120
- package/lib/Socket/chats.js +652 -727
- package/lib/Socket/community.js +10 -2
- package/lib/Socket/groups.d.ts +111 -143
- package/lib/Socket/groups.js +186 -165
- package/lib/Socket/index.d.ts +183 -252
- package/lib/Socket/index.js +18 -38
- package/lib/Socket/messages-recv.d.ts +167 -196
- package/lib/Socket/messages-recv.js +1567 -1443
- package/lib/Socket/messages-send.d.ts +158 -192
- package/lib/Socket/messages-send.js +1208 -1102
- package/lib/Socket/newsletter.d.ts +138 -163
- package/lib/Socket/newsletter.js +249 -153
- package/lib/Socket/socket.d.ts +36 -50
- package/lib/Socket/socket.js +820 -749
- package/lib/Store/index.d.ts +4 -4
- package/lib/Store/index.js +24 -4
- package/lib/Store/make-in-memory-store.d.ts +104 -44
- package/lib/Store/make-in-memory-store.js +213 -199
- package/lib/Store/make-ordered-dictionary.d.ts +12 -13
- package/lib/Store/make-ordered-dictionary.js +45 -38
- package/lib/Store/object-repository.d.ts +10 -11
- package/lib/Store/object-repository.js +16 -9
- package/lib/Types/Auth.d.ts +97 -93
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Bussines.js +3 -2
- package/lib/Types/Call.d.ts +13 -14
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.d.ts +97 -78
- package/lib/Types/Chat.js +9 -8
- package/lib/Types/Contact.d.ts +9 -12
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.d.ts +176 -206
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.d.ts +48 -53
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.d.ts +14 -13
- package/lib/Types/Label.js +30 -24
- package/lib/Types/LabelAssociation.d.ts +20 -15
- package/lib/Types/LabelAssociation.js +12 -6
- package/lib/Types/Message.d.ts +412 -248
- package/lib/Types/Message.js +19 -17
- package/lib/Types/Product.d.ts +71 -58
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.d.ts +82 -71
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.d.ts +81 -76
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/State.d.ts +19 -75
- package/lib/Types/State.js +14 -56
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.d.ts +62 -47
- package/lib/Types/index.js +50 -26
- package/lib/Utils/auth-utils.d.ts +10 -13
- package/lib/Utils/auth-utils.js +472 -213
- package/lib/Utils/business.d.ts +20 -14
- package/lib/Utils/business.js +134 -110
- package/lib/Utils/chat-utils.d.ts +70 -88
- package/lib/Utils/chat-utils.js +403 -466
- package/lib/Utils/crypto.d.ts +46 -27
- package/lib/Utils/crypto.js +188 -117
- package/lib/Utils/decode-wa-message.d.ts +45 -58
- package/lib/Utils/decode-wa-message.js +311 -212
- package/lib/Utils/event-buffer.d.ts +17 -14
- package/lib/Utils/event-buffer.js +296 -321
- package/lib/Utils/generics.d.ts +92 -66
- package/lib/Utils/generics.js +436 -270
- package/lib/Utils/history.d.ts +23 -24
- package/lib/Utils/history.js +76 -106
- package/lib/Utils/index.d.ts +21 -24
- package/lib/Utils/index.js +41 -24
- package/lib/Utils/link-preview.d.ts +14 -12
- package/lib/Utils/link-preview.js +75 -40
- package/lib/Utils/logger.d.ts +11 -10
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +14 -8
- package/lib/Utils/lt-hash.js +53 -3
- package/lib/Utils/make-mutex.d.ts +7 -7
- package/lib/Utils/make-mutex.js +44 -28
- package/lib/Utils/message-retry-manager.d.ts +88 -115
- package/lib/Utils/message-retry-manager.js +160 -265
- package/lib/Utils/messages-media.d.ts +107 -105
- package/lib/Utils/messages-media.js +619 -548
- package/lib/Utils/messages.d.ts +66 -52
- package/lib/Utils/messages.js +1558 -1730
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.js +130 -176
- package/lib/Utils/process-message.d.ts +32 -43
- package/lib/Utils/process-message.js +282 -484
- package/lib/Utils/rich-message-utils.js +724 -1220
- package/lib/Utils/signal.d.ts +32 -37
- package/lib/Utils/signal.js +105 -140
- package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
- package/lib/Utils/use-multi-file-auth-state.js +120 -70
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -11
- package/lib/Utils/use-single-file-auth-state.js +66 -92
- package/lib/Utils/validate-connection.d.ts +13 -11
- package/lib/Utils/validate-connection.js +113 -128
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +1292 -1451
- package/lib/WABinary/decode.d.ts +9 -7
- package/lib/WABinary/decode.js +189 -163
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +155 -110
- package/lib/WABinary/generic-utils.d.ts +27 -14
- package/lib/WABinary/generic-utils.js +105 -177
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +25 -6
- package/lib/WABinary/jid-utils.d.ts +54 -41
- package/lib/WABinary/jid-utils.js +152 -83
- package/lib/WABinary/types.d.ts +13 -10
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.d.ts +15 -8
- package/lib/WAM/BinaryInfo.js +14 -7
- package/lib/WAM/constants.d.ts +37 -30
- package/lib/WAM/constants.js +11983 -19465
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +109 -95
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +23 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +21 -37
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
- package/lib/WAUSync/Protocols/index.d.ts +6 -6
- package/lib/WAUSync/Protocols/index.js +26 -6
- package/lib/WAUSync/USyncQuery.d.ts +28 -27
- package/lib/WAUSync/USyncQuery.js +62 -68
- package/lib/WAUSync/USyncUser.d.ts +10 -15
- package/lib/WAUSync/USyncUser.js +19 -20
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +23 -4
- package/lib/index.d.ts +12 -11
- package/lib/index.js +39 -12
- package/package.json +42 -86
- package/engine-requirements.js +0 -10
package/lib/WABinary/decode.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { BinaryNode, BinaryNodeCodingOptions } from './types
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { BinaryNode, BinaryNodeCodingOptions } from './types'
|
|
2
|
+
|
|
3
|
+
export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer>
|
|
4
|
+
|
|
5
|
+
export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
|
|
6
|
+
index: number
|
|
7
|
+
}) => BinaryNode
|
|
8
|
+
|
|
9
|
+
export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>
|
package/lib/WABinary/decode.js
CHANGED
|
@@ -1,262 +1,288 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict"
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
30
|
+
|
|
31
|
+
const util_1 = require("util")
|
|
32
|
+
const zlib_1 = require("zlib")
|
|
33
|
+
const constants = __importStar(require("./constants"))
|
|
34
|
+
const jid_utils_1 = require("./jid-utils")
|
|
35
|
+
const inflatePromise = util_1.promisify(zlib_1.inflate)
|
|
36
|
+
|
|
37
|
+
const decompressingIfRequired = async (buffer) => {
|
|
7
38
|
if (2 & buffer.readUInt8()) {
|
|
8
|
-
buffer = await inflatePromise(buffer.slice(1))
|
|
39
|
+
buffer = await inflatePromise(buffer.slice(1))
|
|
9
40
|
}
|
|
10
|
-
else {
|
|
11
|
-
|
|
12
|
-
buffer = buffer.slice(1);
|
|
41
|
+
else { // nodes with no compression have a 0x00 prefix, we remove that
|
|
42
|
+
buffer = buffer.slice(1)
|
|
13
43
|
}
|
|
14
|
-
return buffer
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
44
|
+
return buffer
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
|
|
48
|
+
const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts
|
|
18
49
|
const checkEOS = (length) => {
|
|
19
50
|
if (indexRef.index + length > buffer.length) {
|
|
20
|
-
throw new Error('end of stream')
|
|
51
|
+
throw new Error('end of stream')
|
|
21
52
|
}
|
|
22
|
-
}
|
|
53
|
+
}
|
|
54
|
+
|
|
23
55
|
const next = () => {
|
|
24
|
-
const value = buffer[indexRef.index]
|
|
25
|
-
indexRef.index += 1
|
|
26
|
-
return value
|
|
27
|
-
}
|
|
56
|
+
const value = buffer[indexRef.index]
|
|
57
|
+
indexRef.index += 1
|
|
58
|
+
return value
|
|
59
|
+
}
|
|
60
|
+
|
|
28
61
|
const readByte = () => {
|
|
29
|
-
checkEOS(1)
|
|
30
|
-
return next()
|
|
31
|
-
}
|
|
62
|
+
checkEOS(1)
|
|
63
|
+
return next()
|
|
64
|
+
}
|
|
65
|
+
|
|
32
66
|
const readBytes = (n) => {
|
|
33
|
-
checkEOS(n)
|
|
34
|
-
const value = buffer.slice(indexRef.index, indexRef.index + n)
|
|
35
|
-
indexRef.index += n
|
|
36
|
-
return value
|
|
37
|
-
}
|
|
67
|
+
checkEOS(n)
|
|
68
|
+
const value = buffer.slice(indexRef.index, indexRef.index + n)
|
|
69
|
+
indexRef.index += n
|
|
70
|
+
return value
|
|
71
|
+
}
|
|
72
|
+
|
|
38
73
|
const readStringFromChars = (length) => {
|
|
39
|
-
return readBytes(length).toString('utf-8')
|
|
40
|
-
}
|
|
74
|
+
return readBytes(length).toString('utf-8')
|
|
75
|
+
}
|
|
76
|
+
|
|
41
77
|
const readInt = (n, littleEndian = false) => {
|
|
42
|
-
checkEOS(n)
|
|
43
|
-
let val = 0
|
|
78
|
+
checkEOS(n)
|
|
79
|
+
let val = 0
|
|
44
80
|
for (let i = 0; i < n; i++) {
|
|
45
|
-
const shift = littleEndian ? i : n - 1 - i
|
|
46
|
-
val |= next() << (shift * 8)
|
|
81
|
+
const shift = littleEndian ? i : n - 1 - i
|
|
82
|
+
val |= next() << (shift * 8)
|
|
47
83
|
}
|
|
48
|
-
return val
|
|
49
|
-
}
|
|
84
|
+
return val
|
|
85
|
+
}
|
|
86
|
+
|
|
50
87
|
const readInt20 = () => {
|
|
51
|
-
checkEOS(3)
|
|
52
|
-
return ((next() & 15) << 16) + (next() << 8) + next()
|
|
53
|
-
}
|
|
88
|
+
checkEOS(3)
|
|
89
|
+
return ((next() & 15) << 16) + (next() << 8) + next()
|
|
90
|
+
}
|
|
91
|
+
|
|
54
92
|
const unpackHex = (value) => {
|
|
55
93
|
if (value >= 0 && value < 16) {
|
|
56
|
-
return value < 10 ? '0'.charCodeAt(0) + value : 'A'.charCodeAt(0) + value - 10
|
|
94
|
+
return value < 10 ? '0'.charCodeAt(0) + value : 'A'.charCodeAt(0) + value - 10
|
|
57
95
|
}
|
|
58
|
-
throw new Error('invalid hex: ' + value)
|
|
59
|
-
}
|
|
96
|
+
throw new Error('invalid hex: ' + value)
|
|
97
|
+
}
|
|
98
|
+
|
|
60
99
|
const unpackNibble = (value) => {
|
|
61
100
|
if (value >= 0 && value <= 9) {
|
|
62
|
-
return '0'.charCodeAt(0) + value
|
|
101
|
+
return '0'.charCodeAt(0) + value
|
|
63
102
|
}
|
|
64
103
|
switch (value) {
|
|
65
104
|
case 10:
|
|
66
|
-
return '-'.charCodeAt(0)
|
|
105
|
+
return '-'.charCodeAt(0)
|
|
67
106
|
case 11:
|
|
68
|
-
return '.'.charCodeAt(0)
|
|
107
|
+
return '.'.charCodeAt(0)
|
|
69
108
|
case 15:
|
|
70
|
-
return '\0'.charCodeAt(0)
|
|
109
|
+
return '\0'.charCodeAt(0)
|
|
71
110
|
default:
|
|
72
|
-
throw new Error('invalid nibble: ' + value)
|
|
111
|
+
throw new Error('invalid nibble: ' + value)
|
|
73
112
|
}
|
|
74
|
-
}
|
|
113
|
+
}
|
|
114
|
+
|
|
75
115
|
const unpackByte = (tag, value) => {
|
|
76
116
|
if (tag === TAGS.NIBBLE_8) {
|
|
77
|
-
return unpackNibble(value)
|
|
117
|
+
return unpackNibble(value)
|
|
78
118
|
}
|
|
79
119
|
else if (tag === TAGS.HEX_8) {
|
|
80
|
-
return unpackHex(value)
|
|
120
|
+
return unpackHex(value)
|
|
81
121
|
}
|
|
82
122
|
else {
|
|
83
|
-
throw new Error('unknown tag: ' + tag)
|
|
123
|
+
throw new Error('unknown tag: ' + tag)
|
|
84
124
|
}
|
|
85
|
-
}
|
|
125
|
+
}
|
|
126
|
+
|
|
86
127
|
const readPacked8 = (tag) => {
|
|
87
|
-
const startByte = readByte()
|
|
88
|
-
let value = ''
|
|
128
|
+
const startByte = readByte()
|
|
129
|
+
let value = ''
|
|
89
130
|
for (let i = 0; i < (startByte & 127); i++) {
|
|
90
|
-
const curByte = readByte()
|
|
91
|
-
value += String.fromCharCode(unpackByte(tag, (curByte & 0xf0) >> 4))
|
|
92
|
-
value += String.fromCharCode(unpackByte(tag, curByte & 0x0f))
|
|
131
|
+
const curByte = readByte()
|
|
132
|
+
value += String.fromCharCode(unpackByte(tag, (curByte & 0xf0) >> 4))
|
|
133
|
+
value += String.fromCharCode(unpackByte(tag, curByte & 0x0f))
|
|
93
134
|
}
|
|
94
135
|
if (startByte >> 7 !== 0) {
|
|
95
|
-
value = value.slice(0, -1)
|
|
136
|
+
value = value.slice(0, -1)
|
|
96
137
|
}
|
|
97
|
-
return value
|
|
98
|
-
}
|
|
138
|
+
return value
|
|
139
|
+
}
|
|
140
|
+
|
|
99
141
|
const isListTag = (tag) => {
|
|
100
|
-
return tag === TAGS.LIST_EMPTY || tag === TAGS.LIST_8 || tag === TAGS.LIST_16
|
|
101
|
-
}
|
|
142
|
+
return tag === TAGS.LIST_EMPTY || tag === TAGS.LIST_8 || tag === TAGS.LIST_16
|
|
143
|
+
}
|
|
144
|
+
|
|
102
145
|
const readListSize = (tag) => {
|
|
103
146
|
switch (tag) {
|
|
104
147
|
case TAGS.LIST_EMPTY:
|
|
105
|
-
return 0
|
|
148
|
+
return 0
|
|
106
149
|
case TAGS.LIST_8:
|
|
107
|
-
return readByte()
|
|
150
|
+
return readByte()
|
|
108
151
|
case TAGS.LIST_16:
|
|
109
|
-
return readInt(2)
|
|
152
|
+
return readInt(2)
|
|
110
153
|
default:
|
|
111
|
-
throw new Error('invalid tag for list size: ' + tag)
|
|
154
|
+
throw new Error('invalid tag for list size: ' + tag)
|
|
112
155
|
}
|
|
113
|
-
}
|
|
156
|
+
}
|
|
157
|
+
|
|
114
158
|
const readJidPair = () => {
|
|
115
|
-
const i = readString(readByte())
|
|
116
|
-
const j = readString(readByte())
|
|
159
|
+
const i = readString(readByte())
|
|
160
|
+
const j = readString(readByte())
|
|
117
161
|
if (j) {
|
|
118
|
-
return (i || '') + '@' + j
|
|
162
|
+
return (i || '') + '@' + j
|
|
119
163
|
}
|
|
120
|
-
throw new Error('invalid jid pair: ' + i + ', ' + j)
|
|
121
|
-
}
|
|
164
|
+
throw new Error('invalid jid pair: ' + i + ', ' + j)
|
|
165
|
+
}
|
|
166
|
+
|
|
122
167
|
const readAdJid = () => {
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
server = 'lid';
|
|
130
|
-
}
|
|
131
|
-
else if (domainType === WAJIDDomains.HOSTED) {
|
|
132
|
-
server = 'hosted';
|
|
133
|
-
}
|
|
134
|
-
else if (domainType === WAJIDDomains.HOSTED_LID) {
|
|
135
|
-
server = 'hosted.lid';
|
|
136
|
-
}
|
|
137
|
-
return jidEncode(user, server, device);
|
|
138
|
-
};
|
|
139
|
-
const readFbJid = () => {
|
|
140
|
-
const user = readString(readByte());
|
|
141
|
-
const device = readInt(2);
|
|
142
|
-
const server = readString(readByte());
|
|
143
|
-
return `${user}:${device}@${server}`;
|
|
144
|
-
};
|
|
145
|
-
const readInteropJid = () => {
|
|
146
|
-
const user = readString(readByte());
|
|
147
|
-
const device = readInt(2);
|
|
148
|
-
const integrator = readInt(2);
|
|
149
|
-
let server = 'interop';
|
|
150
|
-
const beforeServer = indexRef.index;
|
|
151
|
-
try {
|
|
152
|
-
server = readString(readByte());
|
|
153
|
-
}
|
|
154
|
-
catch (err) {
|
|
155
|
-
indexRef.index = beforeServer;
|
|
156
|
-
}
|
|
157
|
-
return `${integrator}-${user}:${device}@${server}`;
|
|
158
|
-
};
|
|
168
|
+
const agent = readByte()
|
|
169
|
+
const device = readByte()
|
|
170
|
+
const user = readString(readByte())
|
|
171
|
+
return jid_utils_1.jidEncode(user, agent === 0 ? 's.whatsapp.net' : 'lid', device)
|
|
172
|
+
}
|
|
173
|
+
|
|
159
174
|
const readString = (tag) => {
|
|
160
175
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
161
|
-
return SINGLE_BYTE_TOKENS[tag] || ''
|
|
176
|
+
return SINGLE_BYTE_TOKENS[tag] || ''
|
|
162
177
|
}
|
|
163
178
|
switch (tag) {
|
|
164
179
|
case TAGS.DICTIONARY_0:
|
|
165
180
|
case TAGS.DICTIONARY_1:
|
|
166
181
|
case TAGS.DICTIONARY_2:
|
|
167
182
|
case TAGS.DICTIONARY_3:
|
|
168
|
-
return getTokenDouble(tag - TAGS.DICTIONARY_0, readByte())
|
|
183
|
+
return getTokenDouble(tag - TAGS.DICTIONARY_0, readByte())
|
|
169
184
|
case TAGS.LIST_EMPTY:
|
|
170
|
-
return ''
|
|
185
|
+
return ''
|
|
171
186
|
case TAGS.BINARY_8:
|
|
172
|
-
return readStringFromChars(readByte())
|
|
187
|
+
return readStringFromChars(readByte())
|
|
173
188
|
case TAGS.BINARY_20:
|
|
174
|
-
return readStringFromChars(readInt20())
|
|
189
|
+
return readStringFromChars(readInt20())
|
|
175
190
|
case TAGS.BINARY_32:
|
|
176
|
-
return readStringFromChars(readInt(4))
|
|
191
|
+
return readStringFromChars(readInt(4))
|
|
177
192
|
case TAGS.JID_PAIR:
|
|
178
|
-
return readJidPair()
|
|
179
|
-
case TAGS.FB_JID:
|
|
180
|
-
return readFbJid();
|
|
181
|
-
case TAGS.INTEROP_JID:
|
|
182
|
-
return readInteropJid();
|
|
193
|
+
return readJidPair()
|
|
183
194
|
case TAGS.AD_JID:
|
|
184
|
-
return readAdJid()
|
|
195
|
+
return readAdJid()
|
|
185
196
|
case TAGS.HEX_8:
|
|
186
197
|
case TAGS.NIBBLE_8:
|
|
187
|
-
return readPacked8(tag)
|
|
198
|
+
return readPacked8(tag)
|
|
188
199
|
default:
|
|
189
|
-
throw new Error('invalid string with tag: ' + tag)
|
|
200
|
+
throw new Error('invalid string with tag: ' + tag)
|
|
190
201
|
}
|
|
191
|
-
}
|
|
202
|
+
}
|
|
203
|
+
|
|
192
204
|
const readList = (tag) => {
|
|
193
|
-
const items = []
|
|
194
|
-
const size = readListSize(tag)
|
|
205
|
+
const items = []
|
|
206
|
+
const size = readListSize(tag)
|
|
195
207
|
for (let i = 0; i < size; i++) {
|
|
196
|
-
items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef))
|
|
208
|
+
items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef))
|
|
197
209
|
}
|
|
198
|
-
return items
|
|
199
|
-
}
|
|
210
|
+
return items
|
|
211
|
+
}
|
|
212
|
+
|
|
200
213
|
const getTokenDouble = (index1, index2) => {
|
|
201
|
-
const dict = DOUBLE_BYTE_TOKENS[index1]
|
|
214
|
+
const dict = DOUBLE_BYTE_TOKENS[index1]
|
|
202
215
|
if (!dict) {
|
|
203
|
-
throw new Error(`Invalid double token dict (${index1})`)
|
|
216
|
+
throw new Error(`Invalid double token dict (${index1})`)
|
|
204
217
|
}
|
|
205
|
-
const value = dict[index2]
|
|
218
|
+
const value = dict[index2]
|
|
206
219
|
if (typeof value === 'undefined') {
|
|
207
|
-
throw new Error(`Invalid double token (${index2})`)
|
|
220
|
+
throw new Error(`Invalid double token (${index2})`)
|
|
208
221
|
}
|
|
209
|
-
return value
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const
|
|
222
|
+
return value
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const listSize = readListSize(readByte())
|
|
226
|
+
const header = readString(readByte())
|
|
227
|
+
|
|
213
228
|
if (!listSize || !header.length) {
|
|
214
|
-
throw new Error('invalid node')
|
|
229
|
+
throw new Error('invalid node')
|
|
215
230
|
}
|
|
216
|
-
|
|
217
|
-
|
|
231
|
+
|
|
232
|
+
const attrs = {}
|
|
233
|
+
|
|
234
|
+
let data
|
|
235
|
+
|
|
218
236
|
if (listSize === 0 || !header) {
|
|
219
|
-
throw new Error('invalid node')
|
|
237
|
+
throw new Error('invalid node')
|
|
220
238
|
}
|
|
239
|
+
|
|
221
240
|
// read the attributes in
|
|
222
|
-
const attributesLength = (listSize - 1) >> 1
|
|
241
|
+
const attributesLength = (listSize - 1) >> 1
|
|
223
242
|
for (let i = 0; i < attributesLength; i++) {
|
|
224
|
-
const key = readString(readByte())
|
|
225
|
-
const value = readString(readByte())
|
|
226
|
-
attrs[key] = value
|
|
243
|
+
const key = readString(readByte())
|
|
244
|
+
const value = readString(readByte())
|
|
245
|
+
attrs[key] = value
|
|
227
246
|
}
|
|
247
|
+
|
|
228
248
|
if (listSize % 2 === 0) {
|
|
229
|
-
const tag = readByte()
|
|
249
|
+
const tag = readByte()
|
|
230
250
|
if (isListTag(tag)) {
|
|
231
|
-
data = readList(tag)
|
|
251
|
+
data = readList(tag)
|
|
232
252
|
}
|
|
233
253
|
else {
|
|
234
|
-
let decoded
|
|
254
|
+
let decoded
|
|
235
255
|
switch (tag) {
|
|
236
256
|
case TAGS.BINARY_8:
|
|
237
|
-
decoded = readBytes(readByte())
|
|
238
|
-
break
|
|
257
|
+
decoded = readBytes(readByte())
|
|
258
|
+
break
|
|
239
259
|
case TAGS.BINARY_20:
|
|
240
|
-
decoded = readBytes(readInt20())
|
|
241
|
-
break
|
|
260
|
+
decoded = readBytes(readInt20())
|
|
261
|
+
break
|
|
242
262
|
case TAGS.BINARY_32:
|
|
243
|
-
decoded = readBytes(readInt(4))
|
|
244
|
-
break
|
|
263
|
+
decoded = readBytes(readInt(4))
|
|
264
|
+
break
|
|
245
265
|
default:
|
|
246
|
-
decoded = readString(tag)
|
|
247
|
-
break
|
|
266
|
+
decoded = readString(tag)
|
|
267
|
+
break
|
|
248
268
|
}
|
|
249
|
-
data = decoded
|
|
269
|
+
data = decoded
|
|
250
270
|
}
|
|
251
271
|
}
|
|
252
272
|
return {
|
|
253
273
|
tag: header,
|
|
254
274
|
attrs,
|
|
255
275
|
content: data
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const decodeBinaryNode = async (buff) => {
|
|
280
|
+
const decompBuff = await decompressingIfRequired(buff)
|
|
281
|
+
return decodeDecompressedBinaryNode(decompBuff, constants)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
module.exports = {
|
|
285
|
+
decompressingIfRequired,
|
|
286
|
+
decodeDecompressedBinaryNode,
|
|
287
|
+
decodeBinaryNode
|
|
288
|
+
}
|
package/lib/WABinary/encode.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { BinaryNode, BinaryNodeCodingOptions } from './types
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { BinaryNode, BinaryNodeCodingOptions } from './types'
|
|
2
|
+
|
|
3
|
+
export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'>, buffer?: number[]) => Buffer
|