gifted-baileys 1.5.4 → 1.5.6
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 +1 -1
- package/WAProto/WAProto.proto +88 -969
- package/WAProto/index.d.ts +1256 -13195
- package/WAProto/index.js +74730 -125106
- package/package.json +9 -27
- package/src/Defaults/baileys-version.json +3 -0
- package/{lib → src}/Defaults/index.js +14 -7
- package/src/Defaults/index.ts +131 -0
- package/src/README.md +1 -0
- package/src/Signal/libsignal.js +180 -0
- package/src/Signal/libsignal.ts +141 -0
- package/src/Socket/Client/abstract-socket-client.ts +19 -0
- package/{lib → src}/Socket/Client/index.js +3 -2
- package/src/Socket/Client/index.ts +3 -0
- package/src/Socket/Client/mobile-socket-client.js +78 -0
- package/src/Socket/Client/mobile-socket-client.ts +66 -0
- package/src/Socket/Client/web-socket-client.js +75 -0
- package/src/Socket/Client/web-socket-client.ts +57 -0
- package/{lib → src}/Socket/business.js +33 -28
- package/src/Socket/business.ts +281 -0
- package/{lib → src}/Socket/chats.js +176 -174
- package/src/Socket/chats.ts +1030 -0
- package/{lib → src}/Socket/groups.js +68 -80
- package/src/Socket/groups.ts +356 -0
- package/{lib → src}/Socket/index.js +1 -4
- package/src/Socket/index.ts +13 -0
- package/{lib → src}/Socket/messages-recv.js +211 -378
- package/src/Socket/messages-recv.ts +985 -0
- package/{lib → src}/Socket/messages-send.js +177 -452
- package/src/Socket/messages-send.ts +871 -0
- package/{lib → src}/Socket/newsletter.js +98 -107
- package/src/Socket/newsletter.ts +282 -0
- package/{lib → src}/Socket/registration.js +48 -56
- package/src/Socket/registration.ts +250 -0
- package/{lib → src}/Socket/socket.js +77 -77
- package/src/Socket/socket.ts +777 -0
- package/src/Store/index.ts +3 -0
- package/{lib → src}/Store/make-cache-manager-store.js +34 -25
- package/src/Store/make-cache-manager-store.ts +100 -0
- package/{lib → src}/Store/make-in-memory-store.js +32 -36
- package/src/Store/make-in-memory-store.ts +475 -0
- package/src/Store/make-ordered-dictionary.ts +86 -0
- package/{lib → src}/Store/object-repository.js +1 -1
- package/src/Store/object-repository.ts +32 -0
- package/src/Tests/test.app-state-sync.js +204 -0
- package/src/Tests/test.app-state-sync.ts +207 -0
- package/src/Tests/test.event-buffer.js +270 -0
- package/src/Tests/test.event-buffer.ts +319 -0
- package/src/Tests/test.key-store.js +76 -0
- package/src/Tests/test.key-store.ts +92 -0
- package/src/Tests/test.libsignal.js +141 -0
- package/src/Tests/test.libsignal.ts +186 -0
- package/src/Tests/test.media-download.js +93 -0
- package/src/Tests/test.media-download.ts +76 -0
- package/src/Tests/test.messages.js +33 -0
- package/src/Tests/test.messages.ts +37 -0
- package/src/Tests/utils.js +34 -0
- package/src/Tests/utils.ts +36 -0
- package/src/Types/Auth.ts +113 -0
- package/src/Types/Call.ts +15 -0
- package/src/Types/Chat.ts +106 -0
- package/{lib/Types/Contact.d.ts → src/Types/Contact.ts} +9 -8
- package/src/Types/Events.ts +93 -0
- package/src/Types/GroupMetadata.ts +53 -0
- package/src/Types/Label.ts +36 -0
- package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
- package/src/Types/Message.ts +288 -0
- package/src/Types/Newsletter.ts +98 -0
- package/src/Types/Product.ts +85 -0
- package/src/Types/Signal.ts +68 -0
- package/{lib/Types/Socket.d.ts → src/Types/Socket.ts} +68 -61
- package/src/Types/State.ts +29 -0
- package/src/Types/index.ts +59 -0
- package/{lib → src}/Utils/auth-utils.js +90 -73
- package/src/Utils/auth-utils.ts +222 -0
- package/src/Utils/baileys-event-stream.js +92 -0
- package/src/Utils/baileys-event-stream.ts +66 -0
- package/{lib → src}/Utils/business.js +43 -15
- package/src/Utils/business.ts +275 -0
- package/{lib → src}/Utils/chat-utils.js +94 -87
- package/src/Utils/chat-utils.ts +860 -0
- package/{lib → src}/Utils/crypto.js +2 -4
- package/src/Utils/crypto.ts +131 -0
- package/src/Utils/decode-wa-message.js +211 -0
- package/src/Utils/decode-wa-message.ts +228 -0
- package/{lib → src}/Utils/event-buffer.js +13 -4
- package/src/Utils/event-buffer.ts +613 -0
- package/{lib → src}/Utils/generics.js +86 -67
- package/src/Utils/generics.ts +434 -0
- package/{lib → src}/Utils/history.js +39 -13
- package/src/Utils/history.ts +112 -0
- package/src/Utils/index.ts +17 -0
- package/{lib → src}/Utils/link-preview.js +54 -17
- package/src/Utils/link-preview.ts +122 -0
- package/src/Utils/logger.ts +3 -0
- package/src/Utils/lt-hash.ts +61 -0
- package/{lib → src}/Utils/make-mutex.js +13 -4
- package/src/Utils/make-mutex.ts +44 -0
- package/{lib → src}/Utils/messages-media.js +255 -193
- package/src/Utils/messages-media.ts +847 -0
- package/{lib → src}/Utils/messages.js +118 -588
- package/src/Utils/messages.ts +956 -0
- package/src/Utils/noise-handler.ts +197 -0
- package/{lib → src}/Utils/process-message.js +30 -27
- package/src/Utils/process-message.ts +414 -0
- package/{lib → src}/Utils/signal.js +42 -25
- package/src/Utils/signal.ts +177 -0
- package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -27
- package/src/Utils/use-multi-file-auth-state.ts +90 -0
- package/{lib → src}/Utils/validate-connection.js +9 -40
- package/src/Utils/validate-connection.ts +238 -0
- package/src/WABinary/constants.ts +42 -0
- package/src/WABinary/decode.ts +265 -0
- package/{lib → src}/WABinary/encode.js +10 -16
- package/src/WABinary/encode.ts +236 -0
- package/src/WABinary/generic-utils.ts +121 -0
- package/src/WABinary/index.ts +5 -0
- package/src/WABinary/jid-utils.ts +68 -0
- package/src/WABinary/types.ts +17 -0
- package/src/WAM/BinaryInfo.ts +12 -0
- package/src/WAM/constants.ts +15382 -0
- package/src/WAM/encode.ts +174 -0
- package/src/WAM/index.ts +3 -0
- package/{lib → src}/index.js +0 -1
- package/src/index.ts +13 -0
- package/README.md +0 -1645
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/index.d.ts +0 -284
- package/lib/Signal/libsignal.d.ts +0 -3
- package/lib/Signal/libsignal.js +0 -161
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
- package/lib/Socket/Client/index.d.ts +0 -2
- 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 -17
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.d.ts +0 -12
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/business.d.ts +0 -170
- package/lib/Socket/chats.d.ts +0 -81
- package/lib/Socket/groups.d.ts +0 -115
- package/lib/Socket/index.d.ts +0 -172
- package/lib/Socket/messages-recv.d.ts +0 -158
- package/lib/Socket/messages-send.d.ts +0 -155
- package/lib/Socket/newsletter.d.ts +0 -132
- package/lib/Socket/registration.d.ts +0 -264
- package/lib/Socket/socket.d.ts +0 -44
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -70
- package/lib/Store/index.d.ts +0 -3
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -13
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -109
- package/lib/Types/Call.d.ts +0 -13
- package/lib/Types/Chat.d.ts +0 -107
- package/lib/Types/Events.d.ts +0 -172
- package/lib/Types/GroupMetadata.d.ts +0 -56
- package/lib/Types/Label.d.ts +0 -46
- package/lib/Types/Message.d.ts +0 -433
- package/lib/Types/Newsletter.d.ts +0 -92
- package/lib/Types/Product.d.ts +0 -78
- package/lib/Types/Signal.d.ts +0 -57
- package/lib/Types/State.d.ts +0 -27
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/USync.js +0 -2
- package/lib/Types/index.d.ts +0 -66
- package/lib/Utils/auth-utils.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.d.ts +0 -16
- package/lib/Utils/baileys-event-stream.js +0 -63
- package/lib/Utils/business.d.ts +0 -22
- package/lib/Utils/chat-utils.d.ts +0 -70
- package/lib/Utils/crypto.d.ts +0 -40
- package/lib/Utils/decode-wa-message.d.ts +0 -36
- package/lib/Utils/decode-wa-message.js +0 -226
- package/lib/Utils/event-buffer.d.ts +0 -35
- package/lib/Utils/generics.d.ts +0 -88
- package/lib/Utils/history.d.ts +0 -19
- package/lib/Utils/index.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -21
- package/lib/Utils/logger.d.ts +0 -2
- package/lib/Utils/lt-hash.d.ts +0 -12
- package/lib/Utils/make-mutex.d.ts +0 -7
- package/lib/Utils/messages-media.d.ts +0 -113
- package/lib/Utils/messages.d.ts +0 -77
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -41
- package/lib/Utils/signal.d.ts +0 -33
- package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
- package/lib/Utils/validate-connection.d.ts +0 -11
- package/lib/WABinary/constants.d.ts +0 -27
- package/lib/WABinary/decode.d.ts +0 -6
- package/lib/WABinary/encode.d.ts +0 -2
- package/lib/WABinary/generic-utils.d.ts +0 -14
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -31
- package/lib/WABinary/types.d.ts +0 -18
- package/lib/WAM/BinaryInfo.d.ts +0 -8
- package/lib/WAM/constants.d.ts +0 -38
- package/lib/WAM/encode.d.ts +0 -2
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/index.js +0 -20
- package/lib/WAUSync/USyncQuery.d.ts +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -79
- package/lib/WAUSync/USyncUser.d.ts +0 -10
- package/lib/WAUSync/USyncUser.js +0 -22
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/WAUSync/index.js +0 -19
- /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
- /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
- /package/{lib → src}/Store/index.js +0 -0
- /package/{lib → src}/Store/make-ordered-dictionary.js +0 -0
- /package/{lib → src}/Types/Auth.js +0 -0
- /package/{lib → src}/Types/Call.js +0 -0
- /package/{lib → src}/Types/Chat.js +0 -0
- /package/{lib → src}/Types/Contact.js +0 -0
- /package/{lib → src}/Types/Events.js +0 -0
- /package/{lib → src}/Types/GroupMetadata.js +0 -0
- /package/{lib → src}/Types/Label.js +0 -0
- /package/{lib → src}/Types/LabelAssociation.js +0 -0
- /package/{lib → src}/Types/Message.js +0 -0
- /package/{lib → src}/Types/Newsletter.js +0 -0
- /package/{lib → src}/Types/Product.js +0 -0
- /package/{lib → src}/Types/Signal.js +0 -0
- /package/{lib → src}/Types/Socket.js +0 -0
- /package/{lib → src}/Types/State.js +0 -0
- /package/{lib → src}/Types/index.js +0 -0
- /package/{lib → src}/Utils/index.js +0 -0
- /package/{lib → src}/Utils/logger.js +0 -0
- /package/{lib → src}/Utils/lt-hash.js +0 -0
- /package/{lib → src}/Utils/noise-handler.js +0 -0
- /package/{lib → src}/WABinary/constants.js +0 -0
- /package/{lib → src}/WABinary/decode.js +0 -0
- /package/{lib → src}/WABinary/generic-utils.js +0 -0
- /package/{lib → src}/WABinary/index.js +0 -0
- /package/{lib → src}/WABinary/jid-utils.js +0 -0
- /package/{lib → src}/WABinary/types.js +0 -0
- /package/{lib → src}/WAM/BinaryInfo.js +0 -0
- /package/{lib → src}/WAM/constants.js +0 -0
- /package/{lib → src}/WAM/encode.js +0 -0
- /package/{lib → src}/WAM/index.js +0 -0
- /package/{lib → src}/gifted +0 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { KEY_BUNDLE_TYPE } from '../Defaults'
|
|
2
|
+
import { SignalRepository } from '../Types'
|
|
3
|
+
import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth'
|
|
4
|
+
import { assertNodeErrorFree, BinaryNode, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, jidDecode, JidWithDevice, S_WHATSAPP_NET } from '../WABinary'
|
|
5
|
+
import { Curve, generateSignalPubKey } from './crypto'
|
|
6
|
+
import { encodeBigEndian } from './generics'
|
|
7
|
+
|
|
8
|
+
export const createSignalIdentity = (
|
|
9
|
+
wid: string,
|
|
10
|
+
accountSignatureKey: Uint8Array
|
|
11
|
+
): SignalIdentity => {
|
|
12
|
+
return {
|
|
13
|
+
identifier: { name: wid, deviceId: 0 },
|
|
14
|
+
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const getPreKeys = async({ get }: SignalKeyStore, min: number, limit: number) => {
|
|
19
|
+
const idList: string[] = []
|
|
20
|
+
for(let id = min; id < limit;id++) {
|
|
21
|
+
idList.push(id.toString())
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return get('pre-key', idList)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const generateOrGetPreKeys = (creds: AuthenticationCreds, range: number) => {
|
|
28
|
+
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId
|
|
29
|
+
const remaining = range - avaliable
|
|
30
|
+
const lastPreKeyId = creds.nextPreKeyId + remaining - 1
|
|
31
|
+
const newPreKeys: { [id: number]: KeyPair } = { }
|
|
32
|
+
if(remaining > 0) {
|
|
33
|
+
for(let i = creds.nextPreKeyId;i <= lastPreKeyId;i++) {
|
|
34
|
+
newPreKeys[i] = Curve.generateKeyPair()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
newPreKeys,
|
|
40
|
+
lastPreKeyId,
|
|
41
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range] as const,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const xmppSignedPreKey = (key: SignedKeyPair): BinaryNode => (
|
|
46
|
+
{
|
|
47
|
+
tag: 'skey',
|
|
48
|
+
attrs: { },
|
|
49
|
+
content: [
|
|
50
|
+
{ tag: 'id', attrs: { }, content: encodeBigEndian(key.keyId, 3) },
|
|
51
|
+
{ tag: 'value', attrs: { }, content: key.keyPair.public },
|
|
52
|
+
{ tag: 'signature', attrs: { }, content: key.signature }
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
export const xmppPreKey = (pair: KeyPair, id: number): BinaryNode => (
|
|
58
|
+
{
|
|
59
|
+
tag: 'key',
|
|
60
|
+
attrs: { },
|
|
61
|
+
content: [
|
|
62
|
+
{ tag: 'id', attrs: { }, content: encodeBigEndian(id, 3) },
|
|
63
|
+
{ tag: 'value', attrs: { }, content: pair.public }
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
export const parseAndInjectE2ESessions = async(
|
|
69
|
+
node: BinaryNode,
|
|
70
|
+
repository: SignalRepository
|
|
71
|
+
) => {
|
|
72
|
+
const extractKey = (key: BinaryNode) => (
|
|
73
|
+
key ? ({
|
|
74
|
+
keyId: getBinaryNodeChildUInt(key, 'id', 3)!,
|
|
75
|
+
publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')!)!,
|
|
76
|
+
signature: getBinaryNodeChildBuffer(key, 'signature')!,
|
|
77
|
+
}) : undefined
|
|
78
|
+
)
|
|
79
|
+
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user')
|
|
80
|
+
for(const node of nodes) {
|
|
81
|
+
assertNodeErrorFree(node)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
await Promise.all(
|
|
85
|
+
nodes.map(
|
|
86
|
+
async node => {
|
|
87
|
+
const signedKey = getBinaryNodeChild(node, 'skey')!
|
|
88
|
+
const key = getBinaryNodeChild(node, 'key')!
|
|
89
|
+
const identity = getBinaryNodeChildBuffer(node, 'identity')!
|
|
90
|
+
const jid = node.attrs.jid
|
|
91
|
+
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4)
|
|
92
|
+
|
|
93
|
+
await repository.injectE2ESession({
|
|
94
|
+
jid,
|
|
95
|
+
session: {
|
|
96
|
+
registrationId: registrationId!,
|
|
97
|
+
identityKey: generateSignalPubKey(identity),
|
|
98
|
+
signedPreKey: extractKey(signedKey)!,
|
|
99
|
+
preKey: extractKey(key)!
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const extractDeviceJids = (result: BinaryNode, myJid: string, excludeZeroDevices: boolean) => {
|
|
108
|
+
const { user: myUser, device: myDevice } = jidDecode(myJid)!
|
|
109
|
+
const extracted: JidWithDevice[] = []
|
|
110
|
+
for(const node of result.content as BinaryNode[]) {
|
|
111
|
+
const list = getBinaryNodeChild(node, 'list')?.content
|
|
112
|
+
if(list && Array.isArray(list)) {
|
|
113
|
+
for(const item of list) {
|
|
114
|
+
const { user } = jidDecode(item.attrs.jid)!
|
|
115
|
+
const devicesNode = getBinaryNodeChild(item, 'devices')
|
|
116
|
+
const deviceListNode = getBinaryNodeChild(devicesNode, 'device-list')
|
|
117
|
+
if(Array.isArray(deviceListNode?.content)) {
|
|
118
|
+
for(const { tag, attrs } of deviceListNode!.content) {
|
|
119
|
+
const device = +attrs.id
|
|
120
|
+
if(
|
|
121
|
+
tag === 'device' && // ensure the "device" tag
|
|
122
|
+
(!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
123
|
+
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
124
|
+
(device === 0 || !!attrs['key-index']) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
125
|
+
) {
|
|
126
|
+
extracted.push({ user, device })
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return extracted
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* get the next N keys for upload or processing
|
|
139
|
+
* @param count number of pre-keys to get or generate
|
|
140
|
+
*/
|
|
141
|
+
export const getNextPreKeys = async({ creds, keys }: AuthenticationState, count: number) => {
|
|
142
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count)
|
|
143
|
+
|
|
144
|
+
const update: Partial<AuthenticationCreds> = {
|
|
145
|
+
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
146
|
+
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
await keys.set({ 'pre-key': newPreKeys })
|
|
150
|
+
|
|
151
|
+
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1])
|
|
152
|
+
|
|
153
|
+
return { update, preKeys }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const getNextPreKeysNode = async(state: AuthenticationState, count: number) => {
|
|
157
|
+
const { creds } = state
|
|
158
|
+
const { update, preKeys } = await getNextPreKeys(state, count)
|
|
159
|
+
|
|
160
|
+
const node: BinaryNode = {
|
|
161
|
+
tag: 'iq',
|
|
162
|
+
attrs: {
|
|
163
|
+
xmlns: 'encrypt',
|
|
164
|
+
type: 'set',
|
|
165
|
+
to: S_WHATSAPP_NET,
|
|
166
|
+
},
|
|
167
|
+
content: [
|
|
168
|
+
{ tag: 'registration', attrs: { }, content: encodeBigEndian(creds.registrationId) },
|
|
169
|
+
{ tag: 'type', attrs: { }, content: KEY_BUNDLE_TYPE },
|
|
170
|
+
{ tag: 'identity', attrs: { }, content: creds.signedIdentityKey.public },
|
|
171
|
+
{ tag: 'list', attrs: { }, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
|
|
172
|
+
xmppSignedPreKey(creds.signedPreKey)
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return { update, node }
|
|
177
|
+
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
4
10
|
};
|
|
5
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
12
|
exports.useMultiFileAuthState = void 0;
|
|
@@ -9,8 +15,6 @@ const path_1 = require("path");
|
|
|
9
15
|
const WAProto_1 = require("../../WAProto");
|
|
10
16
|
const auth_utils_1 = require("./auth-utils");
|
|
11
17
|
const generics_1 = require("./generics");
|
|
12
|
-
const async_lock_1 = __importDefault(require("async-lock"));
|
|
13
|
-
const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
14
18
|
/**
|
|
15
19
|
* stores the full authentication state in a single folder.
|
|
16
20
|
* Far more efficient than singlefileauthstate
|
|
@@ -18,56 +22,53 @@ const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
|
18
22
|
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
19
23
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
20
24
|
* */
|
|
21
|
-
const useMultiFileAuthState =
|
|
25
|
+
const useMultiFileAuthState = (folder) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
26
|
const writeData = (data, file) => {
|
|
23
|
-
|
|
24
|
-
return fileLock.acquire(filePath, () => (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer)));
|
|
27
|
+
return (0, promises_1.writeFile)((0, path_1.join)(folder, fixFileName(file)), JSON.stringify(data, generics_1.BufferJSON.replacer));
|
|
25
28
|
};
|
|
26
|
-
const readData =
|
|
29
|
+
const readData = (file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
30
|
try {
|
|
28
|
-
const
|
|
29
|
-
const data = await fileLock.acquire(filePath, () => (0, promises_1.readFile)(filePath, { encoding: 'utf-8' }));
|
|
31
|
+
const data = yield (0, promises_1.readFile)((0, path_1.join)(folder, fixFileName(file)), { encoding: 'utf-8' });
|
|
30
32
|
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
31
33
|
}
|
|
32
34
|
catch (error) {
|
|
33
35
|
return null;
|
|
34
36
|
}
|
|
35
|
-
};
|
|
36
|
-
const removeData =
|
|
37
|
+
});
|
|
38
|
+
const removeData = (file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
39
|
try {
|
|
38
|
-
|
|
39
|
-
await fileLock.acquire(filePath, () => (0, promises_1.unlink)(filePath));
|
|
40
|
+
yield (0, promises_1.unlink)((0, path_1.join)(folder, fixFileName(file)));
|
|
40
41
|
}
|
|
41
42
|
catch (_a) {
|
|
42
43
|
}
|
|
43
|
-
};
|
|
44
|
-
const folderInfo =
|
|
44
|
+
});
|
|
45
|
+
const folderInfo = yield (0, promises_1.stat)(folder).catch(() => { });
|
|
45
46
|
if (folderInfo) {
|
|
46
47
|
if (!folderInfo.isDirectory()) {
|
|
47
48
|
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
else {
|
|
51
|
-
|
|
52
|
+
yield (0, promises_1.mkdir)(folder, { recursive: true });
|
|
52
53
|
}
|
|
53
54
|
const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
|
|
54
|
-
const creds =
|
|
55
|
+
const creds = (yield readData('creds.json')) || (0, auth_utils_1.initAuthCreds)();
|
|
55
56
|
return {
|
|
56
57
|
state: {
|
|
57
58
|
creds,
|
|
58
59
|
keys: {
|
|
59
|
-
get:
|
|
60
|
+
get: (type, ids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
61
|
const data = {};
|
|
61
|
-
|
|
62
|
-
let value =
|
|
62
|
+
yield Promise.all(ids.map((id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
let value = yield readData(`${type}-${id}.json`);
|
|
63
64
|
if (type === 'app-state-sync-key' && value) {
|
|
64
65
|
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
65
66
|
}
|
|
66
67
|
data[id] = value;
|
|
67
|
-
}));
|
|
68
|
+
})));
|
|
68
69
|
return data;
|
|
69
|
-
},
|
|
70
|
-
set:
|
|
70
|
+
}),
|
|
71
|
+
set: (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
72
|
const tasks = [];
|
|
72
73
|
for (const category in data) {
|
|
73
74
|
for (const id in data[category]) {
|
|
@@ -76,13 +77,13 @@ const useMultiFileAuthState = async (folder) => {
|
|
|
76
77
|
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
-
}
|
|
80
|
+
yield Promise.all(tasks);
|
|
81
|
+
})
|
|
81
82
|
}
|
|
82
83
|
},
|
|
83
84
|
saveCreds: () => {
|
|
84
85
|
return writeData(creds, 'creds.json');
|
|
85
86
|
}
|
|
86
87
|
};
|
|
87
|
-
};
|
|
88
|
+
});
|
|
88
89
|
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { mkdir, readFile, stat, unlink, writeFile } from 'fs/promises'
|
|
2
|
+
import { join } from 'path'
|
|
3
|
+
import { proto } from '../../WAProto'
|
|
4
|
+
import { AuthenticationCreds, AuthenticationState, SignalDataTypeMap } from '../Types'
|
|
5
|
+
import { initAuthCreds } from './auth-utils'
|
|
6
|
+
import { BufferJSON } from './generics'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* stores the full authentication state in a single folder.
|
|
10
|
+
* Far more efficient than singlefileauthstate
|
|
11
|
+
*
|
|
12
|
+
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
13
|
+
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
14
|
+
* */
|
|
15
|
+
export const useMultiFileAuthState = async(folder: string): Promise<{ state: AuthenticationState, saveCreds: () => Promise<void> }> => {
|
|
16
|
+
|
|
17
|
+
const writeData = (data: any, file: string) => {
|
|
18
|
+
return writeFile(join(folder, fixFileName(file)!), JSON.stringify(data, BufferJSON.replacer))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const readData = async(file: string) => {
|
|
22
|
+
try {
|
|
23
|
+
const data = await readFile(join(folder, fixFileName(file)!), { encoding: 'utf-8' })
|
|
24
|
+
return JSON.parse(data, BufferJSON.reviver)
|
|
25
|
+
} catch(error) {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const removeData = async(file: string) => {
|
|
31
|
+
try {
|
|
32
|
+
await unlink(join(folder, fixFileName(file)!))
|
|
33
|
+
} catch{
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const folderInfo = await stat(folder).catch(() => { })
|
|
39
|
+
if(folderInfo) {
|
|
40
|
+
if(!folderInfo.isDirectory()) {
|
|
41
|
+
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`)
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
await mkdir(folder, { recursive: true })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const fixFileName = (file?: string) => file?.replace(/\//g, '__')?.replace(/:/g, '-')
|
|
48
|
+
|
|
49
|
+
const creds: AuthenticationCreds = await readData('creds.json') || initAuthCreds()
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
state: {
|
|
53
|
+
creds,
|
|
54
|
+
keys: {
|
|
55
|
+
get: async(type, ids) => {
|
|
56
|
+
const data: { [_: string]: SignalDataTypeMap[typeof type] } = { }
|
|
57
|
+
await Promise.all(
|
|
58
|
+
ids.map(
|
|
59
|
+
async id => {
|
|
60
|
+
let value = await readData(`${type}-${id}.json`)
|
|
61
|
+
if(type === 'app-state-sync-key' && value) {
|
|
62
|
+
value = proto.Message.AppStateSyncKeyData.fromObject(value)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
data[id] = value
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
return data
|
|
71
|
+
},
|
|
72
|
+
set: async(data) => {
|
|
73
|
+
const tasks: Promise<void>[] = []
|
|
74
|
+
for(const category in data) {
|
|
75
|
+
for(const id in data[category]) {
|
|
76
|
+
const value = data[category][id]
|
|
77
|
+
const file = `${category}-${id}.json`
|
|
78
|
+
tasks.push(value ? writeData(value, file) : removeData(file))
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
await Promise.all(tasks)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
saveCreds: () => {
|
|
87
|
+
return writeData(creds, 'creds.json')
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -17,24 +17,12 @@ const getUserAgent = (config) => {
|
|
|
17
17
|
const manufacturer = config.mobile ? 'Apple' : '';
|
|
18
18
|
const platform = config.mobile ? WAProto_1.proto.ClientPayload.UserAgent.Platform.IOS : WAProto_1.proto.ClientPayload.UserAgent.Platform.WEB;
|
|
19
19
|
const phoneId = config.mobile ? { phoneId: config.auth.creds.phoneId } : {};
|
|
20
|
-
return {
|
|
21
|
-
appVersion: {
|
|
20
|
+
return Object.assign({ appVersion: {
|
|
22
21
|
primary: version[0],
|
|
23
22
|
secondary: version[1],
|
|
24
23
|
tertiary: version[2],
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
28
|
-
mcc: ((_a = config.auth.creds.registration) === null || _a === void 0 ? void 0 : _a.phoneNumberMobileCountryCode) || '000',
|
|
29
|
-
mnc: ((_b = config.auth.creds.registration) === null || _b === void 0 ? void 0 : _b.phoneNumberMobileNetworkCode) || '000',
|
|
30
|
-
osVersion: osVersion,
|
|
31
|
-
manufacturer,
|
|
32
|
-
device,
|
|
33
|
-
osBuildNumber: osVersion,
|
|
34
|
-
localeLanguageIso6391: 'en',
|
|
35
|
-
localeCountryIso31661Alpha2: 'US',
|
|
36
|
-
...phoneId
|
|
37
|
-
};
|
|
24
|
+
}, platform, releaseChannel: WAProto_1.proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE, mcc: ((_a = config.auth.creds.registration) === null || _a === void 0 ? void 0 : _a.phoneNumberMobileCountryCode) || '000', mnc: ((_b = config.auth.creds.registration) === null || _b === void 0 ? void 0 : _b.phoneNumberMobileNetworkCode) || '000', osVersion: osVersion, manufacturer,
|
|
25
|
+
device, osBuildNumber: osVersion, localeLanguageIso6391: 'en', localeCountryIso31661Alpha2: 'US' }, phoneId);
|
|
38
26
|
};
|
|
39
27
|
const PLATFORM_MAP = {
|
|
40
28
|
'Mac OS': WAProto_1.proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
@@ -62,31 +50,16 @@ const generateMobileNode = (config) => {
|
|
|
62
50
|
if (!config.auth.creds) {
|
|
63
51
|
throw new boom_1.Boom('No registration data found', { data: config });
|
|
64
52
|
}
|
|
65
|
-
const payload = {
|
|
66
|
-
...getClientPayload(config),
|
|
67
|
-
sessionId: Math.floor(Math.random() * 999999999 + 1),
|
|
68
|
-
shortConnect: true,
|
|
69
|
-
connectAttemptCount: 0,
|
|
70
|
-
device: 0,
|
|
71
|
-
dnsSource: {
|
|
53
|
+
const payload = Object.assign(Object.assign({}, getClientPayload(config)), { sessionId: Math.floor(Math.random() * 999999999 + 1), shortConnect: true, connectAttemptCount: 0, device: 0, dnsSource: {
|
|
72
54
|
appCached: false,
|
|
73
55
|
dnsMethod: WAProto_1.proto.ClientPayload.DNSSource.DNSResolutionMethod.SYSTEM,
|
|
74
|
-
},
|
|
75
|
-
passive: false,
|
|
76
|
-
pushName: 'test',
|
|
77
|
-
username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`),
|
|
78
|
-
};
|
|
56
|
+
}, passive: false, pushName: 'test', username: Number(`${config.auth.creds.registration.phoneNumberCountryCode}${config.auth.creds.registration.phoneNumberNationalNumber}`) });
|
|
79
57
|
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
80
58
|
};
|
|
81
59
|
exports.generateMobileNode = generateMobileNode;
|
|
82
60
|
const generateLoginNode = (userJid, config) => {
|
|
83
61
|
const { user, device } = (0, WABinary_1.jidDecode)(userJid);
|
|
84
|
-
const payload = {
|
|
85
|
-
...getClientPayload(config),
|
|
86
|
-
passive: true,
|
|
87
|
-
username: +user,
|
|
88
|
-
device: device,
|
|
89
|
-
};
|
|
62
|
+
const payload = Object.assign(Object.assign({}, getClientPayload(config)), { passive: true, username: +user, device: device });
|
|
90
63
|
return WAProto_1.proto.ClientPayload.fromObject(payload);
|
|
91
64
|
};
|
|
92
65
|
exports.generateLoginNode = generateLoginNode;
|
|
@@ -106,10 +79,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
106
79
|
requireFullSync: config.syncFullHistory,
|
|
107
80
|
};
|
|
108
81
|
const companionProto = WAProto_1.proto.DeviceProps.encode(companion).finish();
|
|
109
|
-
const registerPayload = {
|
|
110
|
-
...getClientPayload(config),
|
|
111
|
-
passive: false,
|
|
112
|
-
devicePairingData: {
|
|
82
|
+
const registerPayload = Object.assign(Object.assign({}, getClientPayload(config)), { passive: false, devicePairingData: {
|
|
113
83
|
buildHash: appVersionBuf,
|
|
114
84
|
deviceProps: companionProto,
|
|
115
85
|
eRegid: (0, generics_1.encodeBigEndian)(registrationId),
|
|
@@ -118,8 +88,7 @@ const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentity
|
|
|
118
88
|
eSkeyId: (0, generics_1.encodeBigEndian)(signedPreKey.keyId, 3),
|
|
119
89
|
eSkeyVal: signedPreKey.keyPair.public,
|
|
120
90
|
eSkeySig: signedPreKey.signature,
|
|
121
|
-
}
|
|
122
|
-
};
|
|
91
|
+
} });
|
|
123
92
|
return WAProto_1.proto.ClientPayload.fromObject(registerPayload);
|
|
124
93
|
};
|
|
125
94
|
exports.generateRegistrationNode = generateRegistrationNode;
|
|
@@ -192,7 +161,7 @@ const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, s
|
|
|
192
161
|
exports.configureSuccessfulPairing = configureSuccessfulPairing;
|
|
193
162
|
const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
194
163
|
var _a;
|
|
195
|
-
account = {
|
|
164
|
+
account = Object.assign({}, account);
|
|
196
165
|
// set to null if we are not to include the signature key
|
|
197
166
|
// or if we are including the signature key but it is empty
|
|
198
167
|
if (!includeSignatureKey || !((_a = account.accountSignatureKey) === null || _a === void 0 ? void 0 : _a.length)) {
|