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    /// Whether to disable base fees, set by the leader
19    pub disable_base_fees: Option<bool>,
20}
21
22impl PeerSetupCode {
23    pub fn encode_base32(&self) -> String {
24        format!(
25            "fedimint{}",
26            base32::encode(&self.consensus_encode_to_vec())
27        )
28    }
29
30    pub fn decode_base32(s: &str) -> anyhow::Result<Self> {
31        ensure!(s.starts_with("fedimint"), "Invalid Prefix");
32
33        let params = Self::consensus_decode_whole(
34            &base32::decode(&s[8..])?,
35            &ModuleDecoderRegistry::default(),
36        )?;
37
38        Ok(params)
39    }
40}
41
42#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable, Serialize)]
43pub enum PeerEndpoints {
44    Tcp {
45        /// Url for our websocket api endpoint
46        api_url: SafeUrl,
47        /// Url for our websocket p2p endpoint
48        p2p_url: SafeUrl,
49        /// TLS certificate for our websocket p2p endpoint#
50        #[serde(with = "::fedimint_core::encoding::as_hex")]
51        cert: Vec<u8>,
52    },
53    Iroh {
54        /// Public key for our iroh api endpoint
55        api_pk: iroh_base::PublicKey,
56        /// Public key for our iroh p2p endpoint
57        p2p_pk: iroh_base::PublicKey,
58    },
59}