diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index e4f63ff..78981e3 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -211,7 +211,7 @@ export const makeChatsSocket = (config: SocketConfig) => { const name = key as WAPatchName // only process if there are syncd patches 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) @@ -387,7 +387,7 @@ export const makeChatsSocket = (config: SocketConfig) => { ) const initial = await authState.keys.getAppStateSyncVersion(name) // 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 = { tag: 'iq', diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index e06393b..ab8cd76 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -1,6 +1,6 @@ import { Boom } from '@hapi/boom' 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 { LT_HASH_ANTI_TAMPERING } from './lt-hash' import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary' @@ -165,7 +165,7 @@ export const encodeSyncdPatch = async( export const decodeSyncdPatch = async( msg: proto.ISyncdPatch, name: WAPatchName, - {keys}: AuthenticationState, + getAppStateSyncKey: SignalKeyStore['getAppStateSyncKey'], validateMacs: boolean = true ) => { const keyCache: { [_: string]: ReturnType } = { } @@ -173,7 +173,7 @@ export const decodeSyncdPatch = async( const base64Key = Buffer.from(keyId!).toString('base64') let key = keyCache[base64Key] if(!key) { - const keyEnc = await keys.getAppStateSyncKey(base64Key) + const keyEnc = await getAppStateSyncKey(base64Key) if(!keyEnc) { 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, syncds: proto.ISyncdPatch[], initial: LTHashState, - auth: AuthenticationState, + getAppStateSyncKey: SignalKeyStore['getAppStateSyncKey'], validateMacs: boolean = true ) => { const successfulMutations: ChatMutation[] = [] @@ -325,7 +325,7 @@ export const decodePatches = async( if(validateMacs) { const base64Key = Buffer.from(keyId!.id!).toString('base64') - const keyEnc = await auth.keys.getAppStateSyncKey(base64Key) + const keyEnc = await getAppStateSyncKey(base64Key) if(!keyEnc) { 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) } return {