Skip to content

Commit

Permalink
refactor: skip serialization of feilds other then secret
Browse files Browse the repository at this point in the history
This avoids wallet fingerprinting by only sending the secret when
checking if a proof is spent as recommnded in the nut.
  • Loading branch information
thesimplekid committed Dec 18, 2023
1 parent 299d4c9 commit 69bdb18
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/cashu-sdk/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl Mint {

Ok(MeltBolt11Response {
paid: true,
proof: preimage.to_string(),
payment_preimage: Some(preimage.to_string()),
change,
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cashu-sdk/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl<C: Client> Wallet<C> {

let melted = Melted {
paid: true,
preimage: Some(melt_response.proof),
preimage: melt_response.payment_preimage,
change: change_proofs,
};

Expand Down
2 changes: 2 additions & 0 deletions crates/cashu/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum Error {
TokenNotVerifed,
#[error("Invoice Amount undefined")]
InvoiceAmountUndefined,
#[error("Proof missing required field")]
MissingProofField,
}

#[cfg(feature = "wallet")]
Expand Down
16 changes: 16 additions & 0 deletions crates/cashu/src/nuts/nut00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,19 @@ impl From<Proof> for mint::Proof {
}
}

impl TryFrom<mint::Proof> for Proof {
type Error = Error;

fn try_from(mint_proof: mint::Proof) -> Result<Proof, Self::Error> {
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};

Expand All @@ -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<Amount>,
/// Secret message
#[serde(skip_serializing)]
pub secret: Secret,
/// Unblinded signature
#[serde(rename = "C")]
pub c: Option<PublicKey>,
/// `Keyset id`
#[serde(skip_serializing)]
pub id: Option<Id>,
}

Expand Down

0 comments on commit 69bdb18

Please sign in to comment.