pub fn verify_request_without_body(
authorization: &str,
target: &RequestTarget<'_>,
now: UnixTime,
policy: &RequestPolicy,
) -> Result<BodyUncheckedRequest, VerifyRequestError>Expand description
Verifies an Authorization header in every respect except the body
digest, for a caller that never sees the body.
This is verify_request for a proxy such as the Stratum gate, which
must name the requester before it forwards a request whose body the
server behind it will hash. It checks the header size and scheme, the
event’s structure, ID and BIP-340 signature, the kind, exactly one u
tag equal to target.url, exactly one method tag equal to
target.method, at most one payload tag that, if present, is 64
lowercase hexadecimal digits, and the time window, with the same errors in
the same order as verify_request.
It does not compare the payload tag with any body, and it does not
require a payload tag to be present or absent: it cannot know whether
the request has a body worth binding. The result is therefore a
BodyUncheckedRequest, not a VerifiedRequest. A server that holds
the body must still verify the request with verify_request.
To look the author up before spending a signature verification, use
UnverifiedRequest::parse followed by
UnverifiedRequest::verify_without_body instead.
§Examples
use stratum_node_core::{
verify_request_without_body, ExpectedRequest, NostrSecretKey, RequestPolicy, RequestTarget,
Sha256Digest, UnixTime,
};
let key = NostrSecretKey::from_hex(&"05".repeat(32))?;
let url = "https://stratum.example.org/pods/abc/x.txt";
let now = UnixTime::from_secs(1_700_000_000);
let header = key.sign_request(&ExpectedRequest::new("PUT", url, Some(b"hello")), now, &[0; 32])?;
let checked = verify_request_without_body(
&header,
&RequestTarget::new("PUT", url),
now,
&RequestPolicy::new(),
)?;
assert_eq!(checked.signer(), key.public());
// The digest the signer claims; nothing has hashed a body.
assert_eq!(checked.claimed_payload(), Some(Sha256Digest::of(b"hello")));§Errors
Returns the VerifyRequestError variant naming the first failed check.
It never returns VerifyRequestError::MissingPayloadTag,
VerifyRequestError::UnexpectedPayloadTag or
VerifyRequestError::PayloadMismatch.