mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-02 12:16:37 +00:00
Use latest ipfs-log
This commit is contained in:
parent
5e3d0c5e81
commit
2f743772b7
@ -9,6 +9,7 @@ const DocumentStore = require('orbit-db-docstore')
|
||||
const Pubsub = require('orbit-db-pubsub')
|
||||
const Cache = require('orbit-db-cache')
|
||||
const Keystore = require('orbit-db-keystore')
|
||||
const IdentityProvider = require('orbit-db-identity-provider')
|
||||
const AccessController = require('./ipfs-access-controller')
|
||||
const OrbitDBAddress = require('./orbit-db-address')
|
||||
const createDBManifest = require('./db-manifest')
|
||||
@ -37,10 +38,14 @@ class OrbitDB {
|
||||
this.stores = {}
|
||||
this.directory = directory || './orbitdb'
|
||||
this.keystore = options.keystore || Keystore.create(path.join(this.directory, this.id, '/keystore'))
|
||||
this.key = this.keystore.getKey(this.id) || this.keystore.createKey(this.id)
|
||||
this.identity = options.identity
|
||||
this._directConnections = {}
|
||||
}
|
||||
|
||||
async initialize(options = {}) {
|
||||
this.identity = await IdentityProvider.createIdentity(this.keystore, this.id, options.identitySignerFn)
|
||||
}
|
||||
|
||||
/* Databases */
|
||||
async feed (address, options = {}) {
|
||||
options = Object.assign({ create: true, type: 'feed' }, options)
|
||||
@ -112,8 +117,11 @@ class OrbitDB {
|
||||
|
||||
/* Private methods */
|
||||
async _createStore (type, address, options) {
|
||||
if (!this.identity)
|
||||
await this.initialize()
|
||||
// Get the type -> class mapping
|
||||
const Store = databaseTypes[type]
|
||||
// this.identity = this.identity || await IdentityProvider.createIdentity(this.keystore, this.id, options.identitySignerFn)
|
||||
|
||||
if (!Store)
|
||||
throw new Error(`Invalid database type '${type}'`)
|
||||
@ -128,12 +136,11 @@ class OrbitDB {
|
||||
|
||||
const opts = Object.assign({ replicate: true }, options, {
|
||||
accessController: accessController,
|
||||
keystore: this.keystore,
|
||||
cache: cache,
|
||||
onClose: this._onClose.bind(this),
|
||||
})
|
||||
|
||||
const store = new Store(this._ipfs, this.id, address, opts)
|
||||
const store = new Store(this._ipfs, this.identity, address, opts)
|
||||
store.events.on('write', this._onWrite.bind(this))
|
||||
|
||||
// ID of the store is the address as a string
|
||||
@ -216,6 +223,9 @@ class OrbitDB {
|
||||
async create (name, type, options = {}) {
|
||||
logger.debug(`create()`)
|
||||
|
||||
if (!this.identity)
|
||||
await this.initialize()
|
||||
|
||||
if (!OrbitDB.isValidType(type))
|
||||
throw new Error(`Invalid database type '${type}'`)
|
||||
|
||||
@ -241,7 +251,7 @@ class OrbitDB {
|
||||
options.write.forEach(e => accessController.add('write', e))
|
||||
} else {
|
||||
// Default is to add ourselves as the admin of the database
|
||||
accessController.add('write', this.key.getPublic('hex'))
|
||||
accessController.add('write', this.identity.publicKey)
|
||||
}
|
||||
// Save the Access Controller in IPFS
|
||||
const accessControllerAddress = await accessController.save()
|
||||
@ -280,6 +290,10 @@ class OrbitDB {
|
||||
*/
|
||||
async open (address, options = {}) {
|
||||
logger.debug(`open()`)
|
||||
|
||||
if (!this.identity)
|
||||
await this.initialize()
|
||||
|
||||
options = Object.assign({ localOnly: false, create: false }, options)
|
||||
logger.debug(`Open database '${address}'`)
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
class AccessController {
|
||||
constructor () {
|
||||
this._access = {
|
||||
admin: [],
|
||||
write: [],
|
||||
this._access = {
|
||||
admin: [],
|
||||
write: [],
|
||||
read: [], // Not used atm
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,17 @@ class AccessController {
|
||||
async load (address) {}
|
||||
async save () {}
|
||||
|
||||
async canAppend(entry, identityProvider){
|
||||
//verify identity?
|
||||
if (this._access.write.includes('*'))
|
||||
return true
|
||||
|
||||
if (this._access.write.includes(entry.identity.publicKey))
|
||||
return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/* Properties */
|
||||
get admin () {
|
||||
return this._access.admin
|
||||
@ -78,7 +89,7 @@ class AccessController {
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user