test_support.rs (2416B)
1 use crate::test_fixtures::{ 2 API_PRIMARY_HTTPS, ApprovedFixtureIdentity, FIXTURE_ALICE, FIXTURE_BOB, FIXTURE_CAROL, 3 FIXTURE_DIEGO, RELAY_PRIMARY_WSS, RELAY_SECONDARY_WSS, RELAY_TERTIARY_WSS, 4 }; 5 use nostr::{Keys, PublicKey, RelayUrl, SecretKey}; 6 use radroots_identity::{RadrootsIdentity, RadrootsIdentityPublic}; 7 8 fn approved_public_identity(identity: ApprovedFixtureIdentity) -> RadrootsIdentityPublic { 9 RadrootsIdentity::from_secret_key_str(identity.secret_key_hex) 10 .expect("identity") 11 .to_public() 12 } 13 14 fn approved_public_key(identity: ApprovedFixtureIdentity) -> PublicKey { 15 let secret = SecretKey::from_hex(identity.secret_key_hex).expect("secret"); 16 Keys::new(secret).public_key() 17 } 18 19 fn relay(url: &str) -> RelayUrl { 20 RelayUrl::parse(url).expect("relay") 21 } 22 23 pub(crate) fn fixture_alice_identity() -> RadrootsIdentityPublic { 24 approved_public_identity(FIXTURE_ALICE) 25 } 26 27 pub(crate) fn fixture_alice_public_key() -> PublicKey { 28 approved_public_key(FIXTURE_ALICE) 29 } 30 31 pub(crate) fn fixture_bob_identity() -> RadrootsIdentityPublic { 32 approved_public_identity(FIXTURE_BOB) 33 } 34 35 pub(crate) fn fixture_carol_identity() -> RadrootsIdentityPublic { 36 approved_public_identity(FIXTURE_CAROL) 37 } 38 39 pub(crate) fn fixture_carol_public_key() -> PublicKey { 40 approved_public_key(FIXTURE_CAROL) 41 } 42 43 pub(crate) fn fixture_diego_identity() -> RadrootsIdentityPublic { 44 approved_public_identity(FIXTURE_DIEGO) 45 } 46 47 pub(crate) fn fixture_diego_public_key() -> PublicKey { 48 approved_public_key(FIXTURE_DIEGO) 49 } 50 51 pub(crate) fn primary_relay() -> RelayUrl { 52 relay(RELAY_PRIMARY_WSS) 53 } 54 55 pub(crate) fn secondary_relay() -> RelayUrl { 56 relay(RELAY_SECONDARY_WSS) 57 } 58 59 pub(crate) fn tertiary_relay() -> RelayUrl { 60 relay(RELAY_TERTIARY_WSS) 61 } 62 63 pub(crate) fn api_primary_https() -> &'static str { 64 API_PRIMARY_HTTPS 65 } 66 67 pub(crate) fn synthetic_secret_hex(index: u32) -> String { 68 format!("{index:064x}") 69 } 70 71 pub(crate) fn synthetic_public_identity(index: u32) -> RadrootsIdentityPublic { 72 let secret_hex = synthetic_secret_hex(index); 73 RadrootsIdentity::from_secret_key_str(secret_hex.as_str()) 74 .expect("identity") 75 .to_public() 76 } 77 78 pub(crate) fn synthetic_public_key(index: u32) -> PublicKey { 79 let secret_hex = synthetic_secret_hex(index); 80 let secret = SecretKey::from_hex(secret_hex.as_str()).expect("secret"); 81 Keys::new(secret).public_key() 82 }