From 9462b6262faeebcb256cf04e96e305017dd94abc Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Tue, 27 Feb 2024 22:07:02 +0000 Subject: [PATCH] refactor: nut11 features --- crates/cashu/src/nuts/nut00.rs | 12 ++++++++++-- crates/cashu/src/nuts/nut01.rs | 6 ++++++ crates/cashu/src/secret.rs | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/cashu/src/nuts/nut00.rs b/crates/cashu/src/nuts/nut00.rs index 28b565bf..a03e9359 100644 --- a/crates/cashu/src/nuts/nut00.rs +++ b/crates/cashu/src/nuts/nut00.rs @@ -7,8 +7,11 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; -use super::{Id, Proofs, PublicKey, Signatures, SigningKey}; +use super::{Id, Proofs, PublicKey}; +#[cfg(feature = "nut11")] +use super::{Signatures, SigningKey}; use crate::error::Error; +#[cfg(feature = "nut11")] use crate::nuts::nut11::{witness_deserialize, witness_serialize}; use crate::secret::Secret; use crate::url::UncheckedUrl; @@ -26,6 +29,7 @@ pub struct BlindedMessage { #[serde(rename = "B_")] pub b: PublicKey, /// Witness + #[cfg(feature = "nut11")] #[serde(default)] #[serde(skip_serializing_if = "Signatures::is_empty")] #[serde(serialize_with = "witness_serialize")] @@ -39,10 +43,12 @@ impl BlindedMessage { amount, keyset_id, b, + #[cfg(feature = "nut11")] witness: Signatures::default(), } } + #[cfg(feature = "nut11")] pub fn sign_p2pk_blinded_message(&mut self, secret_key: SigningKey) -> Result<(), Error> { let msg_to_sign = hex::decode(self.b.to_string())?; @@ -131,7 +137,9 @@ pub mod wallet { use super::{CurrencyUnit, MintProofs}; use crate::dhke::blind_message; use crate::error::wallet; - use crate::nuts::{BlindedMessage, Id, P2PKConditions, Proofs, SecretKey}; + #[cfg(feature = "nut11")] + use crate::nuts::P2PKConditions; + use crate::nuts::{BlindedMessage, Id, Proofs, SecretKey}; use crate::secret::Secret; use crate::url::UncheckedUrl; use crate::{error, Amount}; diff --git a/crates/cashu/src/nuts/nut01.rs b/crates/cashu/src/nuts/nut01.rs index aedb48d8..55f42bf7 100644 --- a/crates/cashu/src/nuts/nut01.rs +++ b/crates/cashu/src/nuts/nut01.rs @@ -7,6 +7,7 @@ use std::str::FromStr; use bip32::{DerivationPath, XPrv}; use bip39::Mnemonic; use k256::elliptic_curve::generic_array::GenericArray; +#[cfg(feature = "nut11")] use k256::schnorr::{SigningKey, VerifyingKey}; use serde::{Deserialize, Serialize}; @@ -36,6 +37,7 @@ impl From for PublicKey { } } +#[cfg(feature = "nut11")] impl TryFrom for VerifyingKey { type Error = Error; fn try_from(value: PublicKey) -> Result { @@ -43,6 +45,7 @@ impl TryFrom for VerifyingKey { } } +#[cfg(feature = "nut11")] impl TryFrom<&PublicKey> for VerifyingKey { type Error = Error; fn try_from(value: &PublicKey) -> Result { @@ -58,12 +61,14 @@ impl TryFrom<&PublicKey> for VerifyingKey { } } +#[cfg(feature = "nut11")] impl From for PublicKey { fn from(value: VerifyingKey) -> PublicKey { PublicKey(value.try_into().unwrap()) } } +#[cfg(feature = "nut11")] impl From for PublicKey { fn from(value: super::VerifyingKey) -> PublicKey { let v: VerifyingKey = value.into(); @@ -108,6 +113,7 @@ impl From for SecretKey { } } +#[cfg(feature = "nut11")] impl TryFrom for SigningKey { type Error = Error; fn try_from(value: SecretKey) -> Result { diff --git a/crates/cashu/src/secret.rs b/crates/cashu/src/secret.rs index a8917c53..a7ee15ec 100644 --- a/crates/cashu/src/secret.rs +++ b/crates/cashu/src/secret.rs @@ -103,6 +103,7 @@ impl TryFrom<&Secret> for Vec { } } +#[cfg(feature = "nut10")] impl TryFrom for crate::nuts::nut10::Secret { type Error = serde_json::Error; @@ -111,6 +112,7 @@ impl TryFrom for crate::nuts::nut10::Secret { } } +#[cfg(feature = "nut10")] impl TryFrom<&Secret> for crate::nuts::nut10::Secret { type Error = serde_json::Error;