@neelegirl/baileys 1.5.2 → 1.5.3
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/LICENSE +21 -21
- package/README.md +195 -187
- package/WAProto/WAProto.proto +537 -236
- package/WAProto/index.d.ts +5971 -2388
- package/WAProto/index.js +17298 -6513
- package/lib/Defaults/baileys-version.json +3 -3
- package/lib/Defaults/index.d.ts +77 -67
- package/lib/Defaults/index.js +148 -136
- package/lib/Defaults/phonenumber-mcc.json +223 -223
- package/lib/Signal/WASignalGroup/GroupProtocol.js +1908 -1908
- package/lib/Signal/WASignalGroup/ciphertext-message.d.ts +9 -0
- package/lib/Signal/WASignalGroup/ciphertext-message.js +19 -0
- package/lib/Signal/WASignalGroup/ciphertext_message.js +15 -15
- package/lib/Signal/WASignalGroup/group-session-builder.d.ts +17 -0
- package/lib/Signal/WASignalGroup/group-session-builder.js +72 -0
- package/lib/Signal/WASignalGroup/group.proto +41 -41
- package/lib/Signal/WASignalGroup/group_cipher.d.ts +19 -0
- package/lib/Signal/WASignalGroup/group_cipher.js +101 -110
- package/lib/Signal/WASignalGroup/group_session_builder.js +45 -45
- package/lib/Signal/WASignalGroup/index.d.ts +11 -0
- package/lib/Signal/WASignalGroup/index.js +61 -6
- package/lib/Signal/WASignalGroup/keyhelper.d.ts +16 -0
- package/lib/Signal/WASignalGroup/keyhelper.js +58 -13
- package/lib/Signal/WASignalGroup/protobufs.js +2 -2
- package/lib/Signal/WASignalGroup/queue_job.js +68 -68
- package/lib/Signal/WASignalGroup/readme.md +5 -5
- package/lib/Signal/WASignalGroup/sender-chain-key.d.ts +14 -0
- package/lib/Signal/WASignalGroup/sender-chain-key.js +47 -0
- package/lib/Signal/WASignalGroup/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/WASignalGroup/sender-key-distribution-message.js +71 -0
- package/lib/Signal/WASignalGroup/sender-key-message.d.ts +19 -0
- package/lib/Signal/WASignalGroup/sender-key-message.js +73 -0
- package/lib/Signal/WASignalGroup/sender-key-name.d.ts +19 -0
- package/lib/Signal/WASignalGroup/sender-key-name.js +59 -0
- package/lib/Signal/WASignalGroup/sender-key-record.d.ts +32 -0
- package/lib/Signal/WASignalGroup/sender-key-record.js +58 -0
- package/lib/Signal/WASignalGroup/sender-key-state.d.ts +44 -0
- package/lib/Signal/WASignalGroup/sender-key-state.js +147 -0
- package/lib/Signal/WASignalGroup/sender-message-key.d.ts +11 -0
- package/lib/Signal/WASignalGroup/sender-message-key.js +33 -0
- package/lib/Signal/WASignalGroup/sender_chain_key.js +49 -49
- package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +77 -77
- package/lib/Signal/WASignalGroup/sender_key_message.js +91 -91
- package/lib/Signal/WASignalGroup/sender_key_name.js +69 -69
- package/lib/Signal/WASignalGroup/sender_key_record.js +55 -55
- package/lib/Signal/WASignalGroup/sender_key_state.js +128 -128
- package/lib/Signal/WASignalGroup/sender_message_key.js +38 -38
- package/lib/Signal/libsignal.d.ts +5 -1
- package/lib/Signal/libsignal.js +390 -161
- package/lib/Signal/lid-mapping.d.ts +28 -0
- package/lib/Signal/lid-mapping.js +184 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +15 -15
- package/lib/Socket/Client/abstract-socket-client.js +13 -13
- package/lib/Socket/Client/index.d.ts +2 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -12
- package/lib/Socket/Client/mobile-socket-client.js +65 -65
- package/lib/Socket/Client/types.d.ts +1 -1
- package/lib/Socket/Client/websocket.d.ts +1 -1
- package/lib/Socket/business.d.ts +6 -6
- package/lib/Socket/business.js +152 -5
- package/lib/Socket/chats.d.ts +3 -4
- package/lib/Socket/chats.js +31 -26
- package/lib/Socket/communities.d.ts +223 -223
- package/lib/Socket/communities.js +432 -432
- package/lib/Socket/groups.d.ts +2 -4
- package/lib/Socket/groups.js +22 -14
- package/lib/Socket/index.d.ts +69 -69
- package/lib/Socket/index.js +3 -2
- package/lib/Socket/messages-recv.d.ts +3 -6
- package/lib/Socket/messages-recv.js +1449 -1707
- package/lib/Socket/messages-send.d.ts +2 -4
- package/lib/Socket/messages-send.js +617 -126
- package/lib/Socket/mex.d.ts +2 -2
- package/lib/Socket/mex.js +46 -46
- package/lib/Socket/newsletter.d.ts +2 -4
- package/lib/Socket/newsletter.js +294 -285
- package/lib/Socket/socket.js +318 -132
- package/lib/Socket/usync.js +3 -3
- package/lib/Store/index.d.ts +4 -4
- package/lib/Store/index.js +23 -23
- package/lib/Store/make-cache-manager-store.d.ts +13 -13
- package/lib/Store/make-cache-manager-store.js +89 -89
- package/lib/Store/make-in-memory-store.d.ts +122 -122
- package/lib/Store/make-in-memory-store.js +428 -428
- package/lib/Store/make-ordered-dictionary.d.ts +11 -11
- package/lib/Store/make-ordered-dictionary.js +85 -85
- package/lib/Store/object-repository.d.ts +9 -9
- package/lib/Store/object-repository.js +30 -30
- package/lib/Types/Auth.d.ts +5 -4
- package/lib/Types/Bussines.js +3 -0
- package/lib/Types/Bussiness.d.ts +28 -0
- package/lib/Types/Chat.d.ts +13 -8
- package/lib/Types/Contact.d.ts +4 -1
- package/lib/Types/Events.d.ts +13 -16
- package/lib/Types/GroupMetadata.d.ts +1 -1
- package/lib/Types/Message.d.ts +18 -7
- package/lib/Types/Message.js +7 -1
- package/lib/Types/MexUpdates.d.ts +8 -8
- package/lib/Types/MexUpdates.js +17 -17
- package/lib/Types/Newsletter.d.ts +1 -1
- package/lib/Types/Product.d.ts +1 -1
- package/lib/Types/Signal.d.ts +31 -1
- package/lib/Types/Socket.d.ts +34 -13
- package/lib/Types/State.d.ts +1 -1
- package/lib/Types/USync.d.ts +2 -2
- package/lib/Types/index.d.ts +16 -15
- package/lib/Types/index.js +4 -2
- package/lib/Utils/auth-utils.d.ts +20 -20
- package/lib/Utils/auth-utils.js +527 -204
- package/lib/Utils/baileys-event-stream.d.ts +17 -17
- package/lib/Utils/baileys-event-stream.js +69 -69
- package/lib/Utils/business.d.ts +28 -28
- package/lib/Utils/business.js +254 -254
- package/lib/Utils/chat-utils.d.ts +81 -81
- package/lib/Utils/chat-utils.js +808 -780
- package/lib/Utils/crypto.d.ts +55 -55
- package/lib/Utils/crypto.js +188 -178
- package/lib/Utils/decode-wa-message.d.ts +52 -40
- package/lib/Utils/decode-wa-message.js +322 -252
- package/lib/Utils/event-buffer.d.ts +38 -38
- package/lib/Utils/event-buffer.js +594 -564
- package/lib/Utils/generics.d.ts +131 -129
- package/lib/Utils/generics.js +629 -623
- package/lib/Utils/history.d.ts +22 -22
- package/lib/Utils/history.js +103 -109
- package/lib/Utils/index.d.ts +20 -19
- package/lib/Utils/index.js +39 -38
- package/lib/Utils/link-preview.d.ts +22 -22
- package/lib/Utils/link-preview.js +119 -119
- package/lib/Utils/logger.d.ts +13 -13
- package/lib/Utils/logger.js +7 -7
- package/lib/Utils/lt-hash.d.ts +13 -13
- package/lib/Utils/lt-hash.js +57 -57
- package/lib/Utils/make-mutex.d.ts +8 -8
- package/lib/Utils/make-mutex.js +48 -48
- package/lib/Utils/message-retry-manager.d.ts +88 -0
- package/lib/Utils/message-retry-manager.js +160 -0
- package/lib/Utils/messages-media.d.ts +134 -128
- package/lib/Utils/messages-media.js +868 -805
- package/lib/Utils/messages.d.ts +104 -102
- package/lib/Utils/messages.js +1744 -1578
- package/lib/Utils/noise-handler.d.ts +20 -19
- package/lib/Utils/noise-handler.js +164 -154
- package/lib/Utils/process-message.d.ts +48 -48
- package/lib/Utils/process-message.js +427 -428
- package/lib/Utils/signal.d.ts +41 -41
- package/lib/Utils/signal.js +165 -165
- package/lib/Utils/use-mongo-file-auth-state.d.ts +5 -5
- package/lib/Utils/use-mongo-file-auth-state.js +83 -83
- package/lib/Utils/use-multi-file-auth-state.d.ts +17 -17
- package/lib/Utils/use-multi-file-auth-state.js +237 -237
- package/lib/Utils/use-single-file-auth-state.d.ts +12 -12
- package/lib/Utils/use-single-file-auth-state.js +79 -79
- package/lib/Utils/validate-connection.d.ts +12 -12
- package/lib/Utils/validate-connection.js +219 -186
- package/lib/WABinary/constants.d.ts +29 -29
- package/lib/WABinary/constants.js +1315 -1315
- package/lib/WABinary/decode.d.ts +8 -8
- package/lib/WABinary/decode.js +287 -287
- package/lib/WABinary/encode.d.ts +2 -2
- package/lib/WABinary/encode.js +264 -264
- package/lib/WABinary/generic-utils.d.ts +27 -27
- package/lib/WABinary/generic-utils.js +141 -141
- package/lib/WABinary/index.d.ts +5 -5
- package/lib/WABinary/index.js +24 -24
- package/lib/WABinary/jid-utils.d.ts +58 -53
- package/lib/WABinary/jid-utils.js +103 -91
- package/lib/WABinary/types.d.ts +21 -21
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +15 -15
- package/lib/WAM/BinaryInfo.js +16 -16
- package/lib/WAM/constants.d.ts +46 -46
- package/lib/WAM/constants.js +15370 -15370
- package/lib/WAM/encode.d.ts +2 -2
- package/lib/WAM/encode.js +163 -164
- package/lib/WAM/index.d.ts +3 -3
- package/lib/WAM/index.js +22 -22
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +27 -27
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +68 -68
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -8
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +37 -29
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
- package/lib/WAUSync/Protocols/index.d.ts +6 -6
- package/lib/WAUSync/USyncQuery.d.ts +3 -3
- package/lib/WAUSync/index.d.ts +3 -3
- package/lib/index.d.ts +13 -13
- package/lib/index.js +33 -33
- package/package.json +96 -94
- package/lib/Socket/registration.d.ts +0 -266
- package/lib/Socket/registration.js +0 -166
package/lib/Utils/signal.d.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { SignalRepository } from '
|
|
2
|
-
import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '
|
|
3
|
-
import { BinaryNode, JidWithDevice } from '
|
|
4
|
-
import { USyncQueryResultList } from '
|
|
5
|
-
|
|
6
|
-
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity
|
|
7
|
-
|
|
8
|
-
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
9
|
-
[id: string]: KeyPair
|
|
10
|
-
}>
|
|
11
|
-
|
|
12
|
-
export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
|
|
13
|
-
newPreKeys: {
|
|
14
|
-
[id: number]: KeyPair
|
|
15
|
-
}
|
|
16
|
-
lastPreKeyId: number
|
|
17
|
-
preKeysRange: readonly [number, number]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode
|
|
21
|
-
|
|
22
|
-
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode
|
|
23
|
-
|
|
24
|
-
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>
|
|
25
|
-
|
|
26
|
-
export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => JidWithDevice[]
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* get the next N keys for upload or processing
|
|
30
|
-
* @param count number of pre-keys to get or generate
|
|
31
|
-
*/
|
|
32
|
-
export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
|
|
33
|
-
update: Partial<AuthenticationCreds>
|
|
34
|
-
preKeys: {
|
|
35
|
-
[id: string]: KeyPair
|
|
36
|
-
}
|
|
37
|
-
}>
|
|
38
|
-
|
|
39
|
-
export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
|
|
40
|
-
update: Partial<AuthenticationCreds>
|
|
41
|
-
node: BinaryNode
|
|
1
|
+
import { SignalRepository } from '@neelegirl/baileys/lib/Types'
|
|
2
|
+
import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '@neelegirl/baileys/lib/Types/Auth'
|
|
3
|
+
import { BinaryNode, JidWithDevice } from '@neelegirl/baileys/lib/WABinary'
|
|
4
|
+
import { USyncQueryResultList } from '@neelegirl/baileys/lib/WAUSync'
|
|
5
|
+
|
|
6
|
+
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity
|
|
7
|
+
|
|
8
|
+
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
9
|
+
[id: string]: KeyPair
|
|
10
|
+
}>
|
|
11
|
+
|
|
12
|
+
export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
|
|
13
|
+
newPreKeys: {
|
|
14
|
+
[id: number]: KeyPair
|
|
15
|
+
}
|
|
16
|
+
lastPreKeyId: number
|
|
17
|
+
preKeysRange: readonly [number, number]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode
|
|
21
|
+
|
|
22
|
+
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode
|
|
23
|
+
|
|
24
|
+
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>
|
|
25
|
+
|
|
26
|
+
export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => JidWithDevice[]
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* get the next N keys for upload or processing
|
|
30
|
+
* @param count number of pre-keys to get or generate
|
|
31
|
+
*/
|
|
32
|
+
export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
|
|
33
|
+
update: Partial<AuthenticationCreds>
|
|
34
|
+
preKeys: {
|
|
35
|
+
[id: string]: KeyPair
|
|
36
|
+
}
|
|
37
|
+
}>
|
|
38
|
+
|
|
39
|
+
export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
|
|
40
|
+
update: Partial<AuthenticationCreds>
|
|
41
|
+
node: BinaryNode
|
|
42
42
|
}>
|
package/lib/Utils/signal.js
CHANGED
|
@@ -1,166 +1,166 @@
|
|
|
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
|
|
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
166
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AuthenticationState } from '
|
|
2
|
-
|
|
3
|
-
export declare const useMongoFileAuthState: (collection: string) => Promise<{
|
|
4
|
-
state: AuthenticationState
|
|
5
|
-
saveCreds: () => Promise<void>
|
|
1
|
+
import { AuthenticationState } from '@neelegirl/baileys/lib/Types'
|
|
2
|
+
|
|
3
|
+
export declare const useMongoFileAuthState: (collection: string) => Promise<{
|
|
4
|
+
state: AuthenticationState
|
|
5
|
+
saveCreds: () => Promise<void>
|
|
6
6
|
}>
|
|
@@ -1,84 +1,84 @@
|
|
|
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, generics_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
|
|
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, generics_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
84
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { AuthenticationState } from '
|
|
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
|
-
}>
|
|
14
|
-
|
|
15
|
-
export declare const useMultiFileAuthStateV2: (folder: string) => Promise<{
|
|
16
|
-
state: AuthenticationState
|
|
17
|
-
saveCreds: () => Promise<void>
|
|
1
|
+
import { AuthenticationState } from '@neelegirl/baileys/lib/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
|
+
}>
|
|
14
|
+
|
|
15
|
+
export declare const useMultiFileAuthStateV2: (folder: string) => Promise<{
|
|
16
|
+
state: AuthenticationState
|
|
17
|
+
saveCreds: () => Promise<void>
|
|
18
18
|
}>
|