add backup encryption key
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use std::cell::Cell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -34,8 +35,8 @@ impl Global for GlobalDeviceRegistry {}
|
||||
pub enum DeviceEvent {
|
||||
/// A new encryption signer has been set
|
||||
Set,
|
||||
/// The encryption key has been reset
|
||||
Reset,
|
||||
/// The device is requesting an encryption key
|
||||
Requesting,
|
||||
/// Encryption key is not set
|
||||
NotSet { reason: SharedString },
|
||||
/// An event to notify that Coop isn't subscribed to gift wrap events
|
||||
@@ -288,6 +289,21 @@ impl DeviceRegistry {
|
||||
})
|
||||
}
|
||||
|
||||
/// Backup the encryption's secret key to a file
|
||||
pub fn backup(&self, path: PathBuf, cx: &App) -> Task<Result<(), Error>> {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
let client = nostr.read(cx).client();
|
||||
|
||||
cx.background_spawn(async move {
|
||||
let keys = get_keys(&client).await?;
|
||||
let content = keys.secret_key().to_bech32()?;
|
||||
|
||||
smol::fs::write(path, &content).await?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
/// Get device announcement for current user
|
||||
pub fn get_announcement(&mut self, cx: &mut Context<Self>) {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
@@ -507,6 +523,8 @@ impl DeviceRegistry {
|
||||
this.update(cx, |this, cx| {
|
||||
this.set_requesting(true, cx);
|
||||
this.wait_for_approval(cx);
|
||||
|
||||
cx.emit(DeviceEvent::Requesting);
|
||||
})?;
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user