@badzz88/baileys 8.5.6 → 8.5.8
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 +337 -1055
- package/WAProto/WAProto.proto +28 -1189
- package/WAProto/fix-imports.js +79 -69
- package/WAProto/index.d.ts +71491 -15254
- package/WAProto/index.js +126436 -19814
- package/engine-requirements.js +8 -15
- package/lib/Defaults/index.js +130 -0
- package/{src → lib}/Signal/Group/ciphertext-message.js +2 -5
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/{src → lib}/Signal/Group/group_cipher.js +11 -11
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/{src → lib}/Signal/Group/sender-chain-key.js +6 -9
- package/{src → lib}/Signal/Group/sender-key-distribution-message.js +6 -9
- package/{src → lib}/Signal/Group/sender-key-message.js +9 -12
- package/{src → lib}/Signal/Group/sender-key-name.js +2 -5
- package/{src → lib}/Signal/Group/sender-key-record.js +8 -11
- package/{src → lib}/Signal/Group/sender-key-state.js +6 -9
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/{src → lib}/Signal/libsignal.js +131 -155
- package/{src → lib}/Signal/lid-mapping.js +27 -23
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/{src → lib}/Socket/Client/websocket.js +11 -18
- package/{src → lib}/Socket/business.js +35 -67
- package/{src → lib}/Socket/chats.js +294 -550
- package/{src → lib}/Socket/communities.js +82 -114
- package/lib/Socket/graphql.js +716 -0
- package/lib/Socket/groups.js +374 -0
- package/lib/Socket/index.js +18 -0
- package/lib/Socket/interop.js +463 -0
- package/{src → lib}/Socket/luxu.js +120 -82
- package/lib/Socket/messages-recv.js +1916 -0
- package/lib/Socket/messages-send.js +1436 -0
- package/lib/Socket/mex.js +54 -0
- package/lib/Socket/newsletter.js +757 -0
- package/lib/Socket/privacy.js +318 -0
- package/{src → lib}/Socket/socket.js +356 -244
- package/lib/Socket/username.js +236 -0
- package/lib/Store/index.js +10 -0
- package/{src → lib}/Store/keyed-db.js +11 -21
- package/lib/Store/make-cache-manager-store.js +85 -0
- package/lib/Store/make-in-memory-store.js +244 -0
- package/{src → lib}/Store/make-ordered-dictionary.js +19 -25
- package/{src → lib}/Store/object-repository.js +11 -5
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Mex.js +111 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +26 -0
- package/{src → lib}/Utils/auth-utils.js +91 -43
- package/lib/Utils/browser-utils.js +48 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.js +872 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/crypto.js +118 -0
- package/lib/Utils/decode-wa-message.js +350 -0
- package/{src → lib}/Utils/event-buffer.js +81 -39
- package/lib/Utils/generics.js +403 -0
- package/lib/Utils/history.js +134 -0
- package/{src → lib}/Utils/identity-change-handler.js +9 -11
- package/lib/Utils/index.js +23 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +8 -0
- package/{src → lib}/Utils/make-mutex.js +7 -10
- package/lib/Utils/message-composer.js +273 -0
- package/{src → lib}/Utils/message-retry-manager.js +76 -28
- package/lib/Utils/messages-media.js +870 -0
- package/lib/Utils/messages.js +1337 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/{src → lib}/Utils/offline-node-processor.js +10 -4
- package/{src → lib}/Utils/pre-key-manager.js +27 -11
- package/lib/Utils/process-message.js +630 -0
- package/{src → lib}/Utils/reporting-utils.js +12 -15
- package/lib/Utils/signal.js +201 -0
- package/{src → lib}/Utils/stanza-ack.js +12 -4
- package/lib/Utils/sticker.js +110 -0
- package/{src → lib}/Utils/sync-action-utils.js +14 -10
- package/{src → lib}/Utils/tc-token-utils.js +48 -43
- package/{src → lib}/Utils/use-multi-file-auth-state.js +35 -25
- package/lib/Utils/validate-connection.js +203 -0
- package/{src → lib}/WABinary/constants.js +9 -12
- package/{src → lib}/WABinary/decode.js +38 -118
- package/{src → lib}/WABinary/encode.js +6 -11
- package/lib/WABinary/generic-utils.js +204 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +98 -0
- package/lib/WABinary/types.js +2 -0
- package/{src → lib}/WAM/BinaryInfo.js +2 -5
- package/{src → lib}/WAM/constants.js +4 -16635
- package/{src → lib}/WAM/encode.js +18 -17
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +58 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
- package/lib/WAUSync/Protocols/index.js +12 -0
- package/lib/WAUSync/USyncQuery.js +151 -0
- package/lib/WAUSync/USyncUser.js +56 -0
- package/lib/WAUSync/index.js +3 -0
- package/{src → lib}/index.js +16 -51
- package/package.json +129 -99
- package/LICENSE +0 -21
- package/src/Defaults/index.js +0 -186
- package/src/Defaults/phonenumber-mcc.json +0 -223
- package/src/Signal/Group/group-session-builder.js +0 -86
- package/src/Signal/Group/index.js +0 -140
- package/src/Signal/Group/keyhelper.js +0 -77
- package/src/Signal/Group/sender-message-key.js +0 -29
- package/src/Socket/Client/index.js +0 -31
- package/src/Socket/Client/types.js +0 -13
- package/src/Socket/aigroups.js +0 -221
- package/src/Socket/graphql.js +0 -523
- package/src/Socket/groups.js +0 -516
- package/src/Socket/index.js +0 -31
- package/src/Socket/interactive-handler.js +0 -527
- package/src/Socket/interop.js +0 -339
- package/src/Socket/managed-account.js +0 -98
- package/src/Socket/messages-recv.js +0 -2685
- package/src/Socket/messages-send.js +0 -2047
- package/src/Socket/mex.js +0 -57
- package/src/Socket/newsletter.js +0 -455
- package/src/Socket/privacy.js +0 -125
- package/src/Socket/registration.js +0 -236
- package/src/Socket/text-router.js +0 -65
- package/src/Socket/username.js +0 -130
- package/src/Store/index.js +0 -33
- package/src/Store/make-cache-manager-store.js +0 -84
- package/src/Store/make-in-memory-store.js +0 -551
- package/src/Types/Auth.js +0 -31
- package/src/Types/Bussines.js +0 -2
- package/src/Types/Call.js +0 -2
- package/src/Types/Chat.js +0 -4
- package/src/Types/Contact.js +0 -2
- package/src/Types/Events.js +0 -2
- package/src/Types/GroupMetadata.js +0 -2
- package/src/Types/Label.js +0 -26
- package/src/Types/LabelAssociation.js +0 -8
- package/src/Types/Message.js +0 -93
- package/src/Types/Mex.js +0 -112
- package/src/Types/Newsletter.js +0 -109
- package/src/Types/Product.js +0 -2
- package/src/Types/Signal.js +0 -2
- package/src/Types/Socket.js +0 -2
- package/src/Types/State.js +0 -62
- package/src/Types/USync.js +0 -2
- package/src/Types/index.js +0 -56
- package/src/Utils/browser-utils.js +0 -112
- package/src/Utils/business.js +0 -240
- package/src/Utils/chat-utils.js +0 -1230
- package/src/Utils/command-loader.d.ts +0 -27
- package/src/Utils/command-loader.js +0 -89
- package/src/Utils/companion-reg-client-utils.js +0 -40
- package/src/Utils/consumer-application.js +0 -105
- package/src/Utils/crypto.js +0 -118
- package/src/Utils/curve25519-js.js +0 -242
- package/src/Utils/decode-wa-message.js +0 -529
- package/src/Utils/generics.js +0 -483
- package/src/Utils/group-history.js +0 -44
- package/src/Utils/history.js +0 -232
- package/src/Utils/index.js +0 -58
- package/src/Utils/jid-display-normalization.js +0 -195
- package/src/Utils/link-preview.js +0 -135
- package/src/Utils/logger.js +0 -8
- package/src/Utils/lt-hash.js +0 -25
- package/src/Utils/message-composer.js +0 -471
- package/src/Utils/messages-media.js +0 -843
- package/src/Utils/messages.js +0 -2817
- package/src/Utils/meta-ai-msmsg.js +0 -222
- package/src/Utils/native-bridge.js +0 -68
- package/src/Utils/noise-handler.js +0 -169
- package/src/Utils/process-message.js +0 -950
- package/src/Utils/session-pool.d.ts +0 -14
- package/src/Utils/session-pool.js +0 -70
- package/src/Utils/signal.js +0 -217
- package/src/Utils/sticker.d.ts +0 -13
- package/src/Utils/sticker.js +0 -123
- package/src/Utils/validate-connection.js +0 -209
- package/src/Utils/view-once-cache.d.ts +0 -12
- package/src/Utils/view-once-cache.js +0 -63
- package/src/Utils/voip-rekey.js +0 -22
- package/src/WABinary/generic-utils.js +0 -238
- package/src/WABinary/index.js +0 -34
- package/src/WABinary/jid-utils.js +0 -351
- package/src/WABinary/types.js +0 -2
- package/src/WAM/index.js +0 -32
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +0 -44
- package/src/WAUSync/Protocols/USyncContactProtocol.js +0 -55
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +0 -55
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -31
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +0 -54
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +0 -32
- package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -473
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +0 -34
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
- package/src/WAUSync/Protocols/index.js +0 -40
- package/src/WAUSync/USyncQuery.js +0 -126
- package/src/WAUSync/USyncUser.js +0 -50
- package/src/WAUSync/index.js +0 -32
- package/src/antiban.js +0 -4152
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export interface SessionPoolOptions {
|
|
2
|
-
makeSocket: (sessionId: string) => Promise<any> | any;
|
|
3
|
-
logger?: any;
|
|
4
|
-
maxBackoffMs?: number;
|
|
5
|
-
onSessionUpdate?: (sessionId: string, sock: any) => void;
|
|
6
|
-
onLoggedOut?: (sessionId: string) => void;
|
|
7
|
-
}
|
|
8
|
-
export interface SessionPool {
|
|
9
|
-
add: (sessionId: string) => Promise<void>;
|
|
10
|
-
remove: (sessionId: string) => void;
|
|
11
|
-
get: (sessionId: string) => any;
|
|
12
|
-
list: () => string[];
|
|
13
|
-
}
|
|
14
|
-
export function createSessionPool(options: SessionPoolOptions): SessionPool;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.createSessionPool = void 0;
|
|
4
|
-
const DISCONNECT_REASON_LOGGED_OUT = 401;
|
|
5
|
-
const createSessionPool = options => {
|
|
6
|
-
const logger = options.logger;
|
|
7
|
-
const maxBackoffMs = options.maxBackoffMs ?? 60000;
|
|
8
|
-
const sessions = new Map();
|
|
9
|
-
const computeBackoffMs = attempts => {
|
|
10
|
-
const base = Math.min(1000 * 2 ** attempts, maxBackoffMs);
|
|
11
|
-
return base + Math.floor(Math.random() * (base * 0.2));
|
|
12
|
-
};
|
|
13
|
-
const start = async (sessionId) => {
|
|
14
|
-
const entry = sessions.get(sessionId) || { attempts: 0, stopped: false };
|
|
15
|
-
sessions.set(sessionId, entry);
|
|
16
|
-
if (entry.stopped)
|
|
17
|
-
return;
|
|
18
|
-
try {
|
|
19
|
-
const sock = await options.makeSocket(sessionId);
|
|
20
|
-
entry.sock = sock;
|
|
21
|
-
options.onSessionUpdate?.(sessionId, sock);
|
|
22
|
-
sock.ev.on('connection.update', update => {
|
|
23
|
-
if (update.connection === 'open') {
|
|
24
|
-
entry.attempts = 0;
|
|
25
|
-
}
|
|
26
|
-
if (update.connection === 'close') {
|
|
27
|
-
const statusCode = update.lastDisconnect?.error?.output?.statusCode;
|
|
28
|
-
if (statusCode === DISCONNECT_REASON_LOGGED_OUT) {
|
|
29
|
-
logger?.info?.({ sessionId }, 'session logged out, removing from pool');
|
|
30
|
-
sessions.delete(sessionId);
|
|
31
|
-
options.onLoggedOut?.(sessionId);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (entry.stopped)
|
|
35
|
-
return;
|
|
36
|
-
entry.attempts += 1;
|
|
37
|
-
const backoffMs = computeBackoffMs(entry.attempts);
|
|
38
|
-
logger?.warn?.({ sessionId, attempt: entry.attempts, backoffMs }, 'session disconnected, reconnecting with backoff');
|
|
39
|
-
setTimeout(() => start(sessionId), backoffMs);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
entry.attempts += 1;
|
|
45
|
-
const backoffMs = computeBackoffMs(entry.attempts);
|
|
46
|
-
logger?.error?.({ error, sessionId, backoffMs }, 'failed to start session, retrying with backoff');
|
|
47
|
-
if (!entry.stopped) {
|
|
48
|
-
setTimeout(() => start(sessionId), backoffMs);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const add = sessionId => start(sessionId);
|
|
53
|
-
const remove = sessionId => {
|
|
54
|
-
const entry = sessions.get(sessionId);
|
|
55
|
-
if (!entry)
|
|
56
|
-
return;
|
|
57
|
-
entry.stopped = true;
|
|
58
|
-
if (entry.sock?.end) {
|
|
59
|
-
try {
|
|
60
|
-
entry.sock.end(undefined);
|
|
61
|
-
}
|
|
62
|
-
catch { }
|
|
63
|
-
}
|
|
64
|
-
sessions.delete(sessionId);
|
|
65
|
-
};
|
|
66
|
-
const get = sessionId => sessions.get(sessionId)?.sock;
|
|
67
|
-
const list = () => [...sessions.keys()];
|
|
68
|
-
return { add, remove, get, list };
|
|
69
|
-
};
|
|
70
|
-
exports.createSessionPool = createSessionPool;
|
package/src/Utils/signal.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.getNextPreKeysNode =
|
|
4
|
-
exports.getNextPreKeys =
|
|
5
|
-
exports.extractDeviceJids =
|
|
6
|
-
exports.parseAndInjectE2ESessions =
|
|
7
|
-
exports.extractE2ESessionFromRetryReceipt =
|
|
8
|
-
exports.xmppPreKey =
|
|
9
|
-
exports.xmppSignedPreKey =
|
|
10
|
-
exports.generateOrGetPreKeys =
|
|
11
|
-
exports.getPreKeys =
|
|
12
|
-
exports.createSignalIdentity =
|
|
13
|
-
void 0;
|
|
14
|
-
const Defaults_1 = require('../Defaults');
|
|
15
|
-
const WABinary_1 = require('../WABinary');
|
|
16
|
-
const crypto_1 = require('./crypto');
|
|
17
|
-
const generics_1 = require('./generics');
|
|
18
|
-
function chunk(array, size) {
|
|
19
|
-
const chunks = [];
|
|
20
|
-
for (let i = 0; i < array.length; i += size) {
|
|
21
|
-
chunks.push(array.slice(i, i + size));
|
|
22
|
-
}
|
|
23
|
-
return chunks;
|
|
24
|
-
}
|
|
25
|
-
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
26
|
-
return {
|
|
27
|
-
identifier: { name: wid, deviceId: 0 },
|
|
28
|
-
identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
exports.createSignalIdentity = createSignalIdentity;
|
|
32
|
-
const getPreKeys = async ({ get }, min, limit) => {
|
|
33
|
-
const idList = [];
|
|
34
|
-
for (let id = min; id < limit; id++) {
|
|
35
|
-
idList.push(id.toString());
|
|
36
|
-
}
|
|
37
|
-
return get('pre-key', idList);
|
|
38
|
-
};
|
|
39
|
-
exports.getPreKeys = getPreKeys;
|
|
40
|
-
const generateOrGetPreKeys = (creds, range) => {
|
|
41
|
-
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
42
|
-
const remaining = range - avaliable;
|
|
43
|
-
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
44
|
-
const newPreKeys = {};
|
|
45
|
-
if (remaining > 0) {
|
|
46
|
-
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
47
|
-
newPreKeys[i] = crypto_1.Curve.generateKeyPair();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
newPreKeys,
|
|
52
|
-
lastPreKeyId,
|
|
53
|
-
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
exports.generateOrGetPreKeys = generateOrGetPreKeys;
|
|
57
|
-
const xmppSignedPreKey = key => ({
|
|
58
|
-
tag: 'skey',
|
|
59
|
-
attrs: {},
|
|
60
|
-
content: [
|
|
61
|
-
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
|
|
62
|
-
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
63
|
-
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
64
|
-
]
|
|
65
|
-
});
|
|
66
|
-
exports.xmppSignedPreKey = xmppSignedPreKey;
|
|
67
|
-
const xmppPreKey = (pair, id) => ({
|
|
68
|
-
tag: 'key',
|
|
69
|
-
attrs: {},
|
|
70
|
-
content: [
|
|
71
|
-
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
|
|
72
|
-
{ tag: 'value', attrs: {}, content: pair.public }
|
|
73
|
-
]
|
|
74
|
-
});
|
|
75
|
-
exports.xmppPreKey = xmppPreKey;
|
|
76
|
-
const isValidUInt = n => typeof n === 'number' && Number.isInteger(n);
|
|
77
|
-
const extractE2ESessionFromRetryReceipt = receipt => {
|
|
78
|
-
const keysNode = (0, WABinary_1.getBinaryNodeChild)(receipt, 'keys');
|
|
79
|
-
if (!keysNode)
|
|
80
|
-
return null;
|
|
81
|
-
const typeBuf = (0, WABinary_1.getBinaryNodeChildBuffer)(keysNode, 'type');
|
|
82
|
-
if (!typeBuf || typeBuf.length !== 1 || typeBuf[0] !== Defaults_1.KEY_BUNDLE_TYPE[0])
|
|
83
|
-
return null;
|
|
84
|
-
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(keysNode, 'identity');
|
|
85
|
-
const skey = (0, WABinary_1.getBinaryNodeChild)(keysNode, 'skey');
|
|
86
|
-
if (!identity || identity.length !== 32 || !skey)
|
|
87
|
-
return null;
|
|
88
|
-
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(receipt, 'registration', 4);
|
|
89
|
-
if (!isValidUInt(registrationId))
|
|
90
|
-
return null;
|
|
91
|
-
const signedPubKey = (0, WABinary_1.getBinaryNodeChildBuffer)(skey, 'value');
|
|
92
|
-
const signedSig = (0, WABinary_1.getBinaryNodeChildBuffer)(skey, 'signature');
|
|
93
|
-
const signedKeyId = (0, WABinary_1.getBinaryNodeChildUInt)(skey, 'id', 3);
|
|
94
|
-
if (!signedPubKey || signedPubKey.length !== 32 || !signedSig || !isValidUInt(signedKeyId)) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
const preKeyNode = (0, WABinary_1.getBinaryNodeChild)(keysNode, 'key');
|
|
98
|
-
let preKey;
|
|
99
|
-
if (preKeyNode) {
|
|
100
|
-
const preKeyPub = (0, WABinary_1.getBinaryNodeChildBuffer)(preKeyNode, 'value');
|
|
101
|
-
const preKeyId = (0, WABinary_1.getBinaryNodeChildUInt)(preKeyNode, 'id', 3);
|
|
102
|
-
if (!preKeyPub || preKeyPub.length !== 32 || !isValidUInt(preKeyId)) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
preKey = { keyId: preKeyId, publicKey: (0, crypto_1.generateSignalPubKey)(preKeyPub) };
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
registrationId,
|
|
109
|
-
identityKey: (0, crypto_1.generateSignalPubKey)(identity),
|
|
110
|
-
signedPreKey: {
|
|
111
|
-
keyId: signedKeyId,
|
|
112
|
-
publicKey: (0, crypto_1.generateSignalPubKey)(signedPubKey),
|
|
113
|
-
signature: signedSig
|
|
114
|
-
},
|
|
115
|
-
preKey
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
exports.extractE2ESessionFromRetryReceipt = extractE2ESessionFromRetryReceipt;
|
|
119
|
-
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
120
|
-
const extractKey = key => key
|
|
121
|
-
? {
|
|
122
|
-
keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
|
|
123
|
-
publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
|
|
124
|
-
signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature')
|
|
125
|
-
}
|
|
126
|
-
: undefined;
|
|
127
|
-
const nodes = (0, WABinary_1.getBinaryNodeChildren)((0, WABinary_1.getBinaryNodeChild)(node, 'list'), 'user');
|
|
128
|
-
for (const node of nodes) {
|
|
129
|
-
;
|
|
130
|
-
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
131
|
-
}
|
|
132
|
-
const chunkSize = 100;
|
|
133
|
-
const chunks = chunk(nodes, chunkSize);
|
|
134
|
-
for (const nodesChunk of chunks) {
|
|
135
|
-
for (const node of nodesChunk) {
|
|
136
|
-
const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
|
|
137
|
-
const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
|
|
138
|
-
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
|
|
139
|
-
const jid = node.attrs.jid;
|
|
140
|
-
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
|
|
141
|
-
await repository.injectE2ESession({
|
|
142
|
-
jid,
|
|
143
|
-
session: {
|
|
144
|
-
registrationId: registrationId,
|
|
145
|
-
identityKey: (0, crypto_1.generateSignalPubKey)(identity),
|
|
146
|
-
signedPreKey: extractKey(signedKey),
|
|
147
|
-
preKey: extractKey(key)
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
154
|
-
const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
|
|
155
|
-
const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
|
|
156
|
-
const extracted = [];
|
|
157
|
-
for (const userResult of result) {
|
|
158
|
-
const { devices, id } = userResult;
|
|
159
|
-
const decoded = (0, WABinary_1.jidDecode)(id), { user, server } = decoded;
|
|
160
|
-
let { domainType } = decoded;
|
|
161
|
-
const deviceList = devices?.deviceList;
|
|
162
|
-
if (!Array.isArray(deviceList))
|
|
163
|
-
continue;
|
|
164
|
-
for (const { id: device, keyIndex, isHosted } of deviceList) {
|
|
165
|
-
if ((!excludeZeroDevices || device !== 0) &&
|
|
166
|
-
((myUser !== user && myLid !== user) || myDevice !== device) &&
|
|
167
|
-
(device === 0 || !!keyIndex)) {
|
|
168
|
-
if (isHosted) {
|
|
169
|
-
domainType =
|
|
170
|
-
domainType === WABinary_1.WAJIDDomains.LID
|
|
171
|
-
? WABinary_1.WAJIDDomains.HOSTED_LID
|
|
172
|
-
: WABinary_1.WAJIDDomains.HOSTED;
|
|
173
|
-
}
|
|
174
|
-
extracted.push({
|
|
175
|
-
user,
|
|
176
|
-
device,
|
|
177
|
-
domainType,
|
|
178
|
-
server: (0, WABinary_1.getServerFromDomainType)(server, domainType)
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return extracted;
|
|
184
|
-
};
|
|
185
|
-
exports.extractDeviceJids = extractDeviceJids;
|
|
186
|
-
const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
187
|
-
const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
|
|
188
|
-
const update = {
|
|
189
|
-
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
190
|
-
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
191
|
-
};
|
|
192
|
-
await keys.set({ 'pre-key': newPreKeys });
|
|
193
|
-
const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
194
|
-
return { update, preKeys };
|
|
195
|
-
};
|
|
196
|
-
exports.getNextPreKeys = getNextPreKeys;
|
|
197
|
-
const getNextPreKeysNode = async (state, count) => {
|
|
198
|
-
const { creds } = state;
|
|
199
|
-
const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
|
|
200
|
-
const node = {
|
|
201
|
-
tag: 'iq',
|
|
202
|
-
attrs: {
|
|
203
|
-
xmlns: 'encrypt',
|
|
204
|
-
type: 'set',
|
|
205
|
-
to: WABinary_1.S_WHATSAPP_NET
|
|
206
|
-
},
|
|
207
|
-
content: [
|
|
208
|
-
{ tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
|
|
209
|
-
{ tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
|
|
210
|
-
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
211
|
-
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
|
|
212
|
-
(0, exports.xmppSignedPreKey)(creds.signedPreKey)
|
|
213
|
-
]
|
|
214
|
-
};
|
|
215
|
-
return { update, node };
|
|
216
|
-
};
|
|
217
|
-
exports.getNextPreKeysNode = getNextPreKeysNode;
|
package/src/Utils/sticker.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface StickerMetaOptions {
|
|
2
|
-
packName?: string;
|
|
3
|
-
packPublisher?: string;
|
|
4
|
-
categories?: string[];
|
|
5
|
-
}
|
|
6
|
-
export function addExifToWebp(webpBuffer: Buffer, options?: StickerMetaOptions): Promise<Buffer>;
|
|
7
|
-
export function imageToWebpSticker(imageBuffer: Buffer, options?: StickerMetaOptions & {
|
|
8
|
-
quality?: number;
|
|
9
|
-
}): Promise<Buffer>;
|
|
10
|
-
export function videoToWebpSticker(videoBuffer: Buffer, options?: StickerMetaOptions & {
|
|
11
|
-
fps?: number;
|
|
12
|
-
seconds?: number;
|
|
13
|
-
}): Promise<Buffer>;
|
package/src/Utils/sticker.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
-
exports.imageToWebpSticker = exports.videoToWebpSticker = exports.addExifToWebp = void 0;
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const crypto = require('crypto');
|
|
8
|
-
const { exec } = require('child_process');
|
|
9
|
-
const addExifToWebp = async (webpBuffer, { packName = '', packPublisher = '', categories = [] } = {}) => {
|
|
10
|
-
const json = {
|
|
11
|
-
'sticker-pack-id': crypto.randomBytes(16).toString('hex'),
|
|
12
|
-
'sticker-pack-name': packName,
|
|
13
|
-
'sticker-pack-publisher': packPublisher,
|
|
14
|
-
emojis: categories.length ? categories : ['😀']
|
|
15
|
-
};
|
|
16
|
-
const jsonBuffer = Buffer.from(JSON.stringify(json), 'utf-8');
|
|
17
|
-
const exifAttr = Buffer.from([
|
|
18
|
-
0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16,
|
|
19
|
-
0x00, 0x00, 0x00
|
|
20
|
-
]);
|
|
21
|
-
exifAttr.writeUIntLE(jsonBuffer.length, 14, 4);
|
|
22
|
-
const exifPayload = Buffer.concat([exifAttr, jsonBuffer]);
|
|
23
|
-
const pad = buf => (buf.length % 2 === 1 ? Buffer.concat([buf, Buffer.from([0x00])]) : buf);
|
|
24
|
-
const makeChunk = (tag, data) => {
|
|
25
|
-
const sizeField = Buffer.alloc(4);
|
|
26
|
-
sizeField.writeUInt32LE(data.length, 0);
|
|
27
|
-
return Buffer.concat([Buffer.from(tag, 'ascii'), sizeField, pad(data)]);
|
|
28
|
-
};
|
|
29
|
-
const exifChunk = makeChunk('EXIF', exifPayload);
|
|
30
|
-
if (webpBuffer.slice(0, 4).toString('ascii') !== 'RIFF' || webpBuffer.slice(8, 12).toString('ascii') !== 'WEBP') {
|
|
31
|
-
throw new Error('addExifToWebp expects a valid WebP buffer');
|
|
32
|
-
}
|
|
33
|
-
let offset = 12;
|
|
34
|
-
let vp8xChunk = null;
|
|
35
|
-
let vp8xOffset = -1;
|
|
36
|
-
const otherChunks = [];
|
|
37
|
-
while (offset < webpBuffer.length) {
|
|
38
|
-
const tag = webpBuffer.slice(offset, offset + 4).toString('ascii');
|
|
39
|
-
const size = webpBuffer.readUInt32LE(offset + 4);
|
|
40
|
-
const dataStart = offset + 8;
|
|
41
|
-
const dataEnd = dataStart + size;
|
|
42
|
-
const chunkTotal = 8 + size + (size % 2);
|
|
43
|
-
if (tag === 'VP8X') {
|
|
44
|
-
vp8xChunk = webpBuffer.slice(offset, offset + chunkTotal);
|
|
45
|
-
vp8xOffset = offset;
|
|
46
|
-
}
|
|
47
|
-
else if (tag !== 'EXIF') {
|
|
48
|
-
otherChunks.push(webpBuffer.slice(offset, offset + chunkTotal));
|
|
49
|
-
}
|
|
50
|
-
offset += chunkTotal;
|
|
51
|
-
}
|
|
52
|
-
let flags;
|
|
53
|
-
let canvasWidth;
|
|
54
|
-
let canvasHeight;
|
|
55
|
-
if (vp8xChunk) {
|
|
56
|
-
flags = vp8xChunk.readUInt8(8);
|
|
57
|
-
canvasWidth = vp8xChunk.readUIntLE(12, 3) + 1;
|
|
58
|
-
canvasHeight = vp8xChunk.readUIntLE(15, 3) + 1;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
flags = 0;
|
|
62
|
-
let sharp;
|
|
63
|
-
try {
|
|
64
|
-
sharp = require('sharp');
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
throw new Error('addExifToWebp needs the optional "sharp" dependency to read image dimensions');
|
|
68
|
-
}
|
|
69
|
-
const meta = await sharp(webpBuffer).metadata();
|
|
70
|
-
canvasWidth = meta.width;
|
|
71
|
-
canvasHeight = meta.height;
|
|
72
|
-
}
|
|
73
|
-
flags |= 0x08;
|
|
74
|
-
const vp8xData = Buffer.alloc(10);
|
|
75
|
-
vp8xData.writeUInt8(flags, 0);
|
|
76
|
-
vp8xData.writeUIntLE(canvasWidth - 1, 4, 3);
|
|
77
|
-
vp8xData.writeUIntLE(canvasHeight - 1, 7, 3);
|
|
78
|
-
const newVp8xChunk = makeChunk('VP8X', vp8xData);
|
|
79
|
-
const body = Buffer.concat([newVp8xChunk, ...otherChunks, exifChunk]);
|
|
80
|
-
const fileSize = Buffer.alloc(4);
|
|
81
|
-
fileSize.writeUInt32LE(4 + body.length, 0);
|
|
82
|
-
return Buffer.concat([Buffer.from('RIFF', 'ascii'), fileSize, Buffer.from('WEBP', 'ascii'), body]);
|
|
83
|
-
};
|
|
84
|
-
exports.addExifToWebp = addExifToWebp;
|
|
85
|
-
const imageToWebpSticker = async (imageBuffer, options = {}) => {
|
|
86
|
-
let sharp;
|
|
87
|
-
try {
|
|
88
|
-
sharp = require('sharp');
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
throw new Error('imageToWebpSticker requires the optional "sharp" dependency to be installed');
|
|
92
|
-
}
|
|
93
|
-
const webp = await sharp(imageBuffer)
|
|
94
|
-
.resize(512, 512, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } })
|
|
95
|
-
.webp({ quality: options.quality ?? 80 })
|
|
96
|
-
.toBuffer();
|
|
97
|
-
return addExifToWebp(webp, options);
|
|
98
|
-
};
|
|
99
|
-
exports.imageToWebpSticker = imageToWebpSticker;
|
|
100
|
-
const videoToWebpSticker = async (videoBuffer, options = {}) => {
|
|
101
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'xazbails-sticker-'));
|
|
102
|
-
const inputPath = path.join(tmpDir, 'input.mp4');
|
|
103
|
-
const outputPath = path.join(tmpDir, 'output.webp');
|
|
104
|
-
fs.writeFileSync(inputPath, videoBuffer);
|
|
105
|
-
const fps = options.fps ?? 10;
|
|
106
|
-
const seconds = options.seconds ?? 5;
|
|
107
|
-
const cmd = `ffmpeg -y -i ${inputPath} -t ${seconds} -vf ` +
|
|
108
|
-
`"fps=${fps},scale=512:512:force_original_aspect_ratio=decrease,` +
|
|
109
|
-
`pad=512:512:(ow-iw)/2:(oh-ih)/2:color=0x00000000,split[a][b];` +
|
|
110
|
-
`[a]palettegen=reserve_transparent=1[p];[b][p]paletteuse" ` +
|
|
111
|
-
`-loop 0 -preset default -an -vsync 0 ${outputPath}`;
|
|
112
|
-
try {
|
|
113
|
-
await new Promise((resolve, reject) => {
|
|
114
|
-
exec(cmd, err => (err ? reject(err) : resolve()));
|
|
115
|
-
});
|
|
116
|
-
const webp = fs.readFileSync(outputPath);
|
|
117
|
-
return await addExifToWebp(webp, options);
|
|
118
|
-
}
|
|
119
|
-
finally {
|
|
120
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
exports.videoToWebpSticker = videoToWebpSticker;
|
|
@@ -1,209 +0,0 @@
|
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
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;
|