mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 03:33:53 +00:00
Belatedly wire-up private key generation
This commit is contained in:
parent
0fba9d4588
commit
bd7363b40e
@ -393,6 +393,24 @@ impl Overlord {
|
||||
settings.save().await?;
|
||||
}
|
||||
}
|
||||
"generate_private_key" => {
|
||||
let mut password: String = serde_json::from_str(&bus_message.json_payload)?;
|
||||
let epk = GLOBALS
|
||||
.signer
|
||||
.write()
|
||||
.await
|
||||
.generate_private_key(&password)?;
|
||||
password.zeroize();
|
||||
|
||||
// Export and save private key
|
||||
let public_key = GLOBALS.signer.read().await.public_key().unwrap();
|
||||
{
|
||||
let mut settings = GLOBALS.settings.write().await;
|
||||
settings.encrypted_private_key = Some(epk);
|
||||
settings.public_key = Some(public_key);
|
||||
settings.save().await?;
|
||||
}
|
||||
}
|
||||
"import_bech32" => {
|
||||
let (mut import_bech32, mut password): (String, String) =
|
||||
serde_json::from_str(&bus_message.json_payload)?;
|
||||
|
@ -29,6 +29,15 @@ impl Signer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_private_key(&mut self, pass: &str) -> Result<EncryptedPrivateKey, Error> {
|
||||
*self = Signer::Ready(PrivateKey::generate());
|
||||
if let Signer::Ready(pk) = self {
|
||||
Ok(pk.export_encrypted(pass)?)
|
||||
} else {
|
||||
Err(Error::NoPrivateKey)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn is_loaded(&self) -> bool {
|
||||
matches!(self, Signer::Encrypted(_)) || matches!(self, Signer::Ready(_))
|
||||
|
@ -4,7 +4,6 @@ use crate::globals::GLOBALS;
|
||||
use eframe::egui;
|
||||
use egui::{Context, TextEdit, Ui};
|
||||
use nostr_types::{KeySecurity, PublicKeyHex};
|
||||
use tracing::info;
|
||||
use zeroize::Zeroize;
|
||||
|
||||
pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||
@ -53,8 +52,19 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
} else {
|
||||
ui.heading("Generate a Keypair");
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Enter a password to keep it encrypted under");
|
||||
ui.add(TextEdit::singleline(&mut app.password).password(true));
|
||||
});
|
||||
if ui.button("Generate Now").clicked() {
|
||||
info!("TBD GENERATE");
|
||||
let tx = GLOBALS.to_overlord.clone();
|
||||
let _ = tx.send(BusMessage {
|
||||
target: "overlord".to_string(),
|
||||
kind: "generate_private_key".to_string(),
|
||||
json_payload: serde_json::to_string(&app.password).unwrap(),
|
||||
});
|
||||
app.password.zeroize();
|
||||
app.password = "".to_owned();
|
||||
}
|
||||
|
||||
ui.add_space(10.0);
|
||||
|
Loading…
Reference in New Issue
Block a user