A simple block-chain framework written in C#
This project creates a framework to do the following:
- Create and manage a block-chain storage for storing blocks linked to the previous block via a custom hash function.
- Provide helper methods to store and retrieve data from block-chain.
- Handle security and signing in messages passing and adding items to the chain, including:
- Give helper methods to create required signing keys
- Verify blocks as they are created using the signing keys
- Have multiple persisting strategies for easier use.
It is simple to use. There is a ChainFactory
that creates an object of type Chain
, which is all needed.
var chain = ChainFactory.Create<string>();
If creating your own block, first get its hash with CreateBlock
, and then add it to chain with AddBlock
var message = "I'm a new block";
var hash = chain.CreateBlock(message);
chain.AddBlock(message, hash);
Send the created block along with its hash.
If you have received a block and it has a content and a hash, call the AddBlock
method of the chain to insert it in your local block-chain. Listen for the Boolean result of this method, which checks the incoming block, returns true and adds it to the chain only if this block matches the chain so far.
if(chain.AddBlock(message, hash))
{
//The block is ok
}
else
{
//The block is corrupted.
}
An example is also available which is just a proof of concept type of project. ChainSaw is a sample chat application that allows two clients to chat using a server. The server in this case is different with other chat application servers in that it's a dummy message passing proxy and the data is kept and verified in client side using block-chains.