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