@vanzxy/baileys 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +111 -0
- package/README.md +830 -0
- package/WAProto/index.d.ts +9 -0
- package/WAProto/index.js +142036 -0
- package/engine-requirements.js +13 -0
- package/lib/Defaults/index.d.ts +152 -0
- package/lib/Defaults/index.js +179 -0
- package/lib/Framework/Bot.js +209 -0
- package/lib/Framework/Context.js +90 -0
- package/lib/Framework/MediaManager.js +152 -0
- package/lib/Framework/SessionManager.js +34 -0
- package/lib/Framework/StatsManager.js +120 -0
- package/lib/Framework/Store/SQLiteStore.js +74 -0
- package/lib/Framework/index.js +11 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.d.ts +10 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.d.ts +54 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.d.ts +5 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +380 -0
- package/lib/Socket/chats.d.ts +136 -0
- package/lib/Socket/chats.js +1328 -0
- package/lib/Socket/communities.d.ts +561 -0
- package/lib/Socket/communities.js +434 -0
- package/lib/Socket/dugong.d.ts +117 -0
- package/lib/Socket/dugong.js +799 -0
- package/lib/Socket/groups.d.ts +285 -0
- package/lib/Socket/groups.js +355 -0
- package/lib/Socket/index.d.ts +531 -0
- package/lib/Socket/index.js +34 -0
- package/lib/Socket/messages-recv.d.ts +333 -0
- package/lib/Socket/messages-recv.js +1782 -0
- package/lib/Socket/messages-send.d.ts +329 -0
- package/lib/Socket/messages-send.js +1383 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.d.ts +281 -0
- package/lib/Socket/newsletter.js +321 -0
- package/lib/Socket/socket.d.ts +60 -0
- package/lib/Socket/socket.js +1001 -0
- package/lib/Socket/username.js +153 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-in-memory-store.d.ts +62 -0
- package/lib/Store/make-in-memory-store.js +429 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +24 -0
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.d.ts +11 -0
- package/lib/Types/Message.js +18 -0
- package/lib/Types/Mex.d.ts +2 -0
- package/lib/Types/Mex.js +39 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/RichType.d.ts +2 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +5 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/A2UI.js +277 -0
- package/lib/Utils/MessageBuilder.js +4405 -0
- package/lib/Utils/MessageBuilder_d.ts +411 -0
- package/lib/Utils/PersistentStore.js +592 -0
- package/lib/Utils/PersistentStore_d.ts +60 -0
- package/lib/Utils/anti-delete.d.ts +74 -0
- package/lib/Utils/anti-delete.js +222 -0
- package/lib/Utils/auth-utils.d.ts +57 -0
- package/lib/Utils/auth-utils.js +307 -0
- package/lib/Utils/auto-reply.d.ts +47 -0
- package/lib/Utils/auto-reply.js +158 -0
- package/lib/Utils/baileys-event-stream.d.ts +8 -0
- package/lib/Utils/baileys-event-stream.js +62 -0
- package/lib/Utils/browser-utils.d.ts +8 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +240 -0
- package/lib/Utils/button-helper-utils.js +314 -0
- package/lib/Utils/button-sender.js +824 -0
- package/lib/Utils/chat-control.d.ts +159 -0
- package/lib/Utils/chat-control.js +232 -0
- package/lib/Utils/chat-history-helpers.d.ts +21 -0
- package/lib/Utils/chat-history-helpers.js +71 -0
- package/lib/Utils/chat-utils.d.ts +407 -0
- package/lib/Utils/chat-utils.js +886 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/companion-reg-client-utils.js +40 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +148 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +317 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +636 -0
- package/lib/Utils/generics.d.ts +69 -0
- package/lib/Utils/generics.js +439 -0
- package/lib/Utils/history.d.ts +90 -0
- package/lib/Utils/history.js +147 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.d.ts +39 -0
- package/lib/Utils/index.js +46 -0
- package/lib/Utils/link-preview.d.ts +12 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +27 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/media-messages.d.ts +18 -0
- package/lib/Utils/media-messages.js +71 -0
- package/lib/Utils/media-set.d.ts +13 -0
- package/lib/Utils/media-set.js +172 -0
- package/lib/Utils/message-kind.js +139 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/message-search.d.ts +44 -0
- package/lib/Utils/message-search.js +189 -0
- package/lib/Utils/messages-media.d.ts +135 -0
- package/lib/Utils/messages-media.js +869 -0
- package/lib/Utils/messages.d.ts +44 -0
- package/lib/Utils/messages.js +2155 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/offline-node-processor.d.ts +9 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/past-participants.d.ts +14 -0
- package/lib/Utils/past-participants.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +25 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.d.ts +82 -0
- package/lib/Utils/process-message.js +809 -0
- package/lib/Utils/reporting-utils.d.ts +12 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +445 -0
- package/lib/Utils/scheduling.d.ts +42 -0
- package/lib/Utils/scheduling.js +140 -0
- package/lib/Utils/signal.d.ts +82 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/stanza-ack.d.ts +16 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/status.d.ts +50 -0
- package/lib/Utils/status.js +108 -0
- package/lib/Utils/stickerpack.d.ts +51 -0
- package/lib/Utils/stickerpack.js +275 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/templates.d.ts +76 -0
- package/lib/Utils/templates.js +151 -0
- package/lib/Utils/use-cache-manager-auth-state.d.ts +13 -0
- package/lib/Utils/use-cache-manager-auth-state.js +82 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-multi-file-auth-state.js +167 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-single-file-auth-state.js +114 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +170 -0
- package/lib/Utils/validate-connection.d.ts +42 -0
- package/lib/Utils/validate-connection.js +199 -0
- package/lib/Utils/vcard.d.ts +58 -0
- package/lib/Utils/vcard.js +105 -0
- package/lib/VoIP/audio-feeder.d.ts +15 -0
- package/lib/VoIP/audio-feeder.js +132 -0
- package/lib/VoIP/index.js +277 -0
- package/lib/VoIP/relay-transport.d.ts +43 -0
- package/lib/VoIP/relay-transport.js +559 -0
- package/lib/VoIP/signaling.js +624 -0
- package/lib/VoIP/types.d.ts +69 -0
- package/lib/VoIP/types.js +17 -0
- package/lib/VoIP/wasm-engine.d.ts +103 -0
- package/lib/VoIP/wasm-engine.js +1214 -0
- package/lib/VoIP/worker-bootstrap.js +1042 -0
- package/lib/WABinary/constants.d.ts +61 -0
- package/lib/WABinary/constants.js +1467 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/generic-utils.d.ts +74 -0
- package/lib/WABinary/generic-utils.js +277 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +63 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.d.ts +7 -0
- package/lib/WAUSync/Protocols/index.js +8 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +122 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/assets/wasm/loader.js +5 -0
- package/lib/assets/wasm/whatsapp.wasm +0 -0
- package/lib/assets/wasm/worker-modules.js +273 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +20 -0
- package/package.json +175 -0
- package/postinstall-banner.js +56 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function makeNoiseHandler({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
|
|
2
|
+
keyPair: {
|
|
3
|
+
private: any;
|
|
4
|
+
public: any;
|
|
5
|
+
};
|
|
6
|
+
NOISE_HEADER: any;
|
|
7
|
+
logger: any;
|
|
8
|
+
routingInfo: any;
|
|
9
|
+
}): {
|
|
10
|
+
encrypt: (plaintext: any) => any;
|
|
11
|
+
decrypt: (ciphertext: any) => any;
|
|
12
|
+
authenticate: (data: any) => void;
|
|
13
|
+
mixIntoKey: (data: any) => void;
|
|
14
|
+
finishInit: () => Promise<void>;
|
|
15
|
+
processHandshake: ({ serverHello }: {
|
|
16
|
+
serverHello: any;
|
|
17
|
+
}, noiseKey: any) => any;
|
|
18
|
+
encodeFrame: (data: any) => any;
|
|
19
|
+
decodeFrame: (newData: any, onFrame: any) => Promise<void>;
|
|
20
|
+
};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
import { NOISE_MODE, WA_CERT_DETAILS } from '../Defaults/index.js';
|
|
4
|
+
import { decodeBinaryNode } from '../WABinary/index.js';
|
|
5
|
+
import { aesDecryptGCM, aesEncryptGCM, Curve, hkdf, sha256 } from './crypto.js';
|
|
6
|
+
const IV_LENGTH = 12;
|
|
7
|
+
const EMPTY_BUFFER = Buffer.alloc(0);
|
|
8
|
+
const generateIV = (counter) => {
|
|
9
|
+
const iv = new ArrayBuffer(IV_LENGTH);
|
|
10
|
+
new DataView(iv).setUint32(8, counter);
|
|
11
|
+
return new Uint8Array(iv);
|
|
12
|
+
};
|
|
13
|
+
class TransportState {
|
|
14
|
+
constructor(encKey, decKey) {
|
|
15
|
+
this.encKey = encKey;
|
|
16
|
+
this.decKey = decKey;
|
|
17
|
+
this.readCounter = 0;
|
|
18
|
+
this.writeCounter = 0;
|
|
19
|
+
this.iv = new Uint8Array(IV_LENGTH);
|
|
20
|
+
}
|
|
21
|
+
encrypt(plaintext) {
|
|
22
|
+
const c = this.writeCounter++;
|
|
23
|
+
this.iv[8] = (c >>> 24) & 0xff;
|
|
24
|
+
this.iv[9] = (c >>> 16) & 0xff;
|
|
25
|
+
this.iv[10] = (c >>> 8) & 0xff;
|
|
26
|
+
this.iv[11] = c & 0xff;
|
|
27
|
+
return aesEncryptGCM(plaintext, this.encKey, this.iv, EMPTY_BUFFER);
|
|
28
|
+
}
|
|
29
|
+
decrypt(ciphertext) {
|
|
30
|
+
const c = this.readCounter++;
|
|
31
|
+
this.iv[8] = (c >>> 24) & 0xff;
|
|
32
|
+
this.iv[9] = (c >>> 16) & 0xff;
|
|
33
|
+
this.iv[10] = (c >>> 8) & 0xff;
|
|
34
|
+
this.iv[11] = c & 0xff;
|
|
35
|
+
return aesDecryptGCM(ciphertext, this.decKey, this.iv, EMPTY_BUFFER);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
|
|
39
|
+
logger = logger.child({ class: 'ns' });
|
|
40
|
+
const data = Buffer.from(NOISE_MODE);
|
|
41
|
+
let hash = data.byteLength === 32 ? data : sha256(data);
|
|
42
|
+
let salt = hash;
|
|
43
|
+
let encKey = hash;
|
|
44
|
+
let decKey = hash;
|
|
45
|
+
let counter = 0;
|
|
46
|
+
let sentIntro = false;
|
|
47
|
+
let inBytes = Buffer.alloc(0);
|
|
48
|
+
let transport = null;
|
|
49
|
+
let isWaitingForTransport = false;
|
|
50
|
+
let pendingOnFrame = null;
|
|
51
|
+
let introHeader;
|
|
52
|
+
if (routingInfo) {
|
|
53
|
+
introHeader = Buffer.alloc(7 + routingInfo.byteLength + NOISE_HEADER.length);
|
|
54
|
+
introHeader.write('ED', 0, 'utf8');
|
|
55
|
+
introHeader.writeUint8(0, 2);
|
|
56
|
+
introHeader.writeUint8(1, 3);
|
|
57
|
+
introHeader.writeUint8(routingInfo.byteLength >> 16, 4);
|
|
58
|
+
introHeader.writeUint16BE(routingInfo.byteLength & 65535, 5);
|
|
59
|
+
introHeader.set(routingInfo, 7);
|
|
60
|
+
introHeader.set(NOISE_HEADER, 7 + routingInfo.byteLength);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
introHeader = Buffer.from(NOISE_HEADER);
|
|
64
|
+
}
|
|
65
|
+
const authenticate = (data) => {
|
|
66
|
+
if (!transport) {
|
|
67
|
+
hash = sha256(Buffer.concat([hash, data]));
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const encrypt = (plaintext) => {
|
|
71
|
+
if (transport) {
|
|
72
|
+
return transport.encrypt(plaintext);
|
|
73
|
+
}
|
|
74
|
+
const result = aesEncryptGCM(plaintext, encKey, generateIV(counter++), hash);
|
|
75
|
+
authenticate(result);
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
78
|
+
const decrypt = (ciphertext) => {
|
|
79
|
+
if (transport) {
|
|
80
|
+
return transport.decrypt(ciphertext);
|
|
81
|
+
}
|
|
82
|
+
const result = aesDecryptGCM(ciphertext, decKey, generateIV(counter++), hash);
|
|
83
|
+
authenticate(ciphertext);
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
const localHKDF = (data) => {
|
|
87
|
+
const key = hkdf(Buffer.from(data), 64, { salt, info: '' });
|
|
88
|
+
return [key.subarray(0, 32), key.subarray(32)];
|
|
89
|
+
};
|
|
90
|
+
const mixIntoKey = (data) => {
|
|
91
|
+
const [write, read] = localHKDF(data);
|
|
92
|
+
salt = write;
|
|
93
|
+
encKey = read;
|
|
94
|
+
decKey = read;
|
|
95
|
+
counter = 0;
|
|
96
|
+
};
|
|
97
|
+
const finishInit = async () => {
|
|
98
|
+
isWaitingForTransport = true;
|
|
99
|
+
const [write, read] = localHKDF(new Uint8Array(0));
|
|
100
|
+
transport = new TransportState(write, read);
|
|
101
|
+
isWaitingForTransport = false;
|
|
102
|
+
logger.trace('Noise handler transitioned to Transport state');
|
|
103
|
+
if (pendingOnFrame) {
|
|
104
|
+
logger.trace({ length: inBytes.length }, 'Flushing buffered frames after transport ready');
|
|
105
|
+
await processData(pendingOnFrame);
|
|
106
|
+
pendingOnFrame = null;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const processData = async (onFrame) => {
|
|
110
|
+
let size;
|
|
111
|
+
while (true) {
|
|
112
|
+
if (inBytes.length < 3)
|
|
113
|
+
return;
|
|
114
|
+
size = (inBytes[0] << 16) | (inBytes[1] << 8) | inBytes[2];
|
|
115
|
+
if (inBytes.length < size + 3)
|
|
116
|
+
return;
|
|
117
|
+
let frame = inBytes.subarray(3, size + 3);
|
|
118
|
+
inBytes = inBytes.subarray(size + 3);
|
|
119
|
+
if (transport) {
|
|
120
|
+
const result = transport.decrypt(frame);
|
|
121
|
+
frame = await decodeBinaryNode(result);
|
|
122
|
+
}
|
|
123
|
+
if (logger.level === 'trace') {
|
|
124
|
+
logger.trace({ msg: frame?.attrs?.id }, 'recv frame');
|
|
125
|
+
}
|
|
126
|
+
onFrame(frame);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
authenticate(NOISE_HEADER);
|
|
130
|
+
authenticate(publicKey);
|
|
131
|
+
return {
|
|
132
|
+
encrypt,
|
|
133
|
+
decrypt,
|
|
134
|
+
authenticate,
|
|
135
|
+
mixIntoKey,
|
|
136
|
+
finishInit,
|
|
137
|
+
processHandshake: ({ serverHello }, noiseKey) => {
|
|
138
|
+
authenticate(serverHello.ephemeral);
|
|
139
|
+
mixIntoKey(Curve.sharedKey(privateKey, serverHello.ephemeral));
|
|
140
|
+
const decStaticContent = decrypt(serverHello.static);
|
|
141
|
+
mixIntoKey(Curve.sharedKey(privateKey, decStaticContent));
|
|
142
|
+
const certDecoded = decrypt(serverHello.payload);
|
|
143
|
+
const { intermediate: certIntermediate, leaf } = proto.CertChain.decode(certDecoded);
|
|
144
|
+
// leaf
|
|
145
|
+
if (!leaf?.details || !leaf?.signature) {
|
|
146
|
+
throw new Boom('invalid noise leaf certificate', { statusCode: 400 });
|
|
147
|
+
}
|
|
148
|
+
if (!certIntermediate?.details || !certIntermediate?.signature) {
|
|
149
|
+
throw new Boom('invalid noise intermediate certificate', { statusCode: 400 });
|
|
150
|
+
}
|
|
151
|
+
const details = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
|
|
152
|
+
const { issuerSerial } = details;
|
|
153
|
+
const verify = Curve.verify(details.key, leaf.details, leaf.signature);
|
|
154
|
+
const verifyIntermediate = Curve.verify(WA_CERT_DETAILS.PUBLIC_KEY, certIntermediate.details, certIntermediate.signature);
|
|
155
|
+
if (!verify) {
|
|
156
|
+
throw new Boom('noise certificate signature invalid', { statusCode: 400 });
|
|
157
|
+
}
|
|
158
|
+
if (!verifyIntermediate) {
|
|
159
|
+
throw new Boom('noise intermediate certificate signature invalid', { statusCode: 400 });
|
|
160
|
+
}
|
|
161
|
+
if (issuerSerial !== WA_CERT_DETAILS.SERIAL) {
|
|
162
|
+
throw new Boom('certification match failed', { statusCode: 400 });
|
|
163
|
+
}
|
|
164
|
+
const keyEnc = encrypt(noiseKey.public);
|
|
165
|
+
mixIntoKey(Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
|
|
166
|
+
return keyEnc;
|
|
167
|
+
},
|
|
168
|
+
encodeFrame: (data) => {
|
|
169
|
+
if (transport) {
|
|
170
|
+
data = transport.encrypt(data);
|
|
171
|
+
}
|
|
172
|
+
const dataLen = data.byteLength;
|
|
173
|
+
const introSize = sentIntro ? 0 : introHeader.length;
|
|
174
|
+
const frame = Buffer.allocUnsafe(introSize + 3 + dataLen);
|
|
175
|
+
if (!sentIntro) {
|
|
176
|
+
frame.set(introHeader);
|
|
177
|
+
sentIntro = true;
|
|
178
|
+
}
|
|
179
|
+
frame[introSize] = (dataLen >>> 16) & 0xff;
|
|
180
|
+
frame[introSize + 1] = (dataLen >>> 8) & 0xff;
|
|
181
|
+
frame[introSize + 2] = dataLen & 0xff;
|
|
182
|
+
frame.set(data, introSize + 3);
|
|
183
|
+
return frame;
|
|
184
|
+
},
|
|
185
|
+
decodeFrame: async (newData, onFrame) => {
|
|
186
|
+
if (isWaitingForTransport) {
|
|
187
|
+
inBytes = Buffer.concat([inBytes, newData]);
|
|
188
|
+
pendingOnFrame = onFrame;
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (inBytes.length === 0) {
|
|
192
|
+
inBytes = Buffer.from(newData);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
inBytes = Buffer.concat([inBytes, newData]);
|
|
196
|
+
}
|
|
197
|
+
await processData(onFrame);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=noise-handler.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a processor for offline stanza nodes that:
|
|
3
|
+
* - Queues nodes for sequential processing
|
|
4
|
+
* - Yields to the event loop periodically to avoid blocking
|
|
5
|
+
* - Catches handler errors to prevent the processing loop from crashing
|
|
6
|
+
*/
|
|
7
|
+
export function makeOfflineNodeProcessor(nodeProcessorMap: any, deps: any, batchSize?: number): {
|
|
8
|
+
enqueue: (type: any, node: any) => void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a processor for offline stanza nodes that:
|
|
3
|
+
* - Queues nodes for sequential processing
|
|
4
|
+
* - Yields to the event loop periodically to avoid blocking
|
|
5
|
+
* - Catches handler errors to prevent the processing loop from crashing
|
|
6
|
+
*/
|
|
7
|
+
export function makeOfflineNodeProcessor(nodeProcessorMap, deps, batchSize = 10) {
|
|
8
|
+
const nodes = [];
|
|
9
|
+
let isProcessing = false;
|
|
10
|
+
const enqueue = (type, node) => {
|
|
11
|
+
nodes.push({ type, node });
|
|
12
|
+
if (isProcessing) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
isProcessing = true;
|
|
16
|
+
const promise = async () => {
|
|
17
|
+
let processedInBatch = 0;
|
|
18
|
+
while (nodes.length && deps.isWsOpen()) {
|
|
19
|
+
const { type, node } = nodes.shift();
|
|
20
|
+
const nodeProcessor = nodeProcessorMap.get(type);
|
|
21
|
+
if (!nodeProcessor) {
|
|
22
|
+
deps.onUnexpectedError(new Error(`unknown offline node type: ${type}`), 'processing offline node');
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
await nodeProcessor(node).catch(err => deps.onUnexpectedError(err, `processing offline ${type}`));
|
|
26
|
+
processedInBatch++;
|
|
27
|
+
// Yield to event loop after processing a batch
|
|
28
|
+
// This prevents blocking the event loop for too long when there are many offline nodes
|
|
29
|
+
if (processedInBatch >= batchSize) {
|
|
30
|
+
processedInBatch = 0;
|
|
31
|
+
await deps.yieldToEventLoop();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
isProcessing = false;
|
|
35
|
+
};
|
|
36
|
+
promise().catch(error => deps.onUnexpectedError(error, 'processing offline nodes'));
|
|
37
|
+
};
|
|
38
|
+
return { enqueue };
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=offline-node-processor.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { proto } from '../../WAProto/index.js';
|
|
2
|
+
export interface ProcessedPastParticipant {
|
|
3
|
+
jid: string;
|
|
4
|
+
leaveTs?: number;
|
|
5
|
+
leaveReason?: 'left' | 'removed';
|
|
6
|
+
}
|
|
7
|
+
export interface ProcessedPastParticipants {
|
|
8
|
+
groupJid: string;
|
|
9
|
+
participants: ProcessedPastParticipant[];
|
|
10
|
+
}
|
|
11
|
+
/** Process proto.IPastParticipants[] from a history sync payload into a structured list per group. */
|
|
12
|
+
export declare const processPastParticipants: (pastParticipantsList: proto.IPastParticipants[]) => ProcessedPastParticipants[];
|
|
13
|
+
/** Check if a history sync event contains past participants data. */
|
|
14
|
+
export declare const hasPastParticipants: (event: { pastParticipants?: unknown[] }) => boolean;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Ported from @queenanya/baileys `addons/past-participants.ts`.
|
|
2
|
+
// No logic changes — @vanzxy/baileys's own WAProto already has the
|
|
3
|
+
// `proto.PastParticipant.LeaveReason` enum and `HistorySync.pastParticipants`
|
|
4
|
+
// field this depends on (confirmed present), so this ports as-is.
|
|
5
|
+
//
|
|
6
|
+
// This reads WhatsApp's own server-provided participant-leave history from
|
|
7
|
+
// a history-sync payload (`proto.IPastParticipants[]`) — it's real protocol
|
|
8
|
+
// data, not something reconstructed by listening to live events, so it
|
|
9
|
+
// includes participants who left/were removed *before* this session ever
|
|
10
|
+
// connected (which a live `group-participants.update` listener can never
|
|
11
|
+
// see).
|
|
12
|
+
import { proto } from '../../WAProto/index.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Process proto.IPastParticipants[] from a history sync payload.
|
|
16
|
+
* Returns a structured list per group.
|
|
17
|
+
*/
|
|
18
|
+
export const processPastParticipants = (pastParticipantsList) => {
|
|
19
|
+
return pastParticipantsList.map((pp) => {
|
|
20
|
+
const groupJid = pp.groupJid ?? '';
|
|
21
|
+
const participants = (pp.pastParticipants ?? []).map((p) => ({
|
|
22
|
+
jid: p.userJid ?? '',
|
|
23
|
+
leaveTs: p.leaveTs ? Number(p.leaveTs) : undefined,
|
|
24
|
+
leaveReason: p.leaveReason === proto.PastParticipant.LeaveReason.LEFT
|
|
25
|
+
? 'left'
|
|
26
|
+
: p.leaveReason === proto.PastParticipant.LeaveReason.REMOVED
|
|
27
|
+
? 'removed'
|
|
28
|
+
: undefined
|
|
29
|
+
}));
|
|
30
|
+
return { groupJid, participants };
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Check if a history sync event contains past participants data.
|
|
36
|
+
* (pastParticipants field replaces chunkOrder in this patch)
|
|
37
|
+
*/
|
|
38
|
+
export const hasPastParticipants = (event) => {
|
|
39
|
+
return Array.isArray(event.pastParticipants) && event.pastParticipants.length > 0;
|
|
40
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages pre-key operations with proper concurrency control
|
|
3
|
+
*/
|
|
4
|
+
export class PreKeyManager {
|
|
5
|
+
constructor(store: any, logger: any);
|
|
6
|
+
store: any;
|
|
7
|
+
logger: any;
|
|
8
|
+
queues: Map<any, any>;
|
|
9
|
+
/**
|
|
10
|
+
* Get or create a queue for a specific key type
|
|
11
|
+
*/
|
|
12
|
+
getQueue(keyType: any): any;
|
|
13
|
+
/**
|
|
14
|
+
* Process pre-key operations (updates and deletions)
|
|
15
|
+
*/
|
|
16
|
+
processOperations(data: any, keyType: any, transactionCache: any, mutations: any, isInTransaction: any): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* Process deletions with validation
|
|
19
|
+
*/
|
|
20
|
+
processDeletions(keyType: any, ids: any, transactionCache: any, mutations: any, isInTransaction: any): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Validate and process pre-key deletions outside transactions
|
|
23
|
+
*/
|
|
24
|
+
validateDeletions(data: any, keyType: any): Promise<any>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import PQueue from 'p-queue';
|
|
2
|
+
/**
|
|
3
|
+
* Manages pre-key operations with proper concurrency control
|
|
4
|
+
*/
|
|
5
|
+
export class PreKeyManager {
|
|
6
|
+
constructor(store, logger) {
|
|
7
|
+
this.store = store;
|
|
8
|
+
this.logger = logger;
|
|
9
|
+
this.queues = new Map();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get or create a queue for a specific key type
|
|
13
|
+
*/
|
|
14
|
+
getQueue(keyType) {
|
|
15
|
+
if (!this.queues.has(keyType)) {
|
|
16
|
+
this.queues.set(keyType, new PQueue({ concurrency: 1 }));
|
|
17
|
+
}
|
|
18
|
+
return this.queues.get(keyType);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Process pre-key operations (updates and deletions)
|
|
22
|
+
*/
|
|
23
|
+
async processOperations(data, keyType, transactionCache, mutations, isInTransaction) {
|
|
24
|
+
const keyData = data[keyType];
|
|
25
|
+
if (!keyData)
|
|
26
|
+
return;
|
|
27
|
+
return this.getQueue(keyType).add(async () => {
|
|
28
|
+
// Ensure structures exist
|
|
29
|
+
transactionCache[keyType] = transactionCache[keyType] || {};
|
|
30
|
+
mutations[keyType] = mutations[keyType] || {};
|
|
31
|
+
// Separate deletions from updates
|
|
32
|
+
const deletions = [];
|
|
33
|
+
const updates = {};
|
|
34
|
+
for (const keyId in keyData) {
|
|
35
|
+
if (keyData[keyId] === null) {
|
|
36
|
+
deletions.push(keyId);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
updates[keyId] = keyData[keyId];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Process updates (no validation needed)
|
|
43
|
+
if (Object.keys(updates).length > 0) {
|
|
44
|
+
Object.assign(transactionCache[keyType], updates);
|
|
45
|
+
Object.assign(mutations[keyType], updates);
|
|
46
|
+
}
|
|
47
|
+
// Process deletions with validation
|
|
48
|
+
if (deletions.length > 0) {
|
|
49
|
+
await this.processDeletions(keyType, deletions, transactionCache, mutations, isInTransaction);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Process deletions with validation
|
|
55
|
+
*/
|
|
56
|
+
async processDeletions(keyType, ids, transactionCache, mutations, isInTransaction) {
|
|
57
|
+
if (isInTransaction) {
|
|
58
|
+
// In transaction, only allow deletion if key exists in cache
|
|
59
|
+
for (const keyId of ids) {
|
|
60
|
+
if (transactionCache[keyType]?.[keyId]) {
|
|
61
|
+
transactionCache[keyType][keyId] = null;
|
|
62
|
+
mutations[keyType][keyId] = null;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.logger.warn(`Skipping deletion of non-existent ${keyType} in transaction: ${keyId}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Outside transaction, validate against store
|
|
71
|
+
const existingKeys = await this.store.get(keyType, ids);
|
|
72
|
+
for (const keyId of ids) {
|
|
73
|
+
if (existingKeys[keyId]) {
|
|
74
|
+
transactionCache[keyType][keyId] = null;
|
|
75
|
+
mutations[keyType][keyId] = null;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validate and process pre-key deletions outside transactions
|
|
85
|
+
*/
|
|
86
|
+
async validateDeletions(data, keyType) {
|
|
87
|
+
const keyData = data[keyType];
|
|
88
|
+
if (!keyData)
|
|
89
|
+
return;
|
|
90
|
+
return this.getQueue(keyType).add(async () => {
|
|
91
|
+
// Find all deletion requests
|
|
92
|
+
const deletionIds = Object.keys(keyData).filter(id => keyData[id] === null);
|
|
93
|
+
if (deletionIds.length === 0)
|
|
94
|
+
return;
|
|
95
|
+
// Validate deletions
|
|
96
|
+
const existingKeys = await this.store.get(keyType, deletionIds);
|
|
97
|
+
for (const keyId of deletionIds) {
|
|
98
|
+
if (!existingKeys[keyId]) {
|
|
99
|
+
this.logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
|
|
100
|
+
delete data[keyType][keyId];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=pre-key-manager.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decrypt a poll vote
|
|
3
|
+
* @param vote encrypted vote
|
|
4
|
+
* @param ctx additional info about the poll required for decryption
|
|
5
|
+
* @returns list of SHA256 options
|
|
6
|
+
*/
|
|
7
|
+
export function decryptPollVote({ encPayload, encIv }: {
|
|
8
|
+
encPayload: any;
|
|
9
|
+
encIv: any;
|
|
10
|
+
}, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }: {
|
|
11
|
+
pollCreatorJid: any;
|
|
12
|
+
pollMsgId: any;
|
|
13
|
+
pollEncKey: any;
|
|
14
|
+
voterJid: any;
|
|
15
|
+
}): any;
|
|
16
|
+
/**
|
|
17
|
+
* Decrypt an event response
|
|
18
|
+
* @param response encrypted event response
|
|
19
|
+
* @param ctx additional info about the event required for decryption
|
|
20
|
+
* @returns event response message
|
|
21
|
+
*/
|
|
22
|
+
export function decryptEventResponse({ encPayload, encIv }: {
|
|
23
|
+
encPayload: any;
|
|
24
|
+
encIv: any;
|
|
25
|
+
}, { eventCreatorJid, eventMsgId, eventEncKey, responderJid }: {
|
|
26
|
+
eventCreatorJid: any;
|
|
27
|
+
eventMsgId: any;
|
|
28
|
+
eventEncKey: any;
|
|
29
|
+
responderJid: any;
|
|
30
|
+
}): any;
|
|
31
|
+
/**
|
|
32
|
+
* Decrypt a `secretEncryptedMessage` carrying a `MESSAGE_EDIT` payload.
|
|
33
|
+
*
|
|
34
|
+
* WhatsApp started wrapping message edits in an E2EE envelope (May 2026).
|
|
35
|
+
* The new content is encrypted with a key derived from the original
|
|
36
|
+
* message's `messageContextInfo.messageSecret` using HKDF-SHA256
|
|
37
|
+
* + AES-256-GCM, same family as polls and event responses but with
|
|
38
|
+
* different constants (validated against live WhatsApp Android traffic):
|
|
39
|
+
*
|
|
40
|
+
* info = msgId || origSenderJid || editorJid || "Message Edit"
|
|
41
|
+
* aad = (empty) <-- differs from Poll Vote / Event Response
|
|
42
|
+
* key = HKDF-SHA256(salt=zeros, ikm=messageSecret, info, L=32)
|
|
43
|
+
*
|
|
44
|
+
* The decrypted plaintext is a regular `proto.Message` whose
|
|
45
|
+
* `protocolMessage.editedMessage` field holds the new content — same
|
|
46
|
+
* shape as the legacy `protocolMessage.editedMessage` edit path, so
|
|
47
|
+
* consumers can treat the result identically.
|
|
48
|
+
*
|
|
49
|
+
* @param edit encrypted edit payload (encPayload + encIv from SecretEncryptedMessage)
|
|
50
|
+
* @param ctx info about the original message required for decryption
|
|
51
|
+
* @returns decoded outer `Message` whose `protocolMessage.editedMessage`
|
|
52
|
+
* carries the new content (extendedTextMessage / conversation / etc.)
|
|
53
|
+
*/
|
|
54
|
+
export function decryptMessageEdit({ encPayload, encIv }: {
|
|
55
|
+
encPayload: any;
|
|
56
|
+
encIv: any;
|
|
57
|
+
}, { originalSenderJid, originalMsgId, editEncKey, editorJid }: {
|
|
58
|
+
originalSenderJid: any;
|
|
59
|
+
originalMsgId: any;
|
|
60
|
+
editEncKey: any;
|
|
61
|
+
editorJid: any;
|
|
62
|
+
}): any;
|
|
63
|
+
export function cleanMessage(message: any, meId: any, meLid: any): void;
|
|
64
|
+
export function isRealMessage(message: any): boolean;
|
|
65
|
+
export function shouldIncrementChatUnread(message: any): boolean;
|
|
66
|
+
export function getChatId({ remoteJid, participant, fromMe }: {
|
|
67
|
+
remoteJid: any;
|
|
68
|
+
participant: any;
|
|
69
|
+
fromMe: any;
|
|
70
|
+
}): any;
|
|
71
|
+
export default processMessage;
|
|
72
|
+
declare function processMessage(message: any, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options, getMessage }: {
|
|
73
|
+
shouldProcessHistoryMsg: any;
|
|
74
|
+
placeholderResendCache: any;
|
|
75
|
+
ev: any;
|
|
76
|
+
creds: any;
|
|
77
|
+
signalRepository: any;
|
|
78
|
+
keyStore: any;
|
|
79
|
+
logger: any;
|
|
80
|
+
options: any;
|
|
81
|
+
getMessage: any;
|
|
82
|
+
}): Promise<void>;
|