diff --git a/crates/cashu-sdk/src/mint.rs b/crates/cashu-sdk/src/mint.rs index ede40f31..a6b7c9de 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 fa1ca0c6..adc38390 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 91daca22..b9df9ed8 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 e1df11f0..611e012e 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, }