enroll

package
v0.0.0-...-09b25d6 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 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 enroll is the station's side of a rig joining it: one-time codes that carry the station key's fingerprint, the /v1/station profile the rig checks that fingerprint against, the /v1/enroll endpoint, and mDNS so a rig on the LAN finds the station without a URL.

Index

Constants

View Source
const (
	// Service is the mDNS service a station advertises.
	Service = "_vibium-station._tcp"
	// CodeLifetime is how long an enrollment code stays usable.
	CodeLifetime = 15 * time.Minute
)

Variables

This section is empty.

Functions

func Advertise(name string, port int) (func(), error)

Advertise announces the station on the LAN over mDNS. The returned function stops it.

func Discover

func Discover(ctx context.Context, timeout time.Duration) (string, error)

Discover looks for a station on the LAN and returns its URL.

func Fingerprint

func Fingerprint(pk nostr.PubKey) string

Fingerprint is the start of the station's key, the last group of every enrollment code: the rig refuses a station whose key does not match it.

func NewCode

func NewCode(pk nostr.PubKey) string

NewCode makes a code such as ABCD-1234-7F3A: two random groups and the station key's fingerprint.

func ParseCode

func ParseCode(code string) (normalized, fingerprint string, err error)

ParseCode normalizes a typed code and returns it with its fingerprint.

Types

type Codes

type Codes interface {
	UseCode(ctx context.Context, code string, now time.Time) error
}

Codes burns codes: the sqlite store does.

type Handler

type Handler struct {
	Key       nostr.SecretKey
	Name      string
	TunnelURL string
	Devices   station.DeviceStore
	Events    station.EventStore
	Codes     Codes
	Audit     station.AuditSink // optional
	Logf      func(format string, args ...any)
}

Handler serves the profile and enrollment endpoints.

func (*Handler) Profile

func (h *Handler) Profile() (Profile, error)

Profile signs the station's profile.

func (*Handler) ServeEnroll

func (h *Handler) ServeEnroll(w http.ResponseWriter, r *http.Request)

ServeEnroll is POST /v1/enroll: a kind 7702 event signed by the rig, naming this station, with a live code and the rig's devices.

func (*Handler) ServeProfile

func (h *Handler) ServeProfile(w http.ResponseWriter, r *http.Request)

ServeProfile is GET /v1/station.

type Offer

type Offer struct {
	Name      string             `json:"name"`
	Kind      string             `json:"kind"`
	Caps      []string           `json:"caps"`
	Key       string             `json:"key,omitempty"`
	Shortcuts []station.Shortcut `json:"shortcuts,omitempty"`
	Input     string             `json:"input,omitempty"`      // "touch" or "mouse"
	Extras    string             `json:"extras,omitempty"`     // the rig's viewer extras script path
	Label     string             `json:"label,omitempty"`      // the device's name for people
	Platform  string             `json:"platform,omitempty"`   // "ios", "android", ...
	Model     string             `json:"model,omitempty"`      // "iPhone 15 Pro Max"
	OSVersion string             `json:"os_version,omitempty"` // "26.6"
}

Offer is a device as a rig describes it before it has an id: the name the station will put after its rig id.

func (Offer) Device

func (o Offer) Device(rigID string) station.Device

Device is the offer as the station's device under the rig's id.

type Profile

type Profile struct {
	Name      string      `json:"name"`
	PubKey    string      `json:"pubkey"`
	TunnelURL string      `json:"tunnel_url"`
	Event     nostr.Event `json:"event"`
}

Profile is what GET /v1/station returns: the station's name, key and tunnel URL, signed as its kind 0 event so the rig can check the key.

type Response

type Response struct {
	RigID     string `json:"rig"`
	Station   string `json:"station"` // the station's key, hex
	Name      string `json:"name"`    // the station's name
	TunnelURL string `json:"tunnel_url"`
}

Response is what a successful enrollment returns.

Jump to

Keyboard shortcuts

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