Help us shape the future of Go! Take the 2026 Go Developer Survey

otp

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 7 Imported by: 0

README

OTP primitives

Generate() returns a cryptographically random six-digit decimal code. NewDigester(key) copies a secret of at least 32 bytes. Digest(fields...) binds ordered proof fields with HMAC-SHA256; Key(scope, value) provides separate keyed fingerprints for private rate-limit identities. Compare digests with hmac.Equal.

Keep the key stable across replicas and restarts. Use the same proof field order when issuing and verifying; changing the key or field order invalidates proofs. This package provides no delivery, storage, eligibility, expiry, one-time consumption, rate limiting or recovery policy. The application must supply those protections.

Documentation

Overview

Package otp generates decimal codes and keyed proof digests. It does not own storage, expiration, retries, rate limits, or account eligibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate() (string, error)

Generate returns a uniformly random six-digit code, including leading zeroes.

Types

type Digester

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

Digester copies its key and supports concurrent use.

func NewDigester

func NewDigester(key []byte) (*Digester, error)

func (*Digester) Digest

func (d *Digester) Digest(fields ...string) []byte

Digest binds an ordered set of proof fields without ambiguous concatenation. Callers must use the same field order during creation and verification.

func (*Digester) Key

func (d *Digester) Key(scope, value string) []byte

Key separates purposes, including proof storage and private rate-limit keys.

Jump to

Keyboard shortcuts

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