1use core::{fmt, str};
2
3use iroh_base::{EndpointAddr, EndpointId};
4use rostra_core::ShortEventId;
5use rostra_core::event::IrohNodeId;
6use rostra_util_error::BoxedError;
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
10pub struct CompactTicket(pub EndpointId);
11
12impl CompactTicket {
13 pub fn to_iroh_node_id(&self) -> IrohNodeId {
15 IrohNodeId::from_bytes(*self.0.as_bytes())
16 }
17}
18
19impl fmt::Display for CompactTicket {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 data_encoding::BASE64URL_NOPAD.encode_write(self.0.as_bytes(), f)
22 }
23}
24
25impl str::FromStr for CompactTicket {
26 type Err = BoxedError;
27
28 fn from_str(s: &str) -> Result<Self, Self::Err> {
29 let bytes = data_encoding::BASE64URL_NOPAD.decode(s.as_bytes())?;
30 let id = EndpointId::try_from(&bytes[..])?;
31 Ok(Self(id))
32 }
33}
34
35impl From<EndpointId> for CompactTicket {
36 fn from(id: EndpointId) -> Self {
37 Self(id)
38 }
39}
40
41impl From<EndpointAddr> for CompactTicket {
42 fn from(addr: EndpointAddr) -> Self {
43 Self(addr.id)
44 }
45}
46
47impl From<CompactTicket> for EndpointAddr {
48 fn from(val: CompactTicket) -> Self {
49 EndpointAddr::new(val.0)
50 }
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct IdPublishedData {
55 pub ticket: Option<CompactTicket>,
57 pub head: Option<ShortEventId>,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct IdResolvedData {
65 pub published: IdPublishedData,
66 pub timestamp: u64,
67}