Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/nip98-verify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 5 additions & 0 deletions crates/nostream-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub enum CoreError {
#[error("{0}")]
InvalidNip44(String),

/// A NIP-98 `Authorization` header failed verification against its request. The
/// message is the capture's reason, verbatim (`src/utils/nip98.ts:146-273`).
#[error("{0}")]
InvalidNip98(String),

/// NIP-77 storage could not be built from the items offered (negative or
/// out-of-range `created_at`, or a set the storage refused).
#[error("invalid negentropy storage: {0}")]
Expand Down
3 changes: 2 additions & 1 deletion crates/nostream-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
//! event schema ([`validation::validate_event`] with the kind 7/17/10002 and geohash
//! refinements), the wire codec ([`messages::decode`] and the one encoder
//! `RelayMessage::to_text`), NIP-42 ([`nip42::authenticate`], [`nip42::generate_challenge`]
//! and [`nip42::Nip42Session`]), the NIP-43 invite code and its event, the NIP-05 identifier
//! and [`nip42::Nip42Session`]), NIP-98 ([`nip98::verify`]; the replay claim on the event
//! id is the admin job's, ADR 0010), the NIP-43 invite code and its event, the NIP-05 identifier
//! helpers and [`nip05::verify`] over its [`nip05::Nip05Fetch`] seam, the
//! adaptive-difficulty signal and its WoT policy, [`clock::Clock`] and
//! [`random::RandomSource`], and the NIP-77 reconciliation engine (over the `negentropy`
Expand Down
15 changes: 12 additions & 3 deletions crates/nostream-core/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,18 @@ fn integer_value(number: &Number) -> Result<f64, WireError> {
/// this pass reports the schema's own message for whatever is left, which is what the
/// NOTICE carries.
pub fn validate_event_value(value: &Value) -> Result<Event, WireError> {
let event = decode_event_fields(value)?;

crate::validation::validate_event(&event)
.map_err(|error| invalid(&strip_invalid_event(&error.to_string())))?;

Ok(event)
}

/// The field schemas and the `.strict()` rule of [`validate_event_value`], without the
/// kind-7/17/10002/geohash refinements. NIP-98 parses its event with exactly these
/// (`nip98EventSchema`, `src/utils/nip98.ts:24-35`).
pub(crate) fn decode_event_fields(value: &Value) -> Result<Event, WireError> {
let Value::Object(object) = value else {
return Err(invalid(&format!(
"Expected object, received {}",
Expand Down Expand Up @@ -635,9 +647,6 @@ pub fn validate_event_value(value: &Value) -> Result<Event, WireError> {
.map_err(|error: crate::error::CoreError| invalid(&error.to_string()))?,
};

crate::validation::validate_event(&event)
.map_err(|error| invalid(&strip_invalid_event(&error.to_string())))?;

Ok(event)
}

Expand Down
Loading
Loading