chainy

package module
v0.0.0-...-64cc20e Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

README

chainy

The simplest immutable supply chain management

Rest-like API

GET /hash => HTTP 200 ...document
GET /next/hash1 => HTTP 301 /hash2
GET /next/ => HTTP 301 /epoch-hash

Headers for /hashX

Content-Length: <number> (mandatory)
X-Prev-Hash: <hash> (if block > 0)
X-Next-Hash: <hash> (if known)
X-Block: <int64> (0..)
X-Date: <int64>:<int64> (UTC unix epoch in seconds:nanoseconds, mandatory)
X-Content-Hash: <hash> (mandatory)
X-Sign: <string> (mandatory)

X-Sign must be valid for hashX

hashX is the hash of (X-Prev-Hash + X-Block + X-Date + X-Content-Hash), where "+" means concatenation of strings, X-Prev-Hash, X-Content-Hash are printed in hex, X-Block is a decimal X-Date is a decimal:decimal, just like in the header

Hello, world

  1. Create a key with ssh-keygen -t rsa -f simple && ssh-keygen -f simple.pub -e -m pem > simple.pub.pem.
  2. Run go run console-chain/main.go
  3. Feel free to enter entries line-by-line, they go into a 'blockchain'.
  4. In a separate window, curl -v -L http://localhost:6001/ for the first block etc.
  5. Or run go run chain-observer/main.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEntryNotFound = errors.New("no entry with the given hash")
View Source
var ErrIncorrectTimestamp = errors.New("incorrect timestamp")
View Source
var ErrMissingSigner = errors.New("*Blocks needs a signer")
View Source
var ErrMissingVerifier = errors.New("*Blocks needs a verifier")
View Source
var ErrVerificationFailed = errors.New("crypto verification failed")

Functions

This section is empty.

Types

type Blocks

type Blocks struct {
	Entries []Entry

	Signer   SignerFunc
	Verifier VerifierFunc

	sync.RWMutex
	// contains filtered or unexported fields
}

Blocks are the "chain".

func New

func New(signer SignerFunc, verifier VerifierFunc) *Blocks

New creates a blockchain.

func (*Blocks) AppendNew

func (b *Blocks) AppendNew(content []byte, instant time.Time, signIfKnown []byte) (*Entry, error)

AppendNew creats and appends an entry to the blockchain.

func (*Blocks) Get

func (b *Blocks) Get(hash []byte) (*Entry, error)

Get returns an entry by its hash.

func (*Blocks) Last

func (b *Blocks) Last() *Entry

Last returns the last entry in the blockchain.

func (*Blocks) WaitForNext

func (b *Blocks) WaitForNext(ctx context.Context, hash []byte) (*Entry, error)

WaitForNext returns the next entry after the given one

type Entry

type Entry struct {
	Instant     time.Time
	Height      int
	PrevHash    []byte
	NextHash    []byte
	ContentHash []byte
	Content     []byte
	Signature   []byte
}

Entry in an entry in the chain.

func (*Entry) Hash

func (e *Entry) Hash() []byte

Hash computes the reference hash for the entry.

type SignerFunc

type SignerFunc func([]byte) ([]byte, error)

type VerifierFunc

type VerifierFunc func(hash []byte, sign []byte) bool

Directories

Path Synopsis
play

Jump to

Keyboard shortcuts

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