upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/sub_commands/send.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-06-25 09:06:47 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-06-25 09:06:47 +0100
commitb63bfc9a34657c5767c507deb7c059e24dd22779 (patch)
tree462be1e29e6f21c5e0d75458e4966f574389451c /src/sub_commands/send.rs
parent20d201740f0ace8437cf595476a52f9e42407724 (diff)
refactor: replace keys with signer
so that nip46 bunker signing can be added
Diffstat (limited to 'src/sub_commands/send.rs')
-rw-r--r--src/sub_commands/send.rs32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs
index 8971d8b..1d20e90 100644
--- a/src/sub_commands/send.rs
+++ b/src/sub_commands/send.rs
@@ -8,7 +8,7 @@ use nostr::{
8 nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}, 8 nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19},
9 EventBuilder, FromBech32, Tag, TagKind, ToBech32, UncheckedUrl, 9 EventBuilder, FromBech32, Tag, TagKind, ToBech32, UncheckedUrl,
10}; 10};
11use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, TagStandard}; 11use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, NostrSigner, TagStandard};
12 12
13use super::list::tag_value; 13use super::list::tag_value;
14#[cfg(not(test))] 14#[cfg(not(test))]
@@ -178,7 +178,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
178 } else { 178 } else {
179 None 179 None
180 }; 180 };
181 let (keys, user_ref) = login::launch( 181 let (signer, user_ref) = login::launch(
182 &git_repo, 182 &git_repo,
183 &cli_args.nsec, 183 &cli_args.nsec,
184 &cli_args.password, 184 &cli_args.password,
@@ -187,7 +187,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
187 ) 187 )
188 .await?; 188 .await?;
189 189
190 client.set_keys(&keys).await; 190 client.set_signer(signer.clone()).await;
191 191
192 let repo_ref = repo_ref::fetch( 192 let repo_ref = repo_ref::fetch(
193 &git_repo, 193 &git_repo,
@@ -208,11 +208,12 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
208 cover_letter_title_description.clone(), 208 cover_letter_title_description.clone(),
209 &git_repo, 209 &git_repo,
210 &commits, 210 &commits,
211 &keys, 211 &signer,
212 &repo_ref, 212 &repo_ref,
213 &root_proposal_id, 213 &root_proposal_id,
214 &mention_tags, 214 &mention_tags,
215 )?; 215 )
216 .await?;
216 217
217 println!( 218 println!(
218 "posting {} patch{} {} a covering letter...", 219 "posting {} patch{} {} a covering letter...",
@@ -576,11 +577,11 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to(
576pub static PATCH_KIND: u16 = 1617; 577pub static PATCH_KIND: u16 = 1617;
577 578
578#[allow(clippy::too_many_lines)] 579#[allow(clippy::too_many_lines)]
579pub fn generate_cover_letter_and_patch_events( 580pub async fn generate_cover_letter_and_patch_events(
580 cover_letter_title_description: Option<(String, String)>, 581 cover_letter_title_description: Option<(String, String)>,
581 git_repo: &Repo, 582 git_repo: &Repo,
582 commits: &[Sha1Hash], 583 commits: &[Sha1Hash],
583 keys: &nostr::Keys, 584 signer: &NostrSigner,
584 repo_ref: &RepoRef, 585 repo_ref: &RepoRef,
585 root_proposal_id: &Option<String>, 586 root_proposal_id: &Option<String>,
586 mentions: &[nostr::Tag], 587 mentions: &[nostr::Tag],
@@ -592,7 +593,7 @@ pub fn generate_cover_letter_and_patch_events(
592 let mut events = vec![]; 593 let mut events = vec![];
593 594
594 if let Some((title, description)) = cover_letter_title_description { 595 if let Some((title, description)) = cover_letter_title_description {
595 events.push(EventBuilder::new( 596 events.push(signer.sign_event_builder(EventBuilder::new(
596 nostr::event::Kind::Custom(PATCH_KIND), 597 nostr::event::Kind::Custom(PATCH_KIND),
597 format!( 598 format!(
598 "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}", 599 "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}",
@@ -655,8 +656,7 @@ pub fn generate_cover_letter_and_patch_events(
655 .map(|pk| Tag::public_key(*pk)) 656 .map(|pk| Tag::public_key(*pk))
656 .collect(), 657 .collect(),
657 ].concat(), 658 ].concat(),
658 ) 659 )).await
659 .to_event(keys)
660 .context("failed to create cover-letter event")?); 660 .context("failed to create cover-letter event")?);
661 } 661 }
662 662
@@ -667,7 +667,7 @@ pub fn generate_cover_letter_and_patch_events(
667 &root_commit, 667 &root_commit,
668 commit, 668 commit,
669 events.first().map(|event| event.id), 669 events.first().map(|event| event.id),
670 keys, 670 signer,
671 repo_ref, 671 repo_ref,
672 events.last().map(nostr::Event::id), 672 events.last().map(nostr::Event::id),
673 if events.is_empty() { 673 if events.is_empty() {
@@ -695,6 +695,7 @@ pub fn generate_cover_letter_and_patch_events(
695 root_proposal_id, 695 root_proposal_id,
696 if events.is_empty() { mentions } else { &[] }, 696 if events.is_empty() { mentions } else { &[] },
697 ) 697 )
698 .await
698 .context("failed to generate patch event")?, 699 .context("failed to generate patch event")?,
699 ); 700 );
700 } 701 }
@@ -864,12 +865,12 @@ pub fn patch_supports_commit_ids(event: &nostr::Event) -> bool {
864 865
865#[allow(clippy::too_many_arguments)] 866#[allow(clippy::too_many_arguments)]
866#[allow(clippy::too_many_lines)] 867#[allow(clippy::too_many_lines)]
867pub fn generate_patch_event( 868pub async fn generate_patch_event(
868 git_repo: &Repo, 869 git_repo: &Repo,
869 root_commit: &Sha1Hash, 870 root_commit: &Sha1Hash,
870 commit: &Sha1Hash, 871 commit: &Sha1Hash,
871 thread_event_id: Option<nostr::EventId>, 872 thread_event_id: Option<nostr::EventId>,
872 keys: &nostr::Keys, 873 signer: &nostr_sdk::NostrSigner,
873 repo_ref: &RepoRef, 874 repo_ref: &RepoRef,
874 parent_patch_event_id: Option<nostr::EventId>, 875 parent_patch_event_id: Option<nostr::EventId>,
875 series_count: Option<(u64, u64)>, 876 series_count: Option<(u64, u64)>,
@@ -882,7 +883,7 @@ pub fn generate_patch_event(
882 .context("failed to get parent commit")?; 883 .context("failed to get parent commit")?;
883 let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from); 884 let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from);
884 885
885 EventBuilder::new( 886 signer.sign_event_builder(EventBuilder::new(
886 nostr::event::Kind::Custom(PATCH_KIND), 887 nostr::event::Kind::Custom(PATCH_KIND),
887 git_repo 888 git_repo
888 .make_patch_from_commit(commit,&series_count) 889 .make_patch_from_commit(commit,&series_count)
@@ -999,8 +1000,7 @@ pub fn generate_patch_event(
999 ], 1000 ],
1000 ] 1001 ]
1001 .concat(), 1002 .concat(),
1002 ) 1003 )).await
1003 .to_event(keys)
1004 .context("failed to sign event") 1004 .context("failed to sign event")
1005} 1005}
1006// TODO 1006// TODO