Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

orbit-db-win

orbitdb2MIT0.21.4

Distributed p2p database on IPFS

readme

OrbitDB

Gitter CircleCI Status npm version node

OrbitDB is a serverless, distributed, peer-to-peer database. OrbitDB uses IPFS as its data storage and IPFS Pubsub to automatically sync databases with peers. It's an eventually consistent database that uses CRDTs for conflict-free database merges making OrbitDB an excellent choice for decentralized apps (dApps), blockchain applications and offline-first web applications.

Test it live at Live demo 1, Live demo 2, or P2P TodoMVC app!

OrbitDB provides various types of databases for different data models and use cases:

  • log: an immutable (append-only) log with traversable history. Useful for "latest N" use cases or as a message queue.
  • feed: a mutable log with traversable history. Entries can be added and removed. Useful for "shopping cart" type of use cases, or for example as a feed of blog posts or "tweets".
  • keyvalue: a key-value database just like your favourite key-value database.
  • docs: a document database to which JSON documents can be stored and indexed by a specified key. Useful for building search indices or version controlling documents and data.
  • counter: Useful for counting events separate from log/feed data.

All databases are implemented on top of ipfs-log, an immutable, operation-based conflict-free replicated data structure (CRDT) for distributed systems. If none of the OrbitDB database types match your needs and/or you need case-specific functionality, you can easily implement and use a custom database store of your own.

Project status & support

Status: in active development

NOTE! OrbitDB is alpha-stage software. It means OrbitDB hasn't been security audited and programming APIs and data formats can still change. We encourage you to reach out to the maintainers if you plan to use OrbitDB in mission critical systems.

This is the Javascript implementation and it works both in Browsers and Node.js with support for Linux and OS X (Windows is not supported yet). The minimum required version of Node.js is now 8.6.0 due to the usage of ... spread syntax. LTS versions (even numbered versions 8, 10, etc) are preferred.

To use with older versions of Node.js, we provide an ES5-compatible build through the npm package, located in dist/es5/ when installed through npm.

Community Calls

We also have regular community calls, which we announce in the issues in the @orbitdb welcome repository. Join us!

Table of Contents

Usage

Read the GETTING STARTED guide for a more in-depth tutorial and to understand how OrbitDB works.

CLI

For the CLI tool to manage orbit-db database, see OrbitDB CLI.

It can be installed from npm with:

npm install orbit-db-cli -g

Module with IPFS Instance

If you're using orbitd-db to develop browser or Node.js applications, use it as a module with the javascript instance of IPFS

Install dependencies:

npm install orbit-db ipfs
const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')
// OrbitDB uses Pubsub which is an experimental feature
// and need to be turned on manually.
// Note that these options need to be passed to IPFS in
// all examples even if not specified so.
const ipfsOptions = {
  EXPERIMENTAL: {
    pubsub: true
  }
}

// Create IPFS instance
const ipfs = new IPFS(ipfsOptions)

ipfs.on('error', (e) => console.error(e))
ipfs.on('ready', async () => {
  const orbitdb = await OrbitDB.createInstance(ipfs)

  // Create / Open a database
  const db = await orbitdb.log('hello')
  await db.load()

  // Listen for updates from peers
  db.events.on('replicated', (address) => {
    console.log(db.iterator({ limit: -1 }).collect())
  })

  // Add an entry
  const hash = await db.add('world')
  console.log(hash)

  // Query
  const result = db.iterator({ limit: -1 }).collect()
  console.log(JSON.stringify(result, null, 2))
})

Module with IPFS Daemon

Alternatively, you can use ipfs-api to use orbit-db with a locally running IPFS daemon. Use this method if you're using orbitd-db to develop backend or desktop applications, eg. with Electron.

Install dependencies:

npm install orbit-db ipfs-http-client
const IpfsClient = require('ipfs-http-client')
const OrbitDB = require('orbit-db')

const ipfs = IpfsClient('localhost', '5001')

const orbitdb = await OrbitDB.createInstance(ipfs)
const db = await orbitdb.log('hello')
// Do something with your db.
// Of course, you may want to wrap these in an async function.

API

See API.md for the full documentation.

Examples

Install dependencies

git clone https://github.com/orbitdb/orbit-db.git
cd orbit-db
npm install

You'll also need babel and webpack, if you don't have them installed already:

npm install --global babel-cli
npm install --global webpack

Some dependencies depend on native addon modules, so you'll also need to meet node-gyp's installation prerequisites. Therefore, Linux users may need to

