Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Export acc js #4973

Merged
merged 47 commits into from Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3c6203a
Export account RPC
tomusdrw Mar 20, 2017
751d69e
Removing GethDirectory and ParityDirectory
tomusdrw Mar 20, 2017
edf480b
js export accounts as json
CraigglesO Mar 21, 2017
f806c1a
js export accounts as json
CraigglesO Mar 21, 2017
3ae039f
api - then - catch
CraigglesO Mar 21, 2017
f29e1b1
final touches
CraigglesO Mar 21, 2017
5e9ff99
pass
CraigglesO Mar 21, 2017
1e6ec1d
oops
CraigglesO Mar 21, 2017
c8d079b
individual accounts
CraigglesO Mar 22, 2017
038b6a8
refactoring
CraigglesO Mar 22, 2017
dc5f0bf
refactor one
CraigglesO Mar 23, 2017
29c991b
refactor one
CraigglesO Mar 23, 2017
f13bc43
refactor two
CraigglesO Mar 23, 2017
82d1a11
some grumble fixes
CraigglesO Mar 24, 2017
1f3e968
file name changes
CraigglesO Mar 24, 2017
ad6d26e
constructor
CraigglesO Mar 24, 2017
0dcbb4e
constructor
CraigglesO Mar 24, 2017
21eec94
Merge branch 'export-acc-js' of github.com:paritytech/parity into exp…
CraigglesO Mar 24, 2017
adfe3a1
ummmm....
CraigglesO Mar 24, 2017
c66102b
git recognize file name change
CraigglesO Mar 24, 2017
6ea1d71
spec and updates
CraigglesO Mar 25, 2017
7683664
specs
CraigglesO Mar 25, 2017
ff5ac83
one tiny fix
CraigglesO Mar 27, 2017
12ae326
one tiny fix
CraigglesO Mar 27, 2017
4efc292
grumbles
CraigglesO Mar 27, 2017
614eccd
more grumbles
CraigglesO Apr 3, 2017
3c5c295
sliders
CraigglesO Apr 4, 2017
af4c0d6
fast forward
CraigglesO Apr 4, 2017
be63bdf
ff
CraigglesO Apr 4, 2017
6bd50e6
pointer default
CraigglesO Apr 4, 2017
67aa8e9
grumbles
CraigglesO Apr 5, 2017
fab6359
almost ready
CraigglesO Apr 5, 2017
ce27d45
lots of updates
CraigglesO Apr 5, 2017
9ce6cdc
accountList
CraigglesO Apr 5, 2017
82327fb
stupid debuglog
CraigglesO Apr 5, 2017
be64717
bug fix
CraigglesO Apr 5, 2017
0267278
bug fix
CraigglesO Apr 5, 2017
38a1868
some more good ol fashioned updates
CraigglesO Apr 6, 2017
6bfc14b
filter accounts
CraigglesO Apr 6, 2017
53892b4
clean
CraigglesO Apr 6, 2017
602a9da
update spec
CraigglesO Apr 6, 2017
feae96f
ff
CraigglesO Apr 10, 2017
da929f9
ff
CraigglesO Apr 10, 2017
043bc22
Merge branch 'master' of github.com:paritytech/parity into export-acc-js
CraigglesO Apr 19, 2017
3cd499a
ff-again
CraigglesO Apr 24, 2017
e85118b
ff-f
CraigglesO Apr 24, 2017
ebc8cd1
balances fix
CraigglesO Apr 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions ethcore/src/account_provider/mod.rs
Expand Up @@ -24,14 +24,16 @@ use std::fmt;
use std::collections::{HashMap, HashSet};
use std::time::{Instant, Duration};
use util::{RwLock};
use ethstore::{SimpleSecretStore, SecretStore, Error as SSError, EthStore, EthMultiStore,
random_string, SecretVaultRef, StoreAccountRef};
use ethstore::{
SimpleSecretStore, SecretStore, Error as SSError, EthStore, EthMultiStore,
random_string, SecretVaultRef, StoreAccountRef,
};
use ethstore::dir::MemoryDirectory;
use ethstore::ethkey::{Address, Message, Public, Secret, Random, Generator};
use ethjson::misc::AccountMeta;
use hardware_wallet::{Error as HardwareError, HardwareWalletManager, KeyPath};
pub use ethstore::ethkey::Signature;
pub use ethstore::{Derivation, IndexDerivation};
pub use ethstore::{Derivation, IndexDerivation, KeyFile};

/// Type of unlock.
#[derive(Clone)]
Expand Down Expand Up @@ -500,6 +502,11 @@ impl AccountProvider {
self.sstore.change_password(&self.sstore.account_ref(address)?, &password, &new_password)
}

/// Exports an account for given address.
pub fn export_account(&self, address: &Address, password: String) -> Result<KeyFile, Error> {
self.sstore.export_account(&self.sstore.account_ref(address)?, &password)
}

