@mrlegendbot/baileys 1.2.5 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +97691 -2
- package/lib/Defaults/index.d.ts +75 -0
- package/lib/Defaults/index.js +92 -89
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -9
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +22 -21
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +69 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +10 -9
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +22 -21
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +60 -51
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +62 -56
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.js +40 -38
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +34 -33
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +76 -72
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -22
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +405 -506
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.js +258 -276
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +7 -6
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +49 -48
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.js +369 -349
- package/lib/Socket/chats.d.ts +125 -0
- package/lib/Socket/chats.js +1148 -1172
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.js +413 -473
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.js +331 -387
- package/lib/Socket/index.d.ts +260 -0
- package/lib/Socket/index.js +8 -6
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.js +1719 -1782
- package/lib/Socket/messages-send.d.ts +200 -0
- package/lib/Socket/messages-send.js +2508 -1384
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +35 -40
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.js +191 -239
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.js +923 -992
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +8 -1
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.js +2 -1
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +22 -20
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +4 -2
- package/lib/Types/Message.d.ts +320 -0
- package/lib/Types/Message.js +5 -3
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.js +31 -26
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.js +2 -1
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.js +3 -2
- package/lib/Types/State.d.ts +97 -0
- package/lib/Types/State.js +52 -4
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +11 -10
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.js +277 -240
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +23 -20
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +204 -200
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.js +810 -836
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.js +25 -23
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +86 -70
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.js +284 -277
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.js +595 -592
- package/lib/Utils/generics.d.ts +92 -0
- package/lib/Utils/generics.js +335 -312
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.js +115 -123
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +2 -1
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +73 -74
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +2 -3
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +6 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +27 -27
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.js +254 -213
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.js +715 -741
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.js +827 -791
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +187 -215
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +98 -69
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +586 -617
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +234 -553
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.js +170 -217
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.js +35 -27
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +41 -37
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.js +141 -120
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +105 -87
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +188 -190
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.js +1294 -28
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +249 -245
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +206 -201
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +89 -86
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +77 -68
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.js +8 -7
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +22853 -19892
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +132 -121
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +43 -46
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -47
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -22
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -30
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +20 -19
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +44 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +30 -0
- package/lib/WAUSync/USyncQuery.js +88 -79
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +29 -28
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +2 -2
- package/package.json +86 -22
- package/README.upstream.md +0 -1312
- package/WAProto/WAProto.json +0 -1
- package/WAProto/WAProto.proto +0 -6275
- package/WAProto/compiler.js +0 -550
- package/lib/Store/index.js +0 -8
- package/lib/Store/keyed-db.js +0 -108
- package/lib/Store/make-cache-manager-store.js +0 -70
- package/lib/Store/make-in-memory-store.js +0 -417
- package/lib/Store/make-ordered-dictionary.js +0 -69
- package/lib/Store/object-repository.js +0 -27
- package/lib/Utils/use-sqlite-auth-state.js +0 -162
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WABrowserDescription } from '../Types/index.js';
|
|
2
|
+
export declare enum CompanionWebClientType {
|
|
3
|
+
UNKNOWN = 0,
|
|
4
|
+
CHROME = 1,
|
|
5
|
+
EDGE = 2,
|
|
6
|
+
FIREFOX = 3,
|
|
7
|
+
IE = 4,
|
|
8
|
+
OPERA = 5,
|
|
9
|
+
SAFARI = 6,
|
|
10
|
+
ELECTRON = 7,
|
|
11
|
+
UWP = 8,
|
|
12
|
+
OTHER_WEB_CLIENT = 9
|
|
13
|
+
}
|
|
14
|
+
export declare const getCompanionWebClientType: ([os, browserName]: WABrowserDescription) => CompanionWebClientType;
|
|
15
|
+
export declare const getCompanionPlatformId: (browser: WABrowserDescription) => string;
|
|
16
|
+
export declare const buildPairingQRData: (ref: string, noiseKeyB64: string, identityKeyB64: string, advB64: string, browser: WABrowserDescription) => string;
|
|
17
|
+
//# sourceMappingURL=companion-reg-client-utils.d.ts.map
|
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
export var CompanionWebClientType;
|
|
2
2
|
(function (CompanionWebClientType) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
CompanionWebClientType[CompanionWebClientType["UNKNOWN"] = 0] = "UNKNOWN";
|
|
4
|
+
CompanionWebClientType[CompanionWebClientType["CHROME"] = 1] = "CHROME";
|
|
5
|
+
CompanionWebClientType[CompanionWebClientType["EDGE"] = 2] = "EDGE";
|
|
6
|
+
CompanionWebClientType[CompanionWebClientType["FIREFOX"] = 3] = "FIREFOX";
|
|
7
|
+
CompanionWebClientType[CompanionWebClientType["IE"] = 4] = "IE";
|
|
8
|
+
CompanionWebClientType[CompanionWebClientType["OPERA"] = 5] = "OPERA";
|
|
9
|
+
CompanionWebClientType[CompanionWebClientType["SAFARI"] = 6] = "SAFARI";
|
|
10
|
+
CompanionWebClientType[CompanionWebClientType["ELECTRON"] = 7] = "ELECTRON";
|
|
11
|
+
CompanionWebClientType[CompanionWebClientType["UWP"] = 8] = "UWP";
|
|
12
|
+
CompanionWebClientType[CompanionWebClientType["OTHER_WEB_CLIENT"] = 9] = "OTHER_WEB_CLIENT";
|
|
13
13
|
})(CompanionWebClientType || (CompanionWebClientType = {}));
|
|
14
14
|
const BROWSER_TO_COMPANION_WEB_CLIENT = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
Chrome: CompanionWebClientType.CHROME,
|
|
16
|
+
Edge: CompanionWebClientType.EDGE,
|
|
17
|
+
Firefox: CompanionWebClientType.FIREFOX,
|
|
18
|
+
IE: CompanionWebClientType.IE,
|
|
19
|
+
Opera: CompanionWebClientType.OPERA,
|
|
20
|
+
Safari: CompanionWebClientType.SAFARI
|
|
21
21
|
};
|
|
22
22
|
export const getCompanionWebClientType = ([os, browserName]) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
if (browserName === 'Desktop') {
|
|
24
|
+
return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON;
|
|
25
|
+
}
|
|
26
|
+
return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT;
|
|
27
27
|
};
|
|
28
|
-
export const getCompanionPlatformId = browser => {
|
|
29
|
-
|
|
28
|
+
export const getCompanionPlatformId = (browser) => {
|
|
29
|
+
return getCompanionWebClientType(browser).toString();
|
|
30
30
|
};
|
|
31
31
|
export const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
|
|
32
|
-
|
|
32
|
+
return ('https://wa.me/settings/linked_devices#' +
|
|
33
|
+
[ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(','));
|
|
33
34
|
};
|
|
35
|
+
//# sourceMappingURL=companion-reg-client-utils.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { KeyPair } from '../Types/index.js';
|
|
2
|
+
export { md5, hkdf } from 'whatsapp-rust-bridge';
|
|
3
|
+
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
4
|
+
export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
|
|
5
|
+
export declare const Curve: {
|
|
6
|
+
generateKeyPair: () => KeyPair;
|
|
7
|
+
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer<ArrayBuffer>;
|
|
8
|
+
sign: (privateKey: Uint8Array, buf: Uint8Array) => Uint8Array<ArrayBufferLike>;
|
|
9
|
+
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) => {
|
|
12
|
+
keyPair: KeyPair;
|
|
13
|
+
signature: Uint8Array<ArrayBufferLike>;
|
|
14
|
+
keyId: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* encrypt AES 256 GCM;
|
|
18
|
+
* where the tag tag is suffixed to the ciphertext
|
|
19
|
+
* */
|
|
20
|
+
export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
|
|
21
|
+
/**
|
|
22
|
+
* decrypt AES 256 GCM;
|
|
23
|
+
* where the auth tag is suffixed to the ciphertext
|
|
24
|
+
* */
|
|
25
|
+
export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer<ArrayBuffer>;
|
|
26
|
+
export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer<ArrayBuffer>;
|
|
27
|
+
export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer<ArrayBuffer>;
|
|
28
|
+
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
29
|
+
export declare function aesDecrypt(buffer: Uint8Array, key: Uint8Array): Buffer<ArrayBuffer>;
|
|
30
|
+
/** decrypt AES 256 CBC */
|
|
31
|
+
export declare function aesDecryptWithIV(buffer: Uint8Array, key: Uint8Array, IV: Uint8Array): Buffer<ArrayBuffer>;
|
|
32
|
+
export declare function aesEncrypt(buffer: Uint8Array, key: Uint8Array): Buffer<ArrayBuffer>;
|
|
33
|
+
export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer<ArrayBuffer>;
|
|
34
|
+
export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer<ArrayBufferLike>;
|
|
35
|
+
export declare function sha256(buffer: Buffer): Buffer<ArrayBufferLike>;
|
|
36
|
+
export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
|
|
37
|
+
//# sourceMappingURL=crypto.d.ts.map
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -2,101 +2,117 @@ import { createCipheriv, createDecipheriv, createHash, createHmac, randomBytes }
|
|
|
2
2
|
import * as curve from 'libsignal/src/curve.js';
|
|
3
3
|
import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
|
|
4
4
|
export { md5, hkdf } from 'whatsapp-rust-bridge';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export const generateSignalPubKey = pubKey => pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey]);
|
|
5
|
+
// insure browser & node compatibility
|
|
6
|
+
const { subtle } = globalThis.crypto;
|
|
7
|
+
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
8
|
+
export const generateSignalPubKey = (pubKey) => pubKey.length === 33 ? pubKey : Buffer.concat([KEY_BUNDLE_TYPE, pubKey]);
|
|
9
9
|
export const Curve = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
10
|
+
generateKeyPair: () => {
|
|
11
|
+
const { pubKey, privKey } = curve.generateKeyPair();
|
|
12
|
+
return {
|
|
13
|
+
private: Buffer.from(privKey),
|
|
14
|
+
// remove version byte
|
|
15
|
+
public: Buffer.from(pubKey.slice(1))
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
sharedKey: (privateKey, publicKey) => {
|
|
19
|
+
const shared = curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey);
|
|
20
|
+
return Buffer.from(shared);
|
|
21
|
+
},
|
|
22
|
+
sign: (privateKey, buf) => curve.calculateSignature(privateKey, buf),
|
|
23
|
+
verify: (pubKey, message, signature) => {
|
|
24
|
+
try {
|
|
25
|
+
curve.verifySignature(generateSignalPubKey(pubKey), message, signature);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
31
|
}
|
|
32
|
-
}
|
|
33
32
|
};
|
|
34
33
|
export const signedKeyPair = (identityKeyPair, keyId) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
keyPair: preKey,
|
|
40
|
-
signature,
|
|
41
|
-
keyId
|
|
42
|
-
};
|
|
34
|
+
const preKey = Curve.generateKeyPair();
|
|
35
|
+
const pubKey = generateSignalPubKey(preKey.public);
|
|
36
|
+
const signature = Curve.sign(identityKeyPair.private, pubKey);
|
|
37
|
+
return { keyPair: preKey, signature, keyId };
|
|
43
38
|
};
|
|
44
39
|
const GCM_TAG_LENGTH = 128 >> 3;
|
|
40
|
+
/**
|
|
41
|
+
* encrypt AES 256 GCM;
|
|
42
|
+
* where the tag tag is suffixed to the ciphertext
|
|
43
|
+
* */
|
|
45
44
|
export function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
46
|
+
cipher.setAAD(additionalData);
|
|
47
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
49
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* decrypt AES 256 GCM;
|
|
51
|
+
* where the auth tag is suffixed to the ciphertext
|
|
52
|
+
* */
|
|
50
53
|
export function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const decipher = createDecipheriv('aes-256-gcm', key, iv);
|
|
55
|
+
// decrypt additional adata
|
|
56
|
+
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
|
|
57
|
+
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
|
|
58
|
+
// set additional data
|
|
59
|
+
decipher.setAAD(additionalData);
|
|
60
|
+
decipher.setAuthTag(tag);
|
|
61
|
+
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
57
62
|
}
|
|
58
63
|
export function aesEncryptCTR(plaintext, key, iv) {
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
const cipher = createCipheriv('aes-256-ctr', key, iv);
|
|
65
|
+
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
61
66
|
}
|
|
62
67
|
export function aesDecryptCTR(ciphertext, key, iv) {
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
const decipher = createDecipheriv('aes-256-ctr', key, iv);
|
|
69
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
65
70
|
}
|
|
71
|
+
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
66
72
|
export function aesDecrypt(buffer, key) {
|
|
67
|
-
|
|
73
|
+
return aesDecryptWithIV(buffer.subarray(16), key, buffer.subarray(0, 16));
|
|
68
74
|
}
|
|
75
|
+
/** decrypt AES 256 CBC */
|
|
69
76
|
export function aesDecryptWithIV(buffer, key, IV) {
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
const aes = createDecipheriv('aes-256-cbc', key, IV);
|
|
78
|
+
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
72
79
|
}
|
|
80
|
+
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
73
81
|
export function aesEncrypt(buffer, key) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
const IV = randomBytes(16);
|
|
83
|
+
const aes = createCipheriv('aes-256-cbc', key, IV);
|
|
84
|
+
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
77
85
|
}
|
|
86
|
+
// encrypt AES 256 CBC with a given IV
|
|
78
87
|
export function aesEncrypWithIV(buffer, key, IV) {
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
const aes = createCipheriv('aes-256-cbc', key, IV);
|
|
89
|
+
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
81
90
|
}
|
|
91
|
+
// sign HMAC using SHA 256
|
|
82
92
|
export function hmacSign(buffer, key, variant = 'sha256') {
|
|
83
|
-
|
|
93
|
+
return createHmac(variant, key).update(buffer).digest();
|
|
84
94
|
}
|
|
85
95
|
export function sha256(buffer) {
|
|
86
|
-
|
|
96
|
+
return createHash('sha256').update(buffer).digest();
|
|
87
97
|
}
|
|
88
98
|
export async function derivePairingCodeKey(pairingCode, salt) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
// Convert inputs to formats Web Crypto API can work with
|
|
100
|
+
const encoder = new TextEncoder();
|
|
101
|
+
const pairingCodeBuffer = encoder.encode(pairingCode);
|
|
102
|
+
const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt));
|
|
103
|
+
// Import the pairing code as key material
|
|
104
|
+
const keyMaterial = await subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, [
|
|
105
|
+
'deriveBits'
|
|
106
|
+
]);
|
|
107
|
+
// Derive bits using PBKDF2 with the same parameters
|
|
108
|
+
// 2 << 16 = 131,072 iterations
|
|
109
|
+
const derivedBits = await subtle.deriveBits({
|
|
110
|
+
name: 'PBKDF2',
|
|
111
|
+
salt: saltBuffer,
|
|
112
|
+
iterations: 2 << 16,
|
|
113
|
+
hash: 'SHA-256'
|
|
114
|
+
}, keyMaterial, 32 * 8 // 32 bytes * 8 = 256 bits
|
|
115
|
+
);
|
|
116
|
+
return Buffer.from(derivedBits);
|
|
102
117
|
}
|
|
118
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { WAMessage } from '../Types/index.js';
|
|
2
|
+
import type { SignalRepositoryWithLIDStore } from '../Types/Signal.js';
|
|
3
|
+
import { type BinaryNode } from '../WABinary/index.js';
|
|
4
|
+
import type { ILogger } from './logger.js';
|
|
5
|
+
export declare const getDecryptionJid: (sender: string, repository: SignalRepositoryWithLIDStore) => Promise<string>;
|
|
6
|
+
export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
|
|
7
|
+
export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled";
|
|
8
|
+
export declare const ACCOUNT_RESTRICTED_TEXT = "Your account has been restricted";
|
|
9
|
+
export declare const DECRYPTION_RETRY_CONFIG: {
|
|
10
|
+
maxRetries: number;
|
|
11
|
+
baseDelayMs: number;
|
|
12
|
+
sessionRecordErrors: string[];
|
|
13
|
+
};
|
|
14
|
+
/** NACK reason codes we send to the server (client → server) */
|
|
15
|
+
export declare const NACK_REASONS: {
|
|
16
|
+
SenderReachoutTimelocked: number;
|
|
17
|
+
ParsingError: number;
|
|
18
|
+
UnrecognizedStanza: number;
|
|
19
|
+
UnrecognizedStanzaClass: number;
|
|
20
|
+
UnrecognizedStanzaType: number;
|
|
21
|
+
InvalidProtobuf: number;
|
|
22
|
+
InvalidHostedCompanionStanza: number;
|
|
23
|
+
MissingMessageSecret: number;
|
|
24
|
+
SignalErrorOldCounter: number;
|
|
25
|
+
MessageDeletedOnPeer: number;
|
|
26
|
+
UnhandledError: number;
|
|
27
|
+
UnsupportedAdminRevoke: number;
|
|
28
|
+
UnsupportedLIDGroup: number;
|
|
29
|
+
DBOperationFailed: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Server-side error codes returned in ack stanzas (server → client) that we
|
|
33
|
+
* currently have dedicated handlers for. Extend as more handlers are added.
|
|
34
|
+
* Distinct from the client-side NackReason enum (WAWebCreateNackFromStanza).
|
|
35
|
+
*/
|
|
36
|
+
export declare const SERVER_ERROR_CODES: {
|
|
37
|
+
/**
|
|
38
|
+
* 1:1 message missing privacy token (tctoken). Usually means the account is
|
|
39
|
+
* restricted: WhatsApp blocks starting new chats but preserves existing ones,
|
|
40
|
+
* since established chats already carry a tctoken.
|
|
41
|
+
*/
|
|
42
|
+
readonly MessageAccountRestriction: "463";
|
|
43
|
+
/** Stanza validation failure (SMAX_INVALID) — likely stale device session */
|
|
44
|
+
readonly SmaxInvalid: "479";
|
|
45
|
+
};
|
|
46
|
+
export declare const extractAddressingContext: (stanza: BinaryNode) => {
|
|
47
|
+
addressingMode: string;
|
|
48
|
+
senderAlt: string | undefined;
|
|
49
|
+
recipientAlt: string | undefined;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Decode the received node as a message.
|
|
53
|
+
* @note this will only parse the message, not decrypt it
|
|
54
|
+
*/
|
|
55
|
+
export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
|
|
56
|
+
fullMessage: WAMessage;
|
|
57
|
+
author: string;
|
|
58
|
+
sender: string;
|
|
59
|
+
};
|
|
60
|
+
export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepositoryWithLIDStore, logger: ILogger) => {
|
|
61
|
+
fullMessage: WAMessage;
|
|
62
|
+
category: string | undefined;
|
|
63
|
+
author: string;
|
|
64
|
+
decrypt(): Promise<void>;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=decode-wa-message.d.ts.map
|