OpenAgentID documentation
Source referencesRust module referenceaegis-auth

aegis-auth · challenge

Declared module signatures, types, configuration, and source documentation.

Source: aegis/aegis-auth/src/challenge.rs. SHA-256: 39efc24b239da3aaa326a390e3b735a62a45b9e8b57dcb25ada5e0992ecebba3.

This source reference follows declared modules and preserves feature attributes. It includes public declarations and implementation methods in those modules. Private-module exports and trait resolution still require the compiler; not every declaration is a crate-root import. Function bodies and constant values are omitted. Source comments describe their implementation context and are not a production deployment claim.

challenge::Challenge

A challenge issued by the verifier to an authenticating entity.

The prover must sign a JCS-canonical payload containing the challenge bytes, their DID, the nonce, and the timestamp. The signed response must arrive before expires_at.

#[derive(Debug, Clone)]
pub struct Challenge {
/// 32 cryptographically random bytes.

pub challenge_bytes: [u8; 32],
/// ISO 8601 timestamp of challenge creation.

pub timestamp: DateTime<Utc>,
/// Verifier-generated nonce (UUID v7) to prevent replay attacks.

pub nonce: String,
/// When this challenge expires (creation time + 60 seconds).

pub expires_at: DateTime<Utc>
}

Source line: 33.

challenge::Challenge::generate

Generate a new random challenge.

Fills 32 bytes from the OS CSPRNG, generates a UUID v7 nonce, and sets expiry to 60 seconds from now.

pub fn generate() -> Self;

Source line: 49.

challenge::ChallengeVerifier

Challenge-response verifier.

Tracks recently used nonces to prevent replay attacks within a 5-minute window. Thread-safe via interior RwLock.

pub struct ChallengeVerifier {

}

Source line: 70.

challenge::ChallengeVerifier::new

Create a new verifier with an empty nonce set.

pub fn new() -> Self;

Source line: 79.

challenge::ChallengeVerifier::verify_response

Verify a challenge response.

Performs the following checks in order:

  1. Challenge has not expired.
  2. Timestamp is within +/- 30 seconds of current time.
  3. Nonce has not been used before.
  4. Constructs JCS-canonical payload and verifies the Ed25519 signature.
  5. Marks the nonce as used.

Arguments

  • challenge - The challenge that was issued to the prover.
  • did - The DID claimed by the prover.
  • signature_b64 - Base64url-encoded Ed25519 signature over the canonical payload.
  • public_key - The prover's Ed25519 verifying key (resolved from their DID document).

Errors

Returns [AuthError::ChallengeInvalid] if any check fails. Returns [AuthError::InvalidCredential] if the signature is malformed or invalid.

pub fn verify_response(
        &self,
        challenge: &Challenge,
        did: &str,
        signature_b64: &str,
        public_key: &VerifyingKey,
    ) -> Result<(), AuthError>;

Source line: 105.

challenge::ChallengeVerifier::clear_nonces

Remove all nonces from the set.

In a production system, nonces would expire via TTL. This method provides a manual reset for testing or periodic cleanup.

pub fn clear_nonces(&self) -> Result<(), AuthError>;

Source line: 186.

challenge::build_challenge_payload

Build the JCS-canonical payload bytes for challenge signing/verification.

The canonical form is a JSON object with keys in alphabetical order:

{"challenge":"<base64url(challenge_bytes)>","did":"<did>","nonce":"<nonce>","timestamp":"<ISO8601>"}

JCS (RFC 8785) handles the key ordering automatically via serde_jcs.

Arguments

  • challenge - The challenge containing the random bytes, nonce, and timestamp.
  • did - The DID of the entity signing the challenge.

Returns

The canonical JSON bytes ready for Ed25519 signing.

Errors

Returns [AuthError::Internal] if JCS serialization fails.

pub fn build_challenge_payload(challenge: &Challenge, did: &str) -> Result<Vec<u8>, AuthError>;

Source line: 225.

On this page