@vex-chat/libvex 1.0.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README.md +103 -41
  2. package/dist/Client.d.ts +449 -554
  3. package/dist/Client.d.ts.map +1 -0
  4. package/dist/Client.js +1542 -1484
  5. package/dist/Client.js.map +1 -1
  6. package/dist/Storage.d.ts +111 -0
  7. package/dist/Storage.d.ts.map +1 -0
  8. package/dist/Storage.js +2 -0
  9. package/dist/Storage.js.map +1 -0
  10. package/dist/__tests__/harness/memory-storage.d.ts +29 -27
  11. package/dist/__tests__/harness/memory-storage.d.ts.map +1 -0
  12. package/dist/__tests__/harness/memory-storage.js +120 -109
  13. package/dist/__tests__/harness/memory-storage.js.map +1 -1
  14. package/dist/codec.d.ts +44 -0
  15. package/dist/codec.d.ts.map +1 -0
  16. package/dist/codec.js +51 -0
  17. package/dist/codec.js.map +1 -0
  18. package/dist/codecs.d.ts +201 -0
  19. package/dist/codecs.d.ts.map +1 -0
  20. package/dist/codecs.js +67 -0
  21. package/dist/codecs.js.map +1 -0
  22. package/dist/index.d.ts +7 -5
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/keystore/memory.d.ts +5 -4
  27. package/dist/keystore/memory.d.ts.map +1 -0
  28. package/dist/keystore/memory.js +9 -7
  29. package/dist/keystore/memory.js.map +1 -1
  30. package/dist/keystore/node.d.ts +6 -5
  31. package/dist/keystore/node.d.ts.map +1 -0
  32. package/dist/keystore/node.js +38 -19
  33. package/dist/keystore/node.js.map +1 -1
  34. package/dist/preset/common.d.ts +9 -0
  35. package/dist/preset/common.d.ts.map +1 -0
  36. package/dist/preset/common.js +2 -0
  37. package/dist/preset/common.js.map +1 -0
  38. package/dist/preset/node.d.ts +3 -5
  39. package/dist/preset/node.d.ts.map +1 -0
  40. package/dist/preset/node.js +5 -7
  41. package/dist/preset/node.js.map +1 -1
  42. package/dist/preset/test.d.ts +4 -4
  43. package/dist/preset/test.d.ts.map +1 -0
  44. package/dist/preset/test.js +8 -10
  45. package/dist/preset/test.js.map +1 -1
  46. package/dist/storage/node.d.ts +4 -3
  47. package/dist/storage/node.d.ts.map +1 -0
  48. package/dist/storage/node.js +4 -4
  49. package/dist/storage/node.js.map +1 -1
  50. package/dist/storage/schema.d.ts +55 -57
  51. package/dist/storage/schema.d.ts.map +1 -0
  52. package/dist/storage/sqlite.d.ts +33 -28
  53. package/dist/storage/sqlite.d.ts.map +1 -0
  54. package/dist/storage/sqlite.js +330 -290
  55. package/dist/storage/sqlite.js.map +1 -1
  56. package/dist/transport/types.d.ts +23 -16
  57. package/dist/transport/types.d.ts.map +1 -0
  58. package/dist/transport/websocket.d.ts +26 -0
  59. package/dist/transport/websocket.d.ts.map +1 -0
  60. package/dist/transport/websocket.js +83 -0
  61. package/dist/transport/websocket.js.map +1 -0
  62. package/dist/types/crypto.d.ts +35 -0
  63. package/dist/types/crypto.d.ts.map +1 -0
  64. package/dist/types/crypto.js +9 -0
  65. package/dist/types/crypto.js.map +1 -0
  66. package/dist/types/identity.d.ts +17 -0
  67. package/dist/types/identity.d.ts.map +1 -0
  68. package/dist/types/identity.js +6 -0
  69. package/dist/types/identity.js.map +1 -0
  70. package/dist/types/index.d.ts +3 -0
  71. package/dist/types/index.d.ts.map +1 -0
  72. package/dist/types/index.js +2 -0
  73. package/dist/types/index.js.map +1 -0
  74. package/dist/utils/capitalize.d.ts +1 -0
  75. package/dist/utils/capitalize.d.ts.map +1 -0
  76. package/dist/utils/createLogger.d.ts +1 -0
  77. package/dist/utils/createLogger.d.ts.map +1 -0
  78. package/dist/utils/createLogger.js +4 -11
  79. package/dist/utils/createLogger.js.map +1 -1
  80. package/dist/utils/formatBytes.d.ts +1 -0
  81. package/dist/utils/formatBytes.d.ts.map +1 -0
  82. package/dist/utils/formatBytes.js +3 -1
  83. package/dist/utils/formatBytes.js.map +1 -1
  84. package/dist/utils/sqlSessionToCrypto.d.ts +4 -2
  85. package/dist/utils/sqlSessionToCrypto.d.ts.map +1 -0
  86. package/dist/utils/sqlSessionToCrypto.js +5 -5
  87. package/dist/utils/sqlSessionToCrypto.js.map +1 -1
  88. package/dist/utils/uint8uuid.d.ts +1 -4
  89. package/dist/utils/uint8uuid.d.ts.map +1 -0
  90. package/dist/utils/uint8uuid.js +1 -7
  91. package/dist/utils/uint8uuid.js.map +1 -1
  92. package/package.json +58 -87
  93. package/src/Client.ts +3304 -0
  94. package/{dist/IStorage.d.ts → src/Storage.ts} +70 -62
  95. package/src/__tests__/codec.test.ts +251 -0
  96. package/src/__tests__/ghost.png +0 -0
  97. package/src/__tests__/harness/fixtures.ts +22 -0
  98. package/src/__tests__/harness/memory-storage.ts +254 -0
  99. package/src/__tests__/harness/platform-transports.ts +17 -0
  100. package/src/__tests__/harness/poison-node-imports.ts +108 -0
  101. package/src/__tests__/harness/shared-suite.ts +446 -0
  102. package/src/__tests__/platform-browser.test.ts +19 -0
  103. package/src/__tests__/platform-node.test.ts +10 -0
  104. package/src/__tests__/triggered.png +0 -0
  105. package/src/codec.ts +68 -0
  106. package/src/codecs.ts +101 -0
  107. package/src/index.ts +33 -0
  108. package/src/keystore/memory.ts +30 -0
  109. package/src/keystore/node.ts +91 -0
  110. package/src/preset/common.ts +13 -0
  111. package/src/preset/node.ts +34 -0
  112. package/src/preset/test.ts +37 -0
  113. package/src/storage/node.ts +33 -0
  114. package/src/storage/schema.ts +94 -0
  115. package/src/storage/sqlite.ts +676 -0
  116. package/src/transport/types.ts +29 -0
  117. package/src/transport/websocket.ts +106 -0
  118. package/src/types/crypto.ts +39 -0
  119. package/src/types/identity.ts +18 -0
  120. package/src/types/index.ts +9 -0
  121. package/src/utils/capitalize.ts +6 -0
  122. package/src/utils/createLogger.ts +37 -0
  123. package/src/utils/formatBytes.ts +15 -0
  124. package/src/utils/sqlSessionToCrypto.ts +16 -0
  125. package/src/utils/uint8uuid.ts +7 -0
  126. package/dist/IStorage.js +0 -2
  127. package/dist/IStorage.js.map +0 -1
  128. package/dist/keystore/types.d.ts +0 -4
  129. package/dist/keystore/types.js +0 -2
  130. package/dist/keystore/types.js.map +0 -1
  131. package/dist/preset/expo.d.ts +0 -2
  132. package/dist/preset/expo.js +0 -37
  133. package/dist/preset/expo.js.map +0 -1
  134. package/dist/preset/tauri.d.ts +0 -2
  135. package/dist/preset/tauri.js +0 -35
  136. package/dist/preset/tauri.js.map +0 -1
  137. package/dist/preset/types.d.ts +0 -13
  138. package/dist/preset/types.js +0 -2
  139. package/dist/preset/types.js.map +0 -1
  140. package/dist/storage/expo.d.ts +0 -3
  141. package/dist/storage/expo.js +0 -18
  142. package/dist/storage/expo.js.map +0 -1
  143. package/dist/storage/tauri.d.ts +0 -3
  144. package/dist/storage/tauri.js +0 -21
  145. package/dist/storage/tauri.js.map +0 -1
  146. package/dist/transport/browser.d.ts +0 -17
  147. package/dist/transport/browser.js +0 -56
  148. package/dist/transport/browser.js.map +0 -1
  149. package/dist/utils/constants.d.ts +0 -8
  150. package/dist/utils/constants.js +0 -9
  151. package/dist/utils/constants.js.map +0 -1
