From 69bdb18ddabd21ecbf8adc122a624959251d0f94 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Mon, 18 Dec 2023 23:21:58 +0000 Subject: [PATCH] refactor: skip serialization of feilds other then secret This avoids wallet fingerprinting by only sending the secret when checking if a proof is spent as recommnded in the nut. --- crates/cashu-sdk/src/mint.rs | 2 +- crates/cashu-sdk/src/wallet.rs | 2 +- crates/cashu/src/error.rs | 2 ++ crates/cashu/src/nuts/nut00.rs | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/cashu-sdk/src/mint.rs b/crates/cashu-sdk/src/mint.rs index ede40f314..a6b7c9de1 100644 --- a/crates/cashu-sdk/src/mint.rs +++ b/crates/cashu-sdk/src/mint.rs @@ -308,7 +308,7 @@ impl Mint { Ok(MeltBolt11Response { paid: true, - proof: preimage.to_string(), + payment_preimage: Some(preimage.to_string()), change, }) } diff --git a/crates/cashu-sdk/src/wallet.rs b/crates/cashu-sdk/src/wallet.rs index fa1ca0c66..adc38390b 100644 --- a/crates/cashu-sdk/src/wallet.rs +++ b/crates/cashu-sdk/src/wallet.rs @@ -300,7 +300,7 @@ impl Wallet { let melted = Melted { paid: true, - preimage: Some(melt_response.proof), + preimage: melt_response.payment_preimage, change: change_proofs, }; diff --git a/crates/cashu/src/error.rs b/crates/cashu/src/error.rs index 91daca22d..b9df9ed85 100644 --- a/crates/cashu/src/error.rs +++ b/crates/cashu/src/error.rs @@ -33,6 +33,8 @@ pub enum Error { TokenNotVerifed, #[error("Invoice Amount undefined")] InvoiceAmountUndefined, + #[error("Proof missing required field")] + MissingProofField, } #[cfg(feature = "wallet")] diff --git a/crates/cashu/src/nuts/nut00.rs b/crates/cashu/src/nuts/nut00.rs index e1df11f0f..611e012e5 100644 --- a/crates/cashu/src/nuts/nut00.rs +++ b/crates/cashu/src/nuts/nut00.rs @@ -389,6 +389,19 @@ impl From for mint::Proof { } } +impl TryFrom for Proof { + type Error = Error; + + fn try_from(mint_proof: mint::Proof) -> Result { + Ok(Self { + id: mint_proof.id.ok_or(Error::MissingProofField)?, + amount: mint_proof.amount.ok_or(Error::MissingProofField)?, + secret: mint_proof.secret, + c: mint_proof.c.ok_or(Error::MissingProofField)?, + }) + } +} + pub mod mint { use serde::{Deserialize, Serialize}; @@ -401,13 +414,16 @@ pub mod mint { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Proof { /// Amount in satoshi + #[serde(skip_serializing)] pub amount: Option, /// Secret message + #[serde(skip_serializing)] pub secret: Secret, /// Unblinded signature #[serde(rename = "C")] pub c: Option, /// `Keyset id` + #[serde(skip_serializing)] pub id: Option, }