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.
- package/package.json +2 -5
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -284
- package/lib/Defaults/index.js +0 -121
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/libsignal.d.ts +0 -4
- package/lib/Signal/libsignal.js +0 -162
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/index.js +0 -22
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/types.js +0 -18
- package/lib/Socket/Client/web-socket-client.js +0 -62
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/business.d.ts +0 -182
- package/lib/Socket/business.js +0 -268
- package/lib/Socket/chats.d.ts +0 -96
- package/lib/Socket/chats.js +0 -1026
- package/lib/Socket/groups.d.ts +0 -130
- package/lib/Socket/groups.js +0 -338
- package/lib/Socket/index.d.ts +0 -185
- package/lib/Socket/index.js +0 -14
- package/lib/Socket/messages-recv.d.ts +0 -171
- package/lib/Socket/messages-recv.js +0 -1182
- package/lib/Socket/messages-send.d.ts +0 -162
- package/lib/Socket/messages-send.js +0 -1006
- package/lib/Socket/newsletter.d.ts +0 -142
- package/lib/Socket/newsletter.js +0 -256
- package/lib/Socket/registration.d.ts +0 -264
- package/lib/Socket/registration.js +0 -166
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/socket.js +0 -751
- package/lib/Socket/socket.js.bak +0 -751
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/index.js +0 -24
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -90
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-in-memory-store.js +0 -429
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/make-ordered-dictionary.js +0 -86
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -31
- package/lib/Types/Auth.d.ts +0 -120
- package/lib/Types/Auth.js +0 -3
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Call.js +0 -3
- package/lib/Types/Chat.d.ts +0 -134
- package/lib/Types/Chat.js +0 -9
- package/lib/Types/Contact.d.ts +0 -25
- package/lib/Types/Contact.js +0 -3
- package/lib/Types/Events.d.ts +0 -212
- package/lib/Types/Events.js +0 -3
- package/lib/Types/GroupMetadata.d.ts +0 -64
- package/lib/Types/GroupMetadata.js +0 -3
- package/lib/Types/Label.d.ts +0 -48
- package/lib/Types/Label.js +0 -31
- package/lib/Types/LabelAssociation.d.ts +0 -35
- package/lib/Types/LabelAssociation.js +0 -13
- package/lib/Types/Message.d.ts +0 -459
- package/lib/Types/Message.js +0 -13
- package/lib/Types/Newsletter.d.ts +0 -107
- package/lib/Types/Newsletter.js +0 -38
- package/lib/Types/Product.d.ts +0 -92
- package/lib/Types/Product.js +0 -3
- package/lib/Types/Signal.d.ts +0 -68
- package/lib/Types/Signal.js +0 -3
- package/lib/Types/Socket.d.ts +0 -120
- package/lib/Types/Socket.js +0 -3
- package/lib/Types/State.d.ts +0 -29
- package/lib/Types/State.js +0 -3
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/USync.js +0 -3
- package/lib/Types/index.d.ts +0 -78
- package/lib/Types/index.js +0 -47
- package/lib/Utils/auth-utils.d.ts +0 -21
- package/lib/Utils/auth-utils.js +0 -205
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/business.d.ts +0 -29
- package/lib/Utils/business.js +0 -247
- package/lib/Utils/chat-utils.d.ts +0 -82
- package/lib/Utils/chat-utils.js +0 -774
- package/lib/Utils/crypto.d.ts +0 -56
- package/lib/Utils/crypto.js +0 -179
- package/lib/Utils/decode-wa-message.d.ts +0 -41
- package/lib/Utils/decode-wa-message.js +0 -236
- package/lib/Utils/event-buffer.d.ts +0 -39
- package/lib/Utils/event-buffer.js +0 -548
- package/lib/Utils/generics.d.ts +0 -129
- package/lib/Utils/generics.js +0 -485
- package/lib/Utils/history.d.ts +0 -23
- package/lib/Utils/history.js +0 -100
- package/lib/Utils/index.d.ts +0 -20
- package/lib/Utils/index.js +0 -40
- package/lib/Utils/link-preview.d.ts +0 -23
- package/lib/Utils/link-preview.js +0 -120
- package/lib/Utils/logger.d.ts +0 -13
- package/lib/Utils/logger.js +0 -7
- package/lib/Utils/lt-hash.d.ts +0 -14
- package/lib/Utils/lt-hash.js +0 -58
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/make-mutex.js +0 -49
- package/lib/Utils/messages-media.d.ts +0 -129
- package/lib/Utils/messages-media.js +0 -782
- package/lib/Utils/messages.d.ts +0 -103
- package/lib/Utils/messages.js +0 -1631
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/noise-handler.js +0 -155
- package/lib/Utils/process-message.d.ts +0 -49
- package/lib/Utils/process-message.js +0 -387
- package/lib/Utils/signal.d.ts +0 -42
- package/lib/Utils/signal.js +0 -166
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-multi-file-auth-state.js +0 -131
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/Utils/use-sql-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-sql-file-auth-state.js +0 -143
- package/lib/Utils/validate-connection.d.ts +0 -13
- package/lib/Utils/validate-connection.js +0 -186
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/constants.js +0 -53
- package/lib/WABinary/decode.d.ts +0 -9
- package/lib/WABinary/decode.js +0 -288
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/encode.js +0 -256
- package/lib/WABinary/generic-utils.d.ts +0 -28
- package/lib/WABinary/generic-utils.js +0 -150
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/index.js +0 -25
- package/lib/WABinary/jid-utils.d.ts +0 -53
- package/lib/WABinary/jid-utils.js +0 -92
- package/lib/WABinary/types.d.ts +0 -22
- package/lib/WABinary/types.js +0 -3
- package/lib/WAM/BinaryInfo.d.ts +0 -16
- package/lib/WAM/BinaryInfo.js +0 -17
- package/lib/WAM/constants.d.ts +0 -47
- package/lib/WAM/constants.js +0 -15371
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/encode.js +0 -165
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAM/index.js +0 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -36
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -62
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -35
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -46
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/Protocols/index.js +0 -26
- package/lib/WAUSync/USyncQuery.d.ts +0 -31
- package/lib/WAUSync/USyncQuery.js +0 -92
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/USyncUser.js +0 -30
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/WAUSync/index.js +0 -23
- package/lib/index.d.ts +0 -13
- package/lib/index.js +0 -33
package/lib/Utils/signal.js
DELETED
|
@@ -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,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,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
|