Merge pull request #281 from Bucko13/import-key-passphrase

pass passphrase for key import
This commit is contained in:
Christopher Jeffrey (JJ) 2017-10-18 22:30:10 -07:00 committed by GitHub
commit bdeb72a035
4 changed files with 8 additions and 7 deletions

View File

@ -429,12 +429,12 @@ CLI.prototype.backup = async function backup() {
CLI.prototype.importKey = async function importKey() {
const key = this.config.str(0);
const account = this.config.str('account');
const passphrase = this.config.str('passphrase');
if (!key)
throw new Error('No key for import.');
if (util.isBase58(key)) {
await this.wallet.importPrivate(account, key);
await this.wallet.importPrivate(account, key, passphrase);
this.log('Imported private key.');
return;
}

View File

@ -785,8 +785,8 @@ HTTPClient.prototype.removeSharedKey = function removeSharedKey(id, account, key
* @returns {Promise}
*/
HTTPClient.prototype.importPrivate = function importPrivate(id, account, key) {
const body = { account: account, privateKey: key };
HTTPClient.prototype.importPrivate = function importPrivate(id, account, key, passphrase) {
const body = { account: account, privateKey: key, passphrase: passphrase };
return this._post(`/wallet/${id}/import`, body);
};

View File

@ -360,8 +360,8 @@ HTTPWallet.prototype.retoken = async function retoken(passphrase) {
* @returns {Promise}
*/
HTTPWallet.prototype.importPrivate = function importPrivate(account, key) {
return this.client.importPrivate(this.id, account, key);
HTTPWallet.prototype.importPrivate = function importPrivate(account, key, passphrase='') {
return this.client.importPrivate(this.id, account, key, passphrase);
};
/**

View File

@ -337,6 +337,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
this.post('/:id/import', async (req, res) => {
const valid = req.valid();
const acct = valid.str('account');
const passphrase = valid.str('passphrase');
const pub = valid.buf('publicKey');
const priv = valid.str('privateKey');
const b58 = valid.str('address');
@ -350,7 +351,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
if (priv) {
const key = KeyRing.fromSecret(priv, this.network);
await req.wallet.importKey(acct, key);
await req.wallet.importKey(acct, key, passphrase);
res.send(200, { success: true });
return;
}