make clean && make

to redo the local package-lock.json with working native dependencies.

Browser example

In macOS:

npm run build
npm run examples:browser-macos

In Linux:

npm run build
npm run examples:browser-linux

Check the code in examples/browser/browser.html and try the live example.

Node.js example

npm run examples:node

Eventlog

See the code in examples/eventlog.js and run it with:

node examples/eventlog.js

More examples at examples.

Packages

OrbitDB uses the following modules:

OrbitDB Store Packages

To understand a little bit about the architecture, check out a visualization of the data flow at https://github.com/haadcode/proto2 or a live demo: http://celebdil.benet.ai:8080/ipfs/Qmezm7g8mBpWyuPk6D84CNcfLKJwU6mpXuEN5GJZNkX3XK/.

Community-maintained Typescript typings are available here: https://github.com/orbitdb/orbit-db-types

Development

Run Tests

npm test

Build

npm run build

Benchmark

node benchmarks/benchmark-add.js

See benchmarks/ for more benchmarks.

Logging

To enable OrbitDB's logging output, set a global ENV variable called LOG to debug,warn or error:

LOG=debug node <file>

Frequently Asked Questions

We have an FAQ! Go take a look at it. If a question isn't there, open an issue and suggest adding it. We can work on the best answer together.

Contributing

Take a look at our organization-wide Contributing Guide. You'll find most of your questions answered there. Some questions may be answered in the FAQ, as well.

As far as code goes, we would be happy to accept PRs! If you want to work on something, it'd be good to talk beforehand to make sure nobody else is working on it. You can reach us on Gitter, or in the issues section.

We also have regular community calls, which we announce in the issues in the @orbitdb welcome repository. Join us!

If you want to code but don't know where to start, check out the issues labelled "help wanted".

Please note that we have a Code of Conduct, and that all activity in the @orbitdb organization falls under it. Read it when you get the chance, as being part of this community means that you agree to abide by it. Thanks.

Sponsors

The development of OrbitDB has been sponsored by:

If you want to sponsor developers to work on OrbitDB, please reach out to @haadcode.

License

MIT © 2015-2018 Protocol Labs Inc., Haja Networks Oy

changelog

Changelog

v0.20.0

This release contains API breaking changes! The release IS backwards compatible with respect to old OrbitDB addresses and will be able to process and read old data-structures. The shape of the Entry object has also changed to include an identity field as well as increment the version v to 1. The hash property now holds a CIDv1 multihash string.

API breaking changes:

  • Constructor:

    The OrbitDB constructor requires an instance of identity to be passed as an argument:
    const orbitdb = new OrbitDB(ipfs, identity, [options])
  • Creating an OrbitDB instance:

    The preferred method for creating an instance of OrbitDB is the async createInstance method which will create an identity for you if one is not passed in the options.
    const orbitdb = await OrbitDB.createInstance(ipfs, [options])
  • OrbitDB key

    The key property has been removed and replaced with identity. You can access the public-key with:
    orbitdb.identity.publicKey

Read further and see the API documentation, examples and Getting Started Guide to learn more about the changes. Note that we don't use semver for the npm module, so be sure to lock your orbit-db dependency to the previous release if you don't want to upgrade.

Improved Write Permissions

OrbitDB now supports dynamically granting write-access to keys after database-creation. Previous releases required the database address to change if the write-access keys were changed. We've added an AccessController module which allows custom-logic access-controllers to be added to OrbitDB. Two examples of how to create and add new access-controllers can be found in the repo. An ethereum-based access-controller which uses a smart-contract to determine access-rights and an OrbitDB Access Controller which uses another OrbitDB store to maintain access-rights. For more information, see: Access Control.

Identity Support

We've added orbit-db-identity-provider which allows users to link external identities, such as an Ethereum account, with their OrbitDB identity. For more information, see orbit-db-identity-provider.

Keystore fix

A bug in orbit-db-keystore in which messages larger than 32-bytes signed by the same key produced the same signature has been fixed.

js-ipfs v0.34.x support

OrbitDB now uses the ipfs-dag API and thus supports the latest js-ipfs again. :tada:

go-ipfs support

With this release, we finally bring back the support for using OrbitDB with go-ipfs (through js-ipfs-http-client). You can now use OrbitDB again with a running IPFS daemon and without starting an in-process js-ipfs node.

