Skip to content

Commit

Permalink
nip46: tolerate empty string pubkeys in nip46 sign_event requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Apr 25, 2024
1 parent d89650f commit 5775514
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion gossip-lib/src/nip46.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl Nip46Server {

#[derive(Debug, Deserialize)]
pub struct Nip46PreEvent {
#[serde(default)]
#[serde(default, deserialize_with = "de_pubkey_none_on_error")]
pub pubkey: Option<PublicKey>,

#[serde(default = "default_now")]
Expand All @@ -319,6 +319,17 @@ pub struct Nip46PreEvent {
pub content: String,
}

fn de_pubkey_none_on_error<'de, D>(deserializer: D) -> Result<Option<PublicKey>, D::Error>
where
D: serde::Deserializer<'de>,
{
if let Ok(answer) = Option::<PublicKey>::deserialize(deserializer) {
Ok(answer)
} else {
Ok(None)
}
}

fn default_now() -> Option<Unixtime> {
Some(Unixtime::now().unwrap())
}
Expand Down

0 comments on commit 5775514

Please sign in to comment.