feat: migrate frontend to new backend
This commit is contained in:
@@ -1,3 +1,2 @@
|
||||
pub mod folder;
|
||||
pub mod opg;
|
||||
pub mod secret;
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
use keyring::Entry;
|
||||
|
||||
#[tauri::command]
|
||||
pub fn secure_save(key: String, value: String) -> Result<(), ()> {
|
||||
let entry = Entry::new("Lume", &key).expect("Failed to create entry");
|
||||
let _ = entry.set_password(&value);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn secure_load(key: String) -> Result<String, String> {
|
||||
let entry = Entry::new("Lume", &key).expect("Failed to create entry");
|
||||
if let Ok(password) = entry.get_password() {
|
||||
Ok(password.into())
|
||||
} else {
|
||||
Err("Not found".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn secure_remove(key: String) -> Result<(), ()> {
|
||||
let entry = Entry::new("Lume", &key).expect("Failed to remove entry");
|
||||
let _ = entry.delete_password();
|
||||
Ok(())
|
||||
}
|
||||
@@ -23,6 +23,7 @@ use tauri_plugin_autostart::MacosLauncher;
|
||||
|
||||
pub struct Nostr {
|
||||
pub client: Arc<Client>,
|
||||
pub client_user: Option<XOnlyPublicKey>,
|
||||
pub contact_list: Option<Vec<Contact>>,
|
||||
}
|
||||
|
||||
@@ -90,17 +91,22 @@ fn main() {
|
||||
client.connect().await;
|
||||
|
||||
// Prepare contact list
|
||||
let mut user = None;
|
||||
let mut contact_list = None;
|
||||
|
||||
// Run somethings if account existed
|
||||
if let Some(key) = stored_nsec_key {
|
||||
let secret_key = SecretKey::from_bech32(key).expect("Get secret key failed");
|
||||
let keys = Keys::new(secret_key);
|
||||
let public_key = keys.public_key();
|
||||
let signer = ClientSigner::Keys(keys);
|
||||
|
||||
// Update client's signer
|
||||
client.set_signer(Some(signer)).await;
|
||||
|
||||
// Update user
|
||||
user = Some(public_key);
|
||||
|
||||
// Get contact list
|
||||
contact_list = Some(
|
||||
client
|
||||
@@ -113,6 +119,7 @@ fn main() {
|
||||
// Init global state
|
||||
handle.manage(Nostr {
|
||||
client: client.into(),
|
||||
client_user: user.into(),
|
||||
contact_list: contact_list.into(),
|
||||
})
|
||||
});
|
||||
@@ -152,9 +159,6 @@ fn main() {
|
||||
nostr::event::repost,
|
||||
nostr::event::upvote,
|
||||
nostr::event::downvote,
|
||||
commands::secret::secure_save,
|
||||
commands::secret::secure_load,
|
||||
commands::secret::secure_remove,
|
||||
commands::folder::show_in_folder,
|
||||
commands::opg::fetch_opg,
|
||||
])
|
||||
|
||||
@@ -8,12 +8,10 @@ pub async fn get_event(id: &str, nostr: State<'_, Nostr>) -> Result<String, ()>
|
||||
let client = &nostr.client;
|
||||
let event_id;
|
||||
|
||||
if id.starts_with("note1") {
|
||||
event_id = EventId::from_bech32(id).unwrap();
|
||||
} else if id.starts_with("nevent1") {
|
||||
event_id = EventId::from_bech32(id).unwrap();
|
||||
} else if id.starts_with("naddr1") {
|
||||
if id.starts_with("note") {
|
||||
event_id = EventId::from_bech32(id).unwrap();
|
||||
} else if id.starts_with("nevent") {
|
||||
event_id = Nip19Event::from_bech32(id).unwrap().event_id;
|
||||
} else {
|
||||
event_id = EventId::from_hex(id).unwrap();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ pub fn create_keys() -> Result<CreateKeysResponse, ()> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn save_key(nsec: &str, app_handle: tauri::AppHandle) -> Result<(), ()> {
|
||||
pub fn save_key(nsec: &str, app_handle: tauri::AppHandle) -> Result<bool, bool> {
|
||||
if let Ok(nostr_secret_key) = SecretKey::from_bech32(nsec) {
|
||||
let nostr_keys = Keys::new(nostr_secret_key);
|
||||
let nostr_npub = nostr_keys.public_key().to_bech32().unwrap();
|
||||
@@ -50,9 +50,9 @@ pub fn save_key(nsec: &str, app_handle: tauri::AppHandle) -> Result<(), ()> {
|
||||
.expect("Write nsec failed");
|
||||
writer.finish().expect("Save nsec failed");
|
||||
|
||||
Ok(())
|
||||
Ok(true)
|
||||
} else {
|
||||
Err(())
|
||||
Err(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,11 +76,19 @@ pub async fn update_signer(nsec: &str, nostr: State<'_, Nostr>) -> Result<(), ()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn verify_signer(nostr: State<'_, Nostr>) -> Result<bool, ()> {
|
||||
pub async fn verify_signer(nostr: State<'_, Nostr>) -> Result<String, ()> {
|
||||
let client = &nostr.client;
|
||||
let status = client.signer().await.is_ok();
|
||||
let user = &nostr.client_user;
|
||||
|
||||
Ok(status)
|
||||
if let Ok(_) = client.signer().await {
|
||||
if let Some(public_key) = user {
|
||||
Ok(public_key.to_string())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
Reference in New Issue
Block a user