diff --git a/js/src/api/rpc/personal/personal.js b/js/src/api/rpc/personal/personal.js index e35333102..ca7dbce9b 100644 --- a/js/src/api/rpc/personal/personal.js +++ b/js/src/api/rpc/personal/personal.js @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -import { inAddress, inNumber10, inNumber16, inOptions } from '../../format/input'; +import { inAddress, inHex, inNumber10, inNumber16, inOptions } from '../../format/input'; import { outAccountInfo, outAddress, outSignerRequest } from '../../format/output'; export default class Personal { @@ -73,6 +73,12 @@ export default class Personal { .then(outAddress); } + newAccountFromSecret (secret, password) { + return this._transport + .execute('personal_newAccountFromSecret', inHex(secret), password) + .then(outAddress); + } + newAccountFromWallet (json, password) { return this._transport .execute('personal_newAccountFromWallet', json, password) diff --git a/js/src/jsonrpc/interfaces/personal.js b/js/src/jsonrpc/interfaces/personal.js index 748c8799f..2a9ce7c19 100644 --- a/js/src/jsonrpc/interfaces/personal.js +++ b/js/src/jsonrpc/interfaces/personal.js @@ -141,7 +141,7 @@ export default { }, newAccountFromPhrase: { - desc: 'Creates a new account from a brainwallet passphrase', + desc: 'Creates a new account from a recovery passphrase', params: [ { type: String, @@ -158,6 +158,24 @@ export default { } }, + newAccountFromSecret: { + desc: 'Creates a new account from a private ethstore secret key', + params: [ + { + type: Data, + desc: 'Secret, 32-byte hex' + }, + { + type: String, + desc: 'Password' + } + ], + returns: { + type: Address, + desc: 'The created address' + } + }, + newAccountFromWallet: { desc: 'Creates a new account from a JSON import', params: [ diff --git a/rpc/src/v1/impls/personal_accounts.rs b/rpc/src/v1/impls/personal_accounts.rs index 0fa236845..6e777f537 100644 --- a/rpc/src/v1/impls/personal_accounts.rs +++ b/rpc/src/v1/impls/personal_accounts.rs @@ -20,7 +20,7 @@ use util::{Address}; use jsonrpc_core::*; use ethkey::{Brain, Generator}; use v1::traits::PersonalAccounts; -use v1::types::{H160 as RpcH160, TransactionRequest}; +use v1::types::{H160 as RpcH160, H256 as RpcH256, TransactionRequest}; use v1::helpers::errors; use v1::helpers::params::expect_no_params; use v1::helpers::dispatch::sign_and_dispatch; @@ -95,6 +95,19 @@ impl PersonalAccounts for PersonalAccountsClient w ) } + fn new_account_from_secret(&self, params: Params) -> Result { + try!(self.active()); + from_params::<(RpcH256, String, )>(params).and_then( + |(secret, pass, )| { + let store = take_weak!(self.accounts); + match store.insert_account(secret.into(), &pass) { + Ok(address) => Ok(to_value(&RpcH160::from(address))), + Err(e) => Err(errors::account("Could not create account.", e)), + } + } + ) + } + fn unlock_account(&self, params: Params) -> Result { try!(self.active()); from_params::<(RpcH160, String, Option)>(params).and_then( diff --git a/rpc/src/v1/traits/personal.rs b/rpc/src/v1/traits/personal.rs index 92a9df6eb..8ad1b7ac6 100644 --- a/rpc/src/v1/traits/personal.rs +++ b/rpc/src/v1/traits/personal.rs @@ -52,6 +52,10 @@ pub trait PersonalAccounts: Sized + Send + Sync + 'static { /// Second parameter is password for the wallet and the new account. fn new_account_from_wallet(&self, params: Params) -> Result; + /// Creates new account from the given raw secret. + /// Second parameter is password for the new account. + fn new_account_from_secret(&self, params: Params) -> Result; + /// Unlocks specified account for use (can only be one unlocked account at one moment) fn unlock_account(&self, _: Params) -> Result; @@ -84,6 +88,7 @@ pub trait PersonalAccounts: Sized + Send + Sync + 'static { delegate.add_method("personal_newAccount", PersonalAccounts::new_account); delegate.add_method("personal_newAccountFromPhrase", PersonalAccounts::new_account_from_phrase); delegate.add_method("personal_newAccountFromWallet", PersonalAccounts::new_account_from_wallet); + delegate.add_method("personal_newAccountFromSecret", PersonalAccounts::new_account_from_secret); delegate.add_method("personal_unlockAccount", PersonalAccounts::unlock_account); delegate.add_method("personal_testPassword", PersonalAccounts::test_password); delegate.add_method("personal_changePassword", PersonalAccounts::change_password);