@alannxd/baileys 6.0.4 → 6.0.5
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/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +5479 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +201 -160
- package/engine-requirements.js +1 -1
- package/lib/Defaults/index.d.ts +37 -15
- package/lib/Defaults/index.js +119 -136
- package/lib/Signal/Group/ciphertext-message.d.ts +1 -0
- package/lib/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/group-session-builder.d.ts +4 -3
- package/lib/Signal/Group/group-session-builder.js +7 -41
- package/lib/Signal/Group/group_cipher.d.ts +4 -4
- package/lib/Signal/Group/group_cipher.js +37 -51
- package/lib/Signal/Group/index.d.ts +12 -11
- package/lib/Signal/Group/index.js +12 -57
- package/lib/Signal/Group/keyhelper.d.ts +2 -1
- package/lib/Signal/Group/keyhelper.js +7 -44
- package/lib/Signal/Group/sender-chain-key.d.ts +3 -2
- package/lib/Signal/Group/sender-chain-key.js +7 -15
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-distribution-message.js +8 -11
- package/lib/Signal/Group/sender-key-message.d.ts +2 -1
- package/lib/Signal/Group/sender-key-message.js +9 -12
- package/lib/Signal/Group/sender-key-name.d.ts +1 -0
- package/lib/Signal/Group/sender-key-name.js +2 -5
- package/lib/Signal/Group/sender-key-record.d.ts +3 -2
- package/lib/Signal/Group/sender-key-record.js +9 -21
- package/lib/Signal/Group/sender-key-state.d.ts +7 -6
- package/lib/Signal/Group/sender-key-state.js +27 -42
- package/lib/Signal/Group/sender-message-key.d.ts +1 -0
- package/lib/Signal/Group/sender-message-key.js +4 -7
- package/lib/Signal/libsignal.d.ts +5 -3
- package/lib/Signal/libsignal.js +347 -90
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +3 -19
- package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +4 -5
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +3 -2
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/business.d.ts +154 -108
- package/lib/Socket/business.js +162 -43
- package/lib/Socket/chats.d.ts +96 -239
- package/lib/Socket/chats.js +627 -427
- package/lib/Socket/communities.d.ts +239 -146
- package/lib/Socket/communities.js +90 -80
- package/lib/Socket/groups.d.ts +104 -57
- package/lib/Socket/groups.js +154 -161
- package/lib/Socket/index.d.ts +202 -115
- package/lib/Socket/index.js +11 -10
- package/lib/Socket/luxu.d.ts +22 -266
- package/lib/Socket/luxu.js +422 -465
- package/lib/Socket/messages-recv.d.ts +136 -84
- package/lib/Socket/messages-recv.js +1421 -615
- package/lib/Socket/messages-send.d.ts +142 -126
- package/lib/Socket/messages-send.js +878 -671
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.d.ts +121 -85
- package/lib/Socket/newsletter.js +147 -272
- package/lib/Socket/socket.d.ts +34 -19
- package/lib/Socket/socket.js +544 -313
- package/lib/Store/index.d.ts +10 -3
- package/lib/Store/index.js +10 -10
- package/lib/Store/keyed-db.d.ts +22 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.d.ts +17 -11
- package/lib/Store/make-cache-manager-store.js +43 -41
- package/lib/Store/make-in-memory-store.d.ts +39 -118
- package/lib/Store/make-in-memory-store.js +112 -341
- package/lib/Store/make-ordered-dictionary.d.ts +11 -10
- package/lib/Store/make-ordered-dictionary.js +14 -20
- package/lib/Store/object-repository.d.ts +10 -9
- package/lib/Store/object-repository.js +11 -6
- package/lib/Types/Auth.d.ts +19 -12
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +3 -1
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +35 -13
- package/lib/Types/Chat.js +8 -4
- package/lib/Types/Contact.d.ts +8 -1
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +116 -17
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +21 -5
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +12 -0
- package/lib/Types/Label.js +3 -5
- package/lib/Types/LabelAssociation.d.ts +1 -0
- package/lib/Types/LabelAssociation.js +3 -5
- package/lib/Types/Message.d.ts +105 -58
- package/lib/Types/Message.js +11 -9
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Product.d.ts +2 -1
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +32 -2
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +50 -25
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.d.ts +72 -2
- package/lib/Types/State.js +56 -2
- package/lib/Types/USync.d.ts +3 -2
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +22 -14
- package/lib/Types/index.js +15 -31
- package/lib/Utils/auth-utils.d.ts +12 -6
- package/lib/Utils/auth-utils.js +239 -143
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.d.ts +3 -2
- package/lib/Utils/business.js +66 -69
- package/lib/Utils/chat-utils.d.ts +52 -23
- package/lib/Utils/chat-utils.js +396 -253
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.d.ts +18 -22
- package/lib/Utils/crypto.js +57 -90
- package/lib/Utils/decode-wa-message.d.ts +55 -8
- package/lib/Utils/decode-wa-message.js +203 -84
- package/lib/Utils/event-buffer.d.ts +9 -8
- package/lib/Utils/event-buffer.js +185 -77
- package/lib/Utils/generics.d.ts +28 -29
- package/lib/Utils/generics.js +180 -210
- package/lib/Utils/history.d.ts +18 -9
- package/lib/Utils/history.js +93 -55
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.d.ts +22 -17
- package/lib/Utils/index.js +22 -33
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +16 -24
- package/lib/Utils/logger.d.ts +11 -3
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/lt-hash.d.ts +8 -12
- package/lib/Utils/lt-hash.js +3 -46
- package/lib/Utils/make-mutex.d.ts +4 -2
- package/lib/Utils/make-mutex.js +24 -34
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/messages-media.d.ts +61 -44
- package/lib/Utils/messages-media.js +451 -482
- package/lib/Utils/messages.d.ts +32 -18
- package/lib/Utils/messages.js +458 -369
- package/lib/Utils/noise-handler.d.ts +13 -14
- package/lib/Utils/noise-handler.js +145 -99
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.d.ts +31 -12
- package/lib/Utils/process-message.js +459 -150
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/signal.d.ts +20 -5
- package/lib/Utils/signal.js +120 -72
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +29 -27
- package/lib/Utils/validate-connection.d.ts +7 -7
- package/lib/Utils/validate-connection.js +73 -99
- package/lib/WABinary/constants.d.ts +25 -27
- package/lib/WABinary/constants.js +1281 -20
- package/lib/WABinary/decode.d.ts +5 -5
- package/lib/WABinary/decode.js +52 -42
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +110 -155
- package/lib/WABinary/generic-utils.d.ts +8 -7
- package/lib/WABinary/generic-utils.js +48 -49
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.js +6 -21
- package/lib/WABinary/jid-utils.d.ts +25 -8
- package/lib/WABinary/jid-utils.js +74 -40
- package/lib/WABinary/types.d.ts +2 -1
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +3 -11
- package/lib/WAM/BinaryInfo.js +2 -5
- package/lib/WAM/constants.d.ts +5 -3
- package/lib/WAM/constants.js +19071 -11568
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +17 -22
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.js +4 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +33 -13
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +11 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +9 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +3 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +9 -13
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +4 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +20 -22
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +5 -3
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +13 -8
- package/lib/WAUSync/Protocols/index.d.ts +6 -4
- package/lib/WAUSync/Protocols/index.js +6 -20
- package/lib/WAUSync/USyncQuery.d.ts +6 -4
- package/lib/WAUSync/USyncQuery.js +44 -35
- package/lib/WAUSync/USyncUser.d.ts +10 -5
- package/lib/WAUSync/USyncUser.js +10 -5
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +4 -19
- package/lib/index.d.ts +10 -9
- package/lib/index.js +12 -34
- package/package.json +84 -51
- package/WAProto/fix-import.js +0 -29
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/registration.d.ts +0 -267
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- package/lib/Types/Newsletter.d.ts +0 -103
- package/lib/Types/Newsletter.js +0 -38
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/baileys-event-stream.js +0 -63
package/lib/WABinary/decode.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, 'DOUBLE_BYTE_TOKENS' | 'SINGLE_BYTE_TOKENS' | 'TAGS'>, indexRef?: {
|
|
1
|
+
import type { BinaryNode, BinaryNodeCodingOptions } from './types.js';
|
|
2
|
+
export declare const decompressingIfRequired: (buffer: Buffer) => Promise<Buffer<ArrayBufferLike>>;
|
|
3
|
+
export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, "DOUBLE_BYTE_TOKENS" | "SINGLE_BYTE_TOKENS" | "TAGS">, indexRef?: {
|
|
5
4
|
index: number;
|
|
6
5
|
}) => BinaryNode;
|
|
7
|
-
export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode
|
|
6
|
+
export declare const decodeBinaryNode: (buff: Buffer) => Promise<BinaryNode>;
|
|
7
|
+
//# sourceMappingURL=decode.d.ts.map
|
package/lib/WABinary/decode.js
CHANGED
|
@@ -1,43 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.decodeBinaryNode = exports.decodeDecompressedBinaryNode = exports.decompressingIfRequired = void 0;
|
|
27
|
-
const zlib_1 = require("zlib");
|
|
28
|
-
const constants = __importStar(require("./constants"));
|
|
29
|
-
const jid_utils_1 = require("./jid-utils");
|
|
30
|
-
const decompressingIfRequired = (buffer) => {
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import { inflate } from 'zlib';
|
|
3
|
+
import * as constants from './constants.js';
|
|
4
|
+
import { jidEncode, WAJIDDomains } from './jid-utils.js';
|
|
5
|
+
const inflatePromise = promisify(inflate);
|
|
6
|
+
export const decompressingIfRequired = async (buffer) => {
|
|
31
7
|
if (2 & buffer.readUInt8()) {
|
|
32
|
-
buffer =
|
|
8
|
+
buffer = await inflatePromise(buffer.slice(1));
|
|
33
9
|
}
|
|
34
|
-
else {
|
|
10
|
+
else {
|
|
11
|
+
// nodes with no compression have a 0x00 prefix, we remove that
|
|
35
12
|
buffer = buffer.slice(1);
|
|
36
13
|
}
|
|
37
14
|
return buffer;
|
|
38
15
|
};
|
|
39
|
-
|
|
40
|
-
const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
|
|
16
|
+
export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
|
|
41
17
|
const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts;
|
|
42
18
|
const checkEOS = (length) => {
|
|
43
19
|
if (indexRef.index + length > buffer.length) {
|
|
@@ -144,10 +120,41 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
144
120
|
throw new Error('invalid jid pair: ' + i + ', ' + j);
|
|
145
121
|
};
|
|
146
122
|
const readAdJid = () => {
|
|
147
|
-
const
|
|
123
|
+
const rawDomainType = readByte();
|
|
124
|
+
const domainType = Number(rawDomainType);
|
|
148
125
|
const device = readByte();
|
|
149
126
|
const user = readString(readByte());
|
|
150
|
-
|
|
127
|
+
let server = 's.whatsapp.net'; // default whatsapp server
|
|
128
|
+
if (domainType === WAJIDDomains.LID) {
|
|
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}`;
|
|
151
158
|
};
|
|
152
159
|
const readString = (tag) => {
|
|
153
160
|
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
@@ -169,6 +176,10 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
169
176
|
return readStringFromChars(readInt(4));
|
|
170
177
|
case TAGS.JID_PAIR:
|
|
171
178
|
return readJidPair();
|
|
179
|
+
case TAGS.FB_JID:
|
|
180
|
+
return readFbJid();
|
|
181
|
+
case TAGS.INTEROP_JID:
|
|
182
|
+
return readInteropJid();
|
|
172
183
|
case TAGS.AD_JID:
|
|
173
184
|
return readAdJid();
|
|
174
185
|
case TAGS.HEX_8:
|
|
@@ -182,7 +193,7 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
182
193
|
const items = [];
|
|
183
194
|
const size = readListSize(tag);
|
|
184
195
|
for (let i = 0; i < size; i++) {
|
|
185
|
-
items.push(
|
|
196
|
+
items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef));
|
|
186
197
|
}
|
|
187
198
|
return items;
|
|
188
199
|
};
|
|
@@ -244,9 +255,8 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
|
|
|
244
255
|
content: data
|
|
245
256
|
};
|
|
246
257
|
};
|
|
247
|
-
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
return (0, exports.decodeDecompressedBinaryNode)(decompBuff, constants);
|
|
258
|
+
export const decodeBinaryNode = async (buff) => {
|
|
259
|
+
const decompBuff = await decompressingIfRequired(buff);
|
|
260
|
+
return decodeDecompressedBinaryNode(decompBuff, constants);
|
|
251
261
|
};
|
|
252
|
-
|
|
262
|
+
//# sourceMappingURL=decode.js.map
|
package/lib/WABinary/encode.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { BinaryNode, BinaryNodeCodingOptions } from './types.js';
|
|
2
|
+
export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, "TAGS" | "TOKEN_MAP">, buffer?: number[]) => Buffer;
|
|
3
|
+
//# sourceMappingURL=encode.d.ts.map
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -1,265 +1,220 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 constants = __importStar(require("./constants"))
|
|
32
|
-
const jid_utils_1 = require("./jid-utils")
|
|
33
|
-
|
|
34
|
-
const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
35
|
-
const encoded = encodeBinaryNodeInner(node, opts, buffer)
|
|
36
|
-
return Buffer.from(encoded)
|
|
37
|
-
}
|
|
38
|
-
|
|
1
|
+
import * as constants from './constants.js';
|
|
2
|
+
import { jidDecode } from './jid-utils.js';
|
|
3
|
+
export const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
4
|
+
const encoded = encodeBinaryNodeInner(node, opts, buffer);
|
|
5
|
+
return Buffer.from(encoded);
|
|
6
|
+
};
|
|
39
7
|
const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
40
|
-
const { TAGS, TOKEN_MAP } = opts
|
|
41
|
-
const pushByte = (value) => buffer.push(value & 0xff)
|
|
8
|
+
const { TAGS, TOKEN_MAP } = opts;
|
|
9
|
+
const pushByte = (value) => buffer.push(value & 0xff);
|
|
42
10
|
const pushInt = (value, n, littleEndian = false) => {
|
|
43
11
|
for (let i = 0; i < n; i++) {
|
|
44
|
-
const curShift = littleEndian ? i : n - 1 - i
|
|
45
|
-
buffer.push((value >> (curShift * 8)) & 0xff)
|
|
12
|
+
const curShift = littleEndian ? i : n - 1 - i;
|
|
13
|
+
buffer.push((value >> (curShift * 8)) & 0xff);
|
|
46
14
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
15
|
+
};
|
|
49
16
|
const pushBytes = (bytes) => {
|
|
50
17
|
for (const b of bytes) {
|
|
51
|
-
buffer.push(b)
|
|
18
|
+
buffer.push(b);
|
|
52
19
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
20
|
+
};
|
|
55
21
|
const pushInt16 = (value) => {
|
|
56
|
-
pushBytes([(value >> 8) & 0xff, value & 0xff])
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const pushInt20 = (value) => (pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]))
|
|
22
|
+
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
23
|
+
};
|
|
24
|
+
const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
|
|
60
25
|
const writeByteLength = (length) => {
|
|
61
26
|
if (length >= 4294967296) {
|
|
62
|
-
throw new Error('string too large to encode: ' + length)
|
|
27
|
+
throw new Error('string too large to encode: ' + length);
|
|
63
28
|
}
|
|
64
29
|
if (length >= 1 << 20) {
|
|
65
|
-
pushByte(TAGS.BINARY_32)
|
|
66
|
-
pushInt(length, 4) // 32 bit integer
|
|
30
|
+
pushByte(TAGS.BINARY_32);
|
|
31
|
+
pushInt(length, 4); // 32 bit integer
|
|
67
32
|
}
|
|
68
33
|
else if (length >= 256) {
|
|
69
|
-
pushByte(TAGS.BINARY_20)
|
|
70
|
-
pushInt20(length)
|
|
34
|
+
pushByte(TAGS.BINARY_20);
|
|
35
|
+
pushInt20(length);
|
|
71
36
|
}
|
|
72
37
|
else {
|
|
73
|
-
pushByte(TAGS.BINARY_8)
|
|
74
|
-
pushByte(length)
|
|
38
|
+
pushByte(TAGS.BINARY_8);
|
|
39
|
+
pushByte(length);
|
|
75
40
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
41
|
+
};
|
|
78
42
|
const writeStringRaw = (str) => {
|
|
79
|
-
const bytes = Buffer.from(str, 'utf-8')
|
|
80
|
-
writeByteLength(bytes.length)
|
|
81
|
-
pushBytes(bytes)
|
|
82
|
-
}
|
|
83
|
-
|
|
43
|
+
const bytes = Buffer.from(str, 'utf-8');
|
|
44
|
+
writeByteLength(bytes.length);
|
|
45
|
+
pushBytes(bytes);
|
|
46
|
+
};
|
|
84
47
|
const writeJid = ({ domainType, device, user, server }) => {
|
|
85
48
|
if (typeof device !== 'undefined') {
|
|
86
|
-
pushByte(TAGS.AD_JID)
|
|
87
|
-
pushByte(domainType || 0)
|
|
88
|
-
pushByte(device || 0)
|
|
89
|
-
writeString(user)
|
|
49
|
+
pushByte(TAGS.AD_JID);
|
|
50
|
+
pushByte(domainType || 0);
|
|
51
|
+
pushByte(device || 0);
|
|
52
|
+
writeString(user);
|
|
90
53
|
}
|
|
91
54
|
else {
|
|
92
|
-
pushByte(TAGS.JID_PAIR)
|
|
55
|
+
pushByte(TAGS.JID_PAIR);
|
|
93
56
|
if (user.length) {
|
|
94
|
-
writeString(user)
|
|
57
|
+
writeString(user);
|
|
95
58
|
}
|
|
96
59
|
else {
|
|
97
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
60
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
98
61
|
}
|
|
99
|
-
writeString(server)
|
|
62
|
+
writeString(server);
|
|
100
63
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
64
|
+
};
|
|
103
65
|
const packNibble = (char) => {
|
|
104
66
|
switch (char) {
|
|
105
67
|
case '-':
|
|
106
|
-
return 10
|
|
68
|
+
return 10;
|
|
107
69
|
case '.':
|
|
108
|
-
return 11
|
|
70
|
+
return 11;
|
|
109
71
|
case '\0':
|
|
110
|
-
return 15
|
|
72
|
+
return 15;
|
|
111
73
|
default:
|
|
112
74
|
if (char >= '0' && char <= '9') {
|
|
113
|
-
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
75
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
114
76
|
}
|
|
115
|
-
throw new Error(`invalid byte for nibble "${char}"`)
|
|
77
|
+
throw new Error(`invalid byte for nibble "${char}"`);
|
|
116
78
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
79
|
+
};
|
|
119
80
|
const packHex = (char) => {
|
|
120
81
|
if (char >= '0' && char <= '9') {
|
|
121
|
-
return char.charCodeAt(0) - '0'.charCodeAt(0)
|
|
82
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
122
83
|
}
|
|
123
84
|
if (char >= 'A' && char <= 'F') {
|
|
124
|
-
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0)
|
|
85
|
+
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
|
|
125
86
|
}
|
|
126
87
|
if (char >= 'a' && char <= 'f') {
|
|
127
|
-
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0)
|
|
88
|
+
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
|
|
128
89
|
}
|
|
129
90
|
if (char === '\0') {
|
|
130
|
-
return 15
|
|
91
|
+
return 15;
|
|
131
92
|
}
|
|
132
|
-
throw new Error(`Invalid hex char "${char}"`)
|
|
133
|
-
}
|
|
134
|
-
|
|
93
|
+
throw new Error(`Invalid hex char "${char}"`);
|
|
94
|
+
};
|
|
135
95
|
const writePackedBytes = (str, type) => {
|
|
136
96
|
if (str.length > TAGS.PACKED_MAX) {
|
|
137
|
-
throw new Error('Too many bytes to pack')
|
|
97
|
+
throw new Error('Too many bytes to pack');
|
|
138
98
|
}
|
|
139
|
-
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8)
|
|
140
|
-
let roundedLength = Math.ceil(str.length / 2.0)
|
|
99
|
+
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
|
|
100
|
+
let roundedLength = Math.ceil(str.length / 2.0);
|
|
141
101
|
if (str.length % 2 !== 0) {
|
|
142
|
-
roundedLength |= 128
|
|
102
|
+
roundedLength |= 128;
|
|
143
103
|
}
|
|
144
|
-
pushByte(roundedLength)
|
|
145
|
-
const packFunction = type === 'nibble' ? packNibble : packHex
|
|
104
|
+
pushByte(roundedLength);
|
|
105
|
+
const packFunction = type === 'nibble' ? packNibble : packHex;
|
|
146
106
|
const packBytePair = (v1, v2) => {
|
|
147
|
-
const result = (packFunction(v1) << 4) | packFunction(v2)
|
|
148
|
-
return result
|
|
149
|
-
}
|
|
150
|
-
const strLengthHalf = Math.floor(str.length / 2)
|
|
107
|
+
const result = (packFunction(v1) << 4) | packFunction(v2);
|
|
108
|
+
return result;
|
|
109
|
+
};
|
|
110
|
+
const strLengthHalf = Math.floor(str.length / 2);
|
|
151
111
|
for (let i = 0; i < strLengthHalf; i++) {
|
|
152
|
-
pushByte(packBytePair(str[2 * i], str[2 * i + 1]))
|
|
112
|
+
pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
|
|
153
113
|
}
|
|
154
114
|
if (str.length % 2 !== 0) {
|
|
155
|
-
pushByte(packBytePair(str[str.length - 1], '\x00'))
|
|
115
|
+
pushByte(packBytePair(str[str.length - 1], '\x00'));
|
|
156
116
|
}
|
|
157
|
-
}
|
|
158
|
-
|
|
117
|
+
};
|
|
159
118
|
const isNibble = (str) => {
|
|
160
119
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
161
|
-
return false
|
|
120
|
+
return false;
|
|
162
121
|
}
|
|
163
122
|
for (const char of str) {
|
|
164
|
-
const isInNibbleRange = char >= '0' && char <= '9'
|
|
123
|
+
const isInNibbleRange = char >= '0' && char <= '9';
|
|
165
124
|
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
166
|
-
return false
|
|
125
|
+
return false;
|
|
167
126
|
}
|
|
168
127
|
}
|
|
169
|
-
return true
|
|
170
|
-
}
|
|
171
|
-
|
|
128
|
+
return true;
|
|
129
|
+
};
|
|
172
130
|
const isHex = (str) => {
|
|
173
131
|
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
174
|
-
return false
|
|
132
|
+
return false;
|
|
175
133
|
}
|
|
176
134
|
for (const char of str) {
|
|
177
|
-
const isInNibbleRange = char >= '0' && char <= '9'
|
|
135
|
+
const isInNibbleRange = char >= '0' && char <= '9';
|
|
178
136
|
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
179
|
-
return false
|
|
137
|
+
return false;
|
|
180
138
|
}
|
|
181
139
|
}
|
|
182
|
-
return true
|
|
183
|
-
}
|
|
184
|
-
|
|
140
|
+
return true;
|
|
141
|
+
};
|
|
185
142
|
const writeString = (str) => {
|
|
186
|
-
|
|
187
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
188
|
-
return
|
|
143
|
+
if (str === undefined || str === null) {
|
|
144
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
145
|
+
return;
|
|
189
146
|
}
|
|
190
|
-
|
|
147
|
+
if (str === '') {
|
|
148
|
+
writeStringRaw(str);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const tokenIndex = TOKEN_MAP[str];
|
|
191
152
|
if (tokenIndex) {
|
|
192
153
|
if (typeof tokenIndex.dict === 'number') {
|
|
193
|
-
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict)
|
|
154
|
+
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
|
|
194
155
|
}
|
|
195
|
-
pushByte(tokenIndex.index)
|
|
156
|
+
pushByte(tokenIndex.index);
|
|
196
157
|
}
|
|
197
158
|
else if (isNibble(str)) {
|
|
198
|
-
writePackedBytes(str, 'nibble')
|
|
159
|
+
writePackedBytes(str, 'nibble');
|
|
199
160
|
}
|
|
200
161
|
else if (isHex(str)) {
|
|
201
|
-
writePackedBytes(str, 'hex')
|
|
162
|
+
writePackedBytes(str, 'hex');
|
|
202
163
|
}
|
|
203
|
-
else
|
|
204
|
-
const decodedJid =
|
|
164
|
+
else {
|
|
165
|
+
const decodedJid = jidDecode(str);
|
|
205
166
|
if (decodedJid) {
|
|
206
|
-
writeJid(decodedJid)
|
|
167
|
+
writeJid(decodedJid);
|
|
207
168
|
}
|
|
208
169
|
else {
|
|
209
|
-
writeStringRaw(str)
|
|
170
|
+
writeStringRaw(str);
|
|
210
171
|
}
|
|
211
172
|
}
|
|
212
|
-
}
|
|
213
|
-
|
|
173
|
+
};
|
|
214
174
|
const writeListStart = (listSize) => {
|
|
215
175
|
if (listSize === 0) {
|
|
216
|
-
pushByte(TAGS.LIST_EMPTY)
|
|
176
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
217
177
|
}
|
|
218
178
|
else if (listSize < 256) {
|
|
219
|
-
pushBytes([TAGS.LIST_8, listSize])
|
|
179
|
+
pushBytes([TAGS.LIST_8, listSize]);
|
|
220
180
|
}
|
|
221
181
|
else {
|
|
222
|
-
pushByte(TAGS.LIST_16)
|
|
223
|
-
pushInt16(listSize)
|
|
182
|
+
pushByte(TAGS.LIST_16);
|
|
183
|
+
pushInt16(listSize);
|
|
224
184
|
}
|
|
225
|
-
}
|
|
226
|
-
|
|
185
|
+
};
|
|
227
186
|
if (!tag) {
|
|
228
|
-
throw new Error('Invalid node: tag cannot be undefined')
|
|
187
|
+
throw new Error('Invalid node: tag cannot be undefined');
|
|
229
188
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
writeString(tag)
|
|
189
|
+
const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
|
|
190
|
+
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
|
|
191
|
+
writeString(tag);
|
|
234
192
|
for (const key of validAttributes) {
|
|
235
193
|
if (typeof attrs[key] === 'string') {
|
|
236
|
-
writeString(key)
|
|
237
|
-
writeString(attrs[key])
|
|
194
|
+
writeString(key);
|
|
195
|
+
writeString(attrs[key]);
|
|
238
196
|
}
|
|
239
197
|
}
|
|
240
198
|
if (typeof content === 'string') {
|
|
241
|
-
writeString(content)
|
|
199
|
+
writeString(content);
|
|
242
200
|
}
|
|
243
201
|
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
244
|
-
writeByteLength(content.length)
|
|
245
|
-
pushBytes(content)
|
|
202
|
+
writeByteLength(content.length);
|
|
203
|
+
pushBytes(content);
|
|
246
204
|
}
|
|
247
205
|
else if (Array.isArray(content)) {
|
|
248
|
-
|
|
249
|
-
writeListStart(validContent.length)
|
|
206
|
+
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
|
|
207
|
+
writeListStart(validContent.length);
|
|
250
208
|
for (const item of validContent) {
|
|
251
|
-
encodeBinaryNodeInner(item, opts, buffer)
|
|
209
|
+
encodeBinaryNodeInner(item, opts, buffer);
|
|
252
210
|
}
|
|
253
211
|
}
|
|
254
212
|
else if (typeof content === 'undefined') {
|
|
255
213
|
// do nothing
|
|
256
214
|
}
|
|
257
215
|
else {
|
|
258
|
-
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`)
|
|
216
|
+
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
|
|
259
217
|
}
|
|
260
|
-
return buffer
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
module.exports = {
|
|
264
|
-
encodeBinaryNode
|
|
265
|
-
}
|
|
218
|
+
return buffer;
|
|
219
|
+
};
|
|
220
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { type BinaryNode } from './types.js';
|
|
3
|
+
|
|
4
4
|
export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
|
|
5
|
-
export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
|
|
6
5
|
export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
|
|
7
|
-
export declare const
|
|
6
|
+
export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
|
|
7
|
+
export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | undefined;
|
|
8
8
|
export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => string | undefined;
|
|
9
9
|
export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
|
|
10
10
|
export declare const assertNodeErrorFree: (node: BinaryNode) => void;
|
|
@@ -12,6 +12,7 @@ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: strin
|
|
|
12
12
|
[_: string]: string;
|
|
13
13
|
};
|
|
14
14
|
export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
|
|
15
|
-
export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number):
|
|
15
|
+
export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): string;
|
|
16
16
|
export declare const getBinaryNodeFilter: (node: BinaryNode[]) => boolean;
|
|
17
|
-
export declare const getAdditionalNode: (name
|
|
17
|
+
export declare const getAdditionalNode: (name?: string) => BinaryNode[];
|
|
18
|
+
//# sourceMappingURL=generic-utils.d.ts.map
|