Skip to content

Commit

Permalink
fix(keypairs): load persisted keypair in a backward-compatible way (#…
Browse files Browse the repository at this point in the history
…1481)

* fix(keypair): load remote_peer_id to deal_creator, generate deal_id on the fly

* chore(lints): fix clippy
  • Loading branch information
folex committed Feb 22, 2023
1 parent 5165a3c commit ab51b9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit ab51b9c

Please sign in to comment.