From 9a450f2ce740da08843a541d230c43194b934f5f Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 22 Mar 2024 15:51:36 +0000 Subject: replace XOnlyPublicKey with wrapper PublicKey to reflect new name in rust-nostr --- src/config.rs | 6 +++--- src/key_handling/users.rs | 12 ++++++------ src/repo_ref.rs | 14 +++++++------- src/sub_commands/init.rs | 10 +++++----- 4 files changed, 21 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 2370e34..7fca446 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,7 @@ use anyhow::{anyhow, Context, Result}; use directories::ProjectDirs; #[cfg(test)] use mockall::*; -use nostr::{secp256k1::XOnlyPublicKey, ToBech32}; +use nostr::{PublicKey, ToBech32}; use serde::{self, Deserialize, Serialize}; #[derive(Default)] @@ -69,7 +69,7 @@ pub struct MyConfig { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct UserRef { - pub public_key: XOnlyPublicKey, + pub public_key: PublicKey, pub encrypted_key: String, pub metadata: UserMetadata, pub relays: UserRelays, @@ -77,7 +77,7 @@ pub struct UserRef { } impl UserRef { - pub fn new(public_key: XOnlyPublicKey, encrypted_key: String) -> Self { + pub fn new(public_key: PublicKey, encrypted_key: String) -> Self { Self { public_key, encrypted_key, diff --git a/src/key_handling/users.rs b/src/key_handling/users.rs index c061cd3..751c577 100644 --- a/src/key_handling/users.rs +++ b/src/key_handling/users.rs @@ -32,13 +32,13 @@ pub trait UserManagement { &self, #[cfg(test)] client: &MockConnect, #[cfg(not(test))] client: &Client, - public_key: &XOnlyPublicKey, + public_key: &PublicKey, after: u64, ) -> Result; - fn get_user_from_cache(&self, public_key: &XOnlyPublicKey) -> Result; + fn get_user_from_cache(&self, public_key: &PublicKey) -> Result; fn add_user_to_config( &self, - public_key: XOnlyPublicKey, + public_key: PublicKey, encrypted_secret_key: Option, overwrite: bool, ) -> Result<()>; @@ -99,7 +99,7 @@ impl UserManagement for UserManager { fn add_user_to_config( &self, - public_key: XOnlyPublicKey, + public_key: PublicKey, encrypted_secret_key: Option, overwrite: bool, ) -> Result<()> { @@ -129,7 +129,7 @@ impl UserManagement for UserManager { .context("failed to save application configuration with new user details in") } - fn get_user_from_cache(&self, public_key: &XOnlyPublicKey) -> Result { + fn get_user_from_cache(&self, public_key: &PublicKey) -> Result { let cfg = self .config_manager .load() @@ -148,7 +148,7 @@ impl UserManagement for UserManager { &self, #[cfg(test)] client: &MockConnect, #[cfg(not(test))] client: &Client, - public_key: &XOnlyPublicKey, + public_key: &PublicKey, use_cache_unless_checked_more_than_x_secs_ago: u64, ) -> Result { let cfg = self diff --git a/src/repo_ref.rs b/src/repo_ref.rs index c7b42fa..0a14005 100644 --- a/src/repo_ref.rs +++ b/src/repo_ref.rs @@ -1,7 +1,7 @@ use std::{fs::File, io::BufReader, str::FromStr}; use anyhow::{bail, Context, Result}; -use nostr::{nips::nip19::Nip19, secp256k1::XOnlyPublicKey, FromBech32, Tag, ToBech32}; +use nostr::{nips::nip19::Nip19, FromBech32, PublicKey, Tag, ToBech32}; use serde::{Deserialize, Serialize}; #[cfg(not(test))] @@ -23,7 +23,7 @@ pub struct RepoRef { pub git_server: String, pub web: Vec, pub relays: Vec, - pub maintainers: Vec, + pub maintainers: Vec, // code languages and hashtags } @@ -78,7 +78,7 @@ impl TryFrom for RepoRef { } for pk in maintainers { r.maintainers.push( - nostr_sdk::prelude::XOnlyPublicKey::from_str(&pk) + nostr_sdk::prelude::PublicKey::from_str(&pk) .context(format!("cannot convert entry from maintainers tag {pk} into a valid nostr public key. it should be in hex format")) .context("invalid repository event")?, ); @@ -246,11 +246,11 @@ pub fn get_repo_config_from_yaml(git_repo: &Repo) -> Result { Ok(repo_config_yaml) } -pub fn extract_pks(pk_strings: Vec) -> Result> { - let mut pks: Vec = vec![]; +pub fn extract_pks(pk_strings: Vec) -> Result> { + let mut pks: Vec = vec![]; for s in pk_strings { pks.push( - nostr_sdk::prelude::XOnlyPublicKey::from_bech32(s.clone()) + nostr_sdk::prelude::PublicKey::from_bech32(s.clone()) .context(format!("cannot convert {s} into a valid nostr public key"))?, ); } @@ -259,7 +259,7 @@ pub fn extract_pks(pk_strings: Vec) -> Result> { pub fn save_repo_config_to_yaml( git_repo: &Repo, - maintainers: Vec, + maintainers: Vec, relays: Vec, ) -> Result<()> { let path = git_repo.get_path()?.join("maintainers.yaml"); diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index 4f098c0..56129a6 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs @@ -1,5 +1,5 @@ use anyhow::{Context, Result}; -use nostr::{secp256k1::XOnlyPublicKey, FromBech32, ToBech32}; +use nostr::{FromBech32, PublicKey, ToBech32}; use super::send::send_events; #[cfg(not(test))] @@ -163,7 +163,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { args.web.clone() }; - let maintainers: Vec = { + let maintainers: Vec = { let mut dont_ask = !args.other_maintainers.is_empty(); let mut maintainers_string = if !args.other_maintainers.is_empty() { [args.other_maintainers.clone()].concat().join(" ") @@ -185,7 +185,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { }; // add current user if not present if maintainers.iter().any(|m| { - if let Ok(m_pubkey) = XOnlyPublicKey::from_bech32(m) { + if let Ok(m_pubkey) = PublicKey::from_bech32(m) { user_ref.public_key.eq(&m_pubkey) } else { false @@ -210,9 +210,9 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { .map(std::string::ToString::to_string) .collect(); } - let mut maintainers: Vec = vec![]; + let mut maintainers: Vec = vec![]; for m in maintainers_string.split(' ') { - if let Ok(m_pubkey) = XOnlyPublicKey::from_bech32(m) { + if let Ok(m_pubkey) = PublicKey::from_bech32(m) { maintainers.push(m_pubkey); } else { println!("not a valid set of npubs seperated by a space"); -- cgit v1.2.3