impl linux credential storage
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
use nostr::nips::nip49::EncryptedSecretKey;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::Pubkey;
|
||||
use crate::SecretKey;
|
||||
|
||||
@@ -93,3 +97,34 @@ impl std::fmt::Display for FullKeypair {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SerializableKeypair {
|
||||
pub pubkey: Pubkey,
|
||||
pub encrypted_secret_key: Option<EncryptedSecretKey>,
|
||||
}
|
||||
|
||||
impl SerializableKeypair {
|
||||
pub fn from_keypair(kp: &Keypair, pass: &str, log_n: u8) -> Self {
|
||||
Self {
|
||||
pubkey: kp.pubkey.clone(),
|
||||
encrypted_secret_key: kp
|
||||
.secret_key
|
||||
.clone()
|
||||
.map(|s| {
|
||||
EncryptedSecretKey::new(&s, pass, log_n, nostr::nips::nip49::KeySecurity::Weak)
|
||||
.ok()
|
||||
})
|
||||
.flatten(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_keypair(&self, pass: &str) -> Keypair {
|
||||
Keypair::new(
|
||||
self.pubkey.clone(),
|
||||
self.encrypted_secret_key
|
||||
.map(|e| e.to_secret_key(pass).ok())
|
||||
.flatten(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ pub use error::Error;
|
||||
pub use event::{Event, EventId};
|
||||
pub use ewebsock;
|
||||
pub use filter::Filter;
|
||||
pub use keypair::{FullKeypair, Keypair};
|
||||
pub use keypair::{FullKeypair, Keypair, SerializableKeypair};
|
||||
pub use nostr::SecretKey;
|
||||
pub use note::NoteId;
|
||||
pub use profile::Profile;
|
||||
|
||||
Reference in New Issue
Block a user