refactor: use Buffer instead of Binary

This commit is contained in:
Adhiraj Singh
2022-04-13 13:21:15 +05:30
parent 647138ffe5
commit 0cf17fb392
2 changed files with 14 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ import { Boom } from '@hapi/boom'
import { createHash } from 'crypto'
import { proto } from '../../WAProto'
import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types'
import { Binary, BinaryNode, getAllBinaryNodeChildren, jidDecode, S_WHATSAPP_NET } from '../WABinary'
import { BinaryNode, getAllBinaryNodeChildren, jidDecode, S_WHATSAPP_NET } from '../WABinary'
import { Curve, hmacSign } from './crypto'
import { encodeInt } from './generics'
import { createSignalIdentity } from './signal'
@@ -116,12 +116,21 @@ export const configureSuccessfulPairing = (
const account = proto.ADVSignedDeviceIdentity.decode(details)
const { accountSignatureKey, accountSignature } = account
const accountMsg = Binary.build(new Uint8Array([6, 0]), account.details, signedIdentityKey.public).readByteArray()
const accountMsg = Buffer.concat([
Buffer.from([6, 0]),
account.details,
signedIdentityKey.public
])
if(!Curve.verify(accountSignatureKey, accountMsg, accountSignature)) {
throw new Boom('Failed to verify account signature')
}
const deviceMsg = Binary.build(new Uint8Array([6, 1]), account.details, signedIdentityKey.public, account.accountSignatureKey).readByteArray()
const deviceMsg = Buffer.concat([
new Uint8Array([6, 1]),
account.details,
signedIdentityKey.public,
account.accountSignatureKey
])
account.deviceSignature = Curve.sign(signedIdentityKey.private, deviceMsg)
const identity = createSignalIdentity(jid, accountSignatureKey)