1.0.1 • Published 6 years ago

ethmimo-orbit v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

mimo-orbit

Custom identity store on OrbitDB

An append-only log with traversable history. Add new claims about your identity to your DB. It uses digital signatures to ensure that all data added to the DB has been approved by the owner of the identity.

Table of Contents

Install

npm install ethmimo-orbit

Usage

First, create an instance of OrbitDB and Web3:

const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')
const Web3 = require('web3')
const MimoStore = require('mimo-orbit')

const ipfs = new IPFS()
const web3 = new Web3()

// add custom type to orbitdb
OrbitDB.addDatabaseType(MimoStore.type, MimoStore)

// instantiate custom store
const orbitdb = new OrbitDB(ipfs)
const store = orbitdb.create(ensname, web3.eth.ens.registrar.owner(ensname), CustomStore.type)

Add a claim to it, if the signature of the data is a valid one then the data will be added successfully:

store.add({ bio: 'I <3 Mimo' }, signature)
  .then(() => {
    const items = store.iterator().collect()
    items.forEach((e) => console.log(e.bio))
    // "I <3 Mimo"
  })

Later, when the database contains data, load the history and query when ready:

store.events.on('ready', () => {
  const items = log.iterator().collect()
  items.forEach((e) => console.log(e.bio))
  // "I <3 Mimo"
})

API

See orbit-db's API Documenations on eventlogs (the base class for MimoStore) for full details. The only difference between MimoStore and EventStore is its use of signatures for adding data.

License

MIT © 2018 Ghilia Weldesselasie