Browse Source

feat: only increment keyset counter for derived secrets

thesimplekid 8 months ago
parent
commit
bfe6ecb197
2 changed files with 10 additions and 2 deletions
  1. 2 0
      crates/cdk/src/nuts/nut03.rs
  2. 8 2
      crates/cdk/src/wallet/mod.rs

+ 2 - 0
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]

+ 8 - 2
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,
         })
     }