{"id":20366004,"url":"https://github.com/altcha-org/altcha-lib-go","last_synced_at":"2025-09-23T17:32:04.575Z","repository":{"id":250217516,"uuid":"833688346","full_name":"altcha-org/altcha-lib-go","owner":"altcha-org","description":"A Go library for creating and verifying ALTCHA challenges.","archived":false,"fork":false,"pushed_at":"2024-07-29T11:52:12.000Z","size":18,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-15T00:24:34.913Z","etag":null,"topics":["altcha","antispam","captcha","go","golang"],"latest_commit_sha":null,"homepage":"https://altcha.org/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/altcha-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-25T14:43:27.000Z","updated_at":"2024-10-02T16:21:31.000Z","dependencies_parsed_at":"2024-07-25T23:52:03.914Z","dependency_job_id":null,"html_url":"https://github.com/altcha-org/altcha-lib-go","commit_stats":null,"previous_names":["altcha-org/altcha-lib-go"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/altcha-org","download_url":"https://codeload.github.com/altcha-org/altcha-lib-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233991024,"owners_count":18762351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["altcha","antispam","captcha","go","golang"],"created_at":"2024-11-15T00:21:47.638Z","updated_at":"2025-09-23T17:32:04.533Z","avatar_url":"https://github.com/altcha-org.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ALTCHA Go Library\n\nThe ALTCHA Go Library is a lightweight, zero-dependency library designed for creating and verifying [ALTCHA](https://altcha.org) challenges, specifically tailored for Go applications.\n\n## Compatibility\n\nThis library is compatible with:\n\n- Go 1.18+\n- All major platforms (Linux, Windows, macOS)\n\n## Example\n\n- [Demo server](https://github.com/altcha-org/altcha-starter-go)\n\n## Installation\n\nTo install the ALTCHA Go Library, use the following command:\n\n```sh\ngo get github.com/altcha-org/altcha-lib-go\n```\n\n## Usage\n\nHere’s a basic example of how to use the ALTCHA Go Library:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n    \"time\"\n\n    \"github.com/altcha-org/altcha-lib-go\"\n)\n\nfunc main() {\n    hmacKey := \"secret hmac key\"\n\n    // Create a new challenge\n    challenge, err := altcha.CreateChallenge(altcha.ChallengeOptions{\n        HMACKey:   hmacKey,\n        MaxNumber: 100000, // the maximum random number\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    fmt.Println(\"Challenge created:\", challenge)\n\n    // Example number\n    var number int64 = 12345 \n\n    // Example payload to verify\n    payload := altcha.Payload{\n        Algorithm: challenge.Algorithm,\n        Challenge: challenge.Challenge,\n        Number:    \u0026number,\n        Salt:      challenge.Salt,\n        Signature: challenge.Signature,\n    }\n\n    // Verify the solution\n    ok, err := altcha.VerifySolution(payload, hmacKey, true)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    if ok {\n        fmt.Println(\"Solution verified!\")\n    } else {\n        fmt.Println(\"Invalid solution.\")\n    }\n}\n```\n\n## API\n\n### `CreateChallenge(options ChallengeOptions) (Challenge, error)`\n\nCreates a new challenge for ALTCHA.\n\n**Parameters:**\n\n- `options ChallengeOptions`:\n  - `Algorithm Algorithm`: Hashing algorithm to use (`SHA-1`, `SHA-256`, `SHA-512`, default: `SHA-256`).\n  - `MaxNumber int64`: Maximum number for the random number generator (default: 1,000,000).\n  - `SaltLength int`: Length of the random salt (default: 12 bytes).\n  - `HMACKey string`: Required HMAC key.\n  - `Salt string`: Optional salt string. If not provided, a random salt will be generated.\n  - `Number *int64`: Optional specific number to use. If not provided, a random number will be generated.\n  - `Expires *time.Time`: Optional expiration time for the challenge.\n  - `Params url.Values`: Optional URL-encoded query parameters.\n\n**Returns:** `Challenge, error`\n\n### `VerifySolution(payload map[string]interface{}, hmacKey string, checkExpires bool) (bool, error)`\n\nVerifies an ALTCHA solution.\n\n**Parameters:**\n\n- `payload map[string]interface{}`: The solution payload to verify.\n- `hmacKey string`: The HMAC key used for verification.\n- `checkExpires bool`: Whether to check if the challenge has expired.\n\n**Returns:** `bool, error`\n\n### `ExtractParams(payload map[string]interface{}) url.Values`\n\nExtracts URL parameters from the payload's salt.\n\n**Parameters:**\n\n- `payload map[string]interface{}`: The payload containing the salt.\n\n**Returns:** `url.Values`\n\n### `VerifyFieldsHash(formData map[string][]string, fields []string, fieldsHash string, algorithm Algorithm) (bool, error)`\n\nVerifies the hash of form fields.\n\n**Parameters:**\n\n- `formData map[string][]string`: The form data to hash.\n- `fields []string`: The fields to include in the hash.\n- `fieldsHash string`: The expected hash value.\n- `algorithm Algorithm`: Hashing algorithm (`SHA-1`, `SHA-256`, `SHA-512`).\n\n**Returns:** `bool, error`\n\n### `VerifyServerSignature(payload interface{}, hmacKey string) (bool, ServerSignatureVerificationData, error)`\n\nVerifies the server signature.\n\n**Parameters:**\n\n- `payload interface{}`: The payload to verify (string or `ServerSignaturePayload`).\n- `hmacKey string`: The HMAC key used for verification.\n\n**Returns:** `bool, ServerSignatureVerificationData, error`\n\n### `SolveChallenge(challenge string, salt string, algorithm Algorithm, max int, start int, stopChan \u003c-chan struct{}) (*Solution, error)`\n\nFinds a solution to the given challenge.\n\n**Parameters:**\n\n- `challenge string`: The challenge hash.\n- `salt string`: The challenge salt.\n- `algorithm Algorithm`: Hashing algorithm (`SHA-1`, `SHA-256`, `SHA-512`).\n- `max int`: Maximum number to iterate to.\n- `start int`: Starting number.\n- `stopChan \u003c-chan struct{}`: Channel to receive stop signals.\n\n**Returns:** `*Solution, error`\n\n## Cryptographically Safe Methods\n\nThis library provides cryptographically safe variants of core methods using `subtle.ConstantTimeCompare` to prevent timing attacks [[#3](https://github.com/altcha-org/altcha-lib-go/issues/3)]. These methods perform two additional SHA-256 iterations.\n\nAvailable methods:\n\n* `VerifySolutionSafe`\n* `VerifyFieldsHashSafe`\n* `VerifyServerSignatureSafe`\n* `SolveChallengeSafe`\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltcha-org%2Faltcha-lib-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faltcha-org%2Faltcha-lib-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltcha-org%2Faltcha-lib-go/lists"}