@zervonexx/baileys 5.0.0 → 5.0.2
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 +22 -22
- package/README.md +4124 -4112
- package/WAProto/WAProto.json +1 -0
- package/WAProto/WAProto.proto +7160 -0
- package/WAProto/WAProtoCompile.js +264 -322
- package/WAProto/index.js +55 -95
- package/lib/Builders/AIRich.js +673 -673
- package/lib/Builders/auto.js +49 -49
- package/lib/Builders/base.js +144 -144
- package/lib/Builders/builders.js +588 -588
- package/lib/Builders/index.js +3 -3
- package/lib/Defaults/index.js +249 -248
- package/lib/Signal/index.js +2 -2
- package/lib/Signal/libsignal.js +526 -526
- package/lib/Signal/lid-mapping.js +282 -282
- package/lib/Socket/Client/index.js +1 -1
- package/lib/Socket/Client/types.js +9 -9
- package/lib/Socket/Client/websocket.js +83 -83
- package/lib/Socket/business.js +151 -151
- package/lib/Socket/chats.js +854 -854
- package/lib/Socket/communities.js +146 -146
- package/lib/Socket/groups.js +293 -293
- package/lib/Socket/index.js +17 -14
- package/lib/Socket/messages-recv.js +993 -993
- package/lib/Socket/messages-send.js +722 -722
- package/lib/Socket/mex.js +33 -33
- package/lib/Socket/newsletter.js +783 -783
- package/lib/Socket/registration.js +154 -154
- package/lib/Socket/socket.js +797 -797
- package/lib/Socket/spam-report.js +143 -143
- package/lib/Socket/username.js +81 -81
- package/lib/Socket/zervonex-handler.js +57 -57
- package/lib/Store/index.js +6 -6
- package/lib/Store/make-cache-manager-store.js +80 -80
- package/lib/Store/make-in-memory-store.js +426 -426
- package/lib/Store/make-ordered-dictionary.js +81 -81
- package/lib/Store/object-repository.js +30 -30
- package/lib/Store/reporting-info-store.js +37 -37
- package/lib/Types/Auth.js +1 -1
- package/lib/Types/Bussines.js +1 -1
- package/lib/Types/Call.js +1 -1
- package/lib/Types/Chat.js +7 -7
- package/lib/Types/Contact.js +1 -1
- package/lib/Types/Events.js +1 -1
- package/lib/Types/GroupMetadata.js +1 -1
- package/lib/Types/Label.js +24 -24
- package/lib/Types/LabelAssociation.js +6 -6
- package/lib/Types/Message.js +14 -14
- package/lib/Types/Newsletter.js +99 -99
- package/lib/Types/Product.js +1 -1
- package/lib/Types/Signal.js +1 -1
- package/lib/Types/Socket.js +14 -14
- package/lib/Types/State.js +26 -26
- package/lib/Types/USync.js +1 -1
- package/lib/Types/index.js +30 -30
- package/lib/Utils/auth-utils.js +159 -159
- package/lib/Utils/baileys-event-stream.js +32 -32
- package/lib/Utils/bot-capabilities.js +40 -40
- package/lib/Utils/bot-planning-replay.js +43 -43
- package/lib/Utils/browser-utils.js +29 -29
- package/lib/Utils/business.js +74 -74
- package/lib/Utils/chat-utils.js +316 -316
- package/lib/Utils/companion-reg-client-utils.js +19 -19
- package/lib/Utils/consumer-application.js +37 -37
- package/lib/Utils/crypto.js +52 -52
- package/lib/Utils/cstoken.js +14 -14
- package/lib/Utils/decode-wa-message.js +199 -199
- package/lib/Utils/event-buffer.js +272 -272
- package/lib/Utils/extras.js +186 -186
- package/lib/Utils/generics.js +195 -194
- package/lib/Utils/history.js +50 -50
- package/lib/Utils/identity-change-handler.js +18 -18
- package/lib/Utils/index.js +40 -40
- package/lib/Utils/link-preview.js +50 -50
- package/lib/Utils/logger.js +3 -2
- package/lib/Utils/lt-hash.js +3 -3
- package/lib/Utils/make-mutex.js +15 -15
- package/lib/Utils/message-composer.js +61 -61
- package/lib/Utils/message-retry-manager.js +47 -47
- package/lib/Utils/messages-media.js +501 -501
- package/lib/Utils/messages.js +944 -942
- package/lib/Utils/meta-ai-msmsg.js +121 -121
- package/lib/Utils/meta-compositing.js +74 -74
- package/lib/Utils/modern-messages.js +234 -234
- package/lib/Utils/native-flow.js +80 -80
- package/lib/Utils/noise-handler.js +160 -160
- package/lib/Utils/pre-key-manager.js +75 -75
- package/lib/Utils/process-message.js +400 -400
- package/lib/Utils/reporting-utils.js +170 -170
- package/lib/Utils/signal.js +166 -166
- package/lib/Utils/spam-report-utils.js +165 -165
- package/lib/Utils/sync-action-utils.js +33 -33
- package/lib/Utils/tc-token-utils.js +153 -153
- package/lib/Utils/use-keyv-auth-state.js +199 -199
- package/lib/Utils/use-multi-file-auth-state.js +83 -83
- package/lib/Utils/validate-connection.js +171 -171
- package/lib/WABinary/constants.js +1320 -1320
- package/lib/WABinary/decode.js +151 -151
- package/lib/WABinary/encode.js +139 -139
- package/lib/WABinary/generic-utils.js +202 -202
- package/lib/WABinary/index.js +6 -6
- package/lib/WABinary/jid-utils.js +235 -235
- package/lib/WABinary/types.js +4 -4
- package/lib/WAM/BinaryInfo.js +9 -9
- package/lib/WAM/constants.js +22852 -22852
- package/lib/WAM/encode.js +149 -149
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +30 -30
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +48 -48
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +28 -28
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +15 -15
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +24 -24
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +21 -21
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +19 -19
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +19 -19
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +22 -22
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +16 -16
- package/lib/WAUSync/Protocols/index.js +12 -12
- package/lib/WAUSync/USyncQuery.js +88 -88
- package/lib/WAUSync/USyncUser.js +20 -20
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.js +66 -66
- package/package.json +187 -192
- package/WAProto/fetcher.js +0 -68
- package/WAProto/parser.js +0 -334
|
@@ -1,172 +1,172 @@
|
|
|
1
|
-
import { Boom } from '@hapi/boom'
|
|
2
|
-
import { createHash } from 'crypto'
|
|
3
|
-
import { proto } from '../../WAProto/index.js'
|
|
4
|
-
import { KEY_BUNDLE_TYPE, WA_ADV_ACCOUNT_SIG_PREFIX, WA_ADV_DEVICE_SIG_PREFIX, WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX } from '../Defaults/index.js'
|
|
5
|
-
import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary/index.js'
|
|
6
|
-
import { Curve, hmacSign } from './crypto.js'
|
|
7
|
-
import { encodeBigEndian } from './generics.js'
|
|
8
|
-
import { createSignalIdentity } from './signal.js'
|
|
9
|
-
import { getPlatformType } from './browser-utils.js'
|
|
10
|
-
|
|
11
|
-
const PLATFORM_MAP = {
|
|
12
|
-
'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
13
|
-
'Windows': proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID,
|
|
14
|
-
'WindowsStore': proto.ClientPayload.WebInfo.WebSubPlatform.WIN_STORE,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const getUserAgent = (config) => ({
|
|
18
|
-
appVersion: {
|
|
19
|
-
primary: config.version[0],
|
|
20
|
-
secondary: config.version[1],
|
|
21
|
-
tertiary: config.version[2],
|
|
22
|
-
},
|
|
23
|
-
platform: proto.ClientPayload.UserAgent.Platform.WEB,
|
|
24
|
-
releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
25
|
-
osVersion: '0.1',
|
|
26
|
-
device: 'Desktop',
|
|
27
|
-
deviceType: proto.ClientPayload.UserAgent.DeviceType.DESKTOP,
|
|
28
|
-
osBuildNumber: '0.1',
|
|
29
|
-
localeLanguageIso6391: 'en',
|
|
30
|
-
mnc: '000',
|
|
31
|
-
mcc: '000',
|
|
32
|
-
localeCountryIso31661Alpha2: config.countryCode,
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const getWebInfo = (config) => {
|
|
36
|
-
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
|
|
37
|
-
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop')
|
|
38
|
-
webSubPlatform = PLATFORM_MAP[config.browser[0]]
|
|
39
|
-
return { webSubPlatform }
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const getClientPayload = (config) => {
|
|
43
|
-
const payload = {
|
|
44
|
-
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
45
|
-
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
46
|
-
userAgent: getUserAgent(config),
|
|
47
|
-
}
|
|
48
|
-
if (!config.browser[1].toLowerCase().includes('android')) payload.webInfo = getWebInfo(config)
|
|
49
|
-
return payload
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const buildHistorySyncConfig = () => {
|
|
53
|
-
const fields = proto.DeviceProps.HistorySyncConfig.fields
|
|
54
|
-
const config = {}
|
|
55
|
-
for (const [name, field] of Object.entries(fields)) {
|
|
56
|
-
if (field.type === 'bool') config[name] = true
|
|
57
|
-
}
|
|
58
|
-
config.storageQuotaMb = 569150
|
|
59
|
-
config.supportCallLogHistory = false
|
|
60
|
-
config.supportGroupHistory = true
|
|
61
|
-
return config
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const generateLoginNode = (userJid, config) => {
|
|
65
|
-
const { user, device } = jidDecode(userJid)
|
|
66
|
-
return proto.ClientPayload.fromObject({
|
|
67
|
-
...getClientPayload(config),
|
|
68
|
-
passive: true,
|
|
69
|
-
pull: true,
|
|
70
|
-
username: +user,
|
|
71
|
-
device,
|
|
72
|
-
lidDbMigrated: false, // hard-set; behaviour under true is unknown
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
77
|
-
const appVersionBuf = createHash('md5').update(config.version.join('.')).digest()
|
|
78
|
-
const companionProto = proto.DeviceProps.encode({
|
|
79
|
-
os: config.browser[0],
|
|
80
|
-
platformType: getPlatformType(config.browser[1]),
|
|
81
|
-
requireFullSync: config.syncFullHistory,
|
|
82
|
-
historySyncConfig: buildHistorySyncConfig(),
|
|
83
|
-
version: { primary: config.version[0], secondary: config.version[1], tertiary: config.version[2] },
|
|
84
|
-
}).finish()
|
|
85
|
-
|
|
86
|
-
return proto.ClientPayload.fromObject({
|
|
87
|
-
...getClientPayload(config),
|
|
88
|
-
passive: false,
|
|
89
|
-
pull: false,
|
|
90
|
-
devicePairingData: {
|
|
91
|
-
eRegid: encodeBigEndian(registrationId),
|
|
92
|
-
eKeytype: KEY_BUNDLE_TYPE,
|
|
93
|
-
eIdent: signedIdentityKey.public,
|
|
94
|
-
eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
|
|
95
|
-
eSkeyVal: signedPreKey.keyPair.public,
|
|
96
|
-
eSkeySig: signedPreKey.signature,
|
|
97
|
-
buildHash: appVersionBuf,
|
|
98
|
-
deviceProps: companionProto,
|
|
99
|
-
},
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
104
|
-
const msgId = stanza.attrs.id
|
|
105
|
-
const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success')
|
|
106
|
-
const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity')
|
|
107
|
-
const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform')
|
|
108
|
-
const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device')
|
|
109
|
-
const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz')
|
|
110
|
-
|
|
111
|
-
if (!deviceIdentityNode || !deviceNode)
|
|
112
|
-
throw new Boom('Missing device-identity or device in pair success node', { data: stanza })
|
|
113
|
-
|
|
114
|
-
const jid = deviceNode.attrs.jid
|
|
115
|
-
const lid = deviceNode.attrs.lid
|
|
116
|
-
const bizName = businessNode?.attrs.name
|
|
117
|
-
|
|
118
|
-
const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content)
|
|
119
|
-
const hmacPrefix = (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED)
|
|
120
|
-
? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
121
|
-
: Buffer.from([])
|
|
122
|
-
|
|
123
|
-
if (Buffer.compare(hmac, hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))) !== 0)
|
|
124
|
-
throw new Boom('Invalid account signature')
|
|
125
|
-
|
|
126
|
-
const account = proto.ADVSignedDeviceIdentity.decode(details)
|
|
127
|
-
const { accountSignatureKey, accountSignature, details: deviceDetails } = account
|
|
128
|
-
const deviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails)
|
|
129
|
-
|
|
130
|
-
const accountSignaturePrefix = deviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
|
|
131
|
-
? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
132
|
-
: WA_ADV_ACCOUNT_SIG_PREFIX
|
|
133
|
-
|
|
134
|
-
if (!Curve.verify(accountSignatureKey, Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]), accountSignature))
|
|
135
|
-
throw new Boom('Failed to verify account signature')
|
|
136
|
-
|
|
137
|
-
account.deviceSignature = Curve.sign(
|
|
138
|
-
signedIdentityKey.private,
|
|
139
|
-
Buffer.concat([WA_ADV_DEVICE_SIG_PREFIX, deviceDetails, signedIdentityKey.public, accountSignatureKey])
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
const identity = createSignalIdentity(lid, accountSignatureKey)
|
|
143
|
-
const accountEnc = encodeSignedDeviceIdentity(account, false)
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
creds: {
|
|
147
|
-
account,
|
|
148
|
-
me: { id: jid, name: bizName, lid },
|
|
149
|
-
signalIdentities: [...(signalIdentities ?? []), identity],
|
|
150
|
-
platform: platformNode?.attrs.name,
|
|
151
|
-
},
|
|
152
|
-
reply: {
|
|
153
|
-
tag: 'iq',
|
|
154
|
-
attrs: { to: S_WHATSAPP_NET, type: 'result', id: msgId },
|
|
155
|
-
content: [{
|
|
156
|
-
tag: 'pair-device-sign',
|
|
157
|
-
attrs: {},
|
|
158
|
-
content: [{
|
|
159
|
-
tag: 'device-identity',
|
|
160
|
-
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
161
|
-
content: accountEnc,
|
|
162
|
-
}],
|
|
163
|
-
}],
|
|
164
|
-
},
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
169
|
-
account = { ...account }
|
|
170
|
-
if (!includeSignatureKey || !account.accountSignatureKey?.length) account.accountSignatureKey = null
|
|
171
|
-
return proto.ADVSignedDeviceIdentity.encode(account).finish()
|
|
1
|
+
import { Boom } from '@hapi/boom'
|
|
2
|
+
import { createHash } from 'crypto'
|
|
3
|
+
import { proto } from '../../WAProto/index.js'
|
|
4
|
+
import { KEY_BUNDLE_TYPE, WA_ADV_ACCOUNT_SIG_PREFIX, WA_ADV_DEVICE_SIG_PREFIX, WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX } from '../Defaults/index.js'
|
|
5
|
+
import { getBinaryNodeChild, jidDecode, S_WHATSAPP_NET } from '../WABinary/index.js'
|
|
6
|
+
import { Curve, hmacSign } from './crypto.js'
|
|
7
|
+
import { encodeBigEndian } from './generics.js'
|
|
8
|
+
import { createSignalIdentity } from './signal.js'
|
|
9
|
+
import { getPlatformType } from './browser-utils.js'
|
|
10
|
+
|
|
11
|
+
const PLATFORM_MAP = {
|
|
12
|
+
'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
|
|
13
|
+
'Windows': proto.ClientPayload.WebInfo.WebSubPlatform.WIN_HYBRID,
|
|
14
|
+
'WindowsStore': proto.ClientPayload.WebInfo.WebSubPlatform.WIN_STORE,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const getUserAgent = (config) => ({
|
|
18
|
+
appVersion: {
|
|
19
|
+
primary: config.version[0],
|
|
20
|
+
secondary: config.version[1],
|
|
21
|
+
tertiary: config.version[2],
|
|
22
|
+
},
|
|
23
|
+
platform: proto.ClientPayload.UserAgent.Platform.WEB,
|
|
24
|
+
releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
|
|
25
|
+
osVersion: '0.1',
|
|
26
|
+
device: 'Desktop',
|
|
27
|
+
deviceType: proto.ClientPayload.UserAgent.DeviceType.DESKTOP,
|
|
28
|
+
osBuildNumber: '0.1',
|
|
29
|
+
localeLanguageIso6391: 'en',
|
|
30
|
+
mnc: '000',
|
|
31
|
+
mcc: '000',
|
|
32
|
+
localeCountryIso31661Alpha2: config.countryCode,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const getWebInfo = (config) => {
|
|
36
|
+
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
|
|
37
|
+
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]] && config.browser[1] === 'Desktop')
|
|
38
|
+
webSubPlatform = PLATFORM_MAP[config.browser[0]]
|
|
39
|
+
return { webSubPlatform }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getClientPayload = (config) => {
|
|
43
|
+
const payload = {
|
|
44
|
+
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
45
|
+
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
46
|
+
userAgent: getUserAgent(config),
|
|
47
|
+
}
|
|
48
|
+
if (!config.browser[1].toLowerCase().includes('android')) payload.webInfo = getWebInfo(config)
|
|
49
|
+
return payload
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const buildHistorySyncConfig = () => {
|
|
53
|
+
const fields = proto.DeviceProps.HistorySyncConfig.fields
|
|
54
|
+
const config = {}
|
|
55
|
+
for (const [name, field] of Object.entries(fields)) {
|
|
56
|
+
if (field.type === 'bool') config[name] = true
|
|
57
|
+
}
|
|
58
|
+
config.storageQuotaMb = 569150
|
|
59
|
+
config.supportCallLogHistory = false
|
|
60
|
+
config.supportGroupHistory = true
|
|
61
|
+
return config
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const generateLoginNode = (userJid, config) => {
|
|
65
|
+
const { user, device } = jidDecode(userJid)
|
|
66
|
+
return proto.ClientPayload.fromObject({
|
|
67
|
+
...getClientPayload(config),
|
|
68
|
+
passive: true,
|
|
69
|
+
pull: true,
|
|
70
|
+
username: +user,
|
|
71
|
+
device,
|
|
72
|
+
lidDbMigrated: false, // hard-set; behaviour under true is unknown
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
|
|
77
|
+
const appVersionBuf = createHash('md5').update(config.version.join('.')).digest()
|
|
78
|
+
const companionProto = proto.DeviceProps.encode({
|
|
79
|
+
os: config.browser[0],
|
|
80
|
+
platformType: getPlatformType(config.browser[1]),
|
|
81
|
+
requireFullSync: config.syncFullHistory,
|
|
82
|
+
historySyncConfig: buildHistorySyncConfig(),
|
|
83
|
+
version: { primary: config.version[0], secondary: config.version[1], tertiary: config.version[2] },
|
|
84
|
+
}).finish()
|
|
85
|
+
|
|
86
|
+
return proto.ClientPayload.fromObject({
|
|
87
|
+
...getClientPayload(config),
|
|
88
|
+
passive: false,
|
|
89
|
+
pull: false,
|
|
90
|
+
devicePairingData: {
|
|
91
|
+
eRegid: encodeBigEndian(registrationId),
|
|
92
|
+
eKeytype: KEY_BUNDLE_TYPE,
|
|
93
|
+
eIdent: signedIdentityKey.public,
|
|
94
|
+
eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
|
|
95
|
+
eSkeyVal: signedPreKey.keyPair.public,
|
|
96
|
+
eSkeySig: signedPreKey.signature,
|
|
97
|
+
buildHash: appVersionBuf,
|
|
98
|
+
deviceProps: companionProto,
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const configureSuccessfulPairing = (stanza, { advSecretKey, signedIdentityKey, signalIdentities }) => {
|
|
104
|
+
const msgId = stanza.attrs.id
|
|
105
|
+
const pairSuccessNode = getBinaryNodeChild(stanza, 'pair-success')
|
|
106
|
+
const deviceIdentityNode = getBinaryNodeChild(pairSuccessNode, 'device-identity')
|
|
107
|
+
const platformNode = getBinaryNodeChild(pairSuccessNode, 'platform')
|
|
108
|
+
const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device')
|
|
109
|
+
const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz')
|
|
110
|
+
|
|
111
|
+
if (!deviceIdentityNode || !deviceNode)
|
|
112
|
+
throw new Boom('Missing device-identity or device in pair success node', { data: stanza })
|
|
113
|
+
|
|
114
|
+
const jid = deviceNode.attrs.jid
|
|
115
|
+
const lid = deviceNode.attrs.lid
|
|
116
|
+
const bizName = businessNode?.attrs.name
|
|
117
|
+
|
|
118
|
+
const { details, hmac, accountType } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content)
|
|
119
|
+
const hmacPrefix = (accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED)
|
|
120
|
+
? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
121
|
+
: Buffer.from([])
|
|
122
|
+
|
|
123
|
+
if (Buffer.compare(hmac, hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))) !== 0)
|
|
124
|
+
throw new Boom('Invalid account signature')
|
|
125
|
+
|
|
126
|
+
const account = proto.ADVSignedDeviceIdentity.decode(details)
|
|
127
|
+
const { accountSignatureKey, accountSignature, details: deviceDetails } = account
|
|
128
|
+
const deviceIdentity = proto.ADVDeviceIdentity.decode(deviceDetails)
|
|
129
|
+
|
|
130
|
+
const accountSignaturePrefix = deviceIdentity.deviceType === proto.ADVEncryptionType.HOSTED
|
|
131
|
+
? WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX
|
|
132
|
+
: WA_ADV_ACCOUNT_SIG_PREFIX
|
|
133
|
+
|
|
134
|
+
if (!Curve.verify(accountSignatureKey, Buffer.concat([accountSignaturePrefix, deviceDetails, signedIdentityKey.public]), accountSignature))
|
|
135
|
+
throw new Boom('Failed to verify account signature')
|
|
136
|
+
|
|
137
|
+
account.deviceSignature = Curve.sign(
|
|
138
|
+
signedIdentityKey.private,
|
|
139
|
+
Buffer.concat([WA_ADV_DEVICE_SIG_PREFIX, deviceDetails, signedIdentityKey.public, accountSignatureKey])
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
const identity = createSignalIdentity(lid, accountSignatureKey)
|
|
143
|
+
const accountEnc = encodeSignedDeviceIdentity(account, false)
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
creds: {
|
|
147
|
+
account,
|
|
148
|
+
me: { id: jid, name: bizName, lid },
|
|
149
|
+
signalIdentities: [...(signalIdentities ?? []), identity],
|
|
150
|
+
platform: platformNode?.attrs.name,
|
|
151
|
+
},
|
|
152
|
+
reply: {
|
|
153
|
+
tag: 'iq',
|
|
154
|
+
attrs: { to: S_WHATSAPP_NET, type: 'result', id: msgId },
|
|
155
|
+
content: [{
|
|
156
|
+
tag: 'pair-device-sign',
|
|
157
|
+
attrs: {},
|
|
158
|
+
content: [{
|
|
159
|
+
tag: 'device-identity',
|
|
160
|
+
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
|
161
|
+
content: accountEnc,
|
|
162
|
+
}],
|
|
163
|
+
}],
|
|
164
|
+
},
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export const encodeSignedDeviceIdentity = (account, includeSignatureKey) => {
|
|
169
|
+
account = { ...account }
|
|
170
|
+
if (!includeSignatureKey || !account.accountSignatureKey?.length) account.accountSignatureKey = null
|
|
171
|
+
return proto.ADVSignedDeviceIdentity.encode(account).finish()
|
|
172
172
|
}
|