hashcash

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: MIT Imports: 10 Imported by: 12

README

hashcash

Implementation of Hashcash version 1 in Go.

The implementation provides an API and a command line utility (hc) to mint or check a Hashcash stamp.

Installation

go get github.com/catalinc/hashcash

To install the hc command line tool:

cd $GOPATH/github.com/catalin/hashcash/cmd/hc && go install

Usage

API

package main

import (
    "fmt"

    hc "github.com/catalinc/hashcash"
) 
 
func main() {
    h := hc.NewStd() // or .New(bits, saltLength, extra)
    
    // Mint a new stamp
    stamp := hc.Mint("something")
    fmt.Println(t)

    // Check a stamp
    valid := hc.Check("1:20:161203:something::+YO19qNZKRs=:a31a2")
    if valid {
        fmt.Println("Valid")
    } else {
        fmt.Println("Invalid")
    }
}

Command line

[cata:...ithub.com/catalinc/hashcash]$ hc -help 
Usage of hc:
  -bits uint
    	Specify required collision bits (default 20)
  -check string
    	Check a stamp for validity
  -extra string
    	Extra extension to a minted stamp
  -mint string
    	Mint a new stamp
  -salt uint
    	Salt length (default 8)
[cata:...ithub.com/catalinc/hashcash]$ hc -mint=something
1:20:161203:something::CIyEo8VUcVY=:3ed98b

License

MIT

Documentation

Overview

Package hashcash provides an implementation of Hashcash version 1 algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

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

Hash provides an implementation of hashcash v1.

func New

func New(bits uint, saltLen uint, extra string) *Hash

New creates a new Hash with specified options.

func NewStd

func NewStd() *Hash

NewStd creates a new Hash with 20 bits of collision and 8 bytes of salt chars.

func (*Hash) Check

func (h *Hash) Check(stamp string) bool

Check whether a hashcash stamp is valid.

func (*Hash) CheckNoDate

func (h *Hash) CheckNoDate(stamp string) bool

CheckNoDate checks whether a hashcash stamp is valid ignoring date.

func (*Hash) Mint

func (h *Hash) Mint(resource string) (string, error)

Mint a new hashcash stamp for resource.

Directories

Path Synopsis
cmd
hc

Jump to

Keyboard shortcuts

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