lordceaser-baileys 2.0.11 → 2.0.13

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.
Files changed (173) hide show
  1. package/package.json +2 -5
  2. package/lib/Defaults/baileys-version.json +0 -3
  3. package/lib/Defaults/index.d.ts +0 -284
  4. package/lib/Defaults/index.js +0 -121
  5. package/lib/Defaults/phonenumber-mcc.json +0 -223
  6. package/lib/Signal/libsignal.d.ts +0 -4
  7. package/lib/Signal/libsignal.js +0 -162
  8. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
  9. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  10. package/lib/Socket/Client/index.d.ts +0 -2
  11. package/lib/Socket/Client/index.js +0 -22
  12. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
  13. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  14. package/lib/Socket/Client/types.d.ts +0 -16
  15. package/lib/Socket/Client/types.js +0 -18
  16. package/lib/Socket/Client/web-socket-client.js +0 -62
  17. package/lib/Socket/Client/websocket.d.ts +0 -13
  18. package/lib/Socket/Client/websocket.js +0 -62
  19. package/lib/Socket/business.d.ts +0 -182
  20. package/lib/Socket/business.js +0 -268
  21. package/lib/Socket/chats.d.ts +0 -96
  22. package/lib/Socket/chats.js +0 -1026
  23. package/lib/Socket/groups.d.ts +0 -130
  24. package/lib/Socket/groups.js +0 -338
  25. package/lib/Socket/index.d.ts +0 -185
  26. package/lib/Socket/index.js +0 -14
  27. package/lib/Socket/messages-recv.d.ts +0 -171
  28. package/lib/Socket/messages-recv.js +0 -1182
  29. package/lib/Socket/messages-send.d.ts +0 -162
  30. package/lib/Socket/messages-send.js +0 -1006
  31. package/lib/Socket/newsletter.d.ts +0 -142
  32. package/lib/Socket/newsletter.js +0 -256
  33. package/lib/Socket/registration.d.ts +0 -264
  34. package/lib/Socket/registration.js +0 -166
  35. package/lib/Socket/socket.d.ts +0 -45
  36. package/lib/Socket/socket.js +0 -751
  37. package/lib/Socket/socket.js.bak +0 -751
  38. package/lib/Socket/usync.d.ts +0 -37
  39. package/lib/Socket/usync.js +0 -83
  40. package/lib/Store/index.d.ts +0 -4
  41. package/lib/Store/index.js +0 -24
  42. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  43. package/lib/Store/make-cache-manager-store.js +0 -90
  44. package/lib/Store/make-in-memory-store.d.ts +0 -123
  45. package/lib/Store/make-in-memory-store.js +0 -429
  46. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  47. package/lib/Store/make-ordered-dictionary.js +0 -86
  48. package/lib/Store/object-repository.d.ts +0 -10
  49. package/lib/Store/object-repository.js +0 -31
  50. package/lib/Types/Auth.d.ts +0 -120
  51. package/lib/Types/Auth.js +0 -3
  52. package/lib/Types/Call.d.ts +0 -14
  53. package/lib/Types/Call.js +0 -3
  54. package/lib/Types/Chat.d.ts +0 -134
  55. package/lib/Types/Chat.js +0 -9
  56. package/lib/Types/Contact.d.ts +0 -25
  57. package/lib/Types/Contact.js +0 -3
  58. package/lib/Types/Events.d.ts +0 -212
  59. package/lib/Types/Events.js +0 -3
  60. package/lib/Types/GroupMetadata.d.ts +0 -64
  61. package/lib/Types/GroupMetadata.js +0 -3
  62. package/lib/Types/Label.d.ts +0 -48
  63. package/lib/Types/Label.js +0 -31
  64. package/lib/Types/LabelAssociation.d.ts +0 -35
  65. package/lib/Types/LabelAssociation.js +0 -13
  66. package/lib/Types/Message.d.ts +0 -459
  67. package/lib/Types/Message.js +0 -13
  68. package/lib/Types/Newsletter.d.ts +0 -107
  69. package/lib/Types/Newsletter.js +0 -38
  70. package/lib/Types/Product.d.ts +0 -92
  71. package/lib/Types/Product.js +0 -3
  72. package/lib/Types/Signal.d.ts +0 -68
  73. package/lib/Types/Signal.js +0 -3
  74. package/lib/Types/Socket.d.ts +0 -120
  75. package/lib/Types/Socket.js +0 -3
  76. package/lib/Types/State.d.ts +0 -29
  77. package/lib/Types/State.js +0 -3
  78. package/lib/Types/USync.d.ts +0 -26
  79. package/lib/Types/USync.js +0 -3
  80. package/lib/Types/index.d.ts +0 -78
  81. package/lib/Types/index.js +0 -47
  82. package/lib/Utils/auth-utils.d.ts +0 -21
  83. package/lib/Utils/auth-utils.js +0 -205
  84. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  85. package/lib/Utils/baileys-event-stream.js +0 -70
  86. package/lib/Utils/business.d.ts +0 -29
  87. package/lib/Utils/business.js +0 -247
  88. package/lib/Utils/chat-utils.d.ts +0 -82
  89. package/lib/Utils/chat-utils.js +0 -774
  90. package/lib/Utils/crypto.d.ts +0 -56
  91. package/lib/Utils/crypto.js +0 -179
  92. package/lib/Utils/decode-wa-message.d.ts +0 -41
  93. package/lib/Utils/decode-wa-message.js +0 -236
  94. package/lib/Utils/event-buffer.d.ts +0 -39
  95. package/lib/Utils/event-buffer.js +0 -548
  96. package/lib/Utils/generics.d.ts +0 -129
  97. package/lib/Utils/generics.js +0 -485
  98. package/lib/Utils/history.d.ts +0 -23
  99. package/lib/Utils/history.js +0 -100
  100. package/lib/Utils/index.d.ts +0 -20
  101. package/lib/Utils/index.js +0 -40
  102. package/lib/Utils/link-preview.d.ts +0 -23
  103. package/lib/Utils/link-preview.js +0 -120
  104. package/lib/Utils/logger.d.ts +0 -13
  105. package/lib/Utils/logger.js +0 -7
  106. package/lib/Utils/lt-hash.d.ts +0 -14
  107. package/lib/Utils/lt-hash.js +0 -58
  108. package/lib/Utils/make-mutex.d.ts +0 -9
  109. package/lib/Utils/make-mutex.js +0 -49
  110. package/lib/Utils/messages-media.d.ts +0 -129
  111. package/lib/Utils/messages-media.js +0 -782
  112. package/lib/Utils/messages.d.ts +0 -103
  113. package/lib/Utils/messages.js +0 -1631
  114. package/lib/Utils/noise-handler.d.ts +0 -20
  115. package/lib/Utils/noise-handler.js +0 -155
  116. package/lib/Utils/process-message.d.ts +0 -49
  117. package/lib/Utils/process-message.js +0 -387
  118. package/lib/Utils/signal.d.ts +0 -42
  119. package/lib/Utils/signal.js +0 -166
  120. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  121. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  122. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  123. package/lib/Utils/use-multi-file-auth-state.js +0 -131
  124. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  125. package/lib/Utils/use-single-file-auth-state.js +0 -80
  126. package/lib/Utils/use-sql-file-auth-state.d.ts +0 -6
  127. package/lib/Utils/use-sql-file-auth-state.js +0 -143
  128. package/lib/Utils/validate-connection.d.ts +0 -13
  129. package/lib/Utils/validate-connection.js +0 -186
  130. package/lib/WABinary/constants.d.ts +0 -30
  131. package/lib/WABinary/constants.js +0 -53
  132. package/lib/WABinary/decode.d.ts +0 -9
  133. package/lib/WABinary/decode.js +0 -288
  134. package/lib/WABinary/encode.d.ts +0 -3
  135. package/lib/WABinary/encode.js +0 -256
  136. package/lib/WABinary/generic-utils.d.ts +0 -28
  137. package/lib/WABinary/generic-utils.js +0 -150
  138. package/lib/WABinary/index.d.ts +0 -5
  139. package/lib/WABinary/index.js +0 -25
  140. package/lib/WABinary/jid-utils.d.ts +0 -53
  141. package/lib/WABinary/jid-utils.js +0 -92
  142. package/lib/WABinary/types.d.ts +0 -22
  143. package/lib/WABinary/types.js +0 -3
  144. package/lib/WAM/BinaryInfo.d.ts +0 -16
  145. package/lib/WAM/BinaryInfo.js +0 -17
  146. package/lib/WAM/constants.d.ts +0 -47
  147. package/lib/WAM/constants.js +0 -15371
  148. package/lib/WAM/encode.d.ts +0 -3
  149. package/lib/WAM/encode.js +0 -165
  150. package/lib/WAM/index.d.ts +0 -3
  151. package/lib/WAM/index.js +0 -23
  152. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  153. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
  154. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  155. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -36
  156. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  157. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -62
  158. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  159. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -35
  160. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -9
  161. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -30
  162. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  163. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -46
  164. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  165. package/lib/WAUSync/Protocols/index.js +0 -26
  166. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  167. package/lib/WAUSync/USyncQuery.js +0 -92
  168. package/lib/WAUSync/USyncUser.d.ts +0 -12
  169. package/lib/WAUSync/USyncUser.js +0 -30
  170. package/lib/WAUSync/index.d.ts +0 -3
  171. package/lib/WAUSync/index.js +0 -23
  172. package/lib/index.d.ts +0 -13
  173. package/lib/index.js +0 -33
