feat: add rust nostr
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
)]
|
||||
|
||||
pub mod commands;
|
||||
pub mod nostr;
|
||||
|
||||
use tauri_plugin_autostart::MacosLauncher;
|
||||
use tauri_plugin_sql::{Migration, MigrationKind};
|
||||
@@ -48,6 +49,8 @@ fn main() {
|
||||
Some(vec![]),
|
||||
))
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
nostr::keys::create_keys,
|
||||
nostr::keys::get_public_key,
|
||||
commands::secret::secure_save,
|
||||
commands::secret::secure_load,
|
||||
commands::secret::secure_remove,
|
||||
|
||||
1
src-tauri/src/nostr.rs
Normal file
1
src-tauri/src/nostr.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod keys;
|
||||
29
src-tauri/src/nostr/keys.rs
Normal file
29
src-tauri/src/nostr/keys.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use nostr::nips::nip19::ToBech32;
|
||||
use nostr::secp256k1::SecretKey;
|
||||
use nostr::{Keys, Result};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct CreateKeysResponse {
|
||||
npub: String,
|
||||
nsec: String,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn create_keys() -> Result<CreateKeysResponse, ()> {
|
||||
let keys = Keys::generate();
|
||||
let public_key = keys.public_key();
|
||||
let secret_key = keys.secret_key().expect("secret key failed");
|
||||
|
||||
let result = CreateKeysResponse {
|
||||
npub: public_key.to_bech32().expect("npub failed"),
|
||||
nsec: secret_key.to_bech32().expect("nsec failed"),
|
||||
};
|
||||
|
||||
Ok(result.into())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_public_key(secret_key: SecretKey) -> Result<String, ()> {
|
||||
let keys = Keys::new(secret_key);
|
||||
Ok(keys.public_key().to_bech32().expect("secret key failed"))
|
||||
}
|
||||
Reference in New Issue
Block a user