@hansaka02/baileys 7.3.2 → 7.3.4

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 (202) hide show
  1. package/README.md +247 -203
  2. package/lib/Defaults/connection.js +51 -0
  3. package/lib/Defaults/constants.js +62 -0
  4. package/lib/Defaults/history.js +17 -0
  5. package/lib/Defaults/index.js +36 -142
  6. package/lib/Defaults/media.js +48 -0
  7. package/lib/Defaults/prefix.js +18 -0
  8. package/lib/Signal/Group/group-session-builder.js +10 -42
  9. package/lib/Signal/Group/group_cipher.js +9 -6
  10. package/lib/Signal/Group/index.js +39 -53
  11. package/lib/Signal/Group/keyhelper.js +8 -41
  12. package/lib/Signal/Group/sender-chain-key.js +4 -4
  13. package/lib/Signal/Group/sender-key-distribution-message.js +5 -5
  14. package/lib/Signal/Group/sender-key-message.js +12 -8
  15. package/lib/Signal/Group/sender-key-record.js +7 -7
  16. package/lib/Signal/Group/sender-key-state.js +4 -4
  17. package/lib/Signal/Group/sender-message-key.js +2 -2
  18. package/lib/Signal/libsignal.js +45 -69
  19. package/lib/Signal/lid-mapping.js +15 -11
  20. package/lib/Socket/Client/types.js +2 -2
  21. package/lib/Socket/Client/websocket.js +16 -14
  22. package/lib/Socket/business.js +41 -32
  23. package/lib/Socket/chats.js +123 -98
  24. package/lib/Socket/community.js +50 -40
  25. package/lib/Socket/groups.js +59 -47
  26. package/lib/Socket/index.js +4 -4
  27. package/lib/Socket/messages-recv.js +219 -172
  28. package/lib/Socket/messages-send.js +187 -143
  29. package/lib/Socket/newsletter.js +61 -47
  30. package/lib/Socket/socket.js +133 -90
  31. package/lib/Socket/usync.js +6 -6
  32. package/lib/Store/index.js +27 -11
  33. package/lib/Store/make-cache-manager-store.js +14 -15
  34. package/lib/Store/make-in-memory-store.js +28 -24
  35. package/lib/Types/LabelAssociation.js +2 -2
  36. package/lib/Types/Message.js +6 -6
  37. package/lib/Types/MexUpdates.js +5 -5
  38. package/lib/Types/State.js +4 -4
  39. package/lib/Types/index.js +28 -12
  40. package/lib/Utils/auth-utils.js +28 -26
  41. package/lib/Utils/baileys-event-stream.js +68 -69
  42. package/lib/Utils/business.js +63 -53
  43. package/lib/Utils/chat-utils.js +81 -71
  44. package/lib/Utils/crypto.js +25 -45
  45. package/lib/Utils/decode-wa-message.js +319 -311
  46. package/lib/Utils/event-buffer.js +21 -22
  47. package/lib/Utils/generics.js +65 -82
  48. package/lib/Utils/history.js +21 -21
  49. package/lib/Utils/index.js +27 -13
  50. package/lib/Utils/link-preview.js +7 -30
  51. package/lib/Utils/logger.js +5 -5
  52. package/lib/Utils/lt-hash.js +3 -3
  53. package/lib/Utils/message-retry-manager.js +4 -4
  54. package/lib/Utils/messages-media.js +104 -109
  55. package/lib/Utils/messages.js +203 -171
  56. package/lib/Utils/noise-handler.js +28 -19
  57. package/lib/Utils/process-message.js +111 -96
  58. package/lib/Utils/signal.js +36 -25
  59. package/lib/Utils/use-multi-file-auth-state.js +18 -22
  60. package/lib/Utils/validate-connection.js +52 -45
  61. package/lib/WABinary/decode.js +6 -32
  62. package/lib/WABinary/encode.js +3 -29
  63. package/lib/WABinary/generic-utils.js +4 -4
  64. package/lib/WABinary/index.js +27 -11
  65. package/lib/WAM/encode.js +16 -8
  66. package/lib/WAM/index.js +27 -11
  67. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
  68. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  69. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
  70. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  71. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
  72. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
  73. package/lib/WAUSync/Protocols/index.js +27 -11
  74. package/lib/WAUSync/USyncQuery.js +17 -10
  75. package/lib/WAUSync/index.js +27 -11
  76. package/lib/index.js +60 -31
  77. package/package.json +8 -14
  78. package/WAProto/AICommon/AICommon.d.ts +0 -11702
  79. package/WAProto/Adv/Adv.d.ts +0 -643
  80. package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
  81. package/WAProto/Cert/Cert.d.ts +0 -613
  82. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
  83. package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
  84. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
  85. package/WAProto/E2E/E2E.d.ts +0 -41724
  86. package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
  87. package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
  88. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
  89. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
  90. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
  91. package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
  92. package/WAProto/Protocol/Protocol.d.ts +0 -270
  93. package/WAProto/Reporting/Reporting.d.ts +0 -371
  94. package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
  95. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
  96. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
  97. package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
  98. package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
  99. package/WAProto/UserPassword/UserPassword.d.ts +0 -363
  100. package/WAProto/VnameCert/VnameCert.d.ts +0 -821
  101. package/WAProto/Wa6/Wa6.d.ts +0 -2128
  102. package/WAProto/Web/Web.d.ts +0 -46383
  103. package/WAProto/index.d.ts +0 -55
  104. package/lib/Defaults/index.d.ts +0 -77
  105. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  106. package/lib/Signal/Group/group-session-builder.d.ts +0 -17
  107. package/lib/Signal/Group/group_cipher.d.ts +0 -19
  108. package/lib/Signal/Group/index.d.ts +0 -11
  109. package/lib/Signal/Group/keyhelper.d.ts +0 -16
  110. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  111. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  112. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  113. package/lib/Signal/Group/sender-key-name.d.ts +0 -19
  114. package/lib/Signal/Group/sender-key-record.d.ts +0 -32
  115. package/lib/Signal/Group/sender-key-state.d.ts +0 -44
  116. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  117. package/lib/Signal/libsignal.d.ts +0 -8
  118. package/lib/Signal/lid-mapping.d.ts +0 -28
  119. package/lib/Socket/Client/index.d.ts +0 -2
  120. package/lib/Socket/Client/types.d.ts +0 -16
  121. package/lib/Socket/Client/websocket.d.ts +0 -13
  122. package/lib/Socket/business.d.ts +0 -187
  123. package/lib/Socket/chats.d.ts +0 -97
  124. package/lib/Socket/community.d.ts +0 -129
  125. package/lib/Socket/groups.d.ts +0 -129
  126. package/lib/Socket/index.d.ts +0 -191
  127. package/lib/Socket/messages-recv.d.ts +0 -174
  128. package/lib/Socket/messages-send.d.ts +0 -165
  129. package/lib/Socket/newsletter.d.ts +0 -145
  130. package/lib/Socket/socket.d.ts +0 -45
  131. package/lib/Socket/usync.d.ts +0 -37
  132. package/lib/Store/index.d.ts +0 -4
  133. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  134. package/lib/Store/make-in-memory-store.d.ts +0 -123
  135. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  136. package/lib/Store/object-repository.d.ts +0 -10
  137. package/lib/Types/Auth.d.ts +0 -121
  138. package/lib/Types/Bussiness.d.ts +0 -28
  139. package/lib/Types/Call.d.ts +0 -14
  140. package/lib/Types/Chat.d.ts +0 -143
  141. package/lib/Types/Contact.d.ts +0 -23
  142. package/lib/Types/Events.d.ts +0 -226
  143. package/lib/Types/GroupMetadata.d.ts +0 -66
  144. package/lib/Types/Label.d.ts +0 -48
  145. package/lib/Types/LabelAssociation.d.ts +0 -35
  146. package/lib/Types/Message.d.ts +0 -484
  147. package/lib/Types/MexUpdates.d.ts +0 -9
  148. package/lib/Types/Newsletter.d.ts +0 -109
  149. package/lib/Types/Product.d.ts +0 -92
  150. package/lib/Types/Signal.d.ts +0 -98
  151. package/lib/Types/Socket.d.ts +0 -141
  152. package/lib/Types/State.d.ts +0 -41
  153. package/lib/Types/USync.d.ts +0 -26
  154. package/lib/Types/index.d.ts +0 -80
  155. package/lib/Utils/auth-utils.d.ts +0 -21
  156. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  157. package/lib/Utils/business.d.ts +0 -29
  158. package/lib/Utils/chat-utils.d.ts +0 -82
  159. package/lib/Utils/crypto.d.ts +0 -56
  160. package/lib/Utils/decode-wa-message.d.ts +0 -53
  161. package/lib/Utils/event-buffer.d.ts +0 -39
  162. package/lib/Utils/generics.d.ts +0 -117
  163. package/lib/Utils/history.d.ts +0 -23
  164. package/lib/Utils/index.d.ts +0 -20
  165. package/lib/Utils/link-preview.d.ts +0 -23
  166. package/lib/Utils/logger.d.ts +0 -13
  167. package/lib/Utils/lt-hash.d.ts +0 -14
  168. package/lib/Utils/make-mutex.d.ts +0 -9
  169. package/lib/Utils/message-retry-manager.d.ts +0 -88
  170. package/lib/Utils/messages-media.d.ts +0 -135
  171. package/lib/Utils/messages.d.ts +0 -105
  172. package/lib/Utils/noise-handler.d.ts +0 -20
  173. package/lib/Utils/process-message.d.ts +0 -49
  174. package/lib/Utils/signal.d.ts +0 -42
  175. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  176. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  177. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  178. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  179. package/lib/Utils/use-single-file-auth-state.js +0 -80
  180. package/lib/Utils/validate-connection.d.ts +0 -13
  181. package/lib/WABinary/constants.d.ts +0 -30
  182. package/lib/WABinary/decode.d.ts +0 -9
  183. package/lib/WABinary/encode.d.ts +0 -3
  184. package/lib/WABinary/generic-utils.d.ts +0 -28
  185. package/lib/WABinary/index.d.ts +0 -5
  186. package/lib/WABinary/jid-utils.d.ts +0 -58
  187. package/lib/WABinary/types.d.ts +0 -22
  188. package/lib/WAM/BinaryInfo.d.ts +0 -16
  189. package/lib/WAM/constants.d.ts +0 -47
  190. package/lib/WAM/encode.d.ts +0 -3
  191. package/lib/WAM/index.d.ts +0 -3
  192. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  193. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  194. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  195. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  196. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
  197. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  198. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  199. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  200. package/lib/WAUSync/USyncUser.d.ts +0 -12
  201. package/lib/WAUSync/index.d.ts +0 -3
  202. package/lib/index.d.ts +0 -13
