altcha

package
v0.0.0-...-e4f123b Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSolutionPayload

func CreateSolutionPayload(algorithm, challenge, salt string, number int, hmacKey string) (string, error)

CreateSolutionPayload creates a solution payload (for testing)

func SolveChallenge

func SolveChallenge(challenge *Challenge, hmacKey string, maxAttempts int) (string, error)

SolveChallenge finds a solution to a challenge (for testing)

func ValidateChallenge

func ValidateChallenge(challenge *Challenge, hmacKey string) bool

ValidateChallenge validates a challenge structure

func VerifySolution

func VerifySolution(payload, hmacKey string, checkExpires bool) (bool, error)

VerifySolution verifies an ALTCHA solution payload

Types

type Challenge

type Challenge struct {
	Algorithm     string         `json:"algorithm"`
	Challenge     string         `json:"challenge"`
	MaxNumber     int            `json:"maxNumber"`
	Salt          string         `json:"salt"`
	Signature     string         `json:"signature"`
	CodeChallenge *CodeChallenge `json:"codeChallenge,omitempty"`
}

Challenge represents an ALTCHA challenge

func CreateChallenge

func CreateChallenge(opts ChallengeOptions) (*Challenge, error)

CreateChallenge generates a new ALTCHA challenge

type ChallengeOptions

type ChallengeOptions struct {
	Algorithm  string
	MaxNumber  int
	SaltLength int
	HMACKey    string
	Expires    time.Time
}

ChallengeOptions contains options for creating a challenge

type CodeChallenge

type CodeChallenge struct {
	Image  string `json:"image"`  // base64-encoded PNG
	Length int    `json:"length"` // code length
}

CodeChallenge represents an optional visual code challenge

func GenerateCodeChallenge

func GenerateCodeChallenge(length int) (*CodeChallenge, string, error)

GenerateCodeChallenge creates a visual code challenge (image with random code)

type Solution

type Solution struct {
	Algorithm string `json:"algorithm"`
	Challenge string `json:"challenge"`
	Number    int    `json:"number"`
	Salt      string `json:"salt"`
	Signature string `json:"signature"`
}

Solution represents an ALTCHA solution

func ParsePayload

func ParsePayload(payload string) (*Solution, error)

ParsePayload decodes and parses an ALTCHA payload

Jump to

Keyboard shortcuts

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