Versions in this module Expand all Collapse all v0 v0.1.0 Jul 24, 2026 Changes in this version + var ErrAlreadyRedeemed = errors.New("already_redeemed") + var ErrCleanupError = errors.New("cleanup_error") + var ErrExpired = errors.New("expired") + var ErrFormat2NoProtocols = errors.New("format-2 requires at least one protocol") + var ErrInstrAutomatedBrowser = errors.New("instr_automated_browser") + var ErrInstrCorrupted = errors.New("instr_corrupted") + var ErrInstrExpired = errors.New("instr_expired") + var ErrInstrFailed = errors.New("instr_failed") + var ErrInstrMissing = errors.New("instr_missing") + var ErrInstrTimeout = errors.New("instr_timeout") + var ErrInvalidSolution = errors.New("invalid_solution") + var ErrInvalidSolutions = errors.New("invalid_solutions") + var ErrInvalidToken = errors.New("invalid_token") + var ErrMissingSolutions = errors.New("missing_solutions") + var ErrMissingToken = errors.New("missing_token") + var ErrNonceStoreError = errors.New("nonce_store_error") + var ErrRSWBitsMustBeEven = errors.New("rsw bits must be even") + var ErrRSWKeypairRequired = errors.New("format-2 rsw requires opts.Keypair") + var ErrScopeMismatch = errors.New("scope_mismatch") + var ErrShortSecret = errors.New("secret must be at least 16 bytes") + var ErrStorageError = errors.New("storage_error") + var ErrStorageNotConfigured = errors.New("storage_not_configured") + var ErrTokenExpired = errors.New("token_expired") + var ErrTokenNotFound = errors.New("token_not_found") + func VerifyInstrumentationResult(meta *InstrumentationMeta, payload *InstrumentationResult) (bool, string) + func VerifyRswSolution(expectedYHex, claimedYHex string) bool + type Cap struct + func NewCap(opts CapOptions) (*Cap, error) + func (c *Cap) CreateChallenge(ctx context.Context) (ChallengeResult, error) + func (c *Cap) RedeemChallenge(ctx context.Context, proof ValidateBody) (ValidateResult, error) + func (c *Cap) ValidateToken(ctx context.Context, token string) ValidateResult + type CapOptions struct + ChallengeCount int + ChallengeDifficulty int + ChallengeSize int + ChallengeTTL time.Duration + ConsumeNonce func(ctx context.Context, signatureHex string, ttl time.Duration) (bool, error) + Extra map[string]any + Format int + Instrumentation bool + InstrumentationOpts *InstrumentationOptions + Keypair *RswKeypair + Protocols []string + RSWT int + Scope string + Secret []byte + SignToken func(data RedeemTokenData) (string, error) + Storage Storage + TokenTTL time.Duration + type ChallengeResult struct + Challenge ChallengeSpec + Challenges []V2Challenge + Expires int64 + Format int + Instrumentation string + Token string + type ChallengeSpec struct + C int + D int + S int + type GenerateOptions struct + ChallengeCount int + ChallengeDifficulty int + ChallengeSize int + Expires time.Duration + Extra map[string]any + Format int + Instrumentation bool + InstrumentationOpts *InstrumentationOptions + Keypair *RswKeypair + Protocols []string + RSWT int + Scope string + Storage Storage + type InstrPayload struct + I string + State map[string]int + Ts int64 + type InstrumentationMeta struct + BlockAutomatedBrowsers bool + ExpectedVals []int + Expires int64 + ID string + Vars []string + func GenerateInstrumentation(opts InstrumentationOptions) (*InstrumentationMeta, string, error) + type InstrumentationOptions struct + BlockAutomatedBrowsers bool + ObfuscationLevel int + TTLMs int64 + type InstrumentationResult struct + I string + State map[string]int + Ts int64 + type MemoryStorage struct + func NewMemoryStorage() *MemoryStorage + func (s *MemoryStorage) CleanupExpired(_ context.Context) error + func (s *MemoryStorage) GetChallengeTokenExpiry(_ context.Context, token string) (time.Time, bool, error) + func (s *MemoryStorage) GetValidationTokenExpiry(_ context.Context, token string) (time.Time, bool, error) + func (s *MemoryStorage) SetChallengeToken(_ context.Context, token string, expiresAt time.Time) error + func (s *MemoryStorage) SetValidationToken(_ context.Context, token string, expiresAt time.Time) error + type RedeemTokenData struct + Expires int64 + Iat int64 + Scope *string + type RswKeypair struct + Bits int + N *big.Int + P *big.Int + Q *big.Int + func DeserializeRswKeypair(s *SerializedRswKeypair) (*RswKeypair, error) + func GenerateRswKeypair(bits ...int) (*RswKeypair, error) + type RswMintResult struct + X_hex string + Y_hex string + type RswMinter struct + G *big.Int + G_hex string + H *big.Int + H_hex string + ModulusBytes int + N *big.Int + N_hex string + T int + func BuildRswMinter(args struct{ ... }) (*RswMinter, error) + func (m *RswMinter) Mint() (*RswMintResult, error) + type SerializedRswKeypair struct + Bits int + N string + P string + Q string + func SerializeRswKeypair(kp *RswKeypair) *SerializedRswKeypair + type Storage interface + CleanupExpired func(ctx context.Context) error + GetChallengeTokenExpiry func(ctx context.Context, token string) (time.Time, bool, error) + GetValidationTokenExpiry func(ctx context.Context, token string) (time.Time, bool, error) + SetChallengeToken func(ctx context.Context, token string, expiresAt time.Time) error + SetValidationToken func(ctx context.Context, token string, expiresAt time.Time) error + type V2Challenge struct + Payload map[string]any + Protocol string + type V2Solution struct + Blocked *bool + Instr any + Nonce any + Protocol string + Timeout *bool + Y string + type ValidateBody struct + Blocked bool + Instr *InstrPayload + Solutions []int64 + Timeout bool + Token string + V2Sol []V2Solution + type ValidateOptions struct + ConsumeNonce func(ctx context.Context, signatureHex string, ttl time.Duration) (bool, error) + Scope string + SignToken func(data RedeemTokenData) (string, error) + Storage Storage + TokenTTL time.Duration + type ValidateResult struct + ErrorStr string + Expires int64 + Iat *int64 + InstrErr bool + Reason string + Scope *string + Success bool + Token string + TokenKey *string + func (r ValidateResult) Error() string + func (r ValidateResult) Unwrap() error