@@ -2,16 +2,27 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const lodash_1 = require("lodash")
6
- const Defaults_1 = require("../Defaults")
7
- const WABinary_1 = require("../WABinary")
8
- const crypto_1 = require("./crypto")
9
- const generics_1 = require("./generics")
5
+ const { chunk } = require("lodash")
6
+ const { KEY_BUNDLE_TYPE } = require("../Defaults/constants")
7
+ const {
8
+ S_WHATSAPP_NET,
9
+ getBinaryNodeChild,
10
+ getBinaryNodeChildren,
11
+ getBinaryNodeChildUInt,
12
+ getBinaryNodeChildBuffer,
13
+ assertNodeErrorFree,
14
+ jidDecode
15
+ } = require("../WABinary")
16
+ const {
17
+ Curve,
18
+ generateSignalPubKey
19
+ } = require("./crypto")
20
+ const { encodeBigEndian } = require("./generics")
10
21
 
11
22
  const createSignalIdentity = (wid, accountSignatureKey) => {
12
23
  return {
13
24
  identifier: { name: wid, deviceId: 0 },
14
- identifierKey: crypto_1.generateSignalPubKey(accountSignatureKey)
25
+ identifierKey: generateSignalPubKey(accountSignatureKey)
15
26
  }
16
27
  }
