@zervonexx/baileys 5.0.0 → 5.0.2
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 +22 -22
- package/README.md +4124 -4112
- package/WAProto/WAProto.json +1 -0
- package/WAProto/WAProto.proto +7160 -0
- package/WAProto/WAProtoCompile.js +264 -322
- package/WAProto/index.js +55 -95
- package/lib/Builders/AIRich.js +673 -673
- package/lib/Builders/auto.js +49 -49
- package/lib/Builders/base.js +144 -144
- package/lib/Builders/builders.js +588 -588
- package/lib/Builders/index.js +3 -3
- package/lib/Defaults/index.js +249 -248
- package/lib/Signal/index.js +2 -2
- package/lib/Signal/libsignal.js +526 -526
- package/lib/Signal/lid-mapping.js +282 -282
- package/lib/Socket/Client/index.js +1 -1
- package/lib/Socket/Client/types.js +9 -9
- package/lib/Socket/Client/websocket.js +83 -83
- package/lib/Socket/business.js +151 -151
- package/lib/Socket/chats.js +854 -854
- package/lib/Socket/communities.js +146 -146
- package/lib/Socket/groups.js +293 -293
- package/lib/Socket/index.js +17 -14
- package/lib/Socket/messages-recv.js +993 -993
- package/lib/Socket/messages-send.js +722 -722
- package/lib/Socket/mex.js +33 -33
- package/lib/Socket/newsletter.js +783 -783
- package/lib/Socket/registration.js +154 -154
- package/lib/Socket/socket.js +797 -797
- package/lib/Socket/spam-report.js +143 -143
- package/lib/Socket/username.js +81 -81
- package/lib/Socket/zervonex-handler.js +57 -57
- package/lib/Store/index.js +6 -6
- package/lib/Store/make-cache-manager-store.js +80 -80
- package/lib/Store/make-in-memory-store.js +426 -426
- package/lib/Store/make-ordered-dictionary.js +81 -81
- package/lib/Store/object-repository.js +30 -30
- package/lib/Store/reporting-info-store.js +37 -37
- package/lib/Types/Auth.js +1 -1
- package/lib/Types/Bussines.js +1 -1
- package/lib/Types/Call.js +1 -1
- package/lib/Types/Chat.js +7 -7
- package/lib/Types/Contact.js +1 -1
- package/lib/Types/Events.js +1 -1
- package/lib/Types/GroupMetadata.js +1 -1
- package/lib/Types/Label.js +24 -24
- package/lib/Types/LabelAssociation.js +6 -6
- package/lib/Types/Message.js +14 -14
- package/lib/Types/Newsletter.js +99 -99
- package/lib/Types/Product.js +1 -1
- package/lib/Types/Signal.js +1 -1
- package/lib/Types/Socket.js +14 -14
- package/lib/Types/State.js +26 -26
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.js +30 -30
- package/lib/Utils/auth-utils.js +159 -159
- package/lib/Utils/baileys-event-stream.js +32 -32
- package/lib/Utils/bot-capabilities.js +40 -40
- package/lib/Utils/bot-planning-replay.js +43 -43
- package/lib/Utils/browser-utils.js +29 -29
- package/lib/Utils/business.js +74 -74
- package/lib/Utils/chat-utils.js +316 -316
- package/lib/Utils/companion-reg-client-utils.js +19 -19
- package/lib/Utils/consumer-application.js +37 -37
- package/lib/Utils/crypto.js +52 -52
- package/lib/Utils/cstoken.js +14 -14
- package/lib/Utils/decode-wa-message.js +199 -199
- package/lib/Utils/event-buffer.js +272 -272
- package/lib/Utils/extras.js +186 -186
- package/lib/Utils/generics.js +195 -194
- package/lib/Utils/history.js +50 -50
- package/lib/Utils/identity-change-handler.js +18 -18
- package/lib/Utils/index.js +40 -40
- package/lib/Utils/link-preview.js +50 -50
- package/lib/Utils/logger.js +3 -2
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/make-mutex.js +15 -15
- package/lib/Utils/message-composer.js +61 -61
- package/lib/Utils/message-retry-manager.js +47 -47
- package/lib/Utils/messages-media.js +501 -501
- package/lib/Utils/messages.js +944 -942
- package/lib/Utils/meta-ai-msmsg.js +121 -121
- package/lib/Utils/meta-compositing.js +74 -74
- package/lib/Utils/modern-messages.js +234 -234
- package/lib/Utils/native-flow.js +80 -80
- package/lib/Utils/noise-handler.js +160 -160
- package/lib/Utils/pre-key-manager.js +75 -75
- package/lib/Utils/process-message.js +400 -400
- package/lib/Utils/reporting-utils.js +170 -170
- package/lib/Utils/signal.js +166 -166
- package/lib/Utils/spam-report-utils.js +165 -165
- package/lib/Utils/sync-action-utils.js +33 -33
- package/lib/Utils/tc-token-utils.js +153 -153
- package/lib/Utils/use-keyv-auth-state.js +199 -199
- package/lib/Utils/use-multi-file-auth-state.js +83 -83
- package/lib/Utils/validate-connection.js +171 -171
- package/lib/WABinary/constants.js +1320 -1320
- package/lib/WABinary/decode.js +151 -151
- package/lib/WABinary/encode.js +139 -139
- package/lib/WABinary/generic-utils.js +202 -202
- package/lib/WABinary/index.js +6 -6
- package/lib/WABinary/jid-utils.js +235 -235
- package/lib/WABinary/types.js +4 -4
- package/lib/WAM/BinaryInfo.js +9 -9
- package/lib/WAM/constants.js +22852 -22852
- package/lib/WAM/encode.js +149 -149
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +30 -30
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +48 -48
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +28 -28
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +15 -15
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +24 -24
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +21 -21
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +19 -19
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +19 -19
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +16 -16
- package/lib/WAUSync/Protocols/index.js +12 -12
- package/lib/WAUSync/USyncQuery.js +88 -88
- package/lib/WAUSync/USyncUser.js +20 -20
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.js +66 -66
- package/package.json +187 -192
- package/WAProto/fetcher.js +0 -68
- package/WAProto/parser.js +0 -334
package/lib/WAM/encode.js
CHANGED
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
import { BinaryInfo } from './BinaryInfo.js';
|
|
2
|
-
import { FLAG_BYTE, FLAG_EVENT, FLAG_EXTENDED, FLAG_FIELD, FLAG_GLOBAL, WEB_EVENTS, WEB_GLOBALS } from './constants.js';
|
|
3
|
-
const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
|
|
4
|
-
export const encodeWAM = (binaryInfo) => {
|
|
5
|
-
binaryInfo.buffer = [];
|
|
6
|
-
encodeWAMHeader(binaryInfo);
|
|
7
|
-
encodeEvents(binaryInfo);
|
|
8
|
-
const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b);
|
|
9
|
-
const buffer = Buffer.alloc(totalSize);
|
|
10
|
-
let offset = 0;
|
|
11
|
-
for (const buffer_ of binaryInfo.buffer) {
|
|
12
|
-
buffer_.copy(buffer, offset);
|
|
13
|
-
offset += buffer_.length;
|
|
14
|
-
}
|
|
15
|
-
return buffer;
|
|
16
|
-
};
|
|
17
|
-
function encodeWAMHeader(binaryInfo) {
|
|
18
|
-
const headerBuffer = Buffer.alloc(8); // starting buffer
|
|
19
|
-
headerBuffer.write('WAM', 0, 'utf8');
|
|
20
|
-
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
|
|
21
|
-
headerBuffer.writeUInt8(1, 4); //random flag
|
|
22
|
-
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
|
|
23
|
-
headerBuffer.writeUInt8(0, 7); // regular channel
|
|
24
|
-
binaryInfo.buffer.push(headerBuffer);
|
|
25
|
-
}
|
|
26
|
-
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
27
|
-
for (const [key, _value] of Object.entries(globals)) {
|
|
28
|
-
const id = WEB_GLOBALS.find(a => a?.name === key).id;
|
|
29
|
-
let value = _value;
|
|
30
|
-
if (typeof value === 'boolean') {
|
|
31
|
-
value = value ? 1 : 0;
|
|
32
|
-
}
|
|
33
|
-
binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function encodeEvents(binaryInfo) {
|
|
37
|
-
for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
|
|
38
|
-
encodeGlobalAttributes(binaryInfo, globals);
|
|
39
|
-
const event = WEB_EVENTS.find(a => a.name === name);
|
|
40
|
-
const props_ = Object.entries(props);
|
|
41
|
-
let extended = false;
|
|
42
|
-
for (const [, value] of props_) {
|
|
43
|
-
extended || (extended = value !== null);
|
|
44
|
-
}
|
|
45
|
-
const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
|
|
46
|
-
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
|
|
47
|
-
for (let i = 0; i < props_.length; i++) {
|
|
48
|
-
const [key, _value] = props_[i];
|
|
49
|
-
const id = event.props[key]?.[0];
|
|
50
|
-
extended = i < props_.length - 1;
|
|
51
|
-
let value = _value;
|
|
52
|
-
if (typeof value === 'boolean') {
|
|
53
|
-
value = value ? 1 : 0;
|
|
54
|
-
}
|
|
55
|
-
const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
|
|
56
|
-
binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function serializeData(key, value, flag) {
|
|
61
|
-
const bufferLength = getHeaderBitLength(key);
|
|
62
|
-
let buffer;
|
|
63
|
-
let offset = 0;
|
|
64
|
-
if (value === null) {
|
|
65
|
-
if (flag === FLAG_GLOBAL) {
|
|
66
|
-
buffer = Buffer.alloc(bufferLength);
|
|
67
|
-
offset = serializeHeader(buffer, offset, key, flag);
|
|
68
|
-
return buffer;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else if (typeof value === 'number' && Number.isInteger(value)) {
|
|
72
|
-
// is number
|
|
73
|
-
if (value === 0 || value === 1) {
|
|
74
|
-
buffer = Buffer.alloc(bufferLength);
|
|
75
|
-
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
|
|
76
|
-
return buffer;
|
|
77
|
-
}
|
|
78
|
-
else if (-128 <= value && value < 128) {
|
|
79
|
-
buffer = Buffer.alloc(bufferLength + 1);
|
|
80
|
-
offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
|
|
81
|
-
buffer.writeInt8(value, offset);
|
|
82
|
-
return buffer;
|
|
83
|
-
}
|
|
84
|
-
else if (-32768 <= value && value < 32768) {
|
|
85
|
-
buffer = Buffer.alloc(bufferLength + 2);
|
|
86
|
-
offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
|
|
87
|
-
buffer.writeInt16LE(value, offset);
|
|
88
|
-
return buffer;
|
|
89
|
-
}
|
|
90
|
-
else if (-2147483648 <= value && value < 2147483648) {
|
|
91
|
-
buffer = Buffer.alloc(bufferLength + 4);
|
|
92
|
-
offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
|
|
93
|
-
buffer.writeInt32LE(value, offset);
|
|
94
|
-
return buffer;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
buffer = Buffer.alloc(bufferLength + 8);
|
|
98
|
-
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
99
|
-
buffer.writeDoubleLE(value, offset);
|
|
100
|
-
return buffer;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else if (typeof value === 'number') {
|
|
104
|
-
// is float
|
|
105
|
-
buffer = Buffer.alloc(bufferLength + 8);
|
|
106
|
-
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
107
|
-
buffer.writeDoubleLE(value, offset);
|
|
108
|
-
return buffer;
|
|
109
|
-
}
|
|
110
|
-
else if (typeof value === 'string') {
|
|
111
|
-
// is string
|
|
112
|
-
const utf8Bytes = Buffer.byteLength(value, 'utf8');
|
|
113
|
-
if (utf8Bytes < 256) {
|
|
114
|
-
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
|
|
115
|
-
offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
|
|
116
|
-
buffer.writeUint8(utf8Bytes, offset++);
|
|
117
|
-
}
|
|
118
|
-
else if (utf8Bytes < 65536) {
|
|
119
|
-
buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
|
|
120
|
-
offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
|
|
121
|
-
buffer.writeUInt16LE(utf8Bytes, offset);
|
|
122
|
-
offset += 2;
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
|
|
126
|
-
offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
|
|
127
|
-
buffer.writeUInt32LE(utf8Bytes, offset);
|
|
128
|
-
offset += 4;
|
|
129
|
-
}
|
|
130
|
-
buffer.write(value, offset, 'utf8');
|
|
131
|
-
return buffer;
|
|
132
|
-
}
|
|
133
|
-
throw 'missing';
|
|
134
|
-
}
|
|
135
|
-
function serializeHeader(buffer, offset, key, flag) {
|
|
136
|
-
if (key < 256) {
|
|
137
|
-
buffer.writeUInt8(flag, offset);
|
|
138
|
-
offset += 1;
|
|
139
|
-
buffer.writeUInt8(key, offset);
|
|
140
|
-
offset += 1;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
buffer.writeUInt8(flag | FLAG_BYTE, offset);
|
|
144
|
-
offset += 1;
|
|
145
|
-
buffer.writeUInt16LE(key, offset);
|
|
146
|
-
offset += 2;
|
|
147
|
-
}
|
|
148
|
-
return offset;
|
|
149
|
-
}
|
|
1
|
+
import { BinaryInfo } from './BinaryInfo.js';
|
|
2
|
+
import { FLAG_BYTE, FLAG_EVENT, FLAG_EXTENDED, FLAG_FIELD, FLAG_GLOBAL, WEB_EVENTS, WEB_GLOBALS } from './constants.js';
|
|
3
|
+
const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
|
|
4
|
+
export const encodeWAM = (binaryInfo) => {
|
|
5
|
+
binaryInfo.buffer = [];
|
|
6
|
+
encodeWAMHeader(binaryInfo);
|
|
7
|
+
encodeEvents(binaryInfo);
|
|
8
|
+
const totalSize = binaryInfo.buffer.map(a => a.length).reduce((a, b) => a + b);
|
|
9
|
+
const buffer = Buffer.alloc(totalSize);
|
|
10
|
+
let offset = 0;
|
|
11
|
+
for (const buffer_ of binaryInfo.buffer) {
|
|
12
|
+
buffer_.copy(buffer, offset);
|
|
13
|
+
offset += buffer_.length;
|
|
14
|
+
}
|
|
15
|
+
return buffer;
|
|
16
|
+
};
|
|
17
|
+
function encodeWAMHeader(binaryInfo) {
|
|
18
|
+
const headerBuffer = Buffer.alloc(8); // starting buffer
|
|
19
|
+
headerBuffer.write('WAM', 0, 'utf8');
|
|
20
|
+
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
|
|
21
|
+
headerBuffer.writeUInt8(1, 4); //random flag
|
|
22
|
+
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
|
|
23
|
+
headerBuffer.writeUInt8(0, 7); // regular channel
|
|
24
|
+
binaryInfo.buffer.push(headerBuffer);
|
|
25
|
+
}
|
|
26
|
+
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
27
|
+
for (const [key, _value] of Object.entries(globals)) {
|
|
28
|
+
const id = WEB_GLOBALS.find(a => a?.name === key).id;
|
|
29
|
+
let value = _value;
|
|
30
|
+
if (typeof value === 'boolean') {
|
|
31
|
+
value = value ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function encodeEvents(binaryInfo) {
|
|
37
|
+
for (const [name, { props, globals }] of binaryInfo.events.map(a => Object.entries(a)[0])) {
|
|
38
|
+
encodeGlobalAttributes(binaryInfo, globals);
|
|
39
|
+
const event = WEB_EVENTS.find(a => a.name === name);
|
|
40
|
+
const props_ = Object.entries(props);
|
|
41
|
+
let extended = false;
|
|
42
|
+
for (const [, value] of props_) {
|
|
43
|
+
extended || (extended = value !== null);
|
|
44
|
+
}
|
|
45
|
+
const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
|
|
46
|
+
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
|
|
47
|
+
for (let i = 0; i < props_.length; i++) {
|
|
48
|
+
const [key, _value] = props_[i];
|
|
49
|
+
const id = event.props[key]?.[0];
|
|
50
|
+
extended = i < props_.length - 1;
|
|
51
|
+
let value = _value;
|
|
52
|
+
if (typeof value === 'boolean') {
|
|
53
|
+
value = value ? 1 : 0;
|
|
54
|
+
}
|
|
55
|
+
const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
|
|
56
|
+
binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function serializeData(key, value, flag) {
|
|
61
|
+
const bufferLength = getHeaderBitLength(key);
|
|
62
|
+
let buffer;
|
|
63
|
+
let offset = 0;
|
|
64
|
+
if (value === null) {
|
|
65
|
+
if (flag === FLAG_GLOBAL) {
|
|
66
|
+
buffer = Buffer.alloc(bufferLength);
|
|
67
|
+
offset = serializeHeader(buffer, offset, key, flag);
|
|
68
|
+
return buffer;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (typeof value === 'number' && Number.isInteger(value)) {
|
|
72
|
+
// is number
|
|
73
|
+
if (value === 0 || value === 1) {
|
|
74
|
+
buffer = Buffer.alloc(bufferLength);
|
|
75
|
+
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
|
|
76
|
+
return buffer;
|
|
77
|
+
}
|
|
78
|
+
else if (-128 <= value && value < 128) {
|
|
79
|
+
buffer = Buffer.alloc(bufferLength + 1);
|
|
80
|
+
offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
|
|
81
|
+
buffer.writeInt8(value, offset);
|
|
82
|
+
return buffer;
|
|
83
|
+
}
|
|
84
|
+
else if (-32768 <= value && value < 32768) {
|
|
85
|
+
buffer = Buffer.alloc(bufferLength + 2);
|
|
86
|
+
offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
|
|
87
|
+
buffer.writeInt16LE(value, offset);
|
|
88
|
+
return buffer;
|
|
89
|
+
}
|
|
90
|
+
else if (-2147483648 <= value && value < 2147483648) {
|
|
91
|
+
buffer = Buffer.alloc(bufferLength + 4);
|
|
92
|
+
offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
|
|
93
|
+
buffer.writeInt32LE(value, offset);
|
|
94
|
+
return buffer;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
buffer = Buffer.alloc(bufferLength + 8);
|
|
98
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
99
|
+
buffer.writeDoubleLE(value, offset);
|
|
100
|
+
return buffer;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (typeof value === 'number') {
|
|
104
|
+
// is float
|
|
105
|
+
buffer = Buffer.alloc(bufferLength + 8);
|
|
106
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
107
|
+
buffer.writeDoubleLE(value, offset);
|
|
108
|
+
return buffer;
|
|
109
|
+
}
|
|
110
|
+
else if (typeof value === 'string') {
|
|
111
|
+
// is string
|
|
112
|
+
const utf8Bytes = Buffer.byteLength(value, 'utf8');
|
|
113
|
+
if (utf8Bytes < 256) {
|
|
114
|
+
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
|
|
115
|
+
offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
|
|
116
|
+
buffer.writeUint8(utf8Bytes, offset++);
|
|
117
|
+
}
|
|
118
|
+
else if (utf8Bytes < 65536) {
|
|
119
|
+
buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
|
|
120
|
+
offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
|
|
121
|
+
buffer.writeUInt16LE(utf8Bytes, offset);
|
|
122
|
+
offset += 2;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
|
|
126
|
+
offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
|
|
127
|
+
buffer.writeUInt32LE(utf8Bytes, offset);
|
|
128
|
+
offset += 4;
|
|
129
|
+
}
|
|
130
|
+
buffer.write(value, offset, 'utf8');
|
|
131
|
+
return buffer;
|
|
132
|
+
}
|
|
133
|
+
throw 'missing';
|
|
134
|
+
}
|
|
135
|
+
function serializeHeader(buffer, offset, key, flag) {
|
|
136
|
+
if (key < 256) {
|
|
137
|
+
buffer.writeUInt8(flag, offset);
|
|
138
|
+
offset += 1;
|
|
139
|
+
buffer.writeUInt8(key, offset);
|
|
140
|
+
offset += 1;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
buffer.writeUInt8(flag | FLAG_BYTE, offset);
|
|
144
|
+
offset += 1;
|
|
145
|
+
buffer.writeUInt16LE(key, offset);
|
|
146
|
+
offset += 2;
|
|
147
|
+
}
|
|
148
|
+
return offset;
|
|
149
|
+
}
|
|
150
150
|
//# sourceMappingURL=encode.js.map
|
package/lib/WAM/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './BinaryInfo.js'
|
|
2
|
-
export * from './encode.js'
|
|
3
|
-
export * from './constants.js'
|
|
1
|
+
export * from './BinaryInfo.js'
|
|
2
|
+
export * from './encode.js'
|
|
3
|
+
export * from './constants.js'
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export class USyncBotProfileProtocol {
|
|
4
|
-
constructor() { this.name = 'bot'; }
|
|
5
|
-
|
|
6
|
-
getQueryElement() { return { tag: 'bot', attrs: {}, content: [{ tag: 'profile', attrs: { v: '1' } }] }; }
|
|
7
|
-
|
|
8
|
-
getUserElement(user) { return { tag: 'bot', attrs: {}, content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }] }; }
|
|
9
|
-
|
|
10
|
-
parser(node) {
|
|
11
|
-
const botNode = getBinaryNodeChild(node, 'bot');
|
|
12
|
-
const profile = getBinaryNodeChild(botNode, 'profile');
|
|
13
|
-
const commandsNode = getBinaryNodeChild(profile, 'commands');
|
|
14
|
-
const promptsNode = getBinaryNodeChild(profile, 'prompts');
|
|
15
|
-
const commands = getBinaryNodeChildren(commandsNode, 'command').map(c => ({ name: getBinaryNodeChildString(c, 'name'), description: getBinaryNodeChildString(c, 'description') }));
|
|
16
|
-
const prompts = getBinaryNodeChildren(promptsNode, 'prompt').map(p => `${getBinaryNodeChildString(p, 'emoji')} ${getBinaryNodeChildString(p, 'text')}`);
|
|
17
|
-
return {
|
|
18
|
-
isDefault: !!getBinaryNodeChild(profile, 'default'),
|
|
19
|
-
jid: node.attrs.jid,
|
|
20
|
-
name: getBinaryNodeChildString(profile, 'name'),
|
|
21
|
-
attributes: getBinaryNodeChildString(profile, 'attributes'),
|
|
22
|
-
description: getBinaryNodeChildString(profile, 'description'),
|
|
23
|
-
category: getBinaryNodeChildString(profile, 'category'),
|
|
24
|
-
personaId: profile.attrs['persona_id'],
|
|
25
|
-
commandsDescription: getBinaryNodeChildString(commandsNode, 'description'),
|
|
26
|
-
commands,
|
|
27
|
-
prompts
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export class USyncBotProfileProtocol {
|
|
4
|
+
constructor() { this.name = 'bot'; }
|
|
5
|
+
|
|
6
|
+
getQueryElement() { return { tag: 'bot', attrs: {}, content: [{ tag: 'profile', attrs: { v: '1' } }] }; }
|
|
7
|
+
|
|
8
|
+
getUserElement(user) { return { tag: 'bot', attrs: {}, content: [{ tag: 'profile', attrs: { persona_id: user.personaId } }] }; }
|
|
9
|
+
|
|
10
|
+
parser(node) {
|
|
11
|
+
const botNode = getBinaryNodeChild(node, 'bot');
|
|
12
|
+
const profile = getBinaryNodeChild(botNode, 'profile');
|
|
13
|
+
const commandsNode = getBinaryNodeChild(profile, 'commands');
|
|
14
|
+
const promptsNode = getBinaryNodeChild(profile, 'prompts');
|
|
15
|
+
const commands = getBinaryNodeChildren(commandsNode, 'command').map(c => ({ name: getBinaryNodeChildString(c, 'name'), description: getBinaryNodeChildString(c, 'description') }));
|
|
16
|
+
const prompts = getBinaryNodeChildren(promptsNode, 'prompt').map(p => `${getBinaryNodeChildString(p, 'emoji')} ${getBinaryNodeChildString(p, 'text')}`);
|
|
17
|
+
return {
|
|
18
|
+
isDefault: !!getBinaryNodeChild(profile, 'default'),
|
|
19
|
+
jid: node.attrs.jid,
|
|
20
|
+
name: getBinaryNodeChildString(profile, 'name'),
|
|
21
|
+
attributes: getBinaryNodeChildString(profile, 'attributes'),
|
|
22
|
+
description: getBinaryNodeChildString(profile, 'description'),
|
|
23
|
+
category: getBinaryNodeChildString(profile, 'category'),
|
|
24
|
+
personaId: profile.attrs['persona_id'],
|
|
25
|
+
commandsDescription: getBinaryNodeChildString(commandsNode, 'description'),
|
|
26
|
+
commands,
|
|
27
|
+
prompts
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildren } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export class USyncBusinessProtocol {
|
|
4
|
-
constructor(profileVersion = '2') { this.name = 'business'; this.profileVersion = profileVersion; }
|
|
5
|
-
|
|
6
|
-
getQueryElement() { return { tag: 'business', attrs: {}, content: [{ tag: 'verified_name', attrs: {} }, { tag: 'profile', attrs: { v: this.profileVersion } }] }; }
|
|
7
|
-
|
|
8
|
-
getUserElement(user) {
|
|
9
|
-
const children = [];
|
|
10
|
-
if (user.verifiedNameSerial) children.push({ tag: 'verified_name', attrs: { serial: user.verifiedNameSerial } });
|
|
11
|
-
if (user.businessProfileTag) children.push({ tag: 'profile', attrs: { tag: user.businessProfileTag } });
|
|
12
|
-
return children.length > 0 ? { tag: 'business', attrs: {}, content: children } : null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
parser(node) {
|
|
16
|
-
if (node.tag !== 'business') return null;
|
|
17
|
-
assertNodeErrorFree(node);
|
|
18
|
-
const verifiedNameNode = getBinaryNodeChild(node, 'verified_name');
|
|
19
|
-
const profileNode = getBinaryNodeChild(node, 'profile');
|
|
20
|
-
|
|
21
|
-
let businessHours;
|
|
22
|
-
if (profileNode) {
|
|
23
|
-
const bhNode = getBinaryNodeChild(profileNode, 'business_hours');
|
|
24
|
-
if (bhNode) businessHours = { timezone: bhNode.attrs?.timezone ?? null, config: getBinaryNodeChildren(bhNode, 'business_hours_config').map(({ attrs }) => ({ dayOfWeek: attrs?.day_of_week ?? null, openTime: attrs?.open_time ?? null, closeTime: attrs?.close_time ?? null, mode: attrs?.mode ?? null })) };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const addressNode = profileNode ? getBinaryNodeChild(profileNode, 'address') : null;
|
|
28
|
-
const businessAddress = addressNode?.content ? (Buffer.isBuffer(addressNode.content) ? addressNode.content.toString() : String(addressNode.content)) : (profileNode?.attrs?.address ?? null);
|
|
29
|
-
const catalogStatus = profileNode ? { exists: profileNode.attrs?.catalog_exists === 'true' || profileNode.attrs?.catalog_exists === true, sendAll: profileNode.attrs?.catalog_send_all === 'true' || profileNode.attrs?.catalog_send_all === true } : null;
|
|
30
|
-
const cartEnabled = profileNode?.attrs?.cart_enabled !== undefined ? profileNode.attrs.cart_enabled === 'true' || profileNode.attrs.cart_enabled === true : null;
|
|
31
|
-
const webCartEnabled = profileNode?.attrs?.web_cart_enabled !== undefined ? profileNode.attrs.web_cart_enabled === 'true' || profileNode.attrs.web_cart_enabled === true : null;
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
verifiedName: verifiedNameNode?.content ?? null,
|
|
35
|
-
verifiedLevel: verifiedNameNode?.attrs?.verified_level ?? null,
|
|
36
|
-
verifiedNameLevel: verifiedNameNode?.attrs?.verified_level ?? null,
|
|
37
|
-
profileTag: profileNode?.attrs?.tag ?? null,
|
|
38
|
-
pnJid: node.attrs?.pn_jid ?? null,
|
|
39
|
-
businessHours: businessHours ?? null,
|
|
40
|
-
businessAddress,
|
|
41
|
-
catalogStatus,
|
|
42
|
-
cartEnabled,
|
|
43
|
-
webCartEnabled,
|
|
44
|
-
webCartOnOff: profileNode?.attrs?.web_cart_on_off ?? null,
|
|
45
|
-
commerceExperience: profileNode?.attrs?.commerce_experience ?? null
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildren } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export class USyncBusinessProtocol {
|
|
4
|
+
constructor(profileVersion = '2') { this.name = 'business'; this.profileVersion = profileVersion; }
|
|
5
|
+
|
|
6
|
+
getQueryElement() { return { tag: 'business', attrs: {}, content: [{ tag: 'verified_name', attrs: {} }, { tag: 'profile', attrs: { v: this.profileVersion } }] }; }
|
|
7
|
+
|
|
8
|
+
getUserElement(user) {
|
|
9
|
+
const children = [];
|
|
10
|
+
if (user.verifiedNameSerial) children.push({ tag: 'verified_name', attrs: { serial: user.verifiedNameSerial } });
|
|
11
|
+
if (user.businessProfileTag) children.push({ tag: 'profile', attrs: { tag: user.businessProfileTag } });
|
|
12
|
+
return children.length > 0 ? { tag: 'business', attrs: {}, content: children } : null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
parser(node) {
|
|
16
|
+
if (node.tag !== 'business') return null;
|
|
17
|
+
assertNodeErrorFree(node);
|
|
18
|
+
const verifiedNameNode = getBinaryNodeChild(node, 'verified_name');
|
|
19
|
+
const profileNode = getBinaryNodeChild(node, 'profile');
|
|
20
|
+
|
|
21
|
+
let businessHours;
|
|
22
|
+
if (profileNode) {
|
|
23
|
+
const bhNode = getBinaryNodeChild(profileNode, 'business_hours');
|
|
24
|
+
if (bhNode) businessHours = { timezone: bhNode.attrs?.timezone ?? null, config: getBinaryNodeChildren(bhNode, 'business_hours_config').map(({ attrs }) => ({ dayOfWeek: attrs?.day_of_week ?? null, openTime: attrs?.open_time ?? null, closeTime: attrs?.close_time ?? null, mode: attrs?.mode ?? null })) };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const addressNode = profileNode ? getBinaryNodeChild(profileNode, 'address') : null;
|
|
28
|
+
const businessAddress = addressNode?.content ? (Buffer.isBuffer(addressNode.content) ? addressNode.content.toString() : String(addressNode.content)) : (profileNode?.attrs?.address ?? null);
|
|
29
|
+
const catalogStatus = profileNode ? { exists: profileNode.attrs?.catalog_exists === 'true' || profileNode.attrs?.catalog_exists === true, sendAll: profileNode.attrs?.catalog_send_all === 'true' || profileNode.attrs?.catalog_send_all === true } : null;
|
|
30
|
+
const cartEnabled = profileNode?.attrs?.cart_enabled !== undefined ? profileNode.attrs.cart_enabled === 'true' || profileNode.attrs.cart_enabled === true : null;
|
|
31
|
+
const webCartEnabled = profileNode?.attrs?.web_cart_enabled !== undefined ? profileNode.attrs.web_cart_enabled === 'true' || profileNode.attrs.web_cart_enabled === true : null;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
verifiedName: verifiedNameNode?.content ?? null,
|
|
35
|
+
verifiedLevel: verifiedNameNode?.attrs?.verified_level ?? null,
|
|
36
|
+
verifiedNameLevel: verifiedNameNode?.attrs?.verified_level ?? null,
|
|
37
|
+
profileTag: profileNode?.attrs?.tag ?? null,
|
|
38
|
+
pnJid: node.attrs?.pn_jid ?? null,
|
|
39
|
+
businessHours: businessHours ?? null,
|
|
40
|
+
businessAddress,
|
|
41
|
+
catalogStatus,
|
|
42
|
+
cartEnabled,
|
|
43
|
+
webCartEnabled,
|
|
44
|
+
webCartOnOff: profileNode?.attrs?.web_cart_on_off ?? null,
|
|
45
|
+
commerceExperience: profileNode?.attrs?.commerce_experience ?? null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export class USyncContactProtocol {
|
|
4
|
-
constructor() { this.name = 'contact'; }
|
|
5
|
-
|
|
6
|
-
getQueryElement() { return { tag: 'contact', attrs: {} }; }
|
|
7
|
-
|
|
8
|
-
getUserElement(user) {
|
|
9
|
-
if (user.phone) return { tag: 'contact', attrs: {}, content: user.phone };
|
|
10
|
-
if (user.username) return { tag: 'contact', attrs: { username: user.username, ...(user.usernameKey ? { pin: user.usernameKey } : {}), ...(user.lid ? { lid: user.lid } : {}) } };
|
|
11
|
-
if (user.type) return { tag: 'contact', attrs: { type: user.type } };
|
|
12
|
-
return { tag: 'contact', attrs: {} };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
parser(node) {
|
|
16
|
-
if (node.tag !== 'contact') return false;
|
|
17
|
-
assertNodeErrorFree(node);
|
|
18
|
-
const inWA = node?.attrs?.type === 'in';
|
|
19
|
-
const restrictionType = node?.attrs?.stella_addressbook_restriction_type;
|
|
20
|
-
if (restrictionType !== undefined) return { inWA, stellaAddressbookRestrictionType: restrictionType };
|
|
21
|
-
return inWA;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export class USyncContactProtocol {
|
|
4
|
+
constructor() { this.name = 'contact'; }
|
|
5
|
+
|
|
6
|
+
getQueryElement() { return { tag: 'contact', attrs: {} }; }
|
|
7
|
+
|
|
8
|
+
getUserElement(user) {
|
|
9
|
+
if (user.phone) return { tag: 'contact', attrs: {}, content: user.phone };
|
|
10
|
+
if (user.username) return { tag: 'contact', attrs: { username: user.username, ...(user.usernameKey ? { pin: user.usernameKey } : {}), ...(user.lid ? { lid: user.lid } : {}) } };
|
|
11
|
+
if (user.type) return { tag: 'contact', attrs: { type: user.type } };
|
|
12
|
+
return { tag: 'contact', attrs: {} };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
parser(node) {
|
|
16
|
+
if (node.tag !== 'contact') return false;
|
|
17
|
+
assertNodeErrorFree(node);
|
|
18
|
+
const inWA = node?.attrs?.type === 'in';
|
|
19
|
+
const restrictionType = node?.attrs?.stella_addressbook_restriction_type;
|
|
20
|
+
if (restrictionType !== undefined) return { inWA, stellaAddressbookRestrictionType: restrictionType };
|
|
21
|
+
return inWA;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export class USyncDeviceProtocol {
|
|
4
|
-
constructor() { this.name = 'devices'; }
|
|
5
|
-
|
|
6
|
-
getQueryElement() { return { tag: 'devices', attrs: { version: '2' } }; }
|
|
7
|
-
|
|
8
|
-
getUserElement() { return null; }
|
|
9
|
-
|
|
10
|
-
parser(node) {
|
|
11
|
-
const deviceList = [];
|
|
12
|
-
let keyIndex;
|
|
13
|
-
if (node.tag === 'devices') {
|
|
14
|
-
assertNodeErrorFree(node);
|
|
15
|
-
const deviceListNode = getBinaryNodeChild(node, 'device-list');
|
|
16
|
-
const keyIndexNode = getBinaryNodeChild(node, 'key-index-list');
|
|
17
|
-
if (Array.isArray(deviceListNode?.content)) {
|
|
18
|
-
for (const { tag, attrs } of deviceListNode.content) {
|
|
19
|
-
if (tag === 'device') deviceList.push({ id: +attrs.id, keyIndex: +attrs['key-index'], isHosted: attrs['is_hosted'] === 'true' });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (keyIndexNode?.tag === 'key-index-list') {
|
|
23
|
-
keyIndex = { timestamp: +keyIndexNode.attrs['ts'], signedKeyIndex: keyIndexNode?.content, expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined };
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return { deviceList, keyIndex };
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export class USyncDeviceProtocol {
|
|
4
|
+
constructor() { this.name = 'devices'; }
|
|
5
|
+
|
|
6
|
+
getQueryElement() { return { tag: 'devices', attrs: { version: '2' } }; }
|
|
7
|
+
|
|
8
|
+
getUserElement() { return null; }
|
|
9
|
+
|
|
10
|
+
parser(node) {
|
|
11
|
+
const deviceList = [];
|
|
12
|
+
let keyIndex;
|
|
13
|
+
if (node.tag === 'devices') {
|
|
14
|
+
assertNodeErrorFree(node);
|
|
15
|
+
const deviceListNode = getBinaryNodeChild(node, 'device-list');
|
|
16
|
+
const keyIndexNode = getBinaryNodeChild(node, 'key-index-list');
|
|
17
|
+
if (Array.isArray(deviceListNode?.content)) {
|
|
18
|
+
for (const { tag, attrs } of deviceListNode.content) {
|
|
19
|
+
if (tag === 'device') deviceList.push({ id: +attrs.id, keyIndex: +attrs['key-index'], isHosted: attrs['is_hosted'] === 'true' });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (keyIndexNode?.tag === 'key-index-list') {
|
|
23
|
+
keyIndex = { timestamp: +keyIndexNode.attrs['ts'], signedKeyIndex: keyIndexNode?.content, expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { deviceList, keyIndex };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
-
|
|
3
|
-
export class USyncDisappearingModeProtocol {
|
|
4
|
-
constructor() { this.name = 'disappearing_mode'; }
|
|
5
|
-
|
|
6
|
-
getQueryElement() { return { tag: 'disappearing_mode', attrs: {} }; }
|
|
7
|
-
|
|
8
|
-
getUserElement() { return null; }
|
|
9
|
-
|
|
10
|
-
parser(node) {
|
|
11
|
-
if (node.tag !== 'disappearing_mode') return;
|
|
12
|
-
assertNodeErrorFree(node);
|
|
13
|
-
return { duration: +node.attrs.duration, setAt: new Date(+(node.attrs.t || 0) * 1000) };
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
+
|
|
3
|
+
export class USyncDisappearingModeProtocol {
|
|
4
|
+
constructor() { this.name = 'disappearing_mode'; }
|
|
5
|
+
|
|
6
|
+
getQueryElement() { return { tag: 'disappearing_mode', attrs: {} }; }
|
|
7
|
+
|
|
8
|
+
getUserElement() { return null; }
|
|
9
|
+
|
|
10
|
+
parser(node) {
|
|
11
|
+
if (node.tag !== 'disappearing_mode') return;
|
|
12
|
+
assertNodeErrorFree(node);
|
|
13
|
+
return { duration: +node.attrs.duration, setAt: new Date(+(node.attrs.t || 0) * 1000) };
|
|
14
|
+
}
|
|
15
|
+
}
|