From 0e72540696b5adcf96ad3f5ce938a57f36b5912b Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 20 Aug 2024 10:31:52 -0300 Subject: [PATCH] nip13: fail when pubkey is not provided -- may help some clueless people like me. --- nip13/nip13.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nip13/nip13.go b/nip13/nip13.go index 0e4832d..53538e4 100644 --- a/nip13/nip13.go +++ b/nip13/nip13.go @@ -15,6 +15,7 @@ import ( var ( ErrDifficultyTooLow = errors.New("nip13: insufficient difficulty") ErrGenerateTimeout = errors.New("nip13: generating proof of work took too long") + ErrMissingPubKey = errors.New("nip13: attempting to work on an event without a pubkey, which makes no sense") ) // Difficulty counts the number of leading zero bits in an event ID. @@ -53,6 +54,10 @@ func Check(id string, minDifficulty int) error { // Upon success, the returned event always contains a "nonce" tag with the target difficulty // commitment, and an updated event.CreatedAt. func Generate(event *nostr.Event, targetDifficulty int, timeout time.Duration) (*nostr.Event, error) { + if event.PubKey == "" { + return nil, ErrMissingPubKey + } + tag := nostr.Tag{"nonce", "", strconv.Itoa(targetDifficulty)} event.Tags = append(event.Tags, tag) var nonce uint64