Altcha.V1 (Altcha v2.0.1)

Copy Markdown View Source

Altcha V1 module provides functions for creating and verifying ALTCHA challenges using the original proof-of-work algorithm (hash-based).

Summary

Functions

Converts an algorithm name from binary format to an atom.

Converts an algorithm atom to its binary representation.

Creates a challenge with the specified options.

Extracts parameters from the payload's salt.

Hashes data using the specified algorithm.

Hashes data using the specified algorithm and returns it as a hex string.

Computes HMAC for the given data using the specified algorithm and key.

Creates an HMAC from the data using the specified algorithm and key, and returns it as a hex string.

Generates a specified number of random bytes.

Generates a random integer between 0 and the given maximum value (inclusive).

Solves a challenge by searching for a number that matches the given challenge.

Verifies if the hash of form fields matches the provided hash.

Verifies the server signature using the payload and HMAC key.

Verifies a solution by checking its validity and comparing it with the expected challenge.

Functions

algorithm_from_binary(algorithm)

@spec algorithm_from_binary(any()) :: any()

Converts an algorithm name from binary format to an atom.

algorithm_to_binary(algorithm)

Converts an algorithm atom to its binary representation.

create_challenge(challenge_options)

Creates a challenge with the specified options.

extract_params(payload)

Extracts parameters from the payload's salt.

hash(data, algorithm)

Hashes data using the specified algorithm.

hash_hex(data, algorithm)

Hashes data using the specified algorithm and returns it as a hex string.

hmac_hash(data, algorithm, key)

Computes HMAC for the given data using the specified algorithm and key.

hmac_hex(data, algorithm, key)

Creates an HMAC from the data using the specified algorithm and key, and returns it as a hex string.

random_bytes(length)

Generates a specified number of random bytes.

random_int(max)

Generates a random integer between 0 and the given maximum value (inclusive).

solve_challenge(challenge, salt, algorithm \\ :sha256, max \\ 1_000_000, start \\ 0)

Solves a challenge by searching for a number that matches the given challenge.

verify_fields_hash(form_data, fields, fields_hash, algorithm)

Verifies if the hash of form fields matches the provided hash.

verify_server_signature(payload, hmac_key)

Verifies the server signature using the payload and HMAC key.

verify_solution(payload, hmac_key, check_expires \\ true)

Verifies a solution by checking its validity and comparing it with the expected challenge.