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

@@ -18,7 +18,7 @@ export const makeNoiseHandler = ({ public: publicKey, private: privateKey }: Key
const authenticate = (data: Uint8Array) => {
if(!isFinished) {
hash = sha256(Buffer.from(Binary.build(hash, data).readByteArray()))
hash = sha256(Buffer.concat([hash, data]))
}
}
@@ -84,7 +84,7 @@ export const makeNoiseHandler = ({ public: publicKey, private: privateKey }: Key
isFinished = true
}
const data = Binary.build(NOISE_MODE).readBuffer()
const data = Buffer.from(NOISE_MODE)
let hash = Buffer.from(data.byteLength === 32 ? data : sha256(Buffer.from(data)))
let salt = hash
let encKey = hash

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)