mirror of
https://github.com/mikedilger/chorus.git
synced 2026-03-04 06:36:27 +00:00
Protected Event: NIP-70 support
This commit is contained in:
parent
7eea4dca7d
commit
1e2187b86c
@ -387,9 +387,20 @@ impl WebSocketService {
|
||||
|
||||
async fn screen_incoming_event(
|
||||
event: &Event<'_>,
|
||||
_event_flags: EventFlags,
|
||||
event_flags: EventFlags,
|
||||
authorized_user: bool,
|
||||
) -> Result<bool, Error> {
|
||||
// If the event has a '-' tag, require the user to be AUTHed and match
|
||||
// the event author
|
||||
for mut tag in event.tags()?.iter() {
|
||||
if tag.next() == Some(b"-") {
|
||||
// The event is protected. Only accept if user is AUTHed as the event author
|
||||
if !event_flags.author_is_current_user {
|
||||
return Err(ChorusError::ProtectedEvent.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Accept anything from authenticated authorized users
|
||||
if authorized_user {
|
||||
return Ok(true);
|
||||
|
||||
@ -100,6 +100,9 @@ pub enum ChorusError {
|
||||
// No such subscription
|
||||
NoSuchSubscription,
|
||||
|
||||
// Protected Event
|
||||
ProtectedEvent,
|
||||
|
||||
// Restricted
|
||||
Restricted,
|
||||
|
||||
@ -175,6 +178,7 @@ impl std::fmt::Display for ChorusError {
|
||||
ChorusError::Lmdb(e) => write!(f, "{e}"),
|
||||
ChorusError::NoPrivateKey => write!(f, "Private Key Not Found"),
|
||||
ChorusError::NoSuchSubscription => write!(f, "No such subscription"),
|
||||
ChorusError::ProtectedEvent => write!(f, "Protected event"),
|
||||
ChorusError::Restricted => write!(f, "Restricted"),
|
||||
ChorusError::Rustls(e) => write!(f, "{e}"),
|
||||
ChorusError::TimedOut => write!(f, "Timed out"),
|
||||
@ -240,6 +244,7 @@ impl ChorusError {
|
||||
ChorusError::Lmdb(_) => 0.0,
|
||||
ChorusError::NoPrivateKey => 0.0,
|
||||
ChorusError::NoSuchSubscription => 0.05,
|
||||
ChorusError::ProtectedEvent => 0.35,
|
||||
ChorusError::Restricted => 0.1,
|
||||
ChorusError::Rustls(_) => 0.0,
|
||||
ChorusError::TimedOut => 0.1,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user