package/dist/Client.d.ts CHANGED
@@ -1,39 +1,9 @@
1
- import type { IChannel, IDevice, IEmoji, IFileResponse, IFileSQL, IInvite, IPermission, IServer, ISessionSQL } from "@vex-chat/types";
2
- import { AxiosError } from "axios";
3
- import { EventEmitter } from "eventemitter3";
4
- import type { IClientAdapters } from "./transport/types.js";
5
- import type { IStorage } from "./IStorage.js";
1
+ import type { Storage } from "./Storage.js";
2
+ import type { Logger } from "./transport/types.js";
3
+ import type { Channel, Device, Emoji, FileResponse, FileSQL, Invite, Permission, Server, SessionSQL } from "@vex-chat/types";
4
+ import { type AxiosError } from "axios";
6
5
  /**
7
- * IMessage is a chat message.
8
- */
9
- export interface IMessage {
10
- /** Hex-encoded nonce used for message encryption. */
11
- nonce: string;
12
- /** Globally unique message identifier. */
13
- mailID: string;
14
- /** Sender device ID. */
15
- sender: string;
16
- /** Recipient device ID. */
17
- recipient: string;
18
- /** Plaintext message content (or empty string when decryption failed). */
19
- message: string;
20
- /** Whether this message was received or sent by the current client. */
21
- direction: "incoming" | "outgoing";
22
- /** Time the message was created/received. */
23
- timestamp: Date;
24
- /** Whether payload decryption succeeded. */
25
- decrypted: boolean;
26
- /** Channel ID for group messages; `null` for direct messages. */
27
- group: string | null;
28
- /** `true` when this message was forwarded to another owned device. */
29
- forward: boolean;
30
- /** User ID of the original author. */
31
- authorID: string;
32
- /** User ID of the intended reader. */
33
- readerID: string;
34
- }
35
- /**
36
- * IPermission is a permission to a resource.
6
+ * Permission is a permission to a resource.
37
7
  *
38
8
  * Common fields:
39
9
  * - `permissionID`: unique permission row ID
@@ -42,16 +12,21 @@ export interface IMessage {
42
12
  * - `resourceType`: type string for the resource
43
13
  * - `powerLevel`: authorization level
44
14
  */
45
- export type { IPermission } from "@vex-chat/types";
15
+ export type { Permission } from "@vex-chat/types";
46
16
  /**
47
- * IKeys are a pair of ed25519 public and private keys,
48
- * encoded as hex strings.
17
+ * @ignore
49
18
  */
