{"id":15063593,"url":"https://github.com/altcha-org/altcha-lib-ex","last_synced_at":"2025-10-31T21:30:36.422Z","repository":{"id":252152583,"uuid":"839581637","full_name":"altcha-org/altcha-lib-ex","owner":"altcha-org","description":"A lightweight Elixir library for creating and verifying ALTCHA challenges.","archived":false,"fork":false,"pushed_at":"2024-08-08T13:13:25.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-30T09:01:36.090Z","etag":null,"topics":["altcha","elixir"],"latest_commit_sha":null,"homepage":"https://altcha.org/","language":"Elixir","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-08-07T23:03:38.000Z","updated_at":"2024-09-19T07:33:03.000Z","dependencies_parsed_at":"2024-09-29T09:01:35.962Z","dependency_job_id":"10de3d7e-331d-4bdb-a683-7d29f4b4d7ed","html_url":"https://github.com/altcha-org/altcha-lib-ex","commit_stats":null,"previous_names":["altcha-org/altcha-lib-ex"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-ex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-ex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-ex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/altcha-org%2Faltcha-lib-ex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/altcha-org","download_url":"https://codeload.github.com/altcha-org/altcha-lib-ex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219855431,"owners_count":16556170,"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","elixir"],"created_at":"2024-09-25T00:04:42.359Z","updated_at":"2024-10-12T23:41:13.371Z","avatar_url":"https://github.com/altcha-org.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ALTCHA Elixir Library\n\nThe ALTCHA Elixir Library is a lightweight library designed for creating and verifying [ALTCHA](https://altcha.org) challenges.\n\n## Compatibility\n\nThis library is compatible with:\n\n- Elixir 1.10+\n\n## Example\n\n- [Demo server](https://github.com/altcha-org/altcha-starter-ex)\n\n## Installation\n\nTo install the ALTCHA Elixir Library, add it to your `mix.exs` dependencies:\n\n```elixir\ndefp deps do\n  [\n    {:altcha, \"~\u003e 0.2\"}\n  ]\nend\n```\n\nThen run:\n\n```sh\nmix deps.get\n```\n\n## Usage\n\nHere’s a basic example of how to use the ALTCHA Elixir Library:\n\n```elixir\nhmac_key = \"secret hmac key\"\n\n# Create a new challenge\noptions = %Altcha.ChallengeOptions{\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: 123, # Example number\n  salt: challenge.salt,\n  signature: challenge.signature\n}\n\n# Verify the solution\nvalid = Altcha.verify_solution(payload, hmac_key, true)\n```\n\n## API Documentation\n\n### `create_challenge/1`\n\n**Description:**\n\nGenerates a new ALTCHA challenge with the specified options. The challenge includes a hashed string and an HMAC signature.\n\n**Parameters:**\n\n- `%ChallengeOptions{}` - A struct containing options for challenge creation:\n\n  - `:algorithm` - (optional) The algorithm to use for hashing (`:sha`, `:sha256`, `:sha512`). Defaults to `:sha256`.\n  - `:max_number` - (optional) The maximum number for challenge generation. Defaults to `1_000_000`.\n  - `:salt_length` - (optional) The length of the salt. Defaults to `12`.\n  - `:hmac_key` - (required) Key used for HMAC calculation.\n  - `:salt` - (optional) The salt value. If not provided, a random salt will be generated.\n  - `:number` - (optional) The number for the challenge. If not provided, a random number will be generated.\n  - `:expires` - (optional) Expiration time for the challenge in seconds from the current time.\n  - `:params` - (optional) Additional parameters to include in the salt.\n\n**Returns:**\n\nA `%Challenge{}` struct containing:\n\n- `:algorithm` - The hashing algorithm used.\n- `:challenge` - The hashed challenge string.\n- `:maxnumber` - The maximum number used.\n- `:salt` - The salt used.\n- `:signature` - The HMAC signature of the challenge.\n\n---\n\n### `verify_solution/2`\n\n**Description:**\n\nVerifies a given solution by checking its validity and comparing it with the expected challenge.\n\n**Parameters:**\n\n- `payload` - The payload containing challenge details. Can be a `%Payload{}` struct, a JSON object, or a Base64-encoded string.\n- `hmac_key` - The key used for HMAC calculation.\n\n**Options:**\n\n- `check_expires` - (optional) A boolean to determine if the expiration of the challenge should be checked. Defaults to `true`.\n\n**Returns:**\n\n`true` if the solution is valid and matches the expected challenge; otherwise, `false`.\n\n---\n\n### `verify_fields_hash/4`\n\n**Description:**\n\nVerifies if the hash of form fields matches the provided hash.\n\n**Parameters:**\n\n- `form_data` - The form data as a map with field names and values.\n- `fields` - A list of field names to be included in the hash calculation.\n- `fields_hash` - The expected hash of the form fields.\n- `algorithm` - The algorithm used for hashing (`:sha`, `:sha256`, `:sha512`).\n\n**Returns:**\n\n`true` if the computed hash of the fields matches the provided hash; otherwise, `false`.\n\n---\n\n### `verify_server_signature/2`\n\n**Description:**\n\nVerifies the server signature using the provided payload and HMAC key.\n\n**Parameters:**\n\n- `payload` - The payload containing server signature details. Can be a `%ServerSignaturePayload{}` struct, a JSON object, or a Base64-encoded string.\n- `hmac_key` - The key used for HMAC calculation.\n\n**Returns:**\n\n`true` if the server signature is valid and matches the expected signature; otherwise, `false`.\n\n---\n\n### `solve_challenge/4`\n\n**Description:**\n\nAttempts to solve a given challenge by searching for a number that matches the challenge criteria.\n\n**Parameters:**\n\n- `challenge` - The challenge string to be matched.\n- `salt` - The salt used in challenge generation.\n- `algorithm` - (optional) The algorithm used for hashing (`:sha`, `:sha256`, `:sha512`). Defaults to `:sha256`.\n- `max` - (optional) The maximum number to search. Defaults to `1_000_000`.\n- `start` - (optional) The starting number for the search. Defaults to `0`.\n\n**Returns:**\n\nA `%Solution{}` struct containing:\n\n- `:number` - The number that solves the challenge.\n- `:took` - The time taken to find the solution in milliseconds.\n\nIf no solution is found, returns `nil`.\n\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltcha-org%2Faltcha-lib-ex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faltcha-org%2Faltcha-lib-ex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faltcha-org%2Faltcha-lib-ex/lists"}