@pontalabs/baileys 1.0.10 → 1.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/README.md +96 -85
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -151
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -15
- package/lib/Signal/Group/group-session-builder.js +34 -60
- package/lib/Signal/Group/group_cipher.js +69 -76
- package/lib/Signal/Group/index.js +41 -60
- package/lib/Signal/Group/keyhelper.js +12 -57
- package/lib/Signal/Group/sender-chain-key.js +20 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
- package/lib/Signal/Group/sender-key-message.js +58 -53
- package/lib/Signal/Group/sender-key-name.js +21 -31
- package/lib/Signal/Group/sender-key-record.js +21 -34
- package/lib/Signal/Group/sender-key-state.js +59 -106
- package/lib/Signal/Group/sender-message-key.js +16 -21
- package/lib/Signal/libsignal.js +282 -203
- package/lib/Signal/lid-mapping.js +164 -184
- package/lib/Socket/Client/index.js +31 -22
- package/lib/Socket/Client/types.js +9 -15
- package/lib/Socket/Client/websocket.js +42 -37
- package/lib/Socket/business.js +212 -336
- package/lib/Socket/chats.js +696 -940
- package/lib/Socket/community.js +454 -369
- package/lib/Socket/groups.js +278 -280
- package/lib/Socket/index.js +9 -21
- package/lib/Socket/messages-recv.js +1027 -1570
- package/lib/Socket/messages-send.js +1180 -1136
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +193 -251
- package/lib/Socket/socket.js +758 -898
- package/lib/Store/index.js +35 -24
- package/lib/Store/make-cache-manager-store.js +53 -66
- package/lib/Store/make-in-memory-store.js +319 -325
- package/lib/Store/make-ordered-dictionary.js +49 -57
- package/lib/Store/object-repository.js +10 -15
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.js +10 -9
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +6 -12
- package/lib/Types/LabelAssociation.js +4 -13
- package/lib/Types/Message.js +10 -18
- package/lib/Types/MexUpdates.js +15 -18
- package/lib/Types/Newsletter.js +26 -34
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +8 -13
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.js +49 -40
- package/lib/Utils/auth-utils.js +190 -495
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +177 -199
- package/lib/Utils/chat-utils.js +711 -624
- package/lib/Utils/crypto.js +116 -161
- package/lib/Utils/decode-wa-message.js +225 -321
- package/lib/Utils/event-buffer.js +363 -405
- package/lib/Utils/generics.js +318 -472
- package/lib/Utils/history.js +72 -76
- package/lib/Utils/index.js +49 -41
- package/lib/Utils/link-preview.js +59 -103
- package/lib/Utils/logger.js +4 -7
- package/lib/Utils/lt-hash.js +29 -42
- package/lib/Utils/make-mutex.js +26 -42
- package/lib/Utils/message-retry-manager.js +134 -160
- package/lib/Utils/messages-media.js +665 -731
- package/lib/Utils/messages.js +518 -1
- package/lib/Utils/noise-handler.js +127 -125
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +739 -351
- package/lib/Utils/signal.js +146 -129
- package/lib/Utils/use-multi-file-auth-state.js +68 -135
- package/lib/Utils/validate-connection.js +183 -142
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1281 -1289
- package/lib/WABinary/decode.js +145 -200
- package/lib/WABinary/encode.js +149 -202
- package/lib/WABinary/generic-utils.js +79 -97
- package/lib/WABinary/index.js +36 -25
- package/lib/WABinary/jid-utils.js +91 -123
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.js +8 -13
- package/lib/WAM/constants.js +16584 -11464
- package/lib/WAM/encode.js +117 -133
- package/lib/WAM/index.js +34 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
- package/lib/WAUSync/Protocols/index.js +37 -26
- package/lib/WAUSync/USyncQuery.js +66 -66
- package/lib/WAUSync/USyncUser.js +13 -18
- package/lib/WAUSync/index.js +34 -23
- package/lib/index.js +95 -28
- package/package.json +4 -3
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/signal-housekeeping.d.ts +0 -19
- package/lib/Utils/signal-housekeeping.js +0 -73
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
package/lib/WAM/encode.js
CHANGED
|
@@ -1,164 +1,148 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const {
|
|
4
|
+
FLAG_BYTE: FLAG_BYTE,
|
|
5
|
+
FLAG_EVENT: FLAG_EVENT,
|
|
6
|
+
FLAG_EXTENDED: FLAG_EXTENDED,
|
|
7
|
+
FLAG_FIELD: FLAG_FIELD,
|
|
8
|
+
FLAG_GLOBAL: FLAG_GLOBAL,
|
|
9
|
+
WEB_EVENTS: WEB_EVENTS,
|
|
10
|
+
WEB_GLOBALS: WEB_GLOBALS,
|
|
11
|
+
} = require("./constants");
|
|
12
|
+
const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
|
|
8
13
|
const encodeWAM = (binaryInfo) => {
|
|
9
|
-
binaryInfo.buffer = []
|
|
10
|
-
encodeWAMHeader(binaryInfo)
|
|
11
|
-
encodeEvents(binaryInfo)
|
|
12
|
-
const totalSize = binaryInfo.buffer
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const buffer = Buffer.alloc(totalSize)
|
|
16
|
-
let offset = 0
|
|
14
|
+
binaryInfo.buffer = [];
|
|
15
|
+
encodeWAMHeader(binaryInfo);
|
|
16
|
+
encodeEvents(binaryInfo);
|
|
17
|
+
const totalSize = binaryInfo.buffer.map((a) => a.length).reduce((a, b) => a + b);
|
|
18
|
+
const buffer = Buffer.alloc(totalSize);
|
|
19
|
+
let offset = 0;
|
|
17
20
|
for (const buffer_ of binaryInfo.buffer) {
|
|
18
|
-
buffer_.copy(buffer, offset)
|
|
19
|
-
offset += buffer_.length
|
|
21
|
+
buffer_.copy(buffer, offset);
|
|
22
|
+
offset += buffer_.length;
|
|
20
23
|
}
|
|
21
|
-
return buffer
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
+
return buffer;
|
|
25
|
+
};
|
|
24
26
|
function encodeWAMHeader(binaryInfo) {
|
|
25
|
-
const headerBuffer = Buffer.alloc(8)
|
|
26
|
-
headerBuffer.write(
|
|
27
|
-
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
|
|
28
|
-
headerBuffer.writeUInt8(1, 4)
|
|
29
|
-
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5)
|
|
30
|
-
headerBuffer.writeUInt8(0, 7)
|
|
31
|
-
binaryInfo.buffer.push(headerBuffer)
|
|
27
|
+
const headerBuffer = Buffer.alloc(8);
|
|
28
|
+
headerBuffer.write("WAM", 0, "utf8");
|
|
29
|
+
headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
|
|
30
|
+
headerBuffer.writeUInt8(1, 4);
|
|
31
|
+
headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
|
|
32
|
+
headerBuffer.writeUInt8(0, 7);
|
|
33
|
+
binaryInfo.buffer.push(headerBuffer);
|
|
32
34
|
}
|
|
33
|
-
|
|
34
35
|
function encodeGlobalAttributes(binaryInfo, globals) {
|
|
35
36
|
for (const [key, _value] of Object.entries(globals)) {
|
|
36
|
-
const id =
|
|
37
|
-
let value = _value
|
|
38
|
-
if (typeof value ===
|
|
39
|
-
value = value ? 1 : 0
|
|
37
|
+
const id = WEB_GLOBALS.find((a) => a?.name === key).id;
|
|
38
|
+
let value = _value;
|
|
39
|
+
if (typeof value === "boolean") {
|
|
40
|
+
value = value ? 1 : 0;
|
|
40
41
|
}
|
|
41
|
-
binaryInfo.buffer.push(serializeData(id, value,
|
|
42
|
+
binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
|
|
45
45
|
function encodeEvents(binaryInfo) {
|
|
46
|
-
for (const [name, { props, globals }
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
for (const [name, { props: props, globals: globals }] of binaryInfo.events.map(
|
|
47
|
+
(a) => Object.entries(a)[0]
|
|
48
|
+
)) {
|
|
49
|
+
encodeGlobalAttributes(binaryInfo, globals);
|
|
50
|
+
const event = WEB_EVENTS.find((a) => a.name === name);
|
|
51
|
+
const props_ = Object.entries(props);
|
|
52
|
+
let extended = false;
|
|
51
53
|
for (const [, value] of props_) {
|
|
52
|
-
extended || (extended = value !== null)
|
|
54
|
+
extended || (extended = value !== null);
|
|
53
55
|
}
|
|
54
|
-
const eventFlag = extended ?
|
|
55
|
-
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
|
|
56
|
+
const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
|
|
57
|
+
binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
|
|
56
58
|
for (let i = 0; i < props_.length; i++) {
|
|
57
|
-
const [key, _value] = props_[i]
|
|
58
|
-
const id =
|
|
59
|
-
extended = i <
|
|
60
|
-
let value = _value
|
|
61
|
-
if (typeof value ===
|
|
62
|
-
value = value ? 1 : 0
|
|
59
|
+
const [key, _value] = props_[i];
|
|
60
|
+
const id = event.props[key]?.[0];
|
|
61
|
+
extended = i < props_.length - 1;
|
|
62
|
+
let value = _value;
|
|
63
|
+
if (typeof value === "boolean") {
|
|
64
|
+
value = value ? 1 : 0;
|
|
63
65
|
}
|
|
64
|
-
const fieldFlag = extended ?
|
|
65
|
-
binaryInfo.buffer.push(serializeData(id, value, fieldFlag))
|
|
66
|
+
const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
|
|
67
|
+
binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
|
-
|
|
70
71
|
function serializeData(key, value, flag) {
|
|
71
|
-
const bufferLength = getHeaderBitLength(key)
|
|
72
|
-
let buffer
|
|
73
|
-
let offset = 0
|
|
72
|
+
const bufferLength = getHeaderBitLength(key);
|
|
73
|
+
let buffer;
|
|
74
|
+
let offset = 0;
|
|
74
75
|
if (value === null) {
|
|
75
|
-
if (flag ===
|
|
76
|
-
buffer = Buffer.alloc(bufferLength)
|
|
77
|
-
offset = serializeHeader(buffer, offset, key, flag)
|
|
78
|
-
return buffer
|
|
76
|
+
if (flag === FLAG_GLOBAL) {
|
|
77
|
+
buffer = Buffer.alloc(bufferLength);
|
|
78
|
+
offset = serializeHeader(buffer, offset, key, flag);
|
|
79
|
+
return buffer;
|
|
79
80
|
}
|
|
80
|
-
}
|
|
81
|
-
else if (typeof value === 'number' && Number.isInteger(value)) {
|
|
82
|
-
// is number
|
|
81
|
+
} else if (typeof value === "number" && Number.isInteger(value)) {
|
|
83
82
|
if (value === 0 || value === 1) {
|
|
84
|
-
buffer = Buffer.alloc(bufferLength)
|
|
85
|
-
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
|
|
86
|
-
return buffer
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
buffer
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
buffer
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
buffer
|
|
102
|
-
|
|
103
|
-
buffer.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
buffer = Buffer.alloc(bufferLength + 8)
|
|
108
|
-
offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
|
|
109
|
-
buffer.writeDoubleLE(value, offset)
|
|
110
|
-
return buffer
|
|
83
|
+
buffer = Buffer.alloc(bufferLength);
|
|
84
|
+
offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
|
|
85
|
+
return buffer;
|
|
86
|
+
} else if (-128 <= value && value < 128) {
|
|
87
|
+
buffer = Buffer.alloc(bufferLength + 1);
|
|
88
|
+
offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
|
|
89
|
+
buffer.writeInt8(value, offset);
|
|
90
|
+
return buffer;
|
|
91
|
+
} else if (-32768 <= value && value < 32768) {
|
|
92
|
+
buffer = Buffer.alloc(bufferLength + 2);
|
|
93
|
+
offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
|
|
94
|
+
buffer.writeInt16LE(value, offset);
|
|
95
|
+
return buffer;
|
|
96
|
+
} else if (-2147483648 <= value && value < 2147483648) {
|
|
97
|
+
buffer = Buffer.alloc(bufferLength + 4);
|
|
98
|
+
offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
|
|
99
|
+
buffer.writeInt32LE(value, offset);
|
|
100
|
+
return buffer;
|
|
101
|
+
} else {
|
|
102
|
+
buffer = Buffer.alloc(bufferLength + 8);
|
|
103
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
104
|
+
buffer.writeDoubleLE(value, offset);
|
|
105
|
+
return buffer;
|
|
111
106
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
buffer
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
else if (typeof value === 'string') {
|
|
121
|
-
// is string
|
|
122
|
-
const utf8Bytes = Buffer.byteLength(value, 'utf8')
|
|
107
|
+
} else if (typeof value === "number") {
|
|
108
|
+
buffer = Buffer.alloc(bufferLength + 8);
|
|
109
|
+
offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
|
|
110
|
+
buffer.writeDoubleLE(value, offset);
|
|
111
|
+
return buffer;
|
|
112
|
+
} else if (typeof value === "string") {
|
|
113
|
+
const utf8Bytes = Buffer.byteLength(value, "utf8");
|
|
123
114
|
if (utf8Bytes < 256) {
|
|
124
|
-
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
|
|
125
|
-
offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
|
|
126
|
-
buffer.writeUint8(utf8Bytes, offset++)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
115
|
+
buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
|
|
116
|
+
offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
|
|
117
|
+
buffer.writeUint8(utf8Bytes, offset++);
|
|
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
|
+
} else {
|
|
124
|
+
buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
|
|
125
|
+
offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
|
|
126
|
+
buffer.writeUInt32LE(utf8Bytes, offset);
|
|
127
|
+
offset += 4;
|
|
133
128
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
|
|
137
|
-
buffer.writeUInt32LE(utf8Bytes, offset)
|
|
138
|
-
offset += 4
|
|
139
|
-
}
|
|
140
|
-
buffer.write(value, offset, 'utf8')
|
|
141
|
-
return buffer
|
|
129
|
+
buffer.write(value, offset, "utf8");
|
|
130
|
+
return buffer;
|
|
142
131
|
}
|
|
143
|
-
throw
|
|
132
|
+
throw "missing";
|
|
144
133
|
}
|
|
145
|
-
|
|
146
134
|
function serializeHeader(buffer, offset, key, flag) {
|
|
147
135
|
if (key < 256) {
|
|
148
|
-
buffer.writeUInt8(flag, offset)
|
|
149
|
-
offset += 1
|
|
150
|
-
buffer.writeUInt8(key, offset)
|
|
151
|
-
offset += 1
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
offset
|
|
156
|
-
|
|
157
|
-
offset += 2
|
|
136
|
+
buffer.writeUInt8(flag, offset);
|
|
137
|
+
offset += 1;
|
|
138
|
+
buffer.writeUInt8(key, offset);
|
|
139
|
+
offset += 1;
|
|
140
|
+
} else {
|
|
141
|
+
buffer.writeUInt8(flag | FLAG_BYTE, offset);
|
|
142
|
+
offset += 1;
|
|
143
|
+
buffer.writeUInt16LE(key, offset);
|
|
144
|
+
offset += 2;
|
|
158
145
|
}
|
|
159
|
-
return offset
|
|
146
|
+
return offset;
|
|
160
147
|
}
|
|
161
|
-
|
|
162
|
-
module.exports = {
|
|
163
|
-
encodeWAM
|
|
164
|
-
}
|
|
148
|
+
module.exports = { encodeWAM: encodeWAM };
|
package/lib/WAM/index.js
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
__exportStar
|
|
23
|
-
__exportStar
|
|
1
|
+
"use strict";
|
|
2
|
+
const __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
let desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return m[k];
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}
|
|
18
|
+
: function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
});
|
|
22
|
+
const __exportStar =
|
|
23
|
+
(this && this.__exportStar) ||
|
|
24
|
+
function (m, exports) {
|
|
25
|
+
for (var p in m) {
|
|
26
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
|
|
27
|
+
__createBinding(exports, m, p);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
__exportStar(require("./constants"), exports);
|
|
33
|
+
__exportStar(require("./encode"), exports);
|
|
34
|
+
__exportStar(require("./BinaryInfo"), exports);
|
|
@@ -1,69 +1,62 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
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
|
-
const
|
|
28
|
-
|
|
29
|
-
const commandsNode =
|
|
30
|
-
const promptsNode =
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
module.exports = {
|
|
68
|
-
USyncBotProfileProtocol
|
|
69
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const {
|
|
4
|
+
getBinaryNodeChild: getBinaryNodeChild,
|
|
5
|
+
getBinaryNodeChildren: getBinaryNodeChildren,
|
|
6
|
+
getBinaryNodeChildString: getBinaryNodeChildString,
|
|
7
|
+
} = require("../../WABinary");
|
|
8
|
+
class USyncBotProfileProtocol {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.name = "bot";
|
|
11
|
+
}
|
|
12
|
+
getQueryElement() {
|
|
13
|
+
return {
|
|
14
|
+
tag: "bot",
|
|
15
|
+
attrs: {},
|
|
16
|
+
content: [{ tag: "profile", attrs: { v: "1" } }],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
getUserElement(user) {
|
|
20
|
+
return {
|
|
21
|
+
tag: "bot",
|
|
22
|
+
attrs: {},
|
|
23
|
+
content: [{ tag: "profile", attrs: { persona_id: user.personaId } }],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
parser(node) {
|
|
27
|
+
const botNode = getBinaryNodeChild(node, "bot");
|
|
28
|
+
const profile = getBinaryNodeChild(botNode, "profile");
|
|
29
|
+
const commandsNode = getBinaryNodeChild(profile, "commands");
|
|
30
|
+
const promptsNode = getBinaryNodeChild(profile, "prompts");
|
|
31
|
+
const commands = [];
|
|
32
|
+
const prompts = [];
|
|
33
|
+
if (commandsNode) {
|
|
34
|
+
for (const command of getBinaryNodeChildren(commandsNode, "command")) {
|
|
35
|
+
commands.push({
|
|
36
|
+
name: getBinaryNodeChildString(command, "name") || "",
|
|
37
|
+
description: getBinaryNodeChildString(command, "description") || "",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (promptsNode) {
|
|
42
|
+
for (const prompt of getBinaryNodeChildren(promptsNode, "prompt")) {
|
|
43
|
+
prompts.push(
|
|
44
|
+
`${getBinaryNodeChildString(prompt, "emoji") || ""} ${getBinaryNodeChildString(prompt, "text") || ""}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
isDefault: !!getBinaryNodeChild(profile, "default"),
|
|
50
|
+
jid: node.attrs.jid,
|
|
51
|
+
name: getBinaryNodeChildString(profile, "name") || "",
|
|
52
|
+
attributes: getBinaryNodeChildString(profile, "attributes") || "",
|
|
53
|
+
description: getBinaryNodeChildString(profile, "description") || "",
|
|
54
|
+
category: getBinaryNodeChildString(profile, "category") || "",
|
|
55
|
+
personaId: profile.attrs["persona_id"] || "",
|
|
56
|
+
commandsDescription: getBinaryNodeChildString(commandsNode, "description") || "",
|
|
57
|
+
commands: commands,
|
|
58
|
+
prompts: prompts,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
module.exports = { USyncBotProfileProtocol: USyncBotProfileProtocol };
|
|
@@ -1,36 +1,22 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const WABinary_1 = require("../../WABinary")
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { assertNodeErrorFree: assertNodeErrorFree } = require("../../WABinary");
|
|
7
4
|
class USyncContactProtocol {
|
|
8
5
|
constructor() {
|
|
9
|
-
this.name =
|
|
6
|
+
this.name = "contact";
|
|
10
7
|
}
|
|
11
8
|
getQueryElement() {
|
|
12
|
-
return {
|
|
13
|
-
tag: 'contact',
|
|
14
|
-
attrs: {},
|
|
15
|
-
}
|
|
9
|
+
return { tag: "contact", attrs: {} };
|
|
16
10
|
}
|
|
17
11
|
getUserElement(user) {
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
tag: 'contact',
|
|
21
|
-
attrs: {},
|
|
22
|
-
content: user.phone,
|
|
23
|
-
}
|
|
12
|
+
return { tag: "contact", attrs: {}, content: user.phone };
|
|
24
13
|
}
|
|
25
14
|
parser(node) {
|
|
26
|
-
if (node.tag ===
|
|
27
|
-
|
|
28
|
-
return node?.attrs?.type ===
|
|
15
|
+
if (node.tag === "contact") {
|
|
16
|
+
assertNodeErrorFree(node);
|
|
17
|
+
return node?.attrs?.type === "in";
|
|
29
18
|
}
|
|
30
|
-
return false
|
|
19
|
+
return false;
|
|
31
20
|
}
|
|
32
21
|
}
|
|
33
|
-
|
|
34
|
-
module.exports = {
|
|
35
|
-
USyncContactProtocol
|
|
36
|
-
}
|
|
22
|
+
module.exports = { USyncContactProtocol: USyncContactProtocol };
|
|
@@ -1,62 +1,50 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const {
|
|
4
|
+
getBinaryNodeChild: getBinaryNodeChild,
|
|
5
|
+
assertNodeErrorFree: assertNodeErrorFree,
|
|
6
|
+
} = require("../../WABinary");
|
|
7
7
|
class USyncDeviceProtocol {
|
|
8
8
|
constructor() {
|
|
9
|
-
this.name =
|
|
9
|
+
this.name = "devices";
|
|
10
10
|
}
|
|
11
11
|
getQueryElement() {
|
|
12
|
-
return {
|
|
13
|
-
tag: 'devices',
|
|
14
|
-
attrs: {
|
|
15
|
-
version: '2',
|
|
16
|
-
},
|
|
17
|
-
}
|
|
12
|
+
return { tag: "devices", attrs: { version: "2" } };
|
|
18
13
|
}
|
|
19
|
-
getUserElement(
|
|
20
|
-
|
|
21
|
-
//TODO: if all are not present, return null <- current behavior
|
|
22
|
-
//TODO: otherwise return a node w tag 'devices' w those as attrs
|
|
23
|
-
return null
|
|
14
|
+
getUserElement() {
|
|
15
|
+
return null;
|
|
24
16
|
}
|
|
25
17
|
parser(node) {
|
|
26
|
-
const deviceList = []
|
|
27
|
-
let keyIndex = undefined
|
|
28
|
-
if (node.tag ===
|
|
29
|
-
|
|
30
|
-
const deviceListNode =
|
|
31
|
-
const keyIndexNode =
|
|
18
|
+
const deviceList = [];
|
|
19
|
+
let keyIndex = undefined;
|
|
20
|
+
if (node.tag === "devices") {
|
|
21
|
+
assertNodeErrorFree(node);
|
|
22
|
+
const deviceListNode = getBinaryNodeChild(node, "device-list");
|
|
23
|
+
const keyIndexNode = getBinaryNodeChild(node, "key-index-list");
|
|
32
24
|
if (Array.isArray(deviceListNode?.content)) {
|
|
33
|
-
for (const { tag, attrs } of deviceListNode.content) {
|
|
34
|
-
const id = +attrs.id
|
|
35
|
-
const keyIndex = +attrs[
|
|
36
|
-
if (tag ===
|
|
25
|
+
for (const { tag: tag, attrs: attrs } of deviceListNode.content) {
|
|
26
|
+
const id = +attrs.id;
|
|
27
|
+
const keyIndex = +attrs["key-index"];
|
|
28
|
+
if (tag === "device") {
|
|
37
29
|
deviceList.push({
|
|
38
|
-
id,
|
|
39
|
-
keyIndex,
|
|
40
|
-
isHosted: !!(attrs[
|
|
41
|
-
})
|
|
30
|
+
id: id,
|
|
31
|
+
keyIndex: keyIndex,
|
|
32
|
+
isHosted: !!(attrs["is_hosted"] && attrs["is_hosted"] === "true"),
|
|
33
|
+
});
|
|
42
34
|
}
|
|
43
35
|
}
|
|
44
36
|
}
|
|
45
|
-
if (keyIndexNode?.tag ===
|
|
37
|
+
if (keyIndexNode?.tag === "key-index-list") {
|
|
46
38
|
keyIndex = {
|
|
47
|
-
timestamp: +keyIndexNode.attrs[
|
|
39
|
+
timestamp: +keyIndexNode.attrs["ts"],
|
|
48
40
|
signedKeyIndex: keyIndexNode?.content,
|
|
49
|
-
expectedTimestamp: keyIndexNode.attrs[
|
|
50
|
-
|
|
41
|
+
expectedTimestamp: keyIndexNode.attrs["expected_ts"]
|
|
42
|
+
? +keyIndexNode.attrs["expected_ts"]
|
|
43
|
+
: undefined,
|
|
44
|
+
};
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
|
-
return {
|
|
54
|
-
deviceList,
|
|
55
|
-
keyIndex
|
|
56
|
-
}
|
|
47
|
+
return { deviceList: deviceList, keyIndex: keyIndex };
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
|
-
|
|
60
|
-
module.exports = {
|
|
61
|
-
USyncDeviceProtocol
|
|
62
|
-
}
|
|
50
|
+
module.exports = { USyncDeviceProtocol: USyncDeviceProtocol };
|