-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Wallet #469
Merged
Merged
Implement Wallet #469
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d9f9469
initial wallet implementation
flodesi 0ce51ba
implemented wallet except generating new private key
flodesi f2f3193
license
flodesi bf72c6c
implemented private key generation and refactor
flodesi b9d55a2
Merge branch 'master' into jaden/wallet
flodesi 8cd1133
reformatting code according to comments on pr
flodesi 52b341f
changed keystore to be a trait and refactored
flodesi 73536cd
Merge branch 'master' into jaden/wallet
flodesi 8e2d034
cargo clippy
flodesi a957827
fixed issues using rust stable 1.44
flodesi 81582ab
Merge branch 'master' into jaden/wallet
flodesi 33951df
fixed issues rust 1.44 issues
flodesi 3767f34
Merge branch 'master' into jaden/wallet
flodesi 30e75b7
added wallet tests
flodesi 3be8fe5
Merge branch 'jaden/wallet' of https://github.com/ChainSafe/forest in…
flodesi 00b18e3
added changes
flodesi f74ea15
Update key_management/src/keystore.rs
flodesi cf033f3
Merge branch 'master' into jaden/wallet
flodesi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,5 @@ members = [ | |
"utils/commcid", | ||
"utils/json_utils", | ||
"types", | ||
"key_management", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "key_management" | ||
version = "0.1.0" | ||
authors = ["ChainSafe Systems <info@chainsafe.io>"] | ||
edition = "2018" | ||
|
||
[dependencies] | ||
thiserror = "1.0" | ||
address = { package = "forest_address", path = "../vm/address", version = "0.2" } | ||
crypto = { package = "forest_crypto", path = "../crypto" } | ||
bls-signatures = "0.6.0" | ||
libsecp256k1 = "0.3.4" | ||
rand = "0.7.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2020 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use thiserror::Error; | ||
|
||
#[derive(Debug, PartialEq, Error)] | ||
pub enum Error { | ||
/// info that corresponds to key does not exist | ||
#[error("Key info not found")] | ||
KeyInfo, | ||
/// Key already exists in keystore | ||
#[error("Key already exists")] | ||
KeyExists, | ||
#[error("Key does not exist")] | ||
KeyNotExists, | ||
#[error("Key not found")] | ||
NoKey, | ||
#[error("{0}")] | ||
Other(String), | ||
#[error("Could not convert from KeyInfo to Key")] | ||
KeyInfoConversion, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2020 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use super::errors::Error; | ||
use crypto::SignatureType; | ||
use std::collections::HashMap; | ||
|
||
/// KeyInfo struct, this contains the type of key (stored as a string) and the private key. | ||
/// note how the private key is stored as a byte vector | ||
#[derive(Clone, PartialEq, Debug, Eq)] | ||
pub struct KeyInfo { | ||
key_type: SignatureType, | ||
// Vec<u8> is used because The private keys for BLS and SECP256K1 are not of the same type | ||
private_key: Vec<u8>, | ||
} | ||
|
||
impl KeyInfo { | ||
/// Return a new KeyInfo given the key_type and private_key | ||
pub fn new(key_type: SignatureType, private_key: Vec<u8>) -> Self { | ||
KeyInfo { | ||
key_type, | ||
private_key, | ||
} | ||
} | ||
|
||
/// Return a clone of the key_type | ||
pub fn key_type(&self) -> &SignatureType { | ||
&self.key_type | ||
} | ||
|
||
/// Return a clone of the private_key | ||
pub fn private_key(&self) -> &Vec<u8> { | ||
&self.private_key | ||
} | ||
} | ||
|
||
/// KeyStore struct, this contains a HashMap that is a set of KeyInfos resolved by their Address | ||
pub trait KeyStore { | ||
/// Return all of the keys that are stored in the KeyStore | ||
fn list(&self) -> Vec<String>; | ||
/// Return Keyinfo that corresponds to a given key | ||
fn get(&self, k: &str) -> Result<KeyInfo, Error>; | ||
/// Save a key key_info pair to the KeyStore | ||
fn put(&mut self, key: String, key_info: KeyInfo) -> Result<(), Error>; | ||
/// Remove the Key and corresponding key_info from the KeyStore | ||
fn remove(&mut self, key: String) -> Option<KeyInfo>; | ||
} | ||
|
||
#[derive(Default, Clone, PartialEq, Debug, Eq)] | ||
pub struct MemKeyStore { | ||
pub key_info: HashMap<String, KeyInfo>, | ||
} | ||
|
||
impl MemKeyStore { | ||
/// Return a new empty KeyStore | ||
pub fn new() -> Self { | ||
MemKeyStore { | ||
key_info: HashMap::new(), | ||
} | ||
} | ||
} | ||
|
||
impl KeyStore for MemKeyStore { | ||
fn list(&self) -> Vec<String> { | ||
self.key_info.iter().map(|(key, _)| key.clone()).collect() | ||
} | ||
|
||
fn get(&self, k: &str) -> Result<KeyInfo, Error> { | ||
self.key_info.get(k).cloned().ok_or(Error::KeyInfo) | ||
} | ||
|
||
fn put(&mut self, key: String, key_info: KeyInfo) -> Result<(), Error> { | ||
if self.key_info.contains_key(&key) { | ||
return Err(Error::KeyExists); | ||
} | ||
self.key_info.insert(key, key_info); | ||
Ok(()) | ||
} | ||
|
||
fn remove(&mut self, key: String) -> Option<KeyInfo> { | ||
self.key_info.remove(&key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2020 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
mod errors; | ||
mod keystore; | ||
mod wallet; | ||
mod wallet_helpers; | ||
|
||
pub use errors::*; | ||
pub use keystore::*; | ||
pub use wallet::*; | ||
pub use wallet_helpers::*; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't keys need to be persisted? Is there a plan for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just in memory storage, when the node stops and starts again, these keys are lost. There should be a way to persist the keys to be reused in some way