pass format in dbManifest creation

use identity.id as default ac check
This commit is contained in:
shamb0t 2019-05-14 08:59:18 +01:00
parent 48e6d4f102
commit 8c694f5170
12 changed files with 449 additions and 250 deletions

604
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -18,15 +18,15 @@
"localstorage-down": "^0.6.7",
"logplease": "^1.2.14",
"multihashes": "^0.4.12",
"orbit-db-access-controllers": "~0.1.0",
"orbit-db-access-controllers": "github:orbitdb/orbit-db-access-controllers#fix/add-legacy-controller",
"orbit-db-cache": "~0.2.4",
"orbit-db-counterstore": "~1.5.0",
"orbit-db-docstore": "~1.5.0",
"orbit-db-eventstore": "~1.5.0",
"orbit-db-feedstore": "~1.5.0",
"orbit-db-identity-provider": "~0.1.0",
"orbit-db-io": "~0.0.1",
"orbit-db-keystore": "~0.2.0",
"orbit-db-io": "github:orbitdb/orbit-db-io#feat/pass-format",
"orbit-db-keystore": "^0.2.1",
"orbit-db-kvstore": "~1.5.0",
"orbit-db-pubsub": "~0.5.5",
"orbit-db-store": "~2.6.0"

View File

@ -239,7 +239,7 @@ let databaseTypes = {
delete this.stores[address]
}
async _determineAddress(name, type, options = {}, onlyHash) {
async _determineAddress(name, type, options = {}) {
if (!OrbitDB.isValidType(type))
throw new Error(`Invalid database type '${type}'`)
@ -248,10 +248,10 @@ let databaseTypes = {
// Create an AccessController, use IPFS AC as the default
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
const manifestHash = await createDBManifest(this._ipfs, name, type, accessControllerAddress, onlyHash)
const manifestHash = await createDBManifest(this._ipfs, name, type, accessControllerAddress, options)
// Create the database address
return OrbitDBAddress.parse(path.join('/orbitdb', manifestHash, name))
@ -295,7 +295,8 @@ let databaseTypes = {
}
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)
}
/*

View File

@ -2,14 +2,14 @@ const path = require('path')
const io = require('orbit-db-io')
// 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 = {
name: name,
type: type,
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

View File

@ -102,8 +102,8 @@ Object.keys(testAPIs).forEach(API => {
accessController: {
// Set write access for both clients
write: [
orbitdb1.identity.publicKey,
orbitdb2.identity.publicKey
orbitdb1.identity.id,
orbitdb2.identity.id
],
}
}

View File

@ -165,21 +165,21 @@ Object.keys(testAPIs).forEach(API => {
it('creates an access controller and adds ourselves as writer by default', async () => {
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 () => {
db = await orbitdb.create('fourth', 'feed', {
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 () => {
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 () => {
db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true })
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 () => {

View File

@ -4,6 +4,7 @@ const assert = require('assert')
const rmrf = require('rimraf')
const path = require('path')
const OrbitDB = require('../src/OrbitDB')
const Identities = require('orbit-db-identity-provider')
// Include test utilities
const {
config,
@ -14,12 +15,14 @@ const {
databases,
} = require('./utils')
Identities.addIdentityProvider(CustomTestKeystore().identityProvider)
const dbPath = './orbitdb/tests/customKeystore'
const ipfsPath = './orbitdb/tests/customKeystore/ipfs'
Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - Use a Custom Keystore (${API})`, function() {
this.timeout(20000)
this.timeout(config.timeout)
let ipfsd, ipfs, orbitdb1
@ -29,9 +32,11 @@ Object.keys(testAPIs).forEach(API => {
rmrf.sync(dbPath)
ipfsd = await startIpfs(API, config.daemon1)
ipfs = ipfsd.api
const identity = await Identities.createIdentity({ type:'custom'})
orbitdb1 = await OrbitDB.createInstance(ipfs, {
directory: path.join(dbPath, '1'),
keystore: CustomTestKeystore().create()
keystore: CustomTestKeystore().create(),
identity
})
})
@ -62,7 +67,7 @@ Object.keys(testAPIs).forEach(API => {
const options = {
accessController: {
// Set write access for both clients
write: [orbitdb1.identity.publicKey],
write: [orbitdb1.identity.id],
}
}

View File

@ -131,8 +131,8 @@ Object.keys(testAPIs).forEach(API => {
let options = {
accessController: {
write: [
orbitdb1.identity.publicKey,
orbitdb2.identity.publicKey
orbitdb1.identity.id,
orbitdb2.identity.id
],
}
}

View File

@ -70,8 +70,8 @@ Object.keys(testAPIs).forEach(API => {
// Set write access for both clients
accessController: {
write: [
orbitdb1.identity.publicKey,
orbitdb2.identity.publicKey
orbitdb1.identity.id,
orbitdb2.identity.id
],
}
}

View File

@ -1,6 +1,6 @@
const EC = require('elliptic').ec
const ec = new EC('secp256k1')
const IdentityProvider = require('orbit-db-identity-provider/src/identity-provider-interface')
/**
* A custom keystore example
*/
@ -40,16 +40,41 @@ class CustomTestKeystore {
verify (signature, publicKey, data) {
return Promise.resolve(true)
}
getPublic (key) {
return key.public.marshal()
}
}
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) => {
return {
create: (directory) => {
return new CustomTestKeystore()
}
},
identityProvider: CustomIdProvider
}
}

View File

@ -85,7 +85,7 @@ Object.keys(testAPIs).forEach(API => {
it('database has the correct access-controller', async () => {
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')
})

View File

@ -51,8 +51,8 @@ Object.keys(testAPIs).forEach(API => {
// Set write access for both clients
accessController: {
write: [
orbitdb1.identity.publicKey,
orbitdb2.identity.publicKey
orbitdb1.identity.id,
orbitdb2.identity.id
],
}
}
@ -80,8 +80,8 @@ Object.keys(testAPIs).forEach(API => {
// Set write access for both clients
accessController: {
write: [
orbitdb1.identity.publicKey,
orbitdb2.identity.publicKey
orbitdb1.identity.id,
orbitdb2.identity.id
]
}
}
@ -147,7 +147,7 @@ Object.keys(testAPIs).forEach(API => {
let options = {
// Only peer 1 can write
accessController: {
write: [orbitdb1.identity.publicKey]
write: [orbitdb1.identity.id]
}
}
let err