@@ -28,7 +28,7 @@ let databaseTypes = {
2828 'keyvalue' : KeyValueStore ,
2929}
3030
31- class OrbitDB {
31+ class OrbitDB {
3232 constructor ( ipfs , identity , options = { } ) {
3333 if ( ! isDefined ( ipfs ) )
3434 throw new Error ( 'IPFS is a required argument. See https://github.com/orbitdb/orbit-db/blob/master/API.md#createinstance' )
@@ -137,14 +137,14 @@ let databaseTypes = {
137137 if ( ! Store )
138138 throw new Error ( `Invalid database type '${ type } '` )
139139
140- let accessController
141- if ( options . accessControllerAddress ) {
140+ let accessController = options . accessController
141+ if ( ! accessController ) {
142142 accessController = new IPFSAccessController ( this . _ipfs )
143- await accessController . load ( options . accessControllerAddress )
144143 }
145144
146- const cache = await this . _loadCache ( this . directory , address )
145+ await accessController . setup ( options )
147146
147+ const cache = await this . _loadCache ( this . directory , address )
148148 const opts = Object . assign ( { replicate : true } , options , {
149149 accessController : accessController ,
150150 cache : cache ,
@@ -245,7 +245,7 @@ let databaseTypes = {
245245 throw new Error ( `Given database name is an address. Please give only the name of the database!` )
246246
247247 // Create an IPFSAccessController
248- const accessController = new IPFSAccessController ( this . _ipfs )
248+ const accessController = options . accessController || new IPFSAccessController ( this . _ipfs )
249249 /* Disabled temporarily until we do something with the admin keys */
250250 // Add admins of the database to the access controller
251251 // if (options && options.admin) {
@@ -255,12 +255,15 @@ let databaseTypes = {
255255 // accessController.add('admin', this.key.getPublic('hex'))
256256 // }
257257 // Add keys that can write to the database
258- if ( options && options . write && options . write . length > 0 ) {
259- options . write . forEach ( e => accessController . add ( 'write' , e ) )
260- } else {
261- // Default is to add ourselves as the admin of the database
262- accessController . add ( 'write' , this . identity . publicKey )
258+ if ( ! options . accessController ) {
259+ if ( options && options . write && options . write . length > 0 ) {
260+ await Promise . all ( options . write . map ( e => accessController . add ( 'write' , e ) ) )
261+ } else {
262+ // Default is to add ourselves as the admin of the database
263+ await accessController . add ( 'write' , this . identity . publicKey )
264+ }
263265 }
266+
264267 // Save the Access Controller in IPFS
265268 const accessControllerAddress = await accessController . save ( )
266269
@@ -295,7 +298,7 @@ let databaseTypes = {
295298 overwrite: TODO
296299
297300 }
298- */
301+ */
299302 async open ( address , options = { } ) {
300303 logger . debug ( `open()` )
301304
@@ -406,3 +409,5 @@ let databaseTypes = {
406409}
407410
408411module . exports = OrbitDB
412+ module . exports . IdentityProvider = IdentityProvider
413+ module . exports . IPFSAccessController = IPFSAccessController
0 commit comments