Socket
Book a DemoInstallSign in
Socket

blockchain-ts

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blockchain-ts

Fully fledged PoW blockchain implementation in TypeScript.

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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)

FAQs

Package last updated on 28 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.