feat: cleaner auth state management

1. removes the "auth-state.update" event since it was bloated and fairly unnecessary
2. adds "creds.update" event that only sends the updated properties of the auth credentials
3. ensure the auth creds are not mutated anywhere, but only with the "creds.update" event
4. Separates the signal credentials from the auth credentials (kinda in progress)
5. in memory key store requires a save function to let one know when to save the keys

!BREAKING_CHANGE
This commit is contained in:
Adhiraj Singh
2021-11-20 16:21:56 +05:30
parent c2c27a5dea
commit 3d0704a317
13 changed files with 229 additions and 201 deletions

View File

@@ -16,12 +16,16 @@ export type SignalIdentity = {
export type LTHashState = { version: number, hash: Buffer, mutations: ChatMutation[] }
export type AuthenticationCreds = {
noiseKey: KeyPair
signedIdentityKey: KeyPair
signedPreKey: SignedKeyPair
registrationId: number
advSecretKey: string
export type SignalCreds = {
readonly signedIdentityKey: KeyPair
readonly signedPreKey: SignedKeyPair
readonly registrationId: number
}
export type AuthenticationCreds = SignalCreds & {
readonly noiseKey: KeyPair
readonly advSecretKey: string
me?: Contact
account?: proto.IADVSignedDeviceIdentity
signalIdentities?: SignalIdentity[]
@@ -49,6 +53,11 @@ export type SignalKeyStore = {
setAppStateSyncVersion: (id: WAPatchName, item: LTHashState) => Awaitable<void>
}
export type SignalAuthState = {
creds: SignalCreds
keys: SignalKeyStore
}
export type AuthenticationState = {
creds: AuthenticationCreds
keys: SignalKeyStore

View File

@@ -11,7 +11,7 @@ import type { Logger } from "pino"
import type { URL } from "url"
import type NodeCache from 'node-cache'
import { AuthenticationState } from './Auth'
import { AuthenticationState, AuthenticationCreds } from './Auth'
import { Chat, PresenceData } from './Chat'
import { Contact } from './Contact'
import { ConnectionState } from './State'
@@ -96,8 +96,8 @@ export type CurveKeyPair = { private: Uint8Array; public: Uint8Array }
export type BaileysEventMap = {
/** connection state has been updated -- WS closed, opened, connecting etc. */
'connection.update': Partial<ConnectionState>
/** auth state updated -- some pre keys, or identity keys etc. */
'auth-state.update': AuthenticationState
/** credentials updated -- some metadata, keys or something */
'creds.update': Partial<AuthenticationCreds>
/** set chats (history sync), messages are reverse chronologically sorted */
'chats.set': { chats: Chat[], messages: WAMessage[] }
/** upsert chats */