@@ -1,56 +0,0 @@
1
- import { KeyPair } from '../Types'
2
-
3
- /** prefix version byte to the pub keys, required for some curve crypto functions */
4
- export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer
5
-
6
- export declare const Curve: {
7
- generateKeyPair: () => KeyPair
8
- sharedKey: (privateKey: Uint8Array, publicKey: Uint8Array) => Buffer
9
- sign: (privateKey: Uint8Array, buf: Uint8Array) => any
10
- verify: (pubKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => boolean
11
- }
12
-
13
- export declare const signedKeyPair: (identityKeyPair: KeyPair, keyId: number) => {
14
- keyPair: KeyPair
15
- signature: any
16
- keyId: number
17
- }
18
-
19
- /**
20
- * encrypt AES 256 GCM
21
- * where the tag tag is suffixed to the ciphertext
22
- * */
23
- export declare function aesEncryptGCM(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer
24
-
25
- /**
26
- * decrypt AES 256 GCM
27
- * where the auth tag is suffixed to the ciphertext
28
- * */
29
- export declare function aesDecryptGCM(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array, additionalData: Uint8Array): Buffer
30
-
31
- export declare function aesEncryptCTR(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer
32
-
33
- export declare function aesDecryptCTR(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Buffer
34
-
35
- /** decrypt AES 256 CBC where the IV is prefixed to the buffer */
36
- export declare function aesDecrypt(buffer: Buffer, key: Buffer): Buffer
37
- /** decrypt AES 256 CBC */
38
-
39
- export declare function aesDecryptWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer
40
-
41
- export declare function aesEncrypt(buffer: Buffer | Uint8Array, key: Buffer): Buffer
42
-
43
- export declare function aesEncrypWithIV(buffer: Buffer, key: Buffer, IV: Buffer): Buffer
44
-
45
- export declare function hmacSign(buffer: Buffer | Uint8Array, key: Buffer | Uint8Array, variant?: 'sha256' | 'sha512'): Buffer
46
-
47
- export declare function sha256(buffer: Buffer): Buffer
48
-
49
- export declare function md5(buffer: Buffer): Buffer
50
-
51
- export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number, info: {
52
- salt?: Buffer
53
- info?: string
54
- }): Promise<Buffer>
55
-
56
- export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>
@@ -1,179 +0,0 @@
1
- "use strict"
2
-
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
8
- }
9
- Object.defineProperty(o, k2, desc)
10
- } : function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k
12
- o[k2] = m[k]
13
- })
14
-
15
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? function(o, v) {
16
- Object.defineProperty(o, "default", { enumerable: true, value: v })
17
- } : function(o, v) {
18
- o["default"] = v
19
- })
20
-
21
- var __importStar = (this && this.__importStar) || function(mod) {
22
- if (mod && mod.__esModule) return mod
23
- var result = {}
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
25
- __setModuleDefault(result, mod)
26
- return result
27
- }
28
-
29
- Object.defineProperty(exports, "__esModule", { value: true })
30
-
31
- const crypto_1 = require("crypto")
32
- const libsignal = __importStar(require("libsignal"))
33
- const Defaults_1 = require("../Defaults")
34
-
35
- const generateSignalPubKey = (pubKey) => (
36
- pubKey.length === 33 ? pubKey : Buffer.concat([Defaults_1.KEY_BUNDLE_TYPE, pubKey])
37
- )
38
-
39
- const Curve = {
40
- generateKeyPair: () => {
41
- const { pubKey, privKey } = libsignal.curve.generateKeyPair()
42
- return {
43
- private: Buffer.from(privKey),
44
- public: Buffer.from(pubKey.slice(1))
45
- }
46
- },
47
- sharedKey: (privateKey, publicKey) => {
48
- const shared = libsignal.curve.calculateAgreement(generateSignalPubKey(publicKey), privateKey)
49
- return Buffer.from(shared)
50
- },
51
- sign: (privateKey, buf) => libsignal.curve.calculateSignature(privateKey, buf),
52
- verify: (pubKey, message, signature) => {
53
- try {
54
- libsignal.curve.verifySignature(generateSignalPubKey(pubKey), message, signature)
55
- return true
56
- } catch {
57
- return false
58
- }
59
- }
60
- }
61
-
62
- const signedKeyPair = (identityKeyPair, keyId) => {
63
- const preKey = Curve.generateKeyPair()
64
- const pubKey = generateSignalPubKey(preKey.public)
65
- const signature = Curve.sign(identityKeyPair.private, pubKey)
66
- return { keyPair: preKey, signature, keyId }
67
- }
68
-
69
- const GCM_TAG_LENGTH = 128 >> 3
70
-
71
- function aesEncryptGCM(plaintext, key, iv, additionalData) {
72
- const cipher = crypto_1.createCipheriv('aes-256-gcm', key, iv)
73
- cipher.setAAD(additionalData)
74
- return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()])
75
- }
76
-
77
- function aesDecryptGCM(ciphertext, key, iv, additionalData) {
78
- const decipher = crypto_1.createDecipheriv('aes-256-gcm', key, iv)
79
- const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH)
80
- const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH)
81
- decipher.setAAD(additionalData)
82
- decipher.setAuthTag(tag)
83
- return Buffer.concat([decipher.update(enc), decipher.final()])
84
- }
85
-
86
- function aesEncryptCTR(plaintext, key, iv) {
87
- const cipher = crypto_1.createCipheriv('aes-256-ctr', key, iv)
88
- return Buffer.concat([cipher.update(plaintext), cipher.final()])
89
- }
90
-
91
- function aesDecryptCTR(ciphertext, key, iv) {
92
- const decipher = crypto_1.createDecipheriv('aes-256-ctr', key, iv)
93
- return Buffer.concat([decipher.update(ciphertext), decipher.final()])
94
- }
95
-
96
- function aesDecrypt(buffer, key) {
97
- return aesDecryptWithIV(buffer.slice(16), key, buffer.slice(0, 16))
98
- }
99
-
100
- function aesDecryptWithIV(buffer, key, IV) {
101
- const aes = crypto_1.createDecipheriv('aes-256-cbc', key, IV)
102
- return Buffer.concat([aes.update(buffer), aes.final()])
103
- }
104
-
105
- function aesEncrypt(buffer, key) {
106
- const IV = crypto_1.randomBytes(16)
107
- const aes = crypto_1.createCipheriv('aes-256-cbc', key, IV)
108
- return Buffer.concat([IV, aes.update(buffer), aes.final()])
109
- }
110
-
111
- function aesEncrypWithIV(buffer, key, IV) {
112
- const aes = crypto_1.createCipheriv('aes-256-cbc', key, IV)
113
- return Buffer.concat([aes.update(buffer), aes.final()])
114
- }
115
-
116
- function hmacSign(buffer, key, variant = 'sha256') {
117
- return crypto_1.createHmac(variant, key).update(buffer).digest()
118
- }
119
-
120
- function sha256(buffer) {
121
- return crypto_1.createHash('sha256').update(buffer).digest()
122
- }
123
-
124
- function md5(buffer) {
125
- return crypto_1.createHash('md5').update(buffer).digest()
126
- }
127
-
128
- async function hkdf(buffer, expandedLength, info) {
129
- const inputKeyMaterial = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer)
130
- const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0)
131
- const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0)
132
-
133
- const importedKey = await crypto_1.subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, ['deriveBits'])
134
-
135
- const derivedBits = await crypto_1.subtle.deriveBits({
136
- name: 'HKDF',
137
- hash: 'SHA-256',
138
- salt,
139
- info: infoBytes
140
- }, importedKey, expandedLength * 8)
141
-
142
- return Buffer.from(derivedBits)
143
- }
144
-
145
- async function derivePairingCodeKey(pairingCode, salt) {
146
- const encoder = new TextEncoder()
147
- const pairingCodeBuffer = encoder.encode(pairingCode)
148
- const saltBuffer = salt instanceof Uint8Array ? salt : new Uint8Array(salt)
149
-
150
- const keyMaterial = await crypto_1.subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, ['deriveBits'])
151
-
152
- const derivedBits = await crypto_1.subtle.deriveBits({
153
- name: 'PBKDF2',
154
- salt: saltBuffer,
155
- iterations: 2 << 16,
156
- hash: 'SHA-256'
157
- }, keyMaterial, 32 * 8)
158
-
159
- return Buffer.from(derivedBits)
160
- }
161
-
162
- module.exports = {
163
- generateSignalPubKey,
164
- Curve,
165
- signedKeyPair,
166
- aesEncryptGCM,
167
- aesDecryptGCM,
168
- aesEncryptCTR,
169
- aesDecryptCTR,
170
- aesDecrypt,
171
- aesDecryptWithIV,
172
- aesEncrypt,
173
- aesEncrypWithIV,
174
- hmacSign,
175
- sha256,
176
- md5,
177
- hkdf,
178
- derivePairingCodeKey
179
- }
@@ -1,41 +0,0 @@
1
- import { proto } from '../../WAProto'
2
- import { SignalRepository } from '../Types'
3
- import { BinaryNode } from '../WABinary'
4
- import { ILogger } from './logger'
5
-
6
- export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node"
7
-
8
- export declare const MISSING_KEYS_ERROR_TEXT = "Key used already or never filled"
9
-
10
- export declare const NACK_REASONS: {
11
- ParsingError: number
12
- UnrecognizedStanza: number
13
- UnrecognizedStanzaClass: number
14
- UnrecognizedStanzaType: number
15
- InvalidProtobuf: number
16
- InvalidHostedCompanionStanza: number
17
- MissingMessageSecret: number
18
- SignalErrorOldCounter: number
19
- MessageDeletedOnPeer: number
20
- UnhandledError: number
21
- UnsupportedAdminRevoke: number
22
- UnsupportedLIDGroup: number
23
- DBOperationFailed: number
24
- }
25
-
26
- /**
27
- * Decode the received node as a message.
28
- * @note this will only parse the message, not decrypt it
29
- */
30
- export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
31
- fullMessage: proto.IWebMessageInfo
32
- author: string
33
- sender: string
34
- }
35
-
36
- export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
37
- fullMessage: proto.IWebMessageInfo
38
- category: string
39
- author: string
40
- decrypt(): Promise<void>
41
- }
@@ -1,236 +0,0 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const boom_1 = require("@hapi/boom")
6
- const WAProto_1 = require("../../WAProto")
7
- const WABinary_1 = require("../WABinary")
8
- const generics_1 = require("./generics")
9
-
10
- const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
11
-
12
- const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled'
13
-
14
- const NACK_REASONS = {
15
- ParsingError: 487,
16
- UnrecognizedStanza: 488,
17
- UnrecognizedStanzaClass: 489,
18
- UnrecognizedStanzaType: 490,
19
- InvalidProtobuf: 491,
20
- InvalidHostedCompanionStanza: 493,
21
- MissingMessageSecret: 495,
22
- SignalErrorOldCounter: 496,
23
- MessageDeletedOnPeer: 499,
24
- UnhandledError: 500,
25
- UnsupportedAdminRevoke: 550,
26
- UnsupportedLIDGroup: 551,
27
- DBOperationFailed: 552
28
- }
29
-
30
- /**
31
- * Decode the received node as a message.
32
- * @note this will only parse the message, not decrypt it
33
- */
34
- function decodeMessageNode(stanza, meId, meLid) {
35
- let msgType
36
- let chatId
37
- let author
38
- const msgId = stanza.attrs.id
39
- const from = stanza.attrs.from
40
- const participant = stanza.attrs.participant
41
- const recipient = stanza.attrs.recipient
42
- const isMe = (jid) => WABinary_1.areJidsSameUser(jid, meId)
43
- const isMeLid = (jid) => WABinary_1.areJidsSameUser(jid, meLid)
44
- if (WABinary_1.isJidUser(from)) {
45
- if (recipient) {
46
- if (!isMe(from)) {
47
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
48
- }
49
- chatId = recipient
50
- }
51
- else {
52
- chatId = from
53
- }
54
- msgType = 'chat'
55
- author = from
56
- }
57
- else if (WABinary_1.isLidUser(from)) {
58
- if (recipient) {
59
- if (!isMeLid(from)) {
60
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
61
- }
62
- chatId = recipient
63
- }
64
- else {
65
- chatId = from
66
- }
67
- msgType = 'chat'
68
- author = from
69
- }
70
- else if (WABinary_1.isJidGroup(from)) {
71
- if (!participant) {
72
- throw new boom_1.Boom('No participant in group message')
73
- }
74
- msgType = 'group'
75
- author = participant
76
- chatId = from
77
- }
78
- else if (WABinary_1.isJidBroadcast(from)) {
79
- if (!participant) {
80
- throw new boom_1.Boom('No participant in group message')
81
- }
82
- const isParticipantMe = isMe(participant)
83
- if (WABinary_1.isJidStatusBroadcast(from)) {
84
- msgType = isParticipantMe ? 'direct_peer_status' : 'other_status'
85
- }
86
- else {
87
- msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast'
88
- }
89
- chatId = from
90
- author = participant
91
- }
92
- else if (WABinary_1.isJidNewsletter(from)) {
93
- msgType = 'newsletter'
94
- chatId = from
95
- author = from
96
- }
97
- else {
98
- throw new boom_1.Boom('Unknown message type', { data: stanza })
99
- }
100
- const fromMe = WABinary_1.isJidNewsletter(from) ? !!stanza.attrs?.is_sender : WABinary_1.isLidUser(from) ? isMeLid(stanza.attrs.participant || stanza.attrs.from) : isMe(stanza.attrs.participant || stanza.attrs.from)
101
- const pushname = stanza?.attrs?.notify
102
- const key = {
103
- remoteJid: chatId,
104
- fromMe,
105
- id: msgId,
106
- participant
107
- }
108
- const fullMessage = {
109
- key,
110
- messageTimestamp: +stanza.attrs.t,
111
- pushName: pushname,
112
- broadcast: WABinary_1.isJidBroadcast(from),
113
- newsletter: WABinary_1.isJidNewsletter(from)
114
- }
115
- if (msgType === 'newsletter') {
116
- fullMessage.newsletter_server_id = +stanza.attrs?.server_id
117
- }
118
- if (key.fromMe) {
119
- fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK
120
- }
121
- return {
122
- fullMessage,
123
- author,
124
- sender: msgType === 'chat' ? author : chatId
125
- }
126
- }
127
-
128
- const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
129
- const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid)
130
- return {
131
- fullMessage,
132
- category: stanza.attrs.category,
133
- author,
134
- async decrypt() {
135
- let decryptables = 0
136
- if (Array.isArray(stanza.content)) {
137
- for (const { tag, attrs, content } of stanza.content) {
138
- if (tag === 'verified_name' && content instanceof Uint8Array) {
139
- const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content)
140
- const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details)
141
- fullMessage.verifiedBizName = details.verifiedName
142
- }
143
- if (tag === 'multicast' && content instanceof Uint8Array) {
144
- fullMessage.multicast = true
145
- }
146
- if (tag === 'meta' && content instanceof Uint8Array) {
147
- fullMessage.metaInfo = {
148
- targetID: attrs.target_id
149
- }
150
- if (attrs.target_sender_jid) {
151
- fullMessage.metaInfo.targetSender = WABinary_1.jidNormalizedUser(attrs.target_sender_jid)
152
- }
153
- }
154
- if (tag === 'bot' && content instanceof Uint8Array) {
155
- if (attrs.edit) {
156
- fullMessage.botInfo = {
157
- editType: attrs.edit,
158
- editTargetID: attrs.edit_target_id,
159
- editSenderTimestampMS: attrs.sender_timestamp_ms
160
- }
161
- }
162
- }
163
- if (tag !== 'enc' && tag !== 'plaintext') {
164
- continue
165
- }
166
- if (!(content instanceof Uint8Array)) {
167
- continue
168
- }
169
- decryptables += 1
170
- let msgBuffer
171
- try {
172
- const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type
173
- switch (e2eType) {
174
- case 'skmsg':
175
- msgBuffer = await repository.decryptGroupMessage({
176
- group: sender,
177
- authorJid: author,
178
- msg: content
179
- })
180
- break
181
- case 'pkmsg':
182
- case 'msg':
183
- const user = WABinary_1.isJidUser(sender) ? sender : author
184
- msgBuffer = await repository.decryptMessage({
185
- jid: user,
186
- type: e2eType,
187
- ciphertext: content
188
- })
189
- break
190
- case 'plaintext':
191
- msgBuffer = content
192
- break
193
- default:
194
- throw new Error(`Unknown e2e type: ${e2eType}`)
195
- }
196
- let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? generics_1.unpadRandomMax16(msgBuffer) : msgBuffer)
197
- msg = msg.deviceSentMessage?.message || msg
198
- if (msg.senderKeyDistributionMessage) {
199
- //eslint-disable-next-line max-depth
200
- try {
201
- await repository.processSenderKeyDistributionMessage({
202
- authorJid: author,
203
- item: msg.senderKeyDistributionMessage
204
- })
205
- }
206
- catch (err) {
207
- logger.error({ key: fullMessage.key, err }, 'failed to decrypt message')
208
- }
209
- }
210
- if (fullMessage.message) {
211
- Object.assign(fullMessage.message, msg)
212
- }
213
- else {
214
- fullMessage.message = msg
215
- }
216
- }
217
- catch (err) {
218
- logger.error({ key: fullMessage.key, err }, 'failed to decrypt message')
219
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
220
- fullMessage.messageStubParameters = [err.message]
221
- }
222
- }
223
- }
224
- // if nothing was found to decrypt
225
- if (!decryptables) {
226
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
227
- fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT]
228
- }
229
- }
230
- }
231
- }
232
-
233
- module.exports = {
234
- decodeMessageNode,
235
- decryptMessageNode
236
- }
@@ -1,39 +0,0 @@
1
- import { BaileysEventEmitter, BaileysEventMap } from '../Types'
2
- import { ILogger } from './logger'
3
-
4
- /**
5
- * A map that contains a list of all events that have been triggered
6
- *
7
- * Note, this can contain different type of events
8
- * this can make processing events extremely efficient -- since everything
9
- * can be done in a single transaction
10
- */
11
- type BaileysEventData = Partial<BaileysEventMap>
12
-
13
- type BaileysBufferableEventEmitter = BaileysEventEmitter & {
14
- /** Use to process events in a batch */
15
- process(handler: (events: BaileysEventData) => void | Promise<void>): (() => void)
16
- /**
17
- * starts buffering events, call flush() to release them
18
- * */
19
- buffer(): void
20
- /** buffers all events till the promise completes */
21
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>)
22
- /**
23
- * flushes all buffered events
24
- * @param force if true, will flush all data regardless of any pending buffers
25
- * @returns returns true if the flush actually happened, otherwise false
26
- */
27
- flush(force?: boolean): boolean
28
- /** is there an ongoing buffer */
29
- isBuffering(): boolean
30
- }
31
-
32
- /**
33
- * The event buffer logically consolidates different events into a single event
34
- * making the data processing more efficient.
35
- * @param ev the baileys event emitter
36
- */
37
- export declare const makeEventBuffer: (logger: ILogger) => BaileysBufferableEventEmitter
38
-
39
- export {}