Documentation
¶
Overview ¶
Package altcha implements BRAIN's Altcha-style SHA-256 proof-of-work captcha.
BRAIN migrated from reCAPTCHA v2 to this PoW some time before 2026-05-17. The full flow used by the BRAIN registration path:
- GET /captcha -> { algorithm, challenge, salt, signature, maxNumber }
- Find n in [0, maxNumber] such that hex(sha256(salt + str(n))) == challenge
- POST /users with auxiliary.captcha = base64(JSON({...challenge, number, took}))
On a modern CPU the linear single-threaded solve median is ~250ms for maxNumber=1_000_000. The parallel solver here splits the [0, maxNumber] range across runtime.NumCPU() goroutines and races them — typically 4-8x faster on multi-core hardware.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoSolution = errors.New("altcha: no solution in range")
ErrNoSolution is returned when no n in [0, MaxNumber] satisfies the challenge. BRAIN's server only issues challenges with a known solution in range; this error means the challenge has been tampered with or the algorithm field doesn't match what we can solve.
Functions ¶
Types ¶
type CaptchaAdapter ¶
type CaptchaAdapter struct {
Workers int
}
CaptchaAdapter implements the brainapi.CaptchaSolver structural interface using the parallel SHA-256 solver in this package.
Wire it up in NewClient:
client, _ := brainapi.NewClient(brainapi.Options{
CaptchaSolver: altcha.CaptchaAdapter{Workers: 8},
...
})
Workers <= 0 picks runtime.NumCPU(); a reasonable default for production.
type Challenge ¶
type Challenge struct {
Algorithm string `json:"algorithm"`
Challenge string `json:"challenge"`
Salt string `json:"salt"`
Signature string `json:"signature"`
MaxNumber int64 `json:"maxNumber"`
}
Challenge is the body BRAIN's /captcha endpoint returns.
func ParseChallenge ¶
ParseChallenge decodes a /captcha JSON body into a Challenge.
type Solution ¶
type Solution struct {
Algorithm string `json:"algorithm"`
Challenge string `json:"challenge"`
Salt string `json:"salt"`
Signature string `json:"signature"`
MaxNumber int64 `json:"maxNumber"`
Number int64 `json:"number"`
Took int64 `json:"took"`
}
Solution embeds the challenge and adds the found Number plus solve duration in milliseconds (Altcha's wire format expects "took" in ms).