Skip to content

Commit

Permalink
feat(signer): load keys from disk if they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-wright committed Jun 28, 2023
1 parent a5da273 commit d2434c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/signer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
pub struct Config {
node_key_path: PathBuf,
network_key_path: PathBuf,
pub node_key_path: PathBuf,
pub network_key_path: PathBuf,
}

impl Default for Config {
Expand Down
20 changes: 17 additions & 3 deletions core/signer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,25 @@ struct SignerInner {
}

impl SignerInner {
fn new(_config: Config) -> Self {
fn new(config: Config) -> Self {
// TODO: load private keys from file if they exist
let node_secret_key = NodeSecretKey::generate();
let node_secret_key =
match NodeSecretKey::decode_pem(config.node_key_path.to_str().unwrap()) {
Some(node_secret_key) => node_secret_key,
None => {
NodeSecretKey::generate()
// TODO(matthias): save file to disk
},
};
let node_public_key = node_secret_key.to_pk();
let network_secret_key = NodeNetworkingSecretKey::generate();
let network_secret_key =
match NodeNetworkingSecretKey::decode_pem(config.network_key_path.to_str().unwrap()) {
Some(network_secret_key) => network_secret_key,
None => {
NodeNetworkingSecretKey::generate()
// TODO(matthias): save file to disk
},
};
let network_public_key = network_secret_key.to_pk();
Self {
node_secret_key,
Expand Down

0 comments on commit d2434c2

Please sign in to comment.