diff --git a/CHANGELOG.md b/CHANGELOG.md index 18432ae71..50024760e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ * nostr: update `FromBech32::from_bech32` method signature ([Yuki Kishimoto]) * nostr: update `NostrURI::from_nostr_uri` method signature ([Yuki Kishimoto]) +* nostr: remove generics from parsing methods in `key` module ([Yuki Kishimoto]) ### Changed diff --git a/crates/nostr-cli/src/cli/io.rs b/crates/nostr-cli/src/cli/io.rs index fc26331d7..1a2d1919b 100644 --- a/crates/nostr-cli/src/cli/io.rs +++ b/crates/nostr-cli/src/cli/io.rs @@ -27,7 +27,7 @@ where S: Into, { let secret_key = Password::new().with_prompt(prompt).interact()?; - Ok(Keys::parse(secret_key)?) + Ok(Keys::parse(&secret_key)?) } /* pub fn get_password_with_confirmation() -> Result { diff --git a/crates/nostr/src/event/raw.rs b/crates/nostr/src/event/raw.rs index a1f3f50d1..67a308fb2 100644 --- a/crates/nostr/src/event/raw.rs +++ b/crates/nostr/src/event/raw.rs @@ -95,7 +95,7 @@ impl TryFrom for Event { fn try_from(raw: RawEvent) -> Result { let id: EventId = EventId::from_hex(raw.id)?; - let public_key: PublicKey = PublicKey::from_hex(raw.pubkey)?; + let public_key: PublicKey = PublicKey::from_hex(&raw.pubkey)?; let created_at: Timestamp = Timestamp::from(raw.created_at); let kind: Kind = Kind::from(raw.kind); let tags: Vec = raw diff --git a/crates/nostr/src/key/mod.rs b/crates/nostr/src/key/mod.rs index d6c3319a6..8ab697b52 100644 --- a/crates/nostr/src/key/mod.rs +++ b/crates/nostr/src/key/mod.rs @@ -141,19 +141,15 @@ impl Keys { /// Parse secret key from `hex` or `bech32` and compose keys #[inline] #[cfg(feature = "std")] - pub fn parse(secret_key: S) -> Result - where - S: AsRef, - { + pub fn parse(secret_key: &str) -> Result { Self::parse_with_ctx(&SECP256K1, secret_key) } /// Parse secret key from `hex` or `bech32` and compose keys #[inline] - pub fn parse_with_ctx(secp: &Secp256k1, secret_key: S) -> Result + pub fn parse_with_ctx(secp: &Secp256k1, secret_key: &str) -> Result where C: Signing, - S: AsRef, { let secret_key: SecretKey = SecretKey::parse(secret_key)?; Ok(Self::new_with_ctx(secp, secret_key)) diff --git a/crates/nostr/src/key/public_key.rs b/crates/nostr/src/key/public_key.rs index d530d60b4..2e685b8b4 100644 --- a/crates/nostr/src/key/public_key.rs +++ b/crates/nostr/src/key/public_key.rs @@ -53,12 +53,7 @@ impl PublicKey { pub const LEN: usize = 32; /// Parse from `hex`, `bech32` or [NIP21](https://github.com/nostr-protocol/nips/blob/master/21.md) uri - pub fn parse(public_key: S) -> Result - where - S: AsRef, - { - let public_key: &str = public_key.as_ref(); - + pub fn parse(public_key: &str) -> Result { // Try from hex if let Ok(public_key) = Self::from_hex(public_key) { return Ok(public_key); @@ -77,7 +72,7 @@ impl PublicKey { Err(Error::InvalidPublicKey) } - /// Parse [PublicKey] from `bytes` + /// Parse from `bytes` #[inline] pub fn from_slice(slice: &[u8]) -> Result { Ok(Self { @@ -85,14 +80,11 @@ impl PublicKey { }) } - /// Parse [PublicKey] from `hex` string + /// Parse from `hex` string #[inline] - pub fn from_hex(hex: S) -> Result - where - S: AsRef, - { + pub fn from_hex(hex: &str) -> Result { Ok(Self { - inner: XOnlyPublicKey::from_str(hex.as_ref())?, + inner: XOnlyPublicKey::from_str(hex)?, }) } @@ -141,7 +133,7 @@ impl<'de> Deserialize<'de> for PublicKey { D: Deserializer<'de>, { let public_key: String = String::deserialize(deserializer)?; - Self::parse(public_key).map_err(serde::de::Error::custom) + Self::parse(&public_key).map_err(serde::de::Error::custom) } } diff --git a/crates/nostr/src/key/secret_key.rs b/crates/nostr/src/key/secret_key.rs index 1845af9f9..1bde26c82 100644 --- a/crates/nostr/src/key/secret_key.rs +++ b/crates/nostr/src/key/secret_key.rs @@ -53,12 +53,7 @@ impl SecretKey { pub const LEN: usize = 32; /// Parse from `hex` or `bech32` - pub fn parse(secret_key: S) -> Result - where - S: AsRef, - { - let secret_key: &str = secret_key.as_ref(); - + pub fn parse(secret_key: &str) -> Result { // Try from hex if let Ok(secret_key) = Self::from_hex(secret_key) { return Ok(secret_key); @@ -82,12 +77,9 @@ impl SecretKey { /// Parse [SecretKey] from `hex` string #[inline] - pub fn from_hex(hex: S) -> Result - where - S: AsRef, - { + pub fn from_hex(hex: &str) -> Result { Ok(Self { - inner: secp256k1::SecretKey::from_str(hex.as_ref())?, + inner: secp256k1::SecretKey::from_str(hex)?, }) } @@ -167,7 +159,7 @@ impl<'de> Deserialize<'de> for SecretKey { D: Deserializer<'de>, { let secret_key: String = String::deserialize(deserializer)?; - Self::parse(secret_key).map_err(serde::de::Error::custom) + Self::parse(&secret_key).map_err(serde::de::Error::custom) } }