diff --git a/crates/cashu-sdk/src/client/minreq_client.rs b/crates/cashu-sdk/src/client/minreq_client.rs index 1dd08881..154e3e85 100644 --- a/crates/cashu-sdk/src/client/minreq_client.rs +++ b/crates/cashu-sdk/src/client/minreq_client.rs @@ -172,15 +172,11 @@ impl Client for HttpClient { ) -> Result { let url = join_url(mint_url, &["v1", "swap"])?; - println!("{}", serde_json::to_string(&swap_request).unwrap()); - let res = minreq::post(url).with_json(&swap_request)?.send()?; let value = res.json::()?; - println!("{}", value); let response: Result = serde_json::from_value(value.clone()); - println!("{:?}", response); match response { Ok(res) => Ok(res), diff --git a/crates/cashu-sdk/src/wallet/mod.rs b/crates/cashu-sdk/src/wallet/mod.rs index d9d527d4..99b4602e 100644 --- a/crates/cashu-sdk/src/wallet/mod.rs +++ b/crates/cashu-sdk/src/wallet/mod.rs @@ -234,7 +234,6 @@ impl Wallet { } let keysets = self.client.get_mint_keysets(mint_url.try_into()?).await?; - println!("{:?}", keysets); self.localstore .add_mint_keysets( @@ -385,16 +384,12 @@ impl Wallet { pre_swap.pre_mint_secrets.secrets(), &keys, )?; - // println!("{:?}", p); let mint_proofs = proofs.entry(token.mint).or_default(); mint_proofs.extend(p); } - //println!("{:?}", proofs); for (mint, p) in proofs { - println!("{:?}", serde_json::to_string(&p)); - println!("{:?}", mint); self.add_mint(mint.clone()).await?; self.localstore.add_proofs(mint, p).await?; } @@ -780,7 +775,6 @@ impl Wallet { let mut change_proofs = vec![]; for proof in post_swap_proofs { - println!("post swap proof: {:?}", proof); let conditions: Result = (&proof.secret).try_into(); if conditions.is_ok() { send_proofs.push(proof); @@ -849,14 +843,12 @@ impl Wallet { { let conditions: Result = secret.try_into(); if let Ok(conditions) = conditions { - println!("{:?}", conditions); let pubkeys = conditions.pubkeys; for pubkey in pubkeys { if let Some(signing) = pubkey_secret_key.get(&pubkey.to_string()) { proof.sign_p2pk_proof(signing.clone()).unwrap(); proof.verify_p2pk().unwrap(); - println!("v"); } } diff --git a/crates/cashu/src/nuts/mod.rs b/crates/cashu/src/nuts/mod.rs index c267807f..dc64c368 100644 --- a/crates/cashu/src/nuts/mod.rs +++ b/crates/cashu/src/nuts/mod.rs @@ -17,8 +17,8 @@ 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, Proof}; +pub use nut00::{BlindedSignature, CurrencyUnit, PaymentMethod}; pub use nut01::{Keys, KeysResponse, PublicKey, SecretKey}; pub use nut02::mint::KeySet as MintKeySet; pub use nut02::{Id, KeySet, KeySetInfo, KeysetResponse}; @@ -40,6 +40,8 @@ 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::{ + BlindedMessage, P2PKConditions, Proof, 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 a03e9359..2e250917 100644 --- a/crates/cashu/src/nuts/nut00.rs +++ b/crates/cashu/src/nuts/nut00.rs @@ -8,11 +8,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; 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; use crate::Amount; @@ -28,13 +24,6 @@ pub struct BlindedMessage { /// encrypted secret message (B_) #[serde(rename = "B_")] pub b: PublicKey, - /// Witness - #[cfg(feature = "nut11")] - #[serde(default)] - #[serde(skip_serializing_if = "Signatures::is_empty")] - #[serde(serialize_with = "witness_serialize")] - #[serde(deserialize_with = "witness_deserialize")] - pub witness: Signatures, } impl BlindedMessage { @@ -43,24 +32,8 @@ 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())?; - - println!("{:?}", msg_to_sign); - - let signature = secret_key.sign(&msg_to_sign); - - self.witness - .signatures - .push(hex::encode(signature.to_bytes())); - Ok(()) - } } #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, hash::Hash)] diff --git a/crates/cashu/src/nuts/nut11.rs b/crates/cashu/src/nuts/nut11.rs index 22a40c21..3c9b8e94 100644 --- a/crates/cashu/src/nuts/nut11.rs +++ b/crates/cashu/src/nuts/nut11.rs @@ -99,6 +99,48 @@ impl PartialOrd for Proof { } } +/// Blinded Message [NUT-00] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct BlindedMessage { + /// Amount + pub amount: Amount, + /// Keyset Id + #[serde(rename = "id")] + pub keyset_id: Id, + /// encrypted secret message (B_) + #[serde(rename = "B_")] + pub b: PublicKey, + /// Witness + #[serde(default)] + #[serde(skip_serializing_if = "Signatures::is_empty")] + #[serde(serialize_with = "witness_serialize")] + #[serde(deserialize_with = "witness_deserialize")] + pub witness: Signatures, +} + +impl BlindedMessage { + pub fn new(amount: Amount, keyset_id: Id, b: PublicKey) -> Self { + Self { + amount, + keyset_id, + b, + 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())?; + + let signature = secret_key.sign(&msg_to_sign); + + self.witness + .signatures + .push(hex::encode(signature.to_bytes())); + Ok(()) + } +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct P2PKConditions { #[serde(skip_serializing_if = "Option::is_none")] @@ -277,12 +319,6 @@ impl Proof { let mut valid_sigs = 0; - println!("{:?}", self.secret.to_string()); - println!( - "sec bytes: {:?}", - self.secret.to_string().into_bytes().len() - ); - let msg = &self.secret.to_bytes().unwrap(); for signature in &self.witness.signatures { @@ -301,7 +337,6 @@ impl Proof { } if valid_sigs.ge(&spending_conditions.num_sigs.unwrap_or(1)) { - println!("valid sigs: {}", valid_sigs); return Ok(()); } diff --git a/crates/cashu/src/secret.rs b/crates/cashu/src/secret.rs index a7ee15ec..23aae53c 100644 --- a/crates/cashu/src/secret.rs +++ b/crates/cashu/src/secret.rs @@ -69,7 +69,7 @@ impl Secret { serde_json::from_str(&self.0); match secret { - Ok(_) => Ok(self.0.clone().replace('\\', "").into_bytes()), + Ok(_) => Ok(self.0.clone().into_bytes()), Err(_) => Ok(hex::decode(&self.0)?), } }