Add import of raw private key RPCs (#2942)
* Importing an account from raw secret * Add jsapi & jsonrpc for personal_newAccountFromSecret
This commit is contained in:
parent
6abd08f5b2
commit
8d66fc50e2
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import { inAddress, inNumber10, inNumber16, inOptions } from '../../format/input';
|
import { inAddress, inHex, inNumber10, inNumber16, inOptions } from '../../format/input';
|
||||||
import { outAccountInfo, outAddress, outSignerRequest } from '../../format/output';
|
import { outAccountInfo, outAddress, outSignerRequest } from '../../format/output';
|
||||||
|
|
||||||
export default class Personal {
|
export default class Personal {
|
||||||
@ -73,6 +73,12 @@ export default class Personal {
|
|||||||
.then(outAddress);
|
.then(outAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newAccountFromSecret (secret, password) {
|
||||||
|
return this._transport
|
||||||
|
.execute('personal_newAccountFromSecret', inHex(secret), password)
|
||||||
|
.then(outAddress);
|
||||||
|
}
|
||||||
|
|
||||||
newAccountFromWallet (json, password) {
|
newAccountFromWallet (json, password) {
|
||||||
return this._transport
|
return this._transport
|
||||||
.execute('personal_newAccountFromWallet', json, password)
|
.execute('personal_newAccountFromWallet', json, password)
|
||||||
|
@ -141,7 +141,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
newAccountFromPhrase: {
|
newAccountFromPhrase: {
|
||||||
desc: 'Creates a new account from a brainwallet passphrase',
|
desc: 'Creates a new account from a recovery passphrase',
|
||||||
params: [
|
params: [
|
||||||
{
|
{
|
||||||
type: String,
|
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: {
|
newAccountFromWallet: {
|
||||||
desc: 'Creates a new account from a JSON import',
|
desc: 'Creates a new account from a JSON import',
|
||||||
params: [
|
params: [
|
||||||
|
@ -20,7 +20,7 @@ use util::{Address};
|
|||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use ethkey::{Brain, Generator};
|
use ethkey::{Brain, Generator};
|
||||||
use v1::traits::PersonalAccounts;
|
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::errors;
|
||||||
use v1::helpers::params::expect_no_params;
|
use v1::helpers::params::expect_no_params;
|
||||||
use v1::helpers::dispatch::sign_and_dispatch;
|
use v1::helpers::dispatch::sign_and_dispatch;
|
||||||
@ -95,6 +95,19 @@ impl<C: 'static, M: 'static> PersonalAccounts for PersonalAccountsClient<C, M> w
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new_account_from_secret(&self, params: Params) -> Result<Value, Error> {
|
||||||
|
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<Value, Error> {
|
fn unlock_account(&self, params: Params) -> Result<Value, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
from_params::<(RpcH160, String, Option<u64>)>(params).and_then(
|
from_params::<(RpcH160, String, Option<u64>)>(params).and_then(
|
||||||
|
@ -52,6 +52,10 @@ pub trait PersonalAccounts: Sized + Send + Sync + 'static {
|
|||||||
/// Second parameter is password for the wallet and the new account.
|
/// Second parameter is password for the wallet and the new account.
|
||||||
fn new_account_from_wallet(&self, params: Params) -> Result<Value, Error>;
|
fn new_account_from_wallet(&self, params: Params) -> Result<Value, Error>;
|
||||||
|
|
||||||
|
/// 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<Value, Error>;
|
||||||
|
|
||||||
/// Unlocks specified account for use (can only be one unlocked account at one moment)
|
/// Unlocks specified account for use (can only be one unlocked account at one moment)
|
||||||
fn unlock_account(&self, _: Params) -> Result<Value, Error>;
|
fn unlock_account(&self, _: Params) -> Result<Value, Error>;
|
||||||
|
|
||||||
@ -84,6 +88,7 @@ pub trait PersonalAccounts: Sized + Send + Sync + 'static {
|
|||||||
delegate.add_method("personal_newAccount", PersonalAccounts::new_account);
|
delegate.add_method("personal_newAccount", PersonalAccounts::new_account);
|
||||||
delegate.add_method("personal_newAccountFromPhrase", PersonalAccounts::new_account_from_phrase);
|
delegate.add_method("personal_newAccountFromPhrase", PersonalAccounts::new_account_from_phrase);
|
||||||
delegate.add_method("personal_newAccountFromWallet", PersonalAccounts::new_account_from_wallet);
|
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_unlockAccount", PersonalAccounts::unlock_account);
|
||||||
delegate.add_method("personal_testPassword", PersonalAccounts::test_password);
|
delegate.add_method("personal_testPassword", PersonalAccounts::test_password);
|
||||||
delegate.add_method("personal_changePassword", PersonalAccounts::change_password);
|
delegate.add_method("personal_changePassword", PersonalAccounts::change_password);
|
||||||
|
Loading…
Reference in New Issue
Block a user