diff --git a/bindings/cdk-js/src/wallet.rs b/bindings/cdk-js/src/wallet.rs index 2a5f0a21..ccfcb33d 100644 --- a/bindings/cdk-js/src/wallet.rs +++ b/bindings/cdk-js/src/wallet.rs @@ -170,16 +170,28 @@ impl JsWallet { &mut self, mint_url: String, quote_id: String, + p2pk_condition: Option, + htlc_condition: Option, split_target_amount: Option, ) -> Result { let target = split_target_amount .map(|a| SplitTarget::Value(*a.deref())) .unwrap_or_default(); let mint_url = UncheckedUrl::from_str(&mint_url).map_err(into_err)?; + let conditions = match (p2pk_condition, htlc_condition) { + (Some(_), Some(_)) => { + return Err(JsValue::from_str( + "Cannot define both p2pk and htlc conditions", + )); + } + (None, Some(htlc_condition)) => Some(htlc_condition.deref().clone()), + (Some(p2pk_condition), None) => Some(p2pk_condition.deref().clone()), + (None, None) => None, + }; Ok(self .inner - .mint(mint_url, "e_id, target) + .mint(mint_url, "e_id, target, conditions) .await .map_err(into_err)? .into()) diff --git a/crates/cdk/src/nuts/nut00.rs b/crates/cdk/src/nuts/nut00.rs index 4e2f38e6..61a3ec7f 100644 --- a/crates/cdk/src/nuts/nut00.rs +++ b/crates/cdk/src/nuts/nut00.rs @@ -432,7 +432,7 @@ impl PreMintSecrets { keyset_id: Id, amount: Amount, amount_split_target: &SplitTarget, - conditions: SpendingConditions, + conditions: &SpendingConditions, ) -> Result { let amount_split = amount.split_targeted(amount_split_target); diff --git a/crates/cdk/src/wallet.rs b/crates/cdk/src/wallet.rs index 1325821c..0e41b55a 100644 --- a/crates/cdk/src/wallet.rs +++ b/crates/cdk/src/wallet.rs @@ -522,7 +522,12 @@ impl Wallet { if mint_quote_response.paid { let amount = self - .mint(mint_quote.mint_url, &mint_quote.id, SplitTarget::default()) + .mint( + mint_quote.mint_url, + &mint_quote.id, + SplitTarget::default(), + None, + ) .await?; total_amount += amount; } else if mint_quote.expiry.le(&unix_time()) { @@ -595,6 +600,7 @@ impl Wallet { mint_url: UncheckedUrl, quote_id: &str, amount_split_target: SplitTarget, + spending_conditions: Option, ) -> Result { // Check that mint is in store of mints if self.localstore.get_mint(mint_url.clone()).await?.is_none() { @@ -622,14 +628,22 @@ impl Wallet { let count = count.map_or(0, |c| c + 1); - let premint_secrets = PreMintSecrets::from_xpriv( - active_keyset_id, - count, - self.xpriv, - quote_info.amount, - false, - &amount_split_target, - )?; + let premint_secrets = match &spending_conditions { + Some(spending_conditions) => PreMintSecrets::with_conditions( + active_keyset_id, + quote_info.amount, + &amount_split_target, + spending_conditions, + )?, + None => PreMintSecrets::from_xpriv( + active_keyset_id, + count, + self.xpriv, + quote_info.amount, + false, + &amount_split_target, + )?, + }; let mint_res = self .client @@ -666,10 +680,12 @@ impl Wallet { // Remove filled quote from store self.localstore.remove_mint_quote("e_info.id).await?; - // Update counter for keyset - self.localstore - .increment_keyset_counter(&active_keyset_id, proofs.len() as u32) - .await?; + if spending_conditions.is_none() { + // Update counter for keyset + self.localstore + .increment_keyset_counter(&active_keyset_id, proofs.len() as u32) + .await?; + } let proofs = proofs .into_iter() @@ -846,7 +862,7 @@ impl Wallet { active_keyset_id, desired_amount, amount_split_target, - conditions, + &conditions, )?, change_premint_secrets, )