@vex-chat/libvex 1.1.0 → 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 +440 -551
  3. package/dist/Client.d.ts.map +1 -0
  4. package/dist/Client.js +1566 -1502
  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 -8
  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 -11
  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 -54
  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 -291
  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 +3 -3
  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 -83
  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 -39
  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 -36
  136. package/dist/preset/tauri.js.map +0 -1
  137. package/dist/preset/types.d.ts +0 -14
  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,314 +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
- /** Platform label for device registration (e.g. "ios", "macos", "linux"). */
347
- deviceName?: string;
348
- }
349
- export declare interface Client {
350
- /**
351
- * This is emitted for file progress events.
352
- *
353
- * Example:
354
- *
355
- * ```ts
356
- * client.on("ready", () => {
357
- * await client.register()
358
- * });
359
- * ```
360
- *
361
- * @event
362
- */
363
- on(event: "fileProgress", callback: (progress: IFileProgress) => void): this;
364
- /**
365
- * This is emitted whenever the keyring is done initializing after an init()
366
- * call. You must wait to login or register until after this event.
367
- *
368
- * Example:
369
- *
370
- * ```ts
371
- * client.on("ready", () => {
372
- * await client.register()
373
- * });
374
- * ```
375
- *
376
- * @event
377
- */
378
- on(event: "ready", callback: () => void): this;
379
- /**
380
- * Emitted before the first inbox fetch/decrypt cycle after connect.
381
- *
382
- * Use this to show temporary loading UI while historical messages are
383
- * decrypted from server payloads.
384
- *
385
- * @event
386
- */
387
- on(event: "decryptingMail", callback: () => void): this;
388
- /**
389
- * This is emitted when you are connected to the chat.
390
- *
391
- * Example:
392
- *
393
- * ```ts
394
- * client.on("connected", (user) => {
395
- * // do something
396
- * });
397
- * ```
398
- *
399
- * @event
400
- */
401
- on(event: "connected", callback: () => void): this;
402
- /**
403
- * This is emitted for every sent and received message.
404
- *
405
- * Example:
406
- *
407
- * ```ts
408
- *
409
- * client.on("message", (msg: IMessage) => {
410
- * console.log(message);
411
- * });
412
- * ```
413
- * @event
414
- */
415
- on(event: "message", callback: (message: IMessage) => void): this;
416
- /**
417
- * This is emitted when the user is granted a new permission.
418
- *
419
- * Example:
420
- *
421
- * ```ts
422
- *
423
- * client.on("permission", (perm: IPermission) => {
424
- * console.log(perm);
425
- * });
426
- * ```
427
- * @event
428
- */
429
- on(event: "permission", callback: (permission: IPermission) => void): this;
430
- /**
431
- * This is emitted for a new encryption session being created with
432
- * a specific user.
433
- *
434
- * Example:
435
- *
436
- * ```ts
437
- *
438
- * client.on("session", (session: ISession, user: IUser) => {
439
- * console.log(session);
440
- * console.log(user);
441
- * });
442
- * ```
443
- * @event
444
- */
445
- on(event: "session", callback: (session: ISession, user: IUser) => void): this;
446
- /**
447
- * This is emitted whenever the connection is closed. You must discard the client
448
- * and connect again with a fresh one.
449
- *
450
- * Example:
451
- * ```ts
452
- *
453
- * client.on("disconnect", () => {
454
- * // do something
455
- * });
456
- * ```
457
- * @event
458
- */
459
- 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[]>;
460
322
  /**
461
- * This is emitted whenever the close() event is called and completed successfully.
462
- * Note this is not fired for an unintentional disconnect, see the disconnect event.
463
- *
464
- * Example:
465
- *
466
- * ```ts
467
- *
468
- * client.on("closed", () => {
469
- * process.exit(0);
470
- * });
471
- * ```
472
- *
473
- * @event
323
+ * Looks up a user by user ID, username, or signing key.
474
324
  */
475
- on(event: "closed", callback: () => void): this;
325
+ retrieve: (userID: string) => Promise<[null | User, AxiosError | null]>;
476
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;
477
345
  /**
478
346
  * Client provides an interface for you to use a vex chat server and
479
347
  * send end to end encrypted messages to other users.
@@ -486,16 +354,11 @@ export declare interface Client {
486
354
  * // generate a secret key to use, save this somewhere permanent
487
355
  * const privateKey = Client.generateSecretKey();
488
356
  *
489
- * const client = new Client(privateKey);
357
+ * const client = await Client.create(privateKey);
490
358
  *
491
- * // the ready event is emitted when init() is finished.
492
- * // you must wait until this event fires to perform
493
- * // registration or login.
494
- * client.on("ready", async () => {
495
- * // you must register once before you can log in
496
- * await client.register(Client.randomUsername());
497
- * await client.login();
498
- * })
359
+ * // you must register once before you can log in
360
+ * await client.register(Client.randomUsername());
361
+ * await client.login();
499
362
  *
500
363
  * // The authed event fires when login() successfully completes
501
364
  * // and the server indicates you are authorized. You must wait to
@@ -512,22 +375,26 @@ export declare interface Client {
512
375
  * client.on("message", (message) => {
513
376
  * console.log("message:", message);
514
377
  * })
515
- *
516
- * // you must call init() to initialize the keyring and
517
- * // start the client.
518
- * client.init();
519
378
  * }
520
379
  *
521
380
  * main();
522
381
  * ```
523
382
  */
524
- export declare class Client extends EventEmitter {
525
- /**
526
- * Encrypts a secret key with a password.
527
- *
528
- * Pass-through utility from `@vex-chat/crypto`.
529
- */
530
- static encryptKeyData: (password: string, keyToSave: string, iterationOverride?: number) => Uint8Array;
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 {
531
398
  /**
532
399
  * Decrypts a secret key from encrypted data produced by encryptKeyData().
533
400
  *
@@ -535,42 +402,20 @@ export declare class Client extends EventEmitter {
535
402
  */
536
403
  static decryptKeyData: (keyData: Uint8Array, password: string) => string;
537
404
  /**
538
- * Creates and initializes a client in one step.
539
- *
540
- * @param privateKey Optional hex secret key. When omitted, a fresh key is generated.
541
- * @param options Runtime options.
542
- * @param storage Optional custom storage backend implementing `IStorage`.
543
- *
544
- * @example
545
- * ```ts
546
- * const client = await Client.create(privateKey, { host: "api.vex.wtf" });
547
- * ```
548
- */
549
- static create: (privateKey?: string, options?: IClientOptions, storage?: IStorage) => Promise<Client>;
550
- /**
551
- * Generates an ed25519 secret key as a hex string.
405
+ * Encrypts a secret key with a password.
552
406
  *
553
- * @returns - A secret key to use for the client. Save it permanently somewhere safe.
407
+ * Pass-through utility from `@vex-chat/crypto`.
554
408
  */
555
- static generateSecretKey(): string;
409
+ static encryptKeyData: (password: string, keyToSave: string, iterationOverride?: number) => Uint8Array;
410
+ private static readonly NOT_FOUND_TTL;
556
411
  /**
557
- * Generates a random username using bip39.
558
- *
559
- * @returns - The username.
412
+ * Channel operations.
560
413
  */
561
- static randomUsername(): string;
562
- private static getMnemonic;
563
- private static deserializeExtra;
414
+ channels: Channels;
564
415
  /**
565
- * User operations.
566
- *
567
- * @example
568
- * ```ts
569
- * const [user] = await client.users.retrieve("alice");
570
- * const familiarUsers = await client.users.familiars();
571
- * ```
416
+ * Device management methods.
572
417
  */
573
- users: IUsers;
418
+ devices: Devices;
574
419
  /**
575
420
  * Emoji operations.
576
421
  *
@@ -580,29 +425,26 @@ export declare class Client extends EventEmitter {
580
425
  * const list = await client.emoji.retrieveList(serverID);
581
426
  * ```
582
427
  */
583
- emoji: IEmojis;
584
- /**
585
- * Helpers for information/actions related to the currently authenticated account.
586
- */
587
- me: IMe;
588
- /**
589
- * Device management methods.
590
- */
591
- devices: IDevices;
428
+ emoji: Emojis;
592
429
  /** File upload/download methods. */
593
- files: IFiles;
430
+ files: Files;
594
431
  /**
595
- * 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.
596
434
  */
597
- permissions: IPermissions;
435
+ hasInit: boolean;
598
436
  /**
599
- * Server moderation helper methods.
437
+ * This is true if the client has ever logged in before. You can only login a client once.
600
438
  */
601
- moderation: IModeration;
439
+ hasLoggedIn: boolean;
602
440
  /**
603
441
  * Invite-management methods.
604
442
  */
605
- invites: IInvites;
443
+ invites: Invites;
444
+ /**
445
+ * Helpers for information/actions related to the currently authenticated account.
446
+ */
447
+ me: Me;
606
448
  /**
607
449
  * Message operations (direct and group).
608
450
  *
@@ -613,11 +455,16 @@ export declare class Client extends EventEmitter {
613
455
  * const dmHistory = await client.messages.retrieve(userID);
614
456
  * ```
615
457
  */
616
- messages: IMessages;
458
+ messages: Messages;
617
459
  /**
618
- * Encryption-session helpers.
460
+ * Server moderation helper methods.
461
+ */
462
+ moderation: Moderation;
463
+ /**
464
+ * Permission-management methods for the current user.
619
465
  */
620
- sessions: ISessions;
466
+ permissions: Permissions;
467
+ sending: Map<string, Device>;
621
468
  /**
622
469
  * Server operations.
623
470
  *
@@ -627,79 +474,121 @@ export declare class Client extends EventEmitter {
627
474
  * const created = await client.servers.create("Team Space");
628
475
  * ```
629
476
  */
630
- servers: IServers;
631
- /**
632
- * Channel operations.
633
- */
634
- channels: IChannels;
477
+ servers: Servers;
635
478
  /**
636
- * This is true if the client has ever been initialized. You can only initialize
637
- * a client once.
479
+ * Encryption-session helpers.
638
480
  */
639
- hasInit: boolean;
481
+ sessions: Sessions;
640
482
  /**
641
- * 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
+ * ```
642
490
  */
643
- hasLoggedIn: boolean;
644
- sending: Record<string, IDevice>;
645
- private database;
646
- private dbPath;
647
- private conn;
648
- private host;
649
- private adapters;
650
- private firstMailFetch;
651
- private signKeys;
652
- private idKeys;
653
- private xKeyRing?;
654
- private user?;
491
+ users: Users;
492
+ private readonly database;
493
+ private readonly dbPath;
655
494
  private device?;
656
- private userRecords;
657
495
  private deviceRecords;
658
- private sessionRecords;
659
- private isAlive;
660
- private reading;
496
+ private readonly emitter;
661
497
  private fetchingMail;
662
- private ax;
663
- private log;
664
- private pingInterval;
665
- 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?;
666
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;
667
516
  private token;
668
- private forwarded;
669
- private prefixes;
670
- private options?;
517
+ private user?;
518
+ private userRecords;
519
+ private xKeyRing?;
671
520
  private constructor();
672
521
  /**
673
- * 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`.
674
527
  *
675
528
  * @example
676
529
  * ```ts
677
- * console.log(client.getHost()); // "https://api.vex.wtf"
530
+ * const client = await Client.create(privateKey, { host: "api.vex.wtf" });
678
531
  * ```
679
532
  */
680
- getHost(): string;
533
+ static create: (privateKey?: string, options?: ClientOptions, storage?: Storage) => Promise<Client>;
681
534
  /**
682
- * 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.
683
544
  */
545
+ static randomUsername(): string;
546
+ private static deserializeExtra;
547
+ private static getMnemonic;
684
548
  close(muteEvent?: boolean): Promise<void>;
549
+ /**
550
+ * Connects your device to the chat. You must have a valid Bearer token.
551
+ * You can check whoami() to see before calling connect().
552
+ */
553
+ connect(): Promise<void>;
554
+ /**
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.
564
+ *
565
+ * @example
566
+ * ```ts
567
+ * console.log(client.getHost()); // "https://api.vex.wtf"
568
+ * ```
569
+ */
570
+ getHost(): string;
685
571
  /**
686
572
  * Gets the hex string representations of the public and private keys.
687
573
  */
688
- getKeys(): IKeys;
574
+ getKeys(): Keys;
689
575
  /**
690
576
  * Authenticates with username/password and stores the Bearer auth token.
691
577
  *
692
578
  * @param username Account username.
693
579
  * @param password Account password.
694
- * @returns `null` on success, or the thrown error object on failure.
580
+ * @returns `{ ok: true }` on success, `{ ok: false, error }` on failure.
695
581
  *
696
582
  * @example
697
583
  * ```ts
698
- * const err = await client.login("alice", "correct horse battery staple");
699
- * if (err) console.error(err);
584
+ * const result = await client.login("alice", "correct horse battery staple");
585
+ * if (!result.ok) console.error(result.error);
700
586
  * ```
701
587
  */
702
- login(username: string, password: string): Promise<Error | null>;
588
+ login(username: string, password: string): Promise<{
589
+ error?: string;
590
+ ok: boolean;
591
+ }>;
703
592
  /**
704
593
  * Authenticates using the device's Ed25519 signing key.
705
594
  * No password needed — proves possession of the private key via
@@ -709,31 +598,13 @@ export declare class Client extends EventEmitter {
709
598
  * but no valid session.
710
599
  */
711
600
  loginWithDeviceKey(deviceID?: string): Promise<Error | null>;
712
- /**
713
- * Returns details about the currently authenticated session.
714
- *
715
- * @returns The authenticated user, token expiry, and active token.
716
- *
717
- * @example
718
- * ```ts
719
- * const auth = await client.whoami();
720
- * console.log(auth.user.username, new Date(auth.exp));
721
- * ```
722
- */
723
- whoami(): Promise<{
724
- user: IUser;
725
- exp: number;
726
- token: string;
727
- }>;
728
601
  /**
729
602
  * Logs out the current authenticated session from the server.
730
603
  */
731
604
  logout(): Promise<void>;
732
- /**
733
- * Connects your device to the chat. You must have a valid Bearer token.
734
- * You can check whoami() to see before calling connect().
735
- */
736
- connect(): 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;
737
608
  /**
738
609
  * Registers a new account on the server.
739
610
  * @param username The username to register. Must be unique.
@@ -742,89 +613,107 @@ export declare class Client extends EventEmitter {
742
613
  *
743
614
  * @example [user, err] = await client.register("MyUsername");
744
615
  */
745
- 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;
746
618
  /**
747
619
  * Returns a compact `<username><deviceID>` debug label.
748
620
  */
749
621
  toString(): string;
750
- private redeemInvite;
751
- 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;
752
641
  private createInvite;
753
- private retrieveEmojiList;
754
- private retrieveEmojiByID;
755
- private leaveServer;
756
- private kickUser;
757
- private uploadEmoji;
758
- private retrieveOrCreateDevice;
759
- private registerDevice;
760
- private getToken;
761
- 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;
762
650
  /**
763
651
  * Gets a list of permissions for a server.
764
652
  *
765
- * @returns - The list of IPermissions objects.
653
+ * @returns - The list of Permissions objects.
766
654
  */
767
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;
768
668
  /**
769
669
  * Gets all permissions for the logged in user.
770
670
  *
771
- * @returns - The list of IPermissions objects.
671
+ * @returns - The list of Permissions objects.
772
672
  */
773
673
  private getPermissions;
774
- private deletePermission;
775
- private retrieveFile;
776
- 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;
777
683
  /**
778
684
  * Initializes the keyring. This must be called before anything else.
779
685
  */
780
686
  private init;
781
- private deleteChannel;
782
- private createFile;
783
- private getUserList;
687
+ private initSocket;
688
+ private kickUser;
689
+ private leaveServer;
784
690
  private markSessionVerified;
785
- private getGroupHistory;
786
- private deleteHistory;
691
+ private negotiateOTK;
692
+ private newEphemeralKeys;
693
+ private ping;
694
+ private pong;
695
+ private populateKeyRing;
696
+ private postAuth;
787
697
  private purgeHistory;
788
- private getMessageHistory;
789
- 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;
790
709
  private sendGroupMessage;
791
- private createServer;
792
- private forward;
793
710
  private sendMail;
794
- private getSessionList;
795
- private getServerList;
796
- private createChannel;
797
- private getDeviceByID;
798
- private deleteDevice;
799
- private getMultiUserDeviceList;
800
- private getUserDeviceList;
801
- private getServerByID;
802
- private getChannelByID;
803
- private getChannelList;
804
- private getUser;
805
- private getDevice;
806
- private setUser;
807
- private retrieveUserDBEntry;
808
- private getFamiliars;
809
- private createSession;
711
+ private sendMessage;
810
712
  private sendReceipt;
811
- private getSessionByPubkey;
812
- private readMail;
813
- private newEphemeralKeys;
814
- private createPreKey;
815
- private handleNotify;
816
- private populateKeyRing;
817
- private initSocket;
818
713
  private setAlive;
819
- private postAuth;
820
- private getMail;
821
- private send;
822
- private retrieveKeyBundle;
823
- private getOTKCount;
714
+ private setUser;
824
715
  private submitOTK;
825
- private negotiateOTK;
826
- private respond;
827
- private pong;
828
- private ping;
829
- private censorPreKey;
716
+ private uploadAvatar;
717
+ private uploadEmoji;
830
718
  }
719
+ //# sourceMappingURL=Client.d.ts.map