mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
refactor: turn hkdf functions to async and remove extra deps (#1272)
* refactor: remove futoin-hkdf dependency and update hkdf implementation * refactor: use crypto subtle and update functions to async --------- Co-authored-by: Rajeh Taher <rajeh@reforward.dev>
This commit is contained in:
committed by
GitHub
parent
e6f98c3902
commit
8083754621
@@ -476,7 +476,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
const companionSharedKey = Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey)
|
||||
const random = randomBytes(32)
|
||||
const linkCodeSalt = randomBytes(32)
|
||||
const linkCodePairingExpanded = hkdf(companionSharedKey, 32, {
|
||||
const linkCodePairingExpanded = await hkdf(companionSharedKey, 32, {
|
||||
salt: linkCodeSalt,
|
||||
info: 'link_code_pairing_key_bundle_encryption_key'
|
||||
})
|
||||
@@ -486,7 +486,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted])
|
||||
const identitySharedKey = Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey)
|
||||
const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random])
|
||||
authState.creds.advSecretKey = hkdf(identityPayload, 32, { info: 'adv_secret' }).toString('base64')
|
||||
authState.creds.advSecretKey = (await hkdf(identityPayload, 32, { info: 'adv_secret' })).toString('base64')
|
||||
await query({
|
||||
tag: 'iq',
|
||||
attrs: {
|
||||
|
||||
@@ -654,20 +654,20 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
||||
const content = assertMediaContent(message.message)
|
||||
const mediaKey = content.mediaKey!
|
||||
const meId = authState.creds.me!.id
|
||||
const node = encryptMediaRetryRequest(message.key, mediaKey, meId)
|
||||
const node = await encryptMediaRetryRequest(message.key, mediaKey, meId)
|
||||
|
||||
let error: Error | undefined = undefined
|
||||
await Promise.all(
|
||||
[
|
||||
sendNode(node),
|
||||
waitForMsgMediaUpdate(update => {
|
||||
waitForMsgMediaUpdate(async(update) => {
|
||||
const result = update.find(c => c.key.id === message.key.id)
|
||||
if(result) {
|
||||
if(result.error) {
|
||||
error = result.error
|
||||
} else {
|
||||
try {
|
||||
const media = decryptMediaRetryData(result.media!, mediaKey, result.key.id!)
|
||||
const media = await decryptMediaRetryData(result.media!, mediaKey, result.key.id!)
|
||||
if(media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
|
||||
const resultStr = proto.MediaRetryNotification.ResultType[media.result]
|
||||
throw new Boom(
|
||||
|
||||
@@ -238,7 +238,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
|
||||
logger.trace({ handshake }, 'handshake recv from WA')
|
||||
|
||||
const keyEnc = noise.processHandshake(handshake, creds.noiseKey)
|
||||
const keyEnc = await noise.processHandshake(handshake, creds.noiseKey)
|
||||
|
||||
let node: proto.IClientPayload
|
||||
if(!creds.me) {
|
||||
|
||||
Reference in New Issue
Block a user