ethstore cli loads passwords from files
This commit is contained in:
parent
927ffa7e9c
commit
9547324b46
@ -50,11 +50,11 @@ Commands:
|
||||
*Encrypt secret with a password and save it in secret store.*
|
||||
|
||||
- `<secret>` - ethereum secret, 32 bytes long
|
||||
- `<password>` - account password, any string
|
||||
- `<password>` - account password, file path
|
||||
- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity
|
||||
|
||||
```
|
||||
ethstore insert 7d29fab185a33e2cd955812397354c472d2b84615b645aa135ff539f6b0d70d5 "this is sparta"
|
||||
ethstore insert 7d29fab185a33e2cd955812397354c472d2b84615b645aa135ff539f6b0d70d5 password.txt
|
||||
```
|
||||
|
||||
```
|
||||
@ -77,12 +77,12 @@ ethstore insert `ethkey generate random -s` "this is sparta"
|
||||
*Change account password.*
|
||||
|
||||
- `<address>` - ethereum address, 20 bytes long
|
||||
- `<old-pwd>` - old account password, any string
|
||||
- `<new-pwd>` - new account password, any string
|
||||
- `<old-pwd>` - old account password, file path
|
||||
- `<new-pwd>` - new account password, file path
|
||||
- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity
|
||||
|
||||
```
|
||||
ethstore change-pwd a8fa5dd30a87bb9e3288d604eb74949c515ab66e "this is sparta" "hello world"
|
||||
ethstore change-pwd a8fa5dd30a87bb9e3288d604eb74949c515ab66e old_pwd.txt new_pwd.txt
|
||||
```
|
||||
|
||||
```
|
||||
@ -114,6 +114,10 @@ ethstore list
|
||||
- `[--src DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: geth
|
||||
- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity
|
||||
|
||||
```
|
||||
ethstore import
|
||||
```
|
||||
|
||||
```
|
||||
0: e6a3d25a7cb7cd21cb720df5b5e8afd154af1bbb
|
||||
1: 6edddfc6349aff20bc6467ccf276c5b52487f7a8
|
||||
@ -125,9 +129,13 @@ ethstore list
|
||||
*Import account from presale wallet.*
|
||||
|
||||
- `<path>` - presale wallet path
|
||||
- `<password>` - account password, any string
|
||||
- `<password>` - account password, file path
|
||||
- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity
|
||||
|
||||
```
|
||||
ethstore import-wallet ethwallet.json password.txt
|
||||
```
|
||||
|
||||
```
|
||||
e6a3d25a7cb7cd21cb720df5b5e8afd154af1bbb
|
||||
```
|
||||
@ -138,11 +146,11 @@ e6a3d25a7cb7cd21cb720df5b5e8afd154af1bbb
|
||||
*Remove account from secret store.*
|
||||
|
||||
- `<address>` - ethereum address, 20 bytes long
|
||||
- `<password>` - account password, any string
|
||||
- `<password>` - account password, file path
|
||||
- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity
|
||||
|
||||
```
|
||||
ethstore remove a8fa5dd30a87bb9e3288d604eb74949c515ab66e "hello world"
|
||||
ethstore remove a8fa5dd30a87bb9e3288d604eb74949c515ab66e password.txt
|
||||
```
|
||||
|
||||
```
|
||||
@ -155,12 +163,12 @@ true
|
||||
*Sign message with account's secret.*
|
||||
|
||||
- `<address>` - ethereum address, 20 bytes long
|
||||
- `<password>` - account password, any string
|
||||
- `<password>` - account password, file path
|
||||
- `<message>` - message to sign, 32 bytes long
|
||||
- `[--dir DIR]` - secret store directory, It may be either parity, parity-test, geth, geth-test or a path. default: parity
|
||||
|
||||
```
|
||||
ethstore sign 24edfff680d536a5f6fe862d36df6f8f6f40f115 "this is sparta" 7d29fab185a33e2cd955812397354c472d2b84615b645aa135ff539f6b0d70d5
|
||||
ethstore sign 24edfff680d536a5f6fe862d36df6f8f6f40f115 password.txt 7d29fab185a33e2cd955812397354c472d2b84615b645aa135ff539f6b0d70d5
|
||||
```
|
||||
|
||||
```
|
||||
|
@ -18,7 +18,8 @@ extern crate rustc_serialize;
|
||||
extern crate docopt;
|
||||
extern crate ethstore;
|
||||
|
||||
use std::{env, process};
|
||||
use std::{env, process, fs};
|
||||
use std::io::Read;
|
||||
use std::ops::Deref;
|
||||
use std::str::FromStr;
|
||||
use docopt::Docopt;
|
||||
@ -109,6 +110,15 @@ fn format_accounts(accounts: &[Address]) -> String {
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
fn load_password(path: &str) -> Result<String, Error> {
|
||||
let mut file = try!(fs::File::open(path));
|
||||
let mut password = String::new();
|
||||
try!(file.read_to_string(&mut password));
|
||||
// drop EOF
|
||||
let _ = password.pop();
|
||||
Ok(password)
|
||||
}
|
||||
|
||||
fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item=S>, S: AsRef<str> {
|
||||
let args: Args = Docopt::new(USAGE)
|
||||
.and_then(|d| d.argv(command).decode())
|
||||
@ -118,11 +128,14 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
|
||||
|
||||
return if args.cmd_insert {
|
||||
let secret = try!(Secret::from_str(&args.arg_secret));
|
||||
let address = try!(store.insert_account(secret, &args.arg_password));
|
||||
let password = try!(load_password(&args.arg_password));
|
||||
let address = try!(store.insert_account(secret, &password));
|
||||
Ok(format!("{}", address))
|
||||
} else if args.cmd_change_pwd {
|
||||
let address = try!(Address::from_str(&args.arg_address));
|
||||
let ok = store.change_password(&address, &args.arg_old_pwd, &args.arg_new_pwd).is_ok();
|
||||
let old_pwd = try!(load_password(&args.arg_old_pwd));
|
||||
let new_pwd = try!(load_password(&args.arg_new_pwd));
|
||||
let ok = store.change_password(&address, &old_pwd, &new_pwd).is_ok();
|
||||
Ok(format!("{}", ok))
|
||||
} else if args.cmd_list {
|
||||
let accounts = store.accounts();
|
||||
@ -134,17 +147,20 @@ fn execute<S, I>(command: I) -> Result<String, Error> where I: IntoIterator<Item
|
||||
Ok(format_accounts(&accounts))
|
||||
} else if args.cmd_import_wallet {
|
||||
let wallet = try!(PresaleWallet::open(&args.arg_path));
|
||||
let kp = try!(wallet.decrypt(&args.arg_password));
|
||||
let address = try!(store.insert_account(kp.secret().clone(), &args.arg_password));
|
||||
let password = try!(load_password(&args.arg_password));
|
||||
let kp = try!(wallet.decrypt(&password));
|
||||
let address = try!(store.insert_account(kp.secret().clone(), &password));
|
||||
Ok(format!("{}", address))
|
||||
} else if args.cmd_remove {
|
||||
let address = try!(Address::from_str(&args.arg_address));
|
||||
let ok = store.remove_account(&address, &args.arg_password).is_ok();
|
||||
let password = try!(load_password(&args.arg_password));
|
||||
let ok = store.remove_account(&address, &password).is_ok();
|
||||
Ok(format!("{}", ok))
|
||||
} else if args.cmd_sign {
|
||||
let address = try!(Address::from_str(&args.arg_address));
|
||||
let message = try!(Message::from_str(&args.arg_message));
|
||||
let signature = try!(store.sign(&address, &args.arg_password, &message));
|
||||
let password = try!(load_password(&args.arg_password));
|
||||
let signature = try!(store.sign(&address, &password, &message));
|
||||
Ok(format!("{}", signature))
|
||||
} else {
|
||||
unreachable!();
|
||||
|
Loading…
Reference in New Issue
Block a user