diff options
| -rw-r--r-- | src/bin/ngit/sub_commands/export_keys.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/bin/ngit/sub_commands/export_keys.rs b/src/bin/ngit/sub_commands/export_keys.rs index 4a32a3a..7633bb6 100644 --- a/src/bin/ngit/sub_commands/export_keys.rs +++ b/src/bin/ngit/sub_commands/export_keys.rs | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | use std::str::FromStr; | ||
| 2 | |||
| 1 | use anyhow::{Context, Result}; | 3 | use anyhow::{Context, Result}; |
| 2 | use ngit::{ | 4 | use ngit::{ |
| 3 | cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms}, | 5 | cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms}, |
| @@ -7,6 +9,7 @@ use ngit::{ | |||
| 7 | fresh::generate_qr, | 9 | fresh::generate_qr, |
| 8 | }, | 10 | }, |
| 9 | }; | 11 | }; |
| 12 | use nostr_sdk::ToBech32; | ||
| 10 | 13 | ||
| 11 | use crate::git::Repo; | 14 | use crate::git::Repo; |
| 12 | 15 | ||
| @@ -50,23 +53,45 @@ pub async fn launch() -> Result<()> { | |||
| 50 | SignerInfo::Nsec { | 53 | SignerInfo::Nsec { |
| 51 | nsec, | 54 | nsec, |
| 52 | password: _, | 55 | password: _, |
| 53 | npub: _, | 56 | npub, |
| 54 | } => { | 57 | } => { |
| 55 | match Interactor::default().choice( | 58 | match Interactor::default().choice( |
| 56 | PromptChoiceParms::default() | 59 | PromptChoiceParms::default() |
| 57 | .with_default(0) | 60 | .with_default(0) |
| 58 | .with_prompt(logged_in_msg) | 61 | .with_prompt(logged_in_msg) |
| 59 | .with_choices(vec![ | 62 | .with_choices(vec![ |
| 63 | "print npub".to_string(), | ||
| 64 | "show QR code of npub".to_string(), | ||
| 60 | "print nsec".to_string(), | 65 | "print nsec".to_string(), |
| 61 | "show QR code of nsec".to_string(), | 66 | "show QR code of nsec".to_string(), |
| 62 | "cancel".to_string(), | 67 | "cancel".to_string(), |
| 63 | ]), | 68 | ]), |
| 64 | )? { | 69 | )? { |
| 65 | 0 => { | 70 | 0 => { |
| 66 | println!("{nsec}"); | 71 | let npub = if let Some(npub) = npub { |
| 72 | npub | ||
| 73 | } else { | ||
| 74 | nostr::Keys::from_str(&nsec)?.public_key().to_bech32()? | ||
| 75 | }; | ||
| 76 | println!("{npub}"); | ||
| 67 | return Ok(()); | 77 | return Ok(()); |
| 68 | } | 78 | } |
| 69 | 1 => { | 79 | 1 => { |
| 80 | let npub = if let Some(npub) = npub { | ||
| 81 | npub | ||
| 82 | } else { | ||
| 83 | nostr::Keys::from_str(&nsec)?.public_key().to_bech32()? | ||
| 84 | }; | ||
| 85 | for line in generate_qr(&npub)? { | ||
| 86 | println!("{line}"); | ||
| 87 | } | ||
| 88 | return Ok(()); | ||
| 89 | } | ||
| 90 | 2 => { | ||
| 91 | println!("{nsec}"); | ||
| 92 | return Ok(()); | ||
| 93 | } | ||
| 94 | 3 => { | ||
| 70 | for line in generate_qr(&nsec)? { | 95 | for line in generate_qr(&nsec)? { |
| 71 | println!("{line}"); | 96 | println!("{line}"); |
| 72 | } | 97 | } |