diff --git a/src/lib.rs b/src/lib.rs index 26a0af2..707b7f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +use crate::nostr::get_nip11_response; pub(crate) use crate::nostr::{ try_queue_event, NOSTR_QUEUE, NOSTR_QUEUE_2, NOSTR_QUEUE_3, NOSTR_QUEUE_4, NOSTR_QUEUE_5, NOSTR_QUEUE_6, @@ -109,7 +110,14 @@ pub async fn main(req: Request, env: Env, _ctx: Context) -> Result { empty_response() }) - .get("/", |_, ctx| { + .get("/", |req, ctx| { + // NIP 11 + if req.headers().get("Accept").ok().flatten() + == Some("application/nostr+json".to_string()) + { + return Response::from_json(&get_nip11_response())?.with_cors(&cors()); + } + // For websocket compatibility let pair = WebSocketPair::new()?; let server = pair.server; diff --git a/src/nostr.rs b/src/nostr.rs index 0db34f4..6eb11ef 100644 --- a/src/nostr.rs +++ b/src/nostr.rs @@ -2,6 +2,7 @@ use crate::error::Error; use futures::pin_mut; use futures::StreamExt; use nostr::prelude::*; +use std::string::ToString; use std::{time::Duration, vec}; use worker::WebsocketEvent; use worker::{console_log, Cache, Delay, Fetch, Queue, Response, WebSocket}; @@ -24,6 +25,23 @@ const RELAYS: [&str; 8] = [ "wss://nostr.wine", ]; +pub fn get_nip11_response() -> RelayInformationDocument { + let version = env!("CARGO_PKG_VERSION"); + let supported_nips = vec![1, 11, 20]; + + RelayInformationDocument { + name: Some("Mutiny blastr relay".to_string()), + description: Some("Mutiny blastr relay".to_string()), + pubkey: Some( + "df173277182f3155d37b330211ba1de4a81500c02d195e964f91be774ec96708".to_string(), + ), + contact: Some("team@mutinywallet.com".to_string()), + supported_nips: Some(supported_nips), + software: Some("git+https://github.com/MutinyWallet/blastr.git".to_string()), + version: Some(version.to_string()), + } +} + pub async fn try_queue_event(event: Event, nostr_queues: Vec) { for nostr_queue in nostr_queues.iter() { match queue_nostr_event_with_queue(nostr_queue, event.clone()).await {