lordceaser-baileys 2.0.11 → 2.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/package.json +2 -5
  2. package/lib/Defaults/baileys-version.json +0 -3
  3. package/lib/Defaults/index.d.ts +0 -284
  4. package/lib/Defaults/index.js +0 -121
  5. package/lib/Defaults/phonenumber-mcc.json +0 -223
  6. package/lib/Signal/libsignal.d.ts +0 -4
  7. package/lib/Signal/libsignal.js +0 -162
  8. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
  9. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  10. package/lib/Socket/Client/index.d.ts +0 -2
  11. package/lib/Socket/Client/index.js +0 -22
  12. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
  13. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  14. package/lib/Socket/Client/types.d.ts +0 -16
  15. package/lib/Socket/Client/types.js +0 -18
  16. package/lib/Socket/Client/web-socket-client.js +0 -62
  17. package/lib/Socket/Client/websocket.d.ts +0 -13
  18. package/lib/Socket/Client/websocket.js +0 -62
  19. package/lib/Socket/business.d.ts +0 -182
  20. package/lib/Socket/business.js +0 -268
  21. package/lib/Socket/chats.d.ts +0 -96
  22. package/lib/Socket/chats.js +0 -1026
  23. package/lib/Socket/groups.d.ts +0 -130
  24. package/lib/Socket/groups.js +0 -338
  25. package/lib/Socket/index.d.ts +0 -185
  26. package/lib/Socket/index.js +0 -14
  27. package/lib/Socket/messages-recv.d.ts +0 -171
  28. package/lib/Socket/messages-recv.js +0 -1182
  29. package/lib/Socket/messages-send.d.ts +0 -162
  30. package/lib/Socket/messages-send.js +0 -1006
  31. package/lib/Socket/newsletter.d.ts +0 -142
  32. package/lib/Socket/newsletter.js +0 -256
  33. package/lib/Socket/registration.d.ts +0 -264
  34. package/lib/Socket/registration.js +0 -166
  35. package/lib/Socket/socket.d.ts +0 -45
  36. package/lib/Socket/socket.js +0 -751
  37. package/lib/Socket/socket.js.bak +0 -751
  38. package/lib/Socket/usync.d.ts +0 -37
  39. package/lib/Socket/usync.js +0 -83
  40. package/lib/Store/index.d.ts +0 -4
  41. package/lib/Store/index.js +0 -24
  42. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  43. package/lib/Store/make-cache-manager-store.js +0 -90
  44. package/lib/Store/make-in-memory-store.d.ts +0 -123
  45. package/lib/Store/make-in-memory-store.js +0 -429
  46. package/lib/Store/make-ordered-dictionary.d.ts +0 -12
  47. package/lib/Store/make-ordered-dictionary.js +0 -86
  48. package/lib/Store/object-repository.d.ts +0 -10
  49. package/lib/Store/object-repository.js +0 -31
  50. package/lib/Types/Auth.d.ts +0 -120
  51. package/lib/Types/Auth.js +0 -3
  52. package/lib/Types/Call.d.ts +0 -14
  53. package/lib/Types/Call.js +0 -3
  54. package/lib/Types/Chat.d.ts +0 -134
  55. package/lib/Types/Chat.js +0 -9
  56. package/lib/Types/Contact.d.ts +0 -25
  57. package/lib/Types/Contact.js +0 -3
  58. package/lib/Types/Events.d.ts +0 -212
  59. package/lib/Types/Events.js +0 -3
  60. package/lib/Types/GroupMetadata.d.ts +0 -64
  61. package/lib/Types/GroupMetadata.js +0 -3
  62. package/lib/Types/Label.d.ts +0 -48
  63. package/lib/Types/Label.js +0 -31
  64. package/lib/Types/LabelAssociation.d.ts +0 -35
  65. package/lib/Types/LabelAssociation.js +0 -13
  66. package/lib/Types/Message.d.ts +0 -459
  67. package/lib/Types/Message.js +0 -13
  68. package/lib/Types/Newsletter.d.ts +0 -107
  69. package/lib/Types/Newsletter.js +0 -38
  70. package/lib/Types/Product.d.ts +0 -92
  71. package/lib/Types/Product.js +0 -3
  72. package/lib/Types/Signal.d.ts +0 -68
  73. package/lib/Types/Signal.js +0 -3
  74. package/lib/Types/Socket.d.ts +0 -120
  75. package/lib/Types/Socket.js +0 -3
  76. package/lib/Types/State.d.ts +0 -29
  77. package/lib/Types/State.js +0 -3
  78. package/lib/Types/USync.d.ts +0 -26
  79. package/lib/Types/USync.js +0 -3
  80. package/lib/Types/index.d.ts +0 -78
  81. package/lib/Types/index.js +0 -47
  82. package/lib/Utils/auth-utils.d.ts +0 -21
  83. package/lib/Utils/auth-utils.js +0 -205
  84. package/lib/Utils/baileys-event-stream.d.ts +0 -18
  85. package/lib/Utils/baileys-event-stream.js +0 -70
  86. package/lib/Utils/business.d.ts +0 -29
  87. package/lib/Utils/business.js +0 -247
  88. package/lib/Utils/chat-utils.d.ts +0 -82
  89. package/lib/Utils/chat-utils.js +0 -774
  90. package/lib/Utils/crypto.d.ts +0 -56
  91. package/lib/Utils/crypto.js +0 -179
  92. package/lib/Utils/decode-wa-message.d.ts +0 -41
  93. package/lib/Utils/decode-wa-message.js +0 -236
  94. package/lib/Utils/event-buffer.d.ts +0 -39
  95. package/lib/Utils/event-buffer.js +0 -548
  96. package/lib/Utils/generics.d.ts +0 -129
  97. package/lib/Utils/generics.js +0 -485
  98. package/lib/Utils/history.d.ts +0 -23
  99. package/lib/Utils/history.js +0 -100
  100. package/lib/Utils/index.d.ts +0 -20
  101. package/lib/Utils/index.js +0 -40
  102. package/lib/Utils/link-preview.d.ts +0 -23
  103. package/lib/Utils/link-preview.js +0 -120
  104. package/lib/Utils/logger.d.ts +0 -13
  105. package/lib/Utils/logger.js +0 -7
  106. package/lib/Utils/lt-hash.d.ts +0 -14
  107. package/lib/Utils/lt-hash.js +0 -58
  108. package/lib/Utils/make-mutex.d.ts +0 -9
  109. package/lib/Utils/make-mutex.js +0 -49
  110. package/lib/Utils/messages-media.d.ts +0 -129
  111. package/lib/Utils/messages-media.js +0 -782
  112. package/lib/Utils/messages.d.ts +0 -103
  113. package/lib/Utils/messages.js +0 -1631
  114. package/lib/Utils/noise-handler.d.ts +0 -20
  115. package/lib/Utils/noise-handler.js +0 -155
  116. package/lib/Utils/process-message.d.ts +0 -49
  117. package/lib/Utils/process-message.js +0 -387
  118. package/lib/Utils/signal.d.ts +0 -42
  119. package/lib/Utils/signal.js +0 -166
  120. package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
  121. package/lib/Utils/use-mongo-file-auth-state.js +0 -84
  122. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  123. package/lib/Utils/use-multi-file-auth-state.js +0 -131
  124. package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
  125. package/lib/Utils/use-single-file-auth-state.js +0 -80
  126. package/lib/Utils/use-sql-file-auth-state.d.ts +0 -6
  127. package/lib/Utils/use-sql-file-auth-state.js +0 -143
  128. package/lib/Utils/validate-connection.d.ts +0 -13
  129. package/lib/Utils/validate-connection.js +0 -186
  130. package/lib/WABinary/constants.d.ts +0 -30
  131. package/lib/WABinary/constants.js +0 -53
  132. package/lib/WABinary/decode.d.ts +0 -9
  133. package/lib/WABinary/decode.js +0 -288
  134. package/lib/WABinary/encode.d.ts +0 -3
  135. package/lib/WABinary/encode.js +0 -256
  136. package/lib/WABinary/generic-utils.d.ts +0 -28
  137. package/lib/WABinary/generic-utils.js +0 -150
  138. package/lib/WABinary/index.d.ts +0 -5
  139. package/lib/WABinary/index.js +0 -25
  140. package/lib/WABinary/jid-utils.d.ts +0 -53
  141. package/lib/WABinary/jid-utils.js +0 -92
  142. package/lib/WABinary/types.d.ts +0 -22
  143. package/lib/WABinary/types.js +0 -3
  144. package/lib/WAM/BinaryInfo.d.ts +0 -16
  145. package/lib/WAM/BinaryInfo.js +0 -17
  146. package/lib/WAM/constants.d.ts +0 -47
  147. package/lib/WAM/constants.js +0 -15371
  148. package/lib/WAM/encode.d.ts +0 -3
  149. package/lib/WAM/encode.js +0 -165
  150. package/lib/WAM/index.d.ts +0 -3
  151. package/lib/WAM/index.js +0 -23
  152. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
  153. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
  154. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  155. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -36
  156. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
  157. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -62
  158. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
  159. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -35
  160. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -9
  161. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -30
  162. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
  163. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -46
  164. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  165. package/lib/WAUSync/Protocols/index.js +0 -26
  166. package/lib/WAUSync/USyncQuery.d.ts +0 -31
  167. package/lib/WAUSync/USyncQuery.js +0 -92
  168. package/lib/WAUSync/USyncUser.d.ts +0 -12
  169. package/lib/WAUSync/USyncUser.js +0 -30
  170. package/lib/WAUSync/index.d.ts +0 -3
  171. package/lib/WAUSync/index.js +0 -23
  172. package/lib/index.d.ts +0 -13
  173. package/lib/index.js +0 -33