17
28
 
@@ -30,7 +41,7 @@ const generateOrGetPreKeys = (creds, range) => {
30
41
  const newPreKeys = {}
31
42
  if (remaining > 0) {
32
43
  for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
33
- newPreKeys[i] = crypto_1.Curve.generateKeyPair()
44
+ newPreKeys[i] = Curve.generateKeyPair()
34
45
  }
35
46
  }
36
47
  return {
@@ -44,7 +55,7 @@ const xmppSignedPreKey = (key) => ({
44
55
  tag: 'skey',
45
56
  attrs: {},
46
57
  content: [
47
- { tag: 'id', attrs: {}, content: generics_1.encodeBigEndian(key.keyId, 3) },
58
+ { tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
48
59
  { tag: 'value', attrs: {}, content: key.keyPair.public },
49
60
  { tag: 'signature', attrs: {}, content: key.signature }
50
61
  ]
@@ -54,20 +65,20 @@ const xmppPreKey = (pair, id) => ({
54
65
  tag: 'key',
55
66
  attrs: {},
56
67
  content: [
57
- { tag: 'id', attrs: {}, content: generics_1.encodeBigEndian(id, 3) },
68
+ { tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
58
69
  { tag: 'value', attrs: {}, content: pair.public }
59
70
  ]
60
71
  })
61
72
 
62
73
  const parseAndInjectE2ESessions = async (node, repository) => {
63
74
  const extractKey = (key) => (key ? ({
64
- keyId: WABinary_1.getBinaryNodeChildUInt(key, 'id', 3),
65
- publicKey: crypto_1.generateSignalPubKey(WABinary_1.getBinaryNodeChildBuffer(key, 'value')),
66
- signature: WABinary_1.getBinaryNodeChildBuffer(key, 'signature')
75
+ keyId: getBinaryNodeChildUInt(key, 'id', 3),
76
+ publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
77
+ signature: getBinaryNodeChildBuffer(key, 'signature')
67
78
  }) : undefined)
68
- const nodes = WABinary_1.getBinaryNodeChildren(WABinary_1.getBinaryNodeChild(node, 'list'), 'user')
79
+ const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user')
69
80
  for (const node of nodes) {
70
- WABinary_1.assertNodeErrorFree(node)
81
+ assertNodeErrorFree(node)
71
82
  }
72
83
  // Most of the work in repository.injectE2ESession is CPU intensive, not IO
73
84
  // So Promise.all doesn't really help here,
@@ -75,19 +86,19 @@ const parseAndInjectE2ESessions = async (node, repository) => {
75
86
  // This way we chunk it in smaller parts and between those parts we can yield to the event loop
76
87
  // It's rare case when you need to E2E sessions for so many users, but it's possible
77
88
  const chunkSize = 100
78
- const chunks = lodash_1.chunk(nodes, chunkSize)
89
+ const chunks = chunk(nodes, chunkSize)
79
90
  for (const nodesChunk of chunks) {
80
91
  await Promise.all(nodesChunk.map(async (node) => {
81
- const signedKey = WABinary_1.getBinaryNodeChild(node, 'skey')
82
- const key = WABinary_1.getBinaryNodeChild(node, 'key')
83
- const identity = WABinary_1.getBinaryNodeChildBuffer(node, 'identity')
92
+ const signedKey = getBinaryNodeChild(node, 'skey')
93
+ const key = getBinaryNodeChild(node, 'key')
94
+ const identity = getBinaryNodeChildBuffer(node, 'identity')
84
95
  const jid = node.attrs.jid
85
- const registrationId = WABinary_1.getBinaryNodeChildUInt(node, 'registration', 4)
96
+ const registrationId = getBinaryNodeChildUInt(node, 'registration', 4)
86
97
  await repository.injectE2ESession({
87
98
  jid,
88
99
  session: {
89
100
  registrationId: registrationId,
90
- identityKey: crypto_1.generateSignalPubKey(identity),
101
+ identityKey: generateSignalPubKey(identity),
91
102
  signedPreKey: extractKey(signedKey),
92
103
  preKey: extractKey(key)
93
104
  }
@@ -97,11 +108,11 @@ const parseAndInjectE2ESessions = async (node, repository) => {
97
108
  }
98
109
 
99
110
  const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
100
- const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
111
+ const { user: myUser, device: myDevice } = jidDecode(myJid)
101
112
  const extracted = []
102
113
  for (const userResult of result) {
103
114
  const { devices, id } = userResult
104
- const { user } = WABinary_1.jidDecode(id)
115
+ const { user } = jidDecode(id)
105
116
  const deviceList = devices?.deviceList
106
117
  if (Array.isArray(deviceList)) {
107
118
  for (const { id: device, keyIndex } of deviceList) {
@@ -140,11 +151,11 @@ const getNextPreKeysNode = async (state, count) => {
140
151
  attrs: {
141
152
  xmlns: 'encrypt',
142
153
  type: 'set',
143
- to: WABinary_1.S_WHATSAPP_NET,
154
+ to: S_WHATSAPP_NET,
144
155
  },
145
156
  content: [
146
- { tag: 'registration', attrs: {}, content: generics_1.encodeBigEndian(creds.registrationId) },
147
- { tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
157
+ { tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
158
+ { tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
148
159
  { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
149
160
  { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
150
161
  xmppSignedPreKey(creds.signedPreKey)
@@ -1,17 +1,13 @@
1
1
  "use strict"
2
2
 
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod }
5
- }
6
-
7
3
  Object.defineProperty(exports, "__esModule", { value: true })
8
4
 
9
- const async_mutex_1 = __importDefault(require("async-mutex"))
10
- const promises_1 = require("fs/promises")
11
- const path_1 = require("path")
12
- const WAProto_1 = require("../../WAProto")
13
- const auth_utils_1 = require("./auth-utils")
14
- const generics_1 = require("./generics")
5
+ const { Mutex } = require("async-mutex")
6
+ const { promises } = require("fs")
7
+ const { join } = require("path")
8
+ const { proto } = require("../../WAProto")
9
+ const { initAuthCreds } = require("./auth-utils")
10
+ const { BufferJSON } = require("./generics")
15
11
  // We need to lock files due to the fact that we are using async functions to read and write files
16
12
  // https://github.com/WhiskeySockets/Baileys/issues/794
17
13
  // https://github.com/nodejs/node/issues/26338
@@ -22,7 +18,7 @@ const fileLocks = new Map()
22
18
  const getFileLock = (path) => {
23
19
  let mutex = fileLocks.get(path)
24
20
  if (!mutex) {
25
- mutex = new async_mutex_1.Mutex()
21
+ mutex = new Mutex()
26
22
  fileLocks.set(path, mutex)
27
23
  }
28
24
 
@@ -39,11 +35,11 @@ const getFileLock = (path) => {
39
35
  const useMultiFileAuthState = async (folder) => {
40
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
37
  const writeData = async (data, file) => {
42
- const filePath = path_1.join(folder, fixFileName(file))
38
+ const filePath = join(folder, fixFileName(file))
43
39
  const mutex = getFileLock(filePath)
44
40
  return mutex.acquire().then(async (release) => {
45
41
  try {
46
- await promises_1.writeFile(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer))
42
+ await promises.writeFile(filePath, JSON.stringify(data, BufferJSON.replacer))
47
43
  } finally {
48
44
  release()
49
45
  }
@@ -51,47 +47,47 @@ const useMultiFileAuthState = async (folder) => {
51
47
  }
52
48
  const readData = async (file) => {
53
49
  try {
54
- const filePath = path_1.join(folder, fixFileName(file))
50
+ const filePath = join(folder, fixFileName(file))
55
51
  const mutex = getFileLock(filePath)
56
52
  const data = await mutex.acquire().then(async (release) => {
57
53
  try {
58
- return await promises_1.readFile(filePath, { encoding: 'utf-8' })
54
+ return await promises.readFile(filePath, { encoding: 'utf-8' })
59
55
  } finally {
60
56
  release()
61
57
  }
62
58
  })
63
59
 
64
- return JSON.parse(data, generics_1.BufferJSON.reviver)
60
+ return JSON.parse(data, BufferJSON.reviver)
65
61
  } catch (error) {
66
62
  return null
67
63
  }
68
64
  }
69
65
  const removeData = async (file) => {
70
66
  try {
71
- const filePath = path_1.join(folder, fixFileName(file))
67
+ const filePath = join(folder, fixFileName(file))
72
68
  const mutex = getFileLock(filePath)
73
69
  await mutex.acquire().then(async (release) => {
74
70
  try {
75
- await promises_1.unlink(filePath)
71
+ await promises.unlink(filePath)
76
72
  } finally {
77
73
  release()
78
74
  }
79
75
  })
80
76
  } catch {}
81
77
  }
82
- const folderInfo = await promises_1.stat(folder).catch(() => { })
78
+ const folderInfo = await promises.stat(folder).catch(() => { })
83
79
  if (folderInfo) {
84
80
  if (!folderInfo.isDirectory()) {
85
81
  throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`)
86
82
  }
87
83
  }
88
84
  else {
89
- await promises_1.mkdir(folder, { recursive: true })
85
+ await promises.mkdir(folder, { recursive: true })
90
86
  }
91
87
  const fixFileName = (file) => {
92
88
  return file?.replace(/\//g, '__')?.replace(/:/g, '-')
93
89
  }
94
- const creds = await readData('creds.json') || auth_utils_1.initAuthCreds()
90
+ const creds = await readData('creds.json') || initAuthCreds()
95
91
  return {
96
92
  state: {
97
93
  creds,
@@ -101,7 +97,7 @@ const useMultiFileAuthState = async (folder) => {
101
97
  await Promise.all(ids.map(async (id) => {
102
98
  let value = await readData(`${type}-${id}.json`)
103
99
  if (type === 'app-state-sync-key' && value) {
104
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value)
100
+ value = proto.Message.AppStateSyncKeyData.fromObject(value)
105
101
  }
106
102
  data[id] = value
107
103
  }))
@@ -2,14 +2,21 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const boom_1 = require("@hapi/boom")
6
- const crypto_1 = require("crypto")
7
- const WAProto_1 = require("../../WAProto")
8
- const Defaults_1 = require("../Defaults")
9
- const WABinary_1 = require("../WABinary")
10
- const crypto_2 = require("./crypto")
11
- const generics_1 = require("./generics")
12
- const signal_1 = require("./signal")
5
+ const { Boom } = require("@hapi/boom")
6
+ const { createHash } = require("crypto")
7
+ const { proto } = require("../../WAProto")
8
+ const { KEY_BUNDLE_TYPE } = require("../Defaults/constants")
9
+ const {
10
+ jidDecode,
11
+ getBinaryNodeChild,
12
+ S_WHATSAPP_NET
13
+ } = require("../WABinary")
14
+ const {
15
+ Curve,
16
+ hmacSign
17
+ } = require("./crypto")
18
+ const { encodeBigEndian } = require("./generics")
19
+ const { createSignalIdentity } = require("./signal")
13
20
 
14
21
  const getUserAgent = (config) => {
15
22
  return {
@@ -18,8 +25,8 @@ const getUserAgent = (config) => {
18
25
  secondary: config.version[1],
19
26
  tertiary: config.version[2],
20
27
  },
21
- platform: WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB,
22
- releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
28
+ platform: proto.ClientPayload.UserAgent.Platform.WEB,
29
+ releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
23
30
  osVersion: '0.1',
24
31
  device: 'Desktop',
25
32
  osBuildNumber: '0.1',
@@ -31,13 +38,13 @@ const getUserAgent = (config) => {
31
38
  }
32
39
 
33
40
  const PLATFORM_MAP = {
34
- 'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
35
- 'Windows': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN32,
36
- 'Android': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID
41
+ 'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
42
+ 'Windows': proto.ClientPayload.WebInfo.WebSubPlatform.WIN32,
43
+ 'Android': proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID
37
44
  }
38
45
 
39
46
  const getWebInfo = (config) => {
40
- let webSubPlatform = WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
47
+ let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
41
48
  if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
42
49
  webSubPlatform = PLATFORM_MAP[config.browser[0]]
43
50
  }
@@ -46,8 +53,8 @@ const getWebInfo = (config) => {
46
53
 
47
54
  const getClientPayload = (config) => {
48
55
  const payload = {
49
- connectType: WAProto_1.proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
50
- connectReason: WAProto_1.proto.ClientPayload.ConnectReason.USER_ACTIVATED,
56
+ connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
57
+ connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
51
58
  userAgent: getUserAgent(config),
52
59
  }
53
60
  payload.webInfo = getWebInfo(config)
@@ -55,7 +62,7 @@ const getClientPayload = (config) => {
55
62
  }
56
63
 
57
64
  const generateLoginNode = (userJid, config) => {
58
- const { user, device } = WABinary_1.jidDecode(userJid)
65
+ const { user, device } = jidDecode(userJid)
59
66
  const payload = {
60
67
  ...getClientPayload(config),
61
68
  passive: false,
@@ -63,18 +70,18 @@ const generateLoginNode = (userJid, config) => {
63
70
  username: +user,
64
71
  device: device,
65
72
  }
66
- return WAProto_1.proto.ClientPayload.fromObject(payload)
73
+ return proto.ClientPayload.fromObject(payload)
67
74
  }
68
75
 
69
76
  const getPlatformType = (platform) => {
70
77
  const platformType = platform.toUpperCase()
71
- return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP
78
+ return proto.DeviceProps.PlatformType[platformType] || proto.DeviceProps.PlatformType.DESKTOP
72
79
  }
73
80
 
74
81
  const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
75
82
  // the app version needs to be md5 hashed
76
83
  // and passed in
77
- const appVersionBuf = crypto_1.createHash('md5')
84
+ const appVersionBuf = createHash('md5')
78
85
  .update(config.version.join('.')) // join as string
79
86
  .digest()
80
87
 
@@ -106,7 +113,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
106
113
  }
107
114
  }
108
115
 
109
- const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish()
116
+ const companionProto = proto.DeviceProps.encode(companion).finish()
110
117
 
111
118
  const registerPayload = {
112
119
  ...getClientPayload(config),
@@ -115,55 +122,55 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
115
122
  devicePairingData: {
116
123
  buildHash: appVersionBuf,
117
124
  deviceProps: companionProto,
118
- eRegid: generics_1.encodeBigEndian(registrationId),
119
- eKeytype: Defaults_1.KEY_BUNDLE_TYPE,
125
+ eRegid: encodeBigEndian(registrationId),
126
+ eKeytype: KEY_BUNDLE_TYPE,
120
127
  eIdent: signedIdentityKey.public,
121
- eSkeyId: generics_1.encodeBigEndian(signedPreKey.keyId, 3),
128
+ eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
122
129
  eSkeyVal: signedPreKey.keyPair.public,
123
130
  eSkeySig: signedPreKey.signature,
124
131
  }
125
132
  }
126
133
 
127
- return WAProto_1.proto.ClientPayload.fromObject(registerPayload)
134
+ return proto.ClientPayload.fromObject(registerPayload)
128
135
  }
129
136
 
130
137
  const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
131
138
  const msgId = stanza.attrs.id
132
- const pairSuccessNode = WABinary_1.getBinaryNodeChild(stanza, 'pair-success')
133
- const deviceIdentityNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device-identity')
134
- const platformNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'platform')
135
- const deviceNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'device')
136
- const businessNode = WABinary_1.getBinaryNodeChild(pairSuccessNode, 'biz')
139
+ const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success')
140
+ const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity')
141
+ const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform')
142
+ const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device')
143
+ const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz')
137
144
  if (!deviceIdentityNode || !deviceNode) {
138
- throw new boom_1.Boom('Missing device-identity or device in pair success node', { data: stanza })
145
+ throw new Boom('Missing device-identity or device in pair success node', { data: stanza })
139
146
  }
140
147
  const bizName = businessNode?.attrs?.name
141
148
  const jid = deviceNode.attrs.jid
142
149
  const lid = deviceNode.attrs.lid
143
- const { details, hmac, accountType } = WAProto_1.proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content)
150
+ const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content)
144
151
 
145
152
  let hmacPrefix = Buffer.from([])
146
- if (accountType !== undefined && accountType === WAProto_1.proto.ADVEncryptionType.HOSTED) {
153
+ if (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED) {
147
154
  hmacPrefix = Buffer.from([6, 5])
148
155
  }
149
156
 
150
- const advSign = crypto_2.hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))
157
+ const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))
151
158
  if (Buffer.compare(hmac, advSign) !== 0) {
152
- throw new boom_1.Boom('Invalid account signature')
159
+ throw new Boom('Invalid account signature')
153
160
  }
154
161
 
155
- const account = WAProto_1.proto.ADVSignedDeviceIdentity.decode(details)
162
+ const account = proto.ADVSignedDeviceIdentity.decode(details)
156
163
  const { accountSignatureKey, accountSignature, details: deviceDetails } = account
157
164
 
158
- const decodedDeviceIdentity = WAProto_1.proto.ADVDeviceIdentity.decode(deviceDetails)
165
+ const decodedDeviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails)
159
166
 
160
167
  const accountSignaturePrefix =
161
- decodedDeviceIdentity.deviceType === WAProto_1.proto.ADVEncryptionType.HOSTED
168
+ decodedDeviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
162
169
  ? Buffer.from([6, 5])
163
170
  : Buffer.from([6, 0])
164
171
  const accountMsg = Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public])
165
- if (!crypto_2.Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
166
- throw new boom_1.Boom('Failed to verify account signature')
172
+ if (!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
173
+ throw new Boom('Failed to verify account signature')
167
174
  }
168
175
 
169
176
  const deviceMsg = Buffer.concat([
@@ -172,14 +179,14 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
172
179
  signedIdentityKey.public,
173
180
  accountSignatureKey
174
181
  ])
175
- account.deviceSignature = crypto_2.Curve.sign(signedIdentityKey.private, deviceMsg)
176
- const identity = signal_1.createSignalIdentity(lid, accountSignatureKey)
182
+ account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg)
183
+ const identity = createSignalIdentity(lid, accountSignatureKey)
177
184
  const accountEnc = encodeSignedDeviceIdentity(account, false)
178
- const deviceIdentityData = WAProto_1.proto.ADVDeviceIdentity.decode(account.details)
185
+ const deviceIdentityData = proto.ADVDeviceIdentity.decode(account.details)
179
186
  const reply = {
180
187
  tag: 'iq',
181
188
  attrs: {
182
- to: WABinary_1.S_WHATSAPP_NET,
189
+ to: S_WHATSAPP_NET,
183
190
  type: 'result',
184
191
  id: msgId,
185
192
  },
@@ -219,7 +226,7 @@ const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
219
226
  if (!includeSignatureKey || !account.accountSignatureKey?.length) {
220
227
  account.accountSignatureKey = null
221
228
  }
222
- return WAProto_1.proto.ADVSignedDeviceIdentity.encode(account).finish()
229
+ return proto.ADVSignedDeviceIdentity.encode(account).finish()
223
230
  }
224
231
 
225
232
  module.exports = {
@@ -1,38 +1,12 @@
1
1
  "use strict"
2
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
3
  Object.defineProperty(exports, "__esModule", { value: true })
30
4
 
31
- const util_1 = require("util")
32
- const zlib_1 = require("zlib")
33
- const constants = __importStar(require("./constants"))
34
- const jid_utils_1 = require("./jid-utils")
35
- const inflatePromise = util_1.promisify(zlib_1.inflate)
5
+ const { promisify } = require("util")
6
+ const { inflate } = require("zlib")
7
+ const { jidEncode } = require("./jid-utils")
8
+ const constants = require("./constants")
9
+ const inflatePromise = promisify(inflate)
36
10
 
37
11
  const decompressingIfRequired = async (buffer) => {
38
12
  if (2 & buffer.readUInt8()) {
@@ -168,7 +142,7 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
168
142
  const agent = readByte()
169
143
  const device = readByte()
170
144
  const user = readString(readByte())
171
- return jid_utils_1.jidEncode(user, agent === 0 ? 's.whatsapp.net' : 'lid', device)
145
+ return jidEncode(user, agent === 0 ? 's.whatsapp.net' : 'lid', device)
172
146
  }
173
147
 
174
148
  const readString = (tag) => {
@@ -1,35 +1,9 @@
1
1
  "use strict"
2
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
3
  Object.defineProperty(exports, "__esModule", { value: true })
30
4
 
31
- const constants = __importStar(require("./constants"))
32
- const jid_utils_1 = require("./jid-utils")
5
+ const { jidDecode } = require("./jid-utils")
6
+ const constants = require("./constants")
33
7
 
34
8
  const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
35
9
  const encoded = encodeBinaryNodeInner(node, opts, buffer)
@@ -201,7 +175,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
201
175
  writePackedBytes(str, 'hex')
202
176
  }
203
177
  else if (str) {
204
- const decodedJid = (0, jid_utils_1.jidDecode)(str)
178
+ const decodedJid = jidDecode(str)
205
179
  if (decodedJid) {
206
180
  writeJid(decodedJid)
207
181
  }
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true })
4
4
 
5
- const boom_1 = require("@hapi/boom")
6
- const WAProto_1 = require("../../WAProto")
5
+ const { Boom } = require("@hapi/boom")
6
+ const { proto } = require("../../WAProto")
7
7
 
8
8
  // some extra useful utilities
9
9
  const getBinaryNodeChildren = (node, childTag) => {
@@ -53,7 +53,7 @@ const getBinaryNodeChildUInt = (node, childTag, length) => {
53
53
  const assertNodeErrorFree = (node) => {
54
54
  const errNode = getBinaryNodeChild(node, 'error')
55
55
  if (errNode) {
56
- throw new boom_1.Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code })
56
+ throw new Boom(errNode.attrs.text || 'Unknown error', { data: +errNode.attrs.code })
57
57
  }
58
58
  }
59
59
 
@@ -71,7 +71,7 @@ const getBinaryNodeMessages = ({ content }) => {
71
71
  if (Array.isArray(content)) {
72
72
  for (const item of content) {
73
73
  if (item.tag === 'message') {
74
- msgs.push(WAProto_1.proto.WebMessageInfo.decode(item.content))
74
+ msgs.push(proto.WebMessageInfo.decode(item.content))
75
75
  }
76
76
  }
77
77
  }
@@ -1,22 +1,38 @@
1
1
  "use strict"
2
2
 
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ const __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k
5
- var desc = Object.getOwnPropertyDescriptor(m, k)
5
+
6
+ let desc = Object.getOwnPropertyDescriptor(m, k)
7
+
6
8
  if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k] } }
9
+ desc = {
10
+ enumerable: true,
11
+ get: function() {
12
+ return m[k]
13
+ }
14
+ }
8
15
  }
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
16
 
15
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
+ Object.defineProperty(o, k2, desc)
18
+
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k
21
+ o[k2] = m[k]
22
+ }
23
+ ))
24
+
25
+ const __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) {
27
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
28
+ __createBinding(exports, m, p)
29
+ }
30
+ }
17
31
  }
18
32
 
19
- Object.defineProperty(exports, "__esModule", { value: true })
33
+ Object.defineProperty(exports, "__esModule", {
34
+ value: true
35
+ })
20
36
 
21
37
  __exportStar(require("./encode"), exports)
22
38
  __exportStar(require("./decode"), exports)