@neelegirl/baileys 1.5.3 → 1.5.5

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 (224) hide show
  1. package/README.md +16 -195
  2. package/index.js +38 -0
  3. package/package.json +16 -96
  4. package/LICENSE +0 -21
  5. package/WAProto/WAProto.proto +0 -5308
  6. package/WAProto/index.d.ts +0 -61295
  7. package/WAProto/index.js +0 -189754
  8. package/lib/Defaults/baileys-version.json +0 -3
  9. package/lib/Defaults/index.d.ts +0 -78
  10. package/lib/Defaults/index.js +0 -149
  11. package/lib/Defaults/phonenumber-mcc.json +0 -223
  12. package/lib/Signal/WASignalGroup/GroupProtocol.js +0 -1909
  13. package/lib/Signal/WASignalGroup/ciphertext-message.d.ts +0 -9
  14. package/lib/Signal/WASignalGroup/ciphertext-message.js +0 -19
  15. package/lib/Signal/WASignalGroup/ciphertext_message.js +0 -16
  16. package/lib/Signal/WASignalGroup/generate-proto.sh +0 -1
  17. package/lib/Signal/WASignalGroup/group-session-builder.d.ts +0 -17
  18. package/lib/Signal/WASignalGroup/group-session-builder.js +0 -72
  19. package/lib/Signal/WASignalGroup/group.proto +0 -42
  20. package/lib/Signal/WASignalGroup/group_cipher.d.ts +0 -19
  21. package/lib/Signal/WASignalGroup/group_cipher.js +0 -111
  22. package/lib/Signal/WASignalGroup/group_session_builder.js +0 -46
  23. package/lib/Signal/WASignalGroup/index.d.ts +0 -11
  24. package/lib/Signal/WASignalGroup/index.js +0 -61
  25. package/lib/Signal/WASignalGroup/keyhelper.d.ts +0 -16
  26. package/lib/Signal/WASignalGroup/keyhelper.js +0 -66
  27. package/lib/Signal/WASignalGroup/protobufs.js +0 -3
  28. package/lib/Signal/WASignalGroup/queue_job.js +0 -69
  29. package/lib/Signal/WASignalGroup/readme.md +0 -6
  30. package/lib/Signal/WASignalGroup/sender-chain-key.d.ts +0 -14
  31. package/lib/Signal/WASignalGroup/sender-chain-key.js +0 -47
  32. package/lib/Signal/WASignalGroup/sender-key-distribution-message.d.ts +0 -17
  33. package/lib/Signal/WASignalGroup/sender-key-distribution-message.js +0 -71
  34. package/lib/Signal/WASignalGroup/sender-key-message.d.ts +0 -19
  35. package/lib/Signal/WASignalGroup/sender-key-message.js +0 -73
  36. package/lib/Signal/WASignalGroup/sender-key-name.d.ts +0 -19
  37. package/lib/Signal/WASignalGroup/sender-key-name.js +0 -59
  38. package/lib/Signal/WASignalGroup/sender-key-record.d.ts +0 -32
  39. package/lib/Signal/WASignalGroup/sender-key-record.js +0 -58
  40. package/lib/Signal/WASignalGroup/sender-key-state.d.ts +0 -44
  41. package/lib/Signal/WASignalGroup/sender-key-state.js +0 -147
  42. package/lib/Signal/WASignalGroup/sender-message-key.d.ts +0 -11
  43. package/lib/Signal/WASignalGroup/sender-message-key.js +0 -33
  44. package/lib/Signal/WASignalGroup/sender_chain_key.js +0 -50
  45. package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +0 -78
  46. package/lib/Signal/WASignalGroup/sender_key_message.js +0 -92
  47. package/lib/Signal/WASignalGroup/sender_key_name.js +0 -70
  48. package/lib/Signal/WASignalGroup/sender_key_record.js +0 -56
  49. package/lib/Signal/WASignalGroup/sender_key_state.js +0 -129
  50. package/lib/Signal/WASignalGroup/sender_message_key.js +0 -39
  51. package/lib/Signal/libsignal.d.ts +0 -8
  52. package/lib/Signal/libsignal.js +0 -391
  53. package/lib/Signal/lid-mapping.d.ts +0 -28
  54. package/lib/Signal/lid-mapping.js +0 -184
  55. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
  56. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  57. package/lib/Socket/Client/index.d.ts +0 -2
  58. package/lib/Socket/Client/index.js +0 -22
  59. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
  60. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  61. package/lib/Socket/Client/types.d.ts +0 -16
  62. package/lib/Socket/Client/types.js +0 -18
  63. package/lib/Socket/Client/websocket.d.ts +0 -13
  64. package/lib/Socket/Client/websocket.js +0 -62
  65. package/lib/Socket/business.d.ts +0 -187
  66. package/lib/Socket/business.js +0 -415
  67. package/lib/Socket/chats.d.ts +0 -97
  68. package/lib/Socket/chats.js +0 -1118
  69. package/lib/Socket/communities.d.ts +0 -223
  70. package/lib/Socket/communities.js +0 -433
  71. package/lib/Socket/groups.d.ts +0 -129
  72. package/lib/Socket/groups.js +0 -360
  73. package/lib/Socket/index.d.ts +0 -191
  74. package/lib/Socket/index.js +0 -24
  75. package/lib/Socket/messages-recv.d.ts +0 -174
  76. package/lib/Socket/messages-recv.js +0 -1506
  77. package/lib/Socket/messages-send.d.ts +0 -165
  78. package/lib/Socket/messages-send.js +0 -1785
  79. package/lib/Socket/mex.d.ts +0 -2
  80. package/lib/Socket/mex.js +0 -47
  81. package/lib/Socket/newsletter.d.ts +0 -145
  82. package/lib/Socket/newsletter.js +0 -295
  83. package/lib/Socket/socket.d.ts +0 -45
  84. package/lib/Socket/socket.js +0 -934
  85. package/lib/Socket/usync.d.ts +0 -37
  86. package/lib/Socket/usync.js +0 -83
  87. package/lib/Store/index.d.ts +0 -4
  88. package/lib/Store/index.js +0 -24
  89. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  90. package/lib/Store/make-cache-manager-store.js +0 -90
  91. package/lib/Store/make-in-memory-store.d.ts +0 -123
  92. package/lib/Store/make-in-memory-store.js +0 -429
  93. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  94. package/lib/Store/make-ordered-dictionary.js +0 -86
  95. package/lib/Store/object-repository.d.ts +0 -10
  96. package/lib/Store/object-repository.js +0 -31
  97. package/lib/Types/Auth.d.ts +0 -121
  98. package/lib/Types/Auth.js +0 -3
  99. package/lib/Types/Bussines.js +0 -3
  100. package/lib/Types/Bussiness.d.ts +0 -28
  101. package/lib/Types/Call.d.ts +0 -14
  102. package/lib/Types/Call.js +0 -3
  103. package/lib/Types/Chat.d.ts +0 -143
  104. package/lib/Types/Chat.js +0 -9
  105. package/lib/Types/Contact.d.ts +0 -23
  106. package/lib/Types/Contact.js +0 -3
  107. package/lib/Types/Events.d.ts +0 -226
  108. package/lib/Types/Events.js +0 -3
  109. package/lib/Types/GroupMetadata.d.ts +0 -66
  110. package/lib/Types/GroupMetadata.js +0 -3
  111. package/lib/Types/Label.d.ts +0 -48
  112. package/lib/Types/Label.js +0 -31
  113. package/lib/Types/LabelAssociation.d.ts +0 -35
  114. package/lib/Types/LabelAssociation.js +0 -13
  115. package/lib/Types/Message.d.ts +0 -484
  116. package/lib/Types/Message.js +0 -19
  117. package/lib/Types/MexUpdates.d.ts +0 -9
  118. package/lib/Types/MexUpdates.js +0 -18
  119. package/lib/Types/Newsletter.d.ts +0 -109
  120. package/lib/Types/Newsletter.js +0 -40
  121. package/lib/Types/Product.d.ts +0 -92
  122. package/lib/Types/Product.js +0 -3
  123. package/lib/Types/Signal.d.ts +0 -98
  124. package/lib/Types/Signal.js +0 -3
  125. package/lib/Types/Socket.d.ts +0 -141
  126. package/lib/Types/Socket.js +0 -3
  127. package/lib/Types/State.d.ts +0 -41
  128. package/lib/Types/State.js +0 -14
  129. package/lib/Types/USync.d.ts +0 -26
  130. package/lib/Types/USync.js +0 -3
  131. package/lib/Types/index.d.ts +0 -80
  132. package/lib/Types/index.js +0 -50
  133. package/lib/Utils/auth-utils.d.ts +0 -21
  134. package/lib/Utils/auth-utils.js +0 -528
  135. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  136. package/lib/Utils/baileys-event-stream.js +0 -70
  137. package/lib/Utils/business.d.ts +0 -29
  138. package/lib/Utils/business.js +0 -255
  139. package/lib/Utils/chat-utils.d.ts +0 -82
  140. package/lib/Utils/chat-utils.js +0 -809
  141. package/lib/Utils/crypto.d.ts +0 -56
  142. package/lib/Utils/crypto.js +0 -189
  143. package/lib/Utils/decode-wa-message.d.ts +0 -53
  144. package/lib/Utils/decode-wa-message.js +0 -323
  145. package/lib/Utils/event-buffer.d.ts +0 -39
  146. package/lib/Utils/event-buffer.js +0 -595
  147. package/lib/Utils/generics.d.ts +0 -131
  148. package/lib/Utils/generics.js +0 -630
  149. package/lib/Utils/history.d.ts +0 -23
  150. package/lib/Utils/history.js +0 -104
  151. package/lib/Utils/index.d.ts +0 -20
  152. package/lib/Utils/index.js +0 -40
  153. package/lib/Utils/link-preview.d.ts +0 -23
  154. package/lib/Utils/link-preview.js +0 -120
  155. package/lib/Utils/logger.d.ts +0 -13
  156. package/lib/Utils/logger.js +0 -7
  157. package/lib/Utils/lt-hash.d.ts +0 -14
  158. package/lib/Utils/lt-hash.js +0 -58
  159. package/lib/Utils/make-mutex.d.ts +0 -9
  160. package/lib/Utils/make-mutex.js +0 -49
  161. package/lib/Utils/message-retry-manager.d.ts +0 -88
  162. package/lib/Utils/message-retry-manager.js +0 -160
  163. package/lib/Utils/messages-media.d.ts +0 -135
  164. package/lib/Utils/messages-media.js +0 -869
  165. package/lib/Utils/messages.d.ts +0 -105
  166. package/lib/Utils/messages.js +0 -1745
  167. package/lib/Utils/noise-handler.d.ts +0 -21
  168. package/lib/Utils/noise-handler.js +0 -165
  169. package/lib/Utils/process-message.d.ts +0 -49
  170. package/lib/Utils/process-message.js +0 -427
  171. package/lib/Utils/signal.d.ts +0 -42
  172. package/lib/Utils/signal.js +0 -166
  173. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  174. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  175. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -18
  176. package/lib/Utils/use-multi-file-auth-state.js +0 -238
  177. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  178. package/lib/Utils/use-single-file-auth-state.js +0 -80
  179. package/lib/Utils/validate-connection.d.ts +0 -13
  180. package/lib/Utils/validate-connection.js +0 -220
  181. package/lib/WABinary/constants.d.ts +0 -30
  182. package/lib/WABinary/constants.js +0 -1316
  183. package/lib/WABinary/decode.d.ts +0 -9
  184. package/lib/WABinary/decode.js +0 -288
  185. package/lib/WABinary/encode.d.ts +0 -3
  186. package/lib/WABinary/encode.js +0 -265
  187. package/lib/WABinary/generic-utils.d.ts +0 -28
  188. package/lib/WABinary/generic-utils.js +0 -142
  189. package/lib/WABinary/index.d.ts +0 -5
  190. package/lib/WABinary/index.js +0 -25
  191. package/lib/WABinary/jid-utils.d.ts +0 -58
  192. package/lib/WABinary/jid-utils.js +0 -104
  193. package/lib/WABinary/types.d.ts +0 -22
  194. package/lib/WABinary/types.js +0 -3
  195. package/lib/WAM/BinaryInfo.d.ts +0 -16
  196. package/lib/WAM/BinaryInfo.js +0 -17
  197. package/lib/WAM/constants.d.ts +0 -47
  198. package/lib/WAM/constants.js +0 -15371
  199. package/lib/WAM/encode.d.ts +0 -3
  200. package/lib/WAM/encode.js +0 -164
  201. package/lib/WAM/index.d.ts +0 -3
  202. package/lib/WAM/index.js +0 -23
  203. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  204. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
  205. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  206. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -36
  207. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  208. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -62
  209. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  210. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -35
  211. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  212. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -38
  213. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  214. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -46
  215. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  216. package/lib/WAUSync/Protocols/index.js +0 -26
  217. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  218. package/lib/WAUSync/USyncQuery.js +0 -92
  219. package/lib/WAUSync/USyncUser.d.ts +0 -12
  220. package/lib/WAUSync/USyncUser.js +0 -30
  221. package/lib/WAUSync/index.d.ts +0 -3
  222. package/lib/WAUSync/index.js +0 -23
  223. package/lib/index.d.ts +0 -13
  224. package/lib/index.js +0 -33
