Skip to main content

Crate altcha

Crate altcha 

Source
Expand description

§altcha

ALTCHA Proof-of-Work v2 implementation in Rust.

This crate provides server-side challenge creation and verification as well as client-side challenge solving for the ALTCHA PoW v2 protocol.

§Quick start

use altcha::{
    CreateChallengeOptions, SolveChallengeOptions, VerifySolutionOptions,
    create_challenge, solve_challenge, verify_solution,
};

// Server: create a challenge
let options = CreateChallengeOptions {
    algorithm: "PBKDF2/SHA-256".to_string(),
    cost: 5000,
    hmac_signature_secret: Some("my-secret".to_string()),
    ..Default::default()
};
let challenge = create_challenge(options).unwrap();

// Client: solve the challenge
let solution = solve_challenge(SolveChallengeOptions::new(&challenge))
    .unwrap()
    .expect("solution not found within timeout");

// Server: verify the solution
let result = verify_solution(VerifySolutionOptions::new(
    &challenge,
    &solution,
    "my-secret",
))
.unwrap();

assert!(result.verified);

Re-exports§

pub use error::Error;
pub use error::Result;
pub use types::Challenge;
pub use types::ChallengeParameters;
pub use types::CreateChallengeOptions;
pub use types::HmacAlgorithm;
pub use types::Payload;
pub use types::Solution;
pub use types::ServerSignaturePayload;
pub use types::ServerSignatureVerificationData;
pub use types::SolveChallengeOptions;
pub use types::VerifySolutionOptions;
pub use types::VerifySolutionResult;
pub use types::VerifyServerSignatureResult;

Modules§

error
types

Functions§

create_challenge
Creates a new ALTCHA PoW v2 challenge.
parse_verification_data
Parses a URL-encoded verificationData string into a ServerSignatureVerificationData struct.
sign_challenge
Signs challenge parameters and returns a Challenge with a signature.
solve_challenge
Solves a challenge by iterating counter values until the derived key matches the required prefix.
verify_fields_hash
Verifies a hash of selected form fields against an expected hex digest.
verify_server_signature
Verifies a ServerSignaturePayload issued by ALTCHA Sentinel.
verify_solution
Verifies a submitted solution against a challenge.