From 2b1cc9cee283fea49850dfb03774f0b61c0baa23 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 15 Dec 2015 06:40:44 +0000 Subject: [PATCH 1/2] add keys to the readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 70119a26..976985f3 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,14 @@ repo.config.write({foo: 'bar'}, function (err) { }) ``` +### keys + +Read/Write keys inside the repo. This feature will be expanded once [IPRS](https://github.com/ipfs/specs/tree/master/records) and [KeyChain](https://github.com/ipfs/specs/tree/master/keychain) are finalized and implemented on go-ipfs. + +```js +repo.keys.get(function (err, privKey) {}) +``` + ### datastore Store data on the block store. From d8d9f412b5222052197e5b39caf80b231f9739d4 Mon Sep 17 00:00:00 2001 From: David Dias Date: Tue, 15 Dec 2015 06:49:25 +0000 Subject: [PATCH 2/2] feature done + tests --- README.md | 2 +- src/index.js | 7 +++---- src/stores/index.js | 6 +++--- src/stores/keys.js | 14 ++++++++++++++ tests/repo-test.js | 13 ++++++++++++- 5 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 src/stores/keys.js diff --git a/README.md b/README.md index 976985f3..2093daeb 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ js-ipfs-repo > Implementation of the IPFS repo spec (https://github.com/ipfs/specs/tree/master/repo) in JavaScript -[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) [![Build Status](https://travis-ci.org/ipfs/js-ipfs-repo.svg)](https://travis-ci.org/ipfs/js-ipfs-repo) ![](https://img.shields.io/badge/coverage-53%25-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/diasdavid/js-peer-id.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-repo) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) +[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) [![Build Status](https://travis-ci.org/ipfs/js-ipfs-repo.svg)](https://travis-ci.org/ipfs/js-ipfs-repo) ![](https://img.shields.io/badge/coverage-86%25-yellow.svg?style=flat-square) [![Dependency Status](https://david-dm.org/diasdavid/js-peer-id.svg?style=flat-square)](https://david-dm.org/ipfs/js-ipfs-repo) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) ## Description diff --git a/src/index.js b/src/index.js index f9965f1c..c9b52115 100644 --- a/src/index.js +++ b/src/index.js @@ -56,10 +56,9 @@ function Repo (repoPath, options) { .config .setUp(repoPath, options.stores.config, self.locks) - // TODO - // self.keys = stores - // .keys - // .setUp(repoPath, options.stores.keys, self.locks) + self.keys = stores + .keys + .setUp(repoPath, options.stores.keys, self.locks, self.config) // TODO // self.datastore = stores diff --git a/src/stores/index.js b/src/stores/index.js index c56ed689..84b70d52 100644 --- a/src/stores/index.js +++ b/src/stores/index.js @@ -3,8 +3,8 @@ exports = module.exports exports.locks = require('./locks') exports.version = require('./version') exports.config = require('./config') -// exports.blocks = require('./blocks') +exports.keys = require('./keys') +// exports.datastore = require('./datastore') +// exports.datastoreLegacy = require('./datastore-legacy') // exports.logs = require('./logs') -// exports.api = require('./api') -// exports.repo = require('./repo') diff --git a/src/stores/keys.js b/src/stores/keys.js new file mode 100644 index 00000000..52a6c84d --- /dev/null +++ b/src/stores/keys.js @@ -0,0 +1,14 @@ +exports = module.exports + +exports.setUp = function (basePath, blobStore, locks, config) { + return { + get: function (callback) { + config.get(function (err, config) { + if (err) { + return callback(err) + } + callback(null, config.Identity.PrivKey) + }) + } + } +} diff --git a/tests/repo-test.js b/tests/repo-test.js index 7dbe34f1..573ea105 100644 --- a/tests/repo-test.js +++ b/tests/repo-test.js @@ -85,6 +85,16 @@ describe('IPFS Repo Tests', function () { }) }) + describe('keys', function () { + it('get PrivKey', function (done) { + repo.keys.get(function (err, privKey) { + expect(err).to.equal(null) + expect(privKey).to.be.a('string') + done() + }) + }) + }) + describe('config', function () { it('get config', function (done) { repo.config.get(function (err, config) { @@ -127,5 +137,6 @@ describe('IPFS Repo Tests', function () { }) }) }) - describe('blocks', function () {}) + describe('datastore', function () {}) + describe('datastore-legacy', function () {}) })