endpointticket

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 11 Imported by: 9 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package endpointticket encodes and decodes Rust-compatible iroh endpoint tickets.

An endpoint ticket is a compact string form of an endpoint address for out-of-band sharing. The string starts with "endpoint" followed by lowercase base32 without padding.

The Go API is not stable before v1 and may change in any v0 release.

Index

Examples

Constants

View Source
const (
	// Kind is the string prefix for endpoint tickets.
	Kind = "endpoint"

	// MaxAddrs is the maximum number of addresses accepted in a ticket.
	// It is a memory-exhaustion guard, not a wire-compatibility limit.
	MaxAddrs = 65536
)

Variables

View Source
var (
	// ErrTrailingBytes is returned when a ticket has extra data after the
	// endpoint address.
	ErrTrailingBytes = errors.New("endpoint ticket: trailing bytes")
	// ErrTruncated is returned when a ticket ends before a complete field.
	ErrTruncated = errors.New("endpoint ticket: truncated")
	// ErrVarintOverflow is returned when a varint field exceeds 64 bits.
	ErrVarintOverflow = errors.New("endpoint ticket: varint overflow")
)
View Source
var (
	// ErrMissingPrefix is returned when a ticket does not start with
	// "endpoint".
	ErrMissingPrefix = &ParseError{Kind: ParseErrorKindKind, Expected: Kind}
	// ErrEncoding is returned when the ticket payload is not valid base32.
	ErrEncoding = &ParseError{Kind: ParseErrorKindEncoding}
	// ErrDecode is returned when the decoded bytes are not a valid endpoint
	// ticket payload.
	ErrDecode = &ParseError{Kind: ParseErrorKindPostcard}
	// ErrVerify is returned when decoded bytes fail semantic validation.
	ErrVerify = &ParseError{Kind: ParseErrorKindVerify}
)

Functions

func Decode

func Decode(s string) (netaddr.EndpointAddr, error)

Decode parses s as an endpoint ticket and returns its endpoint address.

Example
package main

import (
	"fmt"

	"github.com/tmc/go-iroh/endpointticket"
)

func main() {
	addr, err := endpointticket.Decode("endpointacxfr74igmsbvsbnn73wcecg5vt3kbzncqwfrdiampuufwnhkublmaqacbuhi5dqhixs6zdfojyc43lffyxqcad7aaaadaai")
	if err != nil {
		panic(err)
	}
	fmt.Println(addr.ID)
	fmt.Println(len(addr.Addrs()))

}
Output:
ae58ff8833241ac82d6ff7611046ed67b5072d142c588d0063e942d9a75502b6
2

func Encode

func Encode(addr netaddr.EndpointAddr) string

Encode returns the ticket string for addr.

func EncodeString

func EncodeString(t TicketCodec) string

EncodeString returns t's canonical string form.

func RegisterEndpoint

func RegisterEndpoint(r *Registry) error

RegisterEndpoint registers the endpoint ticket decoder in r.

func ShortAddr

func ShortAddr(addr netaddr.EndpointAddr) netaddr.EndpointAddr

ShortAddr returns addr with direct IP and custom addresses removed.

Types

type Decoder

type Decoder func([]byte) (TicketCodec, error)

Decoder decodes a ticket from its byte representation.

type ParseError

type ParseError struct {
	Kind     ParseErrorKind
	Expected string
	Message  string
	Err      error
}

ParseError reports a structured ticket parse failure.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Is

func (e *ParseError) Is(target error) bool

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

type ParseErrorKind

type ParseErrorKind string

ParseErrorKind classifies ticket parse failures.

const (
	// ParseErrorKindKind means the ticket string had the wrong kind prefix.
	ParseErrorKindKind ParseErrorKind = "kind"
	// ParseErrorKindEncoding means the ticket payload was not valid base32.
	ParseErrorKindEncoding ParseErrorKind = "encoding"
	// ParseErrorKindPostcard means the payload looked like this ticket kind but
	// did not decode as the ticket byte format.
	ParseErrorKindPostcard ParseErrorKind = "postcard"
	// ParseErrorKindVerify means decoded bytes failed semantic validation.
	ParseErrorKindVerify ParseErrorKind = "verify"
)

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry decodes tickets by kind.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty ticket decoder registry.

func (*Registry) DecodeBytes

func (r *Registry) DecodeBytes(kind string, b []byte) (TicketCodec, error)

DecodeBytes decodes bytes as a ticket of kind.

func (*Registry) DecodeString

func (r *Registry) DecodeString(s string) (TicketCodec, error)

DecodeString decodes s using the registered kind prefix.

func (*Registry) Register

func (r *Registry) Register(kind string, decoder Decoder) error

Register adds decoder for kind. Kind must be non-empty and unique.

type Ticket

type Ticket struct {
	// contains filtered or unexported fields
}

Ticket is an endpoint ticket.

func DecodeBytes

func DecodeBytes(b []byte) (Ticket, error)

DecodeBytes decodes an endpoint ticket from its byte representation.

func DecodeString

func DecodeString(s string) (Ticket, error)

DecodeString parses s as an endpoint ticket.

func New

func New(addr netaddr.EndpointAddr) Ticket

New returns a ticket for addr.

func Parse

func Parse(s string) (Ticket, error)

Parse parses s as an endpoint ticket.

func Short

func Short(addr netaddr.EndpointAddr) Ticket

Short returns a ticket for addr containing only the endpoint id and relay URLs.

func (Ticket) Addr

func (t Ticket) Addr() netaddr.EndpointAddr

Addr returns the endpoint address in t.

func (Ticket) EncodeBytes

func (t Ticket) EncodeBytes() []byte

EncodeBytes returns the ticket's byte representation.

func (Ticket) EncodeString

func (t Ticket) EncodeString() string

EncodeString returns the encoded ticket string.

func (Ticket) Kind

func (t Ticket) Kind() string

Kind returns the ticket kind prefix.

func (Ticket) MarshalText

func (t Ticket) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Ticket) Short

func (t Ticket) Short() Ticket

Short returns a ticket containing only the endpoint id and relay URLs.

func (Ticket) String

func (t Ticket) String() string

String returns the encoded ticket string.

func (*Ticket) UnmarshalText

func (t *Ticket) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type TicketCodec

type TicketCodec interface {
	Kind() string
	EncodeBytes() []byte
	EncodeString() string
}

TicketCodec is the generic shape of an iroh ticket implementation.

It mirrors Rust's iroh_tickets::Ticket trait: a ticket has a lowercase kind prefix, a byte representation, and a canonical string form of kind plus base32-without-padding bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL