dcodeindra-baileyspro 2.3.9

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 (286) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2534 -0
  3. package/WAProto/Adv/Adv.d.ts +518 -0
  4. package/WAProto/Adv/Adv.js +1734 -0
  5. package/WAProto/Adv/Adv.proto +36 -0
  6. package/WAProto/BotMetadata/BotMetadata.d.ts +5745 -0
  7. package/WAProto/BotMetadata/BotMetadata.js +16291 -0
  8. package/WAProto/BotMetadata/BotMetadata.proto +463 -0
  9. package/WAProto/Cert/Cert.d.ts +497 -0
  10. package/WAProto/Cert/Cert.js +1503 -0
  11. package/WAProto/Cert/Cert.proto +28 -0
  12. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +391 -0
  13. package/WAProto/ChatLockSettings/ChatLockSettings.js +1155 -0
  14. package/WAProto/ChatLockSettings/ChatLockSettings.proto +7 -0
  15. package/WAProto/CompanionReg/CompanionReg.d.ts +1055 -0
  16. package/WAProto/CompanionReg/CompanionReg.js +3532 -0
  17. package/WAProto/CompanionReg/CompanionReg.proto +89 -0
  18. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +187 -0
  19. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +520 -0
  20. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +14 -0
  21. package/WAProto/E2E/E2E.d.ts +28417 -0
  22. package/WAProto/E2E/E2E.js +98438 -0
  23. package/WAProto/E2E/E2E.proto +2289 -0
  24. package/WAProto/Ephemeral/Ephemeral.d.ts +95 -0
  25. package/WAProto/Ephemeral/Ephemeral.js +269 -0
  26. package/WAProto/Ephemeral/Ephemeral.proto +6 -0
  27. package/WAProto/HistorySync/HistorySync.d.ts +40728 -0
  28. package/WAProto/HistorySync/HistorySync.js +142980 -0
  29. package/WAProto/HistorySync/HistorySync.proto +207 -0
  30. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +189 -0
  31. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +585 -0
  32. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +11 -0
  33. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +461 -0
  34. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +1559 -0
  35. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +37 -0
  36. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +29294 -0
  37. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +101732 -0
  38. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +76 -0
  39. package/WAProto/MmsRetry/MmsRetry.d.ts +200 -0
  40. package/WAProto/MmsRetry/MmsRetry.js +586 -0
  41. package/WAProto/MmsRetry/MmsRetry.proto +17 -0
  42. package/WAProto/Protocol/Protocol.d.ts +218 -0
  43. package/WAProto/Protocol/Protocol.js +701 -0
  44. package/WAProto/Protocol/Protocol.proto +20 -0
  45. package/WAProto/Reporting/Reporting.d.ts +301 -0
  46. package/WAProto/Reporting/Reporting.js +989 -0
  47. package/WAProto/Reporting/Reporting.proto +19 -0
  48. package/WAProto/ServerSync/ServerSync.d.ts +1050 -0
  49. package/WAProto/ServerSync/ServerSync.js +3176 -0
  50. package/WAProto/ServerSync/ServerSync.proto +59 -0
  51. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +1507 -0
  52. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +4756 -0
  53. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +88 -0
  54. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +617 -0
  55. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1940 -0
  56. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +38 -0
  57. package/WAProto/StatusAttributions/StatusAttributions.d.ts +636 -0
  58. package/WAProto/StatusAttributions/StatusAttributions.js +2037 -0
  59. package/WAProto/StatusAttributions/StatusAttributions.proto +61 -0
  60. package/WAProto/SyncAction/SyncAction.d.ts +7227 -0
  61. package/WAProto/SyncAction/SyncAction.js +22271 -0
  62. package/WAProto/SyncAction/SyncAction.proto +423 -0
  63. package/WAProto/UserPassword/UserPassword.d.ts +298 -0
  64. package/WAProto/UserPassword/UserPassword.js +898 -0
  65. package/WAProto/UserPassword/UserPassword.proto +27 -0
  66. package/WAProto/VnameCert/VnameCert.d.ts +658 -0
  67. package/WAProto/VnameCert/VnameCert.js +2225 -0
  68. package/WAProto/VnameCert/VnameCert.proto +60 -0
  69. package/WAProto/Wa6/Wa6.d.ts +1613 -0
  70. package/WAProto/Wa6/Wa6.js +6299 -0
  71. package/WAProto/Wa6/Wa6.proto +229 -0
  72. package/WAProto/Web/Web.d.ts +31718 -0
  73. package/WAProto/Web/Web.js +113402 -0
  74. package/WAProto/Web/Web.proto +545 -0
  75. package/WAProto/index.d.ts +49 -0
  76. package/WAProto/index.js +28 -0
  77. package/WASignalGroup/GroupProtocol.js +1771 -0
  78. package/WASignalGroup/ciphertext_message.js +10 -0
  79. package/WASignalGroup/group_cipher.js +103 -0
  80. package/WASignalGroup/group_session_builder.js +39 -0
  81. package/WASignalGroup/index.js +5 -0
  82. package/WASignalGroup/keyhelper.js +17 -0
  83. package/WASignalGroup/protobufs.js +2 -0
  84. package/WASignalGroup/queue_job.js +64 -0
  85. package/WASignalGroup/sender_chain_key.js +38 -0
  86. package/WASignalGroup/sender_key_distribution_message.js +68 -0
  87. package/WASignalGroup/sender_key_message.js +79 -0
  88. package/WASignalGroup/sender_key_name.js +59 -0
  89. package/WASignalGroup/sender_key_record.js +47 -0
  90. package/WASignalGroup/sender_key_state.js +110 -0
  91. package/WASignalGroup/sender_message_key.js +30 -0
  92. package/check-node-version.js +10 -0
  93. package/lib/Defaults/baileys-version.json +3 -0
  94. package/lib/Defaults/index.d.ts +51 -0
  95. package/lib/Defaults/index.js +108 -0
  96. package/lib/Defaults/phonenumber-mcc.json +223 -0
  97. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  98. package/lib/Signal/Group/ciphertext-message.js +19 -0
  99. package/lib/Signal/Group/group-session-builder.d.ts +17 -0
  100. package/lib/Signal/Group/group-session-builder.js +72 -0
  101. package/lib/Signal/Group/group_cipher.d.ts +19 -0
  102. package/lib/Signal/Group/group_cipher.js +99 -0
  103. package/lib/Signal/Group/index.d.ts +11 -0
  104. package/lib/Signal/Group/index.js +61 -0
  105. package/lib/Signal/Group/keyhelper.d.ts +16 -0
  106. package/lib/Signal/Group/keyhelper.js +66 -0
  107. package/lib/Signal/Group/queue-job.d.ts +1 -0
  108. package/lib/Signal/Group/queue-job.js +64 -0
  109. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  110. package/lib/Signal/Group/sender-chain-key.js +39 -0
  111. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  112. package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
  113. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  114. package/lib/Signal/Group/sender-key-message.js +73 -0
  115. package/lib/Signal/Group/sender-key-name.d.ts +19 -0
  116. package/lib/Signal/Group/sender-key-name.js +59 -0
  117. package/lib/Signal/Group/sender-key-record.d.ts +32 -0
  118. package/lib/Signal/Group/sender-key-record.js +53 -0
  119. package/lib/Signal/Group/sender-key-record.ts +77 -0
  120. package/lib/Signal/Group/sender-key-state.d.ts +44 -0
  121. package/lib/Signal/Group/sender-key-state.js +104 -0
  122. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  123. package/lib/Signal/Group/sender-message-key.js +33 -0
  124. package/lib/Signal/libsignal.d.ts +3 -0
  125. package/lib/Signal/libsignal.js +153 -0
  126. package/lib/Socket/Client/index.d.ts +2 -0
  127. package/lib/Socket/Client/index.js +18 -0
  128. package/lib/Socket/Client/types.d.ts +15 -0
  129. package/lib/Socket/Client/types.js +14 -0
  130. package/lib/Socket/Client/websocket.d.ts +12 -0
  131. package/lib/Socket/Client/websocket.js +57 -0
  132. package/lib/Socket/business.d.ts +181 -0
  133. package/lib/Socket/business.js +259 -0
  134. package/lib/Socket/chats.d.ts +95 -0
  135. package/lib/Socket/chats.js +906 -0
  136. package/lib/Socket/community.d.ts +131 -0
  137. package/lib/Socket/community.js +369 -0
  138. package/lib/Socket/groups.d.ts +122 -0
  139. package/lib/Socket/groups.js +360 -0
  140. package/lib/Socket/index.d.ts +183 -0
  141. package/lib/Socket/index.js +10 -0
  142. package/lib/Socket/messages-recv.d.ts +170 -0
  143. package/lib/Socket/messages-recv.js +1074 -0
  144. package/lib/Socket/messages-send.d.ts +161 -0
  145. package/lib/Socket/messages-send.js +982 -0
  146. package/lib/Socket/newsletter.d.ts +140 -0
  147. package/lib/Socket/newsletter.js +242 -0
  148. package/lib/Socket/socket.d.ts +43 -0
  149. package/lib/Socket/socket.js +749 -0
  150. package/lib/Socket/usync.d.ts +36 -0
  151. package/lib/Socket/usync.js +71 -0
  152. package/lib/Store/index.d.ts +4 -0
  153. package/lib/Store/index.js +20 -0
  154. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  155. package/lib/Store/make-cache-manager-store.js +77 -0
  156. package/lib/Store/make-in-memory-store.d.ts +117 -0
  157. package/lib/Store/make-in-memory-store.js +420 -0
  158. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  159. package/lib/Store/make-ordered-dictionary.js +83 -0
  160. package/lib/Store/object-repository.d.ts +10 -0
  161. package/lib/Store/object-repository.js +28 -0
  162. package/lib/Types/Auth.d.ts +103 -0
  163. package/lib/Types/Auth.js +2 -0
  164. package/lib/Types/Call.d.ts +13 -0
  165. package/lib/Types/Call.js +2 -0
  166. package/lib/Types/Chat.d.ts +115 -0
  167. package/lib/Types/Chat.js +6 -0
  168. package/lib/Types/Contact.d.ts +35 -0
  169. package/lib/Types/Contact.js +2 -0
  170. package/lib/Types/Events.d.ts +208 -0
  171. package/lib/Types/Events.js +2 -0
  172. package/lib/Types/GroupMetadata.d.ts +81 -0
  173. package/lib/Types/GroupMetadata.js +2 -0
  174. package/lib/Types/Label.d.ts +46 -0
  175. package/lib/Types/Label.js +28 -0
  176. package/lib/Types/LabelAssociation.d.ts +29 -0
  177. package/lib/Types/LabelAssociation.js +10 -0
  178. package/lib/Types/Message.d.ts +480 -0
  179. package/lib/Types/Message.js +9 -0
  180. package/lib/Types/MexUpdates.d.ts +9 -0
  181. package/lib/Types/MexUpdates.js +18 -0
  182. package/lib/Types/Newsletter.d.ts +92 -0
  183. package/lib/Types/Newsletter.js +33 -0
  184. package/lib/Types/Product.d.ts +78 -0
  185. package/lib/Types/Product.js +2 -0
  186. package/lib/Types/Signal.d.ts +57 -0
  187. package/lib/Types/Signal.js +2 -0
  188. package/lib/Types/Socket.d.ts +116 -0
  189. package/lib/Types/Socket.js +2 -0
  190. package/lib/Types/State.d.ts +27 -0
  191. package/lib/Types/State.js +2 -0
  192. package/lib/Types/USync.d.ts +25 -0
  193. package/lib/Types/USync.js +2 -0
  194. package/lib/Types/index.d.ts +70 -0
  195. package/lib/Types/index.js +42 -0
  196. package/lib/Utils/auth-utils.d.ts +18 -0
  197. package/lib/Utils/auth-utils.js +198 -0
  198. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  199. package/lib/Utils/baileys-event-stream.js +64 -0
  200. package/lib/Utils/business.d.ts +22 -0
  201. package/lib/Utils/business.js +243 -0
  202. package/lib/Utils/chat-utils.d.ts +72 -0
  203. package/lib/Utils/chat-utils.js +762 -0
  204. package/lib/Utils/crypto.d.ts +40 -0
  205. package/lib/Utils/crypto.js +150 -0
  206. package/lib/Utils/decode-wa-message.d.ts +252 -0
  207. package/lib/Utils/decode-wa-message.js +232 -0
  208. package/lib/Utils/event-buffer.d.ts +35 -0
  209. package/lib/Utils/event-buffer.js +539 -0
  210. package/lib/Utils/generics.d.ts +96 -0
  211. package/lib/Utils/generics.js +553 -0
  212. package/lib/Utils/history.d.ts +29 -0
  213. package/lib/Utils/history.js +109 -0
  214. package/lib/Utils/index.d.ts +19 -0
  215. package/lib/Utils/index.js +35 -0
  216. package/lib/Utils/link-preview.d.ts +21 -0
  217. package/lib/Utils/link-preview.js +112 -0
  218. package/lib/Utils/logger.d.ts +11 -0
  219. package/lib/Utils/logger.js +7 -0
  220. package/lib/Utils/lt-hash.d.ts +12 -0
  221. package/lib/Utils/lt-hash.js +53 -0
  222. package/lib/Utils/make-mutex.d.ts +7 -0
  223. package/lib/Utils/make-mutex.js +45 -0
  224. package/lib/Utils/messages-media.d.ts +104 -0
  225. package/lib/Utils/messages-media.js +751 -0
  226. package/lib/Utils/messages.d.ts +80 -0
  227. package/lib/Utils/messages.js +1741 -0
  228. package/lib/Utils/noise-handler.d.ts +19 -0
  229. package/lib/Utils/noise-handler.js +150 -0
  230. package/lib/Utils/process-message.d.ts +41 -0
  231. package/lib/Utils/process-message.js +391 -0
  232. package/lib/Utils/signal.d.ts +33 -0
  233. package/lib/Utils/signal.js +154 -0
  234. package/lib/Utils/use-mongo-file-auth-state.d.ts +5 -0
  235. package/lib/Utils/use-mongo-file-auth-state.js +75 -0
  236. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  237. package/lib/Utils/use-multi-file-auth-state.js +123 -0
  238. package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
  239. package/lib/Utils/use-single-file-auth-state.js +75 -0
  240. package/lib/Utils/validate-connection.d.ts +10 -0
  241. package/lib/Utils/validate-connection.js +174 -0
  242. package/lib/WABinary/constants.d.ts +27 -0
  243. package/lib/WABinary/constants.js +45 -0
  244. package/lib/WABinary/decode.d.ts +6 -0
  245. package/lib/WABinary/decode.js +255 -0
  246. package/lib/WABinary/encode.d.ts +2 -0
  247. package/lib/WABinary/encode.js +243 -0
  248. package/lib/WABinary/generic-utils.d.ts +16 -0
  249. package/lib/WABinary/generic-utils.js +125 -0
  250. package/lib/WABinary/index.d.ts +5 -0
  251. package/lib/WABinary/index.js +21 -0
  252. package/lib/WABinary/jid-utils.d.ts +34 -0
  253. package/lib/WABinary/jid-utils.js +73 -0
  254. package/lib/WABinary/types.d.ts +18 -0
  255. package/lib/WABinary/types.js +2 -0
  256. package/lib/WAM/BinaryInfo.d.ts +16 -0
  257. package/lib/WAM/BinaryInfo.js +14 -0
  258. package/lib/WAM/constants.d.ts +39 -0
  259. package/lib/WAM/constants.js +15362 -0
  260. package/lib/WAM/encode.d.ts +2 -0
  261. package/lib/WAM/encode.js +156 -0
  262. package/lib/WAM/index.d.ts +3 -0
  263. package/lib/WAM/index.js +19 -0
  264. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +25 -0
  265. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +60 -0
  266. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  267. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  268. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  269. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +58 -0
  270. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  271. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  272. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +8 -0
  273. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +26 -0
  274. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  275. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  276. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  277. package/lib/WAUSync/Protocols/index.js +22 -0
  278. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  279. package/lib/WAUSync/USyncQuery.js +88 -0
  280. package/lib/WAUSync/USyncUser.d.ts +12 -0
  281. package/lib/WAUSync/USyncUser.js +27 -0
  282. package/lib/WAUSync/index.d.ts +3 -0
  283. package/lib/WAUSync/index.js +19 -0
  284. package/lib/index.d.ts +13 -0
  285. package/lib/index.js +45 -0
  286. package/package.json +63 -0
