Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ This means:
- [`ipfs.ping()`]()
- [`ipfs.log()`]()

#### [key]()

- [`ipfs.key.gen(name, [options, callback])`]()
- [`ipfs.key.list([options, callback])`]()

##### [name]()

- [`ipfs.name.publish()`]()
Expand Down
29 changes: 29 additions & 0 deletions src/api/key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

const promisify = require('promisify-es6')

module.exports = (send) => {
return {
gen: promisify((args, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send({
path: 'key/gen',
args: args,
qs: opts
}, callback)
}),
list: promisify((opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send({
path: 'key/list',
qs: opts
}, callback)
})
}
}
1 change: 1 addition & 0 deletions src/load-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function requireCommands () {
dht: require('./api/dht'),
diag: require('./api/diag'),
id: require('./api/id'),
key: require('./api/key'),
get: require('./api/get'),
log: require('./api/log'),
ls: require('./api/ls'),
Expand Down
84 changes: 84 additions & 0 deletions test/key.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'

const FactoryClient = require('./ipfs-factory/client')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

describe('.key', () => {
let ipfs
let fc

before(function (done) {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
fc.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
done()
})
})

after((done) => {
fc.dismantle(done)
})

describe('Callback API', () => {
describe('.gen', () => {
it('create a new rsa key', (done) => {
ipfs.key.gen('foobarsa', { type: 'rsa', size: 2048 }, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
done()
})
})

it('create a new ed25519 key', (done) => {
ipfs.key.gen('bazed', { type: 'ed25519' }, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
done()
})
})
})

describe('.list', () => {
it('both keys show up + self', (done) => {
ipfs.key.list((err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res.Keys.length).to.equal(3)
done()
})
})
})
})

describe('Promise API', () => {
describe('.gen', () => {
it('create a new rsa key', () => {
return ipfs.key.gen('foobarsa2', {type: 'rsa', size: 2048}).then((res) => {
expect(res).to.exist()
})
})

it('create a new ed25519 key', () => {
return ipfs.key.gen('bazed2', {type: 'ed25519'}).then((res) => {
expect(res).to.exist()
})
})
})

describe('.list', () => {
it('4 keys to show up + self', () => {
return ipfs.key.list().then((res) => {
expect(res).to.exist()
expect(res.Keys.length).to.equal(5)
})
})
})
})
})