chore: format everything

This commit is contained in:
canove
2025-05-06 12:10:19 -03:00
parent 04afa20244
commit fa706d0b50
76 changed files with 8241 additions and 7142 deletions

View File

@@ -13,7 +13,7 @@ const getUserAgent = (config: SocketConfig): proto.ClientPayload.IUserAgent => {
appVersion: {
primary: config.version[0],
secondary: config.version[1],
tertiary: config.version[2],
tertiary: config.version[2]
},
platform: proto.ClientPayload.UserAgent.Platform.WEB,
releaseChannel: proto.ClientPayload.UserAgent.ReleaseChannel.RELEASE,
@@ -23,30 +23,29 @@ const getUserAgent = (config: SocketConfig): proto.ClientPayload.IUserAgent => {
localeLanguageIso6391: 'en',
mnc: '000',
mcc: '000',
localeCountryIso31661Alpha2: config.countryCode,
localeCountryIso31661Alpha2: config.countryCode
}
}
const PLATFORM_MAP = {
'Mac OS': proto.ClientPayload.WebInfo.WebSubPlatform.DARWIN,
'Windows': proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
Windows: proto.ClientPayload.WebInfo.WebSubPlatform.WIN32
}
const getWebInfo = (config: SocketConfig): proto.ClientPayload.IWebInfo => {
let webSubPlatform = proto.ClientPayload.WebInfo.WebSubPlatform.WEB_BROWSER
if(config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
if (config.syncFullHistory && PLATFORM_MAP[config.browser[0]]) {
webSubPlatform = PLATFORM_MAP[config.browser[0]]
}
return { webSubPlatform }
}
const getClientPayload = (config: SocketConfig) => {
const payload: proto.IClientPayload = {
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
userAgent: getUserAgent(config),
userAgent: getUserAgent(config)
}
payload.webInfo = getWebInfo(config)
@@ -54,7 +53,6 @@ const getClientPayload = (config: SocketConfig) => {
return payload
}
export const generateLoginNode = (userJid: string, config: SocketConfig): proto.IClientPayload => {
const { user, device } = jidDecode(userJid)!
const payload: proto.IClientPayload = {
@@ -62,7 +60,7 @@ export const generateLoginNode = (userJid: string, config: SocketConfig): proto.
passive: false,
pull: true,
username: +user,
device: device,
device: device
}
return proto.ClientPayload.fromObject(payload)
}
@@ -85,7 +83,7 @@ export const generateRegistrationNode = (
const companion: proto.IDeviceProps = {
os: config.browser[0],
platformType: getPlatformType(config.browser[1]),
requireFullSync: config.syncFullHistory,
requireFullSync: config.syncFullHistory
}
const companionProto = proto.DeviceProps.encode(companion).finish()
@@ -102,8 +100,8 @@ export const generateRegistrationNode = (
eIdent: signedIdentityKey.public,
eSkeyId: encodeBigEndian(signedPreKey.keyId, 3),
eSkeyVal: signedPreKey.keyPair.public,
eSkeySig: signedPreKey.signature,
},
eSkeySig: signedPreKey.signature
}
}
return proto.ClientPayload.fromObject(registerPayload)
@@ -111,7 +109,11 @@ export const generateRegistrationNode = (
export const configureSuccessfulPairing = (
stanza: BinaryNode,
{ advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>
{
advSecretKey,
signedIdentityKey,
signalIdentities
}: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>
) => {
const msgId = stanza.attrs.id
@@ -122,7 +124,7 @@ export const configureSuccessfulPairing = (
const deviceNode = getBinaryNodeChild(pairSuccessNode, 'device')
const businessNode = getBinaryNodeChild(pairSuccessNode, 'biz')
if(!deviceIdentityNode || !deviceNode) {
if (!deviceIdentityNode || !deviceNode) {
throw new Boom('Missing device-identity or device in pair success node', { data: stanza })
}
@@ -132,20 +134,20 @@ export const configureSuccessfulPairing = (
const { details, hmac } = proto.ADVSignedDeviceIdentityHMAC.decode(deviceIdentityNode.content as Buffer)
// check HMAC matches
const advSign = hmacSign(details!, Buffer.from(advSecretKey, 'base64'))
if(Buffer.compare(hmac!, advSign) !== 0) {
if (Buffer.compare(hmac!, advSign) !== 0) {
throw new Boom('Invalid account signature')
}
const account = proto.ADVSignedDeviceIdentity.decode(details!)
const { accountSignatureKey, accountSignature, details: deviceDetails } = account
// verify the device signature matches
const accountMsg = Buffer.concat([ Buffer.from([6, 0]), deviceDetails!, signedIdentityKey.public ])
if(!Curve.verify(accountSignatureKey!, accountMsg, accountSignature!)) {
const accountMsg = Buffer.concat([Buffer.from([6, 0]), deviceDetails!, signedIdentityKey.public])
if (!Curve.verify(accountSignatureKey!, accountMsg, accountSignature!)) {
throw new Boom('Failed to verify account signature')
}
// sign the details with our identity key
const deviceMsg = Buffer.concat([ Buffer.from([6, 1]), deviceDetails!, signedIdentityKey.public, accountSignatureKey! ])
const deviceMsg = Buffer.concat([Buffer.from([6, 1]), deviceDetails!, signedIdentityKey.public, accountSignatureKey!])
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg)
const identity = createSignalIdentity(jid, accountSignatureKey!)
@@ -158,12 +160,12 @@ export const configureSuccessfulPairing = (
attrs: {
to: S_WHATSAPP_NET,
type: 'result',
id: msgId,
id: msgId
},
content: [
{
tag: 'pair-device-sign',
attrs: { },
attrs: {},
content: [
{
tag: 'device-identity',
@@ -178,10 +180,7 @@ export const configureSuccessfulPairing = (
const authUpdate: Partial<AuthenticationCreds> = {
account,
me: { id: jid, name: bizName },
signalIdentities: [
...(signalIdentities || []),
identity
],
signalIdentities: [...(signalIdentities || []), identity],
platform: platformNode?.attrs.name
}
@@ -191,18 +190,13 @@ export const configureSuccessfulPairing = (
}
}
export const encodeSignedDeviceIdentity = (
account: proto.IADVSignedDeviceIdentity,
includeSignatureKey: boolean
) => {
export const encodeSignedDeviceIdentity = (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => {
account = { ...account }
// set to null if we are not to include the signature key
// or if we are including the signature key but it is empty
if(!includeSignatureKey || !account.accountSignatureKey?.length) {
if (!includeSignatureKey || !account.accountSignatureKey?.length) {
account.accountSignatureKey = null
}
return proto.ADVSignedDeviceIdentity
.encode(account)
.finish()
return proto.ADVSignedDeviceIdentity.encode(account).finish()
}