trustpin

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLegacyAccountFile = "accounts.json"
	DefaultStoreFileName     = "accounts.enc"
	DefaultKeyFileName       = "accounts.key"
	DefaultInterval          = 30
	DefaultDigits            = 6
)
View Source
const (
	AlgorithmSHA1   = "SHA1"
	AlgorithmSHA256 = "SHA256"
	AlgorithmSHA512 = "SHA512"

	TypeTOTP  = "totp"
	TypeHOTP  = "hotp"
	TypeSteam = "steam"
)

Variables

This section is empty.

Functions

func BuildOTPAuthURI added in v1.4.0

func BuildOTPAuthURI(account Account) string

func FormatOTP

func FormatOTP(otp string) string

func GenerateHOTP added in v1.4.0

func GenerateHOTP(secret string, counter int64, digits int, algorithm string) (string, error)

func GenerateQRCodePNG added in v1.4.0

func GenerateQRCodePNG(account Account, size int) ([]byte, error)

GenerateQRCodePNG creates a QR code PNG for the account's otpauth URI.

func GenerateSteamCode added in v1.4.0

func GenerateSteamCode(secret string, interval int64) (string, int64, error)

func GenerateTOTP

func GenerateTOTP(secret string, interval int64, digits int) (otp string, timeRemaining int64, err error)

func GenerateTOTPWithAlgorithm added in v1.4.0

func GenerateTOTPWithAlgorithm(secret string, interval int64, digits int, algorithm string) (otp string, timeRemaining int64, err error)

func NormalizeAlgorithm added in v1.4.0

func NormalizeAlgorithm(alg string) string

func NormalizeType added in v1.4.0

func NormalizeType(t string) string

func ParseOtpauthURI

func ParseOtpauthURI(uri string) (account string, secret string, interval int, digits int, algorithm string, otpType string, counter int64, err error)

func PreviewSecret

func PreviewSecret(secret string) string

func ReadQRFromFile

func ReadQRFromFile(fp string) (string, error)

func SplitAccountName

func SplitAccountName(name string) (issuer, label string, hasIssuer bool)

func ValidateAccountInput

func ValidateAccountInput(account, secret string) error

func ValidateDigits

func ValidateDigits(digits int) error

Types

type Account

type Account struct {
	Name      string   `json:"Name"`
	Secret    string   `json:"Secret"`
	Interval  int64    `json:"Interval"`
	Digits    int      `json:"Digits"`
	Algorithm string   `json:"Algorithm,omitempty"`
	Type      string   `json:"Type,omitempty"`
	Counter   int64    `json:"Counter,omitempty"`
	Tags      []string `json:"Tags,omitempty"`
	Favorite  bool     `json:"Favorite,omitempty"`
	Notes     string   `json:"Notes,omitempty"`
	SortOrder int      `json:"SortOrder,omitempty"`
	Archived  bool     `json:"Archived,omitempty"`
}

func ParseQRPayload

func ParseQRPayload(payload string) ([]Account, error)

type AccountChange

type AccountChange struct {
	Name   string `json:"name"`
	Action string `json:"action"`
}

type AccountSnapshot

type AccountSnapshot struct {
	Account         Account  `json:"-"`
	Name            string   `json:"name"`
	DisplayName     string   `json:"displayName"`
	Issuer          string   `json:"issuer"`
	Label           string   `json:"label"`
	OTP             string   `json:"otp"`
	FormattedOTP    string   `json:"formattedOTP"`
	TimeRemaining   int64    `json:"timeRemaining"`
	Interval        int64    `json:"interval"`
	Digits          int      `json:"digits"`
	Algorithm       string   `json:"algorithm"`
	Type            string   `json:"type"`
	Counter         int64    `json:"counter,omitempty"`
	Tags            []string `json:"tags,omitempty"`
	Favorite        bool     `json:"favorite"`
	Notes           string   `json:"notes,omitempty"`
	SortOrder       int      `json:"sortOrder"`
	Archived        bool     `json:"archived"`
	StatusLabel     string   `json:"statusLabel"`
	Tone            string   `json:"tone"`
	ProgressPercent int      `json:"progressPercent"`
	PolicyLabel     string   `json:"policyLabel"`
	SecretPreview   string   `json:"secretPreview"`
	ErrorText       string   `json:"errorText,omitempty"`
}

func BuildAccountSnapshot

func BuildAccountSnapshot(account Account) AccountSnapshot

type HealthItem

type HealthItem struct {
	Level   HealthLevel `json:"level"`
	Title   string      `json:"title"`
	Detail  string      `json:"detail"`
	Account string      `json:"account,omitempty"`
}

func AnalyzeAccounts

func AnalyzeAccounts(accounts []Account) []HealthItem

type HealthLevel

type HealthLevel string
const (
	HealthLevelCritical HealthLevel = "critical"
	HealthLevelWarning  HealthLevel = "warning"
	HealthLevelInfo     HealthLevel = "info"
)

type HealthReport

type HealthReport struct {
	Items   []HealthItem  `json:"items"`
	Summary HealthSummary `json:"summary"`
	Total   int           `json:"total"`
}

type HealthSummary

type HealthSummary struct {
	Critical int `json:"critical"`
	Warning  int `json:"warning"`
	Info     int `json:"info"`
}

func SummarizeHealth

func SummarizeHealth(items []HealthItem) HealthSummary

type ImportResult

type ImportResult struct {
	Summary UpsertSummary `json:"summary"`
	Skipped []string      `json:"skipped"`
}

type Service

type Service struct {
	StorePath  string
	KeyPath    string
	LegacyPath string
}

func NewService

func NewService(storePath string) Service

func (Service) DeleteAccount

func (s Service) DeleteAccount(account string) (int, error)

func (Service) HealthReport

func (s Service) HealthReport() (HealthReport, error)

func (Service) ImportAccountsFromQR

func (s Service) ImportAccountsFromQR(qrFile string) (ImportResult, error)

func (Service) LoadAccounts

func (s Service) LoadAccounts() ([]Account, error)

func (Service) MigrateLegacyFrom

func (s Service) MigrateLegacyFrom(path string, removeSource bool) (UpsertSummary, error)

func (Service) SaveAccounts

func (s Service) SaveAccounts(accounts []Account) error

func (Service) SetAccountArchived added in v1.4.0

func (s Service) SetAccountArchived(name string, archived bool) error

func (Service) UpdateAccount

func (s Service) UpdateAccount(currentName string, updated Account) error

func (Service) UpsertAccounts

func (s Service) UpsertAccounts(incoming []Account) (UpsertSummary, error)

type UpsertSummary

type UpsertSummary struct {
	Added    int             `json:"added"`
	Replaced int             `json:"replaced"`
	Changes  []AccountChange `json:"changes"`
}

Jump to

Keyboard shortcuts

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