feat(WAProto): Optimize protobuf generation for 80%+ bundle size reduction (#1665)
* chore: remove comments and veirfy from generated proto files (improve size) * refactor: replace fromObject with create for proto message instantiation and flag no beautiful * chore: lint issues
This commit is contained in:
committed by
GitHub
parent
9e04cce8d3
commit
4d4339dae6
@@ -62,7 +62,7 @@ export const generateLoginNode = (userJid: string, config: SocketConfig): proto.
|
||||
username: +user,
|
||||
device: device
|
||||
}
|
||||
return proto.ClientPayload.fromObject(payload)
|
||||
return proto.ClientPayload.create(payload)
|
||||
}
|
||||
|
||||
const getPlatformType = (platform: string): proto.DeviceProps.PlatformType => {
|
||||
@@ -107,7 +107,7 @@ export const generateRegistrationNode = (
|
||||
}
|
||||
}
|
||||
|
||||
return proto.ClientPayload.fromObject(registerPayload)
|
||||
return proto.ClientPayload.create(registerPayload)
|
||||
}
|
||||
|
||||
export const configureSuccessfulPairing = (
|
||||
@@ -138,26 +138,26 @@ export const configureSuccessfulPairing = (
|
||||
const isHostedAccount = accountType !== undefined && accountType === proto.ADVEncryptionType.HOSTED
|
||||
|
||||
const hmacPrefix = isHostedAccount ? Buffer.from([6, 5]) : Buffer.alloc(0)
|
||||
const advSign = hmacSign(Buffer.concat([hmacPrefix, details!]), Buffer.from(advSecretKey, 'base64'))
|
||||
if (Buffer.compare(hmac!, advSign) !== 0) {
|
||||
const advSign = hmacSign(Buffer.concat([hmacPrefix, details]), Buffer.from(advSecretKey, 'base64'))
|
||||
if (Buffer.compare(hmac, advSign) !== 0) {
|
||||
throw new Boom('Invalid account signature')
|
||||
}
|
||||
|
||||
const account = proto.ADVSignedDeviceIdentity.decode(details!)
|
||||
const account = proto.ADVSignedDeviceIdentity.decode(details)
|
||||
const { accountSignatureKey, accountSignature, details: deviceDetails } = account
|
||||
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')
|
||||
}
|
||||
|
||||
const devicePrefix = isHostedAccount ? Buffer.from([6, 6]) : Buffer.from([6, 1])
|
||||
const deviceMsg = Buffer.concat([devicePrefix, deviceDetails!, signedIdentityKey.public, accountSignatureKey!])
|
||||
const deviceMsg = Buffer.concat([devicePrefix, deviceDetails, signedIdentityKey.public, accountSignatureKey])
|
||||
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg)
|
||||
|
||||
const identity = createSignalIdentity(jid!, accountSignatureKey!)
|
||||
const identity = createSignalIdentity(jid!, accountSignatureKey)
|
||||
const accountEnc = encodeSignedDeviceIdentity(account, false)
|
||||
|
||||
const deviceIdentity = proto.ADVDeviceIdentity.decode(account.details!)
|
||||
const deviceIdentity = proto.ADVDeviceIdentity.decode(account.details)
|
||||
|
||||
const reply: BinaryNode = {
|
||||
tag: 'iq',
|
||||
@@ -173,7 +173,7 @@ export const configureSuccessfulPairing = (
|
||||
content: [
|
||||
{
|
||||
tag: 'device-identity',
|
||||
attrs: { 'key-index': deviceIdentity.keyIndex!.toString() },
|
||||
attrs: { 'key-index': deviceIdentity.keyIndex.toString() },
|
||||
content: accountEnc
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user