Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keystore #155

Merged
merged 3 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ This now has created the following structure, either on disk or as an in memory
│ └── _README
├── config
├── datastore
├── keys
└── version
```

Expand All @@ -145,6 +146,7 @@ Arguments:
* `storageBackends` (object, optional): may contain the following values, which should each be a class implementing the [datastore interface](https://github.com/ipfs/interface-datastore#readme):
* `root` (defaults to [`datastore-fs`](https://github.com/ipfs/js-datastore-fs#readme) in Node.js and [`datastore-level`](https://github.com/ipfs/js-datastore-level#readme) in the browser). Defines the back-end type used for gets and puts of values at the root (`repo.set()`, `repo.get()`)
* `blocks` (defaults to [`datastore-fs`](https://github.com/ipfs/js-datastore-fs#readme) in Node.js and [`datastore-level`](https://github.com/ipfs/js-datastore-level#readme) in the browser). Defines the back-end type used for gets and puts of values at `repo.blocks`.
* `keys` (defaults to [`datastore-fs`](https://github.com/ipfs/js-datastore-fs#readme) in Node.js and [`datastore-level`](https://github.com/ipfs/js-datastore-level#readme) in the browser). Defines the back-end type used for gets and puts of encrypted keys at `repo.keys`
* `datastore` (defaults to [`datastore-level`](https://github.com/ipfs/js-datastore-level#readme)). Defines the back-end type used as the key-valye store used for gets and puts of values at `repo.datastore`.

```js
Expand Down
5 changes: 5 additions & 0 deletions src/default-options-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
storageBackends: {
root: require('datastore-level'),
blocks: require('datastore-level'),
keys: require('datastore-level'),
datastore: require('datastore-level')
},
storageBackendOptions: {
Expand All @@ -17,6 +18,10 @@ module.exports = {
sharding: false,
db: require('level-js')
},
keys: {
sharding: false,
db: require('level-js')
},
datastore: {
db: require('level-js')
}
Expand Down
3 changes: 3 additions & 0 deletions src/default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
storageBackends: {
root: require('datastore-fs'),
blocks: require('datastore-fs'),
keys: require('datastore-fs'),
datastore: require('datastore-level')
},
storageBackendOptions: {
Expand All @@ -15,6 +16,8 @@ module.exports = {
blocks: {
sharding: true,
extension: '.data'
},
keys: {
}
}
}
15 changes: 14 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ class IpfsRepo {
this.blocks = blocks
cb()
},
(cb) => {
log('creating keystore')
const keysBaseStore = backends.create('keys', path.join(this.path, 'keys'), this.options)
blockstore(
keysBaseStore,
this.options.storageBackendOptions.keys,
cb)
},
(keys, cb) => {
this.keys = keys
cb()
},

(cb) => {
this.closed = false
log('all opened')
Expand Down Expand Up @@ -169,7 +182,7 @@ class IpfsRepo {
(cb) => this.apiAddr.delete(ignoringNotFound(cb)),
(cb) => {
each(
[this.blocks, this.datastore],
[this.blocks, this.keys, this.datastore],
(store, callback) => store.close(callback),
cb)
},
Expand Down
1 change: 1 addition & 0 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ describe('IPFS Repo Tests on the Browser', () => {
require('./repo-test')(repo)
require('./blockstore-test')(repo)
require('./datastore-test')(repo)
require('./keystore-test')(repo)
})
15 changes: 15 additions & 0 deletions test/keystore-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */
'use strict'

const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect

module.exports = (repo) => {
describe('keystore', () => {
it('exists', () => {
expect(repo).to.have.property('keys')
})
})
}
1 change: 1 addition & 0 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('IPFS Repo Tests onNode.js', () => {
require('./repo-test')(repo)
require('./blockstore-test')(repo)
require('./datastore-test')(repo)
require('./keystore-test')(repo)
if (!r.init) {
require('./interop-test')(repo)
}
Expand Down
4 changes: 4 additions & 0 deletions test/options-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ function expectedRepoOptions () {
// equivalents via package.browser
root: require('datastore-fs'),
blocks: require('datastore-fs'),
keys: require('datastore-fs'),
datastore: require('datastore-level')
},
storageBackendOptions: {
root: {
extension: ''
},
keys: {},
blocks: {
sharding: true,
extension: '.data'
Expand All @@ -55,6 +57,8 @@ function expectedRepoOptions () {

if (process.browser) {
options.storageBackendOptions.root.db = require('leveldown')
options.storageBackendOptions.keys.db = require('leveldown')
options.storageBackendOptions.keys.sharding = false
options.storageBackendOptions.blocks.db = require('leveldown')
delete options.storageBackendOptions.blocks.extension
options.storageBackendOptions.blocks.sharding = false
Expand Down