diff --git a/README.md b/README.md index cd54992b..303412e3 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ Initialize a repo. `initOpts` (optional) is an object with the following properties: - `keysize` (default 2048) - The bit size of the identity key. - `directory` (default IPFS_PATH if defined, or ~/.ipfs for go-ipfs and ~/.jsipfs for js-ipfs) - The location of the repo. + - `pass` (optional) - The passphrase of the key chain. `callback` is a function with the signature `function (Error, ipfsd)` where `err` is an Error in case something goes wrong and `ipfsd` is the daemon controller instance. diff --git a/src/daemon-node.js b/src/daemon-node.js index 7909cd1f..2bcfed7a 100644 --- a/src/daemon-node.js +++ b/src/daemon-node.js @@ -108,6 +108,7 @@ class Node { * @param {Object} [initOpts={}] * @param {number} [initOpts.keysize=2048] - The bit size of the identiy key. * @param {string} [initOpts.directory=IPFS_PATH] - The location of the repo. + * @param {string} [initOpts.pass] - The passphrase of the keychain. * @param {function (Error, Node)} callback * @returns {undefined} */ @@ -117,13 +118,16 @@ class Node { initOpts = {} } - const keySize = initOpts.keysize || 2048 - if (initOpts.directory && initOpts.directory !== this.path) { this.path = initOpts.directory } - run(this, ['init', '-b', keySize], { env: this.env }, (err, result) => { + const args = ['init', '-b', initOpts.keysize || 2048] + if (initOpts.pass) { + args.push('--pass') + args.push('"' + initOpts.pass + '"') + } + run(this, args, { env: this.env }, (err, result) => { if (err) { return callback(err) } diff --git a/src/in-proc-node.js b/src/in-proc-node.js index f06ac169..2fad9557 100644 --- a/src/in-proc-node.js +++ b/src/in-proc-node.js @@ -116,6 +116,7 @@ class Node { * @param {Object} [initOpts={}] * @param {number} [initOpts.keysize=2048] - The bit size of the identiy key. * @param {string} [initOpts.directory=IPFS_PATH] - The location of the repo. + * @param {string} [initOpts.pass] - The passphrase of the keychain. * @param {function (Error, Node)} callback * @returns {undefined} */