mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-05 16:20:14 +02:00
nip13: fail when pubkey is not provided -- may help some clueless people like me.
This commit is contained in:
parent
18dbda437b
commit
0e72540696
@ -15,6 +15,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
ErrDifficultyTooLow = errors.New("nip13: insufficient difficulty")
|
ErrDifficultyTooLow = errors.New("nip13: insufficient difficulty")
|
||||||
ErrGenerateTimeout = errors.New("nip13: generating proof of work took too long")
|
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.
|
// 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
|
// Upon success, the returned event always contains a "nonce" tag with the target difficulty
|
||||||
// commitment, and an updated event.CreatedAt.
|
// commitment, and an updated event.CreatedAt.
|
||||||
func Generate(event *nostr.Event, targetDifficulty int, timeout time.Duration) (*nostr.Event, error) {
|
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)}
|
tag := nostr.Tag{"nonce", "", strconv.Itoa(targetDifficulty)}
|
||||||
event.Tags = append(event.Tags, tag)
|
event.Tags = append(event.Tags, tag)
|
||||||
var nonce uint64
|
var nonce uint64
|
||||||
|
Loading…
x
Reference in New Issue
Block a user