@d0v3riz/baileys 6.7.8 → 6.7.12
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 +1022 -635
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +1 -0
- package/lib/Socket/business.d.ts +6 -7
- package/lib/Socket/chats.d.ts +6 -6
- package/lib/Socket/chats.js +34 -68
- package/lib/Socket/groups.d.ts +5 -6
- package/lib/Socket/index.d.ts +6 -7
- package/lib/Socket/messages-recv.d.ts +6 -7
- package/lib/Socket/messages-recv.js +72 -23
- package/lib/Socket/messages-send.d.ts +6 -6
- package/lib/Socket/messages-send.js +32 -51
- package/lib/Socket/socket.js +8 -0
- package/lib/Socket/usync.d.ts +38 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Utils/decode-wa-message.d.ts +16 -0
- package/lib/Utils/decode-wa-message.js +17 -1
- package/lib/Utils/messages.js +8 -6
- package/lib/Utils/process-message.js +16 -0
- package/lib/Utils/signal.d.ts +2 -1
- package/lib/Utils/signal.js +11 -21
- package/lib/Utils/validate-connection.js +6 -2
- package/lib/WABinary/encode.js +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +1 -1
- package/WASignalGroup/readme.md +0 -6
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { Boom } from '@hapi/boom';
|
|
4
|
+
import { SocketConfig } from '../Types';
|
|
5
|
+
import { BinaryNode } from '../WABinary';
|
|
6
|
+
import { USyncQuery } from '../WAUSync';
|
|
7
|
+
export declare const makeUSyncSocket: (config: SocketConfig) => {
|
|
8
|
+
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
|
9
|
+
type: "md";
|
|
10
|
+
ws: import("./Client").WebSocketClient;
|
|
11
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
12
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
13
|
+
buffer(): void;
|
|
14
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
15
|
+
flush(force?: boolean | undefined): boolean;
|
|
16
|
+
isBuffering(): boolean;
|
|
17
|
+
};
|
|
18
|
+
authState: {
|
|
19
|
+
creds: import("../Types").AuthenticationCreds;
|
|
20
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
21
|
+
};
|
|
22
|
+
signalRepository: import("../Types").SignalRepository;
|
|
23
|
+
user: import("../Types").Contact | undefined;
|
|
24
|
+
generateMessageTag: () => string;
|
|
25
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
|
|
26
|
+
waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<T_1>;
|
|
27
|
+
waitForSocketOpen: () => Promise<void>;
|
|
28
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
29
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
30
|
+
logout: (msg?: string | undefined) => Promise<void>;
|
|
31
|
+
end: (error: Error | undefined) => void;
|
|
32
|
+
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
|
33
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
34
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
35
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
36
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
37
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
38
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeUSyncSocket = void 0;
|
|
4
|
+
const boom_1 = require("@hapi/boom");
|
|
5
|
+
const WABinary_1 = require("../WABinary");
|
|
6
|
+
const socket_1 = require("./socket");
|
|
7
|
+
const makeUSyncSocket = (config) => {
|
|
8
|
+
const sock = (0, socket_1.makeSocket)(config);
|
|
9
|
+
const { generateMessageTag, query, } = sock;
|
|
10
|
+
const executeUSyncQuery = async (usyncQuery) => {
|
|
11
|
+
if (usyncQuery.protocols.length === 0) {
|
|
12
|
+
throw new boom_1.Boom('USyncQuery must have at least one protocol');
|
|
13
|
+
}
|
|
14
|
+
// todo: validate users, throw WARNING on no valid users
|
|
15
|
+
// variable below has only validated users
|
|
16
|
+
const validUsers = usyncQuery.users;
|
|
17
|
+
const userNodes = validUsers.map((user) => {
|
|
18
|
+
return {
|
|
19
|
+
tag: 'user',
|
|
20
|
+
attrs: {
|
|
21
|
+
jid: !user.phone ? user.id : undefined,
|
|
22
|
+
},
|
|
23
|
+
content: usyncQuery.protocols
|
|
24
|
+
.map((a) => a.getUserElement(user))
|
|
25
|
+
.filter(a => a !== null)
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
const listNode = {
|
|
29
|
+
tag: 'list',
|
|
30
|
+
attrs: {},
|
|
31
|
+
content: userNodes
|
|
32
|
+
};
|
|
33
|
+
const queryNode = {
|
|
34
|
+
tag: 'query',
|
|
35
|
+
attrs: {},
|
|
36
|
+
content: usyncQuery.protocols.map((a) => a.getQueryElement())
|
|
37
|
+
};
|
|
38
|
+
const iq = {
|
|
39
|
+
tag: 'iq',
|
|
40
|
+
attrs: {
|
|
41
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
42
|
+
type: 'get',
|
|
43
|
+
xmlns: 'usync',
|
|
44
|
+
},
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
tag: 'usync',
|
|
48
|
+
attrs: {
|
|
49
|
+
context: usyncQuery.context,
|
|
50
|
+
mode: usyncQuery.mode,
|
|
51
|
+
sid: generateMessageTag(),
|
|
52
|
+
last: 'true',
|
|
53
|
+
index: '0',
|
|
54
|
+
},
|
|
55
|
+
content: [
|
|
56
|
+
queryNode,
|
|
57
|
+
listNode
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
const result = await query(iq);
|
|
63
|
+
return usyncQuery.parseUSyncQueryResult(result);
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
...sock,
|
|
67
|
+
executeUSyncQuery,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
exports.makeUSyncSocket = makeUSyncSocket;
|
package/lib/Types/Socket.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export type SocketConfig = {
|
|
|
64
64
|
transactionOpts: TransactionCapabilityOptions;
|
|
65
65
|
/** marks the client as online whenever the socket successfully connects */
|
|
66
66
|
markOnlineOnConnect: boolean;
|
|
67
|
+
/** alphanumeric country code (USA -> US) for the number used */
|
|
68
|
+
countryCode: string;
|
|
67
69
|
/** provide a cache to store media, so does not have to be re-uploaded */
|
|
68
70
|
mediaCache?: CacheStore;
|
|
69
71
|
/**
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BinaryNode } from '../WABinary';
|
|
2
|
+
import { USyncUser } from '../WAUSync';
|
|
3
|
+
/**
|
|
4
|
+
* Defines the interface for a USyncQuery protocol
|
|
5
|
+
*/
|
|
6
|
+
export interface USyncQueryProtocol {
|
|
7
|
+
/**
|
|
8
|
+
* The name of the protocol
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
/**
|
|
12
|
+
* Defines what goes inside the query part of a USyncQuery
|
|
13
|
+
*/
|
|
14
|
+
getQueryElement: () => BinaryNode;
|
|
15
|
+
/**
|
|
16
|
+
* Defines what goes inside the user part of a USyncQuery
|
|
17
|
+
*/
|
|
18
|
+
getUserElement: (user: USyncUser) => BinaryNode | null;
|
|
19
|
+
/**
|
|
20
|
+
* Parse the result of the query
|
|
21
|
+
* @param data Data from the result
|
|
22
|
+
* @returns Whatever the protocol is supposed to return
|
|
23
|
+
*/
|
|
24
|
+
parser: (data: BinaryNode) => unknown;
|
|
25
|
+
}
|
|
@@ -3,6 +3,22 @@ import { proto } from '../../WAProto';
|
|
|
3
3
|
import { SignalRepository } from '../Types';
|
|
4
4
|
import { BinaryNode } from '../WABinary';
|
|
5
5
|
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
|
|
6
|
+
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
|
|
7
|
+
export declare const NACK_REASONS: {
|
|
8
|
+
ParsingError: number;
|
|
9
|
+
UnrecognizedStanza: number;
|
|
10
|
+
UnrecognizedStanzaClass: number;
|
|
11
|
+
UnrecognizedStanzaType: number;
|
|
12
|
+
InvalidProtobuf: number;
|
|
13
|
+
InvalidHostedCompanionStanza: number;
|
|
14
|
+
MissingMessageSecret: number;
|
|
15
|
+
SignalErrorOldCounter: number;
|
|
16
|
+
MessageDeletedOnPeer: number;
|
|
17
|
+
UnhandledError: number;
|
|
18
|
+
UnsupportedAdminRevoke: number;
|
|
19
|
+
UnsupportedLIDGroup: number;
|
|
20
|
+
DBOperationFailed: number;
|
|
21
|
+
};
|
|
6
22
|
/**
|
|
7
23
|
* Decode the received node as a message.
|
|
8
24
|
* @note this will only parse the message, not decrypt it
|
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decryptMessageNode = exports.decodeMessageNode = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
|
3
|
+
exports.decryptMessageNode = exports.decodeMessageNode = exports.NACK_REASONS = exports.MISSING_KEYS_ERROR_TEXT = exports.NO_MESSAGE_FOUND_ERROR_TEXT = void 0;
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
5
|
const WAProto_1 = require("../../WAProto");
|
|
6
6
|
const WABinary_1 = require("../WABinary");
|
|
7
7
|
const generics_1 = require("./generics");
|
|
8
8
|
exports.NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
9
|
+
exports.MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled';
|
|
10
|
+
exports.NACK_REASONS = {
|
|
11
|
+
ParsingError: 487,
|
|
12
|
+
UnrecognizedStanza: 488,
|
|
13
|
+
UnrecognizedStanzaClass: 489,
|
|
14
|
+
UnrecognizedStanzaType: 490,
|
|
15
|
+
InvalidProtobuf: 491,
|
|
16
|
+
InvalidHostedCompanionStanza: 493,
|
|
17
|
+
MissingMessageSecret: 495,
|
|
18
|
+
SignalErrorOldCounter: 496,
|
|
19
|
+
MessageDeletedOnPeer: 499,
|
|
20
|
+
UnhandledError: 500,
|
|
21
|
+
UnsupportedAdminRevoke: 550,
|
|
22
|
+
UnsupportedLIDGroup: 551,
|
|
23
|
+
DBOperationFailed: 552
|
|
24
|
+
};
|
|
9
25
|
/**
|
|
10
26
|
* Decode the received node as a message.
|
|
11
27
|
* @note this will only parse the message, not decrypt it
|
package/lib/Utils/messages.js
CHANGED
|
@@ -143,10 +143,6 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
143
143
|
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
|
|
144
144
|
logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
|
|
145
145
|
}
|
|
146
|
-
if (requiresWaveformProcessing) {
|
|
147
|
-
uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
|
|
148
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
|
|
149
|
-
}
|
|
150
146
|
if (requiresAudioBackground) {
|
|
151
147
|
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
152
148
|
logger === null || logger === void 0 ? void 0 : logger.debug('computed backgroundColor audio status');
|
|
@@ -161,8 +157,14 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
161
157
|
encWriteStream.destroy();
|
|
162
158
|
// remove tmp files
|
|
163
159
|
if (didSaveToTmpPath && bodyPath) {
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
try {
|
|
161
|
+
await fs_1.promises.access(bodyPath);
|
|
162
|
+
await fs_1.promises.unlink(bodyPath);
|
|
163
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('removed tmp file');
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
|
|
167
|
+
}
|
|
166
168
|
}
|
|
167
169
|
});
|
|
168
170
|
const obj = Types_1.WAProto.Message.fromObject({
|
|
@@ -214,6 +214,22 @@ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderRes
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
+
case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
|
|
218
|
+
ev.emit('messages.update', [
|
|
219
|
+
{
|
|
220
|
+
key: protocolMsg.key,
|
|
221
|
+
update: {
|
|
222
|
+
message: {
|
|
223
|
+
editedMessage: {
|
|
224
|
+
message: protocolMsg.editedMessage
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
messageTimestamp: protocolMsg.timestampMs
|
|
228
|
+
? Math.floor((0, generics_1.toNumber)(protocolMsg.timestampMs) / 1000)
|
|
229
|
+
: message.messageTimestamp
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
]);
|
|
217
233
|
break;
|
|
218
234
|
}
|
|
219
235
|
}
|
package/lib/Utils/signal.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SignalRepository } from '../Types';
|
|
2
2
|
import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
|
|
3
3
|
import { BinaryNode, JidWithDevice } from '../WABinary';
|
|
4
|
+
import { USyncQueryResultList } from '../WAUSync';
|
|
4
5
|
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
5
6
|
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
6
7
|
[id: string]: KeyPair;
|
|
@@ -15,7 +16,7 @@ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: n
|
|
|
15
16
|
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
|
|
16
17
|
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
|
|
17
18
|
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
|
|
18
|
-
export declare const extractDeviceJids: (result:
|
|
19
|
+
export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
|
|
19
20
|
/**
|
|
20
21
|
* get the next N keys for upload or processing
|
|
21
22
|
* @param count number of pre-keys to get or generate
|
package/lib/Utils/signal.js
CHANGED
|
@@ -95,29 +95,19 @@ const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
95
95
|
};
|
|
96
96
|
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
97
97
|
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
98
|
-
var _a;
|
|
99
98
|
const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
|
|
100
99
|
const extracted = [];
|
|
101
|
-
for (const
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
//eslint-disable-next-line max-depth
|
|
113
|
-
if (tag === 'device' && // ensure the "device" tag
|
|
114
|
-
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
115
|
-
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
116
|
-
(device === 0 || !!attrs['key-index']) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
117
|
-
) {
|
|
118
|
-
extracted.push({ user, device });
|
|
119
|
-
}
|
|
120
|
-
}
|
|
100
|
+
for (const userResult of result) {
|
|
101
|
+
const { devices, id } = userResult;
|
|
102
|
+
const { user } = (0, WABinary_1.jidDecode)(id);
|
|
103
|
+
const deviceList = devices === null || devices === void 0 ? void 0 : devices.deviceList;
|
|
104
|
+
if (Array.isArray(deviceList)) {
|
|
105
|
+
for (const { id: device, keyIndex } of deviceList) {
|
|
106
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
107
|
+
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
108
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
109
|
+
) {
|
|
110
|
+
extracted.push({ user, device });
|
|
121
111
|
}
|
|
122
112
|
}
|
|
123
113
|
}
|
|
@@ -22,7 +22,9 @@ const getUserAgent = (config) => {
|
|
|
22
22
|
device: 'Desktop',
|
|
23
23
|
osBuildNumber: '0.1',
|
|
24
24
|
localeLanguageIso6391: 'en',
|
|
25
|
-
|
|
25
|
+
mnc: '000',
|
|
26
|
+
mcc: '000',
|
|
27
|
+
localeCountryIso31661Alpha2: config.countryCode,
|
|
26
28
|
};
|
|
27
29
|
};
|
|
28
30
|
const PLATFORM_MAP = {
|
|
@@ -49,7 +51,8 @@ const generateLoginNode = (userJid, config) => {
|
|
|
49
51
|
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
50
52
|
const payload = {
|
|
51
53
|
...getClientPayload(config),
|
|
52
|
-
passive:
|
|
54
|
+
passive: false,
|
|
55
|
+
pull: true,
|
|
53
56
|
username: +user,
|
|
54
57
|
device: device,
|
|
55
58
|
};
|
|
@@ -75,6 +78,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
75
78
|
const registerPayload = {
|
|
76
79
|
...getClientPayload(config),
|
|
77
80
|
passive: false,
|
|
81
|
+
pull: false,
|
|
78
82
|
devicePairingData: {
|
|
79
83
|
buildHash: appVersionBuf,
|
|
80
84
|
deviceProps: companionProto,
|
package/lib/WABinary/encode.js
CHANGED
|
@@ -160,7 +160,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
|
160
160
|
}
|
|
161
161
|
for (const char of str) {
|
|
162
162
|
const isInNibbleRange = char >= '0' && char <= '9';
|
|
163
|
-
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')
|
|
163
|
+
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
164
164
|
return false;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync';
|
|
2
|
+
import { BinaryNode } from '../../WABinary';
|
|
3
|
+
import { USyncUser } from '../USyncUser';
|
|
4
|
+
export declare class USyncContactProtocol implements USyncQueryProtocol {
|
|
5
|
+
name: string;
|
|
6
|
+
getQueryElement(): BinaryNode;
|
|
7
|
+
getUserElement(user: USyncUser): BinaryNode;
|
|
8
|
+
parser(node: BinaryNode): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USyncContactProtocol = void 0;
|
|
4
|
+
const WABinary_1 = require("../../WABinary");
|
|
5
|
+
class USyncContactProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'contact';
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'contact',
|
|
12
|
+
attrs: {},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
getUserElement(user) {
|
|
16
|
+
//TODO: Implement type / username fields (not yet supported)
|
|
17
|
+
return {
|
|
18
|
+
tag: 'contact',
|
|
19
|
+
attrs: {},
|
|
20
|
+
content: user.phone,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
parser(node) {
|
|
24
|
+
var _a;
|
|
25
|
+
if (node.tag === 'contact') {
|
|
26
|
+
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
27
|
+
return ((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.type) === 'in';
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.USyncContactProtocol = USyncContactProtocol;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync';
|
|
2
|
+
import { BinaryNode } from '../../WABinary';
|
|
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
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USyncDeviceProtocol = void 0;
|
|
4
|
+
const WABinary_1 = require("../../WABinary");
|
|
5
|
+
class USyncDeviceProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'devices';
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'devices',
|
|
12
|
+
attrs: {
|
|
13
|
+
version: '2',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
getUserElement( /* user: USyncUser */) {
|
|
18
|
+
//TODO: Implement device phashing, ts and expectedTs
|
|
19
|
+
//TODO: if all are not present, return null <- current behavior
|
|
20
|
+
//TODO: otherwise return a node w tag 'devices' w those as attrs
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
parser(node) {
|
|
24
|
+
const deviceList = [];
|
|
25
|
+
let keyIndex = undefined;
|
|
26
|
+
if (node.tag === 'devices') {
|
|
27
|
+
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
28
|
+
const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(node, 'device-list');
|
|
29
|
+
const keyIndexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'key-index-list');
|
|
30
|
+
if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
|
|
31
|
+
for (const { tag, attrs } of deviceListNode.content) {
|
|
32
|
+
const id = +attrs.id;
|
|
33
|
+
const keyIndex = +attrs['key-index'];
|
|
34
|
+
if (tag === 'device') {
|
|
35
|
+
deviceList.push({
|
|
36
|
+
id,
|
|
37
|
+
keyIndex,
|
|
38
|
+
isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list') {
|
|
44
|
+
keyIndex = {
|
|
45
|
+
timestamp: +keyIndexNode.attrs['ts'],
|
|
46
|
+
signedKeyIndex: keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.content,
|
|
47
|
+
expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
deviceList,
|
|
53
|
+
keyIndex
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.USyncDeviceProtocol = USyncDeviceProtocol;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync';
|
|
2
|
+
import { BinaryNode } from '../../WABinary';
|
|
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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USyncDisappearingModeProtocol = void 0;
|
|
4
|
+
const WABinary_1 = require("../../WABinary");
|
|
5
|
+
class USyncDisappearingModeProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'disappearing_mode';
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'disappearing_mode',
|
|
12
|
+
attrs: {},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
getUserElement() {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
parser(node) {
|
|
19
|
+
if (node.tag === 'status') {
|
|
20
|
+
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
21
|
+
const duration = +(node === null || node === void 0 ? void 0 : node.attrs.duration);
|
|
22
|
+
const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
|
|
23
|
+
return {
|
|
24
|
+
duration,
|
|
25
|
+
setAt,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.USyncDisappearingModeProtocol = USyncDisappearingModeProtocol;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { USyncQueryProtocol } from '../../Types/USync';
|
|
2
|
+
import { BinaryNode } from '../../WABinary';
|
|
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
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USyncStatusProtocol = void 0;
|
|
4
|
+
const WABinary_1 = require("../../WABinary");
|
|
5
|
+
class USyncStatusProtocol {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'status';
|
|
8
|
+
}
|
|
9
|
+
getQueryElement() {
|
|
10
|
+
return {
|
|
11
|
+
tag: 'status',
|
|
12
|
+
attrs: {},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
getUserElement() {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
parser(node) {
|
|
19
|
+
var _a;
|
|
20
|
+
if (node.tag === 'status') {
|
|
21
|
+
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
22
|
+
let status = node === null || node === void 0 ? void 0 : node.content.toString();
|
|
23
|
+
const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
|
|
24
|
+
if (!status) {
|
|
25
|
+
if (+((_a = node.attrs) === null || _a === void 0 ? void 0 : _a.code) === 401) {
|
|
26
|
+
status = '';
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
status = null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (typeof status === 'string' && status.length === 0) {
|
|
33
|
+
status = null;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
status,
|
|
37
|
+
setAt,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.USyncStatusProtocol = USyncStatusProtocol;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./USyncDeviceProtocol"), exports);
|
|
18
|
+
__exportStar(require("./USyncContactProtocol"), exports);
|
|
19
|
+
__exportStar(require("./USyncStatusProtocol"), exports);
|
|
20
|
+
__exportStar(require("./USyncDisappearingModeProtocol"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { USyncQueryProtocol } from '../Types/USync';
|
|
2
|
+
import { BinaryNode } from '../WABinary';
|
|
3
|
+
import { USyncUser } from './USyncUser';
|
|
4
|
+
export type USyncQueryResultList = {
|
|
5
|
+
[protocol: string]: unknown;
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
export type USyncQueryResult = {
|
|
9
|
+
list: USyncQueryResultList[];
|
|
10
|
+
sideList: USyncQueryResultList[];
|
|
11
|
+
};
|
|
12
|
+
export declare class USyncQuery {
|
|
13
|
+
protocols: USyncQueryProtocol[];
|
|
14
|
+
users: USyncUser[];
|
|
15
|
+
context: string;
|
|
16
|
+
mode: string;
|
|
17
|
+
constructor();
|
|
18
|
+
withMode(mode: string): this;
|
|
19
|
+
withContext(context: string): this;
|
|
20
|
+
withUser(user: USyncUser): this;
|
|
21
|
+
parseUSyncQueryResult(result: BinaryNode): USyncQueryResult | undefined;
|
|
22
|
+
withDeviceProtocol(): this;
|
|
23
|
+
withContactProtocol(): this;
|
|
24
|
+
withStatusProtocol(): this;
|
|
25
|
+
withDisappearingModeProtocol(): this;
|
|
26
|
+
}
|