From 439958c6d3607f108e9391cf74f6c37b5bbd9812 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Wed, 4 Jan 2023 16:35:54 +1300 Subject: [PATCH] Deletion of identity --- README.md | 2 +- src/signer.rs | 21 +++++++++++++++++++++ src/ui/you.rs | 24 ++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d4c61ed..6145e675 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ As of right now you can (if you aren't stopped by some bug): - [x] **Creting content** - [x] Generating a key that is kept securely within the client encrypted under a password that you need to unlock it every time you start the client. - [x] Generate or import (hex or bech32) a private key (your identity) (also kept under a password) - - [x] Exporting your private key encrypted, or decrypted as bech32 or hex + - [x] Exporting your private key encrypted, or decrypted as bech32 or hex, or delete your identity - [x] Choose relays to post to (from among some starting relays, plus ones the client has seen in events), including entering a relay URL directly. - [x] Post root-level text messages - [x] Post replies to other people's text messages diff --git a/src/signer.rs b/src/signer.rs index 9a64e198..9e05721f 100644 --- a/src/signer.rs +++ b/src/signer.rs @@ -129,4 +129,25 @@ impl Signer { _ => Err(Error::NoPrivateKey), } } + + pub fn delete_identity(&mut self, pass: &str) -> Result<(), Error> { + match self { + Signer::Ready(_, epk) => { + // Verify their password + let _pk = epk.decrypt(pass)?; + + // Delete from database + let mut settings = GLOBALS.settings.blocking_write(); + settings.encrypted_private_key = None; + task::spawn(async move { + if let Err(e) = settings.save().await { + tracing::error!("{}", e); + } + }); + *self = Signer::Fresh; + Ok(()) + } + _ => Err(Error::NoPrivateKey), + } + } } diff --git a/src/ui/you.rs b/src/ui/you.rs index a6a6da39..ff9d07a4 100644 --- a/src/ui/you.rs +++ b/src/ui/you.rs @@ -108,6 +108,30 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr app.password.zeroize(); app.password = "".to_owned(); } + + ui.add_space(10.0); + ui.separator(); + ui.add_space(10.0); + ui.heading("DELETE This Identity"); + + ui.horizontal(|ui| { + ui.add_space(10.0); + ui.label("Enter Password To Delete: "); + ui.add(TextEdit::singleline(&mut app.password).password(true)); + }); + + if ui.button("DELETE (Cannot be undone!)").clicked() { + match GLOBALS + .signer + .blocking_write() + .delete_identity(&app.password) + { + Ok(_) => app.status = "Identity deleted.".to_string(), + Err(e) => app.status = format!("{}", e), + } + app.password.zeroize(); + app.password = "".to_owned(); + } } else if GLOBALS.signer.blocking_read().is_loaded() { ui.heading("Password Needed");