cohost re-implementation on atprotocol

Refactor project into workspace with athost and athost_identity crates

Changed files
+60 -30
athost
athost_identity
src
identity
+1
.gitignore
··· 1 + */target 1 2 /target
+18 -13
Cargo.lock athost/Cargo.lock
··· 21 21 name = "athost" 22 22 version = "0.0.1" 23 23 dependencies = [ 24 + "athost_identity", 24 25 "ciborium", 25 26 "futures-util", 26 27 "serde", ··· 29 30 "tokio-tungstenite", 30 31 "url", 31 32 ] 33 + 34 + [[package]] 35 + name = "athost_identity" 36 + version = "0.0.1" 32 37 33 38 [[package]] 34 39 name = "autocfg" ··· 80 85 81 86 [[package]] 82 87 name = "cc" 83 - version = "1.2.18" 88 + version = "1.2.19" 84 89 source = "registry+https://github.com/rust-lang/crates.io-index" 85 - checksum = "525046617d8376e3db1deffb079e91cef90a89fc3ca5c185bbf8c9ecdd15cd5c" 90 + checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362" 86 91 dependencies = [ 87 92 "shlex", 88 93 ] ··· 163 168 164 169 [[package]] 165 170 name = "data-encoding" 166 - version = "2.8.0" 171 + version = "2.9.0" 167 172 source = "registry+https://github.com/rust-lang/crates.io-index" 168 - checksum = "575f75dfd25738df5b91b8e43e14d44bda14637a58fae779fd2b064f8bf3e010" 173 + checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" 169 174 170 175 [[package]] 171 176 name = "digest" ··· 290 295 291 296 [[package]] 292 297 name = "getrandom" 293 - version = "0.2.15" 298 + version = "0.2.16" 294 299 source = "registry+https://github.com/rust-lang/crates.io-index" 295 - checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" 300 + checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" 296 301 dependencies = [ 297 302 "cfg-if", 298 303 "libc", ··· 491 496 492 497 [[package]] 493 498 name = "libc" 494 - version = "0.2.171" 499 + version = "0.2.172" 495 500 source = "registry+https://github.com/rust-lang/crates.io-index" 496 - checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" 501 + checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" 497 502 498 503 [[package]] 499 504 name = "linux-raw-sys" ··· 683 688 684 689 [[package]] 685 690 name = "proc-macro2" 686 - version = "1.0.94" 691 + version = "1.0.95" 687 692 source = "registry+https://github.com/rust-lang/crates.io-index" 688 - checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" 693 + checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" 689 694 dependencies = [ 690 695 "unicode-ident", 691 696 ] ··· 732 737 source = "registry+https://github.com/rust-lang/crates.io-index" 733 738 checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" 734 739 dependencies = [ 735 - "getrandom 0.2.15", 740 + "getrandom 0.2.16", 736 741 ] 737 742 738 743 [[package]] ··· 858 863 859 864 [[package]] 860 865 name = "signal-hook-registry" 861 - version = "1.4.2" 866 + version = "1.4.5" 862 867 source = "registry+https://github.com/rust-lang/crates.io-index" 863 - checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" 868 + checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" 864 869 dependencies = [ 865 870 "libc", 866 871 ]
+2 -2
Cargo.toml athost/Cargo.toml
··· 1 1 [package] 2 2 name = "athost" 3 3 version = "0.0.1" 4 - authors = ["Eric Hamilton <etj2206@rit.edu>"] 5 - edition = "2021" 4 + edition = "2024" 6 5 7 6 [dependencies] 7 + athost_identity = { path = "../athost_identity" } 8 8 tokio = { version = "1", features = ["full"] } 9 9 tokio-tungstenite = { version = "0.20", features = ["native-tls"] } 10 10 futures-util = "0.3"
+9
athost/src/main.rs
··· 1 + use athost_identity::DID; // imports the DID struct 2 + 3 + #[tokio::main] 4 + async fn main() -> Result<(), Box<dyn std::error::Error>> { 5 + let did_test = DID::from_string("did:plc:6vxtya3serxcwvcdk5e7psvv")?; 6 + println!("{}", did_test.to_string()); 7 + println!(""); 8 + Ok(()) 9 + }
+7
athost_identity/Cargo.lock
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "athost_identity" 7 + version = "0.0.1"
+6
athost_identity/Cargo.toml
··· 1 + [package] 2 + name = "athost_identity" 3 + version = "0.0.1" 4 + edition = "2024" 5 + 6 + [dependencies]
+17 -11
src/identity/did.rs athost_identity/src/lib.rs
··· 1 - use serde::{Deserialize, Serialize}; 2 - 3 - #[derive(Serialize, Deserialize, Debug)] 4 1 pub enum DIDType { 5 2 Web, 6 3 PLC, 7 4 } 8 5 9 6 impl DIDType { 10 - pub fn as_str(&self) -> &'static str { 7 + fn as_str(&self) -> &'static str { 11 8 match self { 12 9 DIDType::Web => "web", 13 10 DIDType::PLC => "plc", ··· 15 12 } 16 13 } 17 14 18 - #[derive(Serialize, Deserialize, Debug)] 19 15 pub struct DID { 20 - didType: DIDType, 16 + did_type: DIDType, 21 17 value: String, 18 + } 19 + 20 + impl ToString for DID { 21 + fn to_string(&self) -> String { 22 + format!("did:{}:{}", self.did_type.as_str(), self.value) 23 + } 22 24 } 23 25 24 26 impl DID { 25 - pub fn new(didType: DIDType, value: String) -> Self { 26 - DID { didType, value } 27 + pub fn new(did_type: DIDType, value: String) -> Self { 28 + DID { did_type, value } 27 29 } 28 30 29 31 pub fn from_string(did: &str) -> Result<Self, String> { ··· 31 33 if parts.len() != 3 { 32 34 return Err("Invalid DID format".to_string()); 33 35 } 34 - let didType = match parts[1] { 36 + let did_type = match parts[1] { 35 37 "web" => DIDType::Web, 36 38 "plc" => DIDType::PLC, 37 39 _ => return Err("Unsupported DID type".to_string()), 38 40 }; 39 41 Ok(DID { 40 - didType, 42 + did_type, 41 43 value: parts[2].to_string(), 42 44 }) 43 45 } 44 46 47 + pub fn resolve_handle() { 48 + todo!() 49 + } 50 + 45 51 pub fn uri(&self) -> String { 46 - format!("at://did:{:?}:{}", self.didType, self.value) 52 + format!("at://{:?}", self.to_string()) 47 53 } 48 54 }
-1
src/identity/mod.rs
··· 1 - pub mod did;
-3
src/main.rs
··· 1 - fn main() { 2 - println!("Hello, world!"); 3 - }