pass passphrase for key import

This commit is contained in:
Bucko 2017-08-17 18:24:40 -07:00
parent 58ec9b3fab
commit af32c5d4c2
4 changed files with 8 additions and 7 deletions

View File

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

View File

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

View File

@ -360,8 +360,8 @@ HTTPWallet.prototype.retoken = async function retoken(passphrase) {
* @returns {Promise} * @returns {Promise}
*/ */
HTTPWallet.prototype.importPrivate = function importPrivate(account, key) { HTTPWallet.prototype.importPrivate = function importPrivate(account, key, passphrase='') {
return this.client.importPrivate(this.id, account, key); 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) => { this.post('/:id/import', async (req, res) => {
const valid = req.valid(); const valid = req.valid();
const acct = valid.str('account'); const acct = valid.str('account');
const passphrase = valid.str('passphrase');
const pub = valid.buf('publicKey'); const pub = valid.buf('publicKey');
const priv = valid.str('privateKey'); const priv = valid.str('privateKey');
const b58 = valid.str('address'); const b58 = valid.str('address');
@ -350,7 +351,7 @@ HTTPServer.prototype.initRouter = function initRouter() {
if (priv) { if (priv) {
const key = KeyRing.fromSecret(priv, this.network); 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 }); res.send(200, { success: true });
return; return;
} }