Git Product home page Git Product logo

hlog's Introduction

HashLog

Coverage Status

Principles

  • Records are immutable
  • Records are ordered
  • It must be possible to check hash(Xi) for any i
  • hash(Xi) can be sent to anyone as a proof
  • hash(Xi) == hash(X, hash(Xi-1))
  • You do not need X to perform the check

Installation

$ pip install hlog

Usage

Getting started

# create a chain
c = Chain()

# send some messages
c.append(message="Alice gives 10.36 euros to Bob", amount=10.36, currency="EUR")
c.append(message="Bob gives 2 dollars to Alice", amount=2, currency="USD")

# you can loop through the chain records
used_currencies = set(r.fields["currency"] for r in c.records)

# call verify() to ensure records have not been modified
c.verify()

Raising an exception during validation

c.verify(raise_on_error=True)

Verify will raise a ModifiedRecordException. It has 3 interesting attributes:

  • index: the index in the chain where validation starts to fail
  • message: a user-friendly message to indicate the error
  • record: the Record object itself

Dumping

c = Chain()
c.append(message="hello")
c.append(message="wonderful")
c.append(message="world")

rows = c.dump()

rows is a tuple of bytes, each item being one record of the chain.

Restoring from a dump

If you want to reconstruct your chain based on a file or database records, you can use Chain.from_dump()

c = Chain()
c.append(message="hello")
c.append(message="wonderful")
c.append(message="world")

d = c.dump()

c2 = Chain.from_dump(d)

c2.verify()

hlog's People

Contributors

ericgazoni avatar

Watchers

 avatar

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.