account

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: AGPL-3.0 Imports: 26 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 account coordinates official-service credentials outside relay handshakes.

Index

Constants

View Source
const (
	CacheLoadTimeout = 100 * time.Millisecond
	RequestTimeout   = 8 * time.Second
	// The authority waits up to 15 seconds for the mail provider to accept delivery.
	EmailRequestTimeout = 20 * time.Second
	RefreshInterval     = time.Minute
	TicketRenewalLead   = time.Hour
	PollInterval        = 5 * time.Second
	MinimumRetry        = time.Second
	MaximumRetry        = time.Minute
	TicketMargin        = time.Minute
)

Variables

View Source
var (
	// ErrInvalidState reports a corrupt, oversized, or mismatched local account
	// file that requires manual repair instead of retrying automatically.
	ErrInvalidState = errors.New("invalid account state")
	// ErrUnreadableState reports a local account file that cannot be read due
	// to filesystem permissions or an unexpected file type.
	ErrUnreadableState = errors.New("account state unreadable")
)
View Source
var ErrNotConfigured = errors.New("official account service is not configured")
View Source
var ErrSuperseded = errors.New("account changed while the operation was in progress")

Functions

func CommandErrorCode added in v0.1.4

func CommandErrorCode(err error) string

CommandErrorCode lets interactive clients localize a recovery action without parsing authority messages.

Types

type Challenge

type Challenge struct {
	ID        string `json:"id"`
	Mode      string `json:"mode"`
	Bits      uint8  `json:"bits"`
	ExpiresAt uint64 `json:"expires_at"`
}

type Config

type Config struct {
	URL         string
	Root        [32]byte
	Store       Store
	Client      HTTPClient
	Now         func() time.Time
	ResolveNode func(string) (Node, bool)
	Diagnostics diagnostics.Sink
}

type Credential

type Credential struct {
	Account  [16]byte `json:"account"`
	ID       [16]byte `json:"id"`
	Secret   string   `json:"secret"`
	Username string   `json:"username,omitempty"`
}

type FileStore

type FileStore struct{ Path string }

func (FileStore) Load added in v0.1.5

func (store FileStore) Load(ctx context.Context) (Record, error)

Load reads the latest committed record without taking the write lock. statefile.Write replaces files atomically, so concurrent readers always see a complete state file and never contend on an exclusive lock during polling.

func (FileStore) Update

func (store FileStore) Update(ctx context.Context, apply func(Record) (Record, error)) (Record, error)

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

type MemoryStore

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

func (*MemoryStore) Load added in v0.1.5

func (store *MemoryStore) Load(ctx context.Context) (Record, error)

func (*MemoryStore) Update

func (store *MemoryStore) Update(ctx context.Context, apply func(Record) (Record, error)) (Record, error)

type Nickname added in v0.1.4

type Nickname struct {
	Value        string `json:"value"`
	NextChangeAt int64  `json:"next_change_at"`
}

type Node

type Node struct{ Key [32]byte }

type PendingEmail added in v0.1.4

type PendingEmail struct {
	Address   string    `json:"address"`
	Challenge Challenge `json:"challenge"`
}

type Profile added in v0.1.4

type Profile struct {
	Revision uint64   `json:"revision"`
	Nickname Nickname `json:"nickname,omitzero"`
	Email    string   `json:"email,omitempty"`
}

type Proof

type Proof struct {
	Challenge Challenge `json:"challenge"`
	Solution  string    `json:"solution"`
}

type Record

type Record struct {
	Issuer       string                       `json:"issuer"`
	SetupSecret  string                       `json:"setup_secret,omitempty"`
	Credential   *Credential                  `json:"credential,omitempty"`
	Profile      Profile                      `json:"profile,omitzero"`
	PendingEmail PendingEmail                 `json:"pending_email,omitzero"`
	Certificate  string                       `json:"certificate,omitempty"`
	Ticket       string                       `json:"ticket,omitempty"`
	Entitlement  serviceauthority.Entitlement `json:"entitlement"`
	Denial       string                       `json:"denial,omitempty"`
	Proof        *Proof                       `json:"proof,omitempty"`
}

type RefreshOutcome added in v0.1.4

type RefreshOutcome string

RefreshOutcome describes what a completed attempt achieved for its caller.

const (
	RefreshSucceeded         RefreshOutcome = "refreshed"
	RefreshNeedsRegistration RefreshOutcome = "registration_required"
	RefreshNeedsEmail        RefreshOutcome = "email_required"
)

type Service

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

func New

func New(config Config) (*Service, error)

func (*Service) Close

func (service *Service) Close()

func (*Service) ConfirmProfileEmail added in v0.1.4

func (service *Service) ConfirmProfileEmail(ctx context.Context, accountID, challengeID, code string) error

func (*Service) Login

func (service *Service) Login(ctx context.Context, username, password string) error

func (*Service) NewShareAuthorization added in v0.1.4

func (service *Service) NewShareAuthorization(ctx context.Context) *ShareAuthorization

NewShareAuthorization binds the selected local credential before any official relay attempts registration. Setup and ticket renewal can finish in the background.

func (*Service) ObserveAccount added in v0.1.4

