nip13

package
v0.26.3 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 6 Imported by: 3

Documentation

Overview

Package nip13 implements NIP-13 See https://github.com/nostr-protocol/nips/blob/master/13.md for details.

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

Functions

func Check

func Check(eventID 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 Difficulty

func Difficulty(eventID string) int

Difficulty counts the number of leading zero bits in an event ID. It returns a negative number if the event ID is malformed.

func Generate

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

Generate performs proof of work on the specified event until either the target difficulty is reached or the function runs for longer than the timeout. The latter case results in ErrGenerateTimeout.

Upon success, the returned event always contains a "nonce" tag with the target difficulty commitment, and an updated event.CreatedAt.

Types

This section is empty.

Jump to

Keyboard shortcuts

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