pub struct PoWChallenge {
pub nonce: [u8; 32],
pub difficulty: u8,
}std only.Expand description
Proof-of-Work Challenge
Fields§
§nonce: [u8; 32]§difficulty: u8Implementations§
Source§impl PoWChallenge
impl PoWChallenge
Sourcepub fn new_stateless(
difficulty: u8,
client_id: &[u8],
secret: &[u8; 32],
) -> Self
pub fn new_stateless( difficulty: u8, client_id: &[u8], secret: &[u8; 32], ) -> Self
Generate a new stateless challenge.
The 32-byte nonce is a self-authenticating cookie:
[timestamp (8 bytes, LE) | MAC(timestamp ‖ client_id) (24 bytes)],
where the MAC is a keyed BLAKE3 hash under the server’s secret
(truncated to 24 bytes). Because the MAC binds the timestamp and the
client id, the server need keep no per-challenge state — verify
recomputes the MAC to confirm authenticity and freshness.
Sourcepub fn verify(
&self,
solution: &PoWSolution,
client_id: &[u8],
secret: &[u8; 32],
) -> bool
pub fn verify( &self, solution: &PoWSolution, client_id: &[u8], secret: &[u8; 32], ) -> bool
Verify a solution and the validity of the challenge (stateless check)
Sourcepub fn solve(&self) -> Result<PoWSolution, PowError>
pub fn solve(&self) -> Result<PoWSolution, PowError>
Solve at the challenge’s difficulty, bounded by MAX_SOLVE_ITERATIONS
(H3) so an infeasible difficulty fails closed instead of looping forever.
Sourcepub fn solve_capped(&self, max_difficulty: u8) -> Result<PoWSolution, PowError>
pub fn solve_capped(&self, max_difficulty: u8) -> Result<PoWSolution, PowError>
Like solve but rejects a difficulty above
max_difficulty BEFORE doing any work (H3). The client passes
MAX_CLIENT_POW_DIFFICULTY so an injected high-difficulty
HelloRetryRequest cannot pin a CPU core.
Trait Implementations§
Source§impl BorshDeserialize for PoWChallenge
impl BorshDeserialize for PoWChallenge
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for PoWChallenge
impl BorshSerialize for PoWChallenge
Source§impl Clone for PoWChallenge
impl Clone for PoWChallenge
Source§fn clone(&self) -> PoWChallenge
fn clone(&self) -> PoWChallenge
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more