func (service *Service) ObserveAccount() func()

ObserveAccount maintains the selected account for the lifetime of a visible view.

func (*Service) PrepareShareAuthorization added in v0.1.7

func (service *Service) PrepareShareAuthorization(ctx context.Context) *ShareAuthorization

PrepareShareAuthorization lets independent routes register while the local account store resolves. Every official route waits on the same selection.

func (*Service) RefreshOnce added in v0.1.4

func (service *Service) RefreshOnce(ctx context.Context) (RefreshOutcome, error)

RefreshOnce runs one explicit attempt without activating background maintenance. A usable cached ticket can coexist with an unfinished or failed attempt.

func (*Service) Register added in v0.1.4

func (service *Service) Register(ctx context.Context) (err error)

Register runs one user-requested attempt through issuance or an email handoff. The operation lock also keeps a refresh or a double submission from starting a second solve.

func (*Service) ReloadSelection added in v0.1.4

func (service *Service) ReloadSelection(ctx context.Context) error

ReloadSelection publishes the shared local selection to observers independently of authority operations.

func (*Service) RequestEmail

func (service *Service) RequestEmail(ctx context.Context, email string) error

func (*Service) RequestProfileEmail added in v0.1.4

func (service *Service) RequestProfileEmail(ctx context.Context, accountID, address string) error

func (*Service) RevokeCredential

func (service *Service) RevokeCredential(ctx context.Context, accountID string, credential [16]byte) error

func (*Service) SetNickname added in v0.1.4

func (service *Service) SetNickname(ctx context.Context, accountID, nickname string) error

func (*Service) SetPassword

func (service *Service) SetPassword(ctx context.Context, accountID, username, password string) error

func (*Service) Snapshot

func (service *Service) Snapshot() (Snapshot, <-chan struct{})

func (*Service) VerifyEmail

func (service *Service) VerifyEmail(ctx context.Context, code string) error

VerifyEmail completes registration with the authority before reporting success.

type ShareAuthorization added in v0.1.4

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

ShareAuthorization owns the identity shared by all official relay registrations in one share. Its state and credential references are guarded by Service.mu.

func (*ShareAuthorization) Close added in v0.1.4

func (share *ShareAuthorization) Close()

func (*ShareAuthorization) Source added in v0.1.4

func (share *ShareAuthorization) Source(address string) *Source

type Snapshot

type Snapshot struct {
	Active                   bool                       `json:"active"`
	State                    State                      `json:"state"`
	EmailCodePending         bool                       `json:"email_code_pending,omitempty"`
	Account                  string                     `json:"account,omitempty"`
	Credential               string                     `json:"credential,omitempty"`
	Username                 string                     `json:"username,omitempty"`
	Profile                  Profile                    `json:"profile"`
	PendingEmail             PendingEmail               `json:"pending_email,omitzero"`
	Allowance                serviceauthority.Allowance `json:"allowance"`
	RemainingBytes           uint64                     `json:"remaining_bytes"`
	RemainingPrioritySeconds uint64                     `json:"remaining_priority_seconds"`
	ResetAt                  time.Time                  `json:"reset_at,omitzero"`
	ValidUntil               time.Time                  `json:"valid_until,omitzero"`
	TicketExpires            time.Time                  `json:"ticket_expires,omitzero"`
	RetryAt                  time.Time                  `json:"retry_at,omitzero"`
	RegistrationPermille     uint16                     `json:"registration_permille,omitempty"`
	Reason                   string                     `json:"reason,omitempty"`
	StorageErr               error                      `json:"-"`
}

func (Snapshot) Equal added in v0.1.8

func (s Snapshot) Equal(other Snapshot) bool

Equal reports whether two snapshots carry identical wire-visible state, ignoring the non-serialized StorageErr so callers never pass error values to reflect.DeepEqual.

type Source

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

func (*Source) ReserveRegistrationAuthorization added in v0.1.4

func (source *Source) ReserveRegistrationAuthorization() serviceauthority.RegistrationAuthorization

type State

type State string
const (
	Pending              State = "pending_setup"
	RegistrationRequired State = "registration_required"
	Registering          State = "registering"
	EmailRequired        State = "email_required"
	Ready                State = "ready"
	RefreshRequired      State = "refresh_required"
	Refreshing           State = "refreshing"
	Unavailable          State = "temporarily_unavailable"
	StorageError         State = "storage_error"
	Denied               State = "denied"
)

type Store

type Store interface {
	Load(context.Context) (Record, error)
	Update(context.Context, func(Record) (Record, error)) (Record, error)
}

type UnavailableStore added in v0.1.8

type UnavailableStore struct{ Err error }

UnavailableStore rejects every persistence operation with Err so callers with an invalid configuration path (such as an empty WINDSHARE_CONFIG_FILE) surface a storage error instead of silently falling back to MemoryStore.

func (UnavailableStore) Load added in v0.1.8

func (store UnavailableStore) Load(ctx context.Context) (Record, error)

func (UnavailableStore) Update added in v0.1.8

func (store UnavailableStore) Update(ctx context.Context, _ func(Record) (Record, error)) (Record, error)

Jump to

Keyboard shortcuts

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