Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const IPFS = require('ipfs')
  2. const OrbitDB = require('orbit-db')
  3. const AccessController = require('orbit-db-access-controllers/src/access-controller-interface')
  4. let AccessControllers = require('orbit-db-access-controllers')
  5.  
  6. class OtherAccessController extends AccessController {
  7.  
  8.   static get type () { return 'othertype' } // Return the type for this controller
  9.  
  10.   async canAppend(entry, identityProvider) {
  11.     // logic to determine if entry can be added, for example:
  12.       return true
  13.     }
  14.  
  15.   async grant (access, identity) {} // Logic for granting access to identity
  16. }
  17.  
  18. AccessControllers.addAccessController({ AccessController: OtherAccessController })
  19.  
  20. // Create IPFS instance
  21. const ipfs1 = new IPFS({ repo: './ipfs1', EXPERIMENTAL: { pubsub: true } })
  22. ipfs1.on('ready', async () => {
  23.   const orbitdb1 = await OrbitDB.createInstance(ipfs1, { directory: './orbitdb1', AccessControllers: AccessControllers })
  24.  
  25.  
  26.   const options = {
  27.     accessController: {
  28.       type: 'othertype',
  29.       write: [orbitdb1.identity.id]
  30.     }
  31.   }
  32.  
  33.   const db1 = await orbitdb1.keyvalue('first-database',options)
  34.   console.log(db1.address.toString())
  35.   await db1.put('name', 'test')
  36.  
  37. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement