Skip to content
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

fix(keypairs): load persisted keypair in a backward-compatible way #1481

Merged
merged 2 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/builtins-deployer/src/builtins_deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl BuiltinsDeployer {

let result = self
.send_particle(script, hashmap! {"name".to_string() => json!(name)})
.wrap_err(format!("remove_service call failed, service {}", name))?;
.wrap_err(format!("remove_service call failed, service {name}"))?;

assert_ok(result, "remove_service call failed")
}
Expand Down
9 changes: 8 additions & 1 deletion crates/key-manager/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::error::KeyManagerError::{
CannotExtractRSASecretKey, CreateKeypairsDir, DeserializePersistedKeypair,
ReadPersistedKeypair, SerializePersistedKeypair, WriteErrorPersistedKeypair,
};
use crate::KeyManager;
use fluence_keypair::KeyPair;
use fluence_libp2p::peerid_serializer;
use libp2p::PeerId;
Expand All @@ -30,9 +31,11 @@ use std::path::Path;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PersistedKeypair {
#[serde(with = "peerid_serializer")]
#[serde(alias = "remote_peer_id")]
pub deal_creator: PeerId,
pub private_key_bytes: Vec<u8>,
pub key_format: String,
#[serde(default)]
pub deal_id: String,
}

Expand Down Expand Up @@ -100,12 +103,16 @@ pub fn load_persisted_keypairs(
err,
path: file.to_path_buf(),
})?;
let keypair =
let mut keypair: PersistedKeypair =
toml::from_slice(bytes.as_slice()).map_err(|err| DeserializePersistedKeypair {
err,
path: file.to_path_buf(),
})?;

if keypair.deal_id.is_empty() {
keypair.deal_id = KeyManager::generate_deal_id(keypair.deal_creator);
}

Ok(keypair)
})
.collect()
Expand Down