Skip to content

Commit 1195ee3

Browse files
committed
nostr: ignore malformed public keys during NIP19 event (nevent) parsing
Fixes #432 Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 7b0a582 commit 1195ee3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

crates/nostr/src/nips/nip19.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl Nip19Event {
421421
// the pubkey of the event"
422422
AUTHOR => {
423423
if author.is_none() {
424-
author = Some(PublicKey::from_slice(bytes)?);
424+
author = PublicKey::from_slice(bytes).ok(); // NOT propagate error if public key is invalid
425425
}
426426
}
427427
RELAY => {
@@ -797,6 +797,12 @@ mod tests {
797797
assert_eq!(coordinate.kind, expected_kind);
798798
assert_eq!(coordinate.identifier, exected_identifier);
799799
}
800+
801+
#[test]
802+
fn test_parse_nevent_with_malformed_public_key() {
803+
let event = Nip19Event::from_bech32("nevent1qqsqye53g5jg5pzw87q6a3nstkf2wu7jph87nala2nvfyw5u3ewlhfspr9mhxue69uhkymmnw3ezumr9vd682unfveujumn9wspyqve5xasnyvehxqunqvryxyukydr9xsmn2d3jxgcn2wf5v5uxyerpxucrvct9x43nwwp4v3jnqwt9x5uk2dpkxq6kvwf3vycrxe35893ska2ytu").unwrap();
804+
assert!(event.author.is_none());
805+
}
800806
}
801807

802808
#[cfg(bench)]

0 commit comments

Comments
 (0)