@@ -1,166 +0,0 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
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")
10
-
11
- const createSignalIdentity = (wid, accountSignatureKey) => {
12
- return {
13
- identifier: { name: wid, deviceId: 0 },
14
- identifierKey: crypto_1.generateSignalPubKey(accountSignatureKey)
15
- }
16
- }
17
-
18
- const getPreKeys = async ({ get }, min, limit) => {
19
- const idList = []
20
- for (let id = min; id < limit; id++) {
21
- idList.push(id.toString())
22
- }
23
- return get('pre-key', idList)
24
- }
25
-
26
- const generateOrGetPreKeys = (creds, range) => {
27
- const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId
28
- const remaining = range - avaliable
29
- const lastPreKeyId = creds.nextPreKeyId + remaining - 1
30
- const newPreKeys = {}
31
- if (remaining > 0) {
32
- for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
33
- newPreKeys[i] = crypto_1.Curve.generateKeyPair()
34
- }
35
- }
36
- return {
37
- newPreKeys,
38
- lastPreKeyId,
39
- preKeysRange: [creds.firstUnuploadedPreKeyId, range],
40
- }
41
- }
42
-
43
- const xmppSignedPreKey = (key) => ({
44
- tag: 'skey',
45
- attrs: {},
46
- content: [
47
- { tag: 'id', attrs: {}, content: generics_1.encodeBigEndian(key.keyId, 3) },
48
- { tag: 'value', attrs: {}, content: key.keyPair.public },
49
- { tag: 'signature', attrs: {}, content: key.signature }
50
- ]
51
- })
52
-
53
- const xmppPreKey = (pair, id) => ({
54
- tag: 'key',
55
- attrs: {},
56
- content: [
57
- { tag: 'id', attrs: {}, content: generics_1.encodeBigEndian(id, 3) },
58
- { tag: 'value', attrs: {}, content: pair.public }
59
- ]
60
- })
61
-
62
- const parseAndInjectE2ESessions = async (node, repository) => {
63
- 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')
67
- }) : undefined)
68
- const nodes = WABinary_1.getBinaryNodeChildren(WABinary_1.getBinaryNodeChild(node, 'list'), 'user')
69
- for (const node of nodes) {
70
- WABinary_1.assertNodeErrorFree(node)
71
- }
72
- // Most of the work in repository.injectE2ESession is CPU intensive, not IO
73
- // So Promise.all doesn't really help here,
74
- // but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
75
- // This way we chunk it in smaller parts and between those parts we can yield to the event loop
76
- // It's rare case when you need to E2E sessions for so many users, but it's possible
77
- const chunkSize = 100
78
- const chunks = lodash_1.chunk(nodes, chunkSize)
79
- for (const nodesChunk of chunks) {
80
- 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')
84
- const jid = node.attrs.jid
85
- const registrationId = WABinary_1.getBinaryNodeChildUInt(node, 'registration', 4)
86
- await repository.injectE2ESession({
87
- jid,
88
- session: {
89
- registrationId: registrationId,
90
- identityKey: crypto_1.generateSignalPubKey(identity),
91
- signedPreKey: extractKey(signedKey),
92
- preKey: extractKey(key)
93
- }
94
- })
95
- }))
96
- }
97
- }
98
-
99
- const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
100
- const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
101
- const extracted = []
102
- for (const userResult of result) {
103
- const { devices, id } = userResult
104
- const { user } = WABinary_1.jidDecode(id)
105
- const deviceList = devices?.deviceList
106
- if (Array.isArray(deviceList)) {
107
- for (const { id: device, keyIndex } of deviceList) {
108
- if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
109
- (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
110
- (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
111
- ) {
112
- extracted.push({ user, device })
113
- }
114
- }
115
- }
116
- }
117
- return extracted
118
- }
119
-
120
- /**
121
- * get the next N keys for upload or processing
122
- * @param count number of pre-keys to get or generate
123
- */
124
- const getNextPreKeys = async ({ creds, keys }, count) => {
125
- const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count)
126
- const update = {
127
- nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
128
- firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
129
- }
130
- await keys.set({ 'pre-key': newPreKeys })
131
- const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1])
132
- return { update, preKeys }
133
- }
134
-
135
- const getNextPreKeysNode = async (state, count) => {
136
- const { creds } = state
137
- const { update, preKeys } = await getNextPreKeys(state, count)
138
- const node = {
139
- tag: 'iq',
140
- attrs: {
141
- xmlns: 'encrypt',
142
- type: 'set',
143
- to: WABinary_1.S_WHATSAPP_NET,
144
- },
145
- content: [
146
- { tag: 'registration', attrs: {}, content: generics_1.encodeBigEndian(creds.registrationId) },
147
- { tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
148
- { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
149
- { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
150
- xmppSignedPreKey(creds.signedPreKey)
151
- ]
152
- }
153
- return { update, node }
154
- }
155
-
156
- module.exports = {
157
- createSignalIdentity,
158
- getPreKeys,
159
- generateOrGetPreKeys,
160
- xmppSignedPreKey,
161
- xmppPreKey,
162
- parseAndInjectE2ESessions,
163
- extractDeviceJids,
164
- getNextPreKeys,
165
- getNextPreKeysNode
166
- }
@@ -1,6 +0,0 @@
1
- import { AuthenticationState } from '../Types'
2
-
3
- export declare const useMongoFileAuthState: (collection: string) => Promise<{
4
- state: AuthenticationState
5
- saveCreds: () => Promise<void>
6
- }>
@@ -1,84 +0,0 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const WAProto_1 = require("../../WAProto")
6
- const auth_utils_1 = require("./auth-utils")
7
- const generics_1 = require("./generics")
8
-
9
- /*
10
- code from amiruldev readjusted by @irull2nd, don't delete WM!
11
- */
12
- const useMongoFileAuthState = async (collection) => {
13
- const writeData = (data,id) => {
14
- const informationToStore = JSON.parse(
15
- JSON.stringify(data, generics_1.BufferJSON.replacer)
16
- )
17
- const update = {
18
- $set: {
19
- ...informationToStore,
20
- },
21
- }
22
-
23
- return collection.updateOne({_id: id},update, {upsert: true})
24
- }
25
-
26
- const readData = async (id) => {
27
- try {
28
- const data = JSON.stringify(await collection.findOne({_id: id}))
29
- return JSON.parse(data, generic_1.BufferJSON.reviver)
30
- } catch (err) {
31
- console.log(err)
32
- }
33
- }
34
-
35
- const removeData = async (id) => {
36
- try{
37
- await collection.deleteOne({_id: id})
38
- }catch(err){
39
- console.log('error',err)
40
- }
41
- }
42
-
43
- const creds = (await readData('creds')) || auth_utils_1.initAuthCreds()
44
-
45
- return{
46
- state:{
47
- creds,
48
- keys: {
49
- get: async (type,ids)=> {
50
- const data = {}
51
- await Promise
52
- .all(
53
- ids.map(async (id) => {
54
- let value = await readData(`${type}-${id}`)
55
- if(type === "app-state-sync-key"){
56
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(data)
57
- }
58
- data[id] = value
59
- })
60
- )
61
- return data
62
- },
63
- set: async (data) => {
64
- const tasks = []
65
- for (const category of Object.keys(data)){
66
- for (const id of Object.keys(data[category])){
67
- const value = data[category][id]
68
- const key = `${category}-${id}`
69
- tasks.push(value? writeData(value,key) : removeData(key))
70
- }
71
- }
72
- await Promise.all(tasks)
73
- },
74
- },
75
- },
76
- saveCreds: () => {
77
- return writeData(creds, "creds")
78
- }
79
- }
80
- }
81
-
82
- module.exports = {
83
- useMongoFileAuthState
84
- }
@@ -1,13 +0,0 @@
1
- import { AuthenticationState } from '../Types'
2
-
3
- /**
4
- * stores the full authentication state in a single folder.
5
- * Far more efficient than singlefileauthstate
6
- *
7
- * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
8
- * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
9
- * */
10
- export declare const useMultiFileAuthState: (folder: string) => Promise<{
11
- state: AuthenticationState
12
- saveCreds: () => Promise<void>
13
- }>
@@ -1,131 +0,0 @@
1
- "use strict"
2
-
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod }
5
- }
6
-
7
- Object.defineProperty(exports, "__esModule", { value: true })
8
-
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")
15
- // We need to lock files due to the fact that we are using async functions to read and write files
16
- // https://github.com/WhiskeySockets/Baileys/issues/794
17
- // https://github.com/nodejs/node/issues/26338
18
- // Use a Map to store mutexes for each file path
19
- const fileLocks = new Map()
20
-
21
- // Get or create a mutex for a specific file path
22
- const getFileLock = (path) => {
23
- let mutex = fileLocks.get(path)
24
- if (!mutex) {
25
- mutex = new async_mutex_1.Mutex()
26
- fileLocks.set(path, mutex)
27
- }
28
-
29
- return mutex
30
- }
31
-
32
- /**
33
- * stores the full authentication state in a single folder.
34
- * Far more efficient than singlefileauthstate
35
- *
36
- * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
37
- * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
38
- * */
39
- const useMultiFileAuthState = async (folder) => {
40
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
- const writeData = async (data, file) => {
42
- const filePath = path_1.join(folder, fixFileName(file))
43
- const mutex = getFileLock(filePath)
44
- return mutex.acquire().then(async (release) => {
45
- try {
46
- await promises_1.writeFile(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer))
47
- } finally {
48
- release()
49
- }
50
- })
51
- }
52
- const readData = async (file) => {
53
- try {
54
- const filePath = path_1.join(folder, fixFileName(file))
55
- const mutex = getFileLock(filePath)
56
- const data = await mutex.acquire().then(async (release) => {
57
- try {
58
- return await promises_1.readFile(filePath, { encoding: 'utf-8' })
59
- } finally {
60
- release()
61
- }
62
- })
63
-
64
- return JSON.parse(data, generics_1.BufferJSON.reviver)
65
- } catch (error) {
66
- return null
67
- }
68
- }
69
- const removeData = async (file) => {
70
- try {
71
- const filePath = path_1.join(folder, fixFileName(file))
72
- const mutex = getFileLock(filePath)
73
- await mutex.acquire().then(async (release) => {
74
- try {
75
- await promises_1.unlink(filePath)
76
- } finally {
77
- release()
78
- }
79
- })
80
- } catch {}
81
- }
82
- const folderInfo = await promises_1.stat(folder).catch(() => { })
83
- if (folderInfo) {
84
- if (!folderInfo.isDirectory()) {
85
- throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`)
86
- }
87
- }
88
- else {
89
- await promises_1.mkdir(folder, { recursive: true })
90
- }
91
- const fixFileName = (file) => {
92
- return file?.replace(/\//g, '__')?.replace(/:/g, '-')
93
- }
94
- const creds = await readData('creds.json') || auth_utils_1.initAuthCreds()
95
- return {
96
- state: {
97
- creds,
98
- keys: {
99
- get: async (type, ids) => {
100
- const data = {}
101
- await Promise.all(ids.map(async (id) => {
102
- let value = await readData(`${type}-${id}.json`)
103
- if (type === 'app-state-sync-key' && value) {
104
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value)
105
- }
106
- data[id] = value
107
- }))
108
- return data
109
- },
110
- set: async (data) => {
111
- const tasks = []
112
- for (const category in data) {
113
- for (const id in data[category]) {
114
- const value = data[category][id]
115
- const file = `${category}-${id}.json`
116
- tasks.push(value ? writeData(value, file) : removeData(file))
117
- }
118
- }
119
- await Promise.all(tasks)
120
- }
121
- }
122
- },
123
- saveCreds: async () => {
124
- return writeData(creds, 'creds.json')
125
- }
126
- }
127
- }
128
-
129
- module.exports = {
130
- useMultiFileAuthState
131
- }
@@ -1,13 +0,0 @@
1
- import { ILogger } from './logger'
2
- import type { AuthenticationState } from '../Types'
3
-
4
- /**
5
- * @deprecated use multi file auth state instead please
6
- * stores the full authentication state in a single JSON file
7
- *
8
- * DO NOT USE IN A PROD ENVIRONMENT, only meant to serve as an example
9
- * */
10
- export declare const useSingleFileAuthState: (filename: string, logger?: ILogger) => {
11
- state: AuthenticationState
12
- saveState: () => void
13
- }
@@ -1,80 +0,0 @@
1
- "use strict"
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
- const WAProto_1 = require("../../WAProto")
6
- const auth_utils_1 = require("./auth-utils")
7
- const generics_1 = require("./generics")
8
-
9
- // useless key map only there to maintain backwards compatibility
10
- // do not use in your own systems please
11
- const KEY_MAP = {
12
- 'pre-key': 'preKeys',
13
- 'session': 'sessions',
14
- 'sender-key': 'senderKeys',
15
- 'app-state-sync-key': 'appStateSyncKeys',
16
- 'app-state-sync-version': 'appStateVersions',
17
- 'sender-key-memory': 'senderKeyMemory'
18
- }
19
-
20
- /**
21
- * @deprecated use multi file auth state instead please
22
- * stores the full authentication state in a single JSON file
23
- *
24
- * DO NOT USE IN A PROD ENVIRONMENT, only meant to serve as an example
25
- * */
26
- const useSingleFileAuthState = (filename, logger) => {
27
- // require fs here so that in case "fs" is not available -- the app does not crash
28
- const { readFileSync, writeFileSync, existsSync } = require('fs')
29
- let creds
30
- let keys = {}
31
- // save the authentication state to a file
32
- const saveState = () => {
33
- logger && logger.trace('saving auth state')
34
- writeFileSync(filename,
35
- // BufferJSON replacer utility saves buffers nicely
36
- JSON.stringify({ creds, keys }, generics_1.BufferJSON.replacer, 2))
37
- }
38
- if (existsSync(filename)) {
39
- const result = JSON.parse(readFileSync(filename, { encoding: 'utf-8' }), generics_1.BufferJSON.reviver)
40
- creds = result.creds
41
- keys = result.keys
42
- }
43
- else {
44
- creds = auth_utils_1.initAuthCreds()
45
- keys = {}
46
- }
47
- return {
48
- state: {
49
- creds,
50
- keys: {
51
- get: (type, ids) => {
52
- const key = KEY_MAP[type]
53
- return ids.reduce((dict, id) => {
54
- let value = keys[key]?.[id]
55
- if (value) {
56
- if (type === 'app-state-sync-key') {
57
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value)
58
- }
59
- dict[id] = value
60
- }
61
- return dict
62
- }, {})
63
- },
64
- set: (data) => {
65
- for (const _key in data) {
66
- const key = KEY_MAP[_key]
67
- keys[key] = keys[key] || {}
68
- Object.assign(keys[key], data[_key])
69
- }
70
- saveState()
71
- }
72
- }
73
- },
74
- saveState
75
- }
76
- }
77
-
78
- module.exports = {
79
- useSingleFileAuthState
80
- }
@@ -1,6 +0,0 @@
1
- import { AuthenticationState } from '../Types'
2
-
3
- export declare const useSqlAuthState: (collection: string) => Promise<{
4
- state: AuthenticationState
5
- saveCreds: () => Promise<void>
6
- }>
@@ -1,143 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true })
6
-
7
- const promise_1 = __importDefault(require("mysql2/promise"));
8
- const Utils_1 = require("../Utils");
9
- // Create MySQL connection pool for better performance
10
- /*
11
- code from amiruldev readjusted by @irull2nd, don't delete WM!
12
- */
13
- const createConnectionPool = (config) => {
14
- return promise_1.default.createPool({
15
- host: config.host,
16
- user: config.user,
17
- password: config.password,
18
- database: config.database,
19
- waitForConnections: true,
20
- connectionLimit: 10,
21
- queueLimit: 0
22
- });
23
- };
24
- const useSqlAuthState = async (config) => {
25
- const { host, user, password, database, tableName, session } = config;
26
- const pool = createConnectionPool({ host, user, password, database });
27
- const table = tableName !== null && tableName !== void 0 ? tableName : 'amiruldev_auth';
28
- const sessionName = session !== null && session !== void 0 ? session : `session_`;
29
- // Create table if it doesn't exist
30
- const createTable = async () => {
31
- await pool.execute(`
32
- CREATE TABLE IF NOT EXISTS \`${table}\` (
33
- id VARCHAR(255) PRIMARY KEY,
34
- value JSON,
35
- session VARCHAR(255),
36
- timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
37
- )
38
- `);
39
- };
40
- // Delete sessions older than 1 day
41
- const deleteOldSessions = async () => {
42
- await pool.execute(`
43
- DELETE FROM \`${table}\`
44
- WHERE session = ? AND timestamp < NOW() - INTERVAL 1 DAY
45
- `, [sessionName]);
46
- };
47
- // Remove unused tables (if any)
48
- const removeUnusedTables = async () => {
49
- const [rows] = await pool.execute(`
50
- SELECT table_name
51
- FROM information_schema.tables
52
- WHERE table_schema = ? AND table_name != ?`, [database, table]);
53
- const unusedTables = rows.filter((row) => !row.table_name.startsWith('session_'));
54
- for (const { table_name } of unusedTables) {
55
- await pool.execute(`DROP TABLE IF EXISTS \`${table_name}\``);
56
- }
57
- };
58
- // Ensure creds entry exists
59
- const ensureSession = async () => {
60
- const [rows] = await pool.execute(`SELECT * FROM \`${table}\` WHERE id = 'creds'`);
61
- if (rows.length === 0) {
62
- await pool.execute(`INSERT INTO \`${table}\` (id, value, session) VALUES ('creds', ?, ?)`, [JSON.stringify((0, Utils_1.initAuthCreds)(), Utils_1.BufferJSON.replacer), sessionName]);
63
- }
64
- };
65
- // Initialize the database
66
- await createTable();
67
- await deleteOldSessions();
68
- await removeUnusedTables();
69
- await ensureSession();
70
- const query = async (tableName, docId) => {
71
- const [rows] = await pool.execute(`SELECT * FROM \`${tableName}\` WHERE id = ?`, [`${sessionName}-${docId}`]);
72
- return rows.length > 0 ? rows[0] : null;
73
- };
74
- const readData = async (id) => {
75
- const data = await query(table, id);
76
- if (!data || !data.value) {
77
- return null;
78
- }
79
- const creds = typeof data.value === 'string' ? data.value : JSON.stringify(data.value);
80
- return JSON.parse(creds, Utils_1.BufferJSON.reviver);
81
- };
82
- const writeData = async (id, value) => {
83
- const valueFixed = JSON.stringify(value, Utils_1.BufferJSON.replacer);
84
- await pool.execute(`INSERT INTO \`${table}\` (id, value, session) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE value = VALUES(value), timestamp = CURRENT_TIMESTAMP`, [`${sessionName}-${id}`, valueFixed, sessionName]);
85
- };
86
- const removeData = async (id) => {
87
- await pool.execute(`DELETE FROM \`${table}\` WHERE id = ?`, [`${sessionName}-${id}`]);
88
- };
89
- const clearAll = async () => {
90
- await pool.execute(`DELETE FROM \`${table}\` WHERE session = ? AND id != 'creds'`, [sessionName]);
91
- };
92
- const removeAll = async () => {
93
- await pool.execute(`DELETE FROM \`${table}\` WHERE session = ?`, [sessionName]);
94
- };
95
- const creds = (await readData('creds')) || (0, Utils_1.initAuthCreds)();
96
- return {
97
- state: {
98
- creds,
99
- keys: {
100
- get: async (type, ids) => {
101
- const data = {};
102
- for (const id of ids) {
103
- let value = await readData(`${type}-${id}`);
104
- if (type === 'app-state-sync-key' && value) {
105
- value = (0, Utils_1.fromObject)(value);
106
- }
107
- data[id] = value;
108
- }
109
- return data;
110
- },
111
- set: async (data) => {
112
- for (const category in data) {
113
- for (const id in data[category]) {
114
- const value = data[category][id];
115
- const name = `${category}-${id}`;
116
- if (value) {
117
- await writeData(name, value);
118
- }
119
- else {
120
- await removeData(name);
121
- }
122
- }
123
- }
124
- }
125
- }
126
- },
127
- saveCreds: async () => {
128
- await writeData('creds', creds);
129
- },
130
- clear: async () => {
131
- await clearAll();
132
- },
133
- removeCreds: async () => {
134
- await removeAll();
135
- },
136
- query: async (tableName, docId) => {
137
- return await query(tableName, docId);
138
- }
139
- };
140
- };
141
- module.exports = {
142
- useSqlAuthState
143
- }
@@ -1,13 +0,0 @@
1
- import { proto } from '../../WAProto'
2
- import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types'
3
- import { BinaryNode } from '../WABinary'
4
-
5
- export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload
6
-
7
- export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload
8
-
9
- export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
10
- creds: Partial<AuthenticationCreds>
11
- reply: BinaryNode
12
- }
13
- export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array