mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-08 22:55:54 +01:00
refactor: is_p2pk
This commit is contained in:
@@ -309,11 +309,12 @@ impl TryFrom<Secret> 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;
|
||||
|
||||
@@ -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<crate::nuts::nut10::Secret, serde_json::Error> =
|
||||
serde_json::from_str(&self.0);
|
||||
|
||||
if let Ok(secret) = secret {
|
||||
if secret.kind.eq(&Kind::P2PK) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Secret {
|
||||
|
||||
Reference in New Issue
Block a user