How to use orbit-db - 10 common examples

To help you get started, we’ve selected a few orbit-db examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github christroutner / orbit-tests / db-replication / firewalled-node / firewalled-node.js View on Github external
ipfs.on('ready', async () => {
  console.log(`ipfs ready.`)

  let db

  await ipfs.swarm.connect(MASTER_MULTIADDR)

  try {
    const orbitdb = await OrbitDB.createInstance(ipfs, {
      directory: "./orbitdb/examples/eventlog"
    });

    // Make the DB public, so that anyone can write.
    const options = {
      accessController: {
        write: ["*"]
      }
    }

    db = await orbitdb.eventlog(DB_ADDRESS, options);
    await db.load();

  } catch (e) {
    console.error(e)
    process.exit(1)
github 3box / 3box-js / src / replicator.js View on Github external
async _init (opts) {
    this._pubsub = new Pubsub(this.ipfs, (await this.ipfs.id()).id)
    this._orbitdb = await OrbitDB.createInstance(this.ipfs, { directory: opts.orbitPath })
    this._pubsub.subscribe(PINNING_ROOM, (topic, data) => {
      // console.log('message', topic, data)
      this.events.emit('pinning-room-message', topic, data)
    }, (topic, peer) => {
      // console.log('peer', topic, peer)
      this.events.emit('pinning-room-peer', topic, peer)
    })
  }
github PACTCare / Dweb.page / src / js / ipfs / startIpfs.js View on Github external
export default async function startIpfs() {
  // FIXME: Doesn't work on brave
  console.log('Starting ipfs and orbitdb...');
  window.ipfsNode = await IPFS.create(ipfsOptions);

  const options = { id: 'local-id' };
  const identity = await Identities.createIdentity(options);
  const orbitdb = await OrbitDB.createInstance(window.ipfsNode, { identity });
  // each user has their own metadata database
  window.metadataDb = await orbitdb.docs('metadataDb', { indexBy: 'fileId' });
  await window.metadataDb.load();

  // TODO: Sharding of public database
  // Create Public Metadata Registry
  // const publicDb = {
  //   // Give write access to everyone
  //   accessController: {
  //     write: ['*'],
  //   },
  // };
  // const metadataRegistry = await orbitdb.eventlog('metadataRegistry', publicDb);

  // Connect to Public Metadata Registry
  const metadataRegistry = await orbitdb.open('/orbitdb/zdpuAwxsL6bPpUkmzRFuRzv513htstdndWHsfjgCHmaBuJw99/metadataRegistry');
github orbitdb / orbit-db-cli / src / lib / open-database.js View on Github external
logger.debug(`Going online: ${ipfsConfig.start}`)
  if (ipfsConfig.start) logger.info(`IPFS going online!`)

  const ipfs = await startIpfs(ipfsConfig)

  const peerId = await ipfs.config.get('Identity.PeerID')
  logger.debug("PeerID:", peerId)

  // Try connecting immediately to peer ID given as 'from' argument
  if (argv.from) {
    console.log(">>", argv.from)
    ipfs.swarm.connect(argv.from)
  }

  const directory = process.env.ORBITDB_PATH || config.defaultDatabaseDir
  const orbitdb = await OrbitDB.createInstance(ipfs, {
      directory: directory,
      peerId: peerId })

  logger.debug(`Loading database '${database}'`)

  const db = await orbitdb.open(database, {
    maxHistory: -1,
    indexBy: argv.indexBy,
    replicate: replicate || false,
    type: openAsType,
    create: openAsType ? true : false,
    key: argv.key,
    sync: replicate,
    localOnly: argv.localOnly || false
  })
github OriginProtocol / origin / origin-messaging / src / index.js View on Github external
const startOrbitDbServer = async ipfs => {
  // Remap the peer connected to ours which will wait before exchanging heads
  // with the same peer
  const orbitGlobal = new OrbitDB(ipfs, config.ORBIT_DB_PATH, {
    keystore: new InsertOnlyKeystore()
  })

  orbitGlobal._onPeerConnected = _onPeerConnected

  orbitGlobal.keystore.registerSignVerify(
    config.GLOBAL_KEYS,
    undefined,
    verifyRegistrySignature,
    message => {
      handleGlobalRegistryWrite(orbitGlobal, message.payload)
    }
  )

  const globalRegistry = await orbitGlobal.kvstore(config.GLOBAL_KEYS, {
    write: ['*']
github OriginProtocol / origin / js / messaging / orbit_server.js View on Github external
ipfs.on("ready", async () => {
  // remap the peer connected to ours which will wait before exchanging heads with the same peer
  const orbit_global = new OrbitDB(ipfs, "odb/Main", {keystore:new InsertOnlyKeystore()})
  orbit_global._onPeerConnected = _onPeerConnected
  ipfs.setMaxListeners(MAX_IPFS_CONNECTIONS)

  orbit_global.keystore.registerSignVerify(GLOBAL_KEYS, undefined, verifyRegistrySignature, message => {
    handleGlobalRegistryWrite(orbit_global, message.payload)
  })

  const global_registry = await orbit_global.kvstore(GLOBAL_KEYS, { write: ['*'] })
  rebroadcastOnReplicate(orbit_global, global_registry)

  orbit_global.keystore.registerSignVerify(CONV_INIT_PREFIX, undefined, verifyConversationSignature(global_registry),
    message => {
      const eth_address = message.id.substr(-42) //hopefully the last 42 is the eth address
      onConverse(orbit_global, eth_address, message.payload)
    })
github redacademy / vue-ethereum-ipfs / src / OrbitDBPlugin.js View on Github external
ipfs.on('ready', async () => {
          // Create a database
          const orbitdb = new OrbitDB(ipfs)

          const db = await orbitdb.docstore('obligatron.test')
          resolve(db)
        })
      })
github orbitdb / orbit-db-cli / src / lib / create-database.js View on Github external
const createDatabase = async (database, type, argv) => {
  // TODO: add database path config: { repo: path.join('./.orbitdb') }
  const ipfs = await startIpfs(config.ipfsConfig)
  const peerId = await ipfs.config.get('Identity.PeerID')
  // We need to pass the IPFS ID since we're not starting IPFS
  const directory = process.env.ORBITDB_PATH || config.defaultDatabaseDir
  const orbitdb = await OrbitDB.createInstance(ipfs, {
      directory: directory,
      peerId: peerId })
  const db = await orbitdb.create(database, type, {
    indexBy: argv.indexBy,
    replicate: false,
    key: argv.key,
  })
  await db.saveSnapshot()
  return db
}
github christroutner / orbit-tests / db-replication / master-node / master-node.js View on Github external
ipfs.on("ready", async () => {
  let db;

  try {
    const orbitdb = await OrbitDB.createInstance(ipfs, {
      directory: "./orbitdb/examples/eventlog"
    });

    const options = {
      accessController: {
        write: ["*"]
      }
    }

    db = await orbitdb.eventlog(DB_NAME, options);
    await db.load();

    console.log(`db id: ${db.id}`);
  } catch (e) {
    console.error(e);
    process.exit(1);
github orbitdb / orbit-core / src / Orbit.js View on Github external
}

    const profile = {
      name: defaultIdentityProvider ? credentials : credentials.username,
      location: 'Earth',
      image: null
    }

    const identityKeysPath = path.join('./orbitdb', this._options.directory || '', 'keystore') || credentials.keystorePath
    const newCredentials = Object.assign({}, credentials, { identityKeysPath })

    const identity = await Identities.createIdentity(newCredentials)

    this._user = new OrbitUser(identity, profile)

    this._orbitdb = await OrbitDB.createInstance(
      this._ipfs,
      Object.assign(
        {},
        this._options.dbOptions,
        {
          directory: this._options.directory,
          identity: this.user.identity
        }
      )
    )

    this._startPollingForPeers()

    logger.info(`Connected to Orbit as "${this.user.profile.name}"`)

    this.events.emit('connected', this.user)

orbit-db

Distributed p2p database on IPFS

MIT
Latest version published 1 year ago

Package Health Score

56 / 100
Full package analysis