pub struct UnverifiedRequest { /* private fields */ }Expand description
An Authorization: Nostr header that has been decoded and parsed but
not verified.
UnverifiedRequest::parse applies the header size limit, the scheme,
base64 and every structural check on the event (JSON shape, field
encodings, a public key on the curve, no empty tag, supported
characters). It does not recompute the event ID or verify the signature,
so claimed_author and
claimed_event_id are only what the header
says. Their sole safe use is to decide whether verification is worth
spending, for example by looking the author up in a member directory.
Verify with verify (body known) or
verify_without_body (body not seen); the
header is not parsed again. Both consume the value, and the result of
either is the same as verify_request or
verify_request_without_body on the original header.
§Examples
use stratum_node_core::{
ExpectedRequest, NostrSecretKey, RequestPolicy, RequestTarget, UnixTime, UnverifiedRequest,
};
let key = NostrSecretKey::from_hex(&"05".repeat(32))?;
let url = "https://stratum.example.org/pods/abc/";
let now = UnixTime::from_secs(1_700_000_000);
let header = key.sign_request(&ExpectedRequest::new("GET", url, None), now, &[0; 32])?;
let unverified = UnverifiedRequest::parse(&header, &RequestPolicy::new())?;
// Cheap: no signature has been checked yet.
let members = [key.public()];
assert!(members.contains(&unverified.claimed_author()));
let checked = unverified.verify_without_body(&RequestTarget::new("GET", url), now)?;
assert_eq!(checked.signer(), key.public());Implementations§
Source§impl UnverifiedRequest
impl UnverifiedRequest
Sourcepub fn parse(
authorization: &str,
policy: &RequestPolicy,
) -> Result<Self, VerifyRequestError>
pub fn parse( authorization: &str, policy: &RequestPolicy, ) -> Result<Self, VerifyRequestError>
Decodes and parses an Authorization header value without verifying
the event ID or the signature.
policy supplies the header size limit now and the clock window
later, when the request is verified.
§Errors
Returns VerifyRequestError::TokenTooLarge,
VerifyRequestError::InvalidScheme,
VerifyRequestError::InvalidBase64 or
VerifyRequestError::Event with a structural
ParseEventError. It never returns
ParseEventError::IdMismatch or ParseEventError::BadSignature;
those come from verification.
Returns the author the event names, unverified.
Sourcepub fn claimed_event_id(&self) -> EventId
pub fn claimed_event_id(&self) -> EventId
Returns the event ID as the event states it, unverified and not recomputed.
Sourcepub fn verify(
self,
expected: &ExpectedRequest<'_>,
now: UnixTime,
) -> Result<VerifiedRequest, VerifyRequestError>
pub fn verify( self, expected: &ExpectedRequest<'_>, now: UnixTime, ) -> Result<VerifiedRequest, VerifyRequestError>
Completes verification against the request the server received, body included.
The checks and their order are those of verify_request.
§Errors
Returns the VerifyRequestError variant naming the first failed
check.
Sourcepub fn verify_without_body(
self,
target: &RequestTarget<'_>,
now: UnixTime,
) -> Result<BodyUncheckedRequest, VerifyRequestError>
pub fn verify_without_body( self, target: &RequestTarget<'_>, now: UnixTime, ) -> Result<BodyUncheckedRequest, VerifyRequestError>
Completes verification in every respect except the body digest.
The checks and their order are those of
verify_request_without_body; read its documentation for what is
and is not checked.
§Errors
Returns the VerifyRequestError variant naming the first failed
check.