Skip to content

Commit

Permalink
frost-client: don't allow overwriting contacts (#483)
Browse files Browse the repository at this point in the history
* frost-client: don't allow overwriting contacts

* also block importing contact with your own pubkey
  • Loading branch information
conradoplg authored Feb 24, 2025
1 parent df39100 commit 0cfe769
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions frost-client/src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@ pub(crate) fn import(args: &Command) -> Result<(), Box<dyn Error>> {
let mut config = Config::read(config)?;

let mut contact = Contact::from_text(&text_contact)?;
if config.contact.contains_key(&contact.name) {
return Err(eyre!(
"contact with name {} already exists. Either remove the existing \
one, or ask the sender to change their display name when exporting",
&contact.name
)
.into());
}
if config.contact.values().any(|c| c.pubkey == contact.pubkey) {
return Err(eyre!(
"pubkey {} already registered for {}",
hex::encode(&contact.pubkey),
&contact.name,
)
.into());
}
if config.communication_key.as_ref().map(|c| &c.pubkey) == Some(&contact.pubkey) {
return Err(eyre!(
"pubkey {} already registered for yourself",
hex::encode(&contact.pubkey)
)
.into());
}
// We don't want the version when writing to the config file.
contact.version = None;
config.contact.insert(contact.name.clone(), contact.clone());
Expand Down

0 comments on commit 0cfe769

Please sign in to comment.