gifted-baileys 1.5.4 → 1.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/WAProto/WAProto.proto +88 -969
- package/WAProto/index.d.ts +1256 -13195
- package/WAProto/index.js +74730 -125106
- package/package.json +9 -27
- package/src/Defaults/baileys-version.json +3 -0
- package/{lib → src}/Defaults/index.js +14 -7
- package/src/Defaults/index.ts +131 -0
- package/src/README.md +1 -0
- package/src/Signal/libsignal.js +180 -0
- package/src/Signal/libsignal.ts +141 -0
- package/src/Socket/Client/abstract-socket-client.ts +19 -0
- package/{lib → src}/Socket/Client/index.js +3 -2
- package/src/Socket/Client/index.ts +3 -0
- package/src/Socket/Client/mobile-socket-client.js +78 -0
- package/src/Socket/Client/mobile-socket-client.ts +66 -0
- package/src/Socket/Client/web-socket-client.js +75 -0
- package/src/Socket/Client/web-socket-client.ts +57 -0
- package/{lib → src}/Socket/business.js +33 -28
- package/src/Socket/business.ts +281 -0
- package/{lib → src}/Socket/chats.js +176 -174
- package/src/Socket/chats.ts +1030 -0
- package/{lib → src}/Socket/groups.js +68 -80
- package/src/Socket/groups.ts +356 -0
- package/{lib → src}/Socket/index.js +1 -4
- package/src/Socket/index.ts +13 -0
- package/{lib → src}/Socket/messages-recv.js +211 -378
- package/src/Socket/messages-recv.ts +985 -0
- package/{lib → src}/Socket/messages-send.js +177 -452
- package/src/Socket/messages-send.ts +871 -0
- package/{lib → src}/Socket/newsletter.js +98 -107
- package/src/Socket/newsletter.ts +282 -0
- package/{lib → src}/Socket/registration.js +48 -56
- package/src/Socket/registration.ts +250 -0
- package/{lib → src}/Socket/socket.js +77 -77
- package/src/Socket/socket.ts +777 -0
- package/src/Store/index.ts +3 -0
- package/{lib → src}/Store/make-cache-manager-store.js +34 -25
- package/src/Store/make-cache-manager-store.ts +100 -0
- package/{lib → src}/Store/make-in-memory-store.js +32 -36
- package/src/Store/make-in-memory-store.ts +475 -0
- package/src/Store/make-ordered-dictionary.ts +86 -0
- package/{lib → src}/Store/object-repository.js +1 -1
- package/src/Store/object-repository.ts +32 -0
- package/src/Tests/test.app-state-sync.js +204 -0
- package/src/Tests/test.app-state-sync.ts +207 -0
- package/src/Tests/test.event-buffer.js +270 -0
- package/src/Tests/test.event-buffer.ts +319 -0
- package/src/Tests/test.key-store.js +76 -0
- package/src/Tests/test.key-store.ts +92 -0
- package/src/Tests/test.libsignal.js +141 -0
- package/src/Tests/test.libsignal.ts +186 -0
- package/src/Tests/test.media-download.js +93 -0
- package/src/Tests/test.media-download.ts +76 -0
- package/src/Tests/test.messages.js +33 -0
- package/src/Tests/test.messages.ts +37 -0
- package/src/Tests/utils.js +34 -0
- package/src/Tests/utils.ts +36 -0
- package/src/Types/Auth.ts +113 -0
- package/src/Types/Call.ts +15 -0
- package/src/Types/Chat.ts +106 -0
- package/{lib/Types/Contact.d.ts → src/Types/Contact.ts} +9 -8
- package/src/Types/Events.ts +93 -0
- package/src/Types/GroupMetadata.ts +53 -0
- package/src/Types/Label.ts +36 -0
- package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
- package/src/Types/Message.ts +288 -0
- package/src/Types/Newsletter.ts +98 -0
- package/src/Types/Product.ts +85 -0
- package/src/Types/Signal.ts +68 -0
- package/{lib/Types/Socket.d.ts → src/Types/Socket.ts} +68 -61
- package/src/Types/State.ts +29 -0
- package/src/Types/index.ts +59 -0
- package/{lib → src}/Utils/auth-utils.js +90 -73
- package/src/Utils/auth-utils.ts +222 -0
- package/src/Utils/baileys-event-stream.js +92 -0
- package/src/Utils/baileys-event-stream.ts +66 -0
- package/{lib → src}/Utils/business.js +43 -15
- package/src/Utils/business.ts +275 -0
- package/{lib → src}/Utils/chat-utils.js +94 -87
- package/src/Utils/chat-utils.ts +860 -0
- package/{lib → src}/Utils/crypto.js +2 -4
- package/src/Utils/crypto.ts +131 -0
- package/src/Utils/decode-wa-message.js +211 -0
- package/src/Utils/decode-wa-message.ts +228 -0
- package/{lib → src}/Utils/event-buffer.js +13 -4
- package/src/Utils/event-buffer.ts +613 -0
- package/{lib → src}/Utils/generics.js +86 -67
- package/src/Utils/generics.ts +434 -0
- package/{lib → src}/Utils/history.js +39 -13
- package/src/Utils/history.ts +112 -0
- package/src/Utils/index.ts +17 -0
- package/{lib → src}/Utils/link-preview.js +54 -17
- package/src/Utils/link-preview.ts +122 -0
- package/src/Utils/logger.ts +3 -0
- package/src/Utils/lt-hash.ts +61 -0
- package/{lib → src}/Utils/make-mutex.js +13 -4
- package/src/Utils/make-mutex.ts +44 -0
- package/{lib → src}/Utils/messages-media.js +255 -193
- package/src/Utils/messages-media.ts +847 -0
- package/{lib → src}/Utils/messages.js +118 -588
- package/src/Utils/messages.ts +956 -0
- package/src/Utils/noise-handler.ts +197 -0
- package/{lib → src}/Utils/process-message.js +30 -27
- package/src/Utils/process-message.ts +414 -0
- package/{lib → src}/Utils/signal.js +42 -25
- package/src/Utils/signal.ts +177 -0
- package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -27
- package/src/Utils/use-multi-file-auth-state.ts +90 -0
- package/{lib → src}/Utils/validate-connection.js +9 -40
- package/src/Utils/validate-connection.ts +238 -0
- package/src/WABinary/constants.ts +42 -0
- package/src/WABinary/decode.ts +265 -0
- package/{lib → src}/WABinary/encode.js +10 -16
- package/src/WABinary/encode.ts +236 -0
- package/src/WABinary/generic-utils.ts +121 -0
- package/src/WABinary/index.ts +5 -0
- package/src/WABinary/jid-utils.ts +68 -0
- package/src/WABinary/types.ts +17 -0
- package/src/WAM/BinaryInfo.ts +12 -0
- package/src/WAM/constants.ts +15382 -0
- package/src/WAM/encode.ts +174 -0
- package/src/WAM/index.ts +3 -0
- package/{lib → src}/index.js +0 -1
- package/src/index.ts +13 -0
- package/README.md +0 -1645
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -284
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Signal/libsignal.js +0 -161
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/types.d.ts +0 -17
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.d.ts +0 -12
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/business.d.ts +0 -170
- package/lib/Socket/chats.d.ts +0 -81
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -172
- package/lib/Socket/messages-recv.d.ts +0 -158
- package/lib/Socket/messages-send.d.ts +0 -155
- package/lib/Socket/newsletter.d.ts +0 -132
- package/lib/Socket/registration.d.ts +0 -264
- package/lib/Socket/socket.d.ts +0 -44
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -109
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -107
- package/lib/Types/Events.d.ts +0 -172
- package/lib/Types/GroupMetadata.d.ts +0 -56
- package/lib/Types/Label.d.ts +0 -46
- package/lib/Types/Message.d.ts +0 -433
- package/lib/Types/Newsletter.d.ts +0 -92
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/USync.js +0 -2
- package/lib/Types/index.d.ts +0 -66
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/baileys-event-stream.js +0 -63
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -70
- package/lib/Utils/crypto.d.ts +0 -40
- package/lib/Utils/decode-wa-message.d.ts +0 -36
- package/lib/Utils/decode-wa-message.js +0 -226
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -88
- package/lib/Utils/history.d.ts +0 -19
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -2
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -113
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -33
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -27
- package/lib/WABinary/decode.d.ts +0 -6
- package/lib/WABinary/encode.d.ts +0 -2
- package/lib/WABinary/generic-utils.d.ts +0 -14
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -8
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -2
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/index.js +0 -20
- package/lib/WAUSync/USyncQuery.d.ts +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -79
- package/lib/WAUSync/USyncUser.d.ts +0 -10
- package/lib/WAUSync/USyncUser.js +0 -22
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/WAUSync/index.js +0 -19
- /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
- /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{lib → src}/Store/index.js +0 -0
- /package/{lib → src}/Store/make-ordered-dictionary.js +0 -0
- /package/{lib → src}/Types/Auth.js +0 -0
- /package/{lib → src}/Types/Call.js +0 -0
- /package/{lib → src}/Types/Chat.js +0 -0
- /package/{lib → src}/Types/Contact.js +0 -0
- /package/{lib → src}/Types/Events.js +0 -0
- /package/{lib → src}/Types/GroupMetadata.js +0 -0
- /package/{lib → src}/Types/Label.js +0 -0
- /package/{lib → src}/Types/LabelAssociation.js +0 -0
- /package/{lib → src}/Types/Message.js +0 -0
- /package/{lib → src}/Types/Newsletter.js +0 -0
- /package/{lib → src}/Types/Product.js +0 -0
- /package/{lib → src}/Types/Signal.js +0 -0
- /package/{lib → src}/Types/Socket.js +0 -0
- /package/{lib → src}/Types/State.js +0 -0
- /package/{lib → src}/Types/index.js +0 -0
- /package/{lib → src}/Utils/index.js +0 -0
- /package/{lib → src}/Utils/logger.js +0 -0
- /package/{lib → src}/Utils/lt-hash.js +0 -0
- /package/{lib → src}/Utils/noise-handler.js +0 -0
- /package/{lib → src}/WABinary/constants.js +0 -0
- /package/{lib → src}/WABinary/decode.js +0 -0
- /package/{lib → src}/WABinary/generic-utils.js +0 -0
- /package/{lib → src}/WABinary/index.js +0 -0
- /package/{lib → src}/WABinary/jid-utils.js +0 -0
- /package/{lib → src}/WABinary/types.js +0 -0
- /package/{lib → src}/WAM/BinaryInfo.js +0 -0
- /package/{lib → src}/WAM/constants.js +0 -0
- /package/{lib → src}/WAM/encode.js +0 -0
- /package/{lib → src}/WAM/index.js +0 -0
- /package/{lib → src}/gifted +0 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom'
|
|
2
|
+
import { Logger } from 'pino'
|
|
3
|
+
import { proto } from '../../WAProto'
|
|
4
|
+
import { NOISE_MODE, WA_CERT_DETAILS } from '../Defaults'
|
|
5
|
+
import { KeyPair } from '../Types'
|
|
6
|
+
import { BinaryNode, decodeBinaryNode } from '../WABinary'
|
|
7
|
+
import { aesDecryptGCM, aesEncryptGCM, Curve, hkdf, sha256 } from './crypto'
|
|
8
|
+
|
|
9
|
+
const generateIV = (counter: number) => {
|
|
10
|
+
const iv = new ArrayBuffer(12)
|
|
11
|
+
new DataView(iv).setUint32(8, counter)
|
|
12
|
+
|
|
13
|
+
return new Uint8Array(iv)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const makeNoiseHandler = ({
|
|
17
|
+
keyPair: { private: privateKey, public: publicKey },
|
|
18
|
+
NOISE_HEADER,
|
|
19
|
+
mobile,
|
|
20
|
+
logger,
|
|
21
|
+
routingInfo
|
|
22
|
+
}: {
|
|
23
|
+
keyPair: KeyPair
|
|
24
|
+
NOISE_HEADER: Uint8Array
|
|
25
|
+
mobile: boolean
|
|
26
|
+
logger: Logger
|
|
27
|
+
routingInfo?: Buffer | undefined
|
|
28
|
+
}) => {
|
|
29
|
+
logger = logger.child({ class: 'ns' })
|
|
30
|
+
|
|
31
|
+
const authenticate = (data: Uint8Array) => {
|
|
32
|
+
if(!isFinished) {
|
|
33
|
+
hash = sha256(Buffer.concat([hash, data]))
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const encrypt = (plaintext: Uint8Array) => {
|
|
38
|
+
const result = aesEncryptGCM(plaintext, encKey, generateIV(writeCounter), hash)
|
|
39
|
+
|
|
40
|
+
writeCounter += 1
|
|
41
|
+
|
|
42
|
+
authenticate(result)
|
|
43
|
+
return result
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const decrypt = (ciphertext: Uint8Array) => {
|
|
47
|
+
// before the handshake is finished, we use the same counter
|
|
48
|
+
// after handshake, the counters are different
|
|
49
|
+
const iv = generateIV(isFinished ? readCounter : writeCounter)
|
|
50
|
+
const result = aesDecryptGCM(ciphertext, decKey, iv, hash)
|
|
51
|
+
|
|
52
|
+
if(isFinished) {
|
|
53
|
+
readCounter += 1
|
|
54
|
+
} else {
|
|
55
|
+
writeCounter += 1
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
authenticate(ciphertext)
|
|
59
|
+
return result
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const localHKDF = (data: Uint8Array) => {
|
|
63
|
+
const key = hkdf(Buffer.from(data), 64, { salt, info: '' })
|
|
64
|
+
return [key.slice(0, 32), key.slice(32)]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const mixIntoKey = (data: Uint8Array) => {
|
|
68
|
+
const [write, read] = localHKDF(data)
|
|
69
|
+
salt = write
|
|
70
|
+
encKey = read
|
|
71
|
+
decKey = read
|
|
72
|
+
readCounter = 0
|
|
73
|
+
writeCounter = 0
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const finishInit = () => {
|
|
77
|
+
const [write, read] = localHKDF(new Uint8Array(0))
|
|
78
|
+
encKey = write
|
|
79
|
+
decKey = read
|
|
80
|
+
hash = Buffer.from([])
|
|
81
|
+
readCounter = 0
|
|
82
|
+
writeCounter = 0
|
|
83
|
+
isFinished = true
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const data = Buffer.from(NOISE_MODE)
|
|
87
|
+
let hash = Buffer.from(data.byteLength === 32 ? data : sha256(data))
|
|
88
|
+
let salt = hash
|
|
89
|
+
let encKey = hash
|
|
90
|
+
let decKey = hash
|
|
91
|
+
let readCounter = 0
|
|
92
|
+
let writeCounter = 0
|
|
93
|
+
let isFinished = false
|
|
94
|
+
let sentIntro = false
|
|
95
|
+
|
|
96
|
+
let inBytes = Buffer.alloc(0)
|
|
97
|
+
|
|
98
|
+
authenticate(NOISE_HEADER)
|
|
99
|
+
authenticate(publicKey)
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
encrypt,
|
|
103
|
+
decrypt,
|
|
104
|
+
authenticate,
|
|
105
|
+
mixIntoKey,
|
|
106
|
+
finishInit,
|
|
107
|
+
processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => {
|
|
108
|
+
authenticate(serverHello!.ephemeral!)
|
|
109
|
+
mixIntoKey(Curve.sharedKey(privateKey, serverHello!.ephemeral!))
|
|
110
|
+
|
|
111
|
+
const decStaticContent = decrypt(serverHello!.static!)
|
|
112
|
+
mixIntoKey(Curve.sharedKey(privateKey, decStaticContent))
|
|
113
|
+
|
|
114
|
+
const certDecoded = decrypt(serverHello!.payload!)
|
|
115
|
+
|
|
116
|
+
if(mobile) {
|
|
117
|
+
proto.CertChain.NoiseCertificate.decode(certDecoded)
|
|
118
|
+
} else {
|
|
119
|
+
const { intermediate: certIntermediate } = proto.CertChain.decode(certDecoded)
|
|
120
|
+
|
|
121
|
+
const { issuerSerial } = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate!.details!)
|
|
122
|
+
|
|
123
|
+
if(issuerSerial !== WA_CERT_DETAILS.SERIAL) {
|
|
124
|
+
throw new Boom('certification match failed', { statusCode: 400 })
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const keyEnc = encrypt(noiseKey.public)
|
|
129
|
+
mixIntoKey(Curve.sharedKey(noiseKey.private, serverHello!.ephemeral!))
|
|
130
|
+
|
|
131
|
+
return keyEnc
|
|
132
|
+
},
|
|
133
|
+
encodeFrame: (data: Buffer | Uint8Array) => {
|
|
134
|
+
if(isFinished) {
|
|
135
|
+
data = encrypt(data)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let header: Buffer
|
|
139
|
+
|
|
140
|
+
if(routingInfo) {
|
|
141
|
+
header = Buffer.alloc(7)
|
|
142
|
+
header.write('ED', 0, 'utf8')
|
|
143
|
+
header.writeUint8(0, 2)
|
|
144
|
+
header.writeUint8(1, 3)
|
|
145
|
+
header.writeUint8(routingInfo.byteLength >> 16, 4)
|
|
146
|
+
header.writeUint16BE(routingInfo.byteLength & 65535, 5)
|
|
147
|
+
header = Buffer.concat([header, routingInfo, NOISE_HEADER])
|
|
148
|
+
} else {
|
|
149
|
+
header = Buffer.from(NOISE_HEADER)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const introSize = sentIntro ? 0 : header.length
|
|
153
|
+
const frame = Buffer.alloc(introSize + 3 + data.byteLength)
|
|
154
|
+
|
|
155
|
+
if(!sentIntro) {
|
|
156
|
+
frame.set(header)
|
|
157
|
+
sentIntro = true
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
frame.writeUInt8(data.byteLength >> 16, introSize)
|
|
161
|
+
frame.writeUInt16BE(65535 & data.byteLength, introSize + 1)
|
|
162
|
+
frame.set(data, introSize + 3)
|
|
163
|
+
|
|
164
|
+
return frame
|
|
165
|
+
},
|
|
166
|
+
decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => {
|
|
167
|
+
// the binary protocol uses its own framing mechanism
|
|
168
|
+
// on top of the WS frames
|
|
169
|
+
// so we get this data and separate out the frames
|
|
170
|
+
const getBytesSize = () => {
|
|
171
|
+
if(inBytes.length >= 3) {
|
|
172
|
+
return (inBytes.readUInt8() << 16) | inBytes.readUInt16BE(1)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
inBytes = Buffer.concat([ inBytes, newData ])
|
|
177
|
+
|
|
178
|
+
logger.trace(`recv ${newData.length} bytes, total recv ${inBytes.length} bytes`)
|
|
179
|
+
|
|
180
|
+
let size = getBytesSize()
|
|
181
|
+
while(size && inBytes.length >= size + 3) {
|
|
182
|
+
let frame: Uint8Array | BinaryNode = inBytes.slice(3, size + 3)
|
|
183
|
+
inBytes = inBytes.slice(size + 3)
|
|
184
|
+
|
|
185
|
+
if(isFinished) {
|
|
186
|
+
const result = decrypt(frame as Uint8Array)
|
|
187
|
+
frame = decodeBinaryNode(result)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
logger.trace({ msg: (frame as any)?.attrs?.id }, 'recv frame')
|
|
191
|
+
|
|
192
|
+
onFrame(frame)
|
|
193
|
+
size = getBytesSize()
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
|
|
4
13
|
exports.decryptPollVote = decryptPollVote;
|
|
@@ -102,8 +111,8 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
|
|
|
102
111
|
return Buffer.from(txt);
|
|
103
112
|
}
|
|
104
113
|
}
|
|
105
|
-
const processMessage =
|
|
106
|
-
var
|
|
114
|
+
const processMessage = (message_1, _a) => __awaiter(void 0, [message_1, _a], void 0, function* (message, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }) {
|
|
115
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
107
116
|
const meId = creds.me.id;
|
|
108
117
|
const { accountSettings } = creds;
|
|
109
118
|
const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
|
|
@@ -118,7 +127,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
118
127
|
const content = (0, messages_1.normalizeMessageContent)(message.message);
|
|
119
128
|
// unarchive chat if it's a real message, or someone reacted to our message
|
|
120
129
|
// and we've the unarchive chats setting on
|
|
121
|
-
if ((isRealMsg || ((
|
|
130
|
+
if ((isRealMsg || ((_c = (_b = content === null || content === void 0 ? void 0 : content.reactionMessage) === null || _b === void 0 ? void 0 : _b.key) === null || _c === void 0 ? void 0 : _c.fromMe))
|
|
122
131
|
&& (accountSettings === null || accountSettings === void 0 ? void 0 : accountSettings.unarchiveChats)) {
|
|
123
132
|
chat.archived = false;
|
|
124
133
|
chat.readOnly = false;
|
|
@@ -129,7 +138,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
129
138
|
case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
|
|
130
139
|
const histNotification = protocolMsg.historySyncNotification;
|
|
131
140
|
const process = shouldProcessHistoryMsg;
|
|
132
|
-
const isLatest = !((
|
|
141
|
+
const isLatest = !((_d = creds.processedHistoryMessages) === null || _d === void 0 ? void 0 : _d.length);
|
|
133
142
|
logger === null || logger === void 0 ? void 0 : logger.info({
|
|
134
143
|
histNotification,
|
|
135
144
|
process,
|
|
@@ -143,24 +152,24 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
143
152
|
{ key: message.key, messageTimestamp: message.messageTimestamp }
|
|
144
153
|
]
|
|
145
154
|
});
|
|
146
|
-
const data =
|
|
147
|
-
ev.emit('messaging-history.set', {
|
|
155
|
+
const data = yield (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
|
|
156
|
+
ev.emit('messaging-history.set', Object.assign(Object.assign({}, data), { isLatest }));
|
|
148
157
|
}
|
|
149
158
|
break;
|
|
150
159
|
case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
|
|
151
160
|
const keys = protocolMsg.appStateSyncKeyShare.keys;
|
|
152
161
|
if (keys === null || keys === void 0 ? void 0 : keys.length) {
|
|
153
162
|
let newAppStateSyncKeyId = '';
|
|
154
|
-
|
|
163
|
+
yield keyStore.transaction(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
155
164
|
const newKeys = [];
|
|
156
165
|
for (const { keyData, keyId } of keys) {
|
|
157
166
|
const strKeyId = Buffer.from(keyId.keyId).toString('base64');
|
|
158
167
|
newKeys.push(strKeyId);
|
|
159
|
-
|
|
168
|
+
yield keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
|
|
160
169
|
newAppStateSyncKeyId = strKeyId;
|
|
161
170
|
}
|
|
162
171
|
logger === null || logger === void 0 ? void 0 : logger.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
|
|
163
|
-
});
|
|
172
|
+
}));
|
|
164
173
|
ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
|
|
165
174
|
}
|
|
166
175
|
else {
|
|
@@ -170,10 +179,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
170
179
|
case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
|
|
171
180
|
ev.emit('messages.update', [
|
|
172
181
|
{
|
|
173
|
-
key: {
|
|
174
|
-
...message.key,
|
|
175
|
-
id: protocolMsg.key.id
|
|
176
|
-
},
|
|
182
|
+
key: Object.assign(Object.assign({}, message.key), { id: protocolMsg.key.id }),
|
|
177
183
|
update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
|
|
178
184
|
}
|
|
179
185
|
]);
|
|
@@ -202,10 +208,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
202
208
|
}
|
|
203
209
|
}
|
|
204
210
|
else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
|
|
205
|
-
const reaction = {
|
|
206
|
-
...content.reactionMessage,
|
|
207
|
-
key: message.key,
|
|
208
|
-
};
|
|
211
|
+
const reaction = Object.assign(Object.assign({}, content.reactionMessage), { key: message.key });
|
|
209
212
|
ev.emit('messages.reaction', [{
|
|
210
213
|
reaction,
|
|
211
214
|
key: content.reactionMessage.key,
|
|
@@ -218,7 +221,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
218
221
|
const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
|
|
219
222
|
const emitGroupUpdate = (update) => {
|
|
220
223
|
var _a;
|
|
221
|
-
ev.emit('groups.update', [{ id: jid,
|
|
224
|
+
ev.emit('groups.update', [Object.assign(Object.assign({ id: jid }, update), { author: (_a = message.participant) !== null && _a !== void 0 ? _a : undefined })]);
|
|
222
225
|
};
|
|
223
226
|
const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid));
|
|
224
227
|
switch (message.messageStubType) {
|
|
@@ -249,28 +252,28 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
249
252
|
emitParticipantsUpdate('promote');
|
|
250
253
|
break;
|
|
251
254
|
case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
|
|
252
|
-
const announceValue = (
|
|
255
|
+
const announceValue = (_e = message.messageStubParameters) === null || _e === void 0 ? void 0 : _e[0];
|
|
253
256
|
emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
|
|
254
257
|
break;
|
|
255
258
|
case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
|
|
256
|
-
const restrictValue = (
|
|
259
|
+
const restrictValue = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
|
|
257
260
|
emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
|
|
258
261
|
break;
|
|
259
262
|
case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
|
|
260
|
-
const name = (
|
|
263
|
+
const name = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
|
|
261
264
|
chat.name = name;
|
|
262
265
|
emitGroupUpdate({ subject: name });
|
|
263
266
|
break;
|
|
264
267
|
case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
|
|
265
|
-
const code = (
|
|
268
|
+
const code = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
|
|
266
269
|
emitGroupUpdate({ inviteCode: code });
|
|
267
270
|
break;
|
|
268
271
|
case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
|
|
269
|
-
const memberAddValue = (
|
|
272
|
+
const memberAddValue = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
|
|
270
273
|
emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
|
|
271
274
|
break;
|
|
272
275
|
case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
|
|
273
|
-
const approvalMode = (
|
|
276
|
+
const approvalMode = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
|
|
274
277
|
emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
|
|
275
278
|
break;
|
|
276
279
|
}
|
|
@@ -278,12 +281,12 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
278
281
|
else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
|
|
279
282
|
const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey;
|
|
280
283
|
// we need to fetch the poll creation message to get the poll enc key
|
|
281
|
-
const pollMsg =
|
|
284
|
+
const pollMsg = yield getMessage(creationMsgKey);
|
|
282
285
|
if (pollMsg) {
|
|
283
286
|
const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
|
|
284
287
|
const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
|
|
285
288
|
const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
|
|
286
|
-
const pollEncKey = (
|
|
289
|
+
const pollEncKey = (_l = pollMsg.messageContextInfo) === null || _l === void 0 ? void 0 : _l.messageSecret;
|
|
287
290
|
try {
|
|
288
291
|
const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
|
|
289
292
|
pollEncKey,
|
|
@@ -317,5 +320,5 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
|
|
|
317
320
|
if (Object.keys(chat).length > 1) {
|
|
318
321
|
ev.emit('chats.update', [chat]);
|
|
319
322
|
}
|
|
320
|
-
};
|
|
323
|
+
});
|
|
321
324
|
exports.default = processMessage;
|