diff --git a/doc/CONFIGURATION.md b/doc/CONFIGURATION.md index e2583f4591..0c26b659b7 100644 --- a/doc/CONFIGURATION.md +++ b/doc/CONFIGURATION.md @@ -425,7 +425,7 @@ const node = await Libp2p.create({ #### Setup with Keychain -Libp2p allows you to setup a secure key chain to manage your keys. The keychain configuration object should have the following properties: +Libp2p allows you to setup a secure keychain to manage your keys. The keychain configuration object should have the following properties: | Name | Type | Description | |------|------|-------------| diff --git a/src/config.js b/src/config.js index 2bd5a189fe..53c9c4c2b5 100644 --- a/src/config.js +++ b/src/config.js @@ -1,6 +1,5 @@ 'use strict' -const { MemoryDatastore } = require('interface-datastore') const mergeOptions = require('merge-options') const Constants = require('./constants') @@ -18,9 +17,6 @@ const DefaultConfig = { maxDialsPerPeer: Constants.MAX_PER_PEER_DIALS, dialTimeout: Constants.DIAL_TIMEOUT }, - keychain: { - datastore: new MemoryDatastore() - }, metrics: { enabled: false }, diff --git a/src/index.js b/src/index.js index 28954ae5cb..1036db604e 100644 --- a/src/index.js +++ b/src/index.js @@ -76,13 +76,12 @@ class Libp2p extends EventEmitter { } // Create keychain - if (this._options.keychain.pass) { + if (this._options.keychain && this._options.keychain.pass && this._options.keychain.datastore) { log('creating keychain') - const datastore = this._options.keychain.datastore const keychainOpts = Keychain.generateOptions() - this.keychain = new Keychain(datastore, { + this.keychain = new Keychain(this._options.keychain.datastore, { passPhrase: this._options.keychain.pass, ...keychainOpts, ...this._options.keychain diff --git a/test/keychain/keychain.spec.js b/test/keychain/keychain.spec.js index 2aad3c1cf8..5ba0e8c3c7 100644 --- a/test/keychain/keychain.spec.js +++ b/test/keychain/keychain.spec.js @@ -416,6 +416,7 @@ describe('libp2p.keychain', () => { started: false, config: { keychain: { + datastore: new MemoryDatastore(), pass: '12345678901234567890' } }