@zetagoaurum-socket/wasocket 3.1.0 → 3.2.7
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 +81 -60
- package/WAProto/index.js +56886 -17506
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +50 -9
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +51 -29
- package/lib/Socket/business.d.ts +3 -2
- package/lib/Socket/chats.d.ts +215 -28
- package/lib/Socket/chats.js +185 -70
- package/lib/Socket/chats.js.bak +981 -0
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +432 -141
- package/lib/Socket/groups.js +20 -23
- package/lib/Socket/index.js +2 -15
- package/lib/Socket/messages-recv.d.ts +56 -55
- package/lib/Socket/messages-recv.js +370 -112
- package/lib/Socket/messages-send.d.ts +3 -2
- package/lib/Socket/messages-send.js +464 -377
- package/lib/Socket/newsletter.js +175 -28
- package/lib/Socket/socket.js +204 -176
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/Newsletter.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Utils/anti-crash.js +20 -0
- package/lib/Utils/auto-contact.js +74 -0
- package/lib/Utils/chat-utils.js +17 -3
- package/lib/Utils/generics.js +68 -31
- package/lib/Utils/generics.js.bak +433 -0
- package/lib/Utils/history.js +6 -1
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/link-preview.js +4 -2
- package/lib/Utils/messages-media.js +145 -57
- package/lib/Utils/messages.js +89 -305
- package/lib/Utils/signal.js +48 -46
- package/lib/Utils/use-multi-file-auth-state.js +45 -6
- package/lib/Utils/validate-connection.js +91 -65
- package/lib/Utils/validate-connection.js.bak +237 -0
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/encode.js +160 -123
- package/lib/WABinary/generic-utils.d.ts +2 -0
- package/lib/WABinary/generic-utils.js +124 -36
- package/lib/WABinary/jid-utils.js +5 -26
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +9 -0
- package/package.json +105 -100
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -3344
- package/WAProto/index.d.ts +0 -37016
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Utils/rate-limiter.js +0 -55
- package/lib/WAUSync/Fall +0 -1
- package/lib/WAUSync/Protocols/Fal +0 -1
package/lib/Utils/signal.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids
|
|
|
4
4
|
const Defaults_1 = require("../Defaults");
|
|
5
5
|
const WABinary_1 = require("../WABinary");
|
|
6
6
|
const crypto_1 = require("./crypto");
|
|
7
|
+
const lodash_1 = require("lodash")
|
|
7
8
|
const generics_1 = require("./generics");
|
|
8
9
|
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
9
10
|
return {
|
|
@@ -58,60 +59,61 @@ const xmppPreKey = (pair, id) => ({
|
|
|
58
59
|
exports.xmppPreKey = xmppPreKey;
|
|
59
60
|
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
60
61
|
const extractKey = (key) => (key ? ({
|
|
61
|
-
keyId:
|
|
62
|
-
publicKey:
|
|
63
|
-
signature:
|
|
64
|
-
}) : undefined)
|
|
65
|
-
const nodes =
|
|
62
|
+
keyId: WABinary_1.getBinaryNodeChildUInt(key, 'id', 3),
|
|
63
|
+
publicKey: crypto_1.generateSignalPubKey(WABinary_1.getBinaryNodeChildBuffer(key, 'value')),
|
|
64
|
+
signature: WABinary_1.getBinaryNodeChildBuffer(key, 'signature')
|
|
65
|
+
}) : undefined)
|
|
66
|
+
const nodes = WABinary_1.getBinaryNodeChildren(WABinary_1.getBinaryNodeChild(node, 'list'), 'user')
|
|
66
67
|
for (const node of nodes) {
|
|
67
|
-
|
|
68
|
+
WABinary_1.assertNodeErrorFree(node)
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
70
|
+
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
71
|
+
// So Promise.all doesn't really help here,
|
|
72
|
+
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
73
|
+
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
74
|
+
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
75
|
+
const chunkSize = 100
|
|
76
|
+
const chunks = lodash_1.chunk(nodes, chunkSize)
|
|
77
|
+
for (const nodesChunk of chunks) {
|
|
78
|
+
await Promise.all(nodesChunk.map(async (node) => {
|
|
79
|
+
const signedKey = WABinary_1.getBinaryNodeChild(node, 'skey')
|
|
80
|
+
const key = WABinary_1.getBinaryNodeChild(node, 'key')
|
|
81
|
+
const identity = WABinary_1.getBinaryNodeChildBuffer(node, 'identity')
|
|
82
|
+
const jid = node.attrs.jid
|
|
83
|
+
const registrationId = WABinary_1.getBinaryNodeChildUInt(node, 'registration', 4)
|
|
84
|
+
await repository.injectE2ESession({
|
|
85
|
+
jid,
|
|
86
|
+
session: {
|
|
87
|
+
registrationId: registrationId,
|
|
88
|
+
identityKey: crypto_1.generateSignalPubKey(identity),
|
|
89
|
+
signedPreKey: extractKey(signedKey),
|
|
90
|
+
preKey: extractKey(key)
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
}))
|
|
94
|
+
}
|
|
95
|
+
}
|
|
86
96
|
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
87
97
|
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (tag === 'device' && // ensure the "device" tag
|
|
102
|
-
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
103
|
-
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
104
|
-
(device === 0 || !!attrs['key-index']) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
105
|
-
) {
|
|
106
|
-
extracted.push({ user, device });
|
|
107
|
-
}
|
|
108
|
-
}
|
|
98
|
+
const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
|
|
99
|
+
const extracted = []
|
|
100
|
+
for (const userResult of result) {
|
|
101
|
+
const { devices, id } = userResult
|
|
102
|
+
const { user } = WABinary_1.jidDecode(id)
|
|
103
|
+
const deviceList = 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 })
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
|
-
return extracted
|
|
114
|
-
}
|
|
115
|
+
return extracted
|
|
116
|
+
}
|
|
115
117
|
exports.extractDeviceJids = extractDeviceJids;
|
|
116
118
|
/**
|
|
117
119
|
* get the next N keys for upload or processing
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useMultiFileAuthState = void 0;
|
|
4
|
+
const async_mutex_1 = require("async-mutex");
|
|
4
5
|
const promises_1 = require("fs/promises");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const WAProto_1 = require("../../WAProto");
|
|
7
8
|
const auth_utils_1 = require("./auth-utils");
|
|
8
9
|
const generics_1 = require("./generics");
|
|
10
|
+
const fileLocks = new Map();
|
|
11
|
+
const getFileLock = (path) => {
|
|
12
|
+
let mutex = fileLocks.get(path);
|
|
13
|
+
if (!mutex) {
|
|
14
|
+
mutex = new async_mutex_1.Mutex();
|
|
15
|
+
fileLocks.set(path, mutex);
|
|
16
|
+
}
|
|
17
|
+
return mutex;
|
|
18
|
+
};
|
|
9
19
|
/**
|
|
10
20
|
* stores the full authentication state in a single folder.
|
|
11
21
|
* Far more efficient than singlefileauthstate
|
|
@@ -14,13 +24,31 @@ const generics_1 = require("./generics");
|
|
|
14
24
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
15
25
|
* */
|
|
16
26
|
const useMultiFileAuthState = async (folder) => {
|
|
17
|
-
const writeData = (data, file) => {
|
|
18
|
-
|
|
27
|
+
const writeData = async (data, file) => {
|
|
28
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
29
|
+
const mutex = getFileLock(filePath);
|
|
30
|
+
return mutex.acquire().then(async (release) => {
|
|
31
|
+
try {
|
|
32
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
release();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
19
38
|
};
|
|
20
39
|
const readData = async (file) => {
|
|
21
40
|
try {
|
|
22
|
-
const
|
|
23
|
-
|
|
41
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
42
|
+
const mutex = getFileLock(filePath);
|
|
43
|
+
return await mutex.acquire().then(async (release) => {
|
|
44
|
+
try {
|
|
45
|
+
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
46
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
release();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
24
52
|
}
|
|
25
53
|
catch (error) {
|
|
26
54
|
return null;
|
|
@@ -28,7 +56,18 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
28
56
|
};
|
|
29
57
|
const removeData = async (file) => {
|
|
30
58
|
try {
|
|
31
|
-
|
|
59
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
60
|
+
const mutex = getFileLock(filePath);
|
|
61
|
+
return mutex.acquire().then(async (release) => {
|
|
62
|
+
try {
|
|
63
|
+
await (0, promises_1.unlink)(filePath);
|
|
64
|
+
}
|
|
65
|
+
catch (_a) {
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
release();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
32
71
|
}
|
|
33
72
|
catch (_a) {
|
|
34
73
|
}
|
|
@@ -72,7 +111,7 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
72
111
|
}
|
|
73
112
|
}
|
|
74
113
|
},
|
|
75
|
-
saveCreds: () => {
|
|
114
|
+
saveCreds: async () => {
|
|
76
115
|
return writeData(creds, 'creds.json');
|
|
77
116
|
}
|
|
78
117
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode =
|
|
3
|
+
exports.encodeSignedDeviceIdentity = exports.configureSuccessfulPairing = exports.generateRegistrationNode = exports.generateLoginNode = void 0;
|
|
4
4
|
const boom_1 = require("@hapi/boom");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
6
|
const WAProto_1 = require("../../WAProto");
|
|
@@ -8,107 +8,110 @@ const Defaults_1 = require("../Defaults");
|
|
|
8
8
|
const WABinary_1 = require("../WABinary");
|
|
9
9
|
const crypto_2 = require("./crypto");
|
|
10
10
|
const generics_1 = require("./generics");
|
|
11
|
-
const signal_1 = require("./signal");
|
|
11
|
+
const signal_1 = require("./signal");
|
|
12
|
+
|
|
12
13
|
const getUserAgent = (config) => {
|
|
13
|
-
var _a, _b;
|
|
14
|
-
const osVersion = config.mobile ? '15.3.1' : '0.1';
|
|
15
|
-
const version = config.mobile ? [2, 24, 6] : config.version;
|
|
16
|
-
const device = config.mobile ? 'iPhone_7' : 'Desktop';
|
|
17
|
-
const manufacturer = config.mobile ? 'Apple' : '';
|
|
18
|
-
const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
|
|
19
|
-
const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
|
|
20
14
|
return {
|
|
21
15
|
appVersion: {
|
|
22
|
-
primary: version[0],
|
|
23
|
-
secondary: version[1],
|
|
24
|
-
tertiary: version[2],
|
|
16
|
+
primary: config.version[0],
|
|
17
|
+
secondary: config.version[1],
|
|
18
|
+
tertiary: config.version[2],
|
|
25
19
|
},
|
|
26
|
-
platform,
|
|
20
|
+
platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
27
21
|
releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
manufacturer,
|
|
32
|
-
device,
|
|
33
|
-
osBuildNumber: osVersion,
|
|
22
|
+
osVersion: '0.1',
|
|
23
|
+
device: 'Desktop',
|
|
24
|
+
osBuildNumber: '0.1',
|
|
34
25
|
localeLanguageIso6391: 'en',
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
mnc: '000',
|
|
27
|
+
mcc: '000',
|
|
28
|
+
localeCountryIso31661Alpha2: config.countryCode || 'US'
|
|
37
29
|
};
|
|
38
30
|
};
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
39
34
|
const PLATFORM_MAP = {
|
|
40
35
|
'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
41
36
|
'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
42
37
|
};
|
|
38
|
+
|
|
43
39
|
const getWebInfo = (config) => {
|
|
44
40
|
let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
45
|
-
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
|
|
41
|
+
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
|
|
46
42
|
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
47
43
|
}
|
|
48
44
|
return { webSubPlatform };
|
|
49
45
|
};
|
|
46
|
+
|
|
50
47
|
const getClientPayload = (config) => {
|
|
51
48
|
const payload = {
|
|
52
49
|
connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
53
50
|
connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
54
51
|
userAgent: getUserAgent(config),
|
|
55
52
|
};
|
|
56
|
-
|
|
57
|
-
payload.webInfo = getWebInfo(config);
|
|
58
|
-
}
|
|
53
|
+
payload.webInfo = getWebInfo(config);
|
|
59
54
|
return payload;
|
|
60
55
|
};
|
|
61
|
-
|
|
62
|
-
if (!config.auth.creds) {
|
|
63
|
-
throw new boom_1.Boom('No registration data found', { data: config });
|
|
64
|
-
}
|
|
65
|
-
const payload = {
|
|
66
|
-
...getClientPayload(config),
|
|
67
|
-
sessionId: Math.floor(Math.random() * 999999999 + 1),
|
|
68
|
-
shortConnect: true,
|
|
69
|
-
connectAttemptCount: 0,
|
|
70
|
-
device: 0,
|
|
71
|
-
dnsSource: {
|
|
72
|
-
appCached: false,
|
|
73
|
-
dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
|
|
74
|
-
},
|
|
75
|
-
passive: false,
|
|
76
|
-
pushName: 'test',
|
|
77
|
-
username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
|
|
78
|
-
};
|
|
79
|
-
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
80
|
-
};
|
|
81
|
-
exports.generateMobileNode = generateMobileNode;
|
|
56
|
+
|
|
82
57
|
const generateLoginNode = (userJid, config) => {
|
|
83
58
|
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
84
59
|
const payload = {
|
|
85
60
|
...getClientPayload(config),
|
|
86
61
|
passive: true,
|
|
62
|
+
pull: true,
|
|
87
63
|
username: +user,
|
|
88
64
|
device: device,
|
|
65
|
+
lidDbMigrated: false
|
|
89
66
|
};
|
|
90
67
|
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
91
68
|
};
|
|
92
69
|
exports.generateLoginNode = generateLoginNode;
|
|
70
|
+
|
|
93
71
|
const getPlatformType = (platform) => {
|
|
94
72
|
const platformType = platform.toUpperCase();
|
|
95
|
-
return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.
|
|
73
|
+
return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.CHROME;
|
|
96
74
|
};
|
|
75
|
+
|
|
97
76
|
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
98
|
-
// the app version needs to be md5 hashed
|
|
99
|
-
// and passed in
|
|
100
77
|
const appVersionBuf = (0, crypto_1.createHash)('md5')
|
|
101
|
-
.update(config.version.join('.'))
|
|
78
|
+
.update(config.version.join('.'))
|
|
102
79
|
.digest();
|
|
80
|
+
|
|
103
81
|
const companion = {
|
|
104
82
|
os: config.browser[0],
|
|
105
83
|
platformType: getPlatformType(config.browser[1]),
|
|
106
84
|
requireFullSync: config.syncFullHistory,
|
|
85
|
+
historySyncConfig: {
|
|
86
|
+
storageQuotaMb: 10240,
|
|
87
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
88
|
+
recentSyncDaysLimit: undefined,
|
|
89
|
+
supportCallLogHistory: false,
|
|
90
|
+
supportBotUserAgentChatHistory: true,
|
|
91
|
+
supportCagReactionsAndPolls: true,
|
|
92
|
+
supportBizHostedMsg: true,
|
|
93
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
94
|
+
supportHostedGroupMsg: true,
|
|
95
|
+
supportFbidBotChatHistory: true,
|
|
96
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
97
|
+
supportMessageAssociation: true,
|
|
98
|
+
supportGroupHistory: false,
|
|
99
|
+
onDemandReady: undefined,
|
|
100
|
+
supportGuestChat: undefined
|
|
101
|
+
},
|
|
102
|
+
version: {
|
|
103
|
+
primary: 10,
|
|
104
|
+
secondary: 15,
|
|
105
|
+
tertiary: 7
|
|
106
|
+
}
|
|
107
107
|
};
|
|
108
|
+
|
|
108
109
|
const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
|
|
110
|
+
|
|
109
111
|
const registerPayload = {
|
|
110
112
|
...getClientPayload(config),
|
|
111
113
|
passive: false,
|
|
114
|
+
pull: false,
|
|
112
115
|
devicePairingData: {
|
|
113
116
|
buildHash: appVersionBuf,
|
|
114
117
|
deviceProps: companionProto,
|
|
@@ -123,6 +126,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
123
126
|
return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
|
|
124
127
|
};
|
|
125
128
|
exports.generateRegistrationNode = generateRegistrationNode;
|
|
129
|
+
|
|
126
130
|
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
127
131
|
const msgId = stanza.attrs.id;
|
|
128
132
|
const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
|
|
@@ -130,30 +134,52 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
130
134
|
const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
|
|
131
135
|
const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
|
|
132
136
|
const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
|
|
137
|
+
|
|
133
138
|
if (!deviceIdentityNode || !deviceNode) {
|
|
134
139
|
throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
|
|
135
140
|
}
|
|
136
|
-
|
|
141
|
+
|
|
142
|
+
const bizName = businessNode?.attrs.name;
|
|
137
143
|
const jid = deviceNode.attrs.jid;
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
const
|
|
144
|
+
const lid = deviceNode.attrs.lid;
|
|
145
|
+
|
|
146
|
+
const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
147
|
+
|
|
148
|
+
let hmacPrefix = Buffer.from([]);
|
|
149
|
+
if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
|
|
150
|
+
hmacPrefix = Buffer.from([0x06, 0x05]);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
141
154
|
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
142
155
|
throw new boom_1.Boom('Invalid account signature');
|
|
143
156
|
}
|
|
157
|
+
|
|
144
158
|
const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details);
|
|
145
159
|
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
146
|
-
|
|
147
|
-
const
|
|
160
|
+
|
|
161
|
+
const deviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails);
|
|
162
|
+
|
|
163
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
|
|
164
|
+
? Buffer.from([0x06, 0x05])
|
|
165
|
+
: Buffer.from([0x06, 0x00]);
|
|
166
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
|
|
167
|
+
|
|
148
168
|
if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
149
169
|
throw new boom_1.Boom('Failed to verify account signature');
|
|
150
170
|
}
|
|
151
|
-
|
|
152
|
-
const deviceMsg = Buffer.concat([
|
|
171
|
+
|
|
172
|
+
const deviceMsg = Buffer.concat([
|
|
173
|
+
Buffer.from([0x06, 0x01]),
|
|
174
|
+
deviceDetails,
|
|
175
|
+
signedIdentityKey.public,
|
|
176
|
+
accountSignatureKey
|
|
177
|
+
]);
|
|
153
178
|
account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
179
|
+
|
|
154
180
|
const identity = (0, signal_1.createSignalIdentity)(jid, accountSignatureKey);
|
|
155
181
|
const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
|
|
156
|
-
|
|
182
|
+
|
|
157
183
|
const reply = {
|
|
158
184
|
tag: 'iq',
|
|
159
185
|
attrs: {
|
|
@@ -175,27 +201,27 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
175
201
|
}
|
|
176
202
|
]
|
|
177
203
|
};
|
|
204
|
+
|
|
178
205
|
const authUpdate = {
|
|
179
206
|
account,
|
|
180
|
-
me: { id: jid, name: bizName },
|
|
207
|
+
me: { id: jid, name: bizName, lid },
|
|
181
208
|
signalIdentities: [
|
|
182
209
|
...(signalIdentities || []),
|
|
183
210
|
identity
|
|
184
211
|
],
|
|
185
|
-
platform: platformNode
|
|
212
|
+
platform: platformNode?.attrs.name
|
|
186
213
|
};
|
|
214
|
+
|
|
187
215
|
return {
|
|
188
216
|
creds: authUpdate,
|
|
189
217
|
reply
|
|
190
218
|
};
|
|
191
219
|
};
|
|
192
220
|
exports.configureSuccessfulPairing = configureSuccessfulPairing;
|
|
221
|
+
|
|
193
222
|
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
194
|
-
var _a;
|
|
195
223
|
account = { ...account };
|
|
196
|
-
|
|
197
|
-
// or if we are including the signature key but it is empty
|
|
198
|
-
if (!includeSignatureKey || !((_a = account.accountSignatureKey) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
224
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
199
225
|
account.accountSignatureKey = null;
|
|
200
226
|
}
|
|
201
227
|
return WAProto_1.proto.ADVSignedDeviceIdentity
|