/// Helper method used for unlocking accounts.
fn unlock_account(&self, address: Address, password: String, unlock: Unlock) -> Result<(), Error> {
// verify password by signing dump message
Expand Down
14 changes: 14 additions & 0 deletions ethstore/src/account/safe_account.rs
Expand Up @@ -19,14 +19,22 @@ use {json, Error, crypto};
use account::Version;
use super::crypto::Crypto;

/// Account representation.
#[derive(Debug, PartialEq, Clone)]
pub struct SafeAccount {
/// Account ID
pub id: [u8; 16],
/// Account version
pub version: Version,
/// Account address
pub address: Address,
/// Account private key derivation definition.
pub crypto: Crypto,
/// Account filename
pub filename: Option<String>,
/// Account name
pub name: String,
/// Account metadata
pub meta: String,
}

Expand All @@ -44,6 +52,7 @@ impl Into<json::KeyFile> for SafeAccount {
}

impl SafeAccount {
/// Create a new account
pub fn create(
keypair: &KeyPair,
id: [u8; 16],
Expand Down Expand Up @@ -114,21 +123,25 @@ impl SafeAccount {
})
}

/// Sign a message.
pub fn sign(&self, password: &str, message: &Message) -> Result<Signature, Error> {
let secret = self.crypto.secret(password)?;
sign(&secret, message).map_err(From::from)
}

/// Decrypt a message.
pub fn decrypt(&self, password: &str, shared_mac: &[u8], message: &[u8]) -> Result<Vec<u8>, Error> {
let secret = self.crypto.secret(password)?;
crypto::ecies::decrypt(&secret, shared_mac, message).map_err(From::from)
}

/// Derive public key.
pub fn public(&self, password: &str) -> Result<Public, Error> {
let secret = self.crypto.secret(password)?;
Ok(KeyPair::from_secret(secret)?.public().clone())
}

/// Change account's password.
pub fn change_password(&self, old_password: &str, new_password: &str, iterations: u32) -> Result<Self, Error> {
let secret = self.crypto.secret(old_password)?;
let result = SafeAccount {
Expand All @@ -143,6 +156,7 @@ impl SafeAccount {
Ok(result)
}

/// Check if password matches the account.
pub fn check_password(&self, password: &str) -> bool {
self.crypto.secret(password).is_ok()
}
Expand Down
14 changes: 8 additions & 6 deletions ethstore/src/bin/ethstore.rs
Expand Up @@ -22,7 +22,7 @@ use std::{env, process, fs};
use std::io::Read;
use docopt::Docopt;
use ethstore::ethkey::Address;
use ethstore::dir::{KeyDirectory, ParityDirectory, RootDiskDirectory, GethDirectory, DirectoryType};
use ethstore::dir::{paths, KeyDirectory, RootDiskDirectory};
use ethstore::{EthStore, SimpleSecretStore, SecretStore, import_accounts, Error, PresaleWallet,
SecretVaultRef, StoreAccountRef};

Expand Down Expand Up @@ -116,10 +116,13 @@ fn main() {

fn key_dir(location: &str) -> Result<Box<KeyDirectory>, Error> {
let dir: Box<KeyDirectory> = match location {
"parity" => Box::new(ParityDirectory::create(DirectoryType::Main)?),
"parity-test" => Box::new(ParityDirectory::create(DirectoryType::Testnet)?),
"geth" => Box::new(GethDirectory::create(DirectoryType::Main)?),
"geth-test" => Box::new(GethDirectory::create(DirectoryType::Testnet)?),
"geth" => Box::new(RootDiskDirectory::create(paths::geth(false))?),
"geth-test" => Box::new(RootDiskDirectory::create(paths::geth(true))?),
path if path.starts_with("parity") => {
let chain = path.split('-').nth(1).unwrap_or("ethereum");
let path = paths::parity(chain);
Box::new(RootDiskDirectory::create(path)?)
},
path => Box::new(RootDiskDirectory::create(path)?),
};

Expand Down Expand Up @@ -254,4 +257,3 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
Ok(format!("{}", USAGE))
}
}

102 changes: 0 additions & 102 deletions ethstore/src/dir/geth.rs

This file was deleted.

1 change: 1 addition & 0 deletions ethstore/src/dir/memory.rs
Expand Up @@ -22,6 +22,7 @@ use ethkey::Address;
use {SafeAccount, Error};
use super::KeyDirectory;

/// Accounts in-memory storage.
#[derive(Default)]
pub struct MemoryDirectory {
accounts: RwLock<HashMap<Address, Vec<SafeAccount>>>,
Expand Down
14 changes: 4 additions & 10 deletions ethstore/src/dir/mod.rs
Expand Up @@ -14,19 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

//! Accounts Directory

use std::path::{PathBuf};
use {SafeAccount, Error};

mod disk;
mod geth;
mod memory;
mod parity;
mod vault;

pub enum DirectoryType {
Testnet,
Main,
}
pub mod paths;

/// `VaultKeyDirectory::set_key` error
#[derive(Debug)]
Expand Down Expand Up @@ -54,7 +50,7 @@ pub trait KeyDirectory: Send + Sync {
fn load(&self) -> Result<Vec<SafeAccount>, Error>;
/// Insert new key to directory
fn insert(&self, account: SafeAccount) -> Result<SafeAccount, Error>;
//// Update key in directory
/// Update key in the directory
fn update(&self, account: SafeAccount) -> Result<SafeAccount, Error>;
/// Remove key from directory
fn remove(&self, account: &SafeAccount) -> Result<(), Error>;
Expand Down Expand Up @@ -95,9 +91,7 @@ pub trait VaultKeyDirectory: KeyDirectory {
}

pub use self::disk::RootDiskDirectory;
pub use self::geth::GethDirectory;
pub use self::memory::MemoryDirectory;
pub use self::parity::ParityDirectory;
pub use self::vault::VaultDiskDirectory;

impl VaultKey {
Expand Down
81 changes: 0 additions & 81 deletions ethstore/src/dir/parity.rs

This file was deleted.