1.0.3 • Published 6 years ago

blockchain-js-core v1.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

= Blockchain demo

A simple typescript implementation of a Bitcoin-like distributed blockchain consensus algortihm.

The aim is to have a base work to make experiments with it.

== Introduction

This is perfect for showing simple code on how the bitcoin works, so this can be used as a support for demoes.

This program maintains a distributed database accross active nodes, interconnected by the network.

Since this is written in typescript, blockchain nodes can either run on NodeJS or in the browser.

Traditionnal blockchain implemented concepts :

  • block chain (data is a list of blocks),
  • block validity,
  • proof of work (proof of stake can also be implementation as well as other algorithms,

Concepts not in Bitcoin (as far as I know)

  • branches : like with git, the blockchain structure supports branches. There is a master branch called master, then any branch can be built on it !
  • block data is in Ordered-JSON.

== Build

Do a npm install, followed by tsc.

To run the REST web server : node dist/blockchain-node.js

To run the tests : node dist/index.js

== Documentation

Look first at the index.ts, test.ts and blockchain-node.ts. Those are the executable files.

The main data structure is in block.ts.

Node API is in node-api.ts.

Implementation of a node is in node-impl.ts.

The algorithm for transfering data between nodes is in node-transfer.ts.

Other files are more technical (tools, networking, ...)

=== What does the block store for the users ?

A list of JSON data

=== How are blocks identified

A SHA256 hashing function over the Ordered-JSON representation of the block.

==== Ordered-JSON

The idea is to have only one valid JSON representation of the data.

In JSON one can write one same object in different equivalent forms. For instance :

source

{ "a": 5, "b": 6

}

and

source

{ "b": 6, "a": 5

}

represent the same data.

This poses a problem because it means that depending on how the data has been JSON serialized, it will get to different SHA256 hashs.

So the solution to this is to have a stricter JSON representation where data has ony one representation. The only difference with normal JSON is that in Ordered-JSON, the fields object data type are serialized by lexical order.

This means that between the two JSON representations above, only the first is a valid Ordered-JSON representation.

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago