pub struct PoWChallenge {
pub nonce: [u8; 32],
pub difficulty: u8,
}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
Nonce format: [Timestamp (8 bytes) | HMAC(Timestamp + ClientID, Secret) (24 bytes)]
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>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
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
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PoWChallenge
impl Debug for PoWChallenge
Source§impl<'de> Deserialize<'de> for PoWChallenge
impl<'de> Deserialize<'de> for PoWChallenge
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for PoWChallenge
impl RefUnwindSafe for PoWChallenge
impl Send for PoWChallenge
impl Sync for PoWChallenge
impl Unpin for PoWChallenge
impl UnsafeUnpin for PoWChallenge
impl UnwindSafe for PoWChallenge
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more