public_identity.rs (794B)
1 use radroots_identity::{AccountId, Profile, PublicIdentity, PublicKey, Username}; 2 3 fn main() -> Result<(), radroots_identity::Error> { 4 let public_key = 5 PublicKey::from_hex("585591529da0bab31b3b1b1f986611cf5f435dca84f978c89ee8a40cca7103df")?; 6 let username = Username::parse(" Alice.Farm ")?; 7 let identity = 8 PublicIdentity::new(public_key).with_profile(Profile::new().with_username(username)); 9 let account_id = AccountId::from_public_identity(&identity); 10 11 assert_eq!(identity.id().as_bytes(), public_key.as_bytes()); 12 assert_eq!(account_id.as_bytes(), public_key.as_bytes()); 13 assert_eq!( 14 identity 15 .profile() 16 .and_then(Profile::username) 17 .map(Username::as_str), 18 Some("alice.farm"), 19 ); 20 Ok(()) 21 }