mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
refactor: Change Sync Functions to Promises to Prevent Blocking Event Loop (#896)
* initial commit * lint * lint 2
This commit is contained in:
@@ -440,7 +440,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
const ref = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_ref'))
|
||||
const primaryIdentityPublicKey = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'primary_identity_pub'))
|
||||
const primaryEphemeralPublicKeyWrapped = toRequiredBuffer(getBinaryNodeChildBuffer(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'))
|
||||
const codePairingPublicKey = decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped)
|
||||
const codePairingPublicKey = await decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped)
|
||||
const companionSharedKey = Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey)
|
||||
const random = randomBytes(32)
|
||||
const linkCodeSalt = randomBytes(32)
|
||||
@@ -499,10 +499,10 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
}
|
||||
}
|
||||
|
||||
function decipherLinkPublicKey(data: Uint8Array | Buffer) {
|
||||
async function decipherLinkPublicKey(data: Uint8Array | Buffer) {
|
||||
const buffer = toRequiredBuffer(data)
|
||||
const salt = buffer.slice(0, 32)
|
||||
const secretKey = derivePairingCodeKey(authState.creds.pairingCode!, salt)
|
||||
const secretKey = await derivePairingCodeKey(authState.creds.pairingCode!, salt)
|
||||
const iv = buffer.slice(32, 48)
|
||||
const payload = buffer.slice(48, 80)
|
||||
return aesDecryptCTR(payload, secretKey, iv)
|
||||
|
||||
@@ -548,7 +548,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
async function generatePairingKey() {
|
||||
const salt = randomBytes(32)
|
||||
const randomIv = randomBytes(16)
|
||||
const key = derivePairingCodeKey(authState.creds.pairingCode!, salt)
|
||||
const key = await derivePairingCodeKey(authState.creds.pairingCode!, salt)
|
||||
const ciphered = aesEncryptCTR(authState.creds.pairingEphemeralKeyPair.public, key, randomIv)
|
||||
return Buffer.concat([salt, randomIv, ciphered])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user