From a82546b70303000b4fc053a1ee21d3d8c7d6ad66 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 28 Jun 2024 15:16:43 +0100 Subject: feat(login): login with nip46 remote signer and save details in git config --- src/sub_commands/init.rs | 2 ++ src/sub_commands/login.rs | 22 ++++++++++++++++++++-- src/sub_commands/push.rs | 2 ++ src/sub_commands/send.rs | 12 +++++++----- 4 files changed, 31 insertions(+), 7 deletions(-) (limited to 'src/sub_commands') diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index 4afe83c..57785db 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs @@ -61,6 +61,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { let (signer, user_ref) = login::launch( &git_repo, + &cli_args.bunker_uri, + &cli_args.bunker_app_key, &cli_args.nsec, &cli_args.password, Some(&client), diff --git a/src/sub_commands/login.rs b/src/sub_commands/login.rs index e71d431..6f49ba8 100644 --- a/src/sub_commands/login.rs +++ b/src/sub_commands/login.rs @@ -17,7 +17,16 @@ pub struct SubCommandArgs { pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { let git_repo = Repo::discover().context("cannot find a git repository")?; if command_args.offline { - login::launch(&git_repo, &args.nsec, &args.password, None, true).await?; + login::launch( + &git_repo, + &args.bunker_uri, + &args.bunker_app_key, + &args.nsec, + &args.password, + None, + true, + ) + .await?; Ok(()) } else { #[cfg(not(test))] @@ -25,7 +34,16 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { #[cfg(test)] let client = ::default(); - login::launch(&git_repo, &args.nsec, &args.password, Some(&client), true).await?; + login::launch( + &git_repo, + &args.bunker_uri, + &args.bunker_app_key, + &args.nsec, + &args.password, + Some(&client), + true, + ) + .await?; client.disconnect().await?; Ok(()) } diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs index 92c1c18..3c471c0 100644 --- a/src/sub_commands/push.rs +++ b/src/sub_commands/push.rs @@ -150,6 +150,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { let (signer, user_ref) = login::launch( &git_repo, + &cli_args.bunker_uri, + &cli_args.bunker_app_key, &cli_args.nsec, &cli_args.password, Some(&client), diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 1d20e90..7c8f2ee 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs @@ -19,7 +19,7 @@ use crate::{ cli_interactor::{ Interactor, InteractorPrompt, PromptConfirmParms, PromptInputParms, PromptMultiChoiceParms, }, - client::Connect, + client::{sign_event, Connect}, git::{Repo, RepoActions}, login, repo_ref::{self, RepoRef, REPO_REF_KIND}, @@ -180,6 +180,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { }; let (signer, user_ref) = login::launch( &git_repo, + &cli_args.bunker_uri, + &cli_args.bunker_app_key, &cli_args.nsec, &cli_args.password, Some(&client), @@ -593,7 +595,7 @@ pub async fn generate_cover_letter_and_patch_events( let mut events = vec![]; if let Some((title, description)) = cover_letter_title_description { - events.push(signer.sign_event_builder(EventBuilder::new( + events.push(sign_event(EventBuilder::new( nostr::event::Kind::Custom(PATCH_KIND), format!( "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}", @@ -656,7 +658,7 @@ pub async fn generate_cover_letter_and_patch_events( .map(|pk| Tag::public_key(*pk)) .collect(), ].concat(), - )).await + ), signer).await .context("failed to create cover-letter event")?); } @@ -883,7 +885,7 @@ pub async fn generate_patch_event( .context("failed to get parent commit")?; let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from); - signer.sign_event_builder(EventBuilder::new( + sign_event(EventBuilder::new( nostr::event::Kind::Custom(PATCH_KIND), git_repo .make_patch_from_commit(commit,&series_count) @@ -1000,7 +1002,7 @@ pub async fn generate_patch_event( ], ] .concat(), - )).await + ), signer).await .context("failed to sign event") } // TODO -- cgit v1.2.3