serviceauthority

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0, AGPL-3.0 Imports: 10 Imported by: 1 module, 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 serviceauthority verifies account authority records without I/O.

Index

Constants

View Source
const (
	CertificateDomain      = "windshare/authority-certificate/v1\x00"
	TicketDomain           = "windshare/account-ticket/v1\x00"
	DescriptorDomain       = "windshare/node-descriptor/v2\x00"
	BlocksDomain           = "windshare/public-blocks/v1\x00"
	MaximumTicketBytes     = 512
	MaximumDescriptorBytes = 16 << 10
	MaximumResponseBytes   = 512 << 10
	MaximumCounter         = 1<<53 - 1
	DaySeconds             = 86400
	ClockSkew              = 300
	TicketLifetime         = 12 * 60 * 60
	EntitlementLifetime    = 5 * 60
	CertificateLifetime    = 180 * DaySeconds
)

Variables

View Source
var (
	ErrFormat    = errors.New("invalid authority record")
	ErrSignature = errors.New("authority signature rejected")
	ErrExpired   = errors.New("authority record expired")
	ErrRollback  = errors.New("authority signing generation rollback or equivocation")
)

Functions

func Compare

func Compare(previous, next Generation) error

Compare is independent of wall time: expiry never erases the rollback barrier.

func DecodeBase64

func DecodeBase64(value string, limit int) ([]byte, error)

func PublicKey

func PublicKey(value string) ([32]byte, error)

func VerifySigned

func VerifySigned(domain, encoded string, key [32]byte, limit int) ([]byte, error)

Types

type AdmissionState

type AdmissionState uint8
const (
	AdmissionReady AdmissionState = iota + 1
	AdmissionPendingSetup
	AdmissionExpired
	AdmissionTemporaryFailure
	AdmissionDenied
	AdmissionUserActionRequired
	AdmissionPendingAttribution
)

func (AdmissionState) Name

func (state AdmissionState) Name() string

type Allowance

type Allowance string
const (
	AllowanceAvailable Allowance = "available"
	AllowanceSpent     Allowance = "spent"
	AllowanceStale     Allowance = "stale"
)

type Descriptor

type Descriptor struct {
	Version       int    `json:"version"`
	NodeID        string `json:"node_id"`
	NodeKey       string `json:"node_key"`
	RelayEndpoint string `json:"relay_endpoint"`
	Services      struct {
		Relay bool `json:"relay"`
		STUN  bool `json:"stun"`
	} `json:"services"`
	STUN             []string `json:"stun"`
	Zone             string   `json:"zone"`
	Region           string   `json:"region"`
	Capacity         *uint64  `json:"capacity_bytes_per_second"`
	Classes          []string `json:"classes"`
	IssuedAt         uint64   `json:"issued_at"`
	ExpiresAt        uint64   `json:"expires_at"`
	Available        bool     `json:"relay_available"`
	Anonymous        bool     `json:"anonymous"`
	ConsoleURL       string   `json:"console_url"`
	AccountLoginPage string   `json:"account_login_page,omitempty"`
}

func InspectDescriptor

func InspectDescriptor(data []byte, now time.Time) (Descriptor, error)

InspectDescriptor verifies a self-asserted identity for manual enrollment. Official admission must still pin that key with VerifyDescriptor.

func VerifyDescriptor

func VerifyDescriptor(data []byte, key [32]byte, now time.Time) (Descriptor, error)

func (Descriptor) RelayBaseURL

func (descriptor Descriptor) RelayBaseURL() string

RelayBaseURL is for APIs that append their protocol path. The signed descriptor carries the complete canonical WebSocket endpoint, never an ambiguous base.

type Entitlement

type Entitlement struct {
	Version        uint64 `json:"version"`
	Day            uint64 `json:"day"`
	ValidUntil     uint64 `json:"valid_until"`
	RemainingBytes uint64 `json:"remaining_bytes"`
}

func Advance

func Advance(previous, next Entitlement) Entitlement

func (Entitlement) Allowance

func (value Entitlement) Allowance(now time.Time) Allowance

func (Entitlement) ResetAt

func (value Entitlement) ResetAt() time.Time

func (Entitlement) ValidSnapshot

func (value Entitlement) ValidSnapshot(issued uint64) bool

type Generation

type Generation struct {
	Issuer    [32]byte
	Number    uint64
	Key       [32]byte
	NotBefore uint64
	ExpiresAt uint64
}

func VerifyGeneration

func VerifyGeneration(certificate string, root [32]byte) (Generation, error)

func (Generation) Usable

func (generation Generation) Usable(now time.Time) bool

type RegistrationAuthorization

type RegistrationAuthorization struct {
	State       AdmissionState
	Bearer      string                  `json:"-"`
	Changed     <-chan struct{}         `json:"-"`
	Cause       error                   `json:"-"`
	Reservation RegistrationReservation `json:"-"`
}

A waiting RegistrationAuthorization and its Changed signal describe the same revision so progress cannot be missed while starting a wait.

type RegistrationDelivery added in v0.1.4

type RegistrationDelivery uint8
const (
	RegistrationMayHaveBeenSent RegistrationDelivery = iota
	RegistrationNotSent
)

type RegistrationReservation added in v0.1.4

type RegistrationReservation func(RegistrationDelivery)

A RegistrationReservation pins attribution for one ready attempt. Settle it with the dial result before applying any local cancellation or admission policy.

func (RegistrationReservation) Finish added in v0.1.4

func (reservation RegistrationReservation) Finish(delivery RegistrationDelivery)

type Ticket

type Ticket struct {
	Issuer      [32]byte
	KeyID       uint64
	Account     [16]byte
	Credential  [16]byte
	IssuedAt    uint64
	ExpiresAt   uint64
	Entitlement Entitlement
}

func VerifyTicket

func VerifyTicket(encoded string, generation Generation, now time.Time) (Ticket, error)

Jump to

Keyboard shortcuts

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