@@ -1,56 +0,0 @@
1
- import { KeyPair } from '@neelegirl/baileys/lib/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,189 +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("@neelegirl/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
- // Normalize to a Uint8Array whose underlying buffer is a regular ArrayBuffer (not ArrayBufferLike)
130
- // Cloning via new Uint8Array(...) guarantees the generic parameter is ArrayBuffer which satisfies WebCrypto types.
131
- const inputKeyMaterial = new Uint8Array(buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer))
132
-
133
- // Set default values if not provided
134
- const salt = info.salt ? new Uint8Array(info.salt) : new Uint8Array(0)
135
- const infoBytes = info.info ? new TextEncoder().encode(info.info) : new Uint8Array(0)
136
-
137
- // Import the input key material (cast to BufferSource to appease TS DOM typings)
138
- const importedKey = await crypto.subtle.importKey('raw', inputKeyMaterial, { name: 'HKDF' }, false, [
139
- 'deriveBits'
140
- ])
141
-
142
- const derivedBits = await crypto.subtle.deriveBits({
143
- name: 'HKDF',
144
- hash: 'SHA-256',
145
- salt,
146
- info: infoBytes
147
- }, importedKey, expandedLength * 8)
148
-
149
- return Buffer.from(derivedBits)
150
- }
151
-
152
- async function derivePairingCodeKey(pairingCode, salt) {
153
- const encoder = new TextEncoder()
154
- const pairingCodeBuffer = encoder.encode(pairingCode)
155
- const saltBuffer = new Uint8Array(salt instanceof Uint8Array ? salt : new Uint8Array(salt))
156
-
157
- // Import the pairing code as key material
158
- const keyMaterial = await crypto.subtle.importKey('raw', pairingCodeBuffer, { name: 'PBKDF2' }, false, [
159
- 'deriveBits'
160
- ])
161
-
162
- const derivedBits = await crypto.subtle.deriveBits({
163
- name: 'PBKDF2',
164
- salt: saltBuffer,
165
- iterations: 2 << 16,
166
- hash: 'SHA-256'
167
- }, keyMaterial, 32 * 8)
168
-
169
- return Buffer.from(derivedBits)
170
- }
171
-
172
- module.exports = {
173
- generateSignalPubKey,
174
- Curve,
175
- signedKeyPair,
176
- aesEncryptGCM,
177
- aesDecryptGCM,
178
- aesEncryptCTR,
179
- aesDecryptCTR,
180
- aesDecrypt,
181
- aesDecryptWithIV,
182
- aesEncrypt,
183
- aesEncrypWithIV,
184
- hmacSign,
185
- sha256,
186
- md5,
187
- hkdf,
188
- derivePairingCodeKey
189
- }
@@ -1,53 +0,0 @@
1
- import { proto } from '@neelegirl/baileys/WAProto'
2
- import { SignalRepository } from '@neelegirl/baileys/lib/Types'
3
- import { BinaryNode } from '@neelegirl/baileys/lib/WABinary'
4
- import { ILogger } from '@neelegirl/baileys/lib/Utils/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 DECRYPTION_RETRY_CONFIG: {
11
- maxRetries: number
12
- baseDelayMs: number
13
- sessionRecordErrors: string[]
14
- }
15
-
16
- export declare const NACK_REASONS: {
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
- export declare const extractAddressingContext: (stanza: BinaryNode) => {
33
- addressingMode: string
34
- senderAlt: string | undefined
35
- recipientAlt: string | undefined
36
- }
37
-
38
- /**
39
- * Decode the received node as a message.
40
- * @note this will only parse the message, not decrypt it
41
- */
42
- export declare function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: string): {
43
- fullMessage: proto.IWebMessageInfo
44
- author: string
45
- sender: string
46
- }
47
-
48
- export declare const decryptMessageNode: (stanza: BinaryNode, meId: string, meLid: string, repository: SignalRepository, logger: ILogger) => {
49
- fullMessage: proto.IWebMessageInfo
50
- category: string
51
- author: string
52
- decrypt(): Promise<void>
53
- }
@@ -1,323 +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
- const messages_1 = require("./messages")
10
-
11
- const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
12
-
13
- const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled'
14
-
15
- // Retry configuration for failed decryption
16
- const DECRYPTION_RETRY_CONFIG = {
17
- maxRetries: 3,
18
- baseDelayMs: 100,
19
- sessionRecordErrors: ['No session record', 'SessionError: No session record']
20
- }
21
-
22
- const NACK_REASONS = {
23
- ParsingError: 487,
24
- UnrecognizedStanza: 488,
25
- UnrecognizedStanzaClass: 489,
26
- UnrecognizedStanzaType: 490,
27
- InvalidProtobuf: 491,
28
- InvalidHostedCompanionStanza: 493,
29
- MissingMessageSecret: 495,
30
- SignalErrorOldCounter: 496,
31
- MessageDeletedOnPeer: 499,
32
- UnhandledError: 500,
33
- UnsupportedAdminRevoke: 550,
34
- UnsupportedLIDGroup: 551,
35
- DBOperationFailed: 552
36
- }
37
-
38
- const extractAddressingContext = (stanza) => {
39
- let senderAlt
40
- let recipientAlt
41
-
42
- const sender = stanza.attrs.participant || stanza.attrs.from
43
- const addressingMode = stanza.attrs.addressing_mode || (sender?.endsWith('lid') ? 'lid' : 'pn')
44
-
45
- if (WABinary_1.isLidUser(sender)) {
46
- // Message is LID-addressed: sender is LID, extract corresponding PN
47
- // without device data
48
- senderAlt = stanza.attrs.participant_pn || stanza.attrs.sender_pn || stanza.attrs.peer_recipient_pn
49
- recipientAlt = stanza.attrs.recipient_pn
50
- // with device data
51
- if (sender && senderAlt)
52
- senderAlt = WABinary_1.transferDevice(sender, senderAlt)
53
- }
54
-
55
- else if (WABinary_1.isJidUser(sender)) {
56
- // Message is PN-addressed: sender is PN, extract corresponding LID
57
- // without device data
58
- senderAlt = stanza.attrs.participant_lid || stanza.attrs.sender_lid || stanza.attrs.peer_recipient_lid
59
- recipientAlt = stanza.attrs.recipient_lid
60
- //with device data
61
- if (sender && senderAlt)
62
- senderAlt = WABinary_1.transferDevice(sender, senderAlt)
63
- }
64
- return {
65
- addressingMode,
66
- senderAlt,
67
- recipientAlt
68
- }
69
- }
70
-
71
- const getDecryptionJid = async (sender, repository) => {
72
- if (!sender.includes('@s.whatsapp.net')) {
73
- return sender
74
- }
75
- return (await repository.lidMapping.getLIDForPN(sender))
76
- }
77
-
78
- const storeMappingFromEnvelope = async (stanza, sender, decryptionJid, repository, logger) => {
79
- const { senderAlt } = extractAddressingContext(stanza)
80
-
81
- if (senderAlt && WABinary_1.isLidUser(senderAlt) && WABinary_1.isJidUser(sender) && decryptionJid === sender) {
82
- try {
83
- await repository.lidMapping.storeLIDPNMappings([{ lid: senderAlt, pn: sender }])
84
- logger.debug({ sender, senderAlt }, 'Stored LID mapping from envelope')
85
- }
86
- catch (error) {
87
- logger.warn({ sender, senderAlt, error }, 'Failed to store LID mapping')
88
- }
89
- }
90
- }
91
-
92
- /**
93
- * Decode the received node as a message.
94
- * @note this will only parse the message, not decrypt it
95
- */
96
- function decodeMessageNode(stanza, meId, meLid) {
97
- let msgType
98
- let chatId
99
- let author
100
- const msgId = stanza.attrs.id
101
- const from = stanza.attrs.from
102
- const participant = stanza.attrs.participant
103
- const recipient = stanza.attrs.recipient
104
- const addressingContext = extractAddressingContext(stanza)
105
- const isMe = (jid) => WABinary_1.areJidsSameUser(jid, meId)
106
- const isMeLid = (jid) => WABinary_1.areJidsSameUser(jid, meLid)
107
- if (WABinary_1.isJidUser(from)) {
108
- if (recipient) {
109
- if (!isMe(from)) {
110
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
111
- }
112
- chatId = recipient
113
- }
114
- else {
115
- chatId = from
116
- }
117
- msgType = 'chat'
118
- author = from
119
- }
120
- else if (WABinary_1.isLidUser(from)) {
121
- if (recipient) {
122
- if (!isMeLid(from)) {
123
- throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza })
124
- }
125
- chatId = recipient
126
- }
127
- else {
128
- chatId = from
129
- }
130
- msgType = 'chat'
131
- author = from
132
- }
133
- else if (WABinary_1.isJidGroup(from)) {
134
- if (!participant) {
135
- throw new boom_1.Boom('No participant in group message')
136
- }
137
- msgType = 'group'
138
- author = participant
139
- chatId = from
140
- }
141
- else if (WABinary_1.isJidBroadcast(from)) {
142
- if (!participant) {
143
- throw new boom_1.Boom('No participant in group message')
144
- }
145
- const isParticipantMe = isMe(participant)
146
- if (WABinary_1.isJidStatusBroadcast(from)) {
147
- msgType = isParticipantMe ? 'direct_peer_status' : 'other_status'
148
- }
149
- else {
150
- msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast'
151
- }
152
- chatId = from
153
- author = participant
154
- }
155
- else if (WABinary_1.isJidNewsletter(from)) {
156
- msgType = 'newsletter'
157
- chatId = from
158
- author = from
159
- }
160
- else {
161
- throw new boom_1.Boom('Unknown message type', { data: stanza })
162
- }
163
- // 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)
164
- const senderJid = stanza.attrs.participant || stanza.attrs.from;
165
-
166
- const fromMe = WABinary_1.isJidNewsletter(stanza.attrs.from)
167
- ? !!stanza.attrs?.is_sender
168
- : WABinary_1.isLidUser(senderJid)
169
- ? (0, WABinary_1.areJidsSameUser)(senderJid, meLid)
170
- : (0, WABinary_1.areJidsSameUser)(senderJid, meId);
171
- const pushname = stanza?.attrs?.notify
172
- const key = {
173
- remoteJid: chatId,
174
- remoteJidAlt: !WABinary_1.isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
175
- fromMe,
176
- id: msgId,
177
- participant,
178
- participantAlt: WABinary_1.isJidGroup(chatId) ? addressingContext.senderAlt : undefined,
179
- }
180
- const fullMessage = {
181
- key,
182
- messageTimestamp: +stanza.attrs.t,
183
- pushName: pushname,
184
- broadcast: WABinary_1.isJidBroadcast(from),
185
- newsletter: WABinary_1.isJidNewsletter(from),
186
- additionalAttributes: stanza.attrs,
187
- Owner: "Baron" // Non-WhatsApp attribute
188
- }
189
- if (msgType === 'newsletter') {
190
- fullMessage.newsletter_server_id = +stanza.attrs?.server_id
191
- }
192
- if (key.fromMe) {
193
- fullMessage.status = WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK
194
- }
195
- if (!key.fromMe) {
196
- fullMessage.platform = messages_1.getDevice(key.id)
197
- }
198
- return {
199
- fullMessage,
200
- author,
201
- sender: msgType === 'chat' ? author : chatId
202
- }
203
- }
204
-
205
- const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
206
- const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid)
207
- return {
208
- fullMessage,
209
- category: stanza.attrs.category,
210
- author,
211
- async decrypt() {
212
- let decryptables = 0
213
- if (Array.isArray(stanza.content)) {
214
- for (const { tag, attrs, content } of stanza.content) {
215
- if (tag === 'verified_name' && content instanceof Uint8Array) {
216
- const cert = WAProto_1.proto.VerifiedNameCertificate.decode(content)
217
- const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details)
218
- fullMessage.verifiedBizName = details.verifiedName
219
- }
220
- if (tag === 'unavailable' && attrs.type === 'view_once') {
221
- fullMessage.key.isViewOnce = true; // TODO: remove from here and add a STUB TYPE
222
- }
223
- if (tag !== 'enc' && tag !== 'plaintext') {
224
- continue
225
- }
226
- if (!(content instanceof Uint8Array)) {
227
- continue
228
- }
229
- decryptables += 1
230
- let msgBuffer
231
- const user = WABinary_1.isJidUser(sender) ? sender : author // TODO: flaky logic
232
- const decryptionJid = await getDecryptionJid(user, repository)
233
-
234
- if (tag !== 'plaintext') {
235
- await storeMappingFromEnvelope(stanza, user, decryptionJid, repository, logger)
236
- }
237
- try {
238
- const e2eType = tag === 'plaintext' ? 'plaintext' : attrs.type
239
- switch (e2eType) {
240
- case 'skmsg':
241
- msgBuffer = await repository.decryptGroupMessage({
242
- group: sender,
243
- authorJid: author,
244
- msg: content
245
- })
246
- break
247
- case 'pkmsg':
248
- case 'msg':
249
- msgBuffer = await repository.decryptMessage({
250
- jid: decryptionJid,
251
- type: e2eType,
252
- ciphertext: content
253
- })
254
- break
255
- case 'plaintext':
256
- msgBuffer = content
257
- break
258
- default:
259
- throw new Error(`Unknown e2e type: ${e2eType}`)
260
- }
261
- let msg = WAProto_1.proto.Message.decode(e2eType !== 'plaintext' ? generics_1.unpadRandomMax16(msgBuffer) : msgBuffer)
262
- msg = msg.deviceSentMessage?.message || msg
263
- if (msg.senderKeyDistributionMessage) {
264
- //eslint-disable-next-line max-depth
265
- try {
266
- await repository.processSenderKeyDistributionMessage({
267
- authorJid: author,
268
- item: msg.senderKeyDistributionMessage
269
- })
270
- }
271
- catch (err) {
272
- logger.error({ key: fullMessage.key, err }, 'failed to decrypt message')
273
- }
274
- }
275
- if (fullMessage.message) {
276
- Object.assign(fullMessage.message, msg)
277
- }
278
- else {
279
- fullMessage.message = msg
280
- }
281
- }
282
- catch (err) {
283
- const errorContext = {
284
- key: fullMessage.key,
285
- err,
286
- messageType: tag === 'plaintext' ? 'plaintext' : attrs.type,
287
- sender,
288
- author,
289
- isSessionRecordError: isSessionRecordError(err)
290
- }
291
- logger.error(errorContext, 'failed to process sender key distribution message')
292
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
293
- fullMessage.messageStubParameters = [err.message.toString()]
294
- }
295
- }
296
- }
297
-
298
- // if nothing was found to decrypt
299
- if (!decryptables) {
300
- fullMessage.messageStubType = WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT
301
- fullMessage.messageStubParameters = [NO_MESSAGE_FOUND_ERROR_TEXT]
302
- }
303
- }
304
- }
305
- }
306
-
307
- /**
308
- * Utility function to check if an error is related to missing session record
309
- */
310
- function isSessionRecordError(error) {
311
- const errorMessage = error?.message || error?.toString() || ''
312
- return DECRYPTION_RETRY_CONFIG.sessionRecordErrors.some(errorPattern => errorMessage.includes(errorPattern))
313
- }
314
-
315
- module.exports = {
316
- NACK_REASONS,
317
- decodeMessageNode,
318
- decryptMessageNode,
319
- extractAddressingContext,
320
- MISSING_KEYS_ERROR_TEXT,
321
- DECRYPTION_RETRY_CONFIG,
322
- NO_MESSAGE_FOUND_ERROR_TEXT
323
- }
@@ -1,39 +0,0 @@
1
- import { BaileysEventEmitter, BaileysEventMap } from '@neelegirl/baileys/lib/Types'
2
- import { ILogger } from '@neelegirl/baileys/lib/Utils/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 {}