gifted-baileys 1.5.6 → 1.5.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/README.md +9 -0
- package/WAProto/WAProto.proto +969 -88
- package/WAProto/index.d.ts +13199 -1260
- package/WAProto/index.js +124901 -74525
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +284 -0
- package/{src → lib}/Defaults/index.js +7 -14
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +161 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/{src → lib}/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +17 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/business.d.ts +170 -0
- package/{src → lib}/Socket/business.js +28 -33
- package/lib/Socket/chats.d.ts +81 -0
- package/{src → lib}/Socket/chats.js +174 -176
- package/lib/Socket/groups.d.ts +115 -0
- package/{src → lib}/Socket/groups.js +80 -68
- package/lib/Socket/index.d.ts +172 -0
- package/{src → lib}/Socket/index.js +4 -1
- package/lib/Socket/messages-recv.d.ts +158 -0
- package/{src → lib}/Socket/messages-recv.js +378 -211
- package/lib/Socket/messages-send.d.ts +155 -0
- package/{src → lib}/Socket/messages-send.js +452 -177
- package/lib/Socket/newsletter.d.ts +132 -0
- package/{src → lib}/Socket/newsletter.js +107 -98
- package/lib/Socket/registration.d.ts +264 -0
- package/{src → lib}/Socket/registration.js +56 -48
- package/lib/Socket/socket.d.ts +44 -0
- package/{src → lib}/Socket/socket.js +77 -77
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/{src → lib}/Store/make-cache-manager-store.js +25 -34
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/{src → lib}/Store/make-in-memory-store.js +36 -32
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/{src → lib}/Store/object-repository.js +1 -1
- package/lib/Types/Auth.d.ts +109 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +107 -0
- package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
- package/lib/Types/Events.d.ts +172 -0
- package/lib/Types/GroupMetadata.d.ts +56 -0
- package/lib/Types/Label.d.ts +46 -0
- package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
- package/lib/Types/Message.d.ts +433 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/{src → lib}/Utils/auth-utils.js +73 -90
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/{src → lib}/Utils/business.js +15 -43
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/{src → lib}/Utils/chat-utils.js +87 -94
- package/lib/Utils/crypto.d.ts +40 -0
- package/{src → lib}/Utils/crypto.js +4 -2
- package/lib/Utils/decode-wa-message.d.ts +36 -0
- package/lib/Utils/decode-wa-message.js +226 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/{src → lib}/Utils/event-buffer.js +4 -13
- package/lib/Utils/generics.d.ts +88 -0
- package/{src → lib}/Utils/generics.js +67 -86
- package/lib/Utils/history.d.ts +19 -0
- package/{src → lib}/Utils/history.js +13 -39
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/{src → lib}/Utils/link-preview.js +17 -54
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/{src → lib}/Utils/make-mutex.js +4 -13
- package/lib/Utils/messages-media.d.ts +113 -0
- package/{src → lib}/Utils/messages-media.js +193 -255
- package/lib/Utils/messages.d.ts +77 -0
- package/{src → lib}/Utils/messages.js +588 -118
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/{src → lib}/Utils/process-message.js +27 -30
- package/lib/Utils/signal.d.ts +33 -0
- package/{src → lib}/Utils/signal.js +25 -42
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/{src → lib}/Utils/validate-connection.js +40 -9
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/{src → lib}/WABinary/encode.js +16 -10
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +31 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/{src → lib}/index.js +1 -0
- package/package.json +26 -8
- package/LICENSE +0 -21
- package/src/Defaults/baileys-version.json +0 -3
- package/src/Defaults/index.ts +0 -131
- package/src/README.md +0 -1
- package/src/Signal/libsignal.js +0 -180
- package/src/Signal/libsignal.ts +0 -141
- package/src/Socket/Client/abstract-socket-client.ts +0 -19
- package/src/Socket/Client/index.ts +0 -3
- package/src/Socket/Client/mobile-socket-client.js +0 -78
- package/src/Socket/Client/mobile-socket-client.ts +0 -66
- package/src/Socket/Client/web-socket-client.js +0 -75
- package/src/Socket/Client/web-socket-client.ts +0 -57
- package/src/Socket/business.ts +0 -281
- package/src/Socket/chats.ts +0 -1030
- package/src/Socket/groups.ts +0 -356
- package/src/Socket/index.ts +0 -13
- package/src/Socket/messages-recv.ts +0 -985
- package/src/Socket/messages-send.ts +0 -871
- package/src/Socket/newsletter.ts +0 -282
- package/src/Socket/registration.ts +0 -250
- package/src/Socket/socket.ts +0 -777
- package/src/Store/index.ts +0 -3
- package/src/Store/make-cache-manager-store.ts +0 -100
- package/src/Store/make-in-memory-store.ts +0 -475
- package/src/Store/make-ordered-dictionary.ts +0 -86
- package/src/Store/object-repository.ts +0 -32
- package/src/Tests/test.app-state-sync.js +0 -204
- package/src/Tests/test.app-state-sync.ts +0 -207
- package/src/Tests/test.event-buffer.js +0 -270
- package/src/Tests/test.event-buffer.ts +0 -319
- package/src/Tests/test.key-store.js +0 -76
- package/src/Tests/test.key-store.ts +0 -92
- package/src/Tests/test.libsignal.js +0 -141
- package/src/Tests/test.libsignal.ts +0 -186
- package/src/Tests/test.media-download.js +0 -93
- package/src/Tests/test.media-download.ts +0 -76
- package/src/Tests/test.messages.js +0 -33
- package/src/Tests/test.messages.ts +0 -37
- package/src/Tests/utils.js +0 -34
- package/src/Tests/utils.ts +0 -36
- package/src/Types/Auth.ts +0 -113
- package/src/Types/Call.ts +0 -15
- package/src/Types/Chat.ts +0 -106
- package/src/Types/Events.ts +0 -93
- package/src/Types/GroupMetadata.ts +0 -53
- package/src/Types/Label.ts +0 -36
- package/src/Types/Message.ts +0 -288
- package/src/Types/Newsletter.ts +0 -98
- package/src/Types/Product.ts +0 -85
- package/src/Types/Signal.ts +0 -68
- package/src/Types/State.ts +0 -29
- package/src/Types/index.ts +0 -59
- package/src/Utils/auth-utils.ts +0 -222
- package/src/Utils/baileys-event-stream.js +0 -92
- package/src/Utils/baileys-event-stream.ts +0 -66
- package/src/Utils/business.ts +0 -275
- package/src/Utils/chat-utils.ts +0 -860
- package/src/Utils/crypto.ts +0 -131
- package/src/Utils/decode-wa-message.js +0 -211
- package/src/Utils/decode-wa-message.ts +0 -228
- package/src/Utils/event-buffer.ts +0 -613
- package/src/Utils/generics.ts +0 -434
- package/src/Utils/history.ts +0 -112
- package/src/Utils/index.ts +0 -17
- package/src/Utils/link-preview.ts +0 -122
- package/src/Utils/logger.ts +0 -3
- package/src/Utils/lt-hash.ts +0 -61
- package/src/Utils/make-mutex.ts +0 -44
- package/src/Utils/messages-media.ts +0 -847
- package/src/Utils/messages.ts +0 -956
- package/src/Utils/noise-handler.ts +0 -197
- package/src/Utils/process-message.ts +0 -414
- package/src/Utils/signal.ts +0 -177
- package/src/Utils/use-multi-file-auth-state.ts +0 -90
- package/src/Utils/validate-connection.ts +0 -238
- package/src/WABinary/constants.ts +0 -42
- package/src/WABinary/decode.ts +0 -265
- package/src/WABinary/encode.ts +0 -236
- package/src/WABinary/generic-utils.ts +0 -121
- package/src/WABinary/index.ts +0 -5
- package/src/WABinary/jid-utils.ts +0 -68
- package/src/WABinary/types.ts +0 -17
- package/src/WAM/BinaryInfo.ts +0 -12
- package/src/WAM/constants.ts +0 -15382
- package/src/WAM/encode.ts +0 -174
- package/src/WAM/index.ts +0 -3
- package/src/gifted +0 -1
- package/src/index.ts +0 -13
- /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
- /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{src → lib}/Store/index.js +0 -0
- /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
- /package/{src → lib}/Types/Auth.js +0 -0
- /package/{src → lib}/Types/Call.js +0 -0
- /package/{src → lib}/Types/Chat.js +0 -0
- /package/{src → lib}/Types/Contact.js +0 -0
- /package/{src → lib}/Types/Events.js +0 -0
- /package/{src → lib}/Types/GroupMetadata.js +0 -0
- /package/{src → lib}/Types/Label.js +0 -0
- /package/{src → lib}/Types/LabelAssociation.js +0 -0
- /package/{src → lib}/Types/Message.js +0 -0
- /package/{src → lib}/Types/Newsletter.js +0 -0
- /package/{src → lib}/Types/Product.js +0 -0
- /package/{src → lib}/Types/Signal.js +0 -0
- /package/{src → lib}/Types/Socket.js +0 -0
- /package/{src → lib}/Types/State.js +0 -0
- /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
- /package/{src → lib}/Types/index.js +0 -0
- /package/{src → lib}/Utils/index.js +0 -0
- /package/{src → lib}/Utils/logger.js +0 -0
- /package/{src → lib}/Utils/lt-hash.js +0 -0
- /package/{src → lib}/Utils/noise-handler.js +0 -0
- /package/{src → lib}/WABinary/constants.js +0 -0
- /package/{src → lib}/WABinary/decode.js +0 -0
- /package/{src → lib}/WABinary/generic-utils.js +0 -0
- /package/{src → lib}/WABinary/index.js +0 -0
- /package/{src → lib}/WABinary/jid-utils.js +0 -0
- /package/{src → lib}/WAM/BinaryInfo.js +0 -0
- /package/{src → lib}/WAM/constants.js +0 -0
- /package/{src → lib}/WAM/encode.js +0 -0
- /package/{src → lib}/WAM/index.js +0 -0
package/src/Utils/crypto.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { createCipheriv, createDecipheriv, createHash, createHmac, pbkdf2Sync, randomBytes } from 'crypto'
|
|
2
|
-
import HKDF from 'futoin-hkdf'
|
|
3
|
-
import * as libsignal from 'libsignal'
|
|
4
|
-
import { KEY_BUNDLE_TYPE } from '../Defaults'
|
|
5
|
-
import { KeyPair } from '../Types'
|
|
6
|
-
|
|
7
|
-
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
8
|
-
export const generateSignalPubKey = (pubKey: Uint8Array | Buffer) => (
|
|
9
|
-
pubKey.length === 33
|
|
10
|
-
? pubKey
|
|
11
|
-
: Buffer.concat([ KEY_BUNDLE_TYPE, pubKey ])
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
export const Curve = {
|
|
15
|
-
generateKeyPair: (): KeyPair => {
|
|
16
|
-
const { pubKey, privKey } = libsignal.curve.generateKeyPair()
|
|
17
|
-
return {
|
|
18
|
-
private: Buffer.from(privKey),
|
|
19
|
-
// remove version byte
|
|
20
|
-
public: Buffer.from((pubKey as Uint8Array).slice(1))
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => {
|
|
24
|
-
const shared = libsignal.curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey)
|
|
25
|
-
return Buffer.from(shared)
|
|
26
|
-
},
|
|
27
|
-
sign: (privateKey: Uint8Array, buf: Uint8Array) => (
|
|
28
|
-
libsignal.curve.calculateSignature(privateKey, buf)
|
|
29
|
-
),
|
|
30
|
-
verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => {
|
|
31
|
-
try {
|
|
32
|
-
libsignal.curve.verifySignature(generateSignalPubKey(pubKey), message, signature)
|
|
33
|
-
return true
|
|
34
|
-
} catch(error) {
|
|
35
|
-
return false
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const signedKeyPair = (identityKeyPair: KeyPair, keyId: number) => {
|
|
41
|
-
const preKey = Curve.generateKeyPair()
|
|
42
|
-
const pubKey = generateSignalPubKey(preKey.public)
|
|
43
|
-
|
|
44
|
-
const signature = Curve.sign(identityKeyPair.private, pubKey)
|
|
45
|
-
|
|
46
|
-
return { keyPair: preKey, signature, keyId }
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const GCM_TAG_LENGTH = 128 >> 3
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* encrypt AES 256 GCM;
|
|
53
|
-
* where the tag tag is suffixed to the ciphertext
|
|
54
|
-
* */
|
|
55
|
-
export function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array) {
|
|
56
|
-
const cipher = createCipheriv('aes-256-gcm', key, iv)
|
|
57
|
-
cipher.setAAD(additionalData)
|
|
58
|
-
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()])
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* decrypt AES 256 GCM;
|
|
63
|
-
* where the auth tag is suffixed to the ciphertext
|
|
64
|
-
* */
|
|
65
|
-
export function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array) {
|
|
66
|
-
const decipher = createDecipheriv('aes-256-gcm', key, iv)
|
|
67
|
-
// decrypt additional adata
|
|
68
|
-
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH)
|
|
69
|
-
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH)
|
|
70
|
-
// set additional data
|
|
71
|
-
decipher.setAAD(additionalData)
|
|
72
|
-
decipher.setAuthTag(tag)
|
|
73
|
-
|
|
74
|
-
return Buffer.concat([ decipher.update(enc), decipher.final() ])
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array) {
|
|
78
|
-
const cipher = createCipheriv('aes-256-ctr', key, iv)
|
|
79
|
-
return Buffer.concat([cipher.update(plaintext), cipher.final()])
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array) {
|
|
83
|
-
const decipher = createDecipheriv('aes-256-ctr', key, iv)
|
|
84
|
-
return Buffer.concat([decipher.update(ciphertext), decipher.final()])
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
88
|
-
export function aesDecrypt(buffer: Buffer, key: Buffer) {
|
|
89
|
-
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16))
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** decrypt AES 256 CBC */
|
|
93
|
-
export function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer) {
|
|
94
|
-
const aes = createDecipheriv('aes-256-cbc', key, IV)
|
|
95
|
-
return Buffer.concat([aes.update(buffer), aes.final()])
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
99
|
-
export function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer) {
|
|
100
|
-
const IV = randomBytes(16)
|
|
101
|
-
const aes = createCipheriv('aes-256-cbc', key, IV)
|
|
102
|
-
return Buffer.concat([IV, aes.update(buffer), aes.final()]) // prefix IV to the buffer
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// encrypt AES 256 CBC with a given IV
|
|
106
|
-
export function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer) {
|
|
107
|
-
const aes = createCipheriv('aes-256-cbc', key, IV)
|
|
108
|
-
return Buffer.concat([aes.update(buffer), aes.final()]) // prefix IV to the buffer
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// sign HMAC using SHA 256
|
|
112
|
-
export function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant: 'sha256' | 'sha512' = 'sha256') {
|
|
113
|
-
return createHmac(variant, key).update(buffer).digest()
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function sha256(buffer: Buffer) {
|
|
117
|
-
return createHash('sha256').update(buffer).digest()
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function md5(buffer: Buffer) {
|
|
121
|
-
return createHash('md5').update(buffer).digest()
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// HKDF key expansion
|
|
125
|
-
export function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: { salt?: Buffer, info?: string }) {
|
|
126
|
-
return HKDF(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function derivePairingCodeKey(pairingCode: string, salt: Buffer) {
|
|
130
|
-
return pbkdf2Sync(pairingCode, salt, 2 << 16, 32, 'sha256')
|
|
131
|
-
}
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.decryptMessageNode = void 0;
|
|
13
|
-
exports.decodeMessageNode = decodeMessageNode;
|
|
14
|
-
const boom_1 = require("@hapi/boom");
|
|
15
|
-
const WAProto_1 = require("../../WAProto");
|
|
16
|
-
const WABinary_1 = require("../WABinary");
|
|
17
|
-
const generics_1 = require("./generics");
|
|
18
|
-
const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
|
|
19
|
-
/**
|
|
20
|
-
* Decode the received node as a message.
|
|
21
|
-
* @note this will only parse the message, not decrypt it
|
|
22
|
-
*/
|
|
23
|
-
function decodeMessageNode(stanza, meId, meLid) {
|
|
24
|
-
var _a, _b;
|
|
25
|
-
let msgType;
|
|
26
|
-
let chatId;
|
|
27
|
-
let author;
|
|
28
|
-
const msgId = stanza.attrs.id;
|
|
29
|
-
const from = stanza.attrs.from;
|
|
30
|
-
const participant = stanza.attrs.participant;
|
|
31
|
-
const recipient = stanza.attrs.recipient;
|
|
32
|
-
const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
|
|
33
|
-
const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
|
|
34
|
-
if ((0, WABinary_1.isJidUser)(from)) {
|
|
35
|
-
if (recipient) {
|
|
36
|
-
if (!isMe(from)) {
|
|
37
|
-
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
38
|
-
}
|
|
39
|
-
chatId = recipient;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
chatId = from;
|
|
43
|
-
}
|
|
44
|
-
msgType = 'chat';
|
|
45
|
-
author = from;
|
|
46
|
-
}
|
|
47
|
-
else if ((0, WABinary_1.isLidUser)(from)) {
|
|
48
|
-
if (recipient) {
|
|
49
|
-
if (!isMeLid(from)) {
|
|
50
|
-
throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
|
|
51
|
-
}
|
|
52
|
-
chatId = recipient;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
chatId = from;
|
|
56
|
-
}
|
|
57
|
-
msgType = 'chat';
|
|
58
|
-
author = from;
|
|
59
|
-
}
|
|
60
|
-
else if ((0, WABinary_1.isJidGroup)(from)) {
|
|
61
|
-
if (!participant) {
|
|
62
|
-
throw new boom_1.Boom('No participant in group message');
|
|
63
|
-
}
|
|
64
|
-
msgType = 'group';
|
|
65
|
-
author = participant;
|
|
66
|
-
chatId = from;
|
|
67
|
-
}
|
|
68
|
-
else if ((0, WABinary_1.isJidBroadcast)(from)) {
|
|
69
|
-
if (!participant) {
|
|
70
|
-
throw new boom_1.Boom('No participant in group message');
|
|
71
|
-
}
|
|
72
|
-
const isParticipantMe = isMe(participant);
|
|
73
|
-
if ((0, WABinary_1.isJidStatusBroadcast)(from)) {
|
|
74
|
-
msgType = isParticipantMe ? 'direct_peer_status' : 'other_status';
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast';
|
|
78
|
-
}
|
|
79
|
-
chatId = from;
|
|
80
|
-
author = participant;
|
|
81
|
-
}
|
|
82
|
-
else if ((0, WABinary_1.isJidNewsLetter)(from)) {
|
|
83
|
-
msgType = 'newsletter';
|
|
84
|
-
author = from;
|
|
85
|
-
chatId = from;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
throw new boom_1.Boom('Unknown message type', { data: stanza });
|
|
89
|
-
}
|
|
90
|
-
const fromMe = (0, WABinary_1.isJidNewsLetter)(from) ? !!((_a = stanza.attrs) === null || _a === void 0 ? void 0 : _a.is_sender) : ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
|
|
91
|
-
const pushname = stanza.attrs.notify;
|
|
92
|
-
const key = {
|
|
93
|
-
remoteJid: chatId,
|
|
94
|
-
fromMe,
|
|
95
|
-
id: msgId,
|
|
96
|
-
participant
|
|
97
|
-
};
|
|
98
|
-
const fullMessage = {
|
|
99
|
-
key,
|
|
100
|
-
messageTimestamp: +stanza.attrs.t,
|
|
101
|
-
pushName: pushname,
|
|
102
|
-
broadcast: (0, WABinary_1.isJidBroadcast)(from)
|
|
103
|
-
};
|
|
104
|
-
if (msgType === 'newsletter') {
|
|
105
|
-
fullMessage.newsletterServerId = +((_b = stanza.attrs) === null || _b === void 0 ? void 0 : _b.server_id);
|
|
106
|
-
}
|
|
107
|
-
if (key.fromMe) {
|
|
108
|
-
fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK;
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
fullMessage,
|
|
112
|
-
author,
|
|
113
|
-
sender: msgType === 'chat' ? author : chatId
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
117
|
-
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
|
|
118
|
-
return {
|
|
119
|
-
fullMessage,
|
|
120
|
-
category: stanza.attrs.category,
|
|
121
|
-
author,
|
|
122
|
-
decrypt() {
|
|
123
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
var _a;
|
|
125
|
-
let decryptables = 0;
|
|
126
|
-
function processSenderKeyDistribution(msg) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
if (msg.senderKeyDistributionMessage) {
|
|
129
|
-
try {
|
|
130
|
-
yield repository.processSenderKeyDistributionMessage({
|
|
131
|
-
authorJid: author,
|
|
132
|
-
item: msg.senderKeyDistributionMessage
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
catch (err) {
|
|
136
|
-
logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution');
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
if ((0, WABinary_1.isJidNewsLetter)(fullMessage.key.remoteJid)) {
|
|
142
|
-
const node = (0, WABinary_1.getBinaryNodeChild)(stanza, 'plaintext');
|
|
143
|
-
const msg = WAProto_1.proto.Message.decode(node === null || node === void 0 ? void 0 : node.content);
|
|
144
|
-
yield processSenderKeyDistribution(msg);
|
|
145
|
-
fullMessage.message = msg;
|
|
146
|
-
decryptables += 1;
|
|
147
|
-
}
|
|
148
|
-
else if (Array.isArray(stanza.content)) {
|
|
149
|
-
for (const { tag, attrs, content } of stanza.content) {
|
|
150
|
-
if (tag === 'verified_name' && content instanceof Uint8Array) {
|
|
151
|
-
const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content);
|
|
152
|
-
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
153
|
-
fullMessage.verifiedBizName = details.verifiedName;
|
|
154
|
-
}
|
|
155
|
-
if (tag !== 'enc') {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
if (!(content instanceof Uint8Array)) {
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
decryptables += 1;
|
|
162
|
-
let msgBuffer;
|
|
163
|
-
try {
|
|
164
|
-
const e2eType = attrs.type;
|
|
165
|
-
switch (e2eType) {
|
|
166
|
-
case 'skmsg':
|
|
167
|
-
msgBuffer = yield repository.decryptGroupMessage({
|
|
168
|
-
group: sender,
|
|
169
|
-
authorJid: author,
|
|
170
|
-
msg: content
|
|
171
|
-
});
|
|
172
|
-
break;
|
|
173
|
-
case 'pkmsg':
|
|
174
|
-
case 'msg':
|
|
175
|
-
const user = (0, WABinary_1.isJidUser)(sender) ? sender : author;
|
|
176
|
-
msgBuffer = yield repository.decryptMessage({
|
|
177
|
-
jid: user,
|
|
178
|
-
type: e2eType,
|
|
179
|
-
ciphertext: content
|
|
180
|
-
});
|
|
181
|
-
break;
|
|
182
|
-
default:
|
|
183
|
-
throw new Error(`Unknown e2e type: ${e2eType}`);
|
|
184
|
-
}
|
|
185
|
-
let msg = WAProto_1.proto.Message.decode((0, generics_1.unpadRandomMax16)(msgBuffer));
|
|
186
|
-
msg = ((_a = msg.deviceSentMessage) === null || _a === void 0 ? void 0 : _a.message) || msg;
|
|
187
|
-
yield processSenderKeyDistribution(msg);
|
|
188
|
-
if (fullMessage.message) {
|
|
189
|
-
Object.assign(fullMessage.message, msg);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
fullMessage.message = msg;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
catch (err) {
|
|
196
|
-
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message');
|
|
197
|
-
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
198
|
-
fullMessage.messageStubParameters = [err.message];
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
// if nothing was found to decrypt
|
|
203
|
-
if (!decryptables) {
|
|
204
|
-
fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT;
|
|
205
|
-
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, generics_1.BufferJSON.replacer)];
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
};
|
|
211
|
-
exports.decryptMessageNode = decryptMessageNode;
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import { Boom } from '@hapi/boom'
|
|
2
|
-
import { Logger } from 'pino'
|
|
3
|
-
import { proto } from '../../WAProto'
|
|
4
|
-
import { SignalRepository, WAMessageKey } from '../Types'
|
|
5
|
-
import { areJidsSameUser, BinaryNode, getBinaryNodeChild, isJidBroadcast, isJidGroup, isJidNewsLetter, isJidStatusBroadcast, isJidUser, isLidUser } from '../WABinary'
|
|
6
|
-
import { BufferJSON, unpadRandomMax16 } from './generics'
|
|
7
|
-
|
|
8
|
-
const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
|
|
9
|
-
|
|
10
|
-
type MessageType = 'chat' | 'peer_broadcast' | 'other_broadcast' | 'group' | 'direct_peer_status' | 'other_status' | 'newsletter'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Decode the received node as a message.
|
|
14
|
-
* @note this will only parse the message, not decrypt it
|
|
15
|
-
*/
|
|
16
|
-
export function decodeMessageNode(
|
|
17
|
-
stanza: BinaryNode,
|
|
18
|
-
meId: string,
|
|
19
|
-
meLid: string
|
|
20
|
-
) {
|
|
21
|
-
let msgType: MessageType
|
|
22
|
-
let chatId: string
|
|
23
|
-
let author: string
|
|
24
|
-
|
|
25
|
-
const msgId = stanza.attrs.id
|
|
26
|
-
const from = stanza.attrs.from
|
|
27
|
-
const participant: string | undefined = stanza.attrs.participant
|
|
28
|
-
const recipient: string | undefined = stanza.attrs.recipient
|
|
29
|
-
|
|
30
|
-
const isMe = (jid: string) => areJidsSameUser(jid, meId)
|
|
31
|
-
const isMeLid = (jid: string) => areJidsSameUser(jid, meLid)
|
|
32
|
-
|
|
33
|
-
if(isJidUser(from)) {
|
|
34
|
-
if(recipient) {
|
|
35
|
-
if(!isMe(from)) {
|
|
36
|
-
throw new Boom('receipient present, but msg not from me', { data: stanza })
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
chatId = recipient
|
|
40
|
-
} else {
|
|
41
|
-
chatId = from
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
msgType = 'chat'
|
|
45
|
-
author = from
|
|
46
|
-
} else if(isLidUser(from)) {
|
|
47
|
-
if(recipient) {
|
|
48
|
-
if(!isMeLid(from)) {
|
|
49
|
-
throw new Boom('receipient present, but msg not from me', { data: stanza })
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
chatId = recipient
|
|
53
|
-
} else {
|
|
54
|
-
chatId = from
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
msgType = 'chat'
|
|
58
|
-
author = from
|
|
59
|
-
} else if(isJidGroup(from)) {
|
|
60
|
-
if(!participant) {
|
|
61
|
-
throw new Boom('No participant in group message')
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
msgType = 'group'
|
|
65
|
-
author = participant
|
|
66
|
-
chatId = from
|
|
67
|
-
} else if(isJidBroadcast(from)) {
|
|
68
|
-
if(!participant) {
|
|
69
|
-
throw new Boom('No participant in group message')
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const isParticipantMe = isMe(participant)
|
|
73
|
-
if(isJidStatusBroadcast(from)) {
|
|
74
|
-
msgType = isParticipantMe ? 'direct_peer_status' : 'other_status'
|
|
75
|
-
} else {
|
|
76
|
-
msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast'
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
chatId = from
|
|
80
|
-
author = participant
|
|
81
|
-
} else if (isJidNewsLetter(from)) {
|
|
82
|
-
msgType = 'newsletter'
|
|
83
|
-
author = from
|
|
84
|
-
chatId = from
|
|
85
|
-
} else {
|
|
86
|
-
throw new Boom('Unknown message type', { data: stanza })
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const fromMe = isJidNewsLetter(from) ? !!stanza.attrs?.is_sender : (isLidUser(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from)
|
|
90
|
-
const pushname = stanza.attrs.notify
|
|
91
|
-
|
|
92
|
-
const key: WAMessageKey = {
|
|
93
|
-
remoteJid: chatId,
|
|
94
|
-
fromMe,
|
|
95
|
-
id: msgId,
|
|
96
|
-
participant
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const fullMessage: proto.IWebMessageInfo = {
|
|
100
|
-
key,
|
|
101
|
-
messageTimestamp: +stanza.attrs.t,
|
|
102
|
-
pushName: pushname,
|
|
103
|
-
broadcast: isJidBroadcast(from)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (msgType === 'newsletter') {
|
|
107
|
-
fullMessage.newsletterServerId = +stanza.attrs?.server_id
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if(key.fromMe) {
|
|
111
|
-
fullMessage.status = proto.WebMessageInfo.Status.SERVER_ACK
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
fullMessage,
|
|
116
|
-
author,
|
|
117
|
-
sender: msgType === 'chat' ? author : chatId
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export const decryptMessageNode = (
|
|
122
|
-
stanza: BinaryNode,
|
|
123
|
-
meId: string,
|
|
124
|
-
meLid: string,
|
|
125
|
-
repository: SignalRepository,
|
|
126
|
-
logger: Logger
|
|
127
|
-
) => {
|
|
128
|
-
const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid)
|
|
129
|
-
return {
|
|
130
|
-
fullMessage,
|
|
131
|
-
category: stanza.attrs.category,
|
|
132
|
-
author,
|
|
133
|
-
async decrypt() {
|
|
134
|
-
let decryptables = 0
|
|
135
|
-
|
|
136
|
-
async function processSenderKeyDistribution(msg: proto.IMessage) {
|
|
137
|
-
if(msg.senderKeyDistributionMessage) {
|
|
138
|
-
try {
|
|
139
|
-
await repository.processSenderKeyDistributionMessage({
|
|
140
|
-
authorJid: author,
|
|
141
|
-
item: msg.senderKeyDistributionMessage
|
|
142
|
-
})
|
|
143
|
-
} catch(err) {
|
|
144
|
-
logger.error({ key: fullMessage.key, err }, 'failed to process senderKeyDistribution')
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (isJidNewsLetter(fullMessage.key.remoteJid!)) {
|
|
150
|
-
const node = getBinaryNodeChild(stanza, 'plaintext')
|
|
151
|
-
const msg = proto.Message.decode(node?.content as Uint8Array)
|
|
152
|
-
|
|
153
|
-
await processSenderKeyDistribution(msg)
|
|
154
|
-
|
|
155
|
-
fullMessage.message = msg
|
|
156
|
-
decryptables += 1
|
|
157
|
-
} else if(Array.isArray(stanza.content)) {
|
|
158
|
-
for(const { tag, attrs, content } of stanza.content) {
|
|
159
|
-
if(tag === 'verified_name' && content instanceof Uint8Array) {
|
|
160
|
-
const cert = proto.VerifiedNameCertificate.decode(content)
|
|
161
|
-
const details = proto.VerifiedNameCertificate.Details.decode(cert.details)
|
|
162
|
-
fullMessage.verifiedBizName = details.verifiedName
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if(tag !== 'enc') {
|
|
166
|
-
continue
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if(!(content instanceof Uint8Array)) {
|
|
170
|
-
continue
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
decryptables += 1
|
|
175
|
-
|
|
176
|
-
let msgBuffer: Uint8Array
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
const e2eType = attrs.type
|
|
180
|
-
switch (e2eType) {
|
|
181
|
-
case 'skmsg':
|
|
182
|
-
msgBuffer = await repository.decryptGroupMessage({
|
|
183
|
-
group: sender,
|
|
184
|
-
authorJid: author,
|
|
185
|
-
msg: content
|
|
186
|
-
})
|
|
187
|
-
break
|
|
188
|
-
case 'pkmsg':
|
|
189
|
-
case 'msg':
|
|
190
|
-
const user = isJidUser(sender) ? sender : author
|
|
191
|
-
msgBuffer = await repository.decryptMessage({
|
|
192
|
-
jid: user,
|
|
193
|
-
type: e2eType,
|
|
194
|
-
ciphertext: content
|
|
195
|
-
})
|
|
196
|
-
break
|
|
197
|
-
default:
|
|
198
|
-
throw new Error(`Unknown e2e type: ${e2eType}`)
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
let msg: proto.IMessage = proto.Message.decode(unpadRandomMax16(msgBuffer))
|
|
202
|
-
msg = msg.deviceSentMessage?.message || msg
|
|
203
|
-
await processSenderKeyDistribution(msg)
|
|
204
|
-
|
|
205
|
-
if(fullMessage.message) {
|
|
206
|
-
Object.assign(fullMessage.message, msg)
|
|
207
|
-
} else {
|
|
208
|
-
fullMessage.message = msg
|
|
209
|
-
}
|
|
210
|
-
} catch(err) {
|
|
211
|
-
logger.error(
|
|
212
|
-
{ key: fullMessage.key, err },
|
|
213
|
-
'failed to decrypt message'
|
|
214
|
-
)
|
|
215
|
-
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT
|
|
216
|
-
fullMessage.messageStubParameters = [err.message]
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// if nothing was found to decrypt
|
|
222
|
-
if(!decryptables) {
|
|
223
|
-
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT
|
|
224
|
-
fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT, JSON.stringify(stanza, BufferJSON.replacer)]
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|