pow

package
v2.0.0-...-2cd5660 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package pow implements the Curl-based proof of work for arbitrary binary data.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCancelled = errors.New("canceled")
	ErrDone      = errors.New("done")
)

errors returned by the PoW

Hash defines the hash function that is used to compute the PoW digest.

Functions

func Score

func Score(msg []byte) float64

Score returns the PoW score of msg.

Types

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

The Worker performs the PoW.

func New

func New(numWorkers ...int) *Worker

New creates a new PoW Worker. The optional numWorkers specifies how many go routines should be used to perform the PoW.

func (*Worker) Mine

func (w *Worker) Mine(ctx context.Context, data []byte, targetScore float64) (uint64, error)

Mine performs the PoW for data. It returns a nonce that appended to data results in a PoW score of at least targetScore. The computation can be canceled anytime using ctx.

Jump to

Keyboard shortcuts

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