client server connection loop

This commit is contained in:
2026-08-06 19:17:03 +08:00
parent 5c5f4dbf01
commit eae86c73f7
13 changed files with 528 additions and 15 deletions
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "wyd-common"
version = "0.1.0"
edition = "2024"
publish = false
[dependencies]
serde = { version = "1", features = ["derive"] }
+36
View File
@@ -0,0 +1,36 @@
use serde::{Deserialize, Serialize};
pub const VERSION: u8 = 1;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Profile {
pub id: String,
pub display_name: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum ClientMessage {
Register { profile: Profile, signature: String },
Signed { payload: String, signature: String },
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum ServerMessage {
Challenge { version: u8, challenge: String },
Registered,
}
pub fn register_bytes(challenge: &str, profile: &Profile) -> Vec<u8> {
format!(
"wyd-register-v{VERSION}\n{challenge}\n{}\n{}",
profile.id, profile.display_name
)
.into_bytes()
}
pub fn message_bytes(payload: &str) -> Vec<u8> {
format!("wyd-message-v{VERSION}\n{payload}").into_bytes()
}