korero-chat 0.0.0-stage → 0.1.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/dist/auth.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { type DeviceIdentity } from "./identity.js";
2
+ import type { RelayResponse } from "./types.js";
3
+ export type IdentityAction = {
4
+ operation: "login";
5
+ password?: string;
6
+ } | {
7
+ operation: "register";
8
+ displayName: string;
9
+ invitation?: string;
10
+ password?: string;
11
+ } | {
12
+ operation: "bootstrap";
13
+ displayName: string;
14
+ token: string;
15
+ password?: string;
16
+ };
17
+ export interface IdentityAuthentication {
18
+ serverId: string;
19
+ deviceName: string;
20
+ action: IdentityAction;
21
+ identity: DeviceIdentity;
22
+ }
23
+ export declare function authenticateIdentity(request: (path: string, body: unknown) => Promise<RelayResponse>, origin: string, { serverId, deviceName, action, identity }: IdentityAuthentication): Promise<RelayResponse>;
package/dist/auth.js ADDED
@@ -0,0 +1,22 @@
1
+ import { requestError } from "./errors.js";
2
+ import { signIdentity } from "./identity.js";
3
+ export async function authenticateIdentity(request, origin, { serverId, deviceName, action, identity }) {
4
+ const { operation, ...fields } = action;
5
+ const { publicKey } = identity;
6
+ const challenge = await request("/api/v1/auth/identity/challenge", { origin, operation, deviceName, publicKey });
7
+ if (challenge.status !== 200)
8
+ throw requestError({ value: challenge.body });
9
+ const details = challenge.body;
10
+ if (!details || details.origin !== origin || details.serverId !== serverId || details.operation !== operation ||
11
+ details.publicKey !== publicKey || details.deviceName !== deviceName || details.binding !== "" ||
12
+ typeof details.id !== "string" || !Number.isFinite(details.expiresAt)) {
13
+ throw new Error("The identity challenge does not match this server address or request.");
14
+ }
15
+ const id = details.id;
16
+ const signature = await signIdentity(identity, ["korero-identity-v1", serverId, origin, operation, id, publicKey, "", deviceName, details.expiresAt]);
17
+ switch (operation) {
18
+ case "login": return request("/api/v1/auth/identity/login", { id, signature, ...fields });
19
+ case "register": return request("/api/v1/auth/register", { identity: { id, signature }, deviceName, ...fields });
20
+ case "bootstrap": return request("/api/v1/admin/bootstrap", { identity: { id, signature }, deviceName, ...fields });
21
+ }
22
+ }
@@ -0,0 +1,44 @@
1
+ import type { KoreroClient } from "./session.js";
2
+ import type { ChannelData, Message } from "./types.js";
3
+ export type MessageContent = string | {
4
+ text: string;
5
+ html?: string;
6
+ };
7
+ export interface ChannelOptions {
8
+ name?: string;
9
+ description?: string;
10
+ parentId?: string | null;
11
+ position?: number;
12
+ capacity?: number | null;
13
+ password?: string | null;
14
+ backgroundImageUrl?: string | null;
15
+ icon?: string | null;
16
+ audioBitrate?: number | null;
17
+ }
18
+ /** A channel on a particular signed-in client. */
19
+ export declare class Channel {
20
+ readonly id: string;
21
+ private readonly client;
22
+ constructor(id: string, client: KoreroClient);
23
+ get data(): ChannelData | undefined;
24
+ send(content: MessageContent): Promise<{
25
+ messageId: string;
26
+ }>;
27
+ history(before?: number): Promise<ChannelMessage[]>;
28
+ follow(): Promise<void>;
29
+ join(password?: string): Promise<void>;
30
+ edit(changes: ChannelOptions): Promise<string>;
31
+ delete(): Promise<void>;
32
+ }
33
+ /** A channel message and the operations available on it. */
34
+ export declare class ChannelMessage {
35
+ readonly data: Message;
36
+ readonly channel: Channel;
37
+ private readonly client;
38
+ constructor(data: Message, channel: Channel, client: KoreroClient);
39
+ get id(): string;
40
+ get text(): string;
41
+ get senderId(): string;
42
+ edit(content: MessageContent): Promise<void>;
43
+ delete(): Promise<void>;
44
+ }
@@ -0,0 +1,56 @@
1
+ /** A channel on a particular signed-in client. */
2
+ export class Channel {
3
+ id;
4
+ client;
5
+ constructor(id, client) {
6
+ this.id = id;
7
+ this.client = client;
8
+ }
9
+ get data() {
10
+ return this.client.state.snapshot?.channels.find(({ id }) => id === this.id);
11
+ }
12
+ send(content) {
13
+ const { text, html } = typeof content === "string" ? { text: content } : content;
14
+ return this.client.sendMessage(this.id, text, html);
15
+ }
16
+ history(before) {
17
+ return this.client.rpc("message.history", { channelId: this.id, before })
18
+ .then((messages) => messages.map((message) => new ChannelMessage(message, this, this.client)));
19
+ }
20
+ async follow() {
21
+ const connectionId = this.client.connectionId;
22
+ if (!connectionId)
23
+ throw new Error("Connect to a server first.");
24
+ await this.client.viewChannel(connectionId, this.id);
25
+ }
26
+ join(password) {
27
+ return this.client.joinChannel(this.id, password);
28
+ }
29
+ edit(changes) {
30
+ return this.client.saveChannel({ ...changes, channelId: this.id });
31
+ }
32
+ delete() {
33
+ return this.client.deleteChannel(this.id);
34
+ }
35
+ }
36
+ /** A channel message and the operations available on it. */
37
+ export class ChannelMessage {
38
+ data;
39
+ channel;
40
+ client;
41
+ constructor(data, channel, client) {
42
+ this.data = data;
43
+ this.channel = channel;
44
+ this.client = client;
45
+ }
46
+ get id() { return this.data.id; }
47
+ get text() { return this.data.text; }
48
+ get senderId() { return this.data.senderId; }
49
+ edit(content) {
50
+ const { text, html } = typeof content === "string" ? { text: content } : content;
51
+ return this.client.editMessage(this.id, text, html);
52
+ }
53
+ delete() {
54
+ return this.client.deleteMessage(this.id);
55
+ }
56
+ }
@@ -0,0 +1,26 @@
1
+ import type { DirectMessage } from "./types.js";
2
+ import type { DeviceIdentity } from "./identity.js";
3
+ export type DirectPeer = {
4
+ accountId: string;
5
+ displayName: string;
6
+ publicKey: string;
7
+ };
8
+ export type DirectPacket = Pick<DirectMessage, "id" | "nonce" | "ciphertext" | "signature"> & {
9
+ accountId: string;
10
+ };
11
+ export type DirectCursor = Pick<DirectMessage, "id" | "createdAt">;
12
+ export type DirectPage = {
13
+ messages: DirectMessage[];
14
+ next: DirectCursor | null;
15
+ };
16
+ export declare function encodeDirectContent(text: string, html?: string): string;
17
+ export declare function decodeDirectContent(value: string): {
18
+ text: string;
19
+ html?: string;
20
+ };
21
+ export declare function directConversation(serverId: string, ownId: string, identity: DeviceIdentity, peer: DirectPeer): Promise<{
22
+ safetyCode: string;
23
+ /** Encrypts a new message, or replacement content for the message `id` when editing. */
24
+ encrypt(text: string, id?: string): Promise<DirectPacket>;
25
+ decrypt(message: DirectMessage): Promise<string>;
26
+ }>;
@@ -0,0 +1,79 @@
1
+ import { ed25519, x25519 } from "@noble/curves/ed25519.js";
2
+ import { decodeBase64Url, encodeBase64Url, identitySeed } from "./identity.js";
3
+ const encoder = new TextEncoder();
4
+ const decoder = new TextDecoder("utf-8", { fatal: true });
5
+ const transcript = (fields) => encoder.encode(JSON.stringify(fields));
6
+ const richMessagePrefix = "\0korero-rich-message-v1\n";
7
+ export function encodeDirectContent(text, html) {
8
+ return html ? richMessagePrefix + JSON.stringify({ text, html }) : text;
9
+ }
10
+ export function decodeDirectContent(value) {
11
+ if (value.startsWith(richMessagePrefix)) {
12
+ try {
13
+ const content = JSON.parse(value.slice(richMessagePrefix.length));
14
+ if (typeof content?.text === "string" && typeof content.html === "string") {
15
+ return { text: content.text, html: content.html };
16
+ }
17
+ }
18
+ catch {
19
+ // An unrecognized payload can still be displayed as plain text.
20
+ }
21
+ }
22
+ return { text: value };
23
+ }
24
+ function publicKey(value) {
25
+ const bytes = decodeBase64Url(value);
26
+ if (bytes.length !== 32 || encodeBase64Url(bytes) !== value)
27
+ throw new Error("Invalid conversation identity.");
28
+ const point = ed25519.Point.fromBytes(bytes, false);
29
+ if (!point.isTorsionFree() || point.isSmallOrder())
30
+ throw new Error("Invalid conversation identity.");
31
+ return bytes;
32
+ }
33
+ export async function directConversation(serverId, ownId, identity, peer) {
34
+ const seed = identitySeed(identity.privateKey);
35
+ const ownKey = ed25519.getPublicKey(seed);
36
+ if (encodeBase64Url(ownKey) !== identity.publicKey || ownId === peer.accountId || identity.publicKey === peer.publicKey) {
37
+ throw new Error("Invalid conversation identity.");
38
+ }
39
+ const peerKey = publicKey(peer.publicKey);
40
+ const participants = ownId < peer.accountId
41
+ ? [[ownId, identity.publicKey], [peer.accountId, peer.publicKey]]
42
+ : [[peer.accountId, peer.publicKey], [ownId, identity.publicKey]];
43
+ const digest = await crypto.subtle.digest("SHA-256", transcript(["korero-direct-safety-code-v1", serverId, participants]));
44
+ const safetyCode = Array.from(new Uint8Array(digest, 0, 16), (byte) => byte.toString(16).padStart(2, "0")).join("");
45
+ const secret = x25519.getSharedSecret(ed25519.utils.toMontgomerySecret(seed), ed25519.utils.toMontgomery(peerKey));
46
+ const shared = await crypto.subtle.importKey("raw", secret, "HKDF", false, ["deriveKey"]);
47
+ secret.fill(0);
48
+ const context = (senderId, recipientId, id) => ["korero-direct-message-v1", serverId, senderId, recipientId, id];
49
+ const derive = (info) => crypto.subtle.deriveKey({ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(32), info }, shared, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
50
+ return {
51
+ safetyCode,
52
+ /** Encrypts a new message, or replacement content for the message `id` when editing. */
53
+ async encrypt(text, id = crypto.randomUUID()) {
54
+ const iv = crypto.getRandomValues(new Uint8Array(12));
55
+ const fields = context(ownId, peer.accountId, id);
56
+ const additionalData = transcript(fields);
57
+ const key = await derive(additionalData);
58
+ const nonce = encodeBase64Url(iv);
59
+ const ciphertext = encodeBase64Url(await crypto.subtle.encrypt({ name: "AES-GCM", iv, additionalData }, key, encoder.encode(text)));
60
+ const signature = encodeBase64Url(ed25519.sign(transcript([...fields, nonce, ciphertext]), seed));
61
+ return { accountId: peer.accountId, id, nonce, ciphertext, signature };
62
+ },
63
+ async decrypt(message) {
64
+ const { id, senderId, recipientId, nonce, ciphertext, signature } = message;
65
+ const outgoing = senderId === ownId && recipientId === peer.accountId;
66
+ const incoming = senderId === peer.accountId && recipientId === ownId;
67
+ if (!outgoing && !incoming)
68
+ throw new Error("The message belongs to a different conversation.");
69
+ const fields = context(senderId, recipientId, id);
70
+ if (!ed25519.verify(decodeBase64Url(signature), transcript([...fields, nonce, ciphertext]), outgoing ? ownKey : peerKey, { zip215: false })) {
71
+ throw new Error("The message signature could not be verified.");
72
+ }
73
+ const additionalData = transcript(fields);
74
+ const key = await derive(additionalData);
75
+ const text = await crypto.subtle.decrypt({ name: "AES-GCM", iv: decodeBase64Url(nonce), additionalData }, key, decodeBase64Url(ciphertext));
76
+ return decoder.decode(text);
77
+ },
78
+ };
79
+ }
@@ -0,0 +1,2 @@
1
+ export declare function messageFrom(error: unknown): string;
2
+ export declare function requestError(error: unknown): Error;
package/dist/errors.js ADDED
@@ -0,0 +1,20 @@
1
+ export function messageFrom(error) {
2
+ if (error instanceof Error)
3
+ return error.message;
4
+ if (typeof error === "string")
5
+ return error;
6
+ if (error && typeof error === "object" && "message" in error && typeof error.message === "string") {
7
+ return error.message;
8
+ }
9
+ return "The request could not be completed.";
10
+ }
11
+ export function requestError(error) {
12
+ if (error && typeof error === "object" && "value" in error) {
13
+ const value = error.value;
14
+ if (value && typeof value === "object" && "error" in value) {
15
+ return new Error(messageFrom(value.error));
16
+ }
17
+ return new Error(messageFrom(value));
18
+ }
19
+ return new Error(messageFrom(error));
20
+ }
package/dist/http.d.ts ADDED
@@ -0,0 +1,286 @@
1
+ import type { Account, ServerInfo } from "./types.js";
2
+ type Query = Record<string, string | number | boolean | undefined>;
3
+ type QueryOptions<T extends Query> = {
4
+ query: T;
5
+ };
6
+ type Requester = (request: Request) => Promise<Response>;
7
+ type Empty = Record<string, never>;
8
+ export type ApiResult<T> = {
9
+ data: T;
10
+ error: null;
11
+ status: number;
12
+ } | {
13
+ data: null;
14
+ error: {
15
+ status: number;
16
+ value: unknown;
17
+ };
18
+ status: number;
19
+ };
20
+ export type ChannelPermission = "join" | "speak" | "text" | "deleteChannels" | "mute" | "attachFiles" | "shareScreen" | "useCamera" | "whisper";
21
+ export type Permission = ChannelPermission | "createChannels" | "editChannels" | "move" | "kick" | "ban" | "manageRoles" | "manageInvitations" | "manageSettings" | "viewAdmin" | "sendDirectMessages" | "removeChannels";
22
+ export interface ChannelPermissionTable {
23
+ editable: ChannelPermission[];
24
+ roles: {
25
+ name: string;
26
+ permissions: Record<ChannelPermission, {
27
+ allow: boolean | null;
28
+ inherited: boolean;
29
+ }>;
30
+ }[];
31
+ }
32
+ export interface AccountPage {
33
+ accounts: (Account & {
34
+ editable: boolean;
35
+ bannable: boolean;
36
+ banned: boolean;
37
+ })[];
38
+ next: string | null;
39
+ roles: string[];
40
+ builtInRoles: (RoleDefinition & {
41
+ editable: boolean;
42
+ defaultPermissions: Permission[];
43
+ })[];
44
+ customRoles: RoleDefinition[];
45
+ assignablePermissions: Permission[];
46
+ canDefineRoles: boolean;
47
+ defaultRole: string;
48
+ registrationPermissions: Permission[];
49
+ }
50
+ export interface RoleDefinition {
51
+ name: string;
52
+ permissions: Permission[];
53
+ }
54
+ export interface AuditPage {
55
+ events: {
56
+ id: number;
57
+ action: string;
58
+ actorId: string | null;
59
+ actorName: string | null;
60
+ targetId: string | null;
61
+ targetName: string | null;
62
+ createdAt: number;
63
+ details: Record<string, string | number | boolean | string[] | null> | null;
64
+ }[];
65
+ next: number | null;
66
+ }
67
+ export interface ServerPreferences {
68
+ motd: string;
69
+ defaultRole: string;
70
+ canSetDefaultRole: boolean;
71
+ defaultRoles: string[];
72
+ defaultAudioBitrate: number | null;
73
+ configuredAudioBitrate: number;
74
+ audioBitrateLocked: boolean;
75
+ maxAttachmentMiB: number;
76
+ maxSupportedAttachmentMiB: number;
77
+ }
78
+ export interface Invitation {
79
+ id: string;
80
+ createdBy: string;
81
+ expiresAt: number | null;
82
+ usesLeft: number | null;
83
+ revokedAt: number | null;
84
+ }
85
+ export interface ConnectionDetails {
86
+ displayName: string;
87
+ channelName: string | null;
88
+ connectedSeconds: number;
89
+ latencyMs: number | null;
90
+ }
91
+ export interface ServerCapabilities {
92
+ protocolVersions: number[];
93
+ websocketPath: string;
94
+ audio: string;
95
+ targetAudioBitrate: number;
96
+ heartbeatSeconds: number;
97
+ maxWebSocketBytes: number;
98
+ udp: boolean;
99
+ tcp: boolean;
100
+ textPersistence: boolean;
101
+ }
102
+ export interface AttachmentUpload {
103
+ connectionId: string;
104
+ channelId: string;
105
+ text: string;
106
+ html?: string;
107
+ name: string;
108
+ data: string;
109
+ }
110
+ export interface ChannelOrder {
111
+ channelId: string;
112
+ targetId: string;
113
+ placement: "before" | "after" | "inside";
114
+ parentId?: string | null;
115
+ }
116
+ /** Typed v1 HTTP endpoints. The requester supplies credentials and any platform transport. */
117
+ export declare function createApi(origin: string, send?: Requester): {
118
+ server: {
119
+ info: {
120
+ get: () => Promise<ApiResult<ServerInfo>>;
121
+ };
122
+ capabilities: {
123
+ get: () => Promise<ApiResult<ServerCapabilities>>;
124
+ };
125
+ };
126
+ account: {
127
+ get: () => Promise<ApiResult<Account>>;
128
+ patch: (body: {
129
+ displayName: string;
130
+ }) => Promise<ApiResult<Account>>;
131
+ picture: (({ accountId }: {
132
+ accountId: string;
133
+ }) => {
134
+ get: () => Promise<ApiResult<{
135
+ avatarId: string | null;
136
+ data: string | null;
137
+ }>>;
138
+ }) & {
139
+ patch: (body: {
140
+ data: string | null;
141
+ }) => Promise<ApiResult<{
142
+ avatarId: string | null;
143
+ }>>;
144
+ };
145
+ sessions: (({ id }: {
146
+ id: string;
147
+ }) => {
148
+ delete: () => Promise<ApiResult<Empty>>;
149
+ }) & {
150
+ get: () => Promise<ApiResult<{
151
+ id: string;
152
+ deviceName: string;
153
+ createdAt: number;
154
+ lastActive: number;
155
+ expiresAt: number;
156
+ }[]>>;
157
+ };
158
+ };
159
+ connections: ({ id }: {
160
+ id: string;
161
+ }) => {
162
+ get: () => Promise<ApiResult<ConnectionDetails>>;
163
+ };
164
+ channels: (({ id }: {
165
+ id: string;
166
+ }) => {
167
+ permissions: {
168
+ get: () => Promise<ApiResult<ChannelPermissionTable>>;
169
+ patch: (body: {
170
+ changes: {
171
+ role: string;
172
+ permission: ChannelPermission;
173
+ allow: boolean | null;
174
+ }[];
175
+ }) => Promise<ApiResult<ChannelPermissionTable>>;
176
+ };
177
+ }) & {
178
+ order: {
179
+ patch: (body: ChannelOrder) => Promise<ApiResult<Empty>>;
180
+ };
181
+ };
182
+ chat: {
183
+ attachments: (({ messageId }: {
184
+ messageId: string;
185
+ }) => {
186
+ get: ({ query }: QueryOptions<{
187
+ connectionId: string;
188
+ }>) => Promise<ApiResult<{
189
+ data: string;
190
+ }>>;
191
+ }) & {
192
+ post: (body: AttachmentUpload) => Promise<ApiResult<{
193
+ messageId: string;
194
+ }>>;
195
+ };
196
+ };
197
+ admin: {
198
+ accounts: {
199
+ get: (options?: QueryOptions<{
200
+ after?: string;
201
+ }>) => Promise<ApiResult<AccountPage>>;
202
+ };
203
+ badges: {
204
+ patch: (body: {
205
+ accountId: string;
206
+ badge: string | null;
207
+ }) => Promise<ApiResult<{
208
+ badge: string | null;
209
+ }>>;
210
+ };
211
+ roles: {
212
+ patch: (body: {
213
+ accountId: string;
214
+ role: string;
215
+ }) => Promise<ApiResult<{
216
+ role: string;
217
+ }>>;
218
+ post: (body: RoleDefinition) => Promise<ApiResult<RoleDefinition>>;
219
+ definition: {
220
+ patch: (body: RoleDefinition) => Promise<ApiResult<RoleDefinition>>;
221
+ delete: (body: {
222
+ name: string;
223
+ }) => Promise<ApiResult<Empty>>;
224
+ };
225
+ };
226
+ audit: {
227
+ get: (options?: QueryOptions<{
228
+ before?: number;
229
+ prefix?: string;
230
+ actorId?: string;
231
+ }>) => Promise<ApiResult<AuditPage>>;
232
+ };
233
+ preferences: {
234
+ get: () => Promise<ApiResult<ServerPreferences>>;
235
+ patch: (body: Partial<Pick<ServerPreferences, "motd" | "defaultRole" | "defaultAudioBitrate" | "maxAttachmentMiB">>) => Promise<ApiResult<ServerPreferences>>;
236
+ };
237
+ banner: {
238
+ patch: (body: {
239
+ bannerImageUrl: string | null;
240
+ }) => Promise<ApiResult<{
241
+ bannerImageUrl: string | null;
242
+ }>>;
243
+ };
244
+ invitations: (({ id }: {
245
+ id: string;
246
+ }) => {
247
+ patch: (body: {
248
+ expiresAt?: number | null;
249
+ usesLeft?: number | null;
250
+ }) => Promise<ApiResult<Invitation>>;
251
+ delete: () => Promise<ApiResult<Empty>>;
252
+ }) & {
253
+ get: () => Promise<ApiResult<{
254
+ invitations: Invitation[];
255
+ }>>;
256
+ post: (body: {
257
+ expiresAt?: number;
258
+ expiresInSeconds?: number;
259
+ uses?: number;
260
+ }) => Promise<ApiResult<Pick<Invitation, "id" | "expiresAt" | "usesLeft"> & {
261
+ token: string;
262
+ }>>;
263
+ };
264
+ password: {
265
+ get: () => Promise<ApiResult<{
266
+ passwordRequired: boolean;
267
+ passwordLocked: boolean;
268
+ }>>;
269
+ patch: (body: {
270
+ password: string | null;
271
+ }) => Promise<ApiResult<{
272
+ passwordRequired: boolean;
273
+ }>>;
274
+ };
275
+ };
276
+ };
277
+ /** Public server information is available before signing in. */
278
+ export declare function serverApi(address: string): {
279
+ info: {
280
+ get: () => Promise<ApiResult<ServerInfo>>;
281
+ };
282
+ capabilities: {
283
+ get: () => Promise<ApiResult<ServerCapabilities>>;
284
+ };
285
+ };
286
+ export {};
package/dist/http.js ADDED
@@ -0,0 +1,95 @@
1
+ import { serverOrigin, webTransport } from "./transport.js";
2
+ /** Typed v1 HTTP endpoints. The requester supplies credentials and any platform transport. */
3
+ export function createApi(origin, send = (request) => webTransport.fetch(request, { timeout: 8000 })) {
4
+ async function request(method, path, body, query) {
5
+ const url = new URL("/api/v1/" + path, origin);
6
+ for (const [key, value] of Object.entries(query ?? {})) {
7
+ if (value !== undefined)
8
+ url.searchParams.set(key, String(value));
9
+ }
10
+ const response = await send(new Request(url, {
11
+ method,
12
+ headers: body === undefined ? undefined : { "content-type": "application/json" },
13
+ body: body === undefined ? undefined : JSON.stringify(body),
14
+ }));
15
+ const text = await response.text();
16
+ let value = text;
17
+ if (text) {
18
+ try {
19
+ value = JSON.parse(text);
20
+ }
21
+ catch { }
22
+ }
23
+ else
24
+ value = null;
25
+ const { status } = response;
26
+ return response.ok ? { data: value, error: null, status } : { data: null, error: { status, value }, status };
27
+ }
28
+ const accountPicture = Object.assign(({ accountId }) => ({
29
+ get: () => request("GET", "account/picture/" + encodeURIComponent(accountId)),
30
+ }), { patch: (body) => request("PATCH", "account/picture", body) });
31
+ const attachments = Object.assign(({ messageId }) => ({
32
+ get: ({ query }) => request("GET", "chat/attachments/" + encodeURIComponent(messageId), undefined, query),
33
+ }), { post: (body) => request("POST", "chat/attachments", body) });
34
+ const channels = Object.assign(({ id }) => {
35
+ const path = "channels/" + encodeURIComponent(id) + "/permissions";
36
+ return { permissions: {
37
+ get: () => request("GET", path),
38
+ patch: (body) => request("PATCH", path, body),
39
+ } };
40
+ }, { order: { patch: (body) => request("PATCH", "channels/order", body) } });
41
+ const invitations = Object.assign(({ id }) => {
42
+ const path = "admin/invitations/" + encodeURIComponent(id);
43
+ return {
44
+ patch: (body) => request("PATCH", path, body),
45
+ delete: () => request("DELETE", path),
46
+ };
47
+ }, {
48
+ get: () => request("GET", "admin/invitations"),
49
+ post: (body) => request("POST", "admin/invitations", body),
50
+ });
51
+ return {
52
+ server: {
53
+ info: { get: () => request("GET", "server/info") },
54
+ capabilities: { get: () => request("GET", "server/capabilities") },
55
+ },
56
+ account: {
57
+ get: () => request("GET", "account"),
58
+ patch: (body) => request("PATCH", "account", body),
59
+ picture: accountPicture,
60
+ sessions: Object.assign(({ id }) => ({ delete: () => request("DELETE", "account/sessions/" + encodeURIComponent(id)) }), { get: () => request("GET", "account/sessions") }),
61
+ },
62
+ connections: ({ id }) => ({
63
+ get: () => request("GET", "connections/" + encodeURIComponent(id)),
64
+ }),
65
+ channels,
66
+ chat: { attachments },
67
+ admin: {
68
+ accounts: { get: (options) => request("GET", "admin/accounts", undefined, options?.query) },
69
+ badges: { patch: (body) => request("PATCH", "admin/badges", body) },
70
+ roles: {
71
+ patch: (body) => request("PATCH", "admin/roles", body),
72
+ post: (body) => request("POST", "admin/roles", body),
73
+ definition: {
74
+ patch: (body) => request("PATCH", "admin/roles/definition", body),
75
+ delete: (body) => request("DELETE", "admin/roles/definition", body),
76
+ },
77
+ },
78
+ audit: { get: (options) => request("GET", "admin/audit", undefined, options?.query) },
79
+ preferences: {
80
+ get: () => request("GET", "admin/preferences"),
81
+ patch: (body) => request("PATCH", "admin/preferences", body),
82
+ },
83
+ banner: { patch: (body) => request("PATCH", "admin/banner", body) },
84
+ invitations,
85
+ password: {
86
+ get: () => request("GET", "admin/password"),
87
+ patch: (body) => request("PATCH", "admin/password", body),
88
+ },
89
+ },
90
+ };
91
+ }
92
+ /** Public server information is available before signing in. */
93
+ export function serverApi(address) {
94
+ return createApi(serverOrigin(address)).server;
95
+ }
@@ -0,0 +1,12 @@
1
+ export interface DeviceIdentity {
2
+ publicKey: string;
3
+ privateKey: string;
4
+ }
5
+ export declare function encodeBase64Url(bytes: ArrayBuffer | Uint8Array): string;
6
+ export declare function decodeBase64Url(value: string): Uint8Array<ArrayBuffer>;
7
+ export declare function identitySeed(privateKey: string): Uint8Array<ArrayBuffer>;
8
+ export declare function generateIdentity(): Promise<DeviceIdentity>;
9
+ export declare function identityFromPrivateKey(privateKey: string): DeviceIdentity;
10
+ export declare function importIdentity(blob: string, passphrase: string): Promise<DeviceIdentity>;
11
+ export declare function exportIdentity(privateKey: string, passphrase: string): Promise<string>;
12
+ export declare function signIdentity(identity: DeviceIdentity, transcript: unknown[]): Promise<string>;