To make OrbitDB work again with go-ipfs, we refactored some parts of the messaging and created two new modules to do that: ipfs-pubsub-peer-monitor and ipfs-pubsub-1on1. They're both modules on top of IPFS Pubsub and are used to handle the automatic message exchange upon peers connecting.

As this is the first release with support for go-ipfs in a long time, please report any problems you may experience!

Improved test suite and documentation

We've improved the documents by adding details, fixing errors and clarifying them.

We also improved the tests a lot since the previous release. We now run the tests with js-ipfs-http-client (go-ipfs) in addition to running them with js-ipfs (Node.js). We've also cleaned up and refactored the boilerplate code for tests, improved the speed of the test run and generally polished the test suite for better readability and maintainability.

Custom stores

OrbitDB can now use a custom store through addDatabaseType(), see more here and here.

Important fixes

The previous release brought in LevelDB as the storage backend for Node.js and browser and there were some rough edges. We've fixed a bunch a problems related to using LevelDB and it should all work now.

Last, we further improved the replication code and its performance at places.

v0.19.0

This release bring a bunch of fixes and updates improving performance, stability and browser compatibility. As always, we highly encourage to update to the latest version and report any problems in https://github.com/orbitdb/orbit-db/issues.

A big thank you to all the contributors who helped and contributed to this release! <3

Replication

The previous release included a refactored version of the replication code and we've improved it even further in this release in terms of performance as well as stability. We're now seeing huge improvement in replication speed, especially when replicating a database from scratch.

To observe these improvements, run the browser examples with two (different) browser tabs and replicate a database with > 100 or so entries from tab to another.

Browser compatibility

We had some problems with browsers due to the way we used native modules. This is now fixed and OrbitDB should work in the browsers just the same as in Node.js.

LevelDB

We've switched from using filesystem-based local cache to using LevelDB as the local storage. Leveldown is used when run in Node.js and level-js is used for browsers.

General Updates

We put some work into the CRDTs library we're using and have updated OrbitDB to use the latest version. We've added more tests and improved the test suite code and tests now run faster than they did previously.

Performance

With all the updates and fixes, we're now seeing much better performance for replicating databases between peers as well as for write throughput. See benchmarks if you're interested to try it out yourself.

v0.18.0

This release is a major one as we've added new features, fixed many of the old problems, improved the performance and code base and overhauled the documentation. OrbitDB is now more robust, easier to use, faster and comes with much awaited write-permissions feature.

This release contains API breaking changes with no backward compatibility! Read further and see the API documentation, examples and Getting Started Guide to learn more about the changes. Note that we don't use semver for the npm module, so be sure to lock your orbit-db dependency to the previous release if you don't want to upgrade.

Write-permissions

OrbitDB now has write-permissioned databases! \o/ This gives us verifiable, distributed databases and data structures enabling tons of new use cases and possibilities. User-owned data collections, feeds and lists, State and Payment Channels, and many more!

Permissions are defined by public keys and databases in OrbitDB support one or multiple write keys per database. Each database update is signed with a write-access key and the signature is verified by the clients against access control information. Next step is to extend the access control functionality to include read permissions. Read more about Access Control and Keys.

Addresses

OrbitDB databases, their name and ID, are now addressed through a naming scheme:

/orbitdb/Qmd8TmZrWASypEp4Er9tgWP4kCNQnW4ncSnvjvyHQ3EVSU/my/database/hello

Read more about Addresses.

Replication

The previous versions of OrbitDB had a flaky replication implementation which has been completely re-written for this release. We've made performance improvements and more importantly, peers now start syncing the database automatically and reliably.

Performance

Several performance improvements made throughout OrbitDB's code base together with latest IPFS we're seeing much better throughput numbers in benchmarks. There are still many improvements to be made!

Documentation and Examples

We've written a brand new Getting Started Guide to work as a tutorial and a place to understand OrbitDB's features and usage. The API documentation was also updated to reflect latest features and changes.

All examples were updated along with an updated UI for the browser demo. Another small browser demo was added and there's a TodoMVC with Orbitdb example in the works.

Code Base Improvements

Due to legacy reasons, OrbitDB previously used a wrapper module for IPFS called ipfs-daemon. We have removed and deprecated ipfs-daemon and are now using js-ipfs directly!

We've switched to using async/await in the code base throughout the modules. This means the minimum required version of Node.js is now 8.0.0. To use with older versions of Node.js, we provide an ES5-compatible build. We've also added support for logging, which can be turned on with LOG=[debug|warn|error] environment variable.

v0.12.0

  • IPFS pubsub