Files
psg-backchannel/backchannel-web/src/protocol.ts
2026-02-19 13:51:07 +08:00

73 lines
2.3 KiB
TypeScript

export const GENERAL_CHANNEL_ID = "00000000-0000-0000-0000-000000000010";
export type ClientMessage =
| { type: "login"; username: string; password: string; identity_pubkey: string }
| { type: "register"; username: string; password: string; identity_pubkey: string }
| { type: "resume_session"; token: string }
| { type: "logout" }
| { type: "send_channel_message"; channel_id: string; content: string }
| { type: "fetch_channel_history"; channel_id: string; before_message_id: string | null; limit: number }
| { type: "init_dm_key_exchange"; recipient_id: string; sender_ephemeral_pubkey: string }
| { type: "accept_dm_key_exchange"; initiator_id: string; recipient_ephemeral_pubkey: string }
| { type: "send_dm"; recipient_id: string; ciphertext: string; nonce: string }
| { type: "fetch_dm_history"; peer_id: string; before_message_id: string | null; limit: number }
| { type: "ping" };
export type ServerMessage =
| { type: "auth_success"; user_id: string; username: string; session_token: string }
| { type: "auth_error"; reason: string }
| {
type: "channel_message";
message_id: string;
channel_id: string;
author_id: string;
author_username: string;
content: string;
timestamp: string;
}
| {
type: "channel_history";
channel_id: string;
messages: Array<{
message_id: string;
author_id: string;
author_username: string;
content: string;
timestamp: string;
}>;
}
| {
type: "dm_key_exchange_request";
initiator_id: string;
initiator_username: string;
sender_ephemeral_pubkey: string;
}
| {
type: "dm_key_exchange_response";
recipient_id: string;
recipient_username: string;
recipient_ephemeral_pubkey: string;
}
| {
type: "direct_message";
message_id: string;
sender_id: string;
sender_username: string;
ciphertext: string;
nonce: string;
timestamp: string;
}
| {
type: "dm_history";
peer_id: string;
messages: Array<{
message_id: string;
sender_id: string;
ciphertext: string;
nonce: string;
timestamp: string;
}>;
}
| { type: "error"; code: number; message: string }
| { type: "pong" };