diff --git a/crates/cashu/src/nuts/nut11.rs b/crates/cashu/src/nuts/nut11.rs index 035534be..c2f03705 100644 --- a/crates/cashu/src/nuts/nut11.rs +++ b/crates/cashu/src/nuts/nut11.rs @@ -309,11 +309,12 @@ impl TryFrom for P2PKConditions { impl Proof { pub fn verify_p2pk(&self) -> Result<(), Error> { - let secret: Secret = (&self.secret).try_into()?; - if secret.kind.ne(&super::nut10::Kind::P2PK) { + if !self.secret.is_p2pk() { return Err(Error::IncorrectSecretKind); } + let secret: Secret = self.secret.clone().try_into()?; + let spending_conditions: P2PKConditions = secret.clone().try_into()?; let mut valid_sigs = 0; diff --git a/crates/cashu/src/secret.rs b/crates/cashu/src/secret.rs index 23aae53c..bf526226 100644 --- a/crates/cashu/src/secret.rs +++ b/crates/cashu/src/secret.rs @@ -73,6 +73,22 @@ impl Secret { Err(_) => Ok(hex::decode(&self.0)?), } } + + #[cfg(feature = "nut11")] + pub fn is_p2pk(&self) -> bool { + use crate::nuts::Kind; + + let secret: Result = + serde_json::from_str(&self.0); + + if let Ok(secret) = secret { + if secret.kind.eq(&Kind::P2PK) { + return true; + } + } + + false + } } impl FromStr for Secret {