@mrlegendbot/baileys 1.2.5 → 1.2.6
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/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +97691 -2
- package/lib/Defaults/index.d.ts +75 -0
- package/lib/Defaults/index.js +92 -89
- package/lib/Menu/index.d.ts +42 -0
- package/lib/Menu/index.js +283 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -9
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +22 -21
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +69 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +10 -9
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +22 -21
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +60 -51
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +62 -56
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.js +40 -38
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +34 -33
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +76 -72
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -22
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +405 -506
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.js +258 -276
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +7 -6
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +49 -48
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.js +369 -349
- package/lib/Socket/chats.d.ts +125 -0
- package/lib/Socket/chats.js +1148 -1172
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.js +413 -473
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.js +331 -387
- package/lib/Socket/index.d.ts +267 -0
- package/lib/Socket/index.js +19 -6
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.js +1719 -1782
- package/lib/Socket/messages-send.d.ts +199 -0
- package/lib/Socket/messages-send.js +2451 -1555
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +35 -40
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.js +191 -239
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.js +923 -992
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +8 -1
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.js +2 -1
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +22 -20
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +4 -2
- package/lib/Types/Message.d.ts +320 -0
- package/lib/Types/Message.js +5 -3
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.js +31 -26
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.js +2 -1
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.d.ts +97 -0
- package/lib/Types/State.js +52 -4
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +11 -10
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.js +277 -240
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +23 -20
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +204 -200
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.js +810 -836
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.js +25 -23
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +86 -70
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.js +284 -277
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.js +595 -592
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +335 -312
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.js +115 -123
- 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 -0
- package/lib/Utils/index.js +2 -1
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +73 -74
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +2 -3
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +6 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +27 -27
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.js +254 -213
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.js +715 -741
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.js +827 -791
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +187 -215
- 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 +98 -69
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +586 -617
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +234 -553
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.js +170 -217
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.js +35 -27
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +41 -37
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.js +141 -120
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +105 -87
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +188 -190
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.js +1294 -28
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +249 -245
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +206 -201
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +89 -86
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +77 -68
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.js +8 -7
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +22853 -19892
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +132 -121
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +43 -46
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -30
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +20 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +44 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +30 -0
- package/lib/WAUSync/USyncQuery.js +88 -79
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +29 -28
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +2 -2
- package/package.json +86 -22
- package/README.upstream.md +0 -1312
- package/WAProto/WAProto.json +0 -1
- package/WAProto/WAProto.proto +0 -6275
- package/WAProto/compiler.js +0 -550
- package/lib/Store/index.js +0 -8
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Store/make-cache-manager-store.js +0 -70
- package/lib/Store/make-in-memory-store.js +0 -417
- package/lib/Store/make-ordered-dictionary.js +0 -69
- package/lib/Store/object-repository.js +0 -27
- package/lib/Utils/use-sqlite-auth-state.js +0 -162
package/lib/WAM/encode.js
CHANGED
|
@@ -1,139 +1,150 @@
|
|
|
1
1
|
import { BinaryInfo } from './BinaryInfo.js';
|
|
2
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
16
|
};
|
|
17
17
|
function encodeWAMHeader(binaryInfo) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
25
|
}
|
|
26
26
|
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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));
|
|
32
34
|
}
|
|
33
|
-
binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
|
|
34
|
-
}
|
|
35
35
|
}
|
|
36
36
|
function encodeEvents(binaryInfo) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
}
|
|
47
58
|
}
|
|
48
|
-
const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
|
|
49
|
-
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
|
|
50
|
-
for (let i = 0; i < props_.length; i++) {
|
|
51
|
-
const [key, _value] = props_[i];
|
|
52
|
-
const id = event.props[key]?.[0];
|
|
53
|
-
extended = i < props_.length - 1;
|
|
54
|
-
let value = _value;
|
|
55
|
-
if (typeof value === 'boolean') {
|
|
56
|
-
value = value ? 1 : 0;
|
|
57
|
-
}
|
|
58
|
-
const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
|
|
59
|
-
binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
59
|
}
|
|
63
60
|
function serializeData(key, value, flag) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
}
|
|
72
70
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
+
}
|
|
98
102
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const utf8Bytes = Buffer.byteLength(value, 'utf8');
|
|
106
|
-
if (utf8Bytes < 256) {
|
|
107
|
-
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
|
|
108
|
-
offset = serializeHeader(buffer, offset, key, flag | 8 << 4);
|
|
109
|
-
buffer.writeUint8(utf8Bytes, offset++);
|
|
110
|
-
} else if (utf8Bytes < 65536) {
|
|
111
|
-
buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
|
|
112
|
-
offset = serializeHeader(buffer, offset, key, flag | 9 << 4);
|
|
113
|
-
buffer.writeUInt16LE(utf8Bytes, offset);
|
|
114
|
-
offset += 2;
|
|
115
|
-
} else {
|
|
116
|
-
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
|
|
117
|
-
offset = serializeHeader(buffer, offset, key, flag | 10 << 4);
|
|
118
|
-
buffer.writeUInt32LE(utf8Bytes, offset);
|
|
119
|
-
offset += 4;
|
|
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;
|
|
120
109
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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';
|
|
125
134
|
}
|
|
126
135
|
function serializeHeader(buffer, offset, key, flag) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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;
|
|
139
149
|
}
|
|
150
|
+
//# sourceMappingURL=encode.js.map
|
package/lib/WAM/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { USyncQueryProtocol } from '../../Types/USync.js';
|
|
2
|
+
import { type BinaryNode } from '../../WABinary/index.js';
|
|
3
|
+
import { USyncUser } from '../USyncUser.js';
|
|
4
|
+
export declare class USyncContactProtocol implements USyncQueryProtocol {
|
|
5
|
+
name: string;
|
|
6
|
+
getQueryElement(): BinaryNode;
|
|
7
|
+
getUserElement(user: USyncUser): BinaryNode;
|
|
8
|
+
parser(node: BinaryNode): boolean;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=USyncContactProtocol.d.ts.map
|
|
@@ -1,55 +1,52 @@
|
|
|
1
1
|
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
2
|
import { USyncUser } from '../USyncUser.js';
|
|
3
3
|
export class USyncContactProtocol {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
getQueryElement() {
|
|
8
|
-
return {
|
|
9
|
-
tag: 'contact',
|
|
10
|
-
attrs: {}
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
getUserElement(user) {
|
|
14
|
-
if (user.phone) {
|
|
15
|
-
return {
|
|
16
|
-
tag: 'contact',
|
|
17
|
-
attrs: {},
|
|
18
|
-
content: user.phone
|
|
19
|
-
};
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = 'contact';
|
|
20
6
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
...(user.usernameKey ? {
|
|
27
|
-
pin: user.usernameKey
|
|
28
|
-
} : {}),
|
|
29
|
-
...(user.lid ? {
|
|
30
|
-
lid: user.lid
|
|
31
|
-
} : {})
|
|
32
|
-
}
|
|
33
|
-
};
|
|
7
|
+
getQueryElement() {
|
|
8
|
+
return {
|
|
9
|
+
tag: 'contact',
|
|
10
|
+
attrs: {}
|
|
11
|
+
};
|
|
34
12
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
13
|
+
getUserElement(user) {
|
|
14
|
+
if (user.phone) {
|
|
15
|
+
return {
|
|
16
|
+
tag: 'contact',
|
|
17
|
+
attrs: {},
|
|
18
|
+
content: user.phone
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (user.username) {
|
|
22
|
+
return {
|
|
23
|
+
tag: 'contact',
|
|
24
|
+
attrs: {
|
|
25
|
+
username: user.username,
|
|
26
|
+
...(user.usernameKey ? { pin: user.usernameKey } : {}),
|
|
27
|
+
...(user.lid ? { lid: user.lid } : {})
|
|
28
|
+
}
|
|
29
|
+
};
|
|
40
30
|
}
|
|
41
|
-
|
|
31
|
+
if (user.type) {
|
|
32
|
+
return {
|
|
33
|
+
tag: 'contact',
|
|
34
|
+
attrs: {
|
|
35
|
+
type: user.type
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
tag: 'contact',
|
|
41
|
+
attrs: {}
|
|
42
|
+
};
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (node.tag === 'contact') {
|
|
50
|
-
assertNodeErrorFree(node);
|
|
51
|
-
return node?.attrs?.type === 'in';
|
|
44
|
+
parser(node) {
|
|
45
|
+
if (node.tag === 'contact') {
|
|
46
|
+
assertNodeErrorFree(node);
|
|
47
|
+
return node?.attrs?.type === 'in';
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
52
50
|
}
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
51
|
}
|
|
52
|
+
//# sourceMappingURL=USyncContactProtocol.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { USyncQueryProtocol } from '../../Types/USync.js';
|
|
2
|
+
import { type BinaryNode } from '../../WABinary/index.js';
|
|
3
|
+
export type KeyIndexData = {
|
|
4
|
+
timestamp: number;
|
|
5
|
+
signedKeyIndex?: Uint8Array;
|
|
6
|
+
expectedTimestamp?: number;
|
|
7
|
+
};
|
|
8
|
+
export type DeviceListData = {
|
|
9
|
+
id: number;
|
|
10
|
+
keyIndex?: number;
|
|
11
|
+
isHosted?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type ParsedDeviceInfo = {
|
|
14
|
+
deviceList?: DeviceListData[];
|
|
15
|
+
keyIndex?: KeyIndexData;
|
|
16
|
+
};
|
|
17
|
+
export declare class USyncDeviceProtocol implements USyncQueryProtocol {
|
|
18
|
+
name: string;
|
|
19
|
+
getQueryElement(): BinaryNode;
|
|
20
|
+
getUserElement(): BinaryNode | null;
|
|
21
|
+
parser(node: BinaryNode): ParsedDeviceInfo;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=USyncDeviceProtocol.d.ts.map
|
|
@@ -1,53 +1,54 @@
|
|
|
1
1
|
import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
|
|
2
2
|
export class USyncDeviceProtocol {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
3
|
+
constructor() {
|
|
4
|
+
this.name = 'devices';
|
|
5
|
+
}
|
|
6
|
+
getQueryElement() {
|
|
7
|
+
return {
|
|
8
|
+
tag: 'devices',
|
|
9
|
+
attrs: {
|
|
10
|
+
version: '2'
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
getUserElement( /* user: USyncUser */) {
|
|
15
|
+
//TODO: Implement device phashing, ts and expectedTs
|
|
16
|
+
//TODO: if all are not present, return null <- current behavior
|
|
17
|
+
//TODO: otherwise return a node w tag 'devices' w those as attrs
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
parser(node) {
|
|
21
|
+
const deviceList = [];
|
|
22
|
+
let keyIndex = undefined;
|
|
23
|
+
if (node.tag === 'devices') {
|
|
24
|
+
assertNodeErrorFree(node);
|
|
25
|
+
const deviceListNode = getBinaryNodeChild(node, 'device-list');
|
|
26
|
+
const keyIndexNode = getBinaryNodeChild(node, 'key-index-list');
|
|
27
|
+
if (Array.isArray(deviceListNode?.content)) {
|
|
28
|
+
for (const { tag, attrs } of deviceListNode.content) {
|
|
29
|
+
const id = +attrs.id;
|
|
30
|
+
const keyIndex = +attrs['key-index'];
|
|
31
|
+
if (tag === 'device') {
|
|
32
|
+
deviceList.push({
|
|
33
|
+
id,
|
|
34
|
+
keyIndex,
|
|
35
|
+
isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (keyIndexNode?.tag === 'key-index-list') {
|
|
41
|
+
keyIndex = {
|
|
42
|
+
timestamp: +keyIndexNode.attrs['ts'],
|
|
43
|
+
signedKeyIndex: keyIndexNode?.content,
|
|
44
|
+
expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
|
|
45
|
+
};
|
|
46
|
+
}
|
|
38
47
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
timestamp: +keyIndexNode.attrs['ts'],
|
|
43
|
-
signedKeyIndex: keyIndexNode?.content,
|
|
44
|
-
expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
|
|
48
|
+
return {
|
|
49
|
+
deviceList,
|
|
50
|
+
keyIndex
|
|
45
51
|
};
|
|
46
|
-
}
|
|
47
52
|
}
|
|
48
|
-
return {
|
|
49
|
-
deviceList,
|
|
50
|
-
keyIndex
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
53
|
}
|
|
54
|
+
//# sourceMappingURL=USyncDeviceProtocol.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { USyncQueryProtocol } from '../../Types/USync.js';
|
|
2
|
+
import { type BinaryNode } from '../../WABinary/index.js';
|
|
3
|
+
export type DisappearingModeData = {
|
|
4
|
+
duration: number;
|
|
5
|
+
setAt?: Date;
|
|
6
|
+
};
|
|
7
|
+
export declare class USyncDisappearingModeProtocol implements USyncQueryProtocol {
|
|
8
|
+
name: string;
|
|
9
|
+
getQueryElement(): BinaryNode;
|
|
10
|
+
getUserElement(): null;
|
|
11
|
+
parser(node: BinaryNode): DisappearingModeData | undefined;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=USyncDisappearingModeProtocol.d.ts.map
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
2
|
export class USyncDisappearingModeProtocol {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
3
|
+
constructor() {
|
|
4
|
+
this.name = 'disappearing_mode';
|
|
5
|
+
}
|
|
6
|
+
getQueryElement() {
|
|
7
|
+
return {
|
|
8
|
+
tag: 'disappearing_mode',
|
|
9
|
+
attrs: {}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
getUserElement() {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
parser(node) {
|
|
16
|
+
if (node.tag === 'disappearing_mode') {
|
|
17
|
+
assertNodeErrorFree(node);
|
|
18
|
+
const duration = +node?.attrs.duration;
|
|
19
|
+
const setAt = new Date(+(node?.attrs.t || 0) * 1000);
|
|
20
|
+
return {
|
|
21
|
+
duration,
|
|
22
|
+
setAt
|
|
23
|
+
};
|
|
24
|
+
}
|
|
24
25
|
}
|
|
25
|
-
}
|
|
26
26
|
}
|
|
27
|
+
//# sourceMappingURL=USyncDisappearingModeProtocol.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { USyncQueryProtocol } from '../../Types/USync.js';
|
|
2
|
+
import { type BinaryNode } from '../../WABinary/index.js';
|
|
3
|
+
export type StatusData = {
|
|
4
|
+
status?: string | null;
|
|
5
|
+
setAt?: Date;
|
|
6
|
+
};
|
|
7
|
+
export declare class USyncStatusProtocol implements USyncQueryProtocol {
|
|
8
|
+
name: string;
|
|
9
|
+
getQueryElement(): BinaryNode;
|
|
10
|
+
getUserElement(): null;
|
|
11
|
+
parser(node: BinaryNode): StatusData | undefined;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=USyncStatusProtocol.d.ts.map
|