Skip to content

Commit

Permalink
Verify events
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyGiorgio committed Aug 11, 2023
1 parent faa2cc2 commit 9be8846
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ pub async fn main(req: Request, env: Env, _ctx: Context) -> Result<Response> {
ClientMessage::Event(event) => {
console_log!("got an event from client: {}", event.id);

match event.verify() {
Ok(()) => (),
Err(e) => {
console_log!("could not verify event {}: {}", event.id, e);
let relay_msg = RelayMessage::new_ok(
event.id,
false,
"invalid event",
);
return relay_response(relay_msg);
}
}

// check if disallowed event kind
if DISALLOWED_EVENT_KINDS.contains(&event.kind.as_u32()) {
console_log!(
Expand Down Expand Up @@ -204,6 +217,21 @@ pub async fn main(req: Request, env: Env, _ctx: Context) -> Result<Response> {
match client_msg {
ClientMessage::Event(event) => {
console_log!("got an event from client: {}", event.id);
match event.verify() {
Ok(()) => (),
Err(e) => {
console_log!("could not verify event {}: {}", event.id, e);
let relay_msg = RelayMessage::new_ok(
event.id,
false,
"disallowed event kind",
);
server
.send_with_str(&relay_msg.as_json())
.expect("failed to send response");
continue;
}
}

// check if disallowed event kind
if DISALLOWED_EVENT_KINDS.contains(&event.kind.as_u32()) {
Expand Down

0 comments on commit 9be8846

Please sign in to comment.