@rizzxdc/baileys 8.0.10 → 8.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/LICENSE +4 -2
- package/README.md +107 -245
- package/WAProto/index.d.ts +15795 -0
- package/WAProto/index.js +25587 -4867
- package/lib/Defaults/index.d.ts +147 -0
- package/lib/Defaults/index.js +134 -104
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +9 -11
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +5 -8
- package/lib/Signal/Group/group_cipher.d.ts +11 -0
- package/lib/Signal/Group/group_cipher.js +72 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +11 -13
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +11 -14
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +23 -26
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +58 -61
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +61 -64
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +39 -44
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +35 -38
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +76 -79
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -26
- package/lib/Signal/libsignal.d.ts +55 -0
- package/lib/Signal/libsignal.js +414 -308
- package/lib/Signal/lid-mapping.d.ts +21 -0
- package/lib/Signal/lid-mapping.js +270 -149
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -4
- package/lib/Socket/Client/types.d.ts +6 -0
- package/lib/Socket/Client/types.js +8 -11
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +51 -50
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +357 -355
- package/lib/Socket/chats.d.ts +137 -0
- package/lib/Socket/chats.js +1195 -867
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.js +416 -398
- package/lib/Socket/dugong.js +8 -1
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +336 -301
- package/lib/Socket/index.d.ts +530 -0
- package/lib/Socket/index.js +8 -13
- package/lib/Socket/messages-recv.d.ts +334 -0
- package/lib/Socket/messages-recv.js +1729 -1121
- package/lib/Socket/messages-send.d.ts +330 -0
- package/lib/Socket/messages-send.js +684 -462
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +36 -40
- package/lib/Socket/newsletter.d.ts +284 -0
- package/lib/Socket/newsletter.js +247 -237
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +968 -790
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -6
- package/lib/Store/make-cache-manager-store.js +2 -2
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +414 -284
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +75 -76
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +21 -23
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Auth.js +0 -2
- package/lib/Types/Bussines.d.ts +2 -0
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.d.ts +2 -0
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +5 -7
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.d.ts +2 -0
- package/lib/Types/Events.js +1 -3
- package/lib/Types/GroupMetadata.d.ts +2 -0
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.d.ts +3 -0
- package/lib/Types/Label.js +21 -22
- package/lib/Types/LabelAssociation.d.ts +3 -0
- package/lib/Types/LabelAssociation.js +3 -4
- package/lib/Types/Message.d.ts +12 -0
- package/lib/Types/Message.js +11 -6
- package/lib/Types/Mex.d.ts +3 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +2 -0
- package/lib/Types/Product.js +0 -2
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +2 -0
- package/lib/Types/Signal.js +1 -3
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/Socket.js +1 -4
- package/lib/Types/State.d.ts +6 -0
- package/lib/Types/State.js +52 -8
- package/lib/Types/USync.d.ts +2 -0
- package/lib/Types/USync.js +1 -3
- package/lib/Types/index.d.ts +14 -0
- package/lib/Types/index.js +22 -25
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +285 -203
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +21 -19
- package/lib/Utils/business.d.ts +50 -0
- package/lib/Utils/business.js +206 -209
- package/lib/Utils/chat-utils.d.ts +409 -0
- package/lib/Utils/chat-utils.js +825 -706
- package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +88 -101
- package/lib/Utils/decode-wa-message.d.ts +84 -0
- package/lib/Utils/decode-wa-message.js +287 -238
- package/lib/Utils/event-buffer.d.ts +13 -0
- package/lib/Utils/event-buffer.js +602 -509
- package/lib/Utils/generics.d.ts +64 -0
- package/lib/Utils/generics.js +334 -295
- package/lib/Utils/history.d.ts +76 -0
- package/lib/Utils/history.js +125 -79
- package/lib/Utils/identity-change-handler.d.ts +14 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/index.d.ts +25 -0
- package/lib/Utils/index.js +25 -21
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -70
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +1 -4
- package/lib/Utils/lt-hash.d.ts +7 -0
- package/lib/Utils/lt-hash.js +7 -45
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +27 -31
- package/lib/Utils/message-retry-manager.d.ts +80 -0
- package/lib/Utils/message-retry-manager.js +165 -14
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +768 -572
- package/lib/Utils/messages.d.ts +46 -0
- package/lib/Utils/messages.js +1082 -130
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +191 -135
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/pre-key-manager.d.ts +26 -0
- package/lib/Utils/pre-key-manager.js +96 -76
- package/lib/Utils/process-message.d.ts +84 -0
- package/lib/Utils/process-message.js +718 -311
- package/lib/Utils/reporting-utils.d.ts +13 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.js +257 -0
- package/lib/Utils/signal.d.ts +83 -0
- package/lib/Utils/signal.js +174 -135
- package/lib/Utils/stanza-ack.d.ts +17 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.d.ts +3 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +30 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -95
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +108 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +182 -180
- package/lib/WABinary/constants.d.ts +62 -0
- package/lib/WABinary/constants.js +1455 -1292
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +249 -228
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +207 -206
- package/lib/WABinary/generic-utils.d.ts +77 -0
- package/lib/WABinary/generic-utils.js +135 -99
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +5 -7
- package/lib/WABinary/jid-utils.d.ts +29 -0
- package/lib/WABinary/jid-utils.js +80 -78
- package/lib/WABinary/types.d.ts +2 -0
- package/lib/WABinary/types.js +1 -3
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +7 -9
- package/lib/WAM/constants.d.ts +34927 -0
- package/lib/WAM/constants.js +22847 -22848
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +129 -134
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +48 -27
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -35
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +46 -49
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +23 -25
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +5 -6
- package/lib/WAUSync/USyncQuery.d.ts +21 -0
- package/lib/WAUSync/USyncQuery.js +92 -85
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +28 -22
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -5
- package/lib/index.d.ts +12 -0
- package/lib/index.js +31 -19
- package/package.json +12 -6
- package/lib/Types/Newsletter.js +0 -33
package/lib/WABinary/encode.js
CHANGED
|
@@ -1,218 +1,219 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { jidDecode } from "./jid-utils.js";
|
|
4
|
-
//=======================================================//
|
|
1
|
+
import * as constants from './constants.js';
|
|
2
|
+
import { jidDecode } from './jid-utils.js';
|
|
5
3
|
export const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const encoded = encodeBinaryNodeInner(node, opts, buffer);
|
|
5
|
+
return Buffer.from(encoded);
|
|
8
6
|
};
|
|
9
|
-
//=======================================================//
|
|
10
7
|
const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
const pushBytes = (bytes) => {
|
|
20
|
-
for (const b of bytes) {
|
|
21
|
-
buffer.push(b);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const pushInt16 = (value) => {
|
|
25
|
-
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
26
|
-
};
|
|
27
|
-
const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
|
|
28
|
-
const writeByteLength = (length) => {
|
|
29
|
-
if (length >= 4294967296) {
|
|
30
|
-
throw new Error("string too large to encode: " + length);
|
|
31
|
-
}
|
|
32
|
-
if (length >= 1 << 20) {
|
|
33
|
-
pushByte(TAGS.BINARY_32);
|
|
34
|
-
pushInt(length, 4);
|
|
35
|
-
}
|
|
36
|
-
else if (length >= 256) {
|
|
37
|
-
pushByte(TAGS.BINARY_20);
|
|
38
|
-
pushInt20(length);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
pushByte(TAGS.BINARY_8);
|
|
42
|
-
pushByte(length);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const writeStringRaw = (str) => {
|
|
46
|
-
const bytes = Buffer.from(str, "utf-8");
|
|
47
|
-
writeByteLength(bytes.length);
|
|
48
|
-
pushBytes(bytes);
|
|
49
|
-
};
|
|
50
|
-
const writeJid = ({ domainType, device, user, server }) => {
|
|
51
|
-
if (typeof device !== "undefined") {
|
|
52
|
-
pushByte(TAGS.AD_JID);
|
|
53
|
-
pushByte(domainType || 0);
|
|
54
|
-
pushByte(device || 0);
|
|
55
|
-
writeString(user);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
pushByte(TAGS.JID_PAIR);
|
|
59
|
-
if (user.length) {
|
|
60
|
-
writeString(user);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
pushByte(TAGS.LIST_EMPTY);
|
|
64
|
-
}
|
|
65
|
-
writeString(server);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const packNibble = (char) => {
|
|
69
|
-
switch (char) {
|
|
70
|
-
case "-":
|
|
71
|
-
return 10;
|
|
72
|
-
case ".":
|
|
73
|
-
return 11;
|
|
74
|
-
case "\0":
|
|
75
|
-
return 15;
|
|
76
|
-
default:
|
|
77
|
-
if (char >= "0" && char <= "9") {
|
|
78
|
-
return char.charCodeAt(0) - "0".charCodeAt(0);
|
|
79
|
-
}
|
|
80
|
-
throw new Error(`invalid byte for nibble "${char}"`);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
const packHex = (char) => {
|
|
84
|
-
if (char >= "0" && char <= "9") {
|
|
85
|
-
return char.charCodeAt(0) - "0".charCodeAt(0);
|
|
86
|
-
}
|
|
87
|
-
if (char >= "A" && char <= "F") {
|
|
88
|
-
return 10 + char.charCodeAt(0) - "A".charCodeAt(0);
|
|
89
|
-
}
|
|
90
|
-
if (char >= "a" && char <= "f") {
|
|
91
|
-
return 10 + char.charCodeAt(0) - "a".charCodeAt(0);
|
|
92
|
-
}
|
|
93
|
-
if (char === "\0") {
|
|
94
|
-
return 15;
|
|
95
|
-
}
|
|
96
|
-
throw new Error(`Invalid hex char "${char}"`);
|
|
97
|
-
};
|
|
98
|
-
const writePackedBytes = (str, type) => {
|
|
99
|
-
if (str.length > TAGS.PACKED_MAX) {
|
|
100
|
-
throw new Error("Too many bytes to pack");
|
|
101
|
-
}
|
|
102
|
-
pushByte(type === "nibble" ? TAGS.NIBBLE_8 : TAGS.HEX_8);
|
|
103
|
-
let roundedLength = Math.ceil(str.length / 2.0);
|
|
104
|
-
if (str.length % 2 !== 0) {
|
|
105
|
-
roundedLength |= 128;
|
|
106
|
-
}
|
|
107
|
-
pushByte(roundedLength);
|
|
108
|
-
const packFunction = type === "nibble" ? packNibble : packHex;
|
|
109
|
-
const packBytePair = (v1, v2) => {
|
|
110
|
-
const result = (packFunction(v1) << 4) | packFunction(v2);
|
|
111
|
-
return result;
|
|
8
|
+
const { TAGS, TOKEN_MAP } = opts;
|
|
9
|
+
const pushByte = (value) => buffer.push(value & 0xff);
|
|
10
|
+
const pushInt = (value, n, littleEndian = false) => {
|
|
11
|
+
for (let i = 0; i < n; i++) {
|
|
12
|
+
const curShift = littleEndian ? i : n - 1 - i;
|
|
13
|
+
buffer.push((value >> (curShift * 8)) & 0xff);
|
|
14
|
+
}
|
|
112
15
|
};
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
16
|
+
const pushBytes = (bytes) => {
|
|
17
|
+
for (const b of bytes) {
|
|
18
|
+
buffer.push(b);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const pushInt16 = (value) => {
|
|
22
|
+
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
23
|
+
};
|
|
24
|
+
const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
|
|
25
|
+
const writeByteLength = (length) => {
|
|
26
|
+
if (length >= 4294967296) {
|
|
27
|
+
throw new Error('string too large to encode: ' + length);
|
|
28
|
+
}
|
|
29
|
+
if (length >= 1 << 20) {
|
|
30
|
+
pushByte(TAGS.BINARY_32);
|
|
31
|
+
pushInt(length, 4); // 32 bit integer
|
|
32
|
+
}
|
|
33
|
+
else if (length >= 256) {
|
|
34
|
+
pushByte(TAGS.BINARY_20);
|
|
35
|
+
pushInt20(length);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
pushByte(TAGS.BINARY_8);
|
|
39
|
+
pushByte(length);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const writeStringRaw = (str) => {
|
|
43
|
+
const bytes = Buffer.from(str, 'utf-8');
|
|
44
|
+
writeByteLength(bytes.length);
|
|
45
|
+
pushBytes(bytes);
|
|
46
|
+
};
|
|
47
|
+
const writeJid = ({ domainType, device, user, server }) => {
|
|
48
|
+
if (typeof device !== 'undefined') {
|
|
49
|
+
pushByte(TAGS.AD_JID);
|
|
50
|
+
pushByte(domainType || 0);
|
|
51
|
+
pushByte(device || 0);
|
|
52
|
+
writeString(user);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
pushByte(TAGS.JID_PAIR);
|
|
56
|
+
if (user.length) {
|
|
57
|
+
writeString(user);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
61
|
+
}
|
|
62
|
+
writeString(server);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const packNibble = (char) => {
|
|
66
|
+
switch (char) {
|
|
67
|
+
case '-':
|
|
68
|
+
return 10;
|
|
69
|
+
case '.':
|
|
70
|
+
return 11;
|
|
71
|
+
case '\0':
|
|
72
|
+
return 15;
|
|
73
|
+
default:
|
|
74
|
+
if (char >= '0' && char <= '9') {
|
|
75
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`invalid byte for nibble "${char}"`);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const packHex = (char) => {
|
|
81
|
+
if (char >= '0' && char <= '9') {
|
|
82
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
83
|
+
}
|
|
84
|
+
if (char >= 'A' && char <= 'F') {
|
|
85
|
+
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
|
|
86
|
+
}
|
|
87
|
+
if (char >= 'a' && char <= 'f') {
|
|
88
|
+
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
|
|
89
|
+
}
|
|
90
|
+
if (char === '\0') {
|
|
91
|
+
return 15;
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`Invalid hex char "${char}"`);
|
|
94
|
+
};
|
|
95
|
+
const writePackedBytes = (str, type) => {
|
|
96
|
+
if (str.length > TAGS.PACKED_MAX) {
|
|
97
|
+
throw new Error('Too many bytes to pack');
|
|
98
|
+
}
|
|
99
|
+
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
|
|
100
|
+
let roundedLength = Math.ceil(str.length / 2.0);
|
|
101
|
+
if (str.length % 2 !== 0) {
|
|
102
|
+
roundedLength |= 128;
|
|
103
|
+
}
|
|
104
|
+
pushByte(roundedLength);
|
|
105
|
+
const packFunction = type === 'nibble' ? packNibble : packHex;
|
|
106
|
+
const packBytePair = (v1, v2) => {
|
|
107
|
+
const result = (packFunction(v1) << 4) | packFunction(v2);
|
|
108
|
+
return result;
|
|
109
|
+
};
|
|
110
|
+
const strLengthHalf = Math.floor(str.length / 2);
|
|
111
|
+
for (let i = 0; i < strLengthHalf; i++) {
|
|
112
|
+
pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
|
|
113
|
+
}
|
|
114
|
+
if (str.length % 2 !== 0) {
|
|
115
|
+
pushByte(packBytePair(str[str.length - 1], '\x00'));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const isNibble = (str) => {
|
|
119
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
for (const char of str) {
|
|
123
|
+
const isInNibbleRange = char >= '0' && char <= '9';
|
|
124
|
+
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
};
|
|
130
|
+
const isHex = (str) => {
|
|
131
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
for (const char of str) {
|
|
135
|
+
const isInNibbleRange = char >= '0' && char <= '9';
|
|
136
|
+
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
};
|
|
142
|
+
const writeString = (str) => {
|
|
143
|
+
if (str === undefined || str === null) {
|
|
144
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (str === '') {
|
|
148
|
+
writeStringRaw(str);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const tokenIndex = TOKEN_MAP[str];
|
|
152
|
+
if (tokenIndex) {
|
|
153
|
+
if (typeof tokenIndex.dict === 'number') {
|
|
154
|
+
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
|
|
155
|
+
}
|
|
156
|
+
pushByte(tokenIndex.index);
|
|
157
|
+
}
|
|
158
|
+
else if (isNibble(str)) {
|
|
159
|
+
writePackedBytes(str, 'nibble');
|
|
160
|
+
}
|
|
161
|
+
else if (isHex(str)) {
|
|
162
|
+
writePackedBytes(str, 'hex');
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const decodedJid = jidDecode(str);
|
|
166
|
+
if (decodedJid) {
|
|
167
|
+
writeJid(decodedJid);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
writeStringRaw(str);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const writeListStart = (listSize) => {
|
|
175
|
+
if (listSize === 0) {
|
|
176
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
177
|
+
}
|
|
178
|
+
else if (listSize < 256) {
|
|
179
|
+
pushBytes([TAGS.LIST_8, listSize]);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
pushByte(TAGS.LIST_16);
|
|
183
|
+
pushInt16(listSize);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
if (!tag) {
|
|
187
|
+
throw new Error('Invalid node: tag cannot be undefined');
|
|
188
|
+
}
|
|
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);
|
|
192
|
+
for (const key of validAttributes) {
|
|
193
|
+
if (typeof attrs[key] === 'string') {
|
|
194
|
+
writeString(key);
|
|
195
|
+
writeString(attrs[key]);
|
|
196
|
+
}
|
|
159
197
|
}
|
|
160
|
-
|
|
161
|
-
|
|
198
|
+
if (typeof content === 'string') {
|
|
199
|
+
writeString(content);
|
|
162
200
|
}
|
|
163
|
-
else if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
writeJid(decodedJid);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
writeStringRaw(str);
|
|
170
|
-
}
|
|
201
|
+
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
202
|
+
writeByteLength(content.length);
|
|
203
|
+
pushBytes(content);
|
|
171
204
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
205
|
+
else if (Array.isArray(content)) {
|
|
206
|
+
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
|
|
207
|
+
writeListStart(validContent.length);
|
|
208
|
+
for (const item of validContent) {
|
|
209
|
+
encodeBinaryNodeInner(item, opts, buffer);
|
|
210
|
+
}
|
|
176
211
|
}
|
|
177
|
-
else if (
|
|
178
|
-
|
|
212
|
+
else if (typeof content === 'undefined') {
|
|
213
|
+
// do nothing
|
|
179
214
|
}
|
|
180
215
|
else {
|
|
181
|
-
|
|
182
|
-
pushInt16(listSize);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
if (!tag) {
|
|
186
|
-
throw new Error("Invalid node: tag cannot be undefined");
|
|
187
|
-
}
|
|
188
|
-
const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== "undefined" && attrs[k] !== null);
|
|
189
|
-
writeListStart(2 * validAttributes.length + 1 + (typeof content !== "undefined" ? 1 : 0));
|
|
190
|
-
writeString(tag);
|
|
191
|
-
for (const key of validAttributes) {
|
|
192
|
-
if (typeof attrs[key] === "string") {
|
|
193
|
-
writeString(key);
|
|
194
|
-
writeString(attrs[key]);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (typeof content === "string") {
|
|
198
|
-
writeString(content);
|
|
199
|
-
}
|
|
200
|
-
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
201
|
-
writeByteLength(content.length);
|
|
202
|
-
pushBytes(content);
|
|
203
|
-
}
|
|
204
|
-
else if (Array.isArray(content)) {
|
|
205
|
-
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === "string"));
|
|
206
|
-
writeListStart(validContent.length);
|
|
207
|
-
for (const item of validContent) {
|
|
208
|
-
encodeBinaryNodeInner(item, opts, buffer);
|
|
216
|
+
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
|
|
209
217
|
}
|
|
210
|
-
|
|
211
|
-
else if (typeof content === "undefined") {
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
|
|
215
|
-
}
|
|
216
|
-
return buffer;
|
|
218
|
+
return buffer;
|
|
217
219
|
};
|
|
218
|
-
//=======================================================//
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export function binaryNodeToString(node: any, i?: number): any;
|
|
2
|
+
export function getBinaryNodeChildren(node: any, childTag: any): any;
|
|
3
|
+
export function getBinaryNodeChild(node: any, childTag: any): any;
|
|
4
|
+
export function getAllBinaryNodeChildren({ content }: {
|
|
5
|
+
content: any;
|
|
6
|
+
}): any[];
|
|
7
|
+
export function getBinaryNodeChildBuffer(node: any, childTag: any): any;
|
|
8
|
+
export function getBinaryNodeChildString(node: any, childTag: any): any;
|
|
9
|
+
export function getBinaryNodeChildUInt(node: any, childTag: any, length: any): number | undefined;
|
|
10
|
+
export function assertNodeErrorFree(node: any): void;
|
|
11
|
+
export function reduceBinaryNodeToDictionary(node: any, tag: any): any;
|
|
12
|
+
export function getBinaryNodeMessages({ content }: {
|
|
13
|
+
content: any;
|
|
14
|
+
}): {
|
|
15
|
+
[k: string]: any;
|
|
16
|
+
}[];
|
|
17
|
+
export function getBizBinaryNode(message: any): {
|
|
18
|
+
tag: string;
|
|
19
|
+
attrs: {
|
|
20
|
+
actual_actors: string;
|
|
21
|
+
host_storage: string;
|
|
22
|
+
privacy_mode_ts: string;
|
|
23
|
+
};
|
|
24
|
+
content: ({
|
|
25
|
+
tag: string;
|
|
26
|
+
attrs: {
|
|
27
|
+
decision_id: any;
|
|
28
|
+
source_type: string;
|
|
29
|
+
};
|
|
30
|
+
content: {
|
|
31
|
+
tag: string;
|
|
32
|
+
attrs: {
|
|
33
|
+
value: string;
|
|
34
|
+
};
|
|
35
|
+
}[];
|
|
36
|
+
} | {
|
|
37
|
+
tag: string;
|
|
38
|
+
attrs: {
|
|
39
|
+
type: string;
|
|
40
|
+
v: string;
|
|
41
|
+
};
|
|
42
|
+
content: {
|
|
43
|
+
tag: string;
|
|
44
|
+
attrs: {
|
|
45
|
+
v: string;
|
|
46
|
+
name: any;
|
|
47
|
+
};
|
|
48
|
+
}[];
|
|
49
|
+
})[];
|
|
50
|
+
} | {
|
|
51
|
+
tag: string;
|
|
52
|
+
attrs: {
|
|
53
|
+
actual_actors: string;
|
|
54
|
+
host_storage: string;
|
|
55
|
+
privacy_mode_ts: string;
|
|
56
|
+
};
|
|
57
|
+
content: ({
|
|
58
|
+
tag: string;
|
|
59
|
+
attrs: {
|
|
60
|
+
decision_id: any;
|
|
61
|
+
source_type: string;
|
|
62
|
+
};
|
|
63
|
+
content: {
|
|
64
|
+
tag: string;
|
|
65
|
+
attrs: {
|
|
66
|
+
value: string;
|
|
67
|
+
};
|
|
68
|
+
}[];
|
|
69
|
+
} | {
|
|
70
|
+
tag: string;
|
|
71
|
+
attrs: {
|
|
72
|
+
v: string;
|
|
73
|
+
type: string;
|
|
74
|
+
};
|
|
75
|
+
})[];
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=generic-utils.d.ts.map
|