fedimint_core/
setup_code.rs

1use anyhow::ensure;
2use serde::Serialize;
3
4use crate::base32;
5use crate::encoding::{Decodable, Encodable};
6use crate::module::registry::ModuleDecoderRegistry;
7use crate::util::SafeUrl;
8
9#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable, Serialize)]
10/// Connection information sent between peers in order to start config gen
11pub struct PeerSetupCode {
12    /// Name of the peer, used in TLS auth
13    pub name: String,
14    /// The peer's api and p2p endpoint
15    pub endpoints: PeerEndpoints,
16    /// Federation name set by the leader
17    pub federation_name: Option<String>,
18}
19
20impl PeerSetupCode {
21    pub fn encode_base32(&self) -> String {
22        format!(
23            "fedimint{}",
24            base32::encode(&self.consensus_encode_to_vec())
25        )
26    }
27
28    pub fn decode_base32(s: &str) -> anyhow::Result<Self> {
29        ensure!(s.starts_with("fedimint"), "Invalid Prefix");
30
31        let params = Self::consensus_decode_whole(
32            &base32::decode(&s[8..])?,
33            &ModuleDecoderRegistry::default(),
34        )?;
35
36        Ok(params)
37    }
38}
39
40#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable, Serialize)]
41pub enum PeerEndpoints {
42    Tcp {
43        /// Url for our websocket api endpoint
44        api_url: SafeUrl,
45        /// Url for our websocket p2p endpoint
46        p2p_url: SafeUrl,
47        /// TLS certificate for our websocket p2p endpoint#
48        #[serde(with = "::fedimint_core::encoding::as_hex")]
49        cert: Vec<u8>,
50    },
51    Iroh {
52        /// Public key for our iroh api endpoint
53        api_pk: iroh_base::PublicKey,
54        /// Public key for our iroh p2p endpoint
55        p2p_pk: iroh_base::PublicKey,
56    },
57}