nip13

package
v0.37.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)

Functions

func Check

func Check(id string, minDifficulty int) error

Check reports whether the event ID demonstrates a sufficient proof of work difficulty. Note that Check performs no validation other than counting leading zero bits in an event ID. It is up to the callers to verify the event with other methods, such as nostr.Event.CheckSignature.

func CommittedDifficulty added in v0.34.7

func CommittedDifficulty(event *nostr.Event) int

CommittedDifficulty returns the Difficulty but checks the "nonce" tag for a target.

if the target is smaller than the actual difficulty then the value of the target is used. if the target is bigger than the actual difficulty then it returns 0.

func Difficulty

func Difficulty(id string) int

Difficulty counts the number of leading zero bits in an event ID.

func DoWork added in v0.34.9

func DoWork(ctx context.Context, event nostr.Event, targetDifficulty int) (nostr.Tag, error)

DoWork() performs work in multiple threads (given by runtime.NumCPU()) and returns the first nonce (as a nostr.Tag) that yields the required work. Returns an error if the context expires before that.

func Generate deprecated

func Generate(event *nostr.Event, targetDifficulty int, timeout time.Duration) (*nostr.Event, error)

Deprecated: use DoWork() instead.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL