hashcash

module
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

README

Hashcash

GoDoc Go Report Card Lint Tests Coverage Code quality license


Hashcash is a Go library which implements the hashcash proof-of-work algorithm. Hashcash has been used as a denial-of-service counter measure technique in a number of systems. To learn more about hashcash visit official page.

Usage

Computing a valid hashcash:

package main

import (
	"context"
	"fmt"

	"github.com/PoW-HC/hashcash/pkg/hash"
	"github.com/PoW-HC/hashcash/pkg/pow"
)

const maxIterations = 1 << 30

func main() {
	hasher, err := hash.NewHasher("sha256")
	if err != nil {
		// handle error
	}

	p := pow.New(hasher)

	hashcash, err := pow.InitHashcash(5, "127.0.0.1", pow.SignExt("secret", hasher))
	if err != nil {
		// handle error
	}

	solution, err := p.Compute(context.Background(), hashcash, maxIterations)
	if err != nil {
		// handle error
	}
	fmt.Println(solution)
}

Outputs:

1:5:1649257375:127.0.0.1:41965c8500f67f79b35672d7fb7e19fe5af0d51da582cbfcdbedb0f5944198bb:MgjmhCBiRV4=:MTk3YzA0
echo -n "1:5:1649257375:127.0.0.1:41965c8500f67f79b35672d7fb7e19fe5af0d51da582cbfcdbedb0f5944198bb:MgjmhCBiRV4=:MTk3YzA0" | shasum -a 256
0000067c716fa612cee5eb31eab6163e804c002841cfe96cc81f4f8034fd6006  -

Verification token:

	err := p.Verify(solution, "127.0.0.1")
	if err != nil {
		// hashcash token failed verification.
	}

Documentation

http://godoc.org/github.com/umahmood/hashcash

License

See the LICENSE file for license rights and limitations (MIT).

Directories

Path Synopsis
pkg
hash/mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
pow

Jump to

Keyboard shortcuts

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