-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Auth.ts
113 lines (96 loc) · 3.07 KB
/
Auth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import type { proto } from '../../WAProto'
import { RegistrationOptions } from '../Socket/registration'
import type { Contact } from './Contact'
import type { MinimalMessage } from './Message'
export type KeyPair = { public: Uint8Array, private: Uint8Array }
export type SignedKeyPair = {
keyPair: KeyPair
signature: Uint8Array
keyId: number
timestampS?: number
}
export type ProtocolAddress = {
name: string // jid
deviceId: number
}
export type SignalIdentity = {
identifier: ProtocolAddress
identifierKey: Uint8Array
}
export type LTHashState = {
version: number
hash: Buffer
indexValueMap: {
[indexMacBase64: string]: { valueMac: Uint8Array | Buffer }
}
}
export type SignalCreds = {
readonly signedIdentityKey: KeyPair
readonly signedPreKey: SignedKeyPair
readonly registrationId: number
}
export type AccountSettings = {
/** unarchive chats when a new message is received */
unarchiveChats: boolean
/** the default mode to start new conversations with */
defaultDisappearingMode?: Pick<proto.IConversation, 'ephemeralExpiration' | 'ephemeralSettingTimestamp'>
}
export type AuthenticationCreds = SignalCreds & {
readonly noiseKey: KeyPair
readonly pairingEphemeralKeyPair: KeyPair
advSecretKey: string
me?: Contact
account?: proto.IADVSignedDeviceIdentity
signalIdentities?: SignalIdentity[]
myAppStateKeyId?: string
firstUnuploadedPreKeyId: number
nextPreKeyId: number
lastAccountSyncTimestamp?: number
platform?: string
processedHistoryMessages: MinimalMessage[]
/** number of times history & app state has been synced */
accountSyncCounter: number
accountSettings: AccountSettings
// mobile creds
deviceId: string
phoneId: string
identityId: Buffer
registered: boolean
backupToken: Buffer
registration: RegistrationOptions
pairingCode: string | undefined
lastPropHash: string | undefined
routingInfo: Buffer | undefined
}
export type SignalDataTypeMap = {
'pre-key': KeyPair
'session': Uint8Array
'sender-key': Uint8Array
'sender-key-memory': { [jid: string]: boolean }
'app-state-sync-key': proto.Message.IAppStateSyncKeyData
'app-state-sync-version': LTHashState
}
export type SignalDataSet = { [T in keyof SignalDataTypeMap]?: { [id: string]: SignalDataTypeMap[T] | null } }
type Awaitable<T> = T | Promise<T>
export type SignalKeyStore = {
get<T extends keyof SignalDataTypeMap>(type: T, ids: string[]): Awaitable<{ [id: string]: SignalDataTypeMap[T] }>
set(data: SignalDataSet): Awaitable<void>
/** clear all the data in the store */
clear?(): Awaitable<void>
}
export type SignalKeyStoreWithTransaction = SignalKeyStore & {
isInTransaction: () => boolean
transaction<T>(exec: () => Promise<T>): Promise<T>
}
export type TransactionCapabilityOptions = {
maxCommitRetries: number
delayBetweenTriesMs: number
}
export type SignalAuthState = {
creds: SignalCreds
keys: SignalKeyStore | SignalKeyStoreWithTransaction
}
export type AuthenticationState = {
creds: AuthenticationCreds
keys: SignalKeyStore
}