Files
maarcadetweet/crates/at-shared/src/did.rs
T
tomdebone c586fd39c9 maarcadetweet: initial commit
AT Protocol PDS + AppView + Tauri Desktop Client, 160-char post limit.

- PDS (Rust + axum + sqlx)
  - Auth: createAccount, createSession, refreshSession
  - Records: createRecord, deleteRecord (race-safe via SELECT FOR UPDATE)
  - Feed: feed.like.create, feed.repost.create
  - Sync: getRepo, getBlocks, getLatestCommit, getRecord (with MST proof), listRepos
  - Identity: resolveHandle
  - MST: spec-conformant (at-mst crate, 27 tests)
  - Repo: signed commits, TID counter (monotonic, 4096 wrap safe)

- AppView (Rust + axum + sqlx)
  - Jetstream consumer (WebSocket, exponential backoff, 38k+ events indexed)
  - REST API: timeline/home (graph-aware), profile, search, post (with thread hydration)
  - Handle-sync worker (did:plc + did:web)
  - JSONB embed storage + thread columns (migration 0003)
  - Like/repost counter cache (migration 0004)

- Tauri 2 + Svelte 5 Desktop Client
  - System tray (Show/Compose/Quit menu)
  - OS notifications (tauri-plugin-notification)
  - Auto-update (tauri-plugin-updater, placeholder endpoint)
  - Window-state (tauri-plugin-window-state)
  - 160-char compose with live counter
  - Image/Link embed rendering
  - LocalStorage-persisted like state
  - Timeline with poll (prepend new posts)
  - Custom TitleBar (transparent, no decorations)
  - Orange/IBM Plex Mono maarcade design

Tests: 231 Rust + 9 vitest = 240 passed.
2026-07-05 20:01:31 +02:00

73 lines
1.9 KiB
Rust

use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(tag = "method", content = "id")]
pub enum Did {
Plc { id: String },
Web { id: String },
Key { id: String },
}
impl Did {
pub fn method(&self) -> &'static str {
match self {
Self::Plc { .. } => "plc",
Self::Web { .. } => "web",
Self::Key { .. } => "key",
}
}
pub fn id(&self) -> &str {
match self {
Self::Plc { id }
| Self::Web { id }
| Self::Key { id } => id,
}
}
pub fn as_str(&self) -> String {
format!("did:{}:{}", self.method(), self.id())
}
}
impl std::fmt::Display for Did {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.as_str())
}
}
impl std::str::FromStr for Did {
type Err = anyhow::Error;
fn from_str(s: &str) -> anyhow::Result<Self> {
let s = s.strip_prefix("did:").ok_or_else(|| anyhow::anyhow!("not a did"))?;
let (method, rest) = s
.split_once(':')
.ok_or_else(|| anyhow::anyhow!("malformed did"))?;
Ok(match method {
"plc" => Self::Plc { id: rest.to_string() },
"web" => Self::Web { id: rest.to_string() },
"key" => Self::Key { id: rest.to_string() },
other => anyhow::bail!("unknown did method: {other}"),
})
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::str::FromStr;
#[test]
fn roundtrip_did() {
let d: Did = "did:plc:abc123def".parse().unwrap();
assert_eq!(d, Did::Plc { id: "abc123def".into() });
assert_eq!(d.as_str(), "did:plc:abc123def");
}
#[test]
fn rejects_invalid() {
assert!("not-a-did".parse::<Did>().is_err());
assert!("did:unknown:x".parse::<Did>().is_err());
}
}