diff --git a/crates/cdk/src/nuts/nut03.rs b/crates/cdk/src/nuts/nut03.rs index fcc6bcba..8c4c5b96 100644 --- a/crates/cdk/src/nuts/nut03.rs +++ b/crates/cdk/src/nuts/nut03.rs @@ -14,6 +14,8 @@ pub struct PreSwap { pub pre_mint_secrets: PreMintSecrets, /// Swap request pub swap_request: SwapRequest, + /// Amount to increment keyset counter by + pub derived_secret_count: u32, } /// Split Request [NUT-06] diff --git a/crates/cdk/src/wallet/mod.rs b/crates/cdk/src/wallet/mod.rs index 003fa818..8f51bcf7 100644 --- a/crates/cdk/src/wallet/mod.rs +++ b/crates/cdk/src/wallet/mod.rs @@ -687,9 +687,8 @@ impl Wallet { let active_keyset_id = self.active_mint_keyset().await?; - // FIXME: Should not increment keyset counter for condition proofs self.localstore - .increment_keyset_counter(&active_keyset_id, post_swap_proofs.len() as u32) + .increment_keyset_counter(&active_keyset_id, pre_swap.derived_secret_count) .await?; let mut keep_proofs = Proofs::new(); @@ -791,6 +790,8 @@ impl Wallet { let desired_amount = amount.unwrap_or(proofs_total); let change_amount = proofs_total - desired_amount; + let derived_secret_count; + let (mut desired_messages, change_messages) = match spending_conditions { Some(conditions) => { let count = self @@ -808,6 +809,8 @@ impl Wallet { amount_split_target, )?; + derived_secret_count = change_premint_secrets.len(); + ( PreMintSecrets::with_conditions( active_keyset_id, @@ -844,6 +847,8 @@ impl Wallet { amount_split_target, )?; + derived_secret_count = change_premint_secrets.len() + premint_secrets.len(); + (premint_secrets, change_premint_secrets) } }; @@ -858,6 +863,7 @@ impl Wallet { Ok(PreSwap { pre_mint_secrets: desired_messages, swap_request, + derived_secret_count: derived_secret_count as u32, }) }