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