Versions in this module Expand all Collapse all v0 v0.1.0 Aug 20, 2026 Changes in this version + var ErrTOTPAlreadyEnrolled = errors.New("totp: already enrolled") + var ErrTOTPInvalid = errors.New("totp: invalid code") + var ErrTOTPNotEnrolled = errors.New("totp: not enrolled") + var ErrTOTPNotVerified = errors.New("totp: enrollment not verified") + var ErrTOTPRateLimited = errors.New("totp: rate limited") + var ErrTOTPReplayed = errors.New("totp: code already used") + type AESEncryptor struct + func NewAESEncryptor(key []byte, rotated ...[]byte) (*AESEncryptor, error) + func (e *AESEncryptor) Decrypt(ciphertext string) (string, error) + func (e *AESEncryptor) Encrypt(plaintext string) (string, error) + type Algorithm int + const AlgorithmSHA1 + const AlgorithmSHA256 + const AlgorithmSHA512 + func (a Algorithm) String() string + type Config struct + Algorithm Algorithm + Digits int + Encryptor Encryptor + Issuer string + Limiter Limiter + Period uint64 + SecretSize int + Skew uint + type Credential struct + CreatedAt time.Time + ID string + LastUsedCounter uint64 + Secret string + UserID string + Verified bool + type Encryptor interface + Decrypt func(ciphertext string) (string, error) + Encrypt func(plaintext string) (string, error) + type Limiter interface + Allow func(ctx context.Context, key string) error + type Option func(*Config) + func WithAlgorithm(a Algorithm) Option + func WithDigits(d int) Option + func WithEncryptor(e Encryptor) Option + func WithLimiter(l Limiter) Option + func WithPeriod(p uint64) Option + func WithSecretSize(n int) Option + func WithSkew(s uint) Option + type Service struct + func NewService(store Store, issuer string, opts ...Option) (*Service, error) + func (s *Service) ConfirmEnrollment(ctx context.Context, userID, code string) error + func (s *Service) Enroll(ctx context.Context, userID, accountName string) (secret, uri string, err error) + func (s *Service) Generate(secret string, t time.Time) (string, error) + func (s *Service) ReplaceEnrollment(ctx context.Context, userID, accountName string) (secret, uri string, err error) + func (s *Service) Unenroll(ctx context.Context, userID string) error + func (s *Service) Validate(ctx context.Context, userID, code string) error + type Store interface + ConfirmEnrollment func(ctx context.Context, userID, pendingID string, counter uint64) (*Credential, error) + DeleteTOTP func(ctx context.Context, userID string) error + EnrollPending func(ctx context.Context, cred *Credential) error + GetActiveTOTP func(ctx context.Context, userID string) (*Credential, error) + GetPendingTOTP func(ctx context.Context, userID string) (*Credential, error) + ReplacePending func(ctx context.Context, cred *Credential) error + SaveTOTP func(ctx context.Context, cred *Credential) error