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

Commit

Permalink
KeyStore implementation + key derivation (#97)
Browse files Browse the repository at this point in the history
* improve ed25519 bindings

* probably broken child derivation

* basic keystore

* keystore integration in CLI

* constant-time mac comparison

* fix spaces
  • Loading branch information
rphmeier authored and gavofyork committed Mar 16, 2018
1 parent a70ac87 commit 2174d09
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 17 deletions.
88 changes: 88 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"polkadot/collator",
"polkadot/consensus",
"polkadot/executor",
"polkadot/keystore",
"polkadot/primitives",
"polkadot/runtime",
"polkadot/statement-table",
Expand Down
2 changes: 2 additions & 0 deletions polkadot/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ log = "0.3"
hex-literal = "0.1"
triehash = "0.1"
ed25519 = { path = "../../substrate/ed25519" }
app_dirs = "1.1"
substrate-client = { path = "../../substrate/client" }
substrate-codec = { path = "../../substrate/codec" }
substrate-runtime-io = { path = "../../substrate/runtime-io" }
Expand All @@ -22,3 +23,4 @@ substrate-rpc-servers = { path = "../../substrate/rpc-servers" }
polkadot-primitives = { path = "../primitives" }
polkadot-executor = { path = "../executor" }
polkadot-runtime = { path = "../runtime" }
polkadot-keystore = { path = "../keystore" }
6 changes: 5 additions & 1 deletion polkadot/cli/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ args:
- log:
short: l
value_name: LOG_PATTERN
help: Sets a custom logging
help: Sets a custom logging filter
takes_value: true
- keystore-path:
value_name: KEYSTORE_PATH
help: specify custom keystore path
takes_value: true
subcommands:
- collator:
Expand Down
7 changes: 7 additions & 0 deletions polkadot/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ error_chain! {
links {
Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"];
}
errors {
/// Key store errors
Keystore(e: ::keystore::Error) {
description("Keystore error"),
display("Keystore error: {:?}", e),
}
}
}
27 changes: 27 additions & 0 deletions polkadot/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#![warn(missing_docs)]

extern crate app_dirs;
extern crate env_logger;
extern crate ed25519;
extern crate triehash;
Expand All @@ -29,6 +30,7 @@ extern crate substrate_rpc_servers as rpc;
extern crate polkadot_primitives;
extern crate polkadot_executor;
extern crate polkadot_runtime;
extern crate polkadot_keystore as keystore;

#[macro_use]
extern crate hex_literal;
Expand All @@ -41,9 +43,12 @@ extern crate log;

pub mod error;

use std::path::{Path, PathBuf};

use codec::Slicable;
use polkadot_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig};
use client::genesis;
use keystore::Store as Keystore;

/// Parse command line arguments and start the node.
///
Expand Down Expand Up @@ -79,12 +84,19 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
bonding_duration: 90, // 90 days per bond.
approval_ratio: 667, // 66.7% approvals required for legislation.
};

let prepare_genesis = || {
storage = genesis_config.genesis_map();
let block = genesis::construct_genesis_block(&storage);
storage.extend(additional_storage_with_genesis(&block));
(primitives::block::Header::decode(&mut block.header.encode().as_ref()).expect("to_vec() always gives a valid serialisation; qed"), storage.into_iter().collect())
};

let keystore_path = matches.value_of("keystore")
.map(|x| Path::new(x).to_owned())
.unwrap_or_else(default_keystore_path);

let _keystore = Keystore::open(keystore_path).map_err(::error::ErrorKind::Keystore)?;
let client = client::new_in_mem(executor, prepare_genesis)?;

let address = "127.0.0.1:9933".parse().unwrap();
Expand All @@ -109,6 +121,21 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
Ok(())
}

fn default_keystore_path() -> PathBuf {
use app_dirs::{AppInfo, AppDataType};

let app_info = AppInfo {
name: "Polkadot",
author: "Parity Technologies",
};

app_dirs::get_app_dir(
AppDataType::UserData,
&app_info,
"keystore",
).expect("app directories exist on all supported platforms; qed")
}

fn init_logger(pattern: &str) {
let mut builder = env_logger::LogBuilder::new();
// Disable info logging by default for some modules:
Expand Down
18 changes: 18 additions & 0 deletions polkadot/keystore/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "polkadot-keystore"
version = "0.1.0"
authors = ["Parity Technologies <robert@parity.io>"]

[dependencies]
ethcrypto = { git = "https://github.com/paritytech/parity", default_features = false }
ed25519 = { path = "../../substrate/ed25519" }
error-chain = "0.11"
hex = "0.3"
rand = "0.4"
serde_json = "1.0"
serde = "1.0"
serde_derive = "1.0"
subtle = "0.5"

[dev-dependencies]
tempdir = "0.3"
Loading

0 comments on commit 2174d09

Please sign in to comment.