Skip to content

Commit

Permalink
Check correct service key
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcaseria committed Oct 31, 2024
1 parent 011e797 commit a4678f8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion crates/cdk-nostr/src/nip47.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use nostr_sdk::{
nip47::{self, MakeInvoiceResponseResult, NostrWalletConnectURI},
},
Alphabet, Client, Event, EventBuilder, EventId, EventSource, Filter, JsonUtil, Keys, Kind,
PublicKey, SecretKey, SingleLetterTag, Tag, TagStandard, Timestamp, Url,
PublicKey, SecretKey, SingleLetterTag, Tag, TagKind, TagStandard, Timestamp, Url,
};
use tokio::sync::{Mutex, RwLock};

Expand Down Expand Up @@ -114,6 +114,16 @@ impl NostrWalletConnect {
if event.kind != Kind::WalletConnectRequest {
return Err(Error::InvalidKind);
}
let service_pubkey = PublicKey::from_str(
event
.get_tag_content(TagKind::SingleLetter(SingleLetterTag::lowercase(
Alphabet::P,
)))
.ok_or(Error::MissingServiceKey)?,
)?;
if service_pubkey != self.keys.public_key() {
return Err(Error::InvalidServiceKey(service_pubkey));
}

let event_id = event.id;
let mut response_events = self.response_event_cache.lock().await;
Expand Down Expand Up @@ -576,12 +586,18 @@ pub enum Error {
/// Invalid kind error.
#[error("Invalid kind")]
InvalidKind,
/// Invalid service key error.
#[error("Invalid service key: {0}")]
InvalidServiceKey(PublicKey),
/// Error parsing an invoice.
#[error(transparent)]
InvoiceParse(#[from] lightning_invoice::ParseOrSemanticError),
/// Nostr key error.
#[error(transparent)]
Key(#[from] nostr_sdk::key::Error),
/// Missing service key error.
#[error("Missing service key")]
MissingServiceKey,
/// NIP-04 error.
#[error(transparent)]
Nip04(#[from] nip04::Error),
Expand Down

0 comments on commit a4678f8

Please sign in to comment.