1use iroh_tickets::Ticket as _;2use napi::bindgen_prelude::*;3use napi_derive::napi;45use crate::EndpointAddr;67/// A token containing information for establishing a connection to an endpoint.8910pub struct EndpointTicket(iroh_tickets::endpoint::EndpointTicket);1112impl From<iroh_tickets::endpoint::EndpointTicket> for EndpointTicket {13 fn from(t: iroh_tickets::endpoint::EndpointTicket) -> Self {14 EndpointTicket(t)15 }16}171819impl EndpointTicket {20 /// Wrap an [`EndpointAddr`] into a ticket.21 22 pub fn from_addr(addr: &EndpointAddr) -> Result<Self> {23 let inner: iroh::EndpointAddr = addr.try_into()?;24 Ok(iroh_tickets::endpoint::EndpointTicket::new(inner).into())25 }2627 /// Parse a ticket from its base32 string form.28 29 pub fn from_string(s: String) -> Result<Self> {30 let ticket = iroh_tickets::endpoint::EndpointTicket::decode_string(&s)31 .map_err(anyhow::Error::from)?;32 Ok(EndpointTicket(ticket))33 }3435 /// The [`EndpointAddr`] embedded in this ticket.36 37 pub fn endpoint_addr(&self) -> EndpointAddr {38 self.0.endpoint_addr().clone().into()39 }4041 /// Base32 string form.42 43 pub fn to_string(&self) -> String {44 self.0.to_string()45 }46}