@nexustechpro/baileys 2.0.1 → 2.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/LICENSE +1 -1
- package/README.md +924 -1299
- package/lib/Defaults/baileys-version.json +6 -2
- package/lib/Defaults/index.js +172 -172
- package/lib/Signal/libsignal.js +380 -292
- package/lib/Signal/lid-mapping.js +264 -171
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.js +10 -10
- package/lib/Socket/Client/websocket.js +45 -310
- package/lib/Socket/business.js +375 -375
- package/lib/Socket/chats.js +909 -963
- package/lib/Socket/communities.js +430 -430
- package/lib/Socket/groups.js +342 -342
- package/lib/Socket/index.js +22 -22
- package/lib/Socket/messages-recv.js +777 -743
- package/lib/Socket/messages-send.js +667 -393
- package/lib/Socket/mex.js +50 -50
- package/lib/Socket/newsletter.js +148 -148
- package/lib/Socket/nexus-handler.js +75 -261
- package/lib/Socket/socket.js +709 -1201
- package/lib/Store/index.js +5 -5
- package/lib/Store/make-cache-manager-store.js +81 -81
- package/lib/Store/make-in-memory-store.js +416 -416
- package/lib/Store/make-ordered-dictionary.js +81 -81
- package/lib/Store/object-repository.js +30 -30
- 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 +10 -10
- package/lib/Types/Newsletter.js +28 -28
- package/lib/Types/Product.js +1 -1
- package/lib/Types/Signal.js +1 -1
- package/lib/Types/Socket.js +2 -2
- package/lib/Types/State.js +12 -12
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.js +25 -25
- package/lib/Utils/auth-utils.js +264 -256
- package/lib/Utils/baileys-event-stream.js +55 -55
- package/lib/Utils/browser-utils.js +27 -27
- package/lib/Utils/business.js +228 -230
- package/lib/Utils/chat-utils.js +694 -764
- package/lib/Utils/crypto.js +109 -135
- package/lib/Utils/decode-wa-message.js +310 -314
- package/lib/Utils/event-buffer.js +547 -547
- package/lib/Utils/generics.js +297 -297
- package/lib/Utils/history.js +91 -83
- package/lib/Utils/index.js +21 -20
- package/lib/Utils/key-store.js +17 -0
- package/lib/Utils/link-preview.js +97 -88
- package/lib/Utils/logger.js +2 -2
- package/lib/Utils/lt-hash.js +47 -47
- package/lib/Utils/make-mutex.js +39 -39
- package/lib/Utils/message-retry-manager.js +148 -148
- package/lib/Utils/messages-media.js +534 -532
- package/lib/Utils/messages.js +705 -705
- package/lib/Utils/noise-handler.js +255 -255
- package/lib/Utils/pre-key-manager.js +105 -105
- package/lib/Utils/process-message.js +412 -412
- package/lib/Utils/signal.js +160 -158
- package/lib/Utils/use-multi-file-auth-state.js +120 -120
- package/lib/Utils/validate-connection.js +194 -194
- package/lib/WABinary/constants.js +1300 -1300
- package/lib/WABinary/decode.js +237 -237
- package/lib/WABinary/encode.js +232 -232
- package/lib/WABinary/generic-utils.js +252 -211
- package/lib/WABinary/index.js +5 -5
- package/lib/WABinary/jid-utils.js +279 -95
- package/lib/WABinary/types.js +1 -1
- 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/USyncContactProtocol.js +28 -28
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -53
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -37
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -50
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -28
- package/lib/WAUSync/Protocols/index.js +4 -4
- package/lib/WAUSync/USyncQuery.js +93 -93
- package/lib/WAUSync/USyncUser.js +22 -22
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.js +66 -66
- package/package.json +171 -144
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group_cipher.js +0 -100
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/keyhelper.js +0 -18
- package/lib/Signal/Group/sender-chain-key.js +0 -26
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-message.js +0 -66
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-record.js +0 -41
- package/lib/Signal/Group/sender-key-state.js +0 -84
- package/lib/Signal/Group/sender-message-key.js +0 -26
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,4 +1,4 @@
|
|
|
1
|
-
export * from './constants.js';
|
|
2
|
-
export * from './encode.js';
|
|
3
|
-
export * from './BinaryInfo.js';
|
|
1
|
+
export * from './constants.js';
|
|
2
|
+
export * from './encode.js';
|
|
3
|
+
export * from './BinaryInfo.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
-
import { USyncUser } from '../USyncUser.js';
|
|
3
|
-
export class USyncContactProtocol {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.name = 'contact';
|
|
6
|
-
}
|
|
7
|
-
getQueryElement() {
|
|
8
|
-
return {
|
|
9
|
-
tag: 'contact',
|
|
10
|
-
attrs: {}
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
getUserElement(user) {
|
|
14
|
-
//TODO: Implement type / username fields (not yet supported)
|
|
15
|
-
return {
|
|
16
|
-
tag: 'contact',
|
|
17
|
-
attrs: {},
|
|
18
|
-
content: user.phone
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
parser(node) {
|
|
22
|
-
if (node.tag === 'contact') {
|
|
23
|
-
assertNodeErrorFree(node);
|
|
24
|
-
return node?.attrs?.type === 'in';
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
+
import { USyncUser } from '../USyncUser.js';
|
|
3
|
+
export class USyncContactProtocol {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = 'contact';
|
|
6
|
+
}
|
|
7
|
+
getQueryElement() {
|
|
8
|
+
return {
|
|
9
|
+
tag: 'contact',
|
|
10
|
+
attrs: {}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
getUserElement(user) {
|
|
14
|
+
//TODO: Implement type / username fields (not yet supported)
|
|
15
|
+
return {
|
|
16
|
+
tag: 'contact',
|
|
17
|
+
attrs: {},
|
|
18
|
+
content: user.phone
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
parser(node) {
|
|
22
|
+
if (node.tag === 'contact') {
|
|
23
|
+
assertNodeErrorFree(node);
|
|
24
|
+
return node?.attrs?.type === 'in';
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
29
|
//# sourceMappingURL=USyncContactProtocol.js.map
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
|
|
2
|
-
export class USyncDeviceProtocol {
|
|
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
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
deviceList,
|
|
50
|
-
keyIndex
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
|
|
2
|
+
export class USyncDeviceProtocol {
|
|
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
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
deviceList,
|
|
50
|
+
keyIndex
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
54
|
//# sourceMappingURL=USyncDeviceProtocol.js.map
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
-
export class USyncDisappearingModeProtocol {
|
|
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
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
+
export class USyncDisappearingModeProtocol {
|
|
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
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
27
|
//# sourceMappingURL=USyncDisappearingModeProtocol.js.map
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
-
export class USyncStatusProtocol {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.name = 'status';
|
|
5
|
-
}
|
|
6
|
-
getQueryElement() {
|
|
7
|
-
return {
|
|
8
|
-
tag: 'status',
|
|
9
|
-
attrs: {}
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
getUserElement() {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
parser(node) {
|
|
16
|
-
if (node.tag === 'status') {
|
|
17
|
-
assertNodeErrorFree(node);
|
|
18
|
-
let status = node?.content?.toString() ?? null;
|
|
19
|
-
const setAt = new Date(+(node?.attrs.t || 0) * 1000);
|
|
20
|
-
if (!status) {
|
|
21
|
-
if (node.attrs?.code && +node.attrs.code === 401) {
|
|
22
|
-
status = '';
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
status = null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else if (typeof status === 'string' && status.length === 0) {
|
|
29
|
-
status = null;
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
status,
|
|
33
|
-
setAt
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
1
|
+
import { assertNodeErrorFree } from '../../WABinary/index.js';
|
|
2
|
+
export class USyncStatusProtocol {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.name = 'status';
|
|
5
|
+
}
|
|
6
|
+
getQueryElement() {
|
|
7
|
+
return {
|
|
8
|
+
tag: 'status',
|
|
9
|
+
attrs: {}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
getUserElement() {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
parser(node) {
|
|
16
|
+
if (node.tag === 'status') {
|
|
17
|
+
assertNodeErrorFree(node);
|
|
18
|
+
let status = node?.content?.toString() ?? null;
|
|
19
|
+
const setAt = new Date(+(node?.attrs.t || 0) * 1000);
|
|
20
|
+
if (!status) {
|
|
21
|
+
if (node.attrs?.code && +node.attrs.code === 401) {
|
|
22
|
+
status = '';
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
status = null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if (typeof status === 'string' && status.length === 0) {
|
|
29
|
+
status = null;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
status,
|
|
33
|
+
setAt
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
38
|
//# sourceMappingURL=USyncStatusProtocol.js.map
|