mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
refactor: use only "getAppStateSyncKey" in syncd patch
This commit is contained in:
@@ -211,7 +211,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
const name = key as WAPatchName
|
const name = key as WAPatchName
|
||||||
// only process if there are syncd patches
|
// only process if there are syncd patches
|
||||||
if(decoded[name].length) {
|
if(decoded[name].length) {
|
||||||
const { newMutations, state: newState } = await decodePatches(name, decoded[name], states[name], authState, true)
|
const { newMutations, state: newState } = await decodePatches(name, decoded[name], states[name], authState.keys.getAppStateSyncKey, true)
|
||||||
|
|
||||||
await authState.keys.setAppStateSyncVersion(name, newState)
|
await authState.keys.setAppStateSyncVersion(name, newState)
|
||||||
|
|
||||||
@@ -387,7 +387,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
)
|
)
|
||||||
const initial = await authState.keys.getAppStateSyncVersion(name)
|
const initial = await authState.keys.getAppStateSyncVersion(name)
|
||||||
// temp: verify it was encoded correctly
|
// temp: verify it was encoded correctly
|
||||||
const result = await decodePatches(name, [{ ...patch, version: { version: state.version }, }], initial, authState)
|
const result = await decodePatches(name, [{ ...patch, version: { version: state.version }, }], initial, authState.keys.getAppStateSyncKey)
|
||||||
|
|
||||||
const node: BinaryNode = {
|
const node: BinaryNode = {
|
||||||
tag: 'iq',
|
tag: 'iq',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Boom } from '@hapi/boom'
|
import { Boom } from '@hapi/boom'
|
||||||
import { aesDecrypt, hmacSign, aesEncrypt, hkdf } from "./crypto"
|
import { aesDecrypt, hmacSign, aesEncrypt, hkdf } from "./crypto"
|
||||||
import { AuthenticationState, WAPatchCreate, ChatMutation, WAPatchName, LTHashState, ChatModification } from "../Types"
|
import { AuthenticationState, WAPatchCreate, ChatMutation, WAPatchName, LTHashState, ChatModification, SignalKeyStore } from "../Types"
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { LT_HASH_ANTI_TAMPERING } from './lt-hash'
|
import { LT_HASH_ANTI_TAMPERING } from './lt-hash'
|
||||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary'
|
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary'
|
||||||
@@ -165,7 +165,7 @@ export const encodeSyncdPatch = async(
|
|||||||
export const decodeSyncdPatch = async(
|
export const decodeSyncdPatch = async(
|
||||||
msg: proto.ISyncdPatch,
|
msg: proto.ISyncdPatch,
|
||||||
name: WAPatchName,
|
name: WAPatchName,
|
||||||
{keys}: AuthenticationState,
|
getAppStateSyncKey: SignalKeyStore['getAppStateSyncKey'],
|
||||||
validateMacs: boolean = true
|
validateMacs: boolean = true
|
||||||
) => {
|
) => {
|
||||||
const keyCache: { [_: string]: ReturnType<typeof mutationKeys> } = { }
|
const keyCache: { [_: string]: ReturnType<typeof mutationKeys> } = { }
|
||||||
@@ -173,7 +173,7 @@ export const decodeSyncdPatch = async(
|
|||||||
const base64Key = Buffer.from(keyId!).toString('base64')
|
const base64Key = Buffer.from(keyId!).toString('base64')
|
||||||
let key = keyCache[base64Key]
|
let key = keyCache[base64Key]
|
||||||
if(!key) {
|
if(!key) {
|
||||||
const keyEnc = await keys.getAppStateSyncKey(base64Key)
|
const keyEnc = await getAppStateSyncKey(base64Key)
|
||||||
if(!keyEnc) {
|
if(!keyEnc) {
|
||||||
throw new Boom(`failed to find key "${base64Key}" to decode mutation`, { statusCode: 500, data: msg })
|
throw new Boom(`failed to find key "${base64Key}" to decode mutation`, { statusCode: 500, data: msg })
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ export const decodePatches = async(
|
|||||||
name: WAPatchName,
|
name: WAPatchName,
|
||||||
syncds: proto.ISyncdPatch[],
|
syncds: proto.ISyncdPatch[],
|
||||||
initial: LTHashState,
|
initial: LTHashState,
|
||||||
auth: AuthenticationState,
|
getAppStateSyncKey: SignalKeyStore['getAppStateSyncKey'],
|
||||||
validateMacs: boolean = true
|
validateMacs: boolean = true
|
||||||
) => {
|
) => {
|
||||||
const successfulMutations: ChatMutation[] = []
|
const successfulMutations: ChatMutation[] = []
|
||||||
@@ -325,7 +325,7 @@ export const decodePatches = async(
|
|||||||
|
|
||||||
if(validateMacs) {
|
if(validateMacs) {
|
||||||
const base64Key = Buffer.from(keyId!.id!).toString('base64')
|
const base64Key = Buffer.from(keyId!.id!).toString('base64')
|
||||||
const keyEnc = await auth.keys.getAppStateSyncKey(base64Key)
|
const keyEnc = await getAppStateSyncKey(base64Key)
|
||||||
if(!keyEnc) {
|
if(!keyEnc) {
|
||||||
throw new Boom(`failed to find key "${base64Key}" to decode mutation`, { statusCode: 500 })
|
throw new Boom(`failed to find key "${base64Key}" to decode mutation`, { statusCode: 500 })
|
||||||
}
|
}
|
||||||
@@ -336,7 +336,7 @@ export const decodePatches = async(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodeResult = await decodeSyncdPatch(syncd, name, auth!, validateMacs)
|
const decodeResult = await decodeSyncdPatch(syncd, name, getAppStateSyncKey, validateMacs)
|
||||||
successfulMutations.push(...decodeResult.mutations)
|
successfulMutations.push(...decodeResult.mutations)
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user