From 0be74e6a61f4cb8c27f06efae8acf60c1ea1f1a2 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 13 May 2020 13:18:07 +0200 Subject: [PATCH] chore: apply suggestions from code review Co-authored-by: Jacob Heun --- doc/CONFIGURATION.md | 2 +- src/config.js | 4 ---- src/index.js | 5 ++--- test/keychain/keychain.spec.js | 1 + 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/doc/CONFIGURATION.md b/doc/CONFIGURATION.md index 9dcc141c..c8b2fa68 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 2bd5a189..53c9c4c2 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 28954ae5..1036db60 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 2aad3c1c..5ba0e8c3 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' } }