mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Merge pull request #625 from orbitdb/fix/legacy-controller
pass format in dbManifest creation
This commit is contained in:
commit
e16794cf22
636
package-lock.json
generated
636
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "orbit-db",
|
"name": "orbit-db",
|
||||||
"version": "0.20.1",
|
"version": "0.21.0-rc.1",
|
||||||
"description": "Distributed p2p database on IPFS",
|
"description": "Distributed p2p database on IPFS",
|
||||||
"author": "Haad",
|
"author": "Haad",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -18,15 +18,15 @@
|
|||||||
"localstorage-down": "^0.6.7",
|
"localstorage-down": "^0.6.7",
|
||||||
"logplease": "^1.2.14",
|
"logplease": "^1.2.14",
|
||||||
"multihashes": "^0.4.12",
|
"multihashes": "^0.4.12",
|
||||||
"orbit-db-access-controllers": "~0.1.0",
|
"orbit-db-access-controllers": "next",
|
||||||
"orbit-db-cache": "~0.2.4",
|
"orbit-db-cache": "~0.2.4",
|
||||||
"orbit-db-counterstore": "~1.5.0",
|
"orbit-db-counterstore": "~1.5.0",
|
||||||
"orbit-db-docstore": "~1.5.0",
|
"orbit-db-docstore": "~1.5.0",
|
||||||
"orbit-db-eventstore": "~1.5.0",
|
"orbit-db-eventstore": "~1.5.0",
|
||||||
"orbit-db-feedstore": "~1.5.0",
|
"orbit-db-feedstore": "~1.5.0",
|
||||||
"orbit-db-identity-provider": "~0.1.0",
|
"orbit-db-identity-provider": "~0.1.0",
|
||||||
"orbit-db-io": "~0.0.1",
|
"orbit-db-io": "next",
|
||||||
"orbit-db-keystore": "~0.2.0",
|
"orbit-db-keystore": "^0.2.1",
|
||||||
"orbit-db-kvstore": "~1.5.0",
|
"orbit-db-kvstore": "~1.5.0",
|
||||||
"orbit-db-pubsub": "~0.5.5",
|
"orbit-db-pubsub": "~0.5.5",
|
||||||
"orbit-db-store": "~2.6.0"
|
"orbit-db-store": "~2.6.0"
|
||||||
|
@ -239,7 +239,7 @@ let databaseTypes = {
|
|||||||
delete this.stores[address]
|
delete this.stores[address]
|
||||||
}
|
}
|
||||||
|
|
||||||
async _determineAddress(name, type, options = {}, onlyHash) {
|
async _determineAddress(name, type, options = {}) {
|
||||||
if (!OrbitDB.isValidType(type))
|
if (!OrbitDB.isValidType(type))
|
||||||
throw new Error(`Invalid database type '${type}'`)
|
throw new Error(`Invalid database type '${type}'`)
|
||||||
|
|
||||||
@ -248,10 +248,10 @@ let databaseTypes = {
|
|||||||
|
|
||||||
// Create an AccessController, use IPFS AC as the default
|
// Create an AccessController, use IPFS AC as the default
|
||||||
options.accessController = Object.assign({}, { name: name , type: 'ipfs' }, options.accessController)
|
options.accessController = Object.assign({}, { name: name , type: 'ipfs' }, options.accessController)
|
||||||
const accessControllerAddress = await AccessControllers.create(this, options.accessController.type, options.accessController || {})
|
const accessControllerAddress = await AccessControllers.create(this, options.accessController.type, options.accessController || {})
|
||||||
|
|
||||||
// Save the manifest to IPFS
|
// Save the manifest to IPFS
|
||||||
const manifestHash = await createDBManifest(this._ipfs, name, type, accessControllerAddress, onlyHash)
|
const manifestHash = await createDBManifest(this._ipfs, name, type, accessControllerAddress, options)
|
||||||
|
|
||||||
// Create the database address
|
// Create the database address
|
||||||
return OrbitDBAddress.parse(path.join('/orbitdb', manifestHash, name))
|
return OrbitDBAddress.parse(path.join('/orbitdb', manifestHash, name))
|
||||||
@ -295,7 +295,8 @@ let databaseTypes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async determineAddress(name, type, options = {}) {
|
async determineAddress(name, type, options = {}) {
|
||||||
return this._determineAddress(name, type, options, true)
|
const opts = Object.assign({}, { onlyHash: true }, options)
|
||||||
|
return this._determineAddress(name, type, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2,14 +2,14 @@ const path = require('path')
|
|||||||
const io = require('orbit-db-io')
|
const io = require('orbit-db-io')
|
||||||
|
|
||||||
// Creates a DB manifest file and saves it in IPFS
|
// Creates a DB manifest file and saves it in IPFS
|
||||||
const createDBManifest = async (ipfs, name, type, accessControllerAddress, onlyHash) => {
|
const createDBManifest = async (ipfs, name, type, accessControllerAddress, options) => {
|
||||||
const manifest = {
|
const manifest = {
|
||||||
name: name,
|
name: name,
|
||||||
type: type,
|
type: type,
|
||||||
accessController: path.join('/ipfs', accessControllerAddress),
|
accessController: path.join('/ipfs', accessControllerAddress),
|
||||||
}
|
}
|
||||||
|
|
||||||
return io.write(ipfs, 'dag-cbor', manifest, { onlyHash })
|
return io.write(ipfs, options.format || 'dag-cbor', manifest, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = createDBManifest
|
module.exports = createDBManifest
|
||||||
|
@ -102,8 +102,8 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
accessController: {
|
accessController: {
|
||||||
// Set write access for both clients
|
// Set write access for both clients
|
||||||
write: [
|
write: [
|
||||||
orbitdb1.identity.publicKey,
|
orbitdb1.identity.id,
|
||||||
orbitdb2.identity.publicKey
|
orbitdb2.identity.id
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,21 +165,21 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
|
|
||||||
it('creates an access controller and adds ourselves as writer by default', async () => {
|
it('creates an access controller and adds ourselves as writer by default', async () => {
|
||||||
db = await orbitdb.create('fourth', 'feed')
|
db = await orbitdb.create('fourth', 'feed')
|
||||||
assert.deepEqual(db.access.write, [orbitdb.identity.publicKey])
|
assert.deepEqual(db.access.write, [orbitdb.identity.id])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('creates an access controller and adds writers', async () => {
|
it('creates an access controller and adds writers', async () => {
|
||||||
db = await orbitdb.create('fourth', 'feed', {
|
db = await orbitdb.create('fourth', 'feed', {
|
||||||
accessController: {
|
accessController: {
|
||||||
write: ['another-key', 'yet-another-key', orbitdb.identity.publicKey]
|
write: ['another-key', 'yet-another-key', orbitdb.identity.id]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
assert.deepEqual(db.access.write, ['another-key', 'yet-another-key', orbitdb.identity.publicKey])
|
assert.deepEqual(db.access.write, ['another-key', 'yet-another-key', orbitdb.identity.id])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('creates an access controller and doesn\'t add read access keys', async () => {
|
it('creates an access controller and doesn\'t add read access keys', async () => {
|
||||||
db = await orbitdb.create('seventh', 'feed', { read: ['one', 'two'] })
|
db = await orbitdb.create('seventh', 'feed', { read: ['one', 'two'] })
|
||||||
assert.deepEqual(db.access.write, [orbitdb.identity.publicKey])
|
assert.deepEqual(db.access.write, [orbitdb.identity.id])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -278,7 +278,7 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
it('opens a database and adds the creator as the only writer', async () => {
|
it('opens a database and adds the creator as the only writer', async () => {
|
||||||
db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true })
|
db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true })
|
||||||
assert.equal(db.access.write.length, 1)
|
assert.equal(db.access.write.length, 1)
|
||||||
assert.equal(db.access.write[0], db.identity.publicKey)
|
assert.equal(db.access.write[0], db.identity.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('doesn\'t open a database if we don\'t have it locally', async () => {
|
it('doesn\'t open a database if we don\'t have it locally', async () => {
|
||||||
|
@ -4,6 +4,7 @@ const assert = require('assert')
|
|||||||
const rmrf = require('rimraf')
|
const rmrf = require('rimraf')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const OrbitDB = require('../src/OrbitDB')
|
const OrbitDB = require('../src/OrbitDB')
|
||||||
|
const Identities = require('orbit-db-identity-provider')
|
||||||
// Include test utilities
|
// Include test utilities
|
||||||
const {
|
const {
|
||||||
config,
|
config,
|
||||||
@ -14,12 +15,14 @@ const {
|
|||||||
databases,
|
databases,
|
||||||
} = require('./utils')
|
} = require('./utils')
|
||||||
|
|
||||||
|
Identities.addIdentityProvider(CustomTestKeystore().identityProvider)
|
||||||
|
|
||||||
const dbPath = './orbitdb/tests/customKeystore'
|
const dbPath = './orbitdb/tests/customKeystore'
|
||||||
const ipfsPath = './orbitdb/tests/customKeystore/ipfs'
|
const ipfsPath = './orbitdb/tests/customKeystore/ipfs'
|
||||||
|
|
||||||
Object.keys(testAPIs).forEach(API => {
|
Object.keys(testAPIs).forEach(API => {
|
||||||
describe(`orbit-db - Use a Custom Keystore (${API})`, function() {
|
describe(`orbit-db - Use a Custom Keystore (${API})`, function() {
|
||||||
this.timeout(20000)
|
this.timeout(config.timeout)
|
||||||
|
|
||||||
let ipfsd, ipfs, orbitdb1
|
let ipfsd, ipfs, orbitdb1
|
||||||
|
|
||||||
@ -29,9 +32,11 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
rmrf.sync(dbPath)
|
rmrf.sync(dbPath)
|
||||||
ipfsd = await startIpfs(API, config.daemon1)
|
ipfsd = await startIpfs(API, config.daemon1)
|
||||||
ipfs = ipfsd.api
|
ipfs = ipfsd.api
|
||||||
|
const identity = await Identities.createIdentity({ type:'custom'})
|
||||||
orbitdb1 = await OrbitDB.createInstance(ipfs, {
|
orbitdb1 = await OrbitDB.createInstance(ipfs, {
|
||||||
directory: path.join(dbPath, '1'),
|
directory: path.join(dbPath, '1'),
|
||||||
keystore: CustomTestKeystore().create()
|
keystore: CustomTestKeystore().create(),
|
||||||
|
identity
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -62,7 +67,7 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
const options = {
|
const options = {
|
||||||
accessController: {
|
accessController: {
|
||||||
// Set write access for both clients
|
// Set write access for both clients
|
||||||
write: [orbitdb1.identity.publicKey],
|
write: [orbitdb1.identity.id],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,8 +131,8 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
let options = {
|
let options = {
|
||||||
accessController: {
|
accessController: {
|
||||||
write: [
|
write: [
|
||||||
orbitdb1.identity.publicKey,
|
orbitdb1.identity.id,
|
||||||
orbitdb2.identity.publicKey
|
orbitdb2.identity.id
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,8 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
// Set write access for both clients
|
// Set write access for both clients
|
||||||
accessController: {
|
accessController: {
|
||||||
write: [
|
write: [
|
||||||
orbitdb1.identity.publicKey,
|
orbitdb1.identity.id,
|
||||||
orbitdb2.identity.publicKey
|
orbitdb2.identity.id
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const EC = require('elliptic').ec
|
const EC = require('elliptic').ec
|
||||||
const ec = new EC('secp256k1')
|
const ec = new EC('secp256k1')
|
||||||
|
const IdentityProvider = require('orbit-db-identity-provider/src/identity-provider-interface')
|
||||||
/**
|
/**
|
||||||
* A custom keystore example
|
* A custom keystore example
|
||||||
*/
|
*/
|
||||||
@ -46,10 +46,35 @@ class CustomTestKeystore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CustomIdProvider extends IdentityProvider {
|
||||||
|
constructor (options = {}) {
|
||||||
|
super()
|
||||||
|
this._keystore = options.keystore || new CustomTestKeystore()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the type of the identity provider
|
||||||
|
static get type () { return 'custom' }
|
||||||
|
|
||||||
|
async getId (options = {}) {
|
||||||
|
return 'id'
|
||||||
|
}
|
||||||
|
|
||||||
|
async signIdentity (data, options = {}) {
|
||||||
|
const keystore = this._keystore
|
||||||
|
return keystore.sign(null, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
static async verifyIdentity (identity) {
|
||||||
|
// Verify that identity was signed by the ID
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = (LocalStorage, mkdir) => {
|
module.exports = (LocalStorage, mkdir) => {
|
||||||
return {
|
return {
|
||||||
create: (directory) => {
|
create: (directory) => {
|
||||||
return new CustomTestKeystore()
|
return new CustomTestKeystore()
|
||||||
}
|
},
|
||||||
|
identityProvider: CustomIdProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
|
|
||||||
it('database has the correct access-controller', async () => {
|
it('database has the correct access-controller', async () => {
|
||||||
assert.equal(db.options.accessControllerAddress, '/ipfs/Qmc3S7aMSmH8oGmx7Zdp8UxVWcDyCq5o2H9qYFgT3GW6nM')
|
assert.equal(db.options.accessControllerAddress, '/ipfs/Qmc3S7aMSmH8oGmx7Zdp8UxVWcDyCq5o2H9qYFgT3GW6nM')
|
||||||
assert.equal(db.access.type, 'ipfs')
|
assert.equal(db.access.type, 'legacy-ipfs')
|
||||||
assert.strictEqual(db.access.write[0], '04b54f6ef529cd2dd2f9c6897a382c492222d42e57826269a38101ffe752aa07260ecd092a970d7eef08c4ddae2b7006ee25f07e4ab62fa5262ae3b51fdea29f78')
|
assert.strictEqual(db.access.write[0], '04b54f6ef529cd2dd2f9c6897a382c492222d42e57826269a38101ffe752aa07260ecd092a970d7eef08c4ddae2b7006ee25f07e4ab62fa5262ae3b51fdea29f78')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
// Set write access for both clients
|
// Set write access for both clients
|
||||||
accessController: {
|
accessController: {
|
||||||
write: [
|
write: [
|
||||||
orbitdb1.identity.publicKey,
|
orbitdb1.identity.id,
|
||||||
orbitdb2.identity.publicKey
|
orbitdb2.identity.id
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,8 +80,8 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
// Set write access for both clients
|
// Set write access for both clients
|
||||||
accessController: {
|
accessController: {
|
||||||
write: [
|
write: [
|
||||||
orbitdb1.identity.publicKey,
|
orbitdb1.identity.id,
|
||||||
orbitdb2.identity.publicKey
|
orbitdb2.identity.id
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
let options = {
|
let options = {
|
||||||
// Only peer 1 can write
|
// Only peer 1 can write
|
||||||
accessController: {
|
accessController: {
|
||||||
write: [orbitdb1.identity.publicKey]
|
write: [orbitdb1.identity.id]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let err
|
let err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user