Coder Social home page Coder Social logo

chefbingbong / blockchain Goto Github PK

View Code? Open in Web Editor NEW

This project forked from krystianity/blockchain

0.0 0.0 0.0 324 KB

:muscle::link: PoW Blockchain implementation in Typescript :currency_exchange:

License: Apache License 2.0

JavaScript 23.63% TypeScript 76.37%

blockchain's Introduction

blockchain

Fully fledged PoW blockchain implementation in TypeScript.

Features/Setup

  • Proof of Work (similar to Bitcoin's Hashcash)
  • Consensus (similar to Bitcoin's longest chain)
  • Implemented Node P2P communication via HTTP/S (register, transaction, blocks)
  • Addresses in RSA PEM 1024/2048 easily swapable with e.g. elliptic curves
  • Transaction SHA256 signature validation
  • SHA256 Block Hashes
  • All node operations are call-able via HTTP API
  • Chain backed to disk in nodes via SQLite3 easily swapable with a different backend

Use

Prepare

Requires Node.js > 8.x.x and yarn (npm i -g yarn).

yarn

Start

yarn start

Test

3 Node Network E2E Tests

P2P Protocol

yarn test:p2p

Consensus Algorithm

yarn test:consensus

HTTP Node API

Client Facing

  • GET /api/address/new blocking operation

  • POST /api/address/transactions/:address - {address}

  • POST /api/address/balance/:address - {address}

  • GET /api/blocks/last

  • POST /api/transaction/sign - {transaction, address, privateKey} test endpoint

  • POST /api/transactions/new - {sender, recipient, amount, payload, timestamp, signature}

Operations (trigger)

  • GET /api/mine blocking operation
  • GET /api/nodes/resolve

P2P Node Protocol

  • POST /api/nodes/register - {nodes}
  • GET /api/peer/chain p2p node endpoint
  • POST /api/peer/transaction - {transaction} p2p node endpoint
  • POST /api/peer/block - {block} p2p node endpoint

License

Apache License 2.0

Further Scaling Oppertunities

  • During conflict resolvation the servering node streams TransferInterface to the fetching client node, but currently the client node does not stream insert the blockchain.
  • Currently the blockchain validation function is based on a full in memory process, to scale further this needs to either be chunked/streamed or based on a db process.
  • The balance of a sender should be checked when a transaction is made and when such a transaction is received by another node via peer communcation (requires a single function call)
  • Additional hardening might be needed in case of blocks that are mined at the exact same time
  • Addresses should be switched to elliptic curves to generate and sign faster
  • SQLite3 should be switched with a more scaleable database
  • Nodes should constantly extend their known nodes, by asking for other registered nodes (easily implemented)

blockchain's People

Contributors

krystianity avatar dependabot[bot] 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.