diff --git a/crates/cashu/src/nuts/mod.rs b/crates/cashu/src/nuts/mod.rs index c267807f..0d7224d7 100644 --- a/crates/cashu/src/nuts/mod.rs +++ b/crates/cashu/src/nuts/mod.rs @@ -16,9 +16,7 @@ pub mod nut11; #[cfg(feature = "wallet")] pub use nut00::wallet::{PreMint, PreMintSecrets, Token}; -#[cfg(not(feature = "nut11"))] -pub use nut00::Proof; -pub use nut00::{BlindedMessage, BlindedSignature, CurrencyUnit, PaymentMethod}; +pub use nut00::{BlindedMessage, BlindedSignature, CurrencyUnit, PaymentMethod, Proof}; pub use nut01::{Keys, KeysResponse, PublicKey, SecretKey}; pub use nut02::mint::KeySet as MintKeySet; pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse}; @@ -40,6 +38,6 @@ pub use nut08::{MeltBolt11Request, MeltBolt11Response}; #[cfg(feature = "nut10")] pub use nut10::{Kind, Secret as Nut10Secret, SecretData}; #[cfg(feature = "nut11")] -pub use nut11::{P2PKConditions, Proof, SigFlag, Signatures, SigningKey, VerifyingKey}; +pub use nut11::{P2PKConditions, SigFlag, Signatures, SigningKey, VerifyingKey}; pub type Proofs = Vec; diff --git a/crates/cashu/src/nuts/nut00.rs b/crates/cashu/src/nuts/nut00.rs index 99ca7c8e..f1dd5826 100644 --- a/crates/cashu/src/nuts/nut00.rs +++ b/crates/cashu/src/nuts/nut00.rs @@ -471,6 +471,13 @@ pub struct Proof { /// Unblinded signature #[serde(rename = "C")] pub c: PublicKey, + #[cfg(feature = "nut11")] + /// Witness + #[serde(default)] + #[serde(skip_serializing_if = "Signatures::is_empty")] + #[serde(serialize_with = "witness_serialize")] + #[serde(deserialize_with = "witness_deserialize")] + pub witness: Signatures, } impl Proof { @@ -480,6 +487,8 @@ impl Proof { keyset_id, secret, c, + #[cfg(feature = "nut11")] + witness: Signatures::default(), } } } diff --git a/crates/cashu/src/nuts/nut11.rs b/crates/cashu/src/nuts/nut11.rs index 1d221eec..d6891407 100644 --- a/crates/cashu/src/nuts/nut11.rs +++ b/crates/cashu/src/nuts/nut11.rs @@ -3,7 +3,6 @@ use std::collections::HashMap; use std::fmt; -use std::hash::{self, Hasher}; use std::str::FromStr; use k256::schnorr::signature::{Signer, Verifier}; @@ -14,13 +13,11 @@ use serde::ser::SerializeSeq; use serde::{de, ser, Deserialize, Deserializer, Serialize, Serializer}; use super::nut01::PublicKey; -use super::nut02::Id; use super::nut10::{Secret, SecretData}; -use super::SecretKey; +use super::{Proof, SecretKey}; use crate::error::Error; use crate::nuts::nut00::BlindedMessage; use crate::utils::unix_time; -use crate::Amount; #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Signatures { @@ -35,27 +32,6 @@ impl Signatures { } } -/// Proofs [NUT-11] -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct Proof { - /// Amount in satoshi - pub amount: Amount, - /// NUT-10 Secret - pub secret: crate::secret::Secret, - /// Unblinded signature - #[serde(rename = "C")] - pub c: PublicKey, - /// `Keyset id` - #[serde(rename = "id")] - pub keyset_id: Id, - /// Witness - #[serde(default)] - #[serde(skip_serializing_if = "Signatures::is_empty")] - #[serde(serialize_with = "witness_serialize")] - #[serde(deserialize_with = "witness_deserialize")] - pub witness: Signatures, -} - pub fn witness_serialize(x: &Signatures, s: S) -> Result where S: Serializer, @@ -72,16 +48,6 @@ where } impl Proof { - pub fn new(amount: Amount, keyset_id: Id, secret: crate::secret::Secret, c: PublicKey) -> Self { - Proof { - amount, - keyset_id, - secret, - c, - witness: Signatures::default(), - } - } - pub fn verify_p2pk(&self) -> Result<(), Error> { if !self.secret.is_p2pk() { return Err(Error::IncorrectSecretKind); @@ -153,24 +119,6 @@ impl Proof { } } -impl hash::Hash for Proof { - fn hash(&self, state: &mut H) { - self.secret.hash(state); - } -} - -impl Ord for Proof { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.amount.cmp(&other.amount) - } -} - -impl PartialOrd for Proof { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - impl BlindedMessage { pub fn sign_p2pk(&mut self, secret_key: SigningKey) -> Result<(), Error> { let msg_to_sign = hex::decode(self.b.to_string())?; @@ -725,6 +673,8 @@ mod tests { use std::str::FromStr; use super::*; + use crate::nuts::Id; + use crate::Amount; #[test] fn test_secret_ser() {