Giter Club home page Giter Club logo

hashcash's Introduction

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

https://pkg.go.dev/github.com/PoW-HC/hashcash

License

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

hashcash's People

Contributors

halfi avatar

Stargazers

 avatar

hashcash's Issues

flatten module

remove pkg folder, for example instead of:

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

do:

"github.com/PoW-HC/hashcash/hash"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.