@@ -0,0 +1,19 @@
1
+ import { proto } from '../../WAProto'
2
+ import { KeyPair } from '../Types'
3
+ import { BinaryNode } from '../WABinary'
4
+ import { ILogger } from './logger'
5
+ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
6
+ keyPair: KeyPair
7
+ NOISE_HEADER: Uint8Array
8
+ logger: ILogger
9
+ routingInfo?: Buffer | undefined
10
+ }) => {
11
+ encrypt: (plaintext: Uint8Array) => Buffer
12
+ decrypt: (ciphertext: Uint8Array) => Buffer
13
+ authenticate: (data: Uint8Array) => void
14
+ mixIntoKey: (data: Uint8Array) => Promise<void>
15
+ finishInit: () => Promise<void>
16
+ processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Promise<Buffer>
17
+ encodeFrame: (data: Buffer | Uint8Array) => Buffer
18
+ decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void>
19
+ }
@@ -0,0 +1,150 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const boom_1 = require("@hapi/boom")
4
+ const WAProto_1 = require("../../WAProto")
5
+ const Defaults_1 = require("../Defaults")
6
+ const WABinary_1 = require("../WABinary")
7
+ const crypto_1 = require("./crypto")
8
+ const generateIV = (counter) => {
9
+ const iv = new ArrayBuffer(12)
10
+ new DataView(iv).setUint32(8, counter)
11
+ return new Uint8Array(iv)
12
+ }
13
+ const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
14
+ logger = logger.child({ class: 'ns' })
15
+ const authenticate = (data) => {
16
+ if (!isFinished) {
17
+ hash = crypto_1.sha256(Buffer.concat([hash, data]))
18
+ }
19
+ }
20
+ const encrypt = (plaintext) => {
21
+ const result = crypto_1.aesEncryptGCM(plaintext, encKey, generateIV(writeCounter), hash)
22
+ writeCounter += 1
23
+ authenticate(result)
24
+ return result
25
+ }
26
+ const decrypt = (ciphertext) => {
27
+ // before the handshake is finished, we use the same counter
28
+ // after handshake, the counters are different
29
+ const iv = generateIV(isFinished ? readCounter : writeCounter)
30
+ const result = crypto_1.aesDecryptGCM(ciphertext, decKey, iv, hash)
31
+ if (isFinished) {
32
+ readCounter += 1
33
+ }
34
+ else {
35
+ writeCounter += 1
36
+ }
37
+ authenticate(ciphertext)
38
+ return result
39
+ }
40
+ const localHKDF = async (data) => {
41
+ const key = await crypto_1.hkdf(Buffer.from(data), 64, { salt, info: '' })
42
+ return [key.slice(0, 32), key.slice(32)]
43
+ }
44
+ const mixIntoKey = async (data) => {
45
+ const [write, read] = await localHKDF(data)
46
+ salt = write
47
+ encKey = read
48
+ decKey = read
49
+ readCounter = 0
50
+ writeCounter = 0
51
+ }
52
+ const finishInit = async () => {
53
+ const [write, read] = await localHKDF(new Uint8Array(0))
54
+ encKey = write
55
+ decKey = read
56
+ hash = Buffer.from([])
57
+ readCounter = 0
58
+ writeCounter = 0
59
+ isFinished = true
60
+ }
61
+ const data = Buffer.from(Defaults_1.NOISE_MODE)
62
+ let hash = data.byteLength === 32 ? data : crypto_1.sha256(data)
63
+ let salt = hash
64
+ let encKey = hash
65
+ let decKey = hash
66
+ let readCounter = 0
67
+ let writeCounter = 0
68
+ let isFinished = false
69
+ let sentIntro = false
70
+ let inBytes = Buffer.alloc(0)
71
+ authenticate(NOISE_HEADER)
72
+ authenticate(publicKey)
73
+ return {
74
+ encrypt,
75
+ decrypt,
76
+ authenticate,
77
+ mixIntoKey,
78
+ finishInit,
79
+ processHandshake: async ({ serverHello }, noiseKey) => {
80
+ authenticate(serverHello.ephemeral)
81
+ await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, serverHello.ephemeral))
82
+ const decStaticContent = decrypt(serverHello.static)
83
+ await mixIntoKey(crypto_1.Curve.sharedKey(privateKey, decStaticContent))
84
+ const certDecoded = decrypt(serverHello.payload)
85
+ const { intermediate: certIntermediate } = WAProto_1.proto.CertChain.decode(certDecoded)
86
+ const { issuerSerial } = WAProto_1.proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details)
87
+ if (issuerSerial !== Defaults_1.WA_CERT_DETAILS.SERIAL) {
88
+ throw new boom_1.Boom('certification match failed', { statusCode: 400 })
89
+ }
90
+ const keyEnc = encrypt(noiseKey.public)
91
+ await mixIntoKey(crypto_1.Curve.sharedKey(noiseKey.private, serverHello.ephemeral))
92
+ return keyEnc
93
+ },
94
+ encodeFrame: (data) => {
95
+ if (isFinished) {
96
+ data = encrypt(data)
97
+ }
98
+ let header
99
+ if (routingInfo) {
100
+ header = Buffer.alloc(7)
101
+ header.write('ED', 0, 'utf8')
102
+ header.writeUint8(0, 2)
103
+ header.writeUint8(1, 3)
104
+ header.writeUint8(routingInfo.byteLength >> 16, 4)
105
+ header.writeUint16BE(routingInfo.byteLength & 65535, 5)
106
+ header = Buffer.concat([header, routingInfo, NOISE_HEADER])
107
+ }
108
+ else {
109
+ header = Buffer.from(NOISE_HEADER)
110
+ }
111
+ const introSize = sentIntro ? 0 : header.length
112
+ const frame = Buffer.alloc(introSize + 3 + data.byteLength)
113
+ if (!sentIntro) {
114
+ frame.set(header)
115
+ sentIntro = true
116
+ }
117
+ frame.writeUInt8(data.byteLength >> 16, introSize)
118
+ frame.writeUInt16BE(65535 & data.byteLength, introSize + 1)
119
+ frame.set(data, introSize + 3)
120
+ return frame
121
+ },
122
+ decodeFrame: async (newData, onFrame) => {
123
+ // the binary protocol uses its own framing mechanism
124
+ // on top of the WS frames
125
+ // so we get this data and separate out the frames
126
+ const getBytesSize = () => {
127
+ if (inBytes.length >= 3) {
128
+ return (inBytes.readUInt8() << 16) | inBytes.readUInt16BE(1)
129
+ }
130
+ }
131
+ inBytes = Buffer.concat([inBytes, newData])
132
+ logger.trace(`recv ${newData.length} bytes, total recv ${inBytes.length} bytes`)
133
+ let size = getBytesSize()
134
+ while (size && inBytes.length >= size + 3) {
135
+ let frame = inBytes.slice(3, size + 3)
136
+ inBytes = inBytes.slice(size + 3)
137
+ if (isFinished) {
138
+ const result = decrypt(frame)
139
+ frame = await WABinary_1.decodeBinaryNode(result)
140
+ }
141
+ logger.trace({ msg: frame?.attrs?.id }, 'recv frame')
142
+ onFrame(frame)
143
+ size = getBytesSize()
144
+ }
145
+ }
146
+ }
147
+ }
148
+ module.exports = {
149
+ makeNoiseHandler
150
+ }
@@ -0,0 +1,41 @@
1
+ import { AxiosRequestConfig } from 'axios'
2
+ import { proto } from '../../WAProto'
3
+ import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SocketConfig } from '../Types'
4
+ import { ILogger } from './logger'
5
+ type ProcessMessageContext = {
6
+ shouldProcessHistoryMsg: boolean
7
+ placeholderResendCache?: CacheStore
8
+ creds: AuthenticationCreds
9
+ keyStore: SignalKeyStoreWithTransaction
10
+ ev: BaileysEventEmitter
11
+ getMessage: SocketConfig['getMessage']
12
+ logger?: ILogger
13
+ options: AxiosRequestConfig<{}>
14
+ }
15
+ /** Cleans a received message to further processing */
16
+ export declare const cleanMessage: (message: proto.IWebMessageInfo, meId: string) => void
17
+ export declare const isRealMessage: (message: proto.IWebMessageInfo, meId: string) => boolean | undefined
18
+ export declare const shouldIncrementChatUnread: (message: proto.IWebMessageInfo) => boolean
19
+ /**
20
+ * Get the ID of the chat from the given key.
21
+ * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
22
+ */
23
+ export declare const getChatId: ({ remoteJid, participant, fromMe }: proto.IMessageKey) => string
24
+ type PollContext = {
25
+ /** normalised jid of the person that created the poll */
26
+ pollCreatorJid: string
27
+ /** ID of the poll creation message */
28
+ pollMsgId: string
29
+ /** poll creation message enc key */
30
+ pollEncKey: Uint8Array
31
+ /** jid of the person that voted */
32
+ voterJid: string
33
+ }
34
+ /**
35
+ * Decrypt a poll vote
36
+ * @param vote encrypted vote
37
+ * @param ctx additional info about the poll required for decryption
38
+ * @returns list of SHA256 options
39
+ */
40
+ export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage
41
+ export declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>
@@ -0,0 +1,391 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const WAProto_1 = require("../../WAProto")
4
+ const Types_1 = require("../Types")
5
+ const messages_1 = require("../Utils/messages")
6
+ const WABinary_1 = require("../WABinary")
7
+ const crypto_1 = require("./crypto")
8
+ const generics_1 = require("./generics")
9
+ const history_1 = require("./history")
10
+ const REAL_MSG_STUB_TYPES = new Set([
11
+ Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
12
+ Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
13
+ Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
14
+ Types_1.WAMessageStubType.CALL_MISSED_VOICE
15
+ ])
16
+ const REAL_MSG_REQ_ME_STUB_TYPES = new Set([
17
+ Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD
18
+ ])
19
+ /** Cleans a received message to further processing */
20
+ const cleanMessage = (message, meId) => {
21
+ // ensure remoteJid and participant doesn't have device or agent in it
22
+ message.key.remoteJid = WABinary_1.jidNormalizedUser(message.key.remoteJid)
23
+ message.key.participant = message.key.participant ? WABinary_1.jidNormalizedUser(message.key.participant) : undefined
24
+ const content = messages_1.normalizeMessageContent(message.message)
25
+ // if the message has a reaction, ensure fromMe & remoteJid are from our perspective
26
+ if (content?.reactionMessage) {
27
+ normaliseKey(content.reactionMessage.key)
28
+ }
29
+ if (content?.pollUpdateMessage) {
30
+ normaliseKey(content.pollUpdateMessage.pollCreationMessageKey)
31
+ }
32
+ function normaliseKey(msgKey) {
33
+ // if the reaction is from another user
34
+ // we've to correctly map the key to this user's perspective
35
+ if (!message.key.fromMe) {
36
+ // if the sender believed the message being reacted to is not from them
37
+ // we've to correct the key to be from them, or some other participant
38
+ msgKey.fromMe = !msgKey.fromMe
39
+ ? WABinary_1.areJidsSameUser(msgKey.participant || msgKey.remoteJid, meId)
40
+ // if the message being reacted to, was from them
41
+ // fromMe automatically becomes false
42
+ : false
43
+ // set the remoteJid to being the same as the chat the message came from
44
+ msgKey.remoteJid = message.key.remoteJid
45
+ // set participant of the message
46
+ msgKey.participant = msgKey.participant || message.key.participant
47
+ }
48
+ }
49
+ }
50
+ const isRealMessage = (message, meId) => {
51
+ const normalizedContent = messages_1.normalizeMessageContent(message.message)
52
+ const hasSomeContent = !!messages_1.getContentType(normalizedContent)
53
+ return (
54
+ !!normalizedContent ||
55
+ REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
56
+ (
57
+ REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType) &&
58
+ message.messageStubParameters?.some(p => WABinary_1.areJidsSameUser(meId, p))
59
+ )
60
+ ) &&
61
+ hasSomeContent &&
62
+ !normalizedContent?.protocolMessage &&
63
+ !normalizedContent?.reactionMessage &&
64
+ !normalizedContent?.pollUpdateMessage
65
+ }
66
+ const shouldIncrementChatUnread = (message) => (!message.key.fromMe && !message.messageStubType)
67
+ /**
68
+ * Get the ID of the chat from the given key.
69
+ * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
70
+ */
71
+ const getChatId = ({ remoteJid, participant, fromMe }) => {
72
+ if (WABinary_1.isJidBroadcast(remoteJid)
73
+ && !WABinary_1.isJidStatusBroadcast(remoteJid)
74
+ && !fromMe) {
75
+ return participant
76
+ }
77
+ return remoteJid
78
+ }
79
+ /**
80
+ * Decrypt a poll vote
81
+ * @param vote encrypted vote
82
+ * @param ctx additional info about the poll required for decryption
83
+ * @returns list of SHA256 options
84
+ */
85
+ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }) {
86
+ const sign = Buffer.concat([
87
+ toBinary(pollMsgId),
88
+ toBinary(pollCreatorJid),
89
+ toBinary(voterJid),
90
+ toBinary('Poll Vote'),
91
+ new Uint8Array([1])
92
+ ])
93
+ const key0 = crypto_1.hmacSign(pollEncKey, new Uint8Array(32), 'sha256')
94
+ const decKey = crypto_1.hmacSign(sign, key0, 'sha256')
95
+ const aad = toBinary(`${pollMsgId}\u0000${voterJid}`)
96
+ const decrypted = crypto_1.aesDecryptGCM(encPayload, decKey, encIv, aad)
97
+ return WAProto_1.proto.Message.PollVoteMessage.decode(decrypted)
98
+ function toBinary(txt) {
99
+ return Buffer.from(txt)
100
+ }
101
+ }
102
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
103
+ const meId = creds.me.id
104
+ const { accountSettings } = creds
105
+ const chat = { id: WABinary_1.jidNormalizedUser(getChatId(message.key)) }
106
+ const isRealMsg = isRealMessage(message, meId)
107
+ if (isRealMsg) {
108
+ chat.messages = [{ message }]
109
+ chat.conversationTimestamp = generics_1.toNumber(message.messageTimestamp)
110
+ // only increment unread count if not CIPHERTEXT and from another person
111
+ if (shouldIncrementChatUnread(message)) {
112
+ chat.unreadCount = (chat.unreadCount || 0) + 1
113
+ }
114
+ }
115
+ const content = messages_1.normalizeMessageContent(message.message)
116
+ // unarchive chat if it's a real message, or someone reacted to our message
117
+ // and we've the unarchive chats setting on
118
+ if (isRealMsg || content?.reactionMessage?.key?.fromMe
119
+ && accountSettings?.unarchiveChats) {
120
+ chat.archived = false
121
+ chat.readOnly = false
122
+ }
123
+ const protocolMsg = content?.protocolMessage
124
+ if (protocolMsg) {
125
+ switch (protocolMsg.type) {
126
+ case WAProto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
127
+ const histNotification = protocolMsg.historySyncNotification
128
+ const process = shouldProcessHistoryMsg
129
+ const isLatest = !creds.processedHistoryMessages?.length
130
+ logger?.info({
131
+ histNotification,
132
+ process,
133
+ id: message.key.id,
134
+ isLatest,
135
+ }, 'got history notification')
136
+ if (process) {
137
+ if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
138
+ ev.emit('creds.update', {
139
+ processedHistoryMessages: [
140
+ ...(creds.processedHistoryMessages || []),
141
+ { key: message.key, messageTimestamp: message.messageTimestamp }
142
+ ]
143
+ })
144
+ }
145
+ const data = await history_1.downloadAndProcessHistorySyncNotification(histNotification, options)
146
+ ev.emit('messaging-history.set', {
147
+ ...data,
148
+ isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
149
+ ? isLatest
150
+ : undefined,
151
+ peerDataRequestSessionId: histNotification.peerDataRequestSessionId
152
+ })
153
+ }
154
+ break
155
+ case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
156
+ const keys = protocolMsg.appStateSyncKeyShare.keys
157
+ if (keys?.length) {
158
+ let newAppStateSyncKeyId = ''
159
+ await keyStore.transaction(async () => {
160
+ const newKeys = []
161
+ for (const { keyData, keyId } of keys) {
162
+ const strKeyId = Buffer.from(keyId.keyId).toString('base64')
163
+ newKeys.push(strKeyId)
164
+ await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } })
165
+ newAppStateSyncKeyId = strKeyId
166
+ }
167
+ logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys')
168
+ })
169
+ ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId })
170
+ }
171
+ else {
172
+ logger?.info({ protocolMsg }, 'recv app state sync with 0 keys')
173
+ }
174
+ break
175
+ case WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE:
176
+ ev.emit('messages.update', [
177
+ {
178
+ key: {
179
+ ...message.key,
180
+ id: protocolMsg.key.id
181
+ },
182
+ update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
183
+ }
184
+ ])
185
+ break
186
+ case WAProto_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
187
+ Object.assign(chat, {
188
+ ephemeralSettingTimestamp: generics_1.toNumber(message.messageTimestamp),
189
+ ephemeralExpiration: protocolMsg.ephemeralExpiration || null
190
+ })
191
+ break
192
+ case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
193
+ const response = protocolMsg.peerDataOperationRequestResponseMessage
194
+ if (response) {
195
+ placeholderResendCache?.del(response.stanzaId)
196
+ // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
197
+ const { peerDataOperationResult } = response
198
+ for (const result of peerDataOperationResult) {
199
+ const { placeholderMessageResendResponse: retryResponse } = result
200
+ //eslint-disable-next-line max-depth
201
+ if (retryResponse) {
202
+ const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes)
203
+ // wait till another upsert event is available, don't want it to be part of the PDO response message
204
+ setTimeout(() => {
205
+ ev.emit('messages.upsert', {
206
+ messages: [webMessageInfo],
207
+ type: 'notify',
208
+ requestId: response.stanzaId
209
+ })
210
+ }, 500)
211
+ }
212
+ }
213
+ }
214
+ break
215
+ case WAProto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
216
+ ev.emit('messages.update', [
217
+ {
218
+ // flip the sender / fromMe properties because they're in the perspective of the sender
219
+ key: { ...message.key, id: protocolMsg.key?.id },
220
+ update: {
221
+ message: {
222
+ editedMessage: {
223
+ message: protocolMsg.editedMessage
224
+ }
225
+ },
226
+ messageTimestamp: protocolMsg.timestampMs
227
+ ? Math.floor(generics_1.toNumber(protocolMsg.timestampMs) / 1000)
228
+ : message.messageTimestamp
229
+ }
230
+ }
231
+ ])
232
+ break
233
+ }
234
+ }
235
+ else if (content?.reactionMessage) {
236
+ const reaction = {
237
+ ...content.reactionMessage,
238
+ key: message.key,
239
+ }
240
+ ev.emit('messages.reaction', [{
241
+ reaction,
242
+ key: content.reactionMessage?.key
243
+ }])
244
+ }
245
+ else if (message.messageStubType) {
246
+ const jid = message.key?.remoteJid
247
+ //let actor = whatsappID (message.participant)
248
+ let participants
249
+ const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }))
250
+ const emitGroupUpdate = (update) => {
251
+ ev.emit('groups.update', [{ id: jid, ...update, author: message.participant ? message.participant : undefined }])
252
+ }
253
+ const emitGroupRequestJoin = (participant, action, method) => {
254
+ ev.emit('group.join-request', { id: jid, author: message.participant, participant, action, method: method })
255
+ }
256
+ const participantsIncludesMe = () => participants.find(jid => WABinary_1.areJidsSameUser(meId, jid))
257
+ switch (message.messageStubType) {
258
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
259
+ participants = message.messageStubParameters || []
260
+ emitParticipantsUpdate('modify')
261
+ break
262
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
263
+ participants = message.messageStubParameters || [];
264
+ emitParticipantsUpdate('leave');
265
+ // mark the chat read only if you left the group
266
+ if (participantsIncludesMe()) {
267
+ chat.readOnly = true;
268
+ }
269
+ break;
270
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
271
+ participants = message.messageStubParameters || []
272
+ emitParticipantsUpdate('remove')
273
+ // mark the chat read only if you left the group
274
+ if (participantsIncludesMe()) {
275
+ chat.readOnly = true
276
+ }
277
+ break
278
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
279
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
280
+ let actionGp = 'invite'
281
+ participants = message.messageStubParameters || []
282
+ if (participantsIncludesMe()) chat.readOnly = false;
283
+ if (message?.key?.participant && !participants.includes(message?.key?.participant)) {
284
+ actionGp = 'approval-invite'
285
+ }
286
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
287
+ participants = message.messageStubParameters || []
288
+ if (participantsIncludesMe()) {
289
+ chat.readOnly = false
290
+ }
291
+ emitParticipantsUpdate('add')
292
+ break
293
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
294
+ case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_DEMOTE:
295
+ participants = message.messageStubParameters || []
296
+ emitParticipantsUpdate('demote')
297
+ break
298
+ case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
299
+ case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_PROMOTE:
300
+ participants = message.messageStubParameters || []
301
+ emitParticipantsUpdate('promote')
302
+ break
303
+ case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
304
+ const announceValue = message.messageStubParameters?.[0]
305
+ emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' })
306
+ break
307
+ case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
308
+ const restrictValue = message.messageStubParameters?.[0]
309
+ emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' })
310
+ break
311
+ case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
312
+ const name = message.messageStubParameters?.[0]
313
+ chat.name = name
314
+ emitGroupUpdate({ subject: name })
315
+ break
316
+ case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
317
+ const description = message.messageStubParameters?.[0]
318
+ chat.description = description
319
+ emitGroupUpdate({ desc: description })
320
+ break
321
+ case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
322
+ const code = message.messageStubParameters?.[0]
323
+ emitGroupUpdate({ inviteCode: code })
324
+ break
325
+ case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
326
+ const memberAddValue = message.messageStubParameters?.[0]
327
+ emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' })
328
+ break
329
+ case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
330
+ const approvalMode = message.messageStubParameters?.[0]
331
+ emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' })
332
+ break
333
+ case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
334
+ const participant = message.messageStubParameters?.[0]
335
+ const action = message.messageStubParameters?.[1]
336
+ const method = message.messageStubParameters?.[2]
337
+ emitGroupRequestJoin(participant, action, method)
338
+ break
339
+ }
340
+ }
341
+ else if (content?.pollUpdateMessage) {
342
+ const creationMsgKey = content.pollUpdateMessage.pollCreationMessageKey
343
+ // we need to fetch the poll creation message to get the poll enc key
344
+ const pollMsg = await getMessage(creationMsgKey)
345
+ if (pollMsg) {
346
+ const meIdNormalised = WABinary_1.jidNormalizedUser(meId)
347
+ const pollCreatorJid = generics_1.getKeyAuthor(creationMsgKey, meIdNormalised)
348
+ const voterJid = generics_1.getKeyAuthor(message.key, meIdNormalised)
349
+ const pollEncKey = pollMsg.messageContextInfo?.messageSecret
350
+ try {
351
+ const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
352
+ pollEncKey,
353
+ pollCreatorJid,
354
+ pollMsgId: creationMsgKey.id,
355
+ voterJid,
356
+ })
357
+ ev.emit('messages.update', [
358
+ {
359
+ key: creationMsgKey,
360
+ update: {
361
+ pollUpdates: [
362
+ {
363
+ pollUpdateMessageKey: message.key,
364
+ vote: voteMsg,
365
+ senderTimestampMs: content.pollUpdateMessage.senderTimestampMs.toNumber(),
366
+ }
367
+ ]
368
+ }
369
+ }
370
+ ])
371
+ }
372
+ catch (err) {
373
+ logger?.warn({ err, creationMsgKey }, 'failed to decrypt poll vote')
374
+ }
375
+ }
376
+ else {
377
+ logger?.warn({ creationMsgKey }, 'poll creation message not found, cannot decrypt update')
378
+ }
379
+ }
380
+ if (Object.keys(chat).length > 1) {
381
+ ev.emit('chats.update', [chat])
382
+ }
383
+ }
384
+ module.exports = {
385
+ cleanMessage,
386
+ isRealMessage,
387
+ shouldIncrementChatUnread,
388
+ getChatId,
389
+ decryptPollVote,
390
+ processMessage
391
+ }
@@ -0,0 +1,33 @@
1
+ import { SignalRepository } from '../Types'
2
+ import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth'
3
+ import { BinaryNode, JidWithDevice } from '../WABinary'
4
+ import { USyncQueryResultList } from '../WAUSync'
5
+ export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity
6
+ export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
7
+ [id: string]: KeyPair
8
+ }>
9
+ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
10
+ newPreKeys: {
11
+ [id: number]: KeyPair
12
+ }
13
+ lastPreKeyId: number
14
+ preKeysRange: readonly [number, number]
15
+ }
16
+ export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode
17
+ export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode
18
+ export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>
19
+ export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => JidWithDevice[]
20
+ /**
21
+ * get the next N keys for upload or processing
22
+ * @param count number of pre-keys to get or generate
23
+ */
24
+ export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
25
+ update: Partial<AuthenticationCreds>
26
+ preKeys: {
27
+ [id: string]: KeyPair
28
+ }
29
+ }>
30
+ export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
31
+ update: Partial<AuthenticationCreds>
32
+ node: BinaryNode
33
+ }>