// Copyright (C) 2026 Doan Luu Duc Tai // // 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 . 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; readonly runProbe: (bytes: ArrayBuffer) => Promise; } } declare const stackChatWasi: Readonly;