uhash-core 0.5.1

UniversalHash v4 - democratic proof-of-work algorithm where phones compete with servers
Documentation
//! Challenge generation and difficulty encoding.

use uhash_types::{Challenge, Difficulty};

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

/// Build PoW input bytes from a challenge header and nonce.
pub fn build_input(header: &[u8], nonce: u64) -> Vec<u8> {
    let mut input = Vec::with_capacity(header.len() + 8);
    input.extend_from_slice(header);
    input.extend_from_slice(&nonce.to_le_bytes());
    input
}

/// Build PoW input from a typed Challenge and nonce.
pub fn challenge_input(challenge: &Challenge, nonce: u64) -> Vec<u8> {
    build_input(&challenge.header, nonce)
}

/// Encode a difficulty as leading zero bit count.
pub fn encode_difficulty(bits: u32) -> Difficulty {
    Difficulty::new(bits)
}