Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 637b241

Browse files
fix: if no --pass, then no key management
Helps #1135
1 parent 27b1529 commit 637b241

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/core/components/no-keychain.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
'use strict'
22

33
function fail () {
4-
throw new Error('Key management is not yet implemented')
4+
throw new Error('Key management requires the daemon to run with \'--pass ...\'')
55
}
66

77
class NoKeychain {
8-
static get options () { return {} }
8+
static get options () { fail() }
9+
static generateOptions () { fail() }
910

1011
createKey () { fail() }
1112
listKeys () { fail() }
1213
findKeyById () { fail() }
1314
findKeyByName () { fail() }
1415
renameKey () { fail() }
16+
removeKey () { fail() }
1517
exportKey () { fail() }
1618
importKey () { fail() }
1719
importPeer () { fail() }

src/core/components/pre-start.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const PeerInfo = require('peer-info')
55
const multiaddr = require('multiaddr')
66
const waterfall = require('async/waterfall')
77
const Keychain = require('libp2p-keychain')
8-
8+
const NoKeychain = require('./no-keychain')
99
/*
1010
* Load stuff from Repo into memory
1111
*/
@@ -16,10 +16,15 @@ module.exports = function preStart (self) {
1616
waterfall([
1717
(cb) => self._repo.config.get(cb),
1818
(config, cb) => {
19-
const pass = self._options.pass || 'todo do not hardcode the pass phrase'
20-
const keychainOptions = Object.assign({passPhrase: pass}, config.Keychain)
21-
self._keychain = new Keychain(self._repo.keys, keychainOptions)
22-
self.log('keychain constructed')
19+
const pass = self._options.pass
20+
if (pass) {
21+
const keychainOptions = Object.assign({passPhrase: pass}, config.Keychain)
22+
self._keychain = new Keychain(self._repo.keys, keychainOptions)
23+
self.log('keychain constructed')
24+
} else {
25+
self._keychain = new NoKeychain()
26+
self.log('no keychain, use --pass')
27+
}
2328
cb(null, config)
2429
},
2530
(config, cb) => {

test/cli/key.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const hat = require('hat')
88
describe('key', () => runOnAndOff.off((thing) => {
99
const name = 'test-key-' + hat()
1010
const newName = 'test-key-' + hat()
11+
const pass = '--pass ' + hat()
1112
let ipfs
1213

1314
before(() => {
@@ -17,7 +18,7 @@ describe('key', () => runOnAndOff.off((thing) => {
1718
it('gen', function () {
1819
this.timeout(40 * 1000)
1920

20-
return ipfs(`key gen ${name} --type rsa --size 2048`)
21+
return ipfs(`${pass} key gen ${name} --type rsa --size 2048`)
2122
.then((out) => {
2223
expect(out).to.include(`generated ${name}`)
2324
})
@@ -26,7 +27,7 @@ describe('key', () => runOnAndOff.off((thing) => {
2627
it('list', function () {
2728
this.timeout(20 * 1000)
2829

29-
return ipfs('key list')
30+
return ipfs(`${pass} key list`)
3031
.then((out) => {
3132
expect(out).to.include(name)
3233
})
@@ -35,7 +36,7 @@ describe('key', () => runOnAndOff.off((thing) => {
3536
it('rename', function () {
3637
this.timeout(20 * 1000)
3738

38-
return ipfs(`key rename ${name} ${newName}`)
39+
return ipfs(`${pass} key rename ${name} ${newName}`)
3940
.then((out) => {
4041
expect(out).to.include(`renamed to ${newName}`)
4142
})
@@ -44,7 +45,7 @@ describe('key', () => runOnAndOff.off((thing) => {
4445
it('rm', function () {
4546
this.timeout(20 * 1000)
4647

47-
return ipfs(`key rm ${newName}`)
48+
return ipfs(`${pass} key rm ${newName}`)
4849
.then((out) => {
4950
expect(out).to.include(newName)
5051
})

0 commit comments

Comments
 (0)