mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
nicer patch API
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
import { encodeSyncdPatch, decodePatches, extractSyncdPatches } from "../Utils/chat-utils";
|
import { encodeSyncdPatch, decodePatches, extractSyncdPatches } from "../Utils/chat-utils";
|
||||||
import { SocketConfig, WAPresence, PresenceData, Chat, ChatModification, WAMediaUpload, ChatMutation, WAPatchName, LTHashState } from "../Types";
|
import { SocketConfig, WAPresence, PresenceData, Chat, WAPatchCreate, WAMediaUpload, ChatMutation, WAPatchName, LTHashState } from "../Types";
|
||||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, S_WHATSAPP_NET } from "../WABinary";
|
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidNormalizedUser, S_WHATSAPP_NET } from "../WABinary";
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { generateProfilePicture, toNumber } from "../Utils";
|
import { generateProfilePicture, toNumber } from "../Utils";
|
||||||
import { randomBytes } from "crypto";
|
|
||||||
import { makeMessagesRecvSocket } from "./messages-recv";
|
import { makeMessagesRecvSocket } from "./messages-recv";
|
||||||
|
|
||||||
export const makeChatsSocket = (config: SocketConfig) => {
|
export const makeChatsSocket = (config: SocketConfig) => {
|
||||||
@@ -327,18 +326,12 @@ export const makeChatsSocket = (config: SocketConfig) => {
|
|||||||
ev.emit('chats.update', updates)
|
ev.emit('chats.update', updates)
|
||||||
}
|
}
|
||||||
|
|
||||||
const appPatch = async(
|
const appPatch = async(patchCreate: WAPatchCreate) => {
|
||||||
syncAction: proto.ISyncActionValue,
|
const name = patchCreate.type
|
||||||
index: [string, string],
|
|
||||||
name: WAPatchName,
|
|
||||||
operation: proto.SyncdMutation.SyncdMutationSyncdOperation.SET,
|
|
||||||
) => {
|
|
||||||
await resyncState(name, false)
|
await resyncState(name, false)
|
||||||
const { patch, state } = await encodeSyncdPatch(
|
const { patch, state } = await encodeSyncdPatch(
|
||||||
syncAction,
|
patchCreate,
|
||||||
index,
|
|
||||||
name,
|
|
||||||
operation,
|
|
||||||
authState,
|
authState,
|
||||||
)
|
)
|
||||||
const initial = await authState.keys.getAppStateSyncVersion(name)
|
const initial = await authState.keys.getAppStateSyncVersion(name)
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ export interface PresenceData {
|
|||||||
|
|
||||||
export type ChatMutation = { action: proto.ISyncActionValue, index: [string, string], indexMac: Uint8Array, valueMac: Uint8Array, operation: number }
|
export type ChatMutation = { action: proto.ISyncActionValue, index: [string, string], indexMac: Uint8Array, valueMac: Uint8Array, operation: number }
|
||||||
|
|
||||||
|
export type WAPatchCreate = {
|
||||||
|
syncAction: proto.ISyncActionValue
|
||||||
|
index: [string, string]
|
||||||
|
type: WAPatchName
|
||||||
|
apiVersion: number
|
||||||
|
}
|
||||||
|
|
||||||
export type Chat = Omit<proto.IConversation, 'messages'> & {
|
export type Chat = Omit<proto.IConversation, 'messages'> & {
|
||||||
/** unix timestamp of date when mute ends, if applicable */
|
/** unix timestamp of date when mute ends, if applicable */
|
||||||
mute?: number | null
|
mute?: number | null
|
||||||
|
|||||||
@@ -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, ChatModification, ChatMutation, WAPatchName, LTHashState } from "../Types"
|
import { AuthenticationState, WAPatchCreate, ChatMutation, WAPatchName, LTHashState } from "../Types"
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { LT_HASH_ANTI_TAMPERING } from '../WABinary/LTHash'
|
import { LT_HASH_ANTI_TAMPERING } from '../WABinary/LTHash'
|
||||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary'
|
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren } from '../WABinary'
|
||||||
@@ -92,10 +92,7 @@ const generatePatchMac = (snapshotMac: Uint8Array, valueMacs: Uint8Array[], vers
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const encodeSyncdPatch = async(
|
export const encodeSyncdPatch = async(
|
||||||
syncAction: proto.ISyncActionValue,
|
{ type, index, syncAction, apiVersion }: WAPatchCreate,
|
||||||
index: [string, string],
|
|
||||||
type: WAPatchName,
|
|
||||||
operation: proto.SyncdMutation.SyncdMutationSyncdOperation,
|
|
||||||
{ creds: { myAppStateKeyId }, keys }: AuthenticationState
|
{ creds: { myAppStateKeyId }, keys }: AuthenticationState
|
||||||
) => {
|
) => {
|
||||||
const key = !!myAppStateKeyId ? await keys.getAppStateSyncKey(myAppStateKeyId) : undefined
|
const key = !!myAppStateKeyId ? await keys.getAppStateSyncKey(myAppStateKeyId) : undefined
|
||||||
@@ -104,6 +101,8 @@ export const encodeSyncdPatch = async(
|
|||||||
}
|
}
|
||||||
const encKeyId = Buffer.from(myAppStateKeyId, 'base64')
|
const encKeyId = Buffer.from(myAppStateKeyId, 'base64')
|
||||||
|
|
||||||
|
const operation = proto.SyncdMutation.SyncdMutationSyncdOperation.SET
|
||||||
|
|
||||||
const state = { ...await keys.getAppStateSyncVersion(type) }
|
const state = { ...await keys.getAppStateSyncVersion(type) }
|
||||||
|
|
||||||
const indexBuffer = Buffer.from(JSON.stringify(index))
|
const indexBuffer = Buffer.from(JSON.stringify(index))
|
||||||
@@ -111,7 +110,7 @@ export const encodeSyncdPatch = async(
|
|||||||
index: indexBuffer,
|
index: indexBuffer,
|
||||||
value: syncAction,
|
value: syncAction,
|
||||||
padding: new Uint8Array(0),
|
padding: new Uint8Array(0),
|
||||||
version: 2
|
version: apiVersion
|
||||||
}).finish()
|
}).finish()
|
||||||
|
|
||||||
const keyValue = mutationKeys(key!.keyData!)
|
const keyValue = mutationKeys(key!.keyData!)
|
||||||
|
|||||||
Reference in New Issue
Block a user