mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 16:31:18 +00:00
Option to import encrypted private key
This commit is contained in:
parent
50c1612651
commit
d1fcdeca3b
@ -11,7 +11,8 @@ use crate::tags::{
|
||||
};
|
||||
use minion::Minion;
|
||||
use nostr_types::{
|
||||
Event, EventKind, Id, IdHex, PreEvent, PrivateKey, PublicKey, PublicKeyHex, Tag, Unixtime, Url,
|
||||
EncryptedPrivateKey, Event, EventKind, Id, IdHex, PreEvent, PrivateKey, PublicKey,
|
||||
PublicKeyHex, Tag, Unixtime, Url,
|
||||
};
|
||||
use relay_picker::{BestRelay, RelayPicker};
|
||||
use std::collections::HashMap;
|
||||
@ -410,6 +411,16 @@ impl Overlord {
|
||||
GLOBALS.signer.read().await.save_through_settings().await?;
|
||||
}
|
||||
ToOverlordMessage::ImportPriv(mut import_priv, mut password) => {
|
||||
if import_priv.starts_with("ncryptsec") {
|
||||
let epk = EncryptedPrivateKey(import_priv);
|
||||
GLOBALS.signer.write().await.set_encrypted_private_key(epk);
|
||||
GLOBALS
|
||||
.signer
|
||||
.write()
|
||||
.await
|
||||
.unlock_encrypted_private_key(&password)?;
|
||||
password.zeroize();
|
||||
} else {
|
||||
let maybe_pk1 = PrivateKey::try_from_bech32_string(&import_priv);
|
||||
let maybe_pk2 = PrivateKey::try_from_hex_string(&import_priv);
|
||||
import_priv.zeroize();
|
||||
@ -428,6 +439,7 @@ impl Overlord {
|
||||
GLOBALS.signer.read().await.save_through_settings().await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
ToOverlordMessage::ImportPub(pubstr) => {
|
||||
let maybe_pk1 = PublicKey::try_from_bech32_string(&pubstr);
|
||||
let maybe_pk2 = PublicKey::try_from_hex_string(&pubstr);
|
||||
|
@ -72,9 +72,10 @@ impl Signer {
|
||||
} else if let Some(epk) = &self.encrypted {
|
||||
self.private = Some(epk.decrypt(pass)?);
|
||||
|
||||
// If older version, re-encrypt with new version at default 2^18 rounds
|
||||
if let Some(private) = &self.private {
|
||||
// it will
|
||||
// it will be
|
||||
|
||||
// If older version, re-encrypt with new version at default 2^18 rounds
|
||||
if epk.version()? < 2 {
|
||||
self.encrypted = Some(private.export_encrypted(pass, DEFAULT_LOG_N)?);
|
||||
// and eventually save
|
||||
@ -84,6 +85,10 @@ impl Signer {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if self.public.is_none() {
|
||||
self.public = Some(private.public_key());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -184,12 +184,13 @@ fn offer_import_priv_key(app: &mut GossipUi, ui: &mut Ui) {
|
||||
ui.label("Enter private key");
|
||||
ui.add(
|
||||
TextEdit::singleline(&mut app.import_priv)
|
||||
.hint_text("nsec1 or hex")
|
||||
.hint_text("ncryptsec1, nsec1, or hex")
|
||||
.desired_width(f32::INFINITY)
|
||||
.password(true),
|
||||
);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Enter a password to keep it encrypted under");
|
||||
ui.label("Enter a password for the private key");
|
||||
ui.add(TextEdit::singleline(&mut app.password).password(true));
|
||||
});
|
||||
if ui.button("import").clicked() {
|
||||
@ -234,7 +235,11 @@ fn offer_import_pub_key(app: &mut GossipUi, ui: &mut Ui) {
|
||||
} else {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label("Enter your public key");
|
||||
ui.add(TextEdit::singleline(&mut app.import_pub).hint_text("npub1 or hex"));
|
||||
ui.add(
|
||||
TextEdit::singleline(&mut app.import_pub)
|
||||
.hint_text("npub1 or hex")
|
||||
.desired_width(f32::INFINITY),
|
||||
);
|
||||
if ui.button("Import a Public Key").clicked() {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
|
Loading…
Reference in New Issue
Block a user