50
- export interface IKeys {
51
- /** Public Ed25519 key as hex. */
52
- public: string;
53
- /** Secret Ed25519 key as hex. Store securely. */
54
- private: string;
19
+ export interface Channels {
20
+ /** Creates a channel in a server. */
21
+ create: (name: string, serverID: string) => Promise<Channel>;
22
+ /** Deletes a channel. */
23
+ delete: (channelID: string) => Promise<void>;
24
+ /** Lists channels in a server. */
25
+ retrieve: (serverID: string) => Promise<Channel[]>;
26
+ /** Gets one channel by ID. */
27
+ retrieveByID: (channelID: string) => Promise<Channel | null>;
28
+ /** Lists users currently visible in a channel. */
29
+ userList: (channelID: string) => Promise<User[]>;
55
30
  }
56
31
  /**
57
32
  * Device record associated with a user account.
@@ -64,99 +39,95 @@ export interface IKeys {
64
39
  * - `lastLogin`: last login timestamp string
65
40
  * - `deleted`: soft-delete flag
66
41
  */
67
- export type { IDevice } from "@vex-chat/types";
42
+ export type { Device } from "@vex-chat/types";
68
43
  /**
69
- * IUser is a single user on the vex platform.
70
- *
71
- * This is intentionally a censored user shape for client use, containing:
72
- * - `userID`
73
- * - `username`
74
- * - `lastSeen`
44
+ * ClientOptions are the options you can pass into the client.
75
45
  */
76
- export interface IUser {
77
- /** Last-seen timestamp (unix epoch milliseconds). */
78
- lastSeen: number;
79
- /** User identifier. */
80
- userID: string;
81
- /** Public username. */
82
- username: string;
46
+ export interface ClientOptions {
47
+ /** Folder path where the sqlite file is created. */
48
+ dbFolder?: string;
49
+ /** Logging level for storage/database logs. */
50
+ dbLogLevel?: "debug" | "error" | "http" | "info" | "silly" | "verbose" | "warn";
51
+ /** Platform label for device registration (e.g. "ios", "macos", "linux"). */
52
+ deviceName?: string;
53
+ /** API host without protocol. Defaults to `api.vex.wtf`. */
54
+ host?: string;
55
+ /** Use sqlite in-memory mode (`:memory:`) instead of a file. */
56
+ inMemoryDb?: boolean;
57
+ /** Logger implementation. When omitted, defaults to winston (Node.js). */
58
+ logger?: Logger;
59
+ /** Logging level for client runtime logs. */
60
+ logLevel?: "debug" | "error" | "http" | "info" | "silly" | "verbose" | "warn";
61
+ /** Whether local message history should be persisted by default storage. */
62
+ saveHistory?: boolean;
63
+ /** Use `http/ws` instead of `https/wss`. Intended for local/dev environments. */
64
+ unsafeHttp?: boolean;
83
65
  }
84
66
  /**
85
- * ISession is an end to end encryption session with another peer.
86
- *
87
- * Key fields include:
88
- * - `sessionID`
89
- * - `userID`
90
- * - `deviceID`
91
- * - `mode` (`initiator` or `receiver`)
92
- * - `publicKey` and `fingerprint`
93
- * - `lastUsed`
94
- * - `verified`
95
- *
96
- * @example
97
- * ```ts
98
- * const session: ISession = {
99
- * sessionID: "f6e4fbd0-7222-4ba8-b799-c227faf5c8de",
100
- * userID: "f34f5e37-616f-4d3a-a437-e7c27c31cb73",
101
- * deviceID: "9b0f3f46-06ad-4bc4-8adf-4de10e13cb9c",
102
- * mode: "initiator",
103
- * SK: "7d9afde6683ecc2d1f55e34e1b95de9d4042dfd4e8cda7fdf3f0f7e02fef8f9a",
104
- * publicKey: "d58f39dc4bcfe4e8ef022f34e8b6f4f6ddc9c4acee30c0d58f126aa5db3f61b0",
105
- * fingerprint: "05294b9aa81d0fd0ca12a4b585f531d8ef1f53f8ea3d0200a0df3f9c44a7d8b1",
106
- * lastUsed: new Date(),
107
- * verified: false,
108
- * };
109
- * ```
67
+ * @ignore
110
68
  */
111
- export interface ISession extends ISessionSQL {
69
+ export interface Devices {
70
+ /** Deletes one of the account's devices (except the currently active one). */
71
+ delete: (deviceID: string) => Promise<void>;
72
+ /** Registers the current key material as a new device. */
73
+ register: () => Promise<Device | null>;
74
+ /** Fetches one device by ID. */
75
+ retrieve: (deviceIdentifier: string) => Promise<Device | null>;
112
76
  }
113
77
  /**
114
- * IChannel is a chat channel on a server.
78
+ * Channel is a chat channel on a server.
115
79
  *
116
80
  * Common fields:
117
81
  * - `channelID`
118
82
  * - `serverID`
119
83
  * - `name`
120
84
  */
121
- export type { IChannel } from "@vex-chat/types";
85
+ export type { Channel } from "@vex-chat/types";
122
86
  /**
123
- * IServer is a single chat server.
87
+ * Server is a single chat server.
124
88
  *
125
89
  * Common fields:
126
90
  * - `serverID`
127
91
  * - `name`
128
92
  * - `icon` (optional URL/data)
129
93
  */
130
- export type { IServer } from "@vex-chat/types";
94
+ export type { Server } from "@vex-chat/types";
131
95
  /**
132
- * IFile is an uploaded encrypted file.
133
- *
134
- * Common fields:
135
- * - `fileID`: file identifier
136
- * - `owner`: owner device/user ID
137
- * - `nonce`: file encryption nonce (hex)
138
- *
139
- * @example
140
- * ```ts
141
- * const file: IFile = {
142
- * fileID: "bb1c3fd1-4928-48ab-9d09-3ea0972fbd9d",
143
- * owner: "9b0f3f46-06ad-4bc4-8adf-4de10e13cb9c",
144
- * nonce: "aa6c8d42f3fdd032a1e9fced4be379582d26ce8f69822d64",
145
- * };
146
- * ```
96
+ * @ignore
147
97
  */
148
- export interface IFile extends IFileSQL {
98
+ export interface Emojis {
99
+ /** Uploads a custom emoji to a server. */
100
+ create: (emoji: Uint8Array, name: string, serverID: string) => Promise<Emoji | null>;
101
+ /** Fetches one emoji's metadata by ID. */
102
+ retrieve: (emojiID: string) => Promise<Emoji | null>;
103
+ /** Lists emojis available on a server. */
104
+ retrieveList: (serverID: string) => Promise<Emoji[]>;
149
105
  }
150
106
  /**
151
- * IFileRes is a server response to a file retrieval request.
107
+ * Progress payload emitted by the `fileProgress` event.
108
+ */
109
+ export interface FileProgress {
110
+ /** Whether this progress event is for upload or download. */
111
+ direction: "download" | "upload";
112
+ /** Bytes transferred so far. */
113
+ loaded: number;
114
+ /** Integer percentage from `0` to `100`. */
115
+ progress: number;
116
+ /** Correlation token (file ID, nonce, or label depending on operation). */
117
+ token: string;
118
+ /** Total expected bytes when available, otherwise `0`. */
119
+ total: number;
120
+ }
121
+ /**
122
+ * FileRes is a server response to a file retrieval request.
152
123
  *
153
124
  * Structure:
154
- * - `details`: metadata (`IFile`)
125
+ * - `details`: metadata (`VexFile`)
155
126
  * - `data`: decrypted binary bytes
156
127
  *
157
128
  * @example
158
129
  * ```ts
159
- * const response: IFileRes = {
130
+ * const response: FileRes = {
160
131
  * details: {
161
132
  * fileID: "bb1c3fd1-4928-48ab-9d09-3ea0972fbd9d",
162
133
  * owner: "9b0f3f46-06ad-4bc4-8adf-4de10e13cb9c",
@@ -166,312 +137,211 @@ export interface IFile extends IFileSQL {
166
137
  * };
167
138
  * ```
168
139
  */
169
- export interface IFileRes extends IFileResponse {
140
+ export type FileRes = FileResponse;
141
+ /**
142
+ * @ignore
143
+ */
144
+ export interface Files {
145
+ /** Uploads and encrypts a file. */
146
+ create: (file: Uint8Array) => Promise<[FileSQL, string]>;
147
+ /** Downloads and decrypts a file using a file ID and key. */
148
+ retrieve: (fileID: string, key: string) => Promise<FileResponse | null>;
170
149
  }
171
150
  /**
172
151
  * @ignore
173
152
  */
174
- export interface IMe {
175
- /** Returns the currently authenticated user profile. */
176
- user: () => IUser;
153
+ export interface Invites {
154
+ /** Creates an invite for a server and duration. */
155
+ create: (serverID: string, duration: string) => Promise<Invite>;
156
+ /** Redeems an invite and returns the created permission grant. */
157
+ redeem: (inviteID: string) => Promise<Permission>;
158
+ /** Lists active invites for a server. */
159
+ retrieve: (serverID: string) => Promise<Invite[]>;
160
+ }
161
+ /**
162
+ * Keys are a pair of ed25519 public and private keys,
163
+ * encoded as hex strings.
164
+ */
165
+ export interface Keys {
166
+ /** Secret Ed25519 key as hex. Store securely. */
167
+ private: string;
168
+ /** Public Ed25519 key as hex. */
169
+ public: string;
170
+ }
171
+ /**
172
+ * @ignore
173
+ */
174
+ export interface Me {
177
175
  /** Returns metadata for the currently authenticated device. */
178
- device: () => IDevice;
176
+ device: () => Device;
179
177
  /** Uploads and sets a new avatar image for the current user. */
180
178
  setAvatar: (avatar: Uint8Array) => Promise<void>;
179
+ /** Returns the currently authenticated user profile. */
180
+ user: () => User;
181
181
  }
182
182
  /**
183
- * @ignore
183
+ * Message is a chat message.
184
184
  */
185
- export interface IUsers {
186
- /**
187
- * Looks up a user by user ID, username, or signing key.
188
- */
189
- retrieve: (userID: string) => Promise<[IUser | null, AxiosError | null]>;
190
- /** Returns users with whom the current device has active sessions. */
191
- familiars: () => Promise<IUser[]>;
185
+ export interface Message {
186
+ /** User ID of the original author. */
187
+ authorID: string;
188
+ /** Whether payload decryption succeeded. */
189
+ decrypted: boolean;
190
+ /** Whether this message was received or sent by the current client. */
191
+ direction: "incoming" | "outgoing";
192
+ /** `true` when this message was forwarded to another owned device. */
193
+ forward: boolean;
194
+ /** Channel ID for group messages; `null` for direct messages. */
195
+ group: null | string;
196
+ /** Globally unique message identifier. */
197
+ mailID: string;
198
+ /** Plaintext message content (or empty string when decryption failed). */
199
+ message: string;
200
+ /** Hex-encoded nonce used for message encryption. */
201
+ nonce: string;
202
+ /** User ID of the intended reader. */
203
+ readerID: string;
204
+ /** Recipient device ID. */
205
+ recipient: string;
206
+ /** Sender device ID. */
207
+ sender: string;
208
+ /** Time the message was created/received. */
209
+ timestamp: string;
192
210
  }
193
211
  /**
194
212
  * @ignore
195
213
  */
196
- export interface IMessages {
197
- /** Sends an encrypted direct message to one user. */
198
- send: (userID: string, message: string) => Promise<void>;
214
+ export interface Messages {
215
+ /** Deletes local history for a user/channel. */
216
+ delete: (userOrChannelID: string) => Promise<void>;
199
217
  /** Sends an encrypted message to all members of a channel. */
200
218
  group: (channelID: string, message: string) => Promise<void>;
201
- /** Returns local direct-message history with one user. */
202
- retrieve: (userID: string) => Promise<IMessage[]>;
203
- /** Returns local group-message history for one channel. */
204
- retrieveGroup: (channelID: string) => Promise<IMessage[]>;
205
- /** Deletes local history for a user/channel, optionally older than a duration. */
206
- delete: (userOrChannelID: string, duration?: string) => Promise<void>;
207
219
  /** Deletes all locally stored message history. */
208
220
  purge: () => Promise<void>;
221
+ /** Returns local direct-message history with one user. */
222
+ retrieve: (userID: string) => Promise<Message[]>;
223
+ /** Returns local group-message history for one channel. */
224
+ retrieveGroup: (channelID: string) => Promise<Message[]>;
225
+ /** Sends an encrypted direct message to one user. */
226
+ send: (userID: string, message: string) => Promise<void>;
209
227
  }
210
228
  /**
211
229
  * @ignore
212
230
  */
213
- export interface IServers {
214
- /** Lists servers available to the authenticated user. */
215
- retrieve: () => Promise<IServer[]>;
216
- /** Gets one server by ID. */
217
- retrieveByID: (serverID: string) => Promise<IServer | null>;
218
- /** Creates a server. */
219
- create: (name: string) => Promise<IServer>;
220
- /** Deletes a server. */
221
- delete: (serverID: string) => Promise<void>;
222
- /** Leaves a server by removing the user's permission entry. */
223
- leave: (serverID: string) => Promise<void>;
224
- }
225
- /**
226
- * @ignore
227
- */
228
- export interface IModeration {
231
+ export interface Moderation {
232
+ /** Returns all permission entries for a server. */
233
+ fetchPermissionList: (serverID: string) => Promise<Permission[]>;
229
234
  /** Removes a user from a server by revoking their server permission(s). */
230
235
  kick: (userID: string, serverID: string) => Promise<void>;
231
- /** Returns all permission entries for a server. */
232
- fetchPermissionList: (serverID: string) => Promise<IPermission[]>;
233
236
  }
234
237
  /**
235
238
  * @ignore
236
239
  */
237
- export interface IPermissions {
238
- /** Lists permissions granted to the authenticated user. */
239
- retrieve: () => Promise<IPermission[]>;
240
+ export interface Permissions {
240
241
  /** Deletes one permission grant. */
241
242
  delete: (permissionID: string) => Promise<void>;
243
+ /** Lists permissions granted to the authenticated user. */
244
+ retrieve: () => Promise<Permission[]>;
242
245
  }
243
246
  /**
244
247
  * @ignore
245
248
  */
246
- export interface IInvites {
247
- /** Redeems an invite and returns the created permission grant. */
248
- redeem: (inviteID: string) => Promise<IPermission>;
249
- /** Creates an invite for a server and duration. */
250
- create: (serverID: string, duration: string) => Promise<IInvite>;
251
- /** Lists active invites for a server. */
252
- retrieve: (serverID: string) => Promise<IInvite[]>;
249
+ export interface Servers {
250
+ /** Creates a server. */
251
+ create: (name: string) => Promise<Server>;
252
+ /** Deletes a server. */
253
+ delete: (serverID: string) => Promise<void>;
254
+ /** Leaves a server by removing the user's permission entry. */
255
+ leave: (serverID: string) => Promise<void>;
256
+ /** Lists servers available to the authenticated user. */
257
+ retrieve: () => Promise<Server[]>;
258
+ /** Gets one server by ID. */
259
+ retrieveByID: (serverID: string) => Promise<null | Server>;
253
260
  }
254
261
  /**
255
- * @ignore
262
+ * Session is an end to end encryption session with another peer.
263
+ *
264
+ * Key fields include:
265
+ * - `sessionID`
266
+ * - `userID`
267
+ * - `deviceID`
268
+ * - `mode` (`initiator` or `receiver`)
269
+ * - `publicKey` and `fingerprint`
270
+ * - `lastUsed`
271
+ * - `verified`
272
+ *
273
+ * @example
274
+ * ```ts
275
+ * const session: Session = {
276
+ * sessionID: "f6e4fbd0-7222-4ba8-b799-c227faf5c8de",
277
+ * userID: "f34f5e37-616f-4d3a-a437-e7c27c31cb73",
278
+ * deviceID: "9b0f3f46-06ad-4bc4-8adf-4de10e13cb9c",
279
+ * mode: "initiator",
280
+ * SK: "7d9afde6683ecc2d1f55e34e1b95de9d4042dfd4e8cda7fdf3f0f7e02fef8f9a",
281
+ * publicKey: "d58f39dc4bcfe4e8ef022f34e8b6f4f6ddc9c4acee30c0d58f126aa5db3f61b0",
282
+ * fingerprint: "05294b9aa81d0fd0ca12a4b585f531d8ef1f53f8ea3d0200a0df3f9c44a7d8b1",
283
+ * lastUsed: new Date(),
284
+ * verified: false,
285
+ * };
286
+ * ```
256
287
  */
257
- export interface IChannels {
258
- /** Lists channels in a server. */
259
- retrieve: (serverID: string) => Promise<IChannel[]>;
260
- /** Gets one channel by ID. */
261
- retrieveByID: (channelID: string) => Promise<IChannel | null>;
262
- /** Creates a channel in a server. */
263
- create: (name: string, serverID: string) => Promise<IChannel>;
264
- /** Deletes a channel. */
265
- delete: (channelID: string) => Promise<void>;
266
- /** Lists users currently visible in a channel. */
267
- userList: (channelID: string) => Promise<IUser[]>;
268
- }
288
+ export type Session = SessionSQL;
269
289
  /**
270
290
  * @ignore
271
291
  */
272
- export interface ISessions {
273
- /** Returns all locally known sessions. */
274
- retrieve: () => Promise<ISessionSQL[]>;
275
- /** Builds a human-readable verification phrase from a session fingerprint. */
276
- verify: (session: ISessionSQL) => string;
292
+ export interface Sessions {
277
293
  /** Marks one session as verification-confirmed. */
278
294
  markVerified: (fingerprint: string) => Promise<void>;
295
+ /** Returns all locally known sessions. */
296
+ retrieve: () => Promise<SessionSQL[]>;
297
+ /** Builds a human-readable verification phrase from a session fingerprint. */
298
+ verify: (session: SessionSQL) => string;
279
299
  }
280
300
  /**
281
- * @ignore
282
- */
283
- export interface IDevices {
284
- /** Fetches one device by ID. */
285
- retrieve: (deviceIdentifier: string) => Promise<IDevice | null>;
286
- /** Registers the current key material as a new device. */
287
- register: () => Promise<IDevice | null>;
288
- /** Deletes one of the account's devices (except the currently active one). */
289
- delete: (deviceID: string) => Promise<void>;
290
- }
291
- /**
292
- * @ignore
301
+ * User is a single user on the vex platform.
302
+ *
303
+ * This is intentionally a censored user shape for client use, containing:
304
+ * - `userID`
305
+ * - `username`
306
+ * - `lastSeen`
293
307
  */
294
- export interface IFiles {
295
- /** Uploads and encrypts a file. */
296
- create: (file: Uint8Array) => Promise<[IFileSQL, string]>;
297
- /** Downloads and decrypts a file using a file ID and key. */
298
- retrieve: (fileID: string, key: string) => Promise<IFileResponse | null>;
308
+ export interface User {
309
+ /** Last-seen timestamp (ISO 8601 string). */
310
+ lastSeen: string;
311
+ /** User identifier. */
312
+ userID: string;
313
+ /** Public username. */
314
+ username: string;
299
315
  }
300
316
  /**
301
317
  * @ignore
302
318
  */
303
- export interface IEmojis {
304
- /** Uploads a custom emoji to a server. */
305
- create: (emoji: Uint8Array, name: string, serverID: string) => Promise<IEmoji | null>;
306
- /** Lists emojis available on a server. */
307
- retrieveList: (serverID: string) => Promise<IEmoji[]>;
308
- /** Fetches one emoji's metadata by ID. */
309
- retrieve: (emojiID: string) => Promise<IEmoji | null>;
310
- }
311
- /**
312
- * Progress payload emitted by the `fileProgress` event.
313
- */
314
- export interface IFileProgress {
315
- /** Correlation token (file ID, nonce, or label depending on operation). */
316
- token: string;
317
- /** Whether this progress event is for upload or download. */
318
- direction: "upload" | "download";
319
- /** Integer percentage from `0` to `100`. */
320
- progress: number;
321
- /** Bytes transferred so far. */
322
- loaded: number;
323
- /** Total expected bytes when available, otherwise `0`. */
324
- total: number;
325
- }
326
- /**
327
- * IClientOptions are the options you can pass into the client.
328
- */
329
- export interface IClientOptions {
330
- /** Logging level for client runtime logs. */
331
- logLevel?: "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
332
- /** API host without protocol. Defaults to `api.vex.wtf`. */
333
- host?: string;
334
- /** Folder path where the sqlite file is created. */
335
- dbFolder?: string;
336
- /** Use sqlite in-memory mode (`:memory:`) instead of a file. */
337
- inMemoryDb?: boolean;
338
- /** Logging level for storage/database logs. */
339
- dbLogLevel?: "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
340
- /** Use `http/ws` instead of `https/wss`. Intended for local/dev environments. */
341
- unsafeHttp?: boolean;
342
- /** Whether local message history should be persisted by default storage. */
343
- saveHistory?: boolean;
344
- /** Platform-specific adapters (WebSocket + Logger). When omitted, defaults to Node.js ws. */
345
- adapters?: IClientAdapters;
346
- }
347
- export declare interface Client {
348
- /**
349
- * This is emitted for file progress events.
350
- *
351
- * Example:
352
- *
353
- * ```ts
354
- * client.on("ready", () => {
355
- * await client.register()
356
- * });
357
- * ```
358
- *
359
- * @event
360
- */
361
- on(event: "fileProgress", callback: (progress: IFileProgress) => void): this;
362
- /**
363
- * This is emitted whenever the keyring is done initializing after an init()
364
- * call. You must wait to login or register until after this event.
365
- *
366
- * Example:
367
- *
368
- * ```ts
369
- * client.on("ready", () => {
370
- * await client.register()
371
- * });
372
- * ```
373
- *
374
- * @event
375
- */
376
- on(event: "ready", callback: () => void): this;
377
- /**
378
- * Emitted before the first inbox fetch/decrypt cycle after connect.
379
- *
380
- * Use this to show temporary loading UI while historical messages are
381
- * decrypted from server payloads.
382
- *
383
- * @event
384
- */
385
- on(event: "decryptingMail", callback: () => void): this;
386
- /**
387
- * This is emitted when you are connected to the chat.
388
- *
389
- * Example:
390
- *
391
- * ```ts
392
- * client.on("connected", (user) => {
393
- * // do something
394
- * });
395
- * ```
396
- *
397
- * @event
398
- */
399
- on(event: "connected", callback: () => void): this;
400
- /**
401
- * This is emitted for every sent and received message.
402
- *
403
- * Example:
404
- *
405
- * ```ts
406
- *
407
- * client.on("message", (msg: IMessage) => {
408
- * console.log(message);
409
- * });
410
- * ```
411
- * @event
412
- */
413
- on(event: "message", callback: (message: IMessage) => void): this;
414
- /**
415
- * This is emitted when the user is granted a new permission.
416
- *
417
- * Example:
418
- *
419
- * ```ts
420
- *
421
- * client.on("permission", (perm: IPermission) => {
422
- * console.log(perm);
423
- * });
424
- * ```
425
- * @event
426
- */
427
- on(event: "permission", callback: (permission: IPermission) => void): this;
428
- /**
429
- * This is emitted for a new encryption session being created with
430
- * a specific user.
431
- *
432
- * Example:
433
- *
434
- * ```ts
435
- *
436
- * client.on("session", (session: ISession, user: IUser) => {
437
- * console.log(session);
438
- * console.log(user);
439
- * });
440
- * ```
441
- * @event
442
- */
443
- on(event: "session", callback: (session: ISession, user: IUser) => void): this;
444
- /**
445
- * This is emitted whenever the connection is closed. You must discard the client
446
- * and connect again with a fresh one.
447
- *
448
- * Example:
449
- * ```ts
450
- *
451
- * client.on("disconnect", () => {
452
- * // do something
453
- * });
454
- * ```
455
- * @event
456
- */
457
- on(event: "disconnect", callback: () => void): this;
319
+ export interface Users {
320
+ /** Returns users with whom the current device has active sessions. */
321
+ familiars: () => Promise<User[]>;
458
322
  /**
459
- * This is emitted whenever the close() event is called and completed successfully.
460
- * Note this is not fired for an unintentional disconnect, see the disconnect event.
461
- *
462
- * Example:
463
- *
464
- * ```ts
465
- *
466
- * client.on("closed", () => {
467
- * process.exit(0);
468
- * });
469
- * ```
470
- *
471
- * @event
323
+ * Looks up a user by user ID, username, or signing key.
472
324
  */
473
- on(event: "closed", callback: () => void): this;
325
+ retrieve: (userID: string) => Promise<[null | User, AxiosError | null]>;
474
326
  }
327
+ /**
328
+ * VexFile is an uploaded encrypted file.
329
+ *
330
+ * Common fields:
331
+ * - `fileID`: file identifier
332
+ * - `owner`: owner device/user ID
333
+ * - `nonce`: file encryption nonce (hex)
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * const file: VexFile = {
338
+ * fileID: "bb1c3fd1-4928-48ab-9d09-3ea0972fbd9d",
339
+ * owner: "9b0f3f46-06ad-4bc4-8adf-4de10e13cb9c",
340
+ * nonce: "aa6c8d42f3fdd032a1e9fced4be379582d26ce8f69822d64",
341
+ * };
342
+ * ```
343
+ */
344
+ export type VexFile = FileSQL;
475
345
  /**
476
346
  * Client provides an interface for you to use a vex chat server and
477
347
  * send end to end encrypted messages to other users.
@@ -484,16 +354,11 @@ export declare interface Client {
484
354
  * // generate a secret key to use, save this somewhere permanent
485
355
  * const privateKey = Client.generateSecretKey();
486
356
  *
487
- * const client = new Client(privateKey);
357
+ * const client = await Client.create(privateKey);
488
358
  *
489
- * // the ready event is emitted when init() is finished.
490
- * // you must wait until this event fires to perform
491
- * // registration or login.
492
- * client.on("ready", async () => {
493
- * // you must register once before you can log in
494
- * await client.register(Client.randomUsername());
495
- * await client.login();
496
- * })
359
+ * // you must register once before you can log in
360
+ * await client.register(Client.randomUsername());
361
+ * await client.login();
497
362
  *
498
363
  * // The authed event fires when login() successfully completes
499
364
  * // and the server indicates you are authorized. You must wait to
@@ -510,65 +375,47 @@ export declare interface Client {
510
375
  * client.on("message", (message) => {
511
376
  * console.log("message:", message);
512
377
  * })
513
- *
514
- * // you must call init() to initialize the keyring and
515
- * // start the client.
516
- * client.init();
517
378
  * }
518
379
  *
519
380
  * main();
520
381
  * ```
521
382
  */
522
- export declare class Client extends EventEmitter {
523
- /**
524
- * Encrypts a secret key with a password.
525
- *
526
- * Pass-through utility from `@vex-chat/crypto`.
527
- */
528
- static encryptKeyData: (password: string, keyToSave: string, iterationOverride?: number) => Uint8Array;
529
- /**
530
- * Decrypts a secret key from encrypted data produced by encryptKeyData().
531
- *
532
- * Pass-through utility from `@vex-chat/crypto`.
533
- */
534
- static decryptKeyData: (keyData: Uint8Array, password: string) => string;
535
- /**
536
- * Creates and initializes a client in one step.
537
- *
538
- * @param privateKey Optional hex secret key. When omitted, a fresh key is generated.
539
- * @param options Runtime options.
540
- * @param storage Optional custom storage backend implementing `IStorage`.
541
- *
542
- * @example
543
- * ```ts
544
- * const client = await Client.create(privateKey, { host: "api.vex.wtf" });
545
- * ```
546
- */
547
- static create: (privateKey?: string, options?: IClientOptions, storage?: IStorage) => Promise<Client>;
383
+ /**
384
+ * Event signatures emitted by {@link Client}.
385
+ */
386
+ interface ClientEvents {
387
+ closed: () => void;
388
+ connected: () => void;
389
+ decryptingMail: () => void;
390
+ disconnect: () => void;
391
+ fileProgress: (progress: FileProgress) => void;
392
+ message: (message: Message) => void;
393
+ permission: (permission: Permission) => void;
394
+ ready: () => void;
395
+ session: (session: Session, user: User) => void;
396
+ }
397
+ export declare class Client {
548
398
  /**
549
- * Generates an ed25519 secret key as a hex string.
399
+ * Decrypts a secret key from encrypted data produced by encryptKeyData().
550
400
  *
551
- * @returns - A secret key to use for the client. Save it permanently somewhere safe.
401
+ * Pass-through utility from `@vex-chat/crypto`.
552
402
  */
553
- static generateSecretKey(): string;
403
+ static decryptKeyData: (keyData: Uint8Array, password: string) => string;
554
404
  /**
555
- * Generates a random username using bip39.
405
+ * Encrypts a secret key with a password.
556
406
  *
557
- * @returns - The username.
407
+ * Pass-through utility from `@vex-chat/crypto`.
558
408
  */
559
- static randomUsername(): string;
560
- private static getMnemonic;
561
- private static deserializeExtra;
409
+ static encryptKeyData: (password: string, keyToSave: string, iterationOverride?: number) => Uint8Array;
410
+ private static readonly NOT_FOUND_TTL;
562
411
  /**
563
- * User operations.
564
- *
565
- * @example
566
- * ```ts
567
- * const [user] = await client.users.retrieve("alice");
568
- * const familiarUsers = await client.users.familiars();
569
- * ```
412
+ * Channel operations.
413
+ */
414
+ channels: Channels;
415
+ /**
416
+ * Device management methods.
570
417
  */
571
- users: IUsers;
418
+ devices: Devices;
572
419
  /**
573
420
  * Emoji operations.
574
421
  *
@@ -578,29 +425,26 @@ export declare class Client extends EventEmitter {
578
425
  * const list = await client.emoji.retrieveList(serverID);
579
426
  * ```
580
427
  */
581
- emoji: IEmojis;
582
- /**
583
- * Helpers for information/actions related to the currently authenticated account.
584
- */
585
- me: IMe;
586
- /**
587
- * Device management methods.
588
- */
589
- devices: IDevices;
428
+ emoji: Emojis;
590
429
  /** File upload/download methods. */
591
- files: IFiles;
430
+ files: Files;
592
431
  /**
593
- * Permission-management methods for the current user.
432
+ * This is true if the client has ever been initialized. You can only initialize
433
+ * a client once.
594
434
  */
595
- permissions: IPermissions;
435
+ hasInit: boolean;
596
436
  /**
597
- * Server moderation helper methods.
437
+ * This is true if the client has ever logged in before. You can only login a client once.
598
438
  */
599
- moderation: IModeration;
439
+ hasLoggedIn: boolean;
600
440
  /**
601
441
  * Invite-management methods.
602
442
  */
603
- invites: IInvites;
443
+ invites: Invites;
444
+ /**
445
+ * Helpers for information/actions related to the currently authenticated account.
446
+ */
447
+ me: Me;
604
448
  /**
605
449
  * Message operations (direct and group).
606
450
  *
@@ -611,11 +455,16 @@ export declare class Client extends EventEmitter {
611
455
  * const dmHistory = await client.messages.retrieve(userID);
612
456
  * ```
613
457
  */
614
- messages: IMessages;
458
+ messages: Messages;
615
459
  /**
616
- * Encryption-session helpers.
460
+ * Server moderation helper methods.
617
461
  */
618
- sessions: ISessions;
462
+ moderation: Moderation;
463
+ /**
464
+ * Permission-management methods for the current user.
465
+ */
466
+ permissions: Permissions;
467
+ sending: Map<string, Device>;
619
468
  /**
620
469
  * Server operations.
621
470
  *
@@ -625,107 +474,137 @@ export declare class Client extends EventEmitter {
625
474
  * const created = await client.servers.create("Team Space");
626
475
  * ```
627
476
  */
628
- servers: IServers;
629
- /**
630
- * Channel operations.
631
- */
632
- channels: IChannels;
477
+ servers: Servers;
633
478
  /**
634
- * This is true if the client has ever been initialized. You can only initialize
635
- * a client once.
479
+ * Encryption-session helpers.
636
480
  */
637
- hasInit: boolean;
481
+ sessions: Sessions;
638
482
  /**
639
- * This is true if the client has ever logged in before. You can only login a client once.
483
+ * User operations.
484
+ *
485
+ * @example
486
+ * ```ts
487
+ * const [user] = await client.users.retrieve("alice");
488
+ * const familiarUsers = await client.users.familiars();
489
+ * ```
640
490
  */
641
- hasLoggedIn: boolean;
642
- sending: Record<string, IDevice>;
643
- private database;
644
- private dbPath;
645
- private conn;
646
- private host;
647
- private adapters;
648
- private firstMailFetch;
649
- private signKeys;
650
- private idKeys;
651
- private xKeyRing?;
652
- private user?;
491
+ users: Users;
492
+ private readonly database;
493
+ private readonly dbPath;
653
494
  private device?;
654
- private userRecords;
655
495
  private deviceRecords;
656
- private sessionRecords;
657
- private isAlive;
658
- private reading;
496
+ private readonly emitter;
659
497
  private fetchingMail;
660
- private cookies;
661
- private log;
662
- private pingInterval;
663
- private mailInterval?;
498
+ private firstMailFetch;
499
+ private readonly forwarded;
500
+ private readonly host;
501
+ private readonly http;
502
+ private readonly idKeys;
503
+ private isAlive;
504
+ private readonly log;
505
+ private readonly mailInterval?;
664
506
  private manuallyClosing;
507
+ /** Negative cache for user lookups that returned 404. TTL = 30 minutes. */
508
+ private readonly notFoundUsers;
509
+ private readonly options?;
510
+ private pingInterval;
511
+ private readonly prefixes;
512
+ private reading;
513
+ private sessionRecords;
514
+ private readonly signKeys;
515
+ private socket;
665
516
  private token;
666
- private forwarded;
667
- private prefixes;
517
+ private user?;
518
+ private userRecords;
519
+ private xKeyRing?;
668
520
  private constructor();
669
521
  /**
670
- * Returns the current HTTP API origin with protocol.
522
+ * Creates and initializes a client in one step.
523
+ *
524
+ * @param privateKey Optional hex secret key. When omitted, a fresh key is generated.
525
+ * @param options Runtime options.
526
+ * @param storage Optional custom storage backend implementing `Storage`.
671
527
  *
672
528
  * @example
673
529
  * ```ts
674
- * console.log(client.getHost()); // "https://api.vex.wtf"
530
+ * const client = await Client.create(privateKey, { host: "api.vex.wtf" });
675
531
  * ```
676
532
  */
677
- getHost(): string;
533
+ static create: (privateKey?: string, options?: ClientOptions, storage?: Storage) => Promise<Client>;
678
534
  /**
679
- * Manually closes the client. Emits the closed event on successful shutdown.
535
+ * Generates an ed25519 secret key as a hex string.
536
+ *
537
+ * @returns - A secret key to use for the client. Save it permanently somewhere safe.
538
+ */
539
+ static generateSecretKey(): string;
540
+ /**
541
+ * Generates a random username using bip39.
542
+ *
543
+ * @returns - The username.
680
544
  */
545
+ static randomUsername(): string;
546
+ private static deserializeExtra;
547
+ private static getMnemonic;
681
548
  close(muteEvent?: boolean): Promise<void>;
682
549
  /**
683
- * Gets the hex string representations of the public and private keys.
550
+ * Connects your device to the chat. You must have a valid Bearer token.
551
+ * You can check whoami() to see before calling connect().
684
552
  */
685
- getKeys(): IKeys;
553
+ connect(): Promise<void>;
686
554
  /**
687
- * Authenticates with username/password and stores the auth token/cookie.
688
- *
689
- * @param username Account username.
690
- * @param password Account password.
691
- * @returns `null` on success, or the thrown error object on failure.
555
+ * Manually closes the client. Emits the closed event on successful shutdown.
556
+ */
557
+ /**
558
+ * Delete all local data — message history, encryption sessions, and prekeys.
559
+ * Closes the client afterward. Credentials (keychain) must be cleared by the consumer.
560
+ */
561
+ deleteAllData(): Promise<void>;
562
+ /**
563
+ * Returns the current HTTP API origin with protocol.
692
564
  *
693
565
  * @example
694
566
  * ```ts
695
- * const err = await client.login("alice", "correct horse battery staple");
696
- * if (err) console.error(err);
567
+ * console.log(client.getHost()); // "https://api.vex.wtf"
697
568
  * ```
698
569
  */
699
- login(username: string, password: string): Promise<Error | null>;
570
+ getHost(): string;
700
571
  /**
701
- * Returns the authorization cookie details. Throws if you don't have a
702
- * valid authorization cookie.
572
+ * Gets the hex string representations of the public and private keys.
703
573
  */
574
+ getKeys(): Keys;
704
575
  /**
705
- * Returns details about the currently authenticated session.
576
+ * Authenticates with username/password and stores the Bearer auth token.
706
577
  *
707
- * @returns The authenticated user, token expiry, and active token.
578
+ * @param username Account username.
579
+ * @param password Account password.
580
+ * @returns `{ ok: true }` on success, `{ ok: false, error }` on failure.
708
581
  *
709
582
  * @example
710
583
  * ```ts
711
- * const auth = await client.whoami();
712
- * console.log(auth.user.username, new Date(auth.exp));
584
+ * const result = await client.login("alice", "correct horse battery staple");
585
+ * if (!result.ok) console.error(result.error);
713
586
  * ```
714
587
  */
715
- whoami(): Promise<{
716
- user: IUser;
717
- exp: number;
718
- token: string;
588
+ login(username: string, password: string): Promise<{
589
+ error?: string;
590
+ ok: boolean;
719
591
  }>;
720
592
  /**
721
- * Logs out the current authenticated session from the server.
593
+ * Authenticates using the device's Ed25519 signing key.
594
+ * No password needed — proves possession of the private key via
595
+ * challenge-response. Issues a short-lived (1-hour) JWT.
596
+ *
597
+ * Used by auto-login when stored credentials have a deviceKey
598
+ * but no valid session.
722
599
  */
723
- logout(): Promise<void>;
600
+ loginWithDeviceKey(deviceID?: string): Promise<Error | null>;
724
601
  /**
725
- * Connects your device to the chat. You must have an valid authorization cookie.
726
- * You can check whoami() to see before calling connect().
602
+ * Logs out the current authenticated session from the server.
727
603
  */
728
- connect(): Promise<void>;
604
+ logout(): Promise<void>;
605
+ off<E extends keyof ClientEvents>(event: E, fn?: ClientEvents[E], context?: unknown): this;
606
+ on<E extends keyof ClientEvents>(event: E, fn: ClientEvents[E], context?: unknown): this;
607
+ once<E extends keyof ClientEvents>(event: E, fn: ClientEvents[E], context?: unknown): this;
729
608
  /**
730
609
  * Registers a new account on the server.
731
610
  * @param username The username to register. Must be unique.
@@ -734,91 +613,107 @@ export declare class Client extends EventEmitter {
734
613
  *
735
614
  * @example [user, err] = await client.register("MyUsername");
736
615
  */
737
- register(username: string, password: string): Promise<[IUser | null, Error | null]>;
616
+ register(username: string, password: string): Promise<[null | User, Error | null]>;
617
+ removeAllListeners(event?: keyof ClientEvents): this;
738
618
  /**
739
619
  * Returns a compact `<username><deviceID>` debug label.
740
620
  */
741
621
  toString(): string;
742
- private redeemInvite;
743
- private retrieveInvites;
622
+ /**
623
+ * Returns details about the currently authenticated session.
624
+ *
625
+ * @returns The authenticated user, token expiry, and active token.
626
+ *
627
+ * @example
628
+ * ```ts
629
+ * const auth = await client.whoami();
630
+ * console.log(auth.user.username, new Date(auth.exp));
631
+ * ```
632
+ */
633
+ whoami(): Promise<{
634
+ exp: number;
635
+ token: string;
636
+ user: User;
637
+ }>;
638
+ private censorPreKey;
639
+ private createChannel;
640
+ private createFile;
744
641
  private createInvite;
745
- private retrieveEmojiList;
746
- private retrieveEmojiByID;
747
- private leaveServer;
748
- private kickUser;
749
- private addCookie;
750
- private getCookies;
751
- private uploadEmoji;
752
- private retrieveOrCreateDevice;
753
- private registerDevice;
754
- private getToken;
755
- private uploadAvatar;
642
+ private createPreKey;
643
+ private createServer;
644
+ private createSession;
645
+ private deleteChannel;
646
+ private deleteDevice;
647
+ private deleteHistory;
648
+ private deletePermission;
649
+ private deleteServer;
756
650
  /**
757
651
  * Gets a list of permissions for a server.
758
652
  *
759
- * @returns - The list of IPermissions objects.
653
+ * @returns - The list of Permissions objects.
760
654
  */
761
655
  private fetchPermissionList;
656
+ private fetchUser;
657
+ private forward;
658
+ private getChannelByID;
659
+ private getChannelList;
660
+ private getDevice;
661
+ private getDeviceByID;
662
+ private getFamiliars;
663
+ private getGroupHistory;
664
+ private getMail;
665
+ private getMessageHistory;
666
+ private getMultiUserDeviceList;
667
+ private getOTKCount;
762
668
  /**
763
669
  * Gets all permissions for the logged in user.
764
670
  *
765
- * @returns - The list of IPermissions objects.
671
+ * @returns - The list of Permissions objects.
766
672
  */
767
673
  private getPermissions;
768
- private deletePermission;
769
- private retrieveFile;
770
- private deleteServer;
674
+ private getServerByID;
675
+ private getServerList;
676
+ private getSessionByPubkey;
677
+ private getSessionList;
678
+ private getToken;
679
+ private getUser;
680
+ private getUserDeviceList;
681
+ private getUserList;
682
+ private handleNotify;
771
683
  /**
772
684
  * Initializes the keyring. This must be called before anything else.
773
685
  */
774
686
  private init;
775
- private deleteChannel;
776
- private createFile;
777
- private getUserList;
687
+ private initSocket;
688
+ private kickUser;
689
+ private leaveServer;
778
690
  private markSessionVerified;
779
- private getGroupHistory;
780
- private deleteHistory;
691
+ private negotiateOTK;
692
+ private newEphemeralKeys;
693
+ private ping;
694
+ private pong;
695
+ private populateKeyRing;
696
+ private postAuth;
781
697
  private purgeHistory;
782
- private getMessageHistory;
783
- private sendMessage;
698
+ private readMail;
699
+ private redeemInvite;
700
+ private registerDevice;
701
+ private respond;
702
+ private retrieveEmojiByID;
703
+ private retrieveEmojiList;
704
+ private retrieveFile;
705
+ private retrieveInvites;
706
+ private retrieveKeyBundle;
707
+ private retrieveOrCreateDevice;
708
+ private send;
784
709
  private sendGroupMessage;
785
- private createServer;
786
- private forward;
787
710
  private sendMail;
788
- private getSessionList;
789
- private getServerList;
790
- private createChannel;
791
- private getDeviceByID;
792
- private deleteDevice;
793
- private getMultiUserDeviceList;
794
- private getUserDeviceList;
795
- private getServerByID;
796
- private getChannelByID;
797
- private getChannelList;
798
- private getUser;
799
- private getDevice;
800
- private setUser;
801
- private retrieveUserDBEntry;
802
- private getFamiliars;
803
- private createSession;
711
+ private sendMessage;
804
712
  private sendReceipt;
805
- private getSessionByPubkey;
806
- private readMail;
807
- private newEphemeralKeys;
808
- private createPreKey;
809
- private handleNotify;
810
- private populateKeyRing;
811
- private initSocket;
812
713
  private setAlive;
813
- private postAuth;
814
- private getMail;
815
- private send;
816
- private retrieveKeyBundle;
817
- private getOTKCount;
714
+ private setUser;
818
715
  private submitOTK;
819
- private negotiateOTK;
820
- private respond;
821
- private pong;
822
- private ping;
823
- private censorPreKey;
716
+ private uploadAvatar;
717
+ private uploadEmoji;
824
718
  }
719
+ //# sourceMappingURL=Client.d.ts.map