Skip to main content

UnverifiedRequest

Struct UnverifiedRequest 

Source
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

Source

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.

Source

pub fn claimed_author(&self) -> DidNostr

Returns the author the event names, unverified.

Source

pub fn claimed_event_id(&self) -> EventId

Returns the event ID as the event states it, unverified and not recomputed.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for UnverifiedRequest

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UnverifiedRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.