From 3beef1992e32f1e079b09224d8c6828ef2409e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Sat, 4 Aug 2018 14:02:49 +0200 Subject: [PATCH] feat: allow pregenerated ids --- src/core/components/init.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/core/components/init.js b/src/core/components/init.js index c8ef37c882..81663b8e4d 100644 --- a/src/core/components/init.js +++ b/src/core/components/init.js @@ -61,10 +61,20 @@ module.exports = function init (self) { return cb(new Error('repo already exists')) } - // Generate peer identity keypair + transform to desired format + add to config. - opts.log(`generating ${opts.bits}-bit RSA keypair...`, false) - self.log('generating peer id: %s bits', opts.bits) - peerId.create({ bits: opts.bits }, cb) + if (opts.pregenId) { + // Use pregenerated Id + self.log('using pregenerated id') + cb(null, opts.pregenId) + } else if (process.env.IPFS_PREGENERATED_PRIVATE_KEY) { + // Use pregenerated Id from env + self.log('using pregenerated id from env') + peerId.createFromPrivKey(process.env.IPFS_PREGENERATED_PRIVATE_KEY, cb) + } else { + // Generate peer identity keypair + transform to desired format + add to config. + opts.log(`generating ${opts.bits}-bit RSA keypair...`, false) + self.log('generating peer id: %s bits', opts.bits) + peerId.create({ bits: opts.bits }, cb) + } }, (keys, cb) => { self.log('identity generated')