pub struct PeerPow {
pub sponsor_id: Id,
pub timestamp: TimeMillis,
pub content_hash: Hash,
pub salt: Salt,
pub pow: Pow,
}Expand description
A proof-of-work token sponsored by a specific peer and bound to a specific request body.
PeerPow is the standard “I did work, and I did it for this request” credential. It
fixes four things into the PoW input: the sponsor’s peer Id, the time the work was
performed, a content_hash over the request body, and a Salt that the worker varied
to find a solution. Pinning the content hash is what prevents an attacker from replaying
a valid PoW against a different request — re-using the same salt against a new body
would produce a different hash and fail verification.
PeerPow is worn by Peer itself (three of them: the initial identity PoW plus
rolling day/month “best-effort” PoWs) and by every authenticated RPC (see
crate::protocol::rpc). Because its inputs are canonical and verification is cheap,
receivers can re-derive and compare the PoW without keeping state.
Fields§
§sponsor_id: Id§timestamp: TimeMillis§content_hash: Hash§salt: Salt§pow: PowImplementations§
Source§impl PeerPow
impl PeerPow
pub fn new( sponsor_id: Id, verification_key: &VerificationKeyBytes, pq_commitment_bytes: &PQCommitmentBytes, timestamp: TimeMillis, content_hash: Hash, salt: Salt, ) -> Result<PeerPow>
pub fn zero() -> Self
pub fn random() -> Self
pub fn verify( &self, verification_key: &VerificationKeyBytes, pq_commitment_bytes: &PQCommitmentBytes, ) -> Result<()>
pub fn pow_decayed_day(&self, current_time_millis: TimeMillis) -> f64
pub fn pow_decayed_month(&self, current_time_millis: TimeMillis) -> f64
pub fn pow( sponsor_id: &Id, verification_key: &VerificationKeyBytes, pq_commitment_bytes: &PQCommitmentBytes, timestamp: &TimeMillisBytes, hash: &Hash, salt: &Salt, ) -> Result<(Pow, Hash)>
pub fn own_pow( &self, verification_key: &VerificationKeyBytes, pq_commitment_bytes: &PQCommitmentBytes, ) -> Result<(Pow, Hash)>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for PeerPow
impl<'de> Deserialize<'de> for PeerPow
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>,
impl StructuralPartialEq for PeerPow
Auto Trait Implementations§
impl Freeze for PeerPow
impl RefUnwindSafe for PeerPow
impl Send for PeerPow
impl Sync for PeerPow
impl Unpin for PeerPow
impl UnsafeUnpin for PeerPow
impl UnwindSafe for PeerPow
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.