blob: 30b5bf8719ae2d60297cba25a4c9058fc934ab8c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright (C) 2026 Doan Luu Duc Tai <doan@luuduct.ai>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
declare namespace StackChat {
interface Credentials { file: string; password: string }
interface Identity { public: string; fingerprint: string; owner: string; name: string }
interface Session { public: string; fingerprint: string; name: string; id: string; token: string; owner: boolean; expires_seconds: number }
interface Configuration { owner: string | null; origin: string; protocol: string }
interface Conversation { id: string; public: string; profile?: string | null; total: number; visitor_sent: number; owner_sent: number }
interface Message { seq: number; id: string; sender: string; ciphertext: string }
interface SendRequest { op: 'send'; conversation: string; id: string; ciphertext: string }
interface Api {
config: { request: { op: 'config' }; response: Configuration };
challenge: { request: { op: 'challenge'; public: string; setup_token?: string | undefined }; response: { id: string; challenge: string } };
authenticate: { request: { op: 'authenticate'; id: string; signature: string }; response: { token: string; id: string; owner: boolean; expires_seconds: number } };
profile: { request: { op: 'profile'; conversation: string; ciphertext: string }; response: { stored: boolean } };
inbox: { request: { op: 'inbox' }; response: { conversations: Conversation[] } };
history: { request: { op: 'history'; conversation: string; count: number; before: number }; response: { conversation: Conversation; messages: Message[] } };
send: { request: SendRequest; response: { seq: number; conversation: Conversation } };
lock: { request: { op: 'lock' }; response: { locked: boolean } };
}
interface Protected extends Credentials { origin: string }
interface Decryption { payload: string; signer: string }
type DecryptionEntry = Decryption | { error: string };
interface Crypto {
create: { request: { op: 'create'; origin: string; name: string; password: string; owner: string }; response: { file: string } };
open: { request: Protected & { op: 'open' }; response: Identity };
proof: { request: Protected & { op: 'proof'; challenge: string }; response: { signature: string } };
encrypt: { request: Protected & { op: 'encrypt'; recipient: string; payload: string }; response: { ciphertext: string } };
decrypt: { request: Protected & { op: 'decrypt'; sender: string; ciphertext: string }; response: Decryption };
decrypt_batch: { request: Protected & { op: 'decrypt_batch'; messages: { sender: string; ciphertext: string }[] }; response: { messages: DecryptionEntry[] } };
}
type ApiRequest = Api[keyof Api]['request'];
type CryptoRequest = Crypto[keyof Crypto]['request'];
type CryptoResult = Crypto[keyof Crypto]['response'];
type WorkerResponse = { result: CryptoResult } | { error: string };
interface WorkerRequest { bytes: ArrayBuffer; request: CryptoRequest }
interface Execution { output: string; randomCalls: number; randomBytes: number }
interface Wasi {
readonly runCommand: (bytes: ArrayBuffer, request: CryptoRequest) => Promise<unknown>;
readonly runProbe: (bytes: ArrayBuffer) => Promise<Execution>;
}
}
declare const stackChatWasi: Readonly<StackChat.Wasi>;
|