pow

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExtInvalid    = fmt.Errorf("extension sum invalid")
	ErrHashcashEmpty = fmt.Errorf("hashcash empty")
)
View Source
var (
	ErrMaxIterationsExceeded = fmt.Errorf("max iterations exceeded")
	ErrWrongResource         = fmt.Errorf("wrong resource")
	ErrChallengeExpired      = fmt.Errorf("challenge expired")
	ErrWrongChallenge        = fmt.Errorf("wrong challenge")
)

Functions

This section is empty.

Types

type ExtGeneratorFunc

type ExtGeneratorFunc func(*Hashcach) (string, error)

func SignExt

func SignExt(secret string, hasher hash.Hasher) ExtGeneratorFunc

SignExt creates signed extension See extSum description for hash generating details

type ExtValidatorFunc

type ExtValidatorFunc func(*Hashcach) error

func VerifyExt

func VerifyExt(secret string, hasher hash.Hasher) ExtValidatorFunc

VerifyExt verify extension from hashcash to validate hashcash was provided by server. See extSum description for hash generating details

type Hashcach

type Hashcach struct {
	Version  int32
	Bits     int32
	Date     time.Time
	Resource string
	Ext      string
	Rand     []byte
	Counter  int64
}

Hashcach struct to marshal and unmarshal hashcach to string or proto buf

func InitHashcash

func InitHashcash(bits int32, resource string, extGenerator ExtGeneratorFunc) (*Hashcach, error)

InitHashcash initiate new hashcash

func NewHashcach

func NewHashcach(
	version int32,
	bits int32,
	date time.Time,
	resource string,
	ext string,
	rand []byte,
	counter int64,
) *Hashcach

func (*Hashcach) String

func (h *Hashcach) String() string

String implements fmt.Stringer interface to get string hashcash

type Options

type Options func(*options)

func WithChallengeExpDuration

func WithChallengeExpDuration(callback time.Duration) Options

func WithValidateExtFunc

func WithValidateExtFunc(callback ExtValidatorFunc) Options

type POW

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

POW proof of work class

func New

func New(s hash.Hasher, opts ...Options) *POW

New constructor

func (*POW) Compute

func (p *POW) Compute(ctx context.Context, h *Hashcach, max int64) (*Hashcach, error)

Compute time waster. Do all useless load.

func (*POW) Verify

func (p *POW) Verify(h *Hashcach, resource string) error

Verify that hashcash correct and provided by server

Jump to

Keyboard shortcuts

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