account

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 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
	PollInterval        = 5 * time.Second
	MinimumRetry        = time.Second
	MaximumRetry        = time.Minute
	TicketMargin        = time.Minute
)

Variables

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)
}

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) 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) 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) 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, 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"`
	ResetAt              time.Time                  `json:"reset_at"`
	ValidUntil           time.Time                  `json:"valid_until"`
	TicketExpires        time.Time                  `json:"ticket_expires"`
	RetryAt              time.Time                  `json:"retry_at"`
	RegistrationPermille uint16                     `json:"registration_permille,omitempty"`
	Reason               string                     `json:"reason,omitempty"`
}

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"
	Denied               State = "denied"
)

type Store

type Store interface {
	Update(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