Skip to content

Commit

Permalink
nip46: even better, skip any pubkey field from nip46 sign_event
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Apr 25, 2024
1 parent 5775514 commit 0cbd000
Showing 1 changed file with 0 additions and 21 deletions.
21 changes: 0 additions & 21 deletions gossip-lib/src/nip46.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,12 @@ impl Nip46Server {
};

let Nip46PreEvent {
pubkey,
created_at,
kind,
tags,
content,
} = serde_json::from_str(&params[0])?;

if let Some(pk) = pubkey {
if pk != public_key {
return Err("sign_event: pubkey mismatch".into());
}
}

let pre_event: PreEvent = PreEvent {
pubkey: public_key,
created_at: created_at.unwrap_or(Unixtime::now().unwrap()),
Expand Down Expand Up @@ -306,9 +299,6 @@ impl Nip46Server {

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

#[serde(default = "default_now")]
pub created_at: Option<Unixtime>,

Expand All @@ -319,17 +309,6 @@ 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 0cbd000

Please sign in to comment.