@@ -12,7 +12,7 @@ const Keystore = require('orbit-db-keystore')
1212const IdentityProvider = require ( 'orbit-db-identity-provider' )
1313const IPFSAccessController = require ( './ipfs-access-controller' )
1414const OrbitDBAddress = require ( './orbit-db-address' )
15- const createDBManifest = require ( './db-manifest' )
15+ const { createDBManifest, uploadDBManifest , signDBManifest , verifyDBManifest } = require ( './db-manifest' )
1616const exchangeHeads = require ( './exchange-heads' )
1717const isDefined = require ( './utils/is-defined' )
1818const Logger = require ( 'logplease' )
@@ -268,12 +268,14 @@ class OrbitDB {
268268 const accessControllerAddress = await accessController . save ( )
269269
270270 // Save the manifest to IPFS
271- const manifestHash = await createDBManifest ( this . _ipfs , name , type , accessControllerAddress )
271+ const manifest = createDBManifest ( name , type , accessControllerAddress , this . identity )
272+ const manifestHash = await uploadDBManifest ( this . _ipfs , manifest )
272273
273274 // Create the database address
274- const dbAddress = OrbitDBAddress . parse ( path . join ( '/orbitdb' , manifestHash , name ) )
275+ const manifestSignature = await signDBManifest ( manifest , this . identity , this . identity . provider )
276+ const dbAddress = OrbitDBAddress . parse ( path . join ( '/orbitdb' , manifestHash , name , manifestSignature ) )
275277
276- // // Load local cache
278+ // Load local cache
277279 const haveDB = await this . _loadCache ( directory , dbAddress )
278280 . then ( cache => cache ? cache . get ( path . join ( dbAddress . toString ( ) , '_manifest' ) ) : null )
279281 . then ( data => data !== undefined && data !== null )
@@ -346,6 +348,11 @@ class OrbitDB {
346348 const manifest = JSON . parse ( dag . toJSON ( ) . data )
347349 logger . debug ( `Manifest for '${ dbAddress } ':\n${ JSON . stringify ( manifest , null , 2 ) } ` )
348350
351+ const isValid = await verifyDBManifest ( manifest , dbAddress . signature , this . identity . provider )
352+ if ( ! isValid ) {
353+ throw new Error ( `Could not verify ${ dbAddress } ` )
354+ }
355+
349356 // Make sure the type from the manifest matches the type that was given as an option
350357 if ( options . type && manifest . type !== options . type )
351358 throw new Error ( `Database '${ dbAddress } ' is type '${ manifest . type } ' but was opened as '${ options . type } '` )
0 commit comments