{"id":20365998,"url":"https://github.com/altcha-org/altcha-lib-rb","last_synced_at":"2025-04-09T09:48:49.398Z","repository":{"id":251505615,"uuid":"837580138","full_name":"altcha-org/altcha-lib-rb","owner":"altcha-org","description":"A lightweight library for creating and verifying ALTCHA challenges.","archived":false,"fork":false,"pushed_at":"2024-08-03T14:34:49.000Z","size":12,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T00:11:50.254Z","etag":null,"topics":["altcha","ruby"],"latest_commit_sha":null,"homepage":"https://altcha.org/","language":"Ruby","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":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"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-08-03T11:50:05.000Z","updated_at":"2025-03-14T08:28:26.000Z","dependencies_parsed_at":"2024-08-03T15:27:36.171Z","dependency_job_id":"6a30ed9e-1e19-4799-adc7-366e9f9937de","html_url":"https://github.com/altcha-org/altcha-lib-rb","commit_stats":null,"previous_names":["altcha-org/altcha-lib-rb"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-rb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-rb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-rb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-rb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/altcha-org","download_url":"https://codeload.github.com/altcha-org/altcha-lib-rb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248017997,"owners_count":21034042,"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","ruby"],"created_at":"2024-11-15T00:21:44.596Z","updated_at":"2025-04-09T09:48:49.371Z","avatar_url":"https://github.com/altcha-org.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ALTCHA Ruby Library\n\nThe ALTCHA Ruby Library is a lightweight, zero-dependency library designed for creating and verifying [ALTCHA](https://altcha.org) challenges.\n\n## Compatibility\n\nThis library is compatible with:\n\n- Ruby 2.7+\n\n## Example\n\n- [Demo server](https://github.com/altcha-org/altcha-starter-rb)\n\n## Installation\n\nTo install the ALTCHA Ruby Library, add it to your Gemfile:\n\n```ruby\ngem 'altcha'\n```\n\nThen run:\n\n```sh\nbundle install\n```\n\nAlternatively, install it directly using:\n\n```sh\ngem install altcha\n```\n\n## Usage\n\nHere’s a basic example of how to use the ALTCHA Ruby Library:\n\n```ruby\nrequire 'altcha'\n\nhmac_key = 'secret hmac key'\n\n# Create a new challenge\noptions = Altcha::ChallengeOptions.new(\n  hmac_key: hmac_key,\n  max_number: 100000 # the maximum random number\n)\n\nchallenge = Altcha.create_challenge(options)\n\n# Example payload to verify\npayload = {\n  algorithm: challenge.algorithm,\n  challenge: challenge.challenge,\n  number: 12345, # Example number\n  salt: challenge.salt,\n  signature: challenge.signature\n}\n\n# Verify the solution\nvalid = Altcha.verify_solution(payload, hmac_key, true)\nputs valid ? \"Solution verified!\" : \"Invalid solution.\"\n```\n\n## API\n\n### `Altcha.create_challenge(options)`\n\nCreates a new challenge for ALTCHA.\n\n**Parameters:**\n\n- `options [ChallengeOptions]`:\n  - `algorithm [String]`: Hashing algorithm to use (`SHA-1`, `SHA-256`, `SHA-512`, default: `SHA-256`).\n  - `max_number [Integer]`: Maximum number for the random number generator (default: 1,000,000).\n  - `salt_length [Integer]`: Length of the random salt (default: 12 bytes).\n  - `hmac_key [String]`: Required HMAC key.\n  - `salt [String]`: Optional salt string. If not provided, a random salt will be generated.\n  - `number [Integer]`: Optional specific number to use. If not provided, a random number will be generated.\n  - `expires [Time]`: Optional expiration time for the challenge.\n  - `params [Hash]`: Optional URL-encoded query parameters.\n\n**Returns:** `Challenge`\n\n### `Altcha.verify_solution(payload, hmac_key, check_expires = true)`\n\nVerifies an ALTCHA solution.\n\n**Parameters:**\n\n- `payload [Hash]`: The solution payload to verify.\n- `hmac_key [String]`: The HMAC key used for verification.\n- `check_expires [Boolean]`: Whether to check if the challenge has expired.\n\n**Returns:** `Boolean`\n\n### `Altcha.extract_params(payload)`\n\nExtracts URL parameters from the payload's salt.\n\n**Parameters:**\n\n- `payload [Hash]`: The payload containing the salt.\n\n**Returns:** `Hash`\n\n### `Altcha.verify_fields_hash(form_data, fields, fields_hash, algorithm)`\n\nVerifies the hash of form fields.\n\n**Parameters:**\n\n- `form_data [Hash]`: The form data to hash.\n- `fields [Array\u003cString\u003e]`: The fields to include in the hash.\n- `fields_hash [String]`: The expected hash value.\n- `algorithm [String]`: Hashing algorithm (`SHA-1`, `SHA-256`, `SHA-512`).\n\n**Returns:** `Boolean`\n\n### `Altcha.verify_server_signature(payload, hmac_key)`\n\nVerifies the server's signature.\n\n**Parameters:**\n\n- `payload [String, ServerSignaturePayload]`: The payload to verify (string or `ServerSignaturePayload`).\n- `hmac_key [String]`: The HMAC key used for verification.\n\n**Returns:** `[Boolean, ServerSignatureVerificationData]`\n\n### `Altcha.solve_challenge(challenge, salt, algorithm, max, start)`\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 [String]`: Hashing algorithm (`SHA-1`, `SHA-256`, `SHA-512`).\n- `max [Integer]`: Maximum number to iterate to.\n- `start [Integer]`: Starting number.\n\n**Returns:** `Solution, nil`\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltcha-org%2Faltcha-lib-rb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faltcha-org%2Faltcha-lib-rb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltcha-org%2Faltcha-lib-rb/lists"}