Ver código fonte

refactor: nut11 features

thesimplekid 1 ano atrás
pai
commit
9462b6262f

+ 10 - 2
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};

+ 6 - 0
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<k256::PublicKey> for PublicKey {
     }
 }
 
+#[cfg(feature = "nut11")]
 impl TryFrom<PublicKey> for VerifyingKey {
     type Error = Error;
     fn try_from(value: PublicKey) -> Result<VerifyingKey, Self::Error> {
@@ -43,6 +45,7 @@ impl TryFrom<PublicKey> for VerifyingKey {
     }
 }
 
+#[cfg(feature = "nut11")]
 impl TryFrom<&PublicKey> for VerifyingKey {
     type Error = Error;
     fn try_from(value: &PublicKey) -> Result<VerifyingKey, Self::Error> {
@@ -58,12 +61,14 @@ impl TryFrom<&PublicKey> for VerifyingKey {
     }
 }
 
+#[cfg(feature = "nut11")]
 impl From<VerifyingKey> for PublicKey {
     fn from(value: VerifyingKey) -> PublicKey {
         PublicKey(value.try_into().unwrap())
     }
 }
 
+#[cfg(feature = "nut11")]
 impl From<super::VerifyingKey> for PublicKey {
     fn from(value: super::VerifyingKey) -> PublicKey {
         let v: VerifyingKey = value.into();
@@ -108,6 +113,7 @@ impl From<k256::SecretKey> for SecretKey {
     }
 }
 
+#[cfg(feature = "nut11")]
 impl TryFrom<SecretKey> for SigningKey {
     type Error = Error;
     fn try_from(value: SecretKey) -> Result<SigningKey, Self::Error> {

+ 2 - 0
crates/cashu/src/secret.rs

@@ -103,6 +103,7 @@ impl TryFrom<&Secret> for Vec<u8> {
     }
 }
 
+#[cfg(feature = "nut10")]
 impl TryFrom<Secret> for crate::nuts::nut10::Secret {
     type Error = serde_json::Error;
 
@@ -111,6 +112,7 @@ impl TryFrom<Secret> for crate::nuts::nut10::Secret {
     }
 }
 
+#[cfg(feature = "nut10")]
 impl TryFrom<&Secret> for crate::nuts::nut10::Secret {
     type Error = serde_json::Error;