Giter VIP home page Giter VIP logo

tool-db's Introduction

Tool Db

ToolDb is a peer-to-peer model for a decentralized database, inspired by GundB

It is the mix of a lot of cool concepts into one;

  • Cryptographically secure.
  • Offline first.
  • Fully decentralized.
  • Capable of providing realtime updates.
  • Key-value/document storage.
  • Works in the Browser and Nodejs seamlessly.

For a more detailed documentation head here;

https://github.com/Manwe-777/tool-db-docs

(No live version just yet!, until the protocol is more finalized)

We push towards of the concept of federated servers, where we set up a p2p mesh network between any servers who want to join the swarm, and have those servers manage the connection and data sharing between them, while allowing client peers to connect to them to push updates to the database. This setup IS NOT a requirement! It is just what I think is the best and most reliable way of creating a p2p network for dApps using both desktop and web compatible technologies. Any peer has the capability of connecting to any other peer trough websockets, and modifiying the code to allow webRtc connections between web peers is absolutely possible.

Since anyone can join a federated server swarm to help growing the network we use cryptography (basic public and private key authenthication and signature validation) to ensure all messages are coming from the real authors of the data that they intend to modify; this way by joining a swarm all peers in it can help validate without even having full data; even a new server peer can help, because all information is stored on each message and we dont rely on any centralized database to fetch users data.

Please check the chain-swarm repository to see how a federated server swarm would look like, Tool Db only handles the connection and messaging between peers, but it does not have any logic for peer discovery. We do that using discovery-channel, but you can use any DHT/networking solution you want! even WebRTC between browsers works using the toolDbWebrtc transport.

Future work

While the database is currently functioning as expected, there are many things that could be added or improved to make it even better!

  • Allow data encryption (proably built in), add methods for ECC encryption, shared keys, etc.
  • Allow adding Noise/encryption to connections (probably based on the peer identity, requires initial keys exchange on connection)

Install

You can install ToolDb via npm or yarn;

npm install tool-db

or use it via script in your html;

<script src="https://unpkg.com/tool-db/bundle.js"></script>

That will include all of ToolDb exports in tooldb, then you can use it like;

const { ToolDb, sha256 } = tooldb;

Base usage

Creating a webrtc peers network is as easy as;

import { ToolDb, ToolDbWebrtc } from "tool-db";

const db = new ToolDb({
  networkAdapter: ToolDbWebrtc,
  debug: true,
});

From there you can put and get data using the api;

db.putData("foo-key", "var").then(console.log);

There is a lot more you can do, like subscribe for updates, built-in users credentials validation based on ECC, create federated networks, run servers on Nodejs, auto-replicate data trough them, etc. Make sure more you read trough the documentation!

tool-db's People

Contributors

dderevjanik avatar manwe-777 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tool-db's Issues

Browser package

Hello,

would it be possible to also publish a browser-compatible package? It could be much easier to play with tool-db by using script from CDN like https://unpkg.com/tool-db , so It would be possible to just paste script inside your static html file and test tool-db directly from your browser without need to create dummy node project with all libraries (ts, webpack, etc.).

Btw, really nice project!

Provide Id after initialization

Is there any way to obtain id right after initialization (generatePairKey)? https://github.com/Manwe-777/tool-db/blob/main/src/tooldb.ts#L279 . Accessing tooldb.options.id after initializing ToolDb instance returns nothing, because generatePairKey is async action inside constructor.

Possible solutions:

  • ๐Ÿ‘Ž Provide callback to constructor method constructor(options: Partial<ToolDbOptions> = {}, onId: (id) => void)
  • ๐Ÿ‘Ž Provide listener to ToolDb -> onId: (id: string) => void
  • ๐Ÿ‘ Provide listener to ToolDb -> onInit: () => void after which I know that tooldb was initialized (id generated) and I can access tooldb.options.id

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.