@leonoremods/baileys 0.0.0-stage → 1.2.9
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 +21 -0
- package/README.md +1204 -2
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +8083 -0
- package/WAProto/fix-imports.js +75 -0
- package/WAProto/index.d.ts +23020 -0
- package/WAProto/index.js +136324 -0
- package/engine-requirements.js +17 -0
- package/package.json +107 -4
- package/scripts/check-syntax.js +28 -0
- package/src/Defaults/index.js +186 -0
- package/src/Defaults/phonenumber-mcc.json +223 -0
- package/src/Signal/Group/ciphertext-message.js +15 -0
- package/src/Signal/Group/group-session-builder.js +86 -0
- package/src/Signal/Group/group_cipher.js +82 -0
- package/src/Signal/Group/index.js +140 -0
- package/src/Signal/Group/keyhelper.js +77 -0
- package/src/Signal/Group/sender-chain-key.js +29 -0
- package/src/Signal/Group/sender-key-distribution-message.js +66 -0
- package/src/Signal/Group/sender-key-message.js +69 -0
- package/src/Signal/Group/sender-key-name.js +51 -0
- package/src/Signal/Group/sender-key-record.js +44 -0
- package/src/Signal/Group/sender-key-state.js +87 -0
- package/src/Signal/Group/sender-message-key.js +29 -0
- package/src/Signal/libsignal.js +455 -0
- package/src/Signal/lid-mapping.js +273 -0
- package/src/Socket/Client/index.js +31 -0
- package/src/Socket/Client/types.js +13 -0
- package/src/Socket/Client/websocket.js +61 -0
- package/src/Socket/aigroups.js +221 -0
- package/src/Socket/business.js +411 -0
- package/src/Socket/chats.js +1449 -0
- package/src/Socket/communities.js +463 -0
- package/src/Socket/graphql.js +523 -0
- package/src/Socket/groups.js +516 -0
- package/src/Socket/index.js +31 -0
- package/src/Socket/interactive-handler.js +527 -0
- package/src/Socket/interop.js +339 -0
- package/src/Socket/luxu.js +349 -0
- package/src/Socket/managed-account.js +98 -0
- package/src/Socket/messages-recv.js +2685 -0
- package/src/Socket/messages-send.js +2047 -0
- package/src/Socket/mex.js +57 -0
- package/src/Socket/newsletter.js +455 -0
- package/src/Socket/privacy.js +125 -0
- package/src/Socket/registration.js +236 -0
- package/src/Socket/socket.js +983 -0
- package/src/Socket/text-router.js +65 -0
- package/src/Socket/username.js +130 -0
- package/src/Store/index.js +33 -0
- package/src/Store/keyed-db.js +118 -0
- package/src/Store/make-cache-manager-store.js +84 -0
- package/src/Store/make-in-memory-store.js +551 -0
- package/src/Store/make-ordered-dictionary.js +81 -0
- package/src/Store/object-repository.js +26 -0
- package/src/Types/Auth.js +31 -0
- package/src/Types/Bussines.js +2 -0
- package/src/Types/Call.js +2 -0
- package/src/Types/Chat.js +4 -0
- package/src/Types/Contact.js +2 -0
- package/src/Types/Events.js +2 -0
- package/src/Types/GroupMetadata.js +2 -0
- package/src/Types/Label.js +26 -0
- package/src/Types/LabelAssociation.js +8 -0
- package/src/Types/Message.js +93 -0
- package/src/Types/Mex.js +112 -0
- package/src/Types/Newsletter.js +109 -0
- package/src/Types/Product.js +2 -0
- package/src/Types/Signal.js +2 -0
- package/src/Types/Socket.js +2 -0
- package/src/Types/State.js +62 -0
- package/src/Types/USync.js +2 -0
- package/src/Types/index.js +56 -0
- package/src/Utils/auth-utils.js +254 -0
- package/src/Utils/browser-utils.js +112 -0
- package/src/Utils/business.js +240 -0
- package/src/Utils/chat-utils.js +1230 -0
- package/src/Utils/command-loader.d.ts +27 -0
- package/src/Utils/command-loader.js +89 -0
- package/src/Utils/companion-reg-client-utils.js +40 -0
- package/src/Utils/consumer-application.js +105 -0
- package/src/Utils/crypto.js +118 -0
- package/src/Utils/curve25519-js.js +242 -0
- package/src/Utils/decode-wa-message.js +529 -0
- package/src/Utils/event-buffer.js +580 -0
- package/src/Utils/generics.js +483 -0
- package/src/Utils/group-history.js +44 -0
- package/src/Utils/history.js +232 -0
- package/src/Utils/identity-change-handler.js +52 -0
- package/src/Utils/index.js +59 -0
- package/src/Utils/jid-display-normalization.js +195 -0
- package/src/Utils/link-preview.js +135 -0
- package/src/Utils/logger.js +8 -0
- package/src/Utils/lt-hash.js +25 -0
- package/src/Utils/make-mutex.js +36 -0
- package/src/Utils/message-composer.js +471 -0
- package/src/Utils/message-retry-manager.js +217 -0
- package/src/Utils/messages-media.js +843 -0
- package/src/Utils/messages.js +2817 -0
- package/src/Utils/meta-ai-msmsg.js +222 -0
- package/src/Utils/native-bridge.js +68 -0
- package/src/Utils/noise-handler.js +169 -0
- package/src/Utils/offline-node-processor.js +34 -0
- package/src/Utils/pre-key-manager.js +90 -0
- package/src/Utils/process-message.js +950 -0
- package/src/Utils/reporting-utils.js +261 -0
- package/src/Utils/session-pool.d.ts +14 -0
- package/src/Utils/session-pool.js +70 -0
- package/src/Utils/signal.js +217 -0
- package/src/Utils/socket-tools.js +252 -0
- package/src/Utils/stanza-ack.js +30 -0
- package/src/Utils/sticker.d.ts +13 -0
- package/src/Utils/sticker.js +123 -0
- package/src/Utils/sync-action-utils.js +45 -0
- package/src/Utils/tc-token-utils.js +158 -0
- package/src/Utils/use-multi-file-auth-state.js +111 -0
- package/src/Utils/validate-connection.js +209 -0
- package/src/Utils/view-once-cache.d.ts +12 -0
- package/src/Utils/view-once-cache.js +63 -0
- package/src/Utils/voip-rekey.js +22 -0
- package/src/WABinary/constants.js +1304 -0
- package/src/WABinary/decode.js +342 -0
- package/src/WABinary/encode.js +225 -0
- package/src/WABinary/generic-utils.js +238 -0
- package/src/WABinary/index.js +34 -0
- package/src/WABinary/jid-utils.js +351 -0
- package/src/WABinary/types.js +2 -0
- package/src/WAM/BinaryInfo.js +13 -0
- package/src/WAM/constants.js +39484 -0
- package/src/WAM/encode.js +149 -0
- package/src/WAM/index.js +32 -0
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +44 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +54 -0
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +32 -0
- package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +481 -0
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +34 -0
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
- package/src/WAUSync/Protocols/index.js +40 -0
- package/src/WAUSync/USyncQuery.js +126 -0
- package/src/WAUSync/USyncUser.js +50 -0
- package/src/WAUSync/index.js +32 -0
- package/src/antiban.js +4152 -0
- package/src/index.js +78 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.useMultiFileAuthState = void 0;
|
|
4
|
+
const async_mutex_1 = require('async-mutex');
|
|
5
|
+
const promises_1 = require('fs/promises');
|
|
6
|
+
const path_1 = require('path');
|
|
7
|
+
const index_js_1 = require('../../WAProto/index.js');
|
|
8
|
+
const auth_utils_1 = require('./auth-utils');
|
|
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
|
+
};
|
|
19
|
+
const useMultiFileAuthState = async (folder) => {
|
|
20
|
+
const writeData = async (data, file) => {
|
|
21
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
22
|
+
const mutex = getFileLock(filePath);
|
|
23
|
+
return mutex.acquire().then(async (release) => {
|
|
24
|
+
try {
|
|
25
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
release();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const readData = async (file) => {
|
|
33
|
+
try {
|
|
34
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
35
|
+
const mutex = getFileLock(filePath);
|
|
36
|
+
return await mutex.acquire().then(async (release) => {
|
|
37
|
+
try {
|
|
38
|
+
const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
39
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
release();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const removeData = async (file) => {
|
|
51
|
+
try {
|
|
52
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
53
|
+
const mutex = getFileLock(filePath);
|
|
54
|
+
return mutex.acquire().then(async (release) => {
|
|
55
|
+
try {
|
|
56
|
+
await (0, promises_1.unlink)(filePath);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
release();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch { }
|
|
66
|
+
};
|
|
67
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
|
|
68
|
+
if (folderInfo) {
|
|
69
|
+
if (!folderInfo.isDirectory()) {
|
|
70
|
+
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
const fixFileName = file => file?.replace(/\//g, '__')?.replace(/:/g, '-');
|
|
77
|
+
const creds = (await readData('creds.json')) || (0, auth_utils_1.initAuthCreds)();
|
|
78
|
+
return {
|
|
79
|
+
state: {
|
|
80
|
+
creds,
|
|
81
|
+
keys: {
|
|
82
|
+
get: async (type, ids) => {
|
|
83
|
+
const data = {};
|
|
84
|
+
await Promise.all(ids.map(async (id) => {
|
|
85
|
+
let value = await readData(`${type}-${id}.json`);
|
|
86
|
+
if (type === 'app-state-sync-key' && value) {
|
|
87
|
+
value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
88
|
+
}
|
|
89
|
+
data[id] = value;
|
|
90
|
+
}));
|
|
91
|
+
return data;
|
|
92
|
+
},
|
|
93
|
+
set: async (data) => {
|
|
94
|
+
const tasks = [];
|
|
95
|
+
for (const category in data) {
|
|
96
|
+
for (const id in data[category]) {
|
|
97
|
+
const value = data[category][id];
|
|
98
|
+
const file = `${category}-${id}.json`;
|
|
99
|
+
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
await Promise.all(tasks);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
saveCreds: async () => {
|
|
107
|
+
return writeData(creds, 'creds.json');
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.encodeSignedDeviceIdentity =
|
|
4
|
+
exports.configureSuccessfulPairing =
|
|
5
|
+
exports.generateRegistrationNode =
|
|
6
|
+
exports.generateLoginNode =
|
|
7
|
+
void 0;
|
|
8
|
+
const boom_1 = require('@hapi/boom');
|
|
9
|
+
const crypto_1 = require('crypto');
|
|
10
|
+
const Crypto_1 = require('./crypto');
|
|
11
|
+
const index_js_1 = require('../../WAProto/index.js');
|
|
12
|
+
const Defaults_1 = require('../Defaults');
|
|
13
|
+
const WABinary_1 = require('../WABinary');
|
|
14
|
+
const crypto_2 = require('./crypto');
|
|
15
|
+
const generics_1 = require('./generics');
|
|
16
|
+
const signal_1 = require('./signal');
|
|
17
|
+
const getUserAgent = config => {
|
|
18
|
+
return {
|
|
19
|
+
appVersion: {
|
|
20
|
+
primary: config.version[0],
|
|
21
|
+
secondary: config.version[1],
|
|
22
|
+
tertiary: config.version[2]
|
|
23
|
+
},
|
|
24
|
+
platform: index_js_1.proto.ClientPayload.UserAgent.Platform.WEB,
|
|
25
|
+
releaseChannel: index_js_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
26
|
+
osVersion: '0.1',
|
|
27
|
+
device: 'Desktop',
|
|
28
|
+
osBuildNumber: '0.1',
|
|
29
|
+
localeLanguageIso6391: 'en',
|
|
30
|
+
mnc: '000',
|
|
31
|
+
mcc: '000',
|
|
32
|
+
localeCountryIso31661Alpha2: config.countryCode
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const PLATFORM_MAP = {
|
|
36
|
+
'Mac OS': index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
37
|
+
Windows: index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
|
|
38
|
+
};
|
|
39
|
+
const getWebInfo = config => {
|
|
40
|
+
let webSubPlatform = index_js_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER;
|
|
41
|
+
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop') {
|
|
42
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]];
|
|
43
|
+
}
|
|
44
|
+
return { webSubPlatform };
|
|
45
|
+
};
|
|
46
|
+
const getClientPayload = config => {
|
|
47
|
+
const payload = {
|
|
48
|
+
connectType: index_js_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
49
|
+
connectReason: index_js_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
50
|
+
userAgent: getUserAgent(config)
|
|
51
|
+
};
|
|
52
|
+
payload.webInfo = getWebInfo(config);
|
|
53
|
+
return payload;
|
|
54
|
+
};
|
|
55
|
+
const generateLoginNode = (userJid, config, creds) => {
|
|
56
|
+
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
57
|
+
const effectiveDevice = config.masqueradeAsPrimary ? 0 : device;
|
|
58
|
+
const payload = {
|
|
59
|
+
...getClientPayload(config),
|
|
60
|
+
passive: !config.masqueradeAsPrimary,
|
|
61
|
+
pull: !config.masqueradeAsPrimary,
|
|
62
|
+
username: +user,
|
|
63
|
+
device: effectiveDevice,
|
|
64
|
+
lidDbMigrated: false
|
|
65
|
+
};
|
|
66
|
+
if (creds?.interopData?.accountId) {
|
|
67
|
+
payload.interopData = {
|
|
68
|
+
accountId: creds.interopData.accountId,
|
|
69
|
+
token: creds.interopData.token,
|
|
70
|
+
enableReadReceipts: creds.interopData.enableReadReceipts ?? true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return index_js_1.proto.ClientPayload.fromObject(payload);
|
|
74
|
+
};
|
|
75
|
+
exports.generateLoginNode = generateLoginNode;
|
|
76
|
+
const getPlatformType = platform => {
|
|
77
|
+
const platformType = platform.toUpperCase();
|
|
78
|
+
return index_js_1.proto.DeviceProps.PlatformType[platformType] || index_js_1.proto.DeviceProps.PlatformType.CHROME;
|
|
79
|
+
};
|
|
80
|
+
const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
81
|
+
const appVersionBuf = Buffer.from(Crypto_1.md5(Buffer.from(config.version.join('.'))));
|
|
82
|
+
const companion = {
|
|
83
|
+
os: config.browser[0],
|
|
84
|
+
platformType: getPlatformType(config.browser[1]),
|
|
85
|
+
requireFullSync: config.syncFullHistory,
|
|
86
|
+
historySyncConfig: {
|
|
87
|
+
storageQuotaMb: 10240,
|
|
88
|
+
inlineInitialPayloadInE2EeMsg: true,
|
|
89
|
+
recentSyncDaysLimit: undefined,
|
|
90
|
+
supportCallLogHistory: false,
|
|
91
|
+
supportBotUserAgentChatHistory: true,
|
|
92
|
+
supportCagReactionsAndPolls: true,
|
|
93
|
+
supportBizHostedMsg: true,
|
|
94
|
+
supportRecentSyncChunkMessageCountTuning: true,
|
|
95
|
+
supportHostedGroupMsg: true,
|
|
96
|
+
supportFbidBotChatHistory: true,
|
|
97
|
+
supportAddOnHistorySyncMigration: undefined,
|
|
98
|
+
supportMessageAssociation: true,
|
|
99
|
+
supportGroupHistory: false,
|
|
100
|
+
onDemandReady: undefined,
|
|
101
|
+
supportGuestChat: undefined
|
|
102
|
+
},
|
|
103
|
+
version: {
|
|
104
|
+
primary: 10,
|
|
105
|
+
secondary: 15,
|
|
106
|
+
tertiary: 7
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const companionProto = index_js_1.proto.DeviceProps.encode(companion).finish();
|
|
110
|
+
const registerPayload = {
|
|
111
|
+
...getClientPayload(config),
|
|
112
|
+
passive: false,
|
|
113
|
+
pull: false,
|
|
114
|
+
devicePairingData: {
|
|
115
|
+
buildHash: appVersionBuf,
|
|
116
|
+
deviceProps: companionProto,
|
|
117
|
+
eRegid: (0, generics_1.encodeBigEndian)(registrationId),
|
|
118
|
+
eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
|
|
119
|
+
eIdent: signedIdentityKey.public,
|
|
120
|
+
eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
|
|
121
|
+
eSkeyVal: signedPreKey.keyPair.public,
|
|
122
|
+
eSkeySig: signedPreKey.signature
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
return index_js_1.proto.ClientPayload.fromObject(registerPayload);
|
|
126
|
+
};
|
|
127
|
+
exports.generateRegistrationNode = generateRegistrationNode;
|
|
128
|
+
const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
129
|
+
const msgId = stanza.attrs.id;
|
|
130
|
+
const pairSuccessNode = (0, WABinary_1.getBinaryNodeChild)(stanza, 'pair-success');
|
|
131
|
+
const deviceIdentityNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device-identity');
|
|
132
|
+
const platformNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'platform');
|
|
133
|
+
const deviceNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'device');
|
|
134
|
+
const businessNode = (0, WABinary_1.getBinaryNodeChild)(pairSuccessNode, 'biz');
|
|
135
|
+
if (!deviceIdentityNode || !deviceNode) {
|
|
136
|
+
throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza });
|
|
137
|
+
}
|
|
138
|
+
const bizName = businessNode?.attrs.name;
|
|
139
|
+
const jid = deviceNode.attrs.jid;
|
|
140
|
+
const lid = deviceNode.attrs.lid;
|
|
141
|
+
const { details, hmac, accountType } = index_js_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content);
|
|
142
|
+
let hmacPrefix = Buffer.from([]);
|
|
143
|
+
if (accountType !== undefined && accountType === index_js_1.proto.ADVEncryptionType.HOSTED) {
|
|
144
|
+
hmacPrefix = Defaults_1.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX;
|
|
145
|
+
}
|
|
146
|
+
const advSign = (0, crypto_2.hmacSign)(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'));
|
|
147
|
+
if (Buffer.compare(hmac, advSign) !== 0) {
|
|
148
|
+
throw new boom_1.Boom('Invalid account signature');
|
|
149
|
+
}
|
|
150
|
+
const account = index_js_1.proto.ADVSignedDeviceIdentity.decode(details);
|
|
151
|
+
const { accountSignatureKey, accountSignature, details: deviceDetails } = account;
|
|
152
|
+
const deviceIdentity = index_js_1.proto.ADVDeviceIdentity.decode(deviceDetails);
|
|
153
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === index_js_1.proto.ADVEncryptionType.HOSTED
|
|
154
|
+
? Defaults_1.WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
155
|
+
: Defaults_1.WA_ADV_ACCOUNT_SIG_PREFIX;
|
|
156
|
+
const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]);
|
|
157
|
+
if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
|
|
158
|
+
throw new boom_1.Boom('Failed to verify account signature');
|
|
159
|
+
}
|
|
160
|
+
const deviceMsg = Buffer.concat([
|
|
161
|
+
Defaults_1.WA_ADV_DEVICE_SIG_PREFIX,
|
|
162
|
+
deviceDetails,
|
|
163
|
+
signedIdentityKey.public,
|
|
164
|
+
accountSignatureKey
|
|
165
|
+
]);
|
|
166
|
+
account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg);
|
|
167
|
+
const identity = (0, signal_1.createSignalIdentity)(lid, accountSignatureKey);
|
|
168
|
+
const accountEnc = (0, exports.encodeSignedDeviceIdentity)(account, false);
|
|
169
|
+
const reply = {
|
|
170
|
+
tag: 'iq',
|
|
171
|
+
attrs: {
|
|
172
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
173
|
+
type: 'result',
|
|
174
|
+
id: msgId
|
|
175
|
+
},
|
|
176
|
+
content: [
|
|
177
|
+
{
|
|
178
|
+
tag: 'pair-device-sign',
|
|
179
|
+
attrs: {},
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
tag: 'device-identity',
|
|
183
|
+
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
184
|
+
content: accountEnc
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
};
|
|
190
|
+
const authUpdate = {
|
|
191
|
+
account,
|
|
192
|
+
me: { id: jid, name: bizName, lid },
|
|
193
|
+
signalIdentities: [...(signalIdentities || []), identity],
|
|
194
|
+
platform: platformNode?.attrs.name
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
creds: authUpdate,
|
|
198
|
+
reply
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
exports.configureSuccessfulPairing = configureSuccessfulPairing;
|
|
202
|
+
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
203
|
+
account = { ...account };
|
|
204
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
|
|
205
|
+
account.accountSignatureKey = null;
|
|
206
|
+
}
|
|
207
|
+
return index_js_1.proto.ADVSignedDeviceIdentity.encode(account).finish();
|
|
208
|
+
};
|
|
209
|
+
exports.encodeSignedDeviceIdentity = encodeSignedDeviceIdentity;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface AutoCacheViewOnceOptions {
|
|
2
|
+
cacheDir?: string;
|
|
3
|
+
logger?: any;
|
|
4
|
+
onCached?: (info: {
|
|
5
|
+
id: string;
|
|
6
|
+
jid: string;
|
|
7
|
+
filePath: string;
|
|
8
|
+
type: string;
|
|
9
|
+
}) => void;
|
|
10
|
+
}
|
|
11
|
+
export function getViewOnceContent(message: any): Record<string, any> | null;
|
|
12
|
+
export function autoCacheViewOnceMedia(sock: any, options?: AutoCacheViewOnceOptions): () => void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.autoCacheViewOnceMedia = void 0;
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const Messages_1 = require('./messages');
|
|
7
|
+
const MessagesMedia_1 = require('./messages-media');
|
|
8
|
+
const VIEW_ONCE_WRAPPER_KEYS = ['viewOnceMessage', 'viewOnceMessageV2', 'viewOnceMessageV2Extension'];
|
|
9
|
+
const VIEW_ONCE_INNER_KEYS = ['imageMessage', 'videoMessage', 'audioMessage'];
|
|
10
|
+
const getViewOnceContent = message => {
|
|
11
|
+
if (!message)
|
|
12
|
+
return null;
|
|
13
|
+
const content = (0, Messages_1.extractMessageContent)(message);
|
|
14
|
+
if (!content)
|
|
15
|
+
return null;
|
|
16
|
+
for (const wrapperKey of VIEW_ONCE_WRAPPER_KEYS) {
|
|
17
|
+
const wrapper = content[wrapperKey];
|
|
18
|
+
if (wrapper?.message) {
|
|
19
|
+
const inner = (0, Messages_1.extractMessageContent)(wrapper.message);
|
|
20
|
+
if (inner)
|
|
21
|
+
return inner;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
for (const key of VIEW_ONCE_INNER_KEYS) {
|
|
25
|
+
if (content[key]?.viewOnce) {
|
|
26
|
+
return { [key]: content[key] };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
const autoCacheViewOnceMedia = (sock, options = {}) => {
|
|
32
|
+
const cacheDir = options.cacheDir || './viewonce-cache';
|
|
33
|
+
const logger = options.logger || sock.logger;
|
|
34
|
+
if (!fs.existsSync(cacheDir)) {
|
|
35
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
36
|
+
}
|
|
37
|
+
const handler = async ({ messages, type }) => {
|
|
38
|
+
if (type !== 'notify' && type !== 'append')
|
|
39
|
+
return;
|
|
40
|
+
for (const msg of messages) {
|
|
41
|
+
try {
|
|
42
|
+
const viewOnceContent = getViewOnceContent(msg.message);
|
|
43
|
+
if (!viewOnceContent)
|
|
44
|
+
continue;
|
|
45
|
+
const mediaType = Object.keys(viewOnceContent)[0];
|
|
46
|
+
const buffer = await (0, Messages_1.downloadMediaMessage)(msg, 'buffer', {}, { logger, reuploadRequest: sock.updateMediaMessage });
|
|
47
|
+
const extension = (0, MessagesMedia_1.extensionForMediaMessage)(viewOnceContent) || 'bin';
|
|
48
|
+
const fileName = `${msg.key.id}.${extension}`;
|
|
49
|
+
const filePath = path.join(cacheDir, fileName);
|
|
50
|
+
fs.writeFileSync(filePath, buffer);
|
|
51
|
+
logger?.debug?.({ id: msg.key.id, filePath, mediaType }, 'cached view-once media');
|
|
52
|
+
options.onCached?.({ id: msg.key.id, jid: msg.key.remoteJid, filePath, type: mediaType });
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
logger?.warn?.({ error, id: msg.key?.id }, 'failed to cache view-once media');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
sock.ev.on('messages.upsert', handler);
|
|
60
|
+
return () => sock.ev.off('messages.upsert', handler);
|
|
61
|
+
};
|
|
62
|
+
exports.autoCacheViewOnceMedia = autoCacheViewOnceMedia;
|
|
63
|
+
exports.getViewOnceContent = getViewOnceContent;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.decodeE2eRekeyPayload = void 0;
|
|
4
|
+
const index_js_1 = require('../../WAProto/index.js');
|
|
5
|
+
const REKEY_TYPE_NAMES = {
|
|
6
|
+
[index_js_1.proto.RekeyKeyType.REKEY_KEY_AUDIO]: 'REKEY_KEY_AUDIO',
|
|
7
|
+
[index_js_1.proto.RekeyKeyType.REKEY_KEY_VIDEO]: 'REKEY_KEY_VIDEO',
|
|
8
|
+
[index_js_1.proto.RekeyKeyType.REKEY_KEY_APPDATA]: 'REKEY_KEY_APPDATA'
|
|
9
|
+
};
|
|
10
|
+
const decodeE2eRekeyPayload = buffer => {
|
|
11
|
+
if (!Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array)) {
|
|
12
|
+
throw new TypeError('decodeE2eRekeyPayload: buffer must be Buffer or Uint8Array');
|
|
13
|
+
}
|
|
14
|
+
const decoded = index_js_1.proto.E2eRekeyPayload.decode(buffer);
|
|
15
|
+
return {
|
|
16
|
+
keys: (decoded.keys || []).map(entry => ({
|
|
17
|
+
type: REKEY_TYPE_NAMES[entry.type] ?? entry.type,
|
|
18
|
+
key: entry.key ? Buffer.from(entry.key) : Buffer.alloc(0)
|
|
19
|
+
}))
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.decodeE2eRekeyPayload = decodeE2eRekeyPayload;
|