Documentation
¶
Overview ¶
Package cap 实现了内嵌式 Cap 工作量证明(PoW)人机验证服务端。 算法移植自 Cap 官方 JS 实现(https://github.com/tiagozip/cap), 使用项目现有的 Redis 客户端替代文件系统存储。
Index ¶
Constants ¶
View Source
const ( OperationCapChallenge = "/cap/challenge" OperationCapRedeem = "/cap/redeem" )
Cap 路由使用的 Kratos operation 常量,供外部白名单引用。
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cap ¶
type Cap struct {
// contains filtered or unexported fields
}
Cap is the embedded Cap CAPTCHA server backed by Redis.
func (*Cap) CreateChallenge ¶
func (c *Cap) CreateChallenge(ctx context.Context, conf *ChallengeConfig) (*ChallengeResponse, error)
CreateChallenge generates a new PoW challenge, stores it in Redis, and returns it.
func (*Cap) RedeemChallenge ¶
func (c *Cap) RedeemChallenge(ctx context.Context, token string, solutions []int) (*RedeemResponse, error)
RedeemChallenge validates a PoW solution and, if valid, returns a one-time verification token.
type ChallengeConfig ¶
type ChallengeConfig struct {
ChallengeCount int
ChallengeSize int
ChallengeDifficulty int
ExpiresMs int64
}
ChallengeConfig holds configuration for challenge creation.
type ChallengeParams ¶
ChallengeParams are the c/s/d fields stored in Redis and returned to the client.
type ChallengeResponse ¶
type ChallengeResponse struct {
Challenge ChallengeParams `json:"challenge"`
Token string `json:"token"`
Expires int64 `json:"expires"`
}
ChallengeResponse is returned by CreateChallenge.
Click to show internal directories.